Merge branch 'master' of https://e.coding.net/ctcdevteam/ehs/ehs_server
This commit is contained in:
commit
c00f59f8d9
|
@ -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"],
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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__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:
|
||||
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:
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue