using IStation.Model;
|
using System.Data;
|
using System.Text;
|
|
namespace IStation.Test
|
{
|
internal class Program
|
{
|
// 过滤无效数据
|
// 1输模型修正
|
// 2输数据修正
|
// 修正组合偏差
|
static void Main(string[] args)
|
{
|
Console.WriteLine("start");
|
//Station1Helper.Start(); //1 数据修正
|
//Station2Helper.Start(); //2 模型修正
|
// 3 python修正 ,目前有些数据问题还需要解决
|
//Completion(); //4 修正后相似换算修正
|
|
//StationCombineHelper.Start(1);// 5 组合偏差修正
|
//StationCombineHelper.Start(2);// 5 组合偏差修正
|
|
// AnalysisDeviation(); // 6 分析泵频谱系数
|
|
// 7
|
// Station2TotalFlowDiffHelper.Start();// 8 C# 导出数据 补全流量偏差 + python
|
|
|
//test
|
|
StationTotalFlowPressureHelper.Start();
|
Console.WriteLine();
|
Console.WriteLine("ok");
|
Console.ReadKey();
|
|
}
|
|
public static void AnalysisDeviation()
|
{
|
var fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pumpcombine");
|
var fileNameList = Directory.GetFiles(fullPath).Select(x => x).ToList();
|
if (fileNameList == null || fileNameList.Count < 1)
|
return;
|
|
var stationDict = new Dictionary<int, long>
|
{
|
{ 1, 462958406303813 },
|
{ 2, 462958422204485 }
|
};
|
|
var bllEquipment = new IStation.BLL.Equipment();
|
var bllCurve = new IStation.BLL.PumpCurve();
|
var combineList = new List<ModelCombineViewModel>();
|
|
var minFlow = 0;
|
var maxFlow = 100000;
|
var spaceFlow = 100;
|
foreach (var fileName in fileNameList)
|
{
|
Console.WriteLine(Path.GetFileNameWithoutExtension(fileName) + ":Start");
|
var indexStr = Path.GetFileNameWithoutExtension(fileName).Substring(0, 1);
|
var index = int.Parse(indexStr);
|
var stationId = stationDict[index];
|
var pumpList = bllEquipment.GetPumpModelListByBelongTypeAndBelongID(IStation.ObjectType.Station, stationId);
|
var flagList = pumpList.Select(x => x.SortCode).OrderBy(x => x).ToList();
|
var flagPumpDict = pumpList.ToDictionary(x => x.SortCode, x => x.RatedParas);
|
|
|
var json = File.ReadAllText(fileName);
|
var templist = JsonHelper.Json2Object<List<ModelCombineViewModel>>(json);
|
var run_flags_flow_pressure_diff_dict = templist
|
.Select(x => (x.RunFlags, x.ScadaTotalFlow, x.ModelDeviation))
|
.ToList();
|
var ana_dev_list = StationCombineHelper.GetAnalysisDeviationDtoList(flagPumpDict, run_flags_flow_pressure_diff_dict, minFlow, maxFlow, spaceFlow);
|
ana_dev_list.ForEach(x => x.Station = index);
|
var root_folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pumpcombineana");
|
if (!Directory.Exists(root_folder))
|
{
|
Directory.CreateDirectory(root_folder);
|
}
|
var fileNameDev = Path.Combine(root_folder, $"AnalysisDeviation{spaceFlow}.json");
|
StationCombineHelper.SaveAnalysisDeviationDtoList(index, ana_dev_list, fileNameDev);
|
Console.WriteLine(Path.GetFileNameWithoutExtension(fileName) + ":Save");
|
}
|
|
}
|
|
public static void Completion()
|
{
|
var fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pumpcsv");
|
|
var fileNameList = Directory.GetFiles(fullPath).Select(x => Path.GetFileNameWithoutExtension(x)).ToList();
|
fileNameList = fileNameList.Where(x => x.Contains("update_curve")).ToList();
|
if (fileNameList == null || fileNameList.Count() < 1)
|
return;
|
var deleteList = fileNameList.Where(x => x.Contains("similar") || x.Contains("def")).ToList();
|
deleteList?.ForEach(x => File.Delete(x));
|
|
var flagCurveDict = GetFlagCurveDict();
|
|
fileNameList.RemoveAll(x => x.Contains("similar") ||x.Contains("def"));
|
var group = fileNameList.Where(x => x.Contains("update_curve")).GroupBy(x => x.Substring(0, 2));
|
foreach (var flagItem in group)
|
{
|
if (!int.TryParse(flagItem.Key, out int flag))
|
continue;
|
|
var files = flagItem.OrderBy(x => x).ToList();
|
var fileInfoList = new List<(int Hz, string FileName)>();
|
foreach (var fileName in files)
|
{
|
var hz = fileName.Substring(3, 2);
|
if (!int.TryParse(hz, out int hzInt))
|
continue;
|
if (hzInt > 50)
|
{
|
continue;
|
}
|
fileInfoList.Add((hzInt, fileName));
|
}
|
if (fileInfoList.Count == 1 && fileInfoList[0].Hz==50)
|
{
|
continue;
|
}
|
for (int i = 25; i <= 50; i++)
|
{
|
var maxHz = fileInfoList.Max(x => x.Hz);
|
var curvePointList = new List<CurvePoint>();
|
var fileName = string.Empty;
|
var currentHz = i;
|
var newFileName = "";
|
if (fileInfoList.Exists(x => x.Hz == i))
|
{
|
continue;
|
}
|
else if (currentHz == 50)
|
{
|
var curve = flagCurveDict[flag];
|
curvePointList = curve.GetFitPoints(100).ToList();
|
newFileName = $"{flagItem.Key}_{50}_update_curve_def.csv";
|
}
|
else if (currentHz > maxHz)
|
{
|
var curve = flagCurveDict[flag];
|
var similar_qh = Model.CurveCalcuHelper.CalculateSimilarQH(curve, 50, currentHz);
|
if (similar_qh == null)
|
{
|
continue;
|
}
|
curvePointList = similar_qh.GetFitPoints(100).ToList();
|
newFileName = $"{flagItem.Key}_{currentHz}_update_curve_similar_def.csv";
|
}
|
else
|
{
|
var (Hz, FileName) = fileInfoList.FirstOrDefault(x => x.Hz > i);
|
if (Hz < 1)
|
continue;
|
|
var updateCurvePtList = new List<CurvePoint>();
|
var updateCurveFile = Path.Combine(fullPath, $"{flagItem.Key}_{Hz}_update_curve.csv");
|
using (var fs = new FileStream(updateCurveFile, FileMode.Open, FileAccess.Read))
|
using (var sr = new StreamReader(fs, Encoding.UTF8))
|
{
|
var strLine = string.Empty;
|
sr.ReadLine();
|
while (!string.IsNullOrEmpty(strLine = sr.ReadLine()))
|
{
|
var strList = strLine.Split(',');
|
var x = double.Parse(strList[0]);
|
var y = double.Parse(strList[1]);
|
updateCurvePtList.Add(new CurvePoint(x, y));
|
}
|
}
|
|
var similar_qh = Model.CurveCalcuHelper.CalculateSimilarQH(new CurveExpress(updateCurvePtList), Hz, currentHz);
|
if (similar_qh == null)
|
{
|
continue;
|
}
|
curvePointList = similar_qh.GetFitPoints(100).ToList();
|
newFileName = $"{flagItem.Key}_{currentHz}_update_curve_similar_{Hz}.csv";
|
}
|
if (!curvePointList.Any())
|
{
|
continue;
|
}
|
var currentCurveFile = Path.Combine(fullPath, newFileName);
|
CsvHelper.ExportToCsv(curvePointList, currentCurveFile);
|
Console.WriteLine(newFileName);
|
}
|
}
|
|
}
|
|
|
|
|
private static Dictionary<int, IStation.Model.CurveExpress> GetFlagCurveDict()
|
{
|
var dict = new Dictionary<int, IStation.Model.CurveExpress>();
|
var bll_curve = new IStation.BLL.PumpCurve();
|
var station_list = new IStation.BLL.Station().GetAll();
|
foreach (var station in station_list)
|
{
|
var eq_list = new IStation.BLL.Equipment().GetPumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, station.ID);
|
if (eq_list == null || !eq_list.Any())
|
{
|
continue;
|
}
|
|
foreach (var eq in eq_list)
|
{
|
IStation.Model.CurveExpress qh = null;
|
var curve_info = bll_curve.GetDefaultWorkingByPumpID(eq.ID)?.CurveInfo;
|
if (curve_info != null)
|
{
|
qh = curve_info.CurveQH;
|
}
|
dict.Add(eq.SortCode, qh);
|
}
|
}
|
|
return dict;
|
}
|
}
|
|
|
|
|
}
|