|
@@ -6,16 +6,23 @@
|
|
@Email : zhangdongming@asj6.wecom.work
|
|
@Email : zhangdongming@asj6.wecom.work
|
|
@Software: PyCharm
|
|
@Software: PyCharm
|
|
"""
|
|
"""
|
|
|
|
+import json
|
|
import logging
|
|
import logging
|
|
import time
|
|
import time
|
|
|
|
+from datetime import datetime
|
|
|
|
|
|
from django.db.models import F, Value, CharField
|
|
from django.db.models import F, Value, CharField
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
|
|
|
|
from Model.models import DeviceAlgorithmExplain, DeviceAlgorithmBanner, DeviceUidAlgorithmType, \
|
|
from Model.models import DeviceAlgorithmExplain, DeviceAlgorithmBanner, DeviceUidAlgorithmType, \
|
|
- DeviceTypeAlgorithmInfo, DeviceAppScenario, DeviceScenarioLangInfo, DeviceAlgorithmScenario
|
|
|
|
|
|
+ DeviceTypeAlgorithmInfo, DeviceAppScenario, DeviceScenarioLangInfo, DeviceAlgorithmScenario, \
|
|
|
|
+ DeviceAlgorithmPassengerFlow
|
|
|
|
+from Object.ETkObject import ETkObject
|
|
|
|
+from Object.Enums.TimeZone import TimeZone
|
|
|
|
+from Object.RedisObject import RedisObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
|
|
+from Object.utils import LocalDateTimeUtil
|
|
|
|
|
|
LOGGER = logging.getLogger('info')
|
|
LOGGER = logging.getLogger('info')
|
|
|
|
|
|
@@ -32,6 +39,8 @@ class AlgorithmShopView(View):
|
|
return self.validation(request.POST, request, operation)
|
|
return self.validation(request.POST, request, operation)
|
|
|
|
|
|
def validation(self, request_dict, request, operation):
|
|
def validation(self, request_dict, request, operation):
|
|
|
|
+ if operation == 'passengerFlowStatistical':
|
|
|
|
+ return self.passenger_flow_statistical(request_dict, ResponseObject('en'))
|
|
token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
lang = request_dict.get('lang', token.lang)
|
|
lang = request_dict.get('lang', token.lang)
|
|
response = ResponseObject(lang)
|
|
response = ResponseObject(lang)
|
|
@@ -52,6 +61,72 @@ class AlgorithmShopView(View):
|
|
else:
|
|
else:
|
|
return response.json(0)
|
|
return response.json(0)
|
|
|
|
|
|
|
|
+ @classmethod
|
|
|
|
+ def passenger_flow_statistical(cls, request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ 添加客流统计
|
|
|
|
+ Args:
|
|
|
|
+ request_dict (dict): 请求参数字典
|
|
|
|
+ response: 响应对象
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ LOGGER.info('*****AlgorithmShopView.passenger_flow_statistical:params{}'.format(json.dumps(request_dict)))
|
|
|
|
+ sign = request_dict.get('sign')
|
|
|
|
+ eto = ETkObject(sign)
|
|
|
|
+ uid = eto.uid
|
|
|
|
+ if not uid:
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
|
|
+ d_time = request_dict.get('deviceTime')
|
|
|
|
+ enter_count = request_dict.get('enterCount')
|
|
|
|
+ tz_value = request_dict.get('timeZone')
|
|
|
|
+ exit_count = request_dict.get('exitCount')
|
|
|
|
+
|
|
|
|
+ if not all([sign, enter_count, exit_count, tz_value]):
|
|
|
|
+ return response.json(444)
|
|
|
|
+ enter_count = int(enter_count)
|
|
|
|
+ exit_count = int(exit_count)
|
|
|
|
+ redis = RedisObject(5)
|
|
|
|
+ key = f'ASJ:PASSENGER:FLOW:{uid}:{d_time}'
|
|
|
|
+
|
|
|
|
+ # 检查Redis中是否已存在相同key的数据
|
|
|
|
+ r_data = redis.get_data(key)
|
|
|
|
+ if r_data:
|
|
|
|
+ return response.json(0)
|
|
|
|
+
|
|
|
|
+ now_time = int(time.time())
|
|
|
|
+ data = {
|
|
|
|
+ 'uid': uid,
|
|
|
|
+ 'updated_time': now_time,
|
|
|
|
+ 'created_time': now_time,
|
|
|
|
+ 'device_time': int(d_time)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ tz = TimeZone.get_value(int(tz_value))
|
|
|
|
+ date_time = LocalDateTimeUtil.time_format_date(int(d_time), tz)
|
|
|
|
+ data['statistical_time'] = datetime.strptime(date_time, '%Y-%m-%d %H:%M:%S')
|
|
|
|
+
|
|
|
|
+ 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))
|
|
|
|
+ DeviceAlgorithmPassengerFlow.objects.bulk_create(passenger_flow_list)
|
|
|
|
+ # 将数据存入Redis,并设置过期时间为10分钟
|
|
|
|
+ redis.CONN.setnx(key, d_time)
|
|
|
|
+ redis.CONN.expire(key, 600)
|
|
|
|
+
|
|
|
|
+ return response.json(0)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ LOGGER.info('***get_algorithm_list_by_scenario_id,errLine:{}, errMsg:{}'
|
|
|
|
+ .format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
+
|
|
@classmethod
|
|
@classmethod
|
|
def get_algorithm_list_by_scenario_id(cls, scenario_id, lang):
|
|
def get_algorithm_list_by_scenario_id(cls, scenario_id, lang):
|
|
"""
|
|
"""
|