ningshuxia
2024-06-19 7e673fdd828d857fe1937150fa5f903c17708304
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
using Yw;
 
namespace IStation.Test
{
    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; 
        }
 
    }
}