From c0dd70982a3db81aee13dc0d41713eaecadd71fe Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 28 Aug 2023 09:18:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20enm=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=B7=91?= =?UTF-8?q?=E6=9F=90=E4=B8=80=E6=AE=B5=E6=97=B6=E9=97=B4=E7=9A=84=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/tasks.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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: