Kaynağa Gözat

优化客流折线图统计

zhangdongming 2 yıl önce
ebeveyn
işleme
c9da1acdb4

+ 11 - 5
Controller/AlgorithmShop/AlgorithmShopController.py

@@ -500,17 +500,20 @@ class AlgorithmShopView(View):
             next_time = -1 if i == 0 else t_list[i - 1]
             is_data = False
             count = 0
+            hour = 0
             for item in pf_qs:
                 if next_time == -1 and next_time == item.device_time:
+                    hour = item.statistical_time.hour
                     count += item.count
                     is_data = True
                 elif current_time <= item.device_time < next_time:
                     count += item.count
+                    hour = item.statistical_time.hour
                     is_data = True
             if not is_data:
                 continue
             passenger_flow_list.append({
-                'index': 23 - i,
+                'index': hour,
                 'count': count,
                 'time': current_time
             })
@@ -549,7 +552,7 @@ class AlgorithmShopView(View):
                 s_time = LocalDateTimeUtil.start_of_day_timestamp(s_time)
 
             days_qs = []
-
+            day = 0
             for item in pf_qs:
                 # 计算结束时间
                 end_time = now_time if i == 0 else s_time + (3600 * 24)
@@ -557,11 +560,12 @@ class AlgorithmShopView(View):
                 # 将在起始时间和结束时间范围内的客流数据放入列表中
                 if s_time < item.device_time <= end_time:
                     days_qs.append(item.count)
+                    day = item.statistical_time.day if day == 0 else day
 
             if days_qs:
                 # 将每天的客流数据统计结果添加到列表中
                 passenger_flow_list.append({
-                    'index': 29 - i,
+                    'index': day,
                     'count': sum(days_qs),
                     'time': s_time
                 })
@@ -581,15 +585,17 @@ class AlgorithmShopView(View):
             df_qs = DeviceAlgorithmPassengerFlow.objects.filter(type=flow_type, uid=uid)
             if i == 0:
                 df_qs = df_qs.filter(device_time__range=(month_time, now_time))
+                data_qs = df_qs.first()
             else:
                 previous_month_time = LocalDateTimeUtil.get_previous_month_first_day(month_time)
                 df_qs = df_qs.filter(device_time__range=(previous_month_time, month_time))
+                data_qs = df_qs.first()
+                month_time = previous_month_time
             df_qs = df_qs.aggregate(total=Sum('count'))
             if not df_qs['total']:
                 continue
-
             passenger_flow_list.append({
-                'index': 11 - i,
+                'index': data_qs.statistical_time.month,
                 'count': df_qs['total'],
                 'time': month_time
             })