Shuxia Ning
2024-07-26 19db3c68c67e27531e716567cefaa266e71a2baf
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
using IStation.Hydraulic;
using System.IO;
using Yw;
 
namespace IStation
{
    public class DayValueHelper
    {
 
        public static List<Hydraulic.DayValue> GetDayValues()
        { 
            var fileList = new List<string>(); 
            var folderPath1 = $"{AppDomain.CurrentDomain.BaseDirectory}Eapnet验证数据\\陈行一输";
            var folderPath2 = $"{AppDomain.CurrentDomain.BaseDirectory}Eapnet验证数据\\陈行二输";
            var fileList1 = Directory.GetFiles(folderPath1);
            var fileList2 = Directory.GetFiles(folderPath2);
            fileList.AddRange(fileList1);
            fileList.AddRange(fileList2); 
            
            var timeVlaueList=new List<TimeValue>();    
            foreach (var file in fileList)
            {
                var fileName = Path.GetFileNameWithoutExtension(file);
                if (!DateTime.TryParse(fileName, out DateTime day))
                    continue;
                var json = File.ReadAllText(file);
                var timeValues = JsonHelper.Json2Object<List<TimeValue>>(json);
                if (timeValues == null || !timeValues.Any())
                    continue;
                timeVlaueList.AddRange(timeValues);
            }
 
            if (timeVlaueList == null || !timeVlaueList.Any())
                return default;
            var dayValues = new List<IStation.Hydraulic.DayValue>();
            var timeVlaueDayGroups = timeVlaueList.GroupBy(x =>new { x.Time.Year,x.Time.Month,x.Time.Day});
            foreach (var day in timeVlaueDayGroups)
            { 
                var timeValueList = new List<IStation.Hydraulic.TimeValue>();
                var timeVlaueGroup=day.GroupBy(x=>x.Time.ToOADate());
                foreach (var tvItem in timeVlaueGroup)
                {
                    var t = DateTime.FromOADate(tvItem.Key);
                    var value = new Dictionary<string, double>();
                    foreach (var tv in tvItem)
                    {
                        foreach (var v in tv.Value)
                        {
                            value.Add(v.Key, v.Value);
                        }
                    }
 
                    var timeValue = new IStation.Hydraulic.TimeValue();
                    timeValue.Time = t;
                    timeValue.Value = value;
                    timeValueList.Add(timeValue);
                }
                
 
                var dv = new IStation.Hydraulic.DayValue();
                dv.Year = day.Key.Year;
                dv.Month = day.Key.Month;
                dv.Day = day.Key.Day;
                dv.TimeValueList = timeValueList;
                dayValues.Add(dv);
            }
 
            return dayValues; 
        }
 
 
        public static Hydraulic.DayValue GetDayValue(DateTime time)
        {
            var fileList = new List<string>();
            var folderPath1 = $"{AppDomain.CurrentDomain.BaseDirectory}Eapnet验证数据\\陈行一输";
            var folderPath2 = $"{AppDomain.CurrentDomain.BaseDirectory}Eapnet验证数据\\陈行二输";
            var fileList1 = Directory.GetFiles(folderPath1);
            var fileList2 = Directory.GetFiles(folderPath2);
            fileList.AddRange(fileList1);
            fileList.AddRange(fileList2);
 
            var time_value_list = new List<TimeValue>();
            var findFileNmae = time.ToString("");
            foreach (var file in fileList)
            {
                var fileName = Path.GetFileNameWithoutExtension(file);
                if (!DateTime.TryParse(fileName, out DateTime file_dt))
                    continue;
                if (file_dt.Year != time.Year || file_dt.Month != time.Month || file_dt.Day != time.Day)
                    continue;
 
                var json = File.ReadAllText(file);
                var timeValues = JsonHelper.Json2Object<List<TimeValue>>(json);
                if (timeValues == null || !timeValues.Any())
                    continue;
                time_value_list.AddRange(timeValues);
            }
 
            if (time_value_list == null || !time_value_list.Any())
                return default;
            var dayValue = new IStation.Hydraulic.DayValue();
            var timeVlaueDayGroups = time_value_list.GroupBy(x => new { x.Time.Year, x.Time.Month, x.Time.Day });
 
            var timeValueList = new List<IStation.Hydraulic.TimeValue>();
            var timeVlaueGroup = time_value_list.GroupBy(x => x.Time.ToOADate());
            foreach (var tvItem in timeVlaueGroup)
            {
                var t = DateTime.FromOADate(tvItem.Key);
                var value = new Dictionary<string, double>();
                foreach (var tv in tvItem)
                {
                    foreach (var v in tv.Value)
                    {
                        value.Add(v.Key, v.Value);
                    }
                }
 
                var timeValue = new IStation.Hydraulic.TimeValue();
                timeValue.Time = t;
                timeValue.Value = value;
                timeValueList.Add(timeValue);
            }
 
 
            dayValue.Year = time.Year;
            dayValue.Month = time.Month;
            dayValue.Day = time.Day;
            dayValue.TimeValueList = timeValueList;
 
            return dayValue;
        }
 
 
    }
}