diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index 553778e1..b8d41d61 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -51,6 +51,20 @@ def get_tag_val(): last_tag_id = mr_one.tag_id update_sysconfig({'enm': {'last_tag_id': last_tag_id}}) +@shared_task(base=CustomTask) +def cal_mpointstats_duration(start_time: str, end_time: str): + """ + 重跑某一段时间的任务 + """ + start_time = datetime.datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S') + end_time = datetime.datetime.strptime(end_time, '%Y-%m-%d %H:%M:%S') + current_time = start_time + while current_time <= end_time: + year, month, day, hour = current_time.year, current_time.month, current_time.day, current_time.hour + cal_mpointstats(0, year, month, day, hour) + current_time += datetime.timedelta(hours=1) + + @shared_task(base=CustomTask) def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: int): """ @@ -345,7 +359,7 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s, enstat.production_cost_unit = imaterial_cost_unit + other_cost_unit enstat.save() if enstat.total_production: - MpointStat.objects.filter(mgroup=enstat.mgroup, mpoint__material__code='elec').exclude(ep_monitored=None).update(total_production=enstat.total_production, + MpointStat.objects.filter(mgroup=enstat.mgroup, mpoint__material__code='elec').exclude(mpoint__ep_monitored=None).update(total_production=enstat.total_production, elec_consume_unit=F('val')/enstat.total_production) if enstat.mgroup.cate == 'section': if 'material' in this_cal_attrs: