tangxu
2024-04-24 1c5fa983ae3506c2edaa88c51a959d46685c1ba1
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using DevExpress.Emf;
using DevExpress.XtraTreeList;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.WinFrmUI.Monitor
{
    public class HistoryDataHelper
    {
        public HistoryDataHelper(DateTime dateTime, double water, double electricity, string pump1,string pump2 ,string pump3
            ,string pump4, string pump5)
        {
           this.DateTime = dateTime;
            this.water = water;
            this.electricity = electricity;
            this.pump1 = pump1;
            this.pump2 = pump2;
            this.pump3 = pump3;
            this.pump4 = pump4;
            this.pump5 = pump5;
            //timesspan = new span();
        }
 
        public HistoryDataHelper() { }
        /// <summary>
        /// 时间
        /// </summary>
        public DateTime DateTime { get; set; }
        /// <summary>
        /// 用水量
        /// </summary>
        public double water { get; set; }
        /// <summary>
        /// 用电量
        /// </summary>
        public double electricity { get; set; }
        /// <summary>
 
        public string pump1 { get; set; }
        public string pump2 { get; set; }
        public string pump3 { get; set; }
        public string pump4 { get; set; }
        public string pump5 { get; set; }
 
        private List<HistoryDataHelper> _historyDataHelpers = new List<HistoryDataHelper>();
        public List<HistoryDataHelper> GetHistoryData()
        {
            string path = System.IO.Path.Combine(IStation.DataFolderHelper.GetRootPath(),
                "二取机泵参数", "二取参数.csv");
            if (!File.Exists(path))
                return  null;
            int totalLines = File.ReadLines(path, Encoding.GetEncoding("gb2312")).Count();//总行数
            System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
            System.IO.StreamReader sr = new System.IO.StreamReader(fs, Encoding.GetEncoding("gb2312"));
            string tempText;
            int line = 0;
            while ((tempText = sr.ReadLine()) != null)
            {
                line++;
                string[] arr = tempText.Split(new char[] { ',' });
                //一般第一行为标题,所以取出来作为标头
                    _historyDataHelpers.Add(new HistoryDataHelper(Convert.ToDateTime(arr[0]), Convert.ToDouble(arr[1]), Convert.ToDouble(arr[2]), arr[3], arr[4], arr[5], arr[6], arr[7]));
            }
 
            //关闭流
            sr.Close(); fs.Close();
           // List<HistoryModel> historyModels= GetDataModel();
            return _historyDataHelpers;
        }
 
        HistoryModel historyModel = new HistoryModel();
         List<HistoryModel> historyModels = new List<HistoryModel>();    
        List<span> timespan1List = new List<span>();
        List<span> timespan2List = new List<span>();
        List<span> timespan3List = new List<span>();
        List<span> timespan4List = new List<span>();
        List<span> timespan5List = new List<span>();
        public List<HistoryModel> GetDataModel( List< HistoryDataHelper> historyDataHelper)
        {
            foreach (var item in historyDataHelper)
            {
                string[] arr = item.pump1.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var itm in arr)
                {
                    string[] time = itm.Split(new char[] { '~' });
                    if (time.Length > 1)
                        timespan1List.Add(new span { StartTime = time[0], EndTime = time[1] });
                }
                string[] arr2 = item.pump2.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var itm in arr2)
                {
                    string[] time = itm.Split(new char[] { '~' });
                    if (time.Length > 1)
                        timespan2List.Add(new span { StartTime = time[0], EndTime = time[1] });
                }
                string[] arr3 = item.pump3.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var itm in arr3)
                {
                    string[] time = itm.Split(new char[] { '~' });
                    if (time.Length > 1)
                        timespan3List.Add(new span { StartTime = time[0], EndTime = time[1] });
                }
                string[] arr4 = item.pump4.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var itm in arr4)
                {
                    string[] time = itm.Split(new char[] { '~' });
                    if (time.Length > 1)
                        timespan4List.Add(new span { StartTime = time[0], EndTime = time[1] });
                }
                string[] arr5 = item.pump5.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var itm in arr5)
                {
                    string[] time = itm.Split(new char[] { '~' });
                    if (time.Length > 1)
                        timespan5List.Add(new span { StartTime = time[0], EndTime = time[1] });
                }
                historyModel = new HistoryModel
                    {
                        DateTime = item.DateTime,
                        water = item.water,
                        timespan1=timespan1List,
                        timespan2=timespan2List,
                        timespan3 = timespan3List,
                        timespan4 = timespan4List,
                        timespan5 = timespan5List,
                };
                historyModels.Add(historyModel);
                timespan1List = new List<span>();
                timespan2List = new List<span>();
                timespan3List = new List<span>();
                timespan4List = new List<span>();
                timespan5List = new List<span>();
            }
            return historyModels;
        }
 
 
 
    } 
 
            
}
 
 
 
 
 
 
 
/*        private List<string> GetData( List<Ontime> result,string name)
        {
            List<string> onTime = new List<string>();
            onTime.Clear();
            List<string> timeList = new List<string>();
            string StartTime = null;
            string EndTime = null;
            string Time = null;
            for (int day = 0; day < result.Count(); day += 288)  //最外层循环 控制一天一天的循环
            {
                bool allZero = true;
                for (int time = day; time < day + 288 && time < result.Count; time++)  //内层循环,在当天每个时间进行循环
                {
                    if (result[time].state == 1)
                    {
                        allZero = false;
                        StartTime = result[time].DateTime.ToString("HH:mm");
                        EndTime = result[time].DateTime.ToString("HH:mm");
                        for (int k = time + 1; k < day + 288 && k < result.Count; k++)   //k为从开机后比较的变量下标
                        {
                            if (result[k].state ==1)
                            {
                                EndTime = result[k].DateTime.ToString("HH:mm");
                                time = k;
                            }
                            else break;
                        }
                        Time = $"{name}:{StartTime}~{EndTime}";
                        timeList.Add(Time);
                    }
                }
                if (allZero)   //如果一天都没有开泵,就添加一条空
                {
                    timeList.Add(null);
                }
                var connect = string.Join($"\n", timeList);  //把一天中可能有好几条的list添加到一个list
                onTime.Add(connect);
                timeList.Clear();
              *//*  StartTime = null;*/