refector: formular无需用$符号
This commit is contained in:
parent
5f67673c45
commit
1e8e4c6f70
|
@ -23,12 +23,12 @@ def translate_eval_formula(exp_str: str, year: int, month: int, day: int, hour:
|
|||
"""
|
||||
传入
|
||||
"""
|
||||
pattern = r"\${(.*?)}"
|
||||
pattern = r"\{(.*?)}"
|
||||
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()
|
||||
if mpst:
|
||||
exp_str = exp_str.replace(f"${{{match}}}", str(mpst.val))
|
||||
exp_str = exp_str.replace(f"{{{match}}}", str(mpst.val))
|
||||
rval = eval(exp_str)
|
||||
return rval
|
||||
|
||||
|
@ -38,7 +38,7 @@ def transfer_mpoint_val_to_ep_running_state(current_val, base_val: float, expr_s
|
|||
base_expr: 三元表达式
|
||||
"""
|
||||
if expr_str: # 优先使用表达式
|
||||
pattern = r"\${(.*?)}"
|
||||
pattern = r"\{(.*?)}"
|
||||
matches = re.findall(pattern, expr_str)
|
||||
for match in matches:
|
||||
if match == 'self':
|
||||
|
@ -46,7 +46,7 @@ def transfer_mpoint_val_to_ep_running_state(current_val, base_val: float, expr_s
|
|||
else:
|
||||
mpoint_data = get_mpoint_cache(match)
|
||||
if mpoint_data:
|
||||
expr_str = expr_str.replace(f"${{{match}}}", str(mpoint_data['last_data']['last_val']))
|
||||
expr_str = expr_str.replace(f"{{{match}}}", str(mpoint_data['last_data']['last_val']))
|
||||
rval = eval(expr_str)
|
||||
return rval
|
||||
if isinstance(current_val, bool):
|
||||
|
|
Loading…
Reference in New Issue