feat: 优化mpointstat计算点选择
This commit is contained in:
parent
32a1cd08d0
commit
a26656109c
|
@ -103,7 +103,9 @@ def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: in
|
|||
"""
|
||||
mpoint = Mpoint.objects.get(id=mpointId)
|
||||
mytz = tz.gettz(settings.TIME_ZONE)
|
||||
dt = datetime.datetime(year=year, month=month, day=day, hour=hour, tzinfo=mytz)
|
||||
dt = datetime.datetime(year=year, month=month, day=day, hour=hour, minute=0, second=0, tzinfo=mytz)
|
||||
dt_hour_p= dt - datetime.timedelta(hours=1)
|
||||
dt_hour_n= dt + datetime.timedelta(hours=1)
|
||||
if mpoint.material and mpoint.val_type in ['float', 'int']: # 如果计量的是物料 # 累计量 有的会清零,需要额外处理(还未做)
|
||||
params = {"mpoint": mpoint, "type": "hour"}
|
||||
params["year"], params["month"], params["day"], params["hour"] = year, month, day, hour
|
||||
|
@ -117,10 +119,11 @@ def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: in
|
|||
myLogger.error("公式执行错误:{}-{}".format(mpoint.id, formula), exc_info=True)
|
||||
return
|
||||
else:
|
||||
mrs = MpLogx.objects.filter(mpoint=mpoint, timex__year=params["year"], timex__month=params["month"], timex__day=params["day"], timex__hour=params["hour"]).order_by("timex")
|
||||
if mrs.exists():
|
||||
mrs0 = MpLogx.objects.filter(mpoint=mpoint, timex__gte=dt_hour_p, timex__lte=dt).order_by("timex")
|
||||
mrs = MpLogx.objects.filter(mpoint=mpoint, timex__gte=dt, timex__lte=dt_hour_n).order_by("timex")
|
||||
if mrs0.exists() and mrs.exists():
|
||||
last_val = getattr(mrs.last(), f'val_{val_type}')
|
||||
first_val = getattr(mrs.first(), f'val_{val_type}')
|
||||
first_val = getattr(mrs0.last(), f'val_{val_type}')
|
||||
if last_val >= first_val:
|
||||
val = last_val - first_val
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue