tangxu
2023-04-10 7f8ba13a353ed3da5efbbbf623d586428f4bce96
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IStation.Untity;
 
namespace IStation.Application
{
    /// <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)
                {
                    if (normal_list.Exists(x => x.Qa.HasValue))
                    {
                        model.Qmin = normal_list.Where(x => x.Qa.HasValue).Min(x => x.Qa.Value);
                        model.Qmax = normal_list.Where(x => x.Qa.HasValue).Max(x => x.Qa.Value);
                        model.Qavg = normal_list.Where(x => x.Qa.HasValue).Average(x => x.Qa.Value);
                    }
                    if (normal_list.Exists(x => x.Ha.HasValue))
                    {
                        model.Hmin = normal_list.Where(x => x.Ha.HasValue).Min(x => x.Ha.Value);
                        model.Hmax = normal_list.Where(x => x.Ha.HasValue).Max(x => x.Ha.Value);
                        model.Havg = normal_list.Where(x => x.Ha.HasValue).Average(x => x.Ha.Value);
                    }
                    if (normal_list.Exists(x => x.Ea.HasValue))
                    {
                        model.Emin = normal_list.Where(x => x.Ea.HasValue).Min(x => x.Ea.Value);
                        model.Emax = normal_list.Where(x => x.Ea.HasValue).Max(x => x.Ea.Value);
                        model.Eavg = normal_list.Where(x => x.Ea.HasValue).Average(x => x.Ea.Value);
                    }
                    if (normal_list.Exists(x => x.Pa.HasValue))
                    {
                        model.Pmin = normal_list.Where(x => x.Pa.HasValue).Min(x => x.Pa.Value);
                        model.Pmax = normal_list.Where(x => x.Pa.HasValue).Max(x => x.Pa.Value);
                        model.Pavg = normal_list.Where(x => x.Pa.HasValue).Average(x => x.Pa.Value);
                    }
                    if (normal_list.Exists(x => x.WPa.HasValue))
                    {
                        model.WPmin = normal_list.Where(x => x.WPa.HasValue).Min(x => x.WPa.Value);
                        model.WPmax = normal_list.Where(x => x.WPa.HasValue).Max(x => x.WPa.Value);
                        model.WPavg = normal_list.Where(x => x.WPa.HasValue).Average(x => x.WPa.Value);
                    }
                    if (normal_list.Exists(x => x.UWPa.HasValue))
                    {
                        model.UWPmin = normal_list.Where(x => x.UWPa.HasValue).Min(x => x.UWPa.Value);
                        model.UWPmax = normal_list.Where(x => x.UWPa.HasValue).Max(x => x.UWPa.Value);
                        model.UWPavg = normal_list.Where(x => x.UWPa.HasValue).Average(x => x.UWPa.Value);
                    }
                }
                return model;
 
            }).ToList();
 
            return result;
 
        }
    }
}