using System; using System.Collections.Generic; using System.IO.Pipelines; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.Calculation.DispatchAna { /// /// /// public class CalculatorOptAnaBase: CalculatorBase { /// /// 计算最优方案 /// /// /// /// /// protected virtual List CalcSchemes压力( IStation.Calculation.DispatchAna.Model.RequestParasComplex complex_request_paras, IStation.Calculation.DispatchAna.Model.MachineRunPara machine_run_status, out string error_info) { error_info = "未实例化"; return null; } Dictionary _dict = new Dictionary(); /// /// 提升出口压力每次提升的百分率 /// public double UpOutletPressPercent { get; set; } = 0; /// /// 提升出口压力次数 /// public int UpOutletPressCount { get; set; } = 0; /// /// 计算汇总数据 :成功返回null, 失败返回错误信息 /// /// 月份 /// /// 是否用缓存 /// /// public virtual string CalcSumData( int Month, List HourRequests, bool isUseCache, out IStation.Calculation.DispatchAna.Model.DaySumData daySumData) { daySumData = new Model.DaySumData(); daySumData.Qt = 0; foreach (var hourRequest in HourRequests) { var complex_request_paras = hourRequest.Request; #region 检查数据 if (complex_request_paras.OutletPipePara == null || complex_request_paras.OutletPipePara.Count < 1) { return string.Format("{0}月的{1}时,分析出错,原因是:{2}", Month, hourRequest.Hour , "出口管路参数有误, 请确认是否赋值, ERROR 35"); } StringBuilder cacheNameBuilder = new StringBuilder(); double target_flow = 0; bool isHaveSetPress = false; foreach (var pipe in complex_request_paras.OutletPipePara) { target_flow += pipe.TargetFlow; if (pipe.TargetPress > 0.01) { isHaveSetPress = true; } cacheNameBuilder.AppendFormat("Q{0}H{1}", Math.Round(pipe.TargetFlow, 0), Math.Round(pipe.TargetPress, 3)); } if (target_flow < 50) {//检查流量 continue; } if (!isHaveSetPress) {//检查压力 continue; } if (complex_request_paras.InletPipePara != null) { foreach (var wl in complex_request_paras.InletPipePara) { cacheNameBuilder.AppendFormat("V{0}", Math.Round(wl.Value, 0)); } } #endregion //由于循环调取,所以以前分析数据缓存起来 var cacheName = cacheNameBuilder.ToString(); IStation.Calculation.DispatchAna.Model.AnaScheme opt_anaScheme; if (_dict.ContainsKey(cacheName)) { opt_anaScheme = _dict[cacheName]; } else { string error_info = ""; List result_anaSchemes = null; for (int i = 0; i <= UpOutletPressCount; i++) { result_anaSchemes = CalcSchemes压力(complex_request_paras, null, out error_info); if (result_anaSchemes != null && result_anaSchemes.Count > 0) break; if (UpOutletPressCount > 0 && i != UpOutletPressCount) { foreach (var p in complex_request_paras.OutletPipePara) p.TargetPress = complex_request_paras.OutletPipePara[0].TargetPress * (1.0 + UpOutletPressPercent / 100); } } if (result_anaSchemes == null || result_anaSchemes.Count == 0) { if (string.IsNullOrEmpty(error_info)) { return string.Format("{0}月的{1}时,分析出错,可能是入参数据不合理,请检查", Month, hourRequest.Hour ); } else { return string.Format("{0}月的{1}时,分析出错,原因是:{2}", Month, hourRequest.Hour , error_info); } } opt_anaScheme = result_anaSchemes.First(); _dict[cacheName] = opt_anaScheme; } //汇总 daySumData.Qt = daySumData.Qt + opt_anaScheme.TotalWrkQ; daySumData.Dt = daySumData.Dt + opt_anaScheme.TotalWrkP; // if(!string.IsNullOrEmpty(opt_anaScheme.ResultStatusInfo)) daySumData.Info = opt_anaScheme.ResultStatusInfo; } daySumData.WP = CalculateWP(daySumData.Dt, daySumData.Qt); return null; } /// /// /// /// /// protected static double CalcConnectPipeEta(List pipes) { double eta = 0; double qh = 0; int count = 0; foreach (var pipe in pipes) { if (pipe == null) continue; if (pipe.TotalWrkQ < 1 || pipe.TotalWrkH < 0.1) continue; qh += pipe.TotalWrkQ * pipe.TotalWrkH; eta += pipe.TotalWrkQ * pipe.TotalWrkH * pipe.TotalWrkE; count++; } if (count <= 0) return 0; return Math.Round(eta / qh, 2); } } }