Shuxia Ning
2024-09-10 049f546f25cabfb5b08e29c54f49d61a544b0395
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
namespace IStation.Test.Init
{
    /// <summary>
    /// 分析系数辅助类
    /// </summary>
    public class AnalysisFactorHelper
    {
 
        private  static readonly string folderPath = $"{Settings.ParasHelper.LocalFile.DataFolderDirectory}\\变速修正数据";
        private static IStation.Service.AnalysisFactor _service_analysis_factor = new Service.AnalysisFactor();
 
        public static bool Ana()
        {
 
            var hz_and_head_diff_avg_dict1 = GetHzAndHeadDiffAvgDict1();
            var hz_and_head_diff_avg_dict2 = GetHzAndHeadDiffAvgDict2();
 
            var flag_list_dict1 = new Dictionary<int, List<Model.AnalysisFactor>>();
            foreach (var itme_flag in hz_and_head_diff_avg_dict1)
            {
                var flag = itme_flag.Key;
                flag_list_dict1.Add(flag, new List<Model.AnalysisFactor>());
                foreach (var item in itme_flag.Value)
                {
                    var model = new Model.AnalysisFactor();
                    model.Flag = flag;
                    model.Hz = (double)item.Key;
                    if (item.Value.HasValue)
                    {
                        model.SourceMode = 1;
                    }
                    model.HeadDeviation = item.Value;
                    model.Accuracy = 0;
                    flag_list_dict1[flag].Add(model);
                }
            }
 
            var flag_list_dict2 = new Dictionary<int,List<Model.AnalysisFactor>>();
            foreach (var itme_flag in hz_and_head_diff_avg_dict2)
            {
                var flag = itme_flag.Key;
                flag_list_dict2.Add(flag, new List<Model.AnalysisFactor>());
                foreach (var item in itme_flag.Value)
                {
                    var model = new Model.AnalysisFactor();
                    model.Flag = itme_flag.Key;
                    model.Hz = (double)item.Key;
                    if (item.Value.HasValue)
                    {
                        model.SourceMode = 1;
                    }
                    model.HeadDeviation = item.Value;
                    model.Accuracy = 0;
                    flag_list_dict2[flag].Add(model);
                }
            }
 
            foreach (var item in flag_list_dict2)
            {
                var flag = item.Key;
                var flag_list = item.Value;
                var flag_head_avg = flag_list.Average(x => x.HeadDeviation);
                var hz_list_dict = flag_list.GroupBy(x => Math.Round(x.Hz)).ToDictionary(x => x.Key, x => x.ToList());
                var hz_head_avg_dict = new Dictionary<int, double?>();
                for (int hz = 25; hz <= 50; hz += 1)
                { 
                    if (!hz_list_dict.ContainsKey(hz))
                        continue;
                    var hz_list = hz_list_dict[hz];
                    var hz_avg = hz_list.Average(x => x.HeadDeviation);
                    if (hz_avg == null)
                    {
                        hz_avg = flag_head_avg;
                    }
                    else
                    {
 
                    }
                    hz_head_avg_dict.Add(hz, hz_avg);
 
                }
 
                foreach (var item_hz_head_avg in hz_head_avg_dict)
                {
                    var hz = item_hz_head_avg.Key;
                    var avg= item_hz_head_avg.Value;
                    var hz_list = hz_list_dict[hz];
                    hz_list.ForEach(x =>
                    {
                        if (x.HeadDeviation == null)
                        {
                            x.HeadDeviation = avg;
                        }
                    });
                }
                 
 
            }
 
            var list1=flag_list_dict1.SelectMany(x=>x.Value);
            var list2=flag_list_dict2.SelectMany(x=>x.Value);
 
 
            var list = new List<Model.AnalysisFactor>();
            list.AddRange(list1);
            list.AddRange(list2);
            var bol = _service_analysis_factor.Inserts(list);
            if (!bol)
            {
                throw (new Exception("失败!"));
            }
            return bol;
        }
 
 
 
        private static decimal _hz_space = 0.1m;
  
        private static Dictionary<int, Dictionary<decimal, double?>> GetHzAndHeadDiffAvgDict1()
        {
            var flag_hz_adn_head_avg_dict_dict = new Dictionary<int, Dictionary<decimal, double?>>();
            var pumps = new IStation.Service.Station().Get().Station1;
            foreach (var item in pumps)
            {
                var dict = new Dictionary<decimal, double?>();
                for (decimal hz = 25; hz <= 50; hz = hz + _hz_space)
                {
                    dict.Add(hz, null);
                }
 
                flag_hz_adn_head_avg_dict_dict.Add(item.Flag, dict);
            }
 
            return flag_hz_adn_head_avg_dict_dict;
        }
 
        private static Dictionary<int, Dictionary<decimal, double?>> GetHzAndHeadDiffAvgDict2()
        {
            var file = folderPath + "\\" + "2.json";
            var json = File.ReadAllText(file);
 
            var flag_hz_adn_head_avg_dict_dict = Yw.JsonHelper.Json2Object<Dictionary<int, Dictionary<decimal, double?>>>(json);
            return flag_hz_adn_head_avg_dict_dict;
        }
 
 
         
 
 
    }
 
}