|
@@ -37,6 +37,8 @@ class UserDataView(View):
|
|
|
return self.user_increase(request_dict, response)
|
|
|
elif operation == 'active': # 查询用户活跃数据
|
|
|
return self.user_active(request_dict, response)
|
|
|
+ elif operation == 'active_user': # 查询用户活跃数据
|
|
|
+ return self.get_active_user(request_dict, response)
|
|
|
elif operation == 'region': # 查询用户地区分布
|
|
|
return self.user_region(response)
|
|
|
elif operation == 'global/increase': # 查询全球用户新增数据
|
|
@@ -398,3 +400,52 @@ class UserDataView(View):
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def get_active_user(cls, request_dict, response):
|
|
|
+ """
|
|
|
+ 查询用户活跃数据
|
|
|
+ @param request_dict:请求参数
|
|
|
+ @request_dict startTime:开始时间
|
|
|
+ @request_dict endTime:结束时间
|
|
|
+ @request_dict timeUnit:时间单位
|
|
|
+ @param response:响应对象
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ start_time = request_dict.get('startTime', None)
|
|
|
+ end_time = request_dict.get('endTime', None)
|
|
|
+ device_type = request_dict.get('device_type', None)
|
|
|
+ ucode = request_dict.get('ucode', None)
|
|
|
+ if not all([start_time, end_time]):
|
|
|
+ return response.json(444, {'error param': 'startTime or endTime'})
|
|
|
+ try:
|
|
|
+ all_user_qs = DeviceUserSummary.objects.filter(time__gte=start_time, time__lt=end_time,
|
|
|
+ query_type=1).values('device_type', 'ucode')
|
|
|
+ # 处理用户地区
|
|
|
+ device_type_dict = {}
|
|
|
+ ucode_dict = {}
|
|
|
+ for item in all_user_qs:
|
|
|
+ if item['device_type']:
|
|
|
+ for k, v in item['device_type'].items():
|
|
|
+ if k in device_type_dict:
|
|
|
+ device_type_dict[k] += v
|
|
|
+ else:
|
|
|
+ device_type_dict[k] = v
|
|
|
+ if item['ucode']:
|
|
|
+ for k, v in item['ucode'].items():
|
|
|
+ if k in ucode_dict:
|
|
|
+ ucode_dict[k] += v
|
|
|
+ else:
|
|
|
+ ucode_dict[k] = v
|
|
|
+ res = {
|
|
|
+ 'device_type': device_type_dict,
|
|
|
+ 'ucode': ucode_dict
|
|
|
+ }
|
|
|
+ if device_type:
|
|
|
+ res['device_type'] = {device_type: device_type_dict.get(device_type, 0)}
|
|
|
+ if ucode:
|
|
|
+ res['ucode'] = {ucode: ucode_dict.get(ucode, 0)}
|
|
|
+
|
|
|
+ return response.json(0, res)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|