【发布时间】:2012-09-17 13:47:31
【问题描述】:
我必须注释结果:
cred_rec = Disponibilidad.objects.values('mac__mac', 'int_mes').annotate(tramites=Count('fuar'), recibidas=Count('fecha_disp_mac')
cred14 = Disponibilidad.objects.filter(int_disponible__lte=14).values('mac__mac', 'int_mes').annotate(en14=Count('fuar'))
两者都有相同的键'mac__mac'和'int_mes',我想要创建一个新字典,其中的键为cred_red,加上来自cred14的en14。
我尝试了一些answers found here,但我错过了一些东西。
谢谢。
编辑。经过一些尝试和错误,我得到了这个:
for linea in cred_rec:
clave = (linea['mac__mac'], linea['int_mes'])
for linea2 in cred14:
clave2 = (linea2['mac__mac'], linea2['int_mes'])
if clave2 == clave:
linea['en14'] = linea2['en14']
linea['disp'] = float(linea2['en14'])/linea['recibidas']*100
现在,我必须寻求更好的解决方案。再次感谢。
======= 编辑 这是输入的样子:
fuar, mac_id, int_mes, int_disponible, int_exitoso, fecha_tramite, fecha_actualiza_pe, fecha_disp_mac
1229012106349,1,7,21,14,2012-07-02 08:33:54.0,2012-07-16 17:33:21.0,2012-07-23 08:01:22.0
1229012106350,1,7,25,17,2012-07-02 09:01:25.0,2012-07-19 17:45:57.0,2012-07-27 17:45:59.0
1229012106351,1,7,21,14,2012-07-02 09:15:12.0,2012-07-16 19:14:35.0,2012-07-23 08:01:22.0
1229012106352,1,7,24,16,2012-07-02 09:25:19.0,2012-07-18 07:52:18.0,2012-07-26 16:04:11.0
... a few thousand lines dropped ...
fuar 就像一个 order_id; mac__mac 就像site_id,mes 是month; int_disponible 是 fecha_tramite 和 fecha_disp_mac 之间的时间差; int_exitoso 是 fecha_tramite 和 fecha_actualiza_pe 之间的时间差。
输出是这样的:
mac, mes, tramites, cred_rec, cred14, % rec, % en 14
1, 7, 2023, 2006, 1313, 99.1596638655, 65.4536390828
1, 8, 1748, 1182, 1150, 67.6201372998, 97.2927241963
2, 8, 731, 471, 441, 64.4322845417, 93.6305732484
3, 8, 1352, 840, 784, 62.1301775148, 93.3333333333
-
tramites 是一个月内所有订单 (
fuar) 的总和 -
cred_rec cred是我们的产品,理论上每一个fuar都有一个cred,
cred_rec是一个月内产生的所有cred的总和 - cred_14 是 14 天内所有 cred 的总和
- % rec 收到的fuar和产生的cred之间的关系,单位为%
- % en 14是产生的cred和及时产生的cred的关系
我将在 Annotated Time Line 图表或来自 Google Charts 的 Combo Chart 中使用此表来展示我们制造过程的性能。
感谢您的宝贵时间。
【问题讨论】:
-
您的输入是什么样的,您希望您的输出是什么样的?
-
使用信息编辑的问题。
-
输出涉及“一个月”和“14 天”。我们应该如何处理?
-
14 days是 14 天内生产的产品数量。我们在一个月内有一定数量的订单,我们必须在 14 天或更短的时间内完成它们,这是我们的质量目标。我们必须知道我们在 14 天内完成了多少订单以及占多少百分比。
标签: django dictionary django-queryset annotate