From ed113213fc94c3d9886ea08dfddd09d08d9ba7d5 Mon Sep 17 00:00:00 2001 From: ningshuxia <ningshuxia0927@outlook.com> Date: 星期三, 16 四月 2025 19:19:34 +0800 Subject: [PATCH] 调度代码修正 --- 01-api/_Expand/IStation.Init/Program.cs | 209 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 206 insertions(+), 3 deletions(-) diff --git a/01-api/_Expand/IStation.Init/Program.cs b/01-api/_Expand/IStation.Init/Program.cs index 35549c8..a94321e 100644 --- a/01-api/_Expand/IStation.Init/Program.cs +++ b/01-api/_Expand/IStation.Init/Program.cs @@ -1,12 +1,17 @@ 锘�// See https://aka.ms/new-console-template for more information +using IStation.Curve; using System.Reflection; +using System.Text; Console.WriteLine("鏄惁鍒濆鍖栨暟鎹簱?(y)"); var str = Console.ReadLine(); if (str != "y") return; - +if (File.Exists(IStation.Settings.ParasHelper.LocalFile.DataFolderDirectory + "\\analysis.db")) +{ + File.Delete(IStation.Settings.ParasHelper.LocalFile.DataFolderDirectory + "\\analysis.db"); +} IStation.Settings.ParasHelper.DataBase.SQLite.AnalysisConnectString ="DataSource="+ IStation.Settings.ParasHelper.LocalFile.DataFolderDirectory+ "\\analysis.db"; //IStation.Settings.ParasHelper.DataBase.SQLite.ScheduleConnectString = "DataSource=" + IStation.Settings.ParasHelper.LocalFile.DataFolderDirectory+ "\\schedule.db"; //IStation.Settings.ParasHelper.DataBase.SQLite.HydraulicConnectString = "DataSource=" + IStation.Settings.ParasHelper.LocalFile.DataFolderDirectory+ "\\hydraulic.db"; @@ -23,12 +28,210 @@ all_pump_list.AddRange(station.Station1); all_pump_list.AddRange(station.Station2); +var flagHzCurveDict = GetFlagHzCurveDict(); var helper = new IStation.Service.AnalysisHelper(); -helper.AnalysisNew(all_pump_list, ana_factor_list); +helper.AnalysisNew(all_pump_list, flagHzCurveDict); helper.AnalysisParameter(all_pump_list); Console.WriteLine("Analysis is ok"); Console.WriteLine("OK"); -Console.ReadKey(); \ No newline at end of file +Console.ReadKey(); + + + static Dictionary<int, Dictionary<int, List<CurvePoint>>> GetFlagHzCurveDict() +{ + var fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pumpcsv"); + var fileNameList = Directory.GetFiles(fullPath).Select(x => Path.GetFileNameWithoutExtension(x)).ToList(); + if (fileNameList == null || fileNameList.Count < 1) + { + return new Dictionary<int, Dictionary<int, List<CurvePoint>>>(); + } + + var dict = new Dictionary<int, Dictionary<int, List<CurvePoint>>>(); + var group = fileNameList.Where(x => x.Contains("_update_curve")).GroupBy(x => x.Substring(0, 2)); + foreach (var flagItem in group) + { + var flag = int.Parse(flagItem.Key); + var files = flagItem.OrderBy(x => x).ToList(); + var fileInfoList = new List<(int Hz, string FileName)>(); + + dict[flag] = new Dictionary<int, List<CurvePoint>>(); + foreach (var fileName in files) + { + var hz = int.Parse(fileName.Substring(3, 2)); + if (hz > 50) + { + continue; + } + fileInfoList.Add((hz, fileName)); + } + + foreach (var item in fileInfoList) + { + var updateCurvePtList = new List<CurvePoint>(); + var updateCurveFile = Path.Combine(fullPath, $"{item.FileName}.csv"); + var hz = item.Hz; + 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 x_values = updateCurvePtList.Select(x => (float)x.X).ToArray(); + var y_values = updateCurvePtList.Select(x => (float)x.Y).ToArray(); + if (!CheckFitPointList(x_values, y_values)) + { + var (newX, newY) = UpdateFitPointList(x_values, y_values); + if (newX.Length < x_values.Length / 2) + { + throw new Exception($"{item.FileName}鏁版嵁寮傚父"); + } + updateCurvePtList = new List<CurvePoint>(); + for (int i = 0; i < newX.Length; i++) + { + var x = newX[i]; + var y = newY[i]; + updateCurvePtList.Add(new CurvePoint(x, y)); + } + } + + } + dict[flag][item.Hz] = updateCurvePtList; + } + } + + return dict; +} +/// <summary> +/// 璁$畻鐩镐技娴侀噺鎵▼鏇茬嚎 +/// </summary> +/// <param name="express">琛ㄨ揪寮�</param> +/// <param name="originHz">鍘熷棰戠巼</param> +/// <param name="changeHz">鎹㈢畻棰戠巼</param> +/// <param name="pointNumber">鎷熷悎鐐规暟閲�</param> +/// <returns></returns> + static List<CurvePoint> CalculateSimilarQH(List<CurvePoint> ptList, double originHz, double changeHz, int pointNumber = 12) +{ + if (ptList == null || !ptList.Any()) + return null; + if (changeHz < 1) + return null; + List<CurvePoint> fitPoints = ptList; + + var ratio = changeHz / originHz; + var similarPoints = new List<CurvePoint>(); + foreach (CurvePoint fitPoint in fitPoints) + { + var similarPoint = new CurvePoint(); + similarPoint.X = fitPoint.X * ratio; + similarPoint.Y = fitPoint.Y * ratio * ratio; + similarPoints.Add(similarPoint); + } + return IStation.Curve.FitHelper.BuildCurveExpress(similarPoints).GetFitPoints(pointNumber); +} + +static bool CheckFitPointList(float[] x, float[] y) +{ + + bool is_x_increasing = CheckIncreasing(x); + bool is_y_decreasing = CheckDecreasing(y); + if (!is_x_increasing) + { + Console.WriteLine("x涓嶆弧瓒抽�掑瓒嬪娍"); + return false; + } + if (!is_y_decreasing) + { + Console.WriteLine("y涓嶆弧瓒抽�掑噺瓒嬪娍"); + return false; + } + + return true; +} + +static (float[] NewX, float[] NewY) UpdateFitPointList(float[] x_values, float[] y_values) +{ + List<int> indices_to_keep = new(); + var prev_y_index = 0; + float prev_y = y_values[prev_y_index]; + var max_y_index = y_values.ToList().FindLastIndex(x => x > prev_y); + + if (max_y_index > 0) + { + + var temp_index = (int)(y_values.Length * 0.5); + if (temp_index > max_y_index) + { + prev_y_index = max_y_index; + prev_y = y_values[prev_y_index]; + } + + var tttIndex = y_values.Skip(prev_y_index).ToList().FindLastIndex(x => x > prev_y); + if (tttIndex > 0) + { + throw new Exception("aaa"); + //temp_index = (int)(y_values.Length * 0.5); + //if (temp_index > max_y_index) + //{ + // prev_y_index = max_y_index; + // prev_y = y_values[prev_y_index]; + //} + } + } + + for (int i = prev_y_index; i < y_values.Length; i++) + { + float current_y = y_values[i]; + if (current_y <= prev_y) + { + indices_to_keep.Add(i); + prev_y = current_y; + } + } + + float[] x_processed = new float[indices_to_keep.Count]; + float[] y_processed = new float[indices_to_keep.Count]; + + for (int i = 0; i < indices_to_keep.Count; i++) + { + int index = indices_to_keep[i]; + x_processed[i] = x_values[index]; + y_processed[i] = y_values[index]; + } + + return new(x_processed, y_processed); +} + +static bool CheckIncreasing(float[] values) +{ + for (int i = 1; i < values.Length; i++) + { + if (values[i] < values[i - 1]) + { + return false; + } + } + return true; +} + +static bool CheckDecreasing(float[] values) +{ + for (int i = 1; i < values.Length; i++) + { + if (values[i] > values[i - 1]) + { + return false; + } + } + return true; +} \ No newline at end of file -- Gitblit v1.9.3