From 4cdc48e549b6528c1356faa25b826bc333ad0e34 Mon Sep 17 00:00:00 2001 From: zty Date: Fri, 16 Aug 2024 18:44:00 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20equip=5Felec=5Fdata=20=E8=AE=A1?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/tasks.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index ac6e204e..f2a25d14 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -546,10 +546,15 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s, enstat.save() # 计算一些其他数据 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__isnull=False).values( - "elec_consume_unit", equipment=F("mpoint__ep_monitored__id"), equipment_name=F("mpoint__ep_monitored__name") - ) - enstat.equip_elec_data = list(res) + 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 enstat.save() if enstat.mgroup.name == "回转窑": # 算单位产品(综合电耗/标煤耗/综合能耗) # 综合电耗 @@ -732,9 +737,9 @@ 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', 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=year_s, month=month_s, day=day_s).aggregate(sum=Sum("val"))['sum'] elif type == 'month_s': - enstat2.elec_consume = MpointStat.objects.filter(type='month', 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=year_s, month=month_s).aggregate(sum=Sum("val"))['sum'] if enstat2.elec_consume is None: enstat2.elec_consume = 0 else: From cbce4998d9e13450e84d97046e293d6012e2ff37 Mon Sep 17 00:00:00 2001 From: zty Date: Fri, 16 Aug 2024 18:44:30 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20mpoint=20stat=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=AD=9B=E9=80=89=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/enm/filters.py b/apps/enm/filters.py index cfc5a607..ef7bbdc1 100644 --- a/apps/enm/filters.py +++ b/apps/enm/filters.py @@ -12,7 +12,7 @@ class MpointStatFilter(filters.FilterSet): class Meta: model = MpointStat fields = { - "mpoint": ["exact"], + "mpoint": ["exact", "in"], "mgroup": ["exact"], "mgroup__name": ["exact"], "mpoint__mgroup": ["exact"], From 7a780ebd0d1c8c4a8241640676e9a9bebc7af868 Mon Sep 17 00:00:00 2001 From: zty Date: Fri, 16 Aug 2024 18:44:50 +0800 Subject: [PATCH 3/5] fix: set coefficient --- apps/enm/services.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/enm/services.py b/apps/enm/services.py index 0631d684..f5c234dc 100644 --- a/apps/enm/services.py +++ b/apps/enm/services.py @@ -177,10 +177,9 @@ class MpointCache: current_cache_val = self.data cache_key = self.cache_key last_data = current_cache_val["last_data"] - if last_val: - last_data["last_val"] = last_val*current_cache_val.get('coefficient', 1.0) - else: - last_data["last_val"] = last_val + if isinstance(last_val, (int, float)): + last_val = last_val*current_cache_val.get('coefficient', 1.0) + last_data["last_val"] = last_val last_data["last_timex"] = last_timex last_mrs = None # 设备状态信号 mpoint_is_rep_ep_running_state = current_cache_val["is_rep_ep_running_state"] From 62fb5aa54ccf23b8e261c12d04aac94068224757 Mon Sep 17 00:00:00 2001 From: zty Date: Fri, 16 Aug 2024 18:45:11 +0800 Subject: [PATCH 4/5] feat: sflog teamchange cal_quastat_sflog --- apps/wpm/serializers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index 7eec80ba..064b610e 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -136,7 +136,9 @@ class SfLogSerializer(CustomModelSerializer): AttLog.objects.get_or_create(sflog=instance, user=item.user, defaults={ 'sflog': instance, 'user': item.user, 'post': item.post, 'state': default_state, 'create_by': self.context['request'].user}) if mgroup.need_enm: + from apps.qm.tasks import cal_quastat_sflog cal_enstat_when_team_change.delay(instance.id) + cal_quastat_sflog.delay(instance.id) return instance def to_representation(self, instance): From c3b62f1831df95e51fcdc093b2f349bc1c587c9e Mon Sep 17 00:00:00 2001 From: zty Date: Fri, 16 Aug 2024 18:45:31 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20equip=5Felec=5Fdata=20=E8=AE=A1?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index f2a25d14..cb820e3e 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -546,7 +546,7 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s, enstat.save() # 计算一些其他数据 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( + res = MpointStat.objects.filter(type='sflog', year_s=year_s, month_s=month_s, sflog__team=enstat.team, mpoint__material__code='elec', mpoint__ep_monitored__isnull=False).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: