Kaynağa Gözat

Merge branch 'test' of http://192.168.136.99:3000/servers/ASJServer into locky

 Conflicts:
	.pre-commit-config.yaml
locky 2 yıl önce
ebeveyn
işleme
107dc6dfd7

+ 26 - 19
Controller/AlgorithmShop/AlgorithmShopController.py

@@ -111,14 +111,12 @@ class AlgorithmShopView(View):
 
             LOGGER.info(f'uid{uid}-DeviceTime:{d_time},tz:{tz},结果:{date_time}')
             passenger_flow_list = []
-            if enter_count > 0:
-                data['count'] = enter_count
-                data['type'] = 1
-                passenger_flow_list.append(DeviceAlgorithmPassengerFlow(**data))
-            if exit_count > 0:
-                data['count'] = exit_count
-                data['type'] = 2
-                passenger_flow_list.append(DeviceAlgorithmPassengerFlow(**data))
+            data['count'] = enter_count
+            data['type'] = 1
+            passenger_flow_list.append(DeviceAlgorithmPassengerFlow(**data))
+            data['count'] = exit_count
+            data['type'] = 2
+            passenger_flow_list.append(DeviceAlgorithmPassengerFlow(**data))
             DeviceAlgorithmPassengerFlow.objects.bulk_create(passenger_flow_list)
             # 将数据存入Redis,并设置过期时间为10分钟
             redis.CONN.setnx(key, d_time)
@@ -489,24 +487,33 @@ class AlgorithmShopView(View):
         t_list = [math.floor((c_time - timedelta(hours=i)).timestamp()) for i in range(24)]
         passenger_flow_list = []
         pf_qs = DeviceAlgorithmPassengerFlow.objects.filter(
-            device_time__in=t_list,
+            device_time__gte=t_list[23],
+            device_time__lte=t_list[0],
             type=int(flow_type),
             uid=uid
         ).order_by('device_time')
         if not pf_qs.exists():
             return passenger_flow_list
-        # 将查询到的数据时间戳转字典
-        pf_dict = {pf.device_time: pf for pf in pf_qs}
         # 循环查找最近24小时的记录(包含当前时间)
         for i in range(24):
-            current_timestamp = t_list[i]
-            if current_timestamp in pf_dict:
-                item = pf_dict[current_timestamp]
-                passenger_flow_list.append({
-                    'index': 23 - i,
-                    'count': item.count,
-                    'time': item.device_time
-                })
+            current_time = t_list[i]
+            next_time = -1 if i == 0 else t_list[i - 1]
+            is_data = False
+            count = 0
+            for item in pf_qs:
+                if next_time == -1 and next_time == item.device_time:
+                    count += item.count
+                    is_data = True
+                elif current_time <= item.device_time < next_time:
+                    count += item.count
+                    is_data = True
+            if not is_data:
+                continue
+            passenger_flow_list.append({
+                'index': 23 - i,
+                'count': count,
+                'time': current_time
+            })
         return passenger_flow_list
 
     @staticmethod

+ 1 - 1
Controller/DeviceTypeController.py

@@ -97,7 +97,7 @@ class DeviceTypeView(View):
         """
         app_bundle_id = request_dict.get('app_bundle_id', None)
         if not app_bundle_id:
-            return response.json(444, {'error param': 'app_bundle_id'})
+            app_bundle_id = 'com.ansjer.zccloud_a'
         try:
             lang = response.lang
             app_device_qs = DeviceNameLanguage.objects.filter(lang=lang)

+ 1 - 2
Object/IPWeatherObject.py

@@ -47,6 +47,5 @@ class WeatherInfo:
             result = response.json()
             if result['code'] == 0:
                 # 返回温湿度
-                return '{} ℃'.format(result['data']['condition']['temp']), '{} %'.format(
-                    result['data']['condition']['humidity'])
+                return result['data']['condition']['temp'], result['data']['condition']['humidity']
         return None, None