From 8808a14ef2f39fe1ed42caf13d5cfecce8e5a8e7 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 4 Aug 2023 14:34:39 +0800 Subject: [PATCH] fix: translate_eval_formula bug --- apps/enm/services.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/enm/services.py b/apps/enm/services.py index 9ddc595f..4c2d33de 100644 --- a/apps/enm/services.py +++ b/apps/enm/services.py @@ -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)