feat: enm增加重跑某一段时间的任务

This commit is contained in:
caoqianming 2023-08-28 09:18:32 +08:00
parent 620351c8bf
commit c0dd70982a
1 changed files with 15 additions and 1 deletions

View File

@ -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: