fix: transfer_mpoint_val_to_ep_running_state 对expr_str的replace

This commit is contained in:
caoqianming 2024-05-07 13:07:52 +08:00
parent 52fc0c6bd3
commit 25965c7072
1 changed files with 5 additions and 2 deletions

View File

@ -46,7 +46,10 @@ def transfer_mpoint_val_to_ep_running_state(current_val, base_val: float, expr_s
else:
mpoint_data = MpointCache(match).data
if mpoint_data:
expr_str = expr_str.replace(f"{{{match}}}", str(mpoint_data['last_data']['last_val'])) # 这个last_val可能不存在
match_val = 50
if mpoint_data.get('gather_state', -2) == 0: # 测点正常采集
match_val = mpoint_data['last_data']['last_mrs']
expr_str = expr_str.replace(f"{{{match}}}", str(match_val))
rval = eval(expr_str)
return rval
if isinstance(current_val, bool):
@ -136,7 +139,7 @@ class MpointCache:
except Exception:
return None
mpoint_data = MpointSerializer(instance=mpoint).data
mpoint_data['last_data'] = {'last_val': None, 'last_timex': None}
mpoint_data['last_data'] = {'last_val': None, 'last_timex': None, 'last_mrs': None} # 初始化
if update_mplogx:
now = timezone.now()
last_mplogx = MpLogx.objects.filter(mpoint=mpoint, timex__gte=now - timedelta(minutes=5)).order_by("-timex").first()