using IStation.Model;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.IO;
|
using System.Linq;
|
|
namespace IStation.DAL
|
{
|
/// <summary>
|
/// 监测月数据集
|
/// </summary>
|
public partial class StationSignalRecordPacket
|
{
|
/// <summary>
|
/// 文件信息类
|
/// </summary>
|
private class FileInfo
|
{
|
public string FullName { get; set; }
|
public int Year { get; set; }
|
public int Month { get; set; }
|
public int TimeStep { get; set; }
|
public int RecordCount { get; set; }
|
}
|
|
#region FolderInfo
|
|
/// <summary>
|
/// 查询年月
|
/// </summary>
|
private bool GetYearMonth(string folderPath, out int year, out int month, out int timeStep, out int recordCount)
|
{
|
year = month = timeStep = recordCount = 0;
|
if (!File.Exists(folderPath))
|
return false;
|
|
var name = Path.GetFileNameWithoutExtension(folderPath);
|
var strList = name.Split(Settings.File.FileNameSpacer);
|
if (strList.Length != 4)
|
return false;
|
if (!int.TryParse(strList[0], out year))
|
{
|
return false;
|
}
|
if (!int.TryParse(strList[1], out month))
|
{
|
return false;
|
}
|
if (!int.TryParse(strList[2], out recordCount))
|
{
|
return false;
|
}
|
if (!int.TryParse(strList[3], out timeStep))
|
{
|
return false;
|
}
|
|
return true;
|
}
|
|
/// <summary>
|
/// 查询文件信息列表
|
/// </summary>
|
private List<FileInfo> GetStationSignalRecordPacketFileInfoList(string stationFolder)
|
{
|
if (!Directory.Exists(stationFolder))
|
return default;
|
var files = Directory.GetFiles(stationFolder);
|
if (files == null || files.Count() < 1)
|
return default;
|
|
var list = new List<FileInfo>(files.Count());
|
foreach (var file in files)
|
{
|
if (!GetYearMonth(file, out int year, out int month, out int timeStep, out int recordCount))
|
continue;
|
var info = new FileInfo
|
{
|
FullName = file,
|
Year = year,
|
Month = month,
|
TimeStep = timeStep,
|
RecordCount = recordCount
|
};
|
list.Add(info);
|
}
|
if (list.Count > 0)
|
{
|
list = list.OrderBy(x => x.Year).ThenBy(x => x.Month).ToList();
|
}
|
return list;
|
}
|
|
#endregion
|
|
|
#region CsvConvert
|
//To
|
private string ToDsString(Model.StationSignalRecord stationSignalRecord)
|
{
|
var line = $"{stationSignalRecord.Time:yyyy-MM-dd HH:mm:ss},{stationSignalRecord.PumpRunCount}";
|
for (int i = 0; i < stationSignalRecord.PumpSignalRecords.Count; i++)
|
{
|
var pumpSignalRecord = stationSignalRecord.PumpSignalRecords[i];
|
line += $",{pumpSignalRecord.EnginePumpID}" +
|
$",{pumpSignalRecord.RunStatus}" +
|
$",{pumpSignalRecord.Rpm}" +
|
$",{pumpSignalRecord.Frequency}" +
|
$",{pumpSignalRecord.FlowRate}" +
|
$",{pumpSignalRecord.TotalFlow}" +
|
$",{pumpSignalRecord.InletPressure}" +
|
$",{pumpSignalRecord.OutletPressure}" +
|
$",{pumpSignalRecord.InstantaneousPower}" +
|
$",{pumpSignalRecord.TotalActiveEnergy}";
|
}
|
return line;
|
}
|
|
//from
|
public Model.StationSignalRecord FromDsString(string dsString)
|
{
|
var strList = dsString.Split(',');
|
if (strList.Length < 2)
|
return default;
|
var model = new Model.StationSignalRecord
|
{
|
Time = DateTime.Parse(strList[0]),
|
PumpRunCount = int.Parse(strList[1]),
|
PumpSignalRecords = new List<PumpSignalRecord>()
|
};
|
for (int i = 0; i < model.PumpRunCount; i++)
|
{
|
var pumpSignalRecord = new Model.PumpSignalRecord();
|
var startIndex = i * 10 + 2;
|
if (!string.IsNullOrEmpty(strList[startIndex]))
|
pumpSignalRecord.EnginePumpID = long.Parse(strList[startIndex]);
|
startIndex++;
|
if (!string.IsNullOrEmpty(strList[startIndex]))
|
pumpSignalRecord.RunStatus = int.Parse(strList[startIndex]);
|
startIndex++;
|
if (!string.IsNullOrEmpty(strList[startIndex]))
|
pumpSignalRecord.Rpm = double.Parse(strList[startIndex]);
|
startIndex++;
|
if (!string.IsNullOrEmpty(strList[startIndex]))
|
pumpSignalRecord.Frequency = double.Parse(strList[startIndex]);
|
startIndex++;
|
if (!string.IsNullOrEmpty(strList[startIndex]))
|
pumpSignalRecord.FlowRate = double.Parse(strList[startIndex]);
|
startIndex++;
|
if (!string.IsNullOrEmpty(strList[startIndex]))
|
pumpSignalRecord.TotalFlow = double.Parse(strList[startIndex]);
|
startIndex++;
|
if (!string.IsNullOrEmpty(strList[startIndex]))
|
pumpSignalRecord.InletPressure = double.Parse(strList[startIndex]);
|
startIndex++;
|
if (!string.IsNullOrEmpty(strList[startIndex]))
|
pumpSignalRecord.OutletPressure = double.Parse(strList[startIndex]);
|
startIndex++;
|
if (!string.IsNullOrEmpty(strList[startIndex]))
|
pumpSignalRecord.InstantaneousPower = double.Parse(strList[startIndex]);
|
startIndex++;
|
if (!string.IsNullOrEmpty(strList[startIndex]))
|
pumpSignalRecord.TotalActiveEnergy = double.Parse(strList[startIndex]);
|
model.PumpSignalRecords.Add(pumpSignalRecord);
|
}
|
return model;
|
}
|
#endregion
|
}
|
}
|