|
|
@@ -846,7 +846,8 @@ class CronUpdateDataView(View):
|
|
|
'status': 200,
|
|
|
'time': now_time,
|
|
|
'url': 'cron/update/deleteUidData',
|
|
|
- 'operation': '已解绑序列号{}清除uid{}成功,执行时间{}秒'.format(serial_list, uid_list, end_time-now_time)
|
|
|
+ 'operation': '已解绑序列号{}清除uid{}成功,执行时间{}秒'.format(serial_list, uid_list,
|
|
|
+ end_time - now_time)
|
|
|
}
|
|
|
LogModel.objects.create(**log)
|
|
|
|
|
|
@@ -1395,16 +1396,21 @@ class CronCollectDataView(View):
|
|
|
monthly_income = round((price - fee) / order_days * settlement_days, 2)
|
|
|
real_income = round(price - fee, 2)
|
|
|
|
|
|
+ vod_location = item['vod_location']
|
|
|
# 根据云存位置选择不同的成本计算方式
|
|
|
- if item['vod_location'] == 1: # 阿里云OSS
|
|
|
+ if vod_location == 1: # 阿里云OSS
|
|
|
try:
|
|
|
- yesterday_stamp = end_time_stamp - 86400
|
|
|
- uid_bucket_statistics = uid_bucket_statistics.filter(uid=item['uid'],
|
|
|
- time__gte=yesterday_stamp,
|
|
|
- time__lt=end_time_stamp)
|
|
|
- storage_cost, api_cost = CronCollectDataView._calculate_aliyun_costs(
|
|
|
- uid_bucket_statistics, redis_obj
|
|
|
- )
|
|
|
+ yesterday_stamp = end_time_stamp - 86400 # 昨日凌晨0点时间戳
|
|
|
+ # 获取昨日凌晨0点至今日凌晨0点之间的所有日统计记录
|
|
|
+ uid_bucket_statistics = UidBucketStatistics.objects.filter(uid=item['uid'],
|
|
|
+ time__gte=yesterday_stamp,
|
|
|
+ time__lt=end_time_stamp
|
|
|
+ ).order_by('time')
|
|
|
+ storage_cost, api_cost = 0, 0
|
|
|
+ if uid_bucket_statistics.exists():
|
|
|
+ storage_cost, api_cost = CronCollectDataView._calculate_aliyun_costs(
|
|
|
+ uid_bucket_statistics, redis_obj
|
|
|
+ )
|
|
|
ali_costs_qs = OperatingCosts.objects.filter(
|
|
|
time=start_time_stamp,
|
|
|
order_id=item['order_id'],
|
|
|
@@ -1415,7 +1421,8 @@ class CronCollectDataView(View):
|
|
|
storage_cost += float(ali_costs['storage_cost'])
|
|
|
api_cost += float(ali_costs['api_cost'])
|
|
|
except Exception as e:
|
|
|
- LOGGER.error(f'统计阿里云云存成本异常error_line:{e.__traceback__.tb_lineno}, error_msg:{str(e)}')
|
|
|
+ LOGGER.error(
|
|
|
+ f'统计阿里云云存成本异常error_line:{e.__traceback__.tb_lineno}, error_msg:{str(e)}')
|
|
|
continue
|
|
|
|
|
|
else: # AWS S3
|
|
|
@@ -1428,9 +1435,9 @@ class CronCollectDataView(View):
|
|
|
storage_cost = storage_cost * 7
|
|
|
api_cost = api_cost * 7
|
|
|
|
|
|
- profit = round(monthly_income - storage_cost - api_cost, 2)
|
|
|
- storage_cost = round(storage_cost, 2)
|
|
|
- api_cost = round(api_cost, 2)
|
|
|
+ profit = round(monthly_income - storage_cost - api_cost, 4 if vod_location == 1 else 2)
|
|
|
+ storage_cost = round(storage_cost, 4 if vod_location == 1 else 2)
|
|
|
+ api_cost = round(api_cost, 4 if vod_location == 1 else 2)
|
|
|
|
|
|
if monthly_income == 0.0:
|
|
|
profit_margin = 0
|
|
|
@@ -1464,7 +1471,7 @@ class CronCollectDataView(View):
|
|
|
order_type=order_type,
|
|
|
expire=expire
|
|
|
)
|
|
|
- print('结束')
|
|
|
+ LOGGER.info('结束')
|
|
|
except Exception as e:
|
|
|
LOGGER.info(
|
|
|
'thread_collect_operating_costs接口异常:errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno,
|
|
|
@@ -1548,7 +1555,6 @@ class CronCollectDataView(View):
|
|
|
|
|
|
return total_storage_cost_discounted, total_api_cost_discounted
|
|
|
|
|
|
-
|
|
|
@staticmethod
|
|
|
def collect_obj_size(response):
|
|
|
try:
|
|
|
@@ -1626,7 +1632,8 @@ class CronCollectDataView(View):
|
|
|
if not operating_costs_qs.exists():
|
|
|
OperatingCosts.objects.create(order_id=item['orderId'], uid=item['uid'],
|
|
|
created_time=creat_time, time=first_date,
|
|
|
- end_time=item['endTime'], vod_location=item['bucket__vod_location'])
|
|
|
+ end_time=item['endTime'],
|
|
|
+ vod_location=item['bucket__vod_location'])
|
|
|
LOGGER.info(f"uid:{item['uid']} 大小:{actual_storage} api次数:{actual_api}")
|
|
|
LOGGER.info('结束')
|
|
|
except Exception as e:
|
|
|
@@ -1840,7 +1847,8 @@ class CronCollectDataView(View):
|
|
|
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_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']
|
|
|
@@ -1856,7 +1864,8 @@ class CronCollectDataView(View):
|
|
|
except Exception as e:
|
|
|
LOGGER.info(
|
|
|
'thread_collect_activity_user接口异常:errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno,
|
|
|
- repr(e)))
|
|
|
+ repr(e)))
|
|
|
+
|
|
|
@staticmethod
|
|
|
def collect_flow_info(response):
|
|
|
try:
|