我正在使用 PyGal 在前端渲染一些图表。我的 django-view [基于函数] 有点像这样:
def random_view(request):
values_list = list()
camera_dict = dict()
bar_chart = pygal.Bar(spacing=60, explicit_size=True, width=2000,
height=800, pretty_print=True, margin=5, x_label_rotation=60, show_minor_x_labels=True)
bar_chart.x_labels = ['8 AM', '9 AM', '10 AM', '11 AM', '12 Noon', '13 PM', '14 PM',
'15 PM', '16 PM', '17 PM', '18 PM', '19 PM', '20 PM', '21 PM', '22 PM', '23 PM']
if request.method == 'GET':
profile = Profile.objects.get(user_profile=request.user)
store_qs = Store.objects.filter(brand_admin=profile)
for store in store_qs:
cam_qs = Camera.objects.filter(install_location=store)
for cam in cam_qs:
for x in range(10, 22):
value = PeopleCount.objects.filter(
timestamp__date='2017-09-06', timestamp__hour=x, camera=cam).aggregate(Sum('people_count_entry'))['people_count_entry__sum'] # noqa
values_list.append(value)
bar_chart.add(str(cam), values_list)
context = {'test': camera_dict, 'fun': bar_chart.render_data_uri()}
return render(request, 'reports/report_daily.html', context)
问题是我为两个不同的相机对象获得了相同的值。
信息:
例如,如果 astore
让two cameras
我们说cam1 and cam2
. 我得到两个凸轮的相同值,这不应该是这种情况。
我不知道我在哪里犯错误。帮助赞赏
提前致谢 :)