This commit is contained in:
caoqianming 2024-08-26 13:28:40 +08:00
commit 4739124cc8
2 changed files with 12 additions and 5 deletions

View File

@ -147,7 +147,7 @@ class EnStatSerializer(CustomModelSerializer):
equip_elec_data = ret.get("equip_elec_data", {})
if qua_data:
for item in qua_data:
ret[f'{item["material_name"]}_{item["testitem_name"]}_rate_pass'] = "{:.2f}".format(round(item["rate_pass"], 4))
ret[f'{item["material_name"]}_{item["testitem_name"].replace("-", "")}_rate_pass'] = "{:.2f}".format(round(item["rate_pass"], 4))
if equip_elec_data:
for item in equip_elec_data:
val = item.get("consume_unit", None)

View File

@ -135,6 +135,7 @@ def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: in
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
@ -142,7 +143,10 @@ def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: in
val_type = mpoint.val_type
if mpoint.type == Mpoint.MT_AUTO:
if mpoint.is_unit:
val = MpLogx.objects.filter(mpoint=mpoint, timex__gte=dt, timex__lt=dt_hour_n).aggregate(sum=Sum(f'val_{mpoint.val_type}'))["sum"] or 0
val = MpLogx.objects.filter(mpoint=mpoint, timex__gte=dt, timex__lt=dt_hour_n).aggregate(sum=Sum(f'val_{mpoint.val_type}'))["sum"]
if val is None:
val = 0
myLogger.info(str(val), "-------val")
else:
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")
@ -155,6 +159,8 @@ def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: in
# 这里判断有可能清零了
max_val = max(mrs.aggregate(max=Max(f'val_{val_type}'))["max"], first_val)
val = max_val - first_val + last_val
# if mpoint.code == 'x水泥+P.O42.5 散装':
elif mpoint.type == Mpoint.MT_COMPUTE and mpoint.formula:
formula = mpoint.formula
val = translate_eval_formula(formula, year, month, day, hour)
@ -727,6 +733,7 @@ def cal_enstat2(type: str, year_s: int, month_s: int, day_s: int, cascade=True):
res = EnStat.objects.filter(mgroup__product__code="cement", type="day_s", year_s=year_s, month_s=month_s, day_s=day_s).aggregate(sum=Sum("total_production"), avg=Avg("production_cost_unit"))
enstat2.cement_val = res["sum"] if res["sum"] else 0
enstat2.cement_cost_unit = res["avg"] if res["avg"] else 0
# 出窑熟料产量
if type == "month_s":
@ -736,20 +743,20 @@ def cal_enstat2(type: str, year_s: int, month_s: int, day_s: int, cascade=True):
enstat2.clinker_val = res["sum"] if res["sum"] else 0
# 出厂水泥产量
# 出厂产量
if type == "month_s":
res = EnStat.objects.filter(mgroup__product__code="out_cement", type="month_s", year_s=year_s, month_s=month_s).aggregate(sum=Sum("total_production"), avg=Avg("production_cost_unit"))
elif type == "day_s":
res = EnStat.objects.filter(mgroup__product__code="out_cement", type="day_s", year_s=year_s, month_s=month_s, day_s=day_s).aggregate(sum=Sum("total_production"), avg=Avg("production_cost_unit"))
enstat2.out_cement_val = res["sum"] if res["sum"] else 0
enstat2.out_cement_cost_unit = res["avg"] if res["avg"] else 0
# enstat2.out_cement_cost_unit = res["avg"] if res["avg"] else 0
# enstat2.out_cement_val = enstat2.bag_cement_val + enstat2.bulk_cement_val + enstat2.bulk_clinker_val
enstat2.industry_add_val = enstat2.industry_total_val - enstat2.out_cement_val * enstat2.out_cement_cost_unit / 10000
enstat2.industry_add_val = enstat2.industry_total_val - enstat2.cement_val * enstat2.cement_cost_unit / 10000
# 全厂电量
# 全厂的耗电量得单独处理