ningshuxia
2025-04-16 8c68ab4be4bff7981e745cc2b41c7bba5257a2d3
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>();