我正在尝试对jsPDF库应用一些更改,以便能够证明文本的合理性.
我很难找到Tw(字间距)的正确值.
在jspdf.js(L:1413)中,我添加了以下代码:
if (align) {
...
else if (align === 'justify') {
left = x;
}
else {
throw new Error('Unrecognized alignment option, use "center" or "right".');
}
prevX = x;
text = '(' + da[0];
let pdfPageWidth = this.internal.pageSize.width;
let wordSpacing;
if( align === 'justify' ) {
let fontSize = this.internal.getFontSize();
let nWords = da[0].trim().split(/\s+/).length;
let textWidth = this.getStringUnitWidth(da[0].replace(/\s+/g, '')) / this.internal.scaleFactor;
wordSpacing = (Math.max(0, (pdfPageWidth - textWidth) / Math.max(1, nWords - …Run Code Online (Sandbox Code Playgroud) 我正在使用聚合来计算一列布尔值.我想要真值的数量.
DJANGO代码:
count = Model.objects.filter(id=pk).aggregate(bool_col=Count('my_bool_col')
Run Code Online (Sandbox Code Playgroud)
这将返回所有行的计数.
SQL QUERY应该是:
SELECT count(CASE WHEN my_bool_col THEN 1 ELSE null END) FROM <table_name>
Run Code Online (Sandbox Code Playgroud)
这是我的实际代码:
stats = Team.objects.filter(id=team.id).aggregate(
goals=Sum('statistics__goals'),
assists=Sum('statistics__assists'),
min_penalty=Sum('statistics__minutes_of_penalty'),
balance=Sum('statistics__balance'),
gwg=Count('statistics__gwg'),
gk_goals_avg=Sum('statistics__gk_goals_avg'),
gk_shutout=Count('statistics__gk_shutout'),
points=Sum('statistics__points'),
)
Run Code Online (Sandbox Code Playgroud)
感谢Peter DeGlopper建议使用django-aggregate-if
这是解决方案:
from django.db.models import Sum
from django.db.models import Q
from aggregate_if import Count
stats = Team.objects.filter(id=team.id).aggregate(
goals=Sum('statistics__goals'),
assists=Sum('statistics__assists'),
balance=Sum('statistics__balance'),
min_penalty=Sum('statistics__minutes_of_penalty'),
gwg=Count('statistics__gwg', only=Q(statistics__gwg=True)),
gk_goals_avg=Sum('statistics__gk_goals_avg'),
gk_shutout=Count('statistics__gk_shutout', only=Q(statistics__gk_shutout=True)),
points=Sum('statistics__points'),
)
Run Code Online (Sandbox Code Playgroud) 我指的是这个github项目,我正在尝试编写一个KeyPad.js组件的简单测试.
我已经看到在这个问题上打开了问题,一个建议的解决方案是将主题作为prop传递给组件.该解决方案不适用于酶.
在我的情况下,问题是子组件通过ThemeProvider接收主题,并且能够进行测试工作,我需要向所有人添加主题道具.
例:
const tree = renderer.create(
<KeyPad
theme={theme}
cancel={()=> true}
confirm={()=> true}
validation={()=> true}
keyValid={()=>true} />
).toJSON();
expect(tree).toMatchSnapshot();
Run Code Online (Sandbox Code Playgroud)
KeyPad的渲染方法会像这样改变,主题道具无处不在
render() {
let { displayRule, validation, label, confirm, cancel, theme, keyValid, dateFormat } = this.props
return (
<Container theme={theme}>
<Content theme={theme}>
<Header theme={theme}>
<CancelButton theme={theme} onClick={cancel}>
<MdCancel />
</CancelButton>
<Label>{label}</Label>
<ConfirmButton theme={theme} onClick={() => confirm(this.state.input)} disabled={!validation(this.state.input)}>
<MdCheck />
</ConfirmButton>
</Header>
<Display
theme={theme}
value={this.state.input}
displayRule={displayRule}
dateFormat={dateFormat}
cancel={this.cancelLastInsert} />
<Keys>
{[7, 8, 9, 4, 5, 6, 1, …Run Code Online (Sandbox Code Playgroud) 我对人工智能有点困惑.
我理解它是机器学习新事物的能力,或者在不实际执行代码的情况下做不同的事情(已经由某人编写).
在SO中,我在游戏中看到许多关于AI的线索,但IMO不是AI因为如果它是每个软件甚至打印命令应该被称为AI在游戏中只有执行的代码.我称之为伪AI.
我错了吗?应该也算是AI吗?
有一种简单的方法可以将hibernate设置为使用postgres为每个表使用不同的主键ID吗?我试图在DataSource中使用postgres方言:
dialect = org.hibernate.dialect.PostgreSQLDialect
or
dialect = net.sf.hibernate.dialect.PostgreSQLDialect
Run Code Online (Sandbox Code Playgroud)
但它不起作用.谢谢
我正在尝试在没有模型关联的情况下将自定义页面添加到管理员。
这是我到目前为止所取得的成就。
class MyCustomAdmin(AdminSite):
def get_urls(self):
from django.conf.urls import url
urls = super(MyCustomAdmin, self).get_urls()
urls += [
url(r'^my_custom_view/$', self.admin_view(MyCustomView.as_view()))
]
return urls
class MyCustomView(View):
template_name = 'admin/myapp/views/my_custom_template.html'
def get(self, request):
return render(request, self.template_name, {})
def post(self, request):
# Do something
pass
admin_site = MyCustomAdmin()
admin_site.register(MyModel1)
admin_site.register(MyModel2)
# etc...
Run Code Online (Sandbox Code Playgroud)
这实际上是可行的,但是问题是,通过此解决方案,我从Django管理界面(帐户,身份验证,社交帐户,网站)中松了一些应用。
我正在尝试使用类似于SQL的查询语法找到一种过滤器js集合的方法.
我发现完成此任务的唯一库是json-query.
它在某些情况下有效,但它有局限性.对于多个结果,不可能使用相同的查询或查询在不同的对象级别上进行查询.
以下是一些示例(以下面的数据结构作为参考)
[{
"type": "UU",
"value": "100",
"tipo": "G",
"strumento": "P",
"aspetto": "C",
"unit": "ml"
},
{
"type": "PS",
"value": "120/88",
"rilevamento": "Manuale",
"lato": "SX",
"part": "Supina",
"unit": "mmHg"
},
{
"type": "TP",
"value": "33.6",
"tipo": "T",
"unit": "°C"
},
{
"type": "VO",
"value": "12",
"tipo": "VOAL",
"unit": "ml"
},
{
"type": "RS",
"value": "60",
"unit": "atti/min"
},
{
"type": "HH",
"value": "180",
"modalita": "R",
"unit": "cm"
},
{
"type": "AA",
"value": "50",
"unit": "cm"
}, …Run Code Online (Sandbox Code Playgroud) 我开始使用Spring了.
当我到达WebDomainIntegrationTest时,在本教程之后,由于内容响应为空,测试失败.
我想也许问题可能是serverport.应用程序在端口8000上运行,集成测试请求localhost端口80.(如果这是问题,我该如何设置不同的端口?)
码
SiteController:
@Controller
@RequestMapping("/")
public class SiteController {
private static final Logger LOG = LoggerFactory.getLogger(SiteController.class);
@Autowired
private MenuService menuService;
@Autowired
private Basket basket;
@RequestMapping(method = RequestMethod.GET)
public String getCurrentMenu(Model model) {
LOG.debug("Yummy MenuItemDetails to home view");
model.addAttribute("menuItems",getMenuItems(menuService.requestAllMenuItems(new RequestAllMenuItemsEvent())));
System.out.println("getCurrentMenu");
return "home";
}
private List<MenuItem> getMenuItems(AllMenuItemsEvent requestAllMenuItems) {
List<MenuItem> menuDetails = new ArrayList<MenuItem>();
for (MenuItemDetails menuItemDetails : requestAllMenuItems.getMenuItemDetails()) {
menuDetails.add(MenuItem.fromMenuDetails(menuItemDetails));
}
return menuDetails;
}
/*
Lastly, you need to put the Basket into the model for …Run Code Online (Sandbox Code Playgroud) 我需要一些有关 Docker 配置的帮助,以使 Django 在开发模式下与 webpack 开发服务器配合使用。我希望 django docker 容器能够访问 webpack 生成的包。
我正在努力理解容器如何与 docker-compose 中的卷共享文件。
到目前为止,我只设法拥有一个可用的 django dockerized 应用程序,然后在本地运行 npm install && node server.js 。
Dockerfile
# use base python image with python 2.7
FROM python:2.7
ENV PYTHONUNBUFFERED 1
# set working directory to /code/
RUN mkdir /code
WORKDIR /code
# add requirements.txt to the image
ADD requirements.txt /code/
# install python dependencies
RUN pip install -r requirements.txt
ADD . /code/
# Port to expose
EXPOSE 8000
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml
version: '2' …Run Code Online (Sandbox Code Playgroud) django ×3
javascript ×3
python ×2
admin ×1
aggregate ×1
docker ×1
dockerfile ×1
grails ×1
groovy ×1
hibernate ×1
java ×1
jestjs ×1
jquery ×1
json ×1
json-query ×1
jspdf ×1
junit ×1
pdf ×1
postgresql ×1
primary-key ×1
reactjs ×1
spring ×1
spring-mvc ×1
swap ×1
webpack ×1