lixiaojun
2022-08-09 c7c696753fbe0b8ebf56eb6cfe584601a36c5fb2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IStation.Untity;
 
namespace IStation.Calculation
{
    /// <summary>
    /// 能效汇总多日辅助类
    /// </summary>
    public class EtaSumMultiDayHelper
    {
 
        /// <summary>
        /// 汇总
        /// </summary>
        public static List<Model.EtaSumMultiDayRecord> Sum
            (
                long CorpID,
                string ObjectType,
                long ObjectID,
                DateTime Day,
                IEnumerable<Model.EtaMultiRealRecord> list
            )
        {
            if (list == null || list.Count() < 1)
                return default;
            var run_list = list.Where(x =>x.RunningCount>0).ToList();
            if (run_list.Count < 1)
                return default;
 
            var group_list = run_list.GroupBy(x => new {
                    CorpID=x.CorpID,
                    ObjectType=x.ObjectType,
                    ObjectID=x.ObjectID,
                    RunningCount = x.RunningCount, 
                    RunningFlag =IntListHelper.ToString(x.RunningFlag)
                }).ToList();
 
            var result= group_list.Select(x => {
                var model = new Model.EtaSumMultiDayRecord();
                model.CorpID = CorpID;
                model.ObjectType = ObjectType;
                model.ObjectID = ObjectID;
                model.DataDay = Day.Date;
                model.DataTime = DateTime.Now;
                model.RunningCount = x.Key.RunningCount;
                model.RunningFlag = IntListHelper.ToList(x.Key.RunningFlag);
                model.Qt = x.Sum(t => (t.Qa ?? 0) * t.Duration) / 3600f;
                model.Dt = x.Sum(t => (t.Pa ?? 0) * t.Duration) / 3600f;
                model.RunTime = x.Sum(t => t.Duration);
                model.PointCount = x.Count();
 
                var normal_list = x.Where(x => x.AnalyStatus == Model.Eta.eAnalyStatus.Normal).ToList();
                if (normal_list.Count > 0)
                {
                    model.Qmin = normal_list.Min(x => x.Qa.Value);
                    model.Qmax = normal_list.Max(x => x.Qa.Value);
                    model.Qavg = normal_list.Average(x => x.Qa.Value);
 
                    model.Hmin = normal_list.Min(x => x.Ha.Value);
                    model.Hmax = normal_list.Max(x => x.Ha.Value);
                    model.Havg = normal_list.Average(x => x.Ha.Value);
 
                    model.Emin = normal_list.Min(x => x.Ea.Value);
                    model.Emax = normal_list.Max(x => x.Ea.Value);
                    model.Eavg = normal_list.Average(x => x.Ea.Value);
 
                    model.Pmin = normal_list.Min(x => x.Pa.Value);
                    model.Pmax = normal_list.Max(x => x.Pa.Value);
                    model.Pavg = normal_list.Average(x => x.Pa.Value);
 
                    model.WPmin = normal_list.Min(x => x.WPa.Value);
                    model.WPmax = normal_list.Max(x => x.WPa.Value);
                    model.WPavg = normal_list.Average(x => x.WPa.Value);
 
                    model.UWPmin = normal_list.Min(x => x.UWPa.Value);
                    model.UWPmax = normal_list.Max(x => x.UWPa.Value);
                    model.UWPavg = normal_list.Average(x => x.UWPa.Value);
                }
                return model;
 
            }).ToList();
 
            return result;
 
 
        }
    }
}