This commit is contained in:
zty 2024-12-24 18:09:03 +08:00
commit 13c4fb6663
1 changed files with 83 additions and 28 deletions

View File

@ -619,13 +619,27 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
item['consume_unit'] = None
enstat.equip_elec_data = res
enstat.save()
# 开始计算互相影响的数据
if mgroup.name == "原料磨":
if enstat.type in ["hour_s", "day_s", "year_s", "month_s"]:
hzy_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="回转窑").first()
if hzy_enstat:
try:
hzy_enstat.celec_consume_unit = (hzy_enstat.elec_consume + enstat.elec_consume) / hzy_enstat.total_production
except ZeroDivisionError:
hzy_enstat.celec_consume_unit = 0
hzy_enstat.save()
if enstat.mgroup.name == "回转窑": # 算单位产品(综合电耗/标煤耗/综合能耗)
# 综合电耗
if enstat.type in ["hour_s", "day_s", "year_s", "month_s"]:
pre_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="原料磨").first()
ylm_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="原料磨").first()
if ylm_enstat:
try:
enstat.celec_consume_unit = (enstat.elec_consume + ylm_enstat.elec_consume)/enstat.total_production
except ZeroDivisionError:
enstat.celec_consume_unit = 0
enstat.save()
# pre_enstat2 = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="煤磨").first()
if pre_enstat:
enstat.celec_consume_unit = (enstat.elec_consume + pre_enstat.elec_consume)/enstat.total_production
# if pre_enstat2:
# try:
# pre_enstat2.production_elec_consume_unit = pre_enstat2.elec_consume / enstat.total_production
@ -633,8 +647,7 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
# pre_enstat2.production_elec_consume_unit = 0
# pre_enstat2.save(update_fields=["production_elec_consume_unit"])
# enstat.celec_consume_unit += pre_enstat2.production_elec_consume_unit
enstat.save()
# 算总煤耗
# 算标煤耗
if "pcoal" in this_cal_attrs:
if type in ["hour_s", "sflog", "day_s"]:
enstat.pcoal_heat = get_pcoal_heat(enstat.year_s, enstat.month_s, enstat.day_s)
@ -650,39 +663,70 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
if enstat.pcoal_coal_consume is None:
enstat.pcoal_coal_consume = 0
# 加柴油消耗量 todo
oil_consume = enstat.imaterial_data_dict.get("柴油", {}).get("amount_consume", 0)
# 算单位产品标煤耗
try:
enstat.coal_consume_unit = enstat.pcoal_coal_consume * 1000 / enstat.total_production
enstat.coal_consume_unit = (enstat.pcoal_coal_consume + oil_consume*1.46) * 1000 / enstat.total_production
except ZeroDivisionError:
enstat.coal_consume_unit = 0
# 综合能耗
enstat.cen_consume_unit = enstat.coal_consume_unit + 0.1229 * enstat.elec_consume_unit
enstat.save()
elif enstat.mgroup.name == "水泥包装" and enstat.type not in ["month_st", "sflog"] and "pcoal" in this_cal_attrs:
# 触发水泥磨综合能耗
snm_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="水泥磨").first()
if snm_enstat:
hzy_enstat = enstat
snbz_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="水泥包装").first()
snbz_enstat_elec_consume = snbz_enstat.elec_consume if snbz_enstat else 0
hzy_enstat_cen_consume_unit = hzy_enstat.cen_consume_unit if hzy_enstat else 0
if snm_enstat.total_production == 0:
snm_enstat_cen_consume_unit = 0
else:
slpb = snm_enstat.imaterial_data_dict.get("入磨熟料", {}).get("amount_consume", 0) / snm_enstat.total_production
snm_enstat_cen_consume_unit = ((snm_enstat.elec_consume + snbz_enstat_elec_consume)/snm_enstat.total_production) * 0.1229 + slpb * hzy_enstat_cen_consume_unit
snm_enstat.cen_consume_unit = snm_enstat_cen_consume_unit
snm_enstat.save()
elif enstat.mgroup.name == "水泥磨" and enstat.type not in ["month_st", "sflog"] and "pcoal" in this_cal_attrs:
hzy_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="回转窑").first()
snm_enstat = enstat
snbz_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="水泥包装").first()
snbz_enstat_elec_consume = snbz_enstat.elec_consume if snbz_enstat else 0
hzy_enstat_cen_consume_unit = hzy_enstat.cen_consume_unit if hzy_enstat else 0
if snm_enstat.total_production == 0:
snm_enstat_cen_consume_unit = 0
else:
slpb = snm_enstat.imaterial_data_dict.get("入磨熟料", {}).get("amount_consume", 0) / snm_enstat.total_production
snm_enstat_cen_consume_unit = ((snm_enstat.elec_consume + snbz_enstat_elec_consume)/snm_enstat.total_production) * 0.1229 + slpb * hzy_enstat_cen_consume_unit
snm_enstat.cen_consume_unit = snm_enstat_cen_consume_unit
snm_enstat.save()
elif enstat.mgroup.name == "水泥包装" and enstat.type not in ["month_st", "sflog"] and "pcoal" in this_cal_attrs:
snm_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="水泥磨").first()
if snm_enstat:
# 综合能耗
# 熟料配比 用 入磨熟料/水泥磨产量 todo
snm_enstat.cen_consume_unit = ((snm_enstat.elec_consume + enstat.elec_consume)/snm_enstat.total_production) * 0.1229 + 0.7 * hzy_enstat.cen_consume_unit
hzy_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="回转窑").first()
snbz_enstat = enstat
snbz_enstat_elec_consume = snbz_enstat.elec_consume if snbz_enstat else 0
hzy_enstat_cen_consume_unit = hzy_enstat.cen_consume_unit if hzy_enstat else 0
if snm_enstat.total_production == 0:
snm_enstat_cen_consume_unit = 0
else:
slpb = snm_enstat.imaterial_data_dict.get("入磨熟料", {}).get("amount_consume", 0) / snm_enstat.total_production
snm_enstat_cen_consume_unit = ((snm_enstat.elec_consume + snbz_enstat_elec_consume)/snm_enstat.total_production) * 0.1229 + slpb * hzy_enstat_cen_consume_unit
snm_enstat.cen_consume_unit = snm_enstat_cen_consume_unit
snm_enstat.save()
elif enstat.mgroup.name == '余热发电':
pre_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="回转窑").first()
if pre_enstat:
hzy_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="回转窑").first()
if hzy_enstat:
# 吨熟料发电量
try:
enstat.production_elec_unit = enstat.total_production / pre_enstat.total_production
enstat.save()
enstat.production_elec_unit = enstat.total_production / hzy_enstat.total_production
except ZeroDivisionError:
enstat.production_elec_unit = 0
enstat.save()
enstat.save()
# 运转时长相关
if type != "hour_s" and "run_hour" in this_cal_attrs:
enstat.total_sec_now, enstat.shut_sec = get_total_sec_now_and_shut_sec(enstat)
@ -696,7 +740,6 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
except ZeroDivisionError:
enstat.production_hour = 0
enstat.save()
enstat.save()
return year_s, month_s, day_s # 返回这个值主要为了全厂数据计算而用
@ -888,23 +931,35 @@ def cal_enstat_pcoal_change(enstat: EnStat, new_pcoal_heat):
if enstat.pcoal_coal_consume is None:
enstat.pcoal_coal_consume = 0
oil_consume = enstat.imaterial_data_dict.get("柴油", {}).get("amount_consume", 0)
# 算单位产品标煤耗
try:
enstat.coal_consume_unit = enstat.pcoal_coal_consume * 1000 / enstat.total_production
enstat.coal_consume_unit = (enstat.pcoal_coal_consume + oil_consume*1.46) * 1000 / enstat.total_production
except ZeroDivisionError:
enstat.coal_consume_unit = 0
# 综合能耗
enstat.cen_consume_unit = enstat.coal_consume_unit + 0.1229 * enstat.elec_consume_unit
# enstat.save()
enstat.save(update_fields=["pcoal_heat", "pcoal_coal_consume", "coal_consume_unit", "cen_consume_unit"])
# 同步更新水泥磨的综合能耗,这步有可能不成功,因为水泥磨是后算的, 但是当pcoal_change时这个就有用了
if type not in ["month_st", "sflog"]:
next_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="水泥磨").first()
if next_enstat:
next_enstat.cen_consume_unit = next_enstat.elec_consume_unit * 0.1229 + 0.7 * enstat.cen_consume_unit
next_enstat.save(update_fields=["cen_consume_unit"])
snm_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="水泥磨").first()
if snm_enstat:
hzy_enstat = enstat
snbz_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="水泥包装").first()
snbz_enstat_elec_consume = snbz_enstat.elec_consume if snbz_enstat else 0
hzy_enstat_cen_consume_unit = hzy_enstat.cen_consume_unit if hzy_enstat else 0
if snm_enstat.total_production == 0:
snm_enstat_cen_consume_unit = 0
else:
slpb = snm_enstat.imaterial_data_dict.get("入磨熟料", {}).get("amount_consume", 0) / snm_enstat.total_production
snm_enstat_cen_consume_unit = ((snm_enstat.elec_consume + snbz_enstat_elec_consume)/snm_enstat.total_production) * 0.1229 + slpb * hzy_enstat_cen_consume_unit
snm_enstat.cen_consume_unit = snm_enstat_cen_consume_unit
snm_enstat.save()
enm_alarms_list = [