feat: mpointstat增加elec_consume_unit及相应逻辑
This commit is contained in:
parent
ad30803836
commit
7bfea08a7d
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.2.12 on 2023-08-25 08:49
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('enm', '0020_auto_20230822_1758'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='mpointstat',
|
||||
name='elec_consume_unit',
|
||||
field=models.FloatField(default=0, help_text='kw·h/t', verbose_name='单位产品电耗'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='mpointstat',
|
||||
name='total_production',
|
||||
field=models.FloatField(default=0, help_text='t', verbose_name='总产量'),
|
||||
),
|
||||
]
|
|
@ -48,6 +48,8 @@ class MpointStat(CommonADModel):
|
|||
mgroup = models.ForeignKey(Mgroup, verbose_name='关联测点集', on_delete=models.CASCADE, null=True, blank=True)
|
||||
mpoint = models.ForeignKey(Mpoint, verbose_name='关联测点', on_delete=models.CASCADE)
|
||||
val = models.FloatField('统计值', default=0)
|
||||
total_production = models.FloatField('总产量', default=0, help_text='t')
|
||||
elec_consume_unit = models.FloatField('单位产品电耗', default=0, help_text='kw·h/t')
|
||||
|
||||
|
||||
class EnStat(BaseModel):
|
||||
|
|
|
@ -90,6 +90,15 @@ class MpointStatSerializer(CustomModelSerializer):
|
|||
# attrs['type'] = key
|
||||
return super().validate(attrs)
|
||||
|
||||
def to_representation(self, instance):
|
||||
ret = super().to_representation(instance)
|
||||
my_dic_keys = list(ret.keys())
|
||||
for key in my_dic_keys:
|
||||
ret_one_val = ret[key]
|
||||
if isinstance(ret_one_val, float):
|
||||
ret[key] = "{:.2f}".format(round(ret_one_val, 2))
|
||||
return ret
|
||||
|
||||
|
||||
class EnStatSerializer(CustomModelSerializer):
|
||||
mgroup_name = serializers.CharField(source='mgroup.name', read_only=True)
|
||||
|
|
|
@ -344,7 +344,9 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
|
|||
enstat.other_cost_data = other_cost_data
|
||||
enstat.production_cost_unit = imaterial_cost_unit + other_cost_unit
|
||||
enstat.save()
|
||||
|
||||
if enstat.total_production:
|
||||
MpointStat.objects.filter(mgroup=enstat.mgroup, mpoint__material__code='elec').exclude(ep_monitored=None).update(total_production=enstat.total_production,
|
||||
elec_consume_unit=F('val')/enstat.total_production)
|
||||
if enstat.mgroup.cate == 'section':
|
||||
if 'material' in this_cal_attrs:
|
||||
# 算能耗
|
||||
|
@ -355,16 +357,18 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
|
|||
pass
|
||||
enstat.save()
|
||||
# 计算一些其他数据
|
||||
if type == 'month_st' and 'material' in this_cal_attrs: # 如果计算的是班月,把主要设备电耗数据拉过来
|
||||
if type == 'month_st' and 'material' in this_cal_attrs: # 如果计算的是班月,把主要设备电耗数据拉过来, 方便查询
|
||||
# res = MpointStat.objects.filter(type='sflog', year_s=year_s, month_s=month_s, sflog__team=enstat.team, mpoint__ep_monitored__power_kw__gte=100).values(
|
||||
# equipment=F('mpoint__ep_monitored__id'), equipment_name=F('mpoint__ep_monitored__name')).annotate(consume=Sum('val'))
|
||||
# res = list(res)
|
||||
# for item in res:
|
||||
# try:
|
||||
# item['consume_unit'] = item['consume'] / enstat.total_production
|
||||
# except ZeroDivisionError:
|
||||
# item['consume_unit'] = None
|
||||
res = MpointStat.objects.filter(type='sflog', year_s=year_s, month_s=month_s, sflog__team=enstat.team, mpoint__ep_monitored__power_kw__gte=100).values(
|
||||
equipment=F('mpoint__ep_monitored__id'), equipment_name=F('mpoint__ep_monitored__name')).annotate(consume=Sum('val'))
|
||||
res = list(res)
|
||||
for item in res:
|
||||
try:
|
||||
item['consume_unit'] = item['consume'] / enstat.total_production
|
||||
except ZeroDivisionError:
|
||||
item['consume_unit'] = None
|
||||
enstat.equip_elec_data = res
|
||||
'elec_consume_unit', equipment=F('mpoint__ep_monitored__id'), equipment_name=F('mpoint__ep_monitored__name'))
|
||||
enstat.equip_elec_data = list(res)
|
||||
enstat.save()
|
||||
if enstat.mgroup.name == '回转窑': # 算单位产品(综合电耗/标煤耗/综合能耗)
|
||||
# 综合电耗
|
||||
|
|
Loading…
Reference in New Issue