fix: translate_eval_formula bug

This commit is contained in:
caoqianming 2023-08-04 14:34:39 +08:00
parent 50a34a44bb
commit 8808a14ef2
1 changed files with 2 additions and 1 deletions

View File

@ -2,6 +2,7 @@ from apps.enm.models import Mpoint, MpointStat, EnStat
import re
import traceback
from apps.mtm.services import get_mgroup_goals
from django.db.models import Q
def translate_eval_formula(exp_str: str, year: int, month: int, day: int, hour: int):
@ -12,7 +13,7 @@ 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(type='hour', mpoint__id=match, year=year, month=month, day=day).first()
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()
if mpst:
exp_str = exp_str.replace(f"${{{match}}}", mpst.val)