ningshuxia
2025-04-16 8c68ab4be4bff7981e745cc2b41c7bba5257a2d3
流量偏差 辅助类
已修改6个文件
已添加1个文件
194 ■■■■ 文件已修改
01-api/Application/IStation.Application/01-open-api/01-schedule/Schedule_Controller.cs 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
01-api/Service/IStation.Service/03-settings/paras/Paras_LocalFile.cs 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
01-api/Service/IStation.Service/05-service/00-basic/FlowDeviation.cs 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
01-api/Service/IStation.Service/07-helper/02-schedule/ScheduleHelper.cs 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
01-api/Service/IStation.Service/paras_schedule_settings.json 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
01-api/_Expand/IStation.Win.Schedule/bjMain.cs 89 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
02-desktop/Desktop/IStation.Test/Program.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
01-api/Application/IStation.Application/01-open-api/01-schedule/Schedule_Controller.cs
@@ -18,6 +18,7 @@
        private static readonly Service.ScheduleConfig _service_schedule_config = new();
        private static readonly Service.AnalysisDeviation _service_analysis_deviation = new();
        private static readonly Service.FlowDeviation _service_flow_deviation = new();
        /// <summary>
        /// è®¡ç®—
@@ -56,7 +57,8 @@
            var is_monitor_record_debug = false;
#if DEBUG
            is_monitor_record_debug = true;
#endif
#endif
            log_title = "实时ZyScada请求";
            var get_msg = GlobalHelper.GetMonitorRecordList(receipt_time, out List<Model.MonitorRecord> monitor_record_list, is_monitor_record_debug);
@@ -104,17 +106,20 @@
            }
            log_title = "调度返回";
            var msg = "计算结束!";
            var helper = new Service.ScheduleHelper();
            log_title = "流量补差";
            var helper = new Service.ScheduleHelper();
            helper.Initial(station1_open_flag_list, station1_schedule_config, analysis_deviation_list);
            var optimal_combine1 = helper.GetOptAnaCombine(station1, station1_flag_inlet_water_level_dict, target_flow1, target_pressure1);
            helper.Initial(station2_open_flag_list, station2_schedule_config, analysis_deviation_list);
            var station2_target_flow_diff=_service_flow_deviation.GetFlowDiff(target_pressure2);
            ScheduleLog.Info(request_id, log_title, $"2输水:{station2_target_flow_diff:N1}");
            helper.Initial(station2_open_flag_list, station2_schedule_config, analysis_deviation_list,station2_target_flow_diff);
            var optimal_combine2 = helper.GetOptAnaCombine(station2, station2_flag_inlet_water_level_dict, target_flow2, target_pressure2);
            log_title = "调度返回";
            var msg = "计算结束!";
            var schedule_request = new Model.ScheduleRequest
            {
                ID = request_id,
01-api/Service/IStation.Service/03-settings/paras/Paras_LocalFile.cs
@@ -68,6 +68,12 @@
        /// åˆ†æžåå·®æ–‡ä»¶
        /// </summary>
        public string AnalysisDeviationFile { get; set; } = "AnalysisDeviation.json";
        /// <summary>
        /// æµé‡åå·®æ–‡ä»¶
        /// </summary>
        public string FlowDeviationFile { get; set; } = "FlowDeviation.csv";
    }
}
01-api/Service/IStation.Service/05-service/00-basic/FlowDeviation.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,59 @@
namespace IStation.Service
{
    /// <summary>
    ///
    /// </summary>
    public partial class FlowDeviation
    {
        private readonly string _filePath = Path.Combine(
                     Settings.ParasHelper.LocalFile.DataFolderDirectory,
                     Settings.ParasHelper.LocalFile.FlowDeviationFile);
        private Curve.CurveExpress _flowDiffCurve = null;
        private bool _isCurveLoaded = false;
        /// <summary>
        /// èŽ·å–
        /// </summary>
        public double GetFlowDiff(double pressure)
        {
            if (_flowDiffCurve == null)
            {
                if (_isCurveLoaded)
                    return 0;
                _isCurveLoaded = true;
                if (!File.Exists(_filePath))
                    return default;
                var ptList = new List<Curve.CurvePoint>();
                using StreamReader reader = new StreamReader(_filePath);
                reader.ReadLine();
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    string[] values = line.Split(',');
                    var xStr = values[0];
                    var yStr = values[1];
                    var pX = double.Parse(xStr);
                    var pY = double.Parse(yStr);
                    pY = Math.Abs(pY);
                    ptList.Add(new CurvePoint(pX, pY));
                }
                if (ptList.Any())
                {
                    _flowDiffCurve = Curve.FitHelper.BuildCurveExpress(ptList);
                }
            }
            var flowDiff = _flowDiffCurve.GetFitPointY(pressure);
            return flowDiff;
        }
    }
}
01-api/Service/IStation.Service/07-helper/02-schedule/ScheduleHelper.cs
@@ -25,12 +25,14 @@
        private readonly decimal _frequency_max = 50;
        private readonly decimal _frequency_space = 1;//频率间隔 
        private readonly double _start_stop_loss_coefficient = 0.95;//泵启停损失系数
        private readonly double _start_stop_loss_coefficient = 0.9;//泵启停损失系数
        private double _sel_opt_flow_excess = 1;//可选方案的流量余量
        private readonly double _sel_opt_pump_pressure_excess = 0;//可选方案的单泵扬程默认抬升余量
        private double _station_target_flow_diff = 0; // ç«™ç‚¹ç›®æ ‡æµé‡å·®å€¼
        private double _sel_opt_flow_deviation_ratio = 0.05;//可选方案的流量偏差比
        private readonly double _sel_opt_flow_deviation_ratio = 0.05;//可选方案的流量偏差比
        private readonly double _sel_opt_reasonable_flow_deviation_ratio = 0.005;//合理的方案的流量偏差比
        private readonly Service.AnalysisParameter _service_analysis_parameter = new(); 
@@ -51,12 +53,14 @@
        private List<Model.AnalysisDeviation> _analysis_deviation_list = null;//分析偏差
        #endregion
        /// <summary>
        /// åˆå§‹åŒ–
        /// </summary>
        public void Initial(List<int> current_open_flag_list, Model.ScheduleConfig schedule_config, List<Model.AnalysisDeviation> analysis_deviation_list)
        public void Initial(List<int> current_open_flag_list, Model.ScheduleConfig schedule_config, List<Model.AnalysisDeviation> analysis_deviation_list, double station_target_flow_diff = 0)
        {
            _current_open_flag_list = current_open_flag_list;
            _min_open_count = 1;
@@ -70,6 +74,7 @@
            _frequency_limit_list = null;
            _flag_cumulative_runtime_dict = null;
            _priority_open_flag_list = null;
            _station_target_flow_diff = 0;
            if (schedule_config != null)
            {
                _min_open_count = schedule_config.MinOpenCount;
@@ -86,7 +91,7 @@
            }
            _analysis_deviation_list = analysis_deviation_list;
            _station_target_flow_diff = station_target_flow_diff;
        }
@@ -109,6 +114,7 @@
            )
        {
            target_flow+=_station_target_flow_diff;
            #region åˆå§‹åŒ–参数 
            if (pump_list == null || !pump_list.Any())
            {
01-api/Service/IStation.Service/paras_schedule_settings.json
@@ -12,7 +12,8 @@
    "ScheduleConfigFile": "ScheduleConfig.json",
    "HydraulicModelFile": "HydraulicModel.inp",
    "AnalysisFactorFile": "AnalysisFactor.json",
    "AnalysisDeviationFile": "AnalysisDeviation.json"
    "AnalysisDeviationFile": "AnalysisDeviation.json",
    "FlowDeviationFile": "FlowDeviation.csv"
  },
  "DataBase": {
    "DbType": "SQLite",
01-api/_Expand/IStation.Win.Schedule/bjMain.cs
@@ -83,8 +83,8 @@
            {
                return;
            }
            var deline = new DateTime(2024,12,1);
            var deline2 = new DateTime(2025,1,1);
            var deline = new DateTime(2025,2,12);
            var deline2 = new DateTime(2025,5,1);
            var time_list = _schedule_request_list.Where(x=>x.ReceptionTime>=deline&&x.ReceptionTime<= deline2).Select(x => x.ReceptionTime).OrderBy(x => x).ToList();
  
            foreach (var item in time_list)
@@ -157,57 +157,60 @@
                    }
                }
                double station2_target_flow_diff = 0;
                if (this.barCekCalcFlowDiff.Checked)
                {
                    var ptList = new List<CurvePoint>();
                    try
                    {
                        var filePath = @"D:\WorkCode\Project\ChDt1\Schedule.Ch.V1.0\02-desktop\Desktop\IStation.Test\bin\Debug\net6.0-windows\stationcsv\characteristic_curve.csv";
                        using (StreamReader reader = new StreamReader(filePath))
                        {
                            reader.ReadLine();
                            string line;
                            while ((line = reader.ReadLine()) != null)
                            {
                                // æŒ‰é€—号分隔每一行
                                string[] values = line.Split(',');
                                var xStr = values[0];
                                var yStr = values[1];
                    station2_target_flow_diff = new Service.FlowDeviation().GetFlowDiff(target_pressure2);
                    AlertTool.ShowInfo(this, "预测流量缺失", $"{station2_target_flow_diff:N1}");
                    //var ptList = new List<CurvePoint>();
                    //try
                    //{
                    //    var filePath = @"D:\WorkCode\Project\ChDt1\Schedule.Ch.V1.0\02-desktop\Desktop\IStation.Test\bin\Debug\net6.0-windows\stationcsv\characteristic_curve.csv";
                    //    using (StreamReader reader = new StreamReader(filePath))
                    //    {
                    //        reader.ReadLine();
                    //        string line;
                    //        while ((line = reader.ReadLine()) != null)
                    //        {
                    //            // æŒ‰é€—号分隔每一行
                    //            string[] values = line.Split(',');
                    //            var xStr = values[0];
                    //            var yStr = values[1];
                                var pX = double.Parse(xStr);
                                var pY = double.Parse(yStr);
                    //            var pX = double.Parse(xStr);
                    //            var pY = double.Parse(yStr);
                                pY = Math.Abs(pY);
                                ptList.Add(new CurvePoint(pX, pY));
                    //            pY = Math.Abs(pY);
                    //            ptList.Add(new CurvePoint(pX, pY));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("读取文件时出错: " + ex.Message);
                    }
                    //        }
                    //    }
                    //}
                    //catch (Exception ex)
                    //{
                    //    Console.WriteLine("读取文件时出错: " + ex.Message);
                    //}
                    var x = ptList.Select(x => x.X).ToArray();
                    var y = ptList.Select(x => x.Y).ToArray();
                    //var x = ptList.Select(x => x.X).ToArray();
                    //var y = ptList.Select(x => x.Y).ToArray();
                    // å¤šé¡¹å¼å›žå½’的阶数(例如,二次多项式)
                    int degree = 3;
                    //// å¤šé¡¹å¼å›žå½’的阶数(例如,二次多项式)
                    //int degree = 3;
                    // æ‹Ÿåˆå¤šé¡¹å¼å›žå½’模型
                    double[] coefficients = NonlinearRegressionHelper.FitPolynomial(x, y, degree);
                    //// æ‹Ÿåˆå¤šé¡¹å¼å›žå½’模型
                    //double[] coefficients = NonlinearRegressionHelper.FitPolynomial(x, y, degree);
                    // ä½¿ç”¨æ¨¡åž‹è¿›è¡Œé¢„测
                    double xNew = target_pressure2;
                    double yPredicted = NonlinearRegressionHelper.PredictPolynomial(xNew, coefficients);
                    //// ä½¿ç”¨æ¨¡åž‹è¿›è¡Œé¢„测
                    //double xNew = target_pressure2;
                    //double yPredicted = NonlinearRegressionHelper.PredictPolynomial(xNew, coefficients);
                    target_flow2 += yPredicted;
                    AlertTool.ShowInfo(this, "预测流量缺失", $"{yPredicted:N1}");
                    //station2_target_flow_diff = yPredicted;
                    //AlertTool.ShowInfo(this, "预测流量缺失", $"{yPredicted:N1}");
                    // è®¡ç®— R² å’Œ MSE
                    double rSquared = NonlinearRegressionHelper.CalculateRSquared(x, y, coefficients);
                    double mse = NonlinearRegressionHelper.CalculateMSE(x, y, coefficients);
                    //// è®¡ç®— R² å’Œ MSE
                    //double rSquared = NonlinearRegressionHelper.CalculateRSquared(x, y, coefficients);
                    //double mse = NonlinearRegressionHelper.CalculateMSE(x, y, coefficients);
                }
@@ -221,7 +224,7 @@
                helper.Initial(station1_open_flag_list, station1_schedule_config, analysis_deviation_list);
                var optimal_combine1 = helper.GetOptAnaCombine(station1, station1_flag_inlet_water_level_dict, target_flow1, target_pressure1);
                helper.Initial(station2_open_flag_list, station2_schedule_config, analysis_deviation_list);
                helper.Initial(station2_open_flag_list, station2_schedule_config, analysis_deviation_list, station2_target_flow_diff);
                var optimal_combine2 = helper.GetOptAnaCombine(station2, station2_flag_inlet_water_level_dict, target_flow2, target_pressure2);
                conclusion_list = new List<Model.ScheduleConclusion>();
02-desktop/Desktop/IStation.Test/Program.cs
@@ -14,7 +14,7 @@
        {
            //Station1Helper.Start();  //1 æ•°æ®ä¿®æ­£
            //Station2Helper.Start();  //2 æ¨¡åž‹ä¿®æ­£
            // 3  python修正
            // 3  python修正 ,目前有些数据问题还需要解决
            //Completion();            //4 ä¿®æ­£åŽç›¸ä¼¼æ¢ç®—修正
            //StationCombineHelper.Start(1);// 5 ç»„合偏差修正
@@ -22,7 +22,7 @@
            // 6 åˆ†æžæ³µé¢‘谱系数
            // 7 
            Station2TotalFlowDiffHelper.Start();// 8 è¡¥å…¨æµé‡åå·®
           // Station2TotalFlowDiffHelper.Start();// 8 è¡¥å…¨æµé‡åå·® + python
            Console.WriteLine();
            Console.WriteLine("ok");