feat: enm_alarm任务函数
This commit is contained in:
parent
ec8d416e80
commit
5835e2f6a0
|
@ -22,6 +22,7 @@ import logging
|
|||
from django.db.models import F
|
||||
from apps.wpm.services import get_pcoal_heat
|
||||
import traceback
|
||||
from django.utils import timezone
|
||||
myLogger = logging.getLogger('log')
|
||||
|
||||
def get_current_and_previous_time():
|
||||
|
@ -215,6 +216,9 @@ def cal_mpointstats(is_now=1, year=None, month=None, day=None, hour=None):
|
|||
cal_enstat2(type="day_s", year_s=year_s, month_s=month_s, day_s=day_s)
|
||||
# task_chain = chain(group(mpoints_without_formula_group), group(mpoints_other_group), group(mgroups_group), group(mgroups_t_group), group([cal_enstat2.s(year_s=year, month_s=month)]))
|
||||
# task_chain.delay()
|
||||
if hour == 21:
|
||||
enm_alarm.delay(year_s, month_s, day_s)
|
||||
|
||||
|
||||
@shared_task(base=CustomTask)
|
||||
def cal_mpointstat_manual(mpointId: str, sflogId: str, mgroupId: str, year: int, month: int, day: int, hour: int, year_s: int, month_s: int, day_s: int, next_cal=0):
|
||||
|
@ -410,6 +414,7 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
|
|||
if pre_enstat:
|
||||
try:
|
||||
enstat.celec_consume_unit = enstat.elec_consume_unit + 1.45*pre_enstat.elec_consume_unit
|
||||
enstat.save()
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
|
@ -611,4 +616,47 @@ def cal_enstat_pcoal_change(enstat, new_pcoal_heat):
|
|||
next_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name='水泥磨').first()
|
||||
if next_enstat:
|
||||
next_enstat.cen_consume_unit = next_enstat.elec_consume_unit*0.1229 + 0.7*enstat.cen_consume_unit
|
||||
next_enstat.save(update_fields=['cen_consume_unit'])
|
||||
next_enstat.save(update_fields=['cen_consume_unit'])
|
||||
|
||||
|
||||
enm_alarms_list = [
|
||||
['回转窑', 'celec_consume_unit', '单位产品综合电耗'],
|
||||
['回转窑', 'coal_consume_unit', '单位产品标煤耗'],
|
||||
['水泥磨', 'elec_consume_unit', '单位产品分布电耗']
|
||||
]
|
||||
|
||||
@shared_task(base=CustomTask)
|
||||
def enm_alarm(year_s: int, month_s: int, day_s: int):
|
||||
"""
|
||||
enm报警任务
|
||||
"""
|
||||
from apps.ecm.models import Event, EventCate, Eventdo
|
||||
from apps.mtm.models import Goal
|
||||
from apps.ecm.service import notify_event
|
||||
now = timezone.now()
|
||||
event_cate, _ = EventCate.objects.get_or_create(code='consume_exceed', default={'name': '能耗超过目标值', 'code': 'consume_exceed', 'triger': 30})
|
||||
for item in enm_alarms_list:
|
||||
mgroups = Mgroup.objects.filter(name=item[0])
|
||||
for mgroup in mgroups:
|
||||
enstat = EnStat.objects.filter(mgroup=mgroup, type='day_s', year_s=year_s, month_s=month_s, day_s=day_s).first()
|
||||
if enstat:
|
||||
mgroup_name = item[0]
|
||||
goal_cate_str = item[1]
|
||||
real_val = getattr(enstat, goal_cate_str, None)
|
||||
goal = Goal.objects.filter(goal_cate__code=goal_cate_str, year=year_s, mgroup=mgroup).first()
|
||||
if goal:
|
||||
goal_val = getattr(goal, f'goal_val_{month_s}', None)
|
||||
if goal_val and real_val and real_val > goal_val: # 触发事件
|
||||
event = Event()
|
||||
event.obj_cate = 'enm'
|
||||
event.happen_time = now
|
||||
event.voice_msg = f'{mgroup_name}{item[2]}超过设定目标值'
|
||||
event.enm_data = {'mgroup': mgroup.id, 'mgroup_name': mgroup.name, 'type': f'{goal_cate_str}.exceed', 'year_s': year_s, 'month_s': month_s, 'day_s': day_s, 'val': real_val, 'goal_val': goal_val}
|
||||
event.save()
|
||||
Eventdo.objects.get_or_create(cate=event_cate, event=event, defaults={
|
||||
'cate': event_cate,
|
||||
'event': event
|
||||
})
|
||||
notify_event(event)
|
||||
|
||||
|
Loading…
Reference in New Issue