From 1e4e80879f1302c66d9749933db73cf978418be0 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 25 Dec 2024 15:24:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E7=B3=BB=E6=95=B0=E5=90=8E=E7=9A=84enm=20task=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/services.py | 17 +++++++---------- apps/enm/tasks.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/apps/enm/services.py b/apps/enm/services.py index 1a82c00a..c6a411b5 100644 --- a/apps/enm/services.py +++ b/apps/enm/services.py @@ -33,16 +33,13 @@ def translate_eval_formula(exp_str: str, year: int, month: int, day: int, hour: matches = re.findall(pattern, exp_str) exp_str2 = exp_str for match in matches: - if match in ["enm_lhxs"]: - exp_str2 = exp_str2.replace(f"{{{match}}}", str(get_sysconfig(f"enm.{match}"))) - else: - mpst = MpointStat.objects.filter(mpoint__code=match, type="hour", year=year, month=month, day=day, hour=hour).first() - if mpst is None: - mpoint = Mpoint.objects.get(code=match) - mpst, _ = MpointStat.objects.get_or_create(mpoint=mpoint, type="hour", year=year, month=month, day=day, hour=hour, defaults={"val": 0}) - myLogger.error(f"找不到该测点的时间线数据: {match}, {year}, {month}, {day}, {hour}, 赋予0值") - if mpst: - exp_str2 = exp_str2.replace(f"{{{match}}}", str(mpst.val)) + mpst = MpointStat.objects.filter(mpoint__code=match, type="hour", year=year, month=month, day=day, hour=hour).first() + if mpst is None: + mpoint = Mpoint.objects.get(code=match) + mpst, _ = MpointStat.objects.get_or_create(mpoint=mpoint, type="hour", year=year, month=month, day=day, hour=hour, defaults={"val": 0}) + myLogger.error(f"找不到该测点的时间线数据: {match}, {year}, {month}, {day}, {hour}, 赋予0值") + if mpst: + exp_str2 = exp_str2.replace(f"{{{match}}}", str(mpst.val)) try: rval = eval(exp_str2) except Exception as e: diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index dd37ee7e..51f0b1b7 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -208,6 +208,20 @@ def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: in else: return ms, _ = MpointStat.safe_get_or_create(**params) + ms.val_origin = val + need_cal_co = False + if ms.current_cal_coefficient is None and mpoint.cal_coefficient is not None: + ms.current_cal_coefficient = mpoint.cal_coefficient + need_cal_co = True + elif ms.current_cal_coefficient is not None: + need_cal_co = True + + if need_cal_co: + if mpoint.cal_coefficient_method == 1: + val = val * ms.current_cal_coefficient + elif mpoint.cal_coefficient_method == 2: + val = val / ms.current_cal_coefficient + # 如果有correct直接用correct代替 ms.val = ms.val_correct if ms.val_correct is not None else val if material_code == 'elec': val_level = get_elec_level(month, hour)