From 836c2a2baf97e4f6f74b9adedd4d4973917a3297 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 29 Apr 2024 17:29:04 +0800 Subject: [PATCH] fix: translate_eval_formula bug2 --- apps/enm/services.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/enm/services.py b/apps/enm/services.py index 9a68e374..52af8419 100644 --- a/apps/enm/services.py +++ b/apps/enm/services.py @@ -27,10 +27,8 @@ def translate_eval_formula(exp_str: str, year: int, month: int, day: int, hour: matches = re.findall(pattern, exp_str) for match in matches: mpst = MpointStat.objects.filter(Q(mpoint__id=match) | Q(mpoint__name=match) | Q(mpoint__code=match), type="hour", year=year, month=month, day=day, hour=hour).first() - val = 0 if mpst: - val = mpst.val - exp_str = exp_str.replace(f"${{{match}}}", str(val)) + exp_str = exp_str.replace(f"${{{match}}}", str(mpst.val)) rval = eval(exp_str) return rval