fix: ZeroDivisionError 时要把属性值反设为0
This commit is contained in:
parent
7c087024c9
commit
295a971000
|
@ -494,7 +494,7 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
|
|||
try:
|
||||
enstat.coal_consume_unit = enstat.pcoal_coal_consume / enstat.total_production
|
||||
except ZeroDivisionError:
|
||||
pass
|
||||
enstat.coal_consume_unit = 0
|
||||
|
||||
# 综合能耗
|
||||
enstat.cen_consume_unit = enstat.coal_consume_unit + 0.1229 * enstat.elec_consume_unit
|
||||
|
@ -513,16 +513,20 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
|
|||
enstat.production_elec_unit = enstat.total_production / pre_enstat.total_production
|
||||
enstat.save()
|
||||
except ZeroDivisionError:
|
||||
pass
|
||||
enstat.production_elec_unit = 0
|
||||
enstat.save()
|
||||
# 运转时长相关
|
||||
if type != "hour_s" and "run_hour" in this_cal_attrs:
|
||||
enstat.total_hour_now, enstat.shut_hour = get_total_hour_now_and_shut_hour(enstat)
|
||||
enstat.run_hour = enstat.total_hour_now - enstat.shut_hour
|
||||
try:
|
||||
enstat.run_rate = (enstat.run_hour / enstat.total_hour_now) * 100
|
||||
except ZeroDivisionError:
|
||||
enstat.run_rate = 0
|
||||
try:
|
||||
enstat.production_hour = enstat.total_production / enstat.run_hour
|
||||
except ZeroDivisionError:
|
||||
pass
|
||||
enstat.production_hour = 0
|
||||
enstat.save()
|
||||
enstat.save()
|
||||
return year_s, month_s, day_s # 返回这个值主要为了全厂数据计算而用
|
||||
|
@ -654,11 +658,11 @@ def cal_enstat2(type: str, year_s: int, month_s: int, day_s: int, cascade=True):
|
|||
try:
|
||||
enstat2.en_consume_unit = enstat2.en_consume / enstat2.industry_total_val
|
||||
except ZeroDivisionError:
|
||||
pass
|
||||
enstat2.en_consume_unit = 0
|
||||
try:
|
||||
enstat2.en_add_consume_unit = enstat2.en_consume / enstat2.industry_add_val
|
||||
except ZeroDivisionError:
|
||||
pass
|
||||
enstat2.en_add_consume_unit = 0
|
||||
enstat2.save()
|
||||
|
||||
|
||||
|
@ -682,7 +686,7 @@ def cal_enstat_pcoal_change(enstat: EnStat, new_pcoal_heat):
|
|||
try:
|
||||
enstat.coal_consume_unit = enstat.pcoal_coal_consume / enstat.total_production
|
||||
except ZeroDivisionError:
|
||||
pass
|
||||
enstat.coal_consume_unit = 0
|
||||
|
||||
# 综合能耗
|
||||
enstat.cen_consume_unit = enstat.coal_consume_unit + 0.1229 * enstat.elec_consume_unit
|
||||
|
|
Loading…
Reference in New Issue