This commit is contained in:
caoqianming 2024-11-18 10:42:44 +08:00
commit e67bd892ae
4 changed files with 41 additions and 14 deletions

View File

@ -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='出窑熟料成本'),
),
]

View File

@ -178,6 +178,7 @@ class EnStat2(BaseModel):
bag_cement_price = models.FloatField("袋装水泥价格", default=0) bag_cement_price = models.FloatField("袋装水泥价格", default=0)
clinker_val = models.FloatField("出窑熟料产量", default=0) clinker_val = models.FloatField("出窑熟料产量", default=0)
clinker_price = 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_val = models.FloatField("散装熟料出厂量", default=0)
bulk_clinker_price = models.FloatField("散装熟料价格", default=0) bulk_clinker_price = models.FloatField("散装熟料价格", default=0)
cement_val = models.FloatField("出磨水泥产量", default=0) cement_val = models.FloatField("出磨水泥产量", default=0)

View File

@ -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}"))) exp_str2 = exp_str2.replace(f"{{{match}}}", str(get_sysconfig(f"enm.{match}")))
else: else:
mpst = MpointStat.objects.filter(mpoint__code=match, type="hour", year=year, month=month, day=day, hour=hour).first() 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: if mpst:
exp_str2 = exp_str2.replace(f"{{{match}}}", str(mpst.val)) exp_str2 = exp_str2.replace(f"{{{match}}}", str(mpst.val))
try: 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 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 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 = ( 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__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)) .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 = ( res = (
qs.values("mgroup", "mgroup__name") 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") .order_by("mgroup__sort")
) )
res_dict = {} 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["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["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_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"], 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 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"] == "回转窑": if item["mgroup_name"] == "回转窑":
total_production_ylm = res_dict.get("原料磨", {}).get("total_production", 0) 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["celec_consume_unit"] = 0
item["en_consume_unit"] = 0 item["en_consume_unit"] = 0
else: 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["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 return res

View File

@ -472,7 +472,7 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
elif mtype == "P_COST": # 如果是产量(用于计算成本) elif mtype == "P_COST": # 如果是产量(用于计算成本)
enstat.total_production_cost = amount_consume enstat.total_production_cost = amount_consume
else: else:
if material.code in ["pcoal", "cair", "steam"]: if material.code in ["cair", "steam"]:
price_unit = 0 price_unit = 0
else: else:
price_unit = get_price_unit(material, year_s, month_s) 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")) 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": 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")) 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 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")) 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": 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")) 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_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.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 use_mpoint_elec_val:
if type == 'day_s': 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': 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: if enstat2.elec_consume is None:
enstat2.elec_consume = 0 enstat2.elec_consume = 0
else: else:
enstat2.elec_consume = res_elec_pcoal["sum1"] if res_elec_pcoal["sum1"] else 0 enstat2.elec_consume = res_elec_pcoal["sum1"] if res_elec_pcoal["sum1"] else 0
enstat2.elec_coal_consume = enstat2.elec_consume * 0.1229 / 1000 enstat2.elec_coal_consume = enstat2.elec_consume * 0.1229 / 1000
# 其他的统计工段合就行 # 其他的统计工段合就行