|
@@ -784,6 +784,8 @@ class CronCollectDataView(View):
|
|
|
return self.collect_play_back(response)
|
|
|
elif operation == 'collectDeviceUser': # 定时保存用户数据
|
|
|
return self.collect_device_user(response)
|
|
|
+ elif operation == 'collectActivityUser': # 定时保存用户数据
|
|
|
+ return self.collect_activity_user(response)
|
|
|
elif operation == 'collectOrder': # 定时保存订单数据
|
|
|
return self.collect_order(response)
|
|
|
elif operation == 'collectDeviceInfo': # 定时保存设备数据
|
|
@@ -1447,6 +1449,60 @@ class CronCollectDataView(View):
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@staticmethod
|
|
|
+ def collect_activity_user(response):
|
|
|
+ try:
|
|
|
+ created_time = int(time.time())
|
|
|
+ today = datetime.datetime.today()
|
|
|
+ start_time = datetime.datetime(today.year, today.month, today.day)
|
|
|
+ end_time = start_time + datetime.timedelta(days=1)
|
|
|
+ start_time = CommonService.str_to_timestamp(start_time.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
+ end_time = CommonService.str_to_timestamp(end_time.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
+ thread = threading.Thread(target=CronCollectDataView.thread_collect_activity_user,
|
|
|
+ args=(start_time, end_time, created_time))
|
|
|
+ thread.start() # 启动线程
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def thread_collect_activity_user(start_time, end_time, created_time):
|
|
|
+ try:
|
|
|
+ active_uid = UserExModel.objects.filter(updTime__gte=start_time, updTime__lt=end_time).values_list(
|
|
|
+ 'userID__device_info__UID', flat=True).distinct()
|
|
|
+ active_device_qs = UidSetModel.objects.filter(uid__in=active_uid).values('addTime', 'device_type', 'ucode')
|
|
|
+ # 设备类型数据
|
|
|
+ device_type_qs = DeviceTypeModel.objects.values('name', 'type')
|
|
|
+ device_type_dict = {}
|
|
|
+ for item in device_type_qs:
|
|
|
+ device_type_dict[item['type']] = item['name']
|
|
|
+ with transaction.atomic():
|
|
|
+ if active_device_qs.exists():
|
|
|
+ # 按设备设备类型
|
|
|
+ active_device_type_list = active_device_qs.values('device_type').annotate(
|
|
|
+ count=Count('device_type')).order_by('count')
|
|
|
+ active_device_type_dict = {}
|
|
|
+ for item in active_device_type_list:
|
|
|
+ type_name = device_type_dict.get(item['device_type'], '未知设备类型')
|
|
|
+ active_device_type_dict[type_name] = item['count']
|
|
|
+ # 按ucode分类
|
|
|
+ active_ucode_list = active_device_qs.values('ucode').annotate(count=Count('ucode')).order_by('count')
|
|
|
+ active_ucode_dict = {}
|
|
|
+ for item in active_ucode_list:
|
|
|
+ ucode = item['ucode']
|
|
|
+ if item['ucode'] == '':
|
|
|
+ ucode = '未知ucode'
|
|
|
+ active_ucode_dict[ucode] = item['count']
|
|
|
+ user_qs = DeviceUserSummary.objects.filter(time=start_time)
|
|
|
+ if user_qs.exists():
|
|
|
+ user_qs.update(device_type=active_device_type_dict, ucode=active_ucode_dict)
|
|
|
+ else:
|
|
|
+ DeviceUserSummary.objects.create(time=start_time, query_type=1, created_time=created_time,
|
|
|
+ device_type=active_device_type_dict, ucode=active_ucode_dict)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info(
|
|
|
+ 'thread_collect_activity_user接口异常:errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno,
|
|
|
+ repr(e)))
|
|
|
+ @staticmethod
|
|
|
def collect_flow_info(response):
|
|
|
try:
|
|
|
unicom_qs = UnicomDeviceInfo.objects.filter(card_type=0).values('iccid').distinct().order_by('iccid')
|