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;*/
|
|