From 9d5d7eceaf66b0e002ddc0013bdd8a7b4b236f8a Mon Sep 17 00:00:00 2001 From: zty Date: Thu, 14 Nov 2024 17:48:48 +0800 Subject: [PATCH 1/2] fix : tkx enm bug fix --- .../0047_enstat2_cliker_price_cost.py | 18 ++++++++++++++++++ apps/enm/models.py | 1 + apps/enm/services.py | 18 +++++++++++++----- apps/enm/tasks.py | 16 ++++++++-------- 4 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 apps/enm/migrations/0047_enstat2_cliker_price_cost.py diff --git a/apps/enm/migrations/0047_enstat2_cliker_price_cost.py b/apps/enm/migrations/0047_enstat2_cliker_price_cost.py new file mode 100644 index 00000000..8c43328e --- /dev/null +++ b/apps/enm/migrations/0047_enstat2_cliker_price_cost.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.12 on 2024-11-14 02:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('enm', '0046_auto_20241010_1140'), + ] + + operations = [ + migrations.AddField( + model_name='enstat2', + name='cliker_price_cost', + field=models.FloatField(default=0, verbose_name='出窑熟料成本'), + ), + ] diff --git a/apps/enm/models.py b/apps/enm/models.py index 6c4dba69..edd1abf9 100644 --- a/apps/enm/models.py +++ b/apps/enm/models.py @@ -178,6 +178,7 @@ class EnStat2(BaseModel): bag_cement_price = models.FloatField("袋装水泥价格", default=0) clinker_val = models.FloatField("出窑熟料产量", default=0) clinker_price = models.FloatField("出窑熟料价格", default=0) + cliker_price_cost = models.FloatField("出窑熟料成本", default=0) bulk_clinker_val = models.FloatField("散装熟料出厂量", default=0) bulk_clinker_price = models.FloatField("散装熟料价格", default=0) cement_val = models.FloatField("出磨水泥产量", default=0) diff --git a/apps/enm/services.py b/apps/enm/services.py index f513728b..bb3be7ad 100644 --- a/apps/enm/services.py +++ b/apps/enm/services.py @@ -37,6 +37,10 @@ def translate_eval_formula(exp_str: str, year: int, month: int, day: int, hour: exp_str2 = exp_str2.replace(f"{{{match}}}", str(get_sysconfig(f"enm.{match}"))) else: mpst = MpointStat.objects.filter(mpoint__code=match, type="hour", year=year, month=month, day=day, hour=hour).first() + if mpst is None: + mpoint = Mpoint.objects.get(code=match) + mpst, _ = MpointStat.objects.get_or_create(mpoint=mpoint, type="hour", year=year, month=month, day=day, hour=hour, defaults={"val": 0}) + myLogger.error(f"找不到该测点的时间线数据: {match}, {year}, {month}, {day}, {hour}, 赋予0值") if mpst: exp_str2 = exp_str2.replace(f"{{{match}}}", str(mpst.val)) try: @@ -435,16 +439,19 @@ def get_analyse_data_mgroups_duration(start_date: datetime, end_date: datetime) """ start_year, start_month, start_day = start_date.year, start_date.month, start_date.day end_year, end_month, end_day = end_date.year, end_date.month, end_date.day - total_sec = (end_date - start_date).total_seconds() + 3600 * 24 + # total_sec = (end_date - start_date).total_seconds() + 3600 * 24 qs = ( - EnStat.objects.filter(mgroup__cate="section") + EnStat.objects.filter(mgroup__cate="section", type="day_s") .filter(Q(year_s__gt=start_year) | Q(year_s=start_year, month_s__gt=start_month) | Q(year_s=start_year, month_s=start_month, day_s__gte=start_day)) .filter(Q(year_s__lt=end_year) | Q(year_s=end_year, month_s__lt=end_month) | Q(year_s=end_year, month_s=end_month, day_s__lte=end_day)) ) res = ( qs.values("mgroup", "mgroup__name") - .annotate(total_production=Sum("total_production"), run_sec=Sum("run_sec"), elec_consume=Sum("elec_consume"), pcoal_coal_consume=Sum("pcoal_coal_consume")) + .annotate(total_production=Sum("total_production"), + run_sec=Sum("run_sec"), elec_consume=Sum("elec_consume"), + pcoal_coal_consume=Sum("pcoal_coal_consume"), + total_sec_now=Sum("total_sec_now")) .order_by("mgroup__sort") ) res_dict = {} @@ -459,7 +466,7 @@ def get_analyse_data_mgroups_duration(start_date: datetime, end_date: datetime) item["production_hour"] = round(item["total_production"] * 3600 / item["run_sec"], 2) if item["run_sec"] > 0 else 0 item["elec_consume_unit"] = round(item["elec_consume"] / item["total_production"], 2) if item["total_production"] > 0 else 0 item["run_hour"] = round(item["run_sec"] / 3600, 2) if item["run_sec"] > 0 else 0 - item["run_rate"] = round(item["run_sec"] * 100 / total_sec, 4) if total_sec > 0 else 0 + item["run_rate"] = round(item["run_sec"] * 100 / item["total_sec_now"], 4) if item["total_sec_now"] > 0 else 0 item["coal_consume_unit"] = round(item["pcoal_coal_consume"] * 1000 / item["total_production"], 2) if item["total_production"] > 0 else 0 if item["mgroup_name"] == "回转窑": total_production_ylm = res_dict.get("原料磨", {}).get("total_production", 0) @@ -469,6 +476,7 @@ def get_analyse_data_mgroups_duration(start_date: datetime, end_date: datetime) item["celec_consume_unit"] = 0 item["en_consume_unit"] = 0 else: - item["celec_consume_unit"] = ((elec_consume_mm + item["elec_consume"]) / item["total_production"] + get_sysconfig("enm.enm_lhxs") * elec_consume_ylm / total_production_ylm, 2) + item["celec_consume_unit"] = round((elec_consume_mm + item["elec_consume"]) / item["total_production"] + get_sysconfig("enm.enm_lhxs") * elec_consume_ylm / total_production_ylm, 2) item["en_consume_unit"] = item["coal_consume_unit"] + 0.1229 * item["elec_consume_unit"] + item["total_production"] = round(item["total_production"], 2) return res \ No newline at end of file diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index bfd3c6e6..2536b001 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -472,7 +472,7 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s, elif mtype == "P_COST": # 如果是产量(用于计算成本) enstat.total_production_cost = amount_consume else: - if material.code in ["pcoal", "cair", "steam"]: + if material.code in ["cair", "steam"]: price_unit = 0 else: price_unit = get_price_unit(material, year_s, month_s) @@ -754,7 +754,9 @@ def cal_enstat2(type: str, year_s: int, month_s: int, day_s: int, cascade=True): res = EnStat.objects.filter(mgroup__product__code="clinker", 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="clinker", 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.cliker_price_cost = res["avg"] if res["avg"] else 0 enstat2.clinker_val = res["sum"] if res["sum"] else 0 # 出厂总产量 @@ -762,15 +764,14 @@ def cal_enstat2(type: str, year_s: int, month_s: int, day_s: int, cascade=True): 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_val = enstat2.bag_cement_val + enstat2.bulk_cement_val + enstat2.bulk_clinker_val - enstat2.industry_add_val = enstat2.industry_total_val - enstat2.cement_val * enstat2.cement_cost_unit / 10000 + enstat2.industry_add_val = enstat2.industry_total_val - enstat2.out_cement_val * enstat2.cement_cost_unit / 10000 - enstat2.bulk_clinker_val*enstat2.cliker_price_cost / 10000 # 全厂电量 # 全厂的耗电量得单独处理 @@ -787,14 +788,13 @@ def cal_enstat2(type: str, year_s: int, month_s: int, day_s: int, cascade=True): ) if use_mpoint_elec_val: if type == 'day_s': - enstat2.elec_consume = MpointStat.objects.filter(type='day_s', mpoint__in=mp_elecs, year=year_s, month=month_s, day=day_s).aggregate(sum=Sum("val"))['sum'] + enstat2.elec_consume = MpointStat.objects.filter(type='day_s', mpoint__in=mp_elecs, year_s=year_s, month_s=month_s, day_s=day_s).aggregate(sum=Sum("val"))['sum'] elif type == 'month_s': - enstat2.elec_consume = MpointStat.objects.filter(type='month_s', mpoint__in=mp_elecs, year=year_s, month=month_s).aggregate(sum=Sum("val"))['sum'] + enstat2.elec_consume = MpointStat.objects.filter(type='month_s', mpoint__in=mp_elecs, year_s=year_s, month_s=month_s).aggregate(sum=Sum("val"))['sum'] if enstat2.elec_consume is None: enstat2.elec_consume = 0 else: enstat2.elec_consume = res_elec_pcoal["sum1"] if res_elec_pcoal["sum1"] else 0 - enstat2.elec_coal_consume = enstat2.elec_consume * 0.1229 / 1000 # 其他的统计工段合就行 From c2cae12c4f7b186786cb1904ab7f6d8b58e3ec56 Mon Sep 17 00:00:00 2001 From: zty Date: Mon, 18 Nov 2024 09:34:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:enm/service=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=B0=8F=E6=95=B0=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/services.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/enm/services.py b/apps/enm/services.py index bb3be7ad..29e319be 100644 --- a/apps/enm/services.py +++ b/apps/enm/services.py @@ -466,7 +466,7 @@ def get_analyse_data_mgroups_duration(start_date: datetime, end_date: datetime) item["production_hour"] = round(item["total_production"] * 3600 / item["run_sec"], 2) if item["run_sec"] > 0 else 0 item["elec_consume_unit"] = round(item["elec_consume"] / item["total_production"], 2) if item["total_production"] > 0 else 0 item["run_hour"] = round(item["run_sec"] / 3600, 2) if item["run_sec"] > 0 else 0 - item["run_rate"] = round(item["run_sec"] * 100 / item["total_sec_now"], 4) if item["total_sec_now"] > 0 else 0 + item["run_rate"] = round(item["run_sec"] * 100 / item["total_sec_now"], 2) if item["total_sec_now"] > 0 else 0 item["coal_consume_unit"] = round(item["pcoal_coal_consume"] * 1000 / item["total_production"], 2) if item["total_production"] > 0 else 0 if item["mgroup_name"] == "回转窑": total_production_ylm = res_dict.get("原料磨", {}).get("total_production", 0) @@ -477,6 +477,6 @@ def get_analyse_data_mgroups_duration(start_date: datetime, end_date: datetime) item["en_consume_unit"] = 0 else: item["celec_consume_unit"] = round((elec_consume_mm + item["elec_consume"]) / item["total_production"] + get_sysconfig("enm.enm_lhxs") * elec_consume_ylm / total_production_ylm, 2) - item["en_consume_unit"] = item["coal_consume_unit"] + 0.1229 * item["elec_consume_unit"] + item["en_consume_unit"] = round(item["coal_consume_unit"] + 0.1229 * item["elec_consume_unit"], 2) item["total_production"] = round(item["total_production"], 2) return res \ No newline at end of file