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; /// /// 流量范围最大百分比 0 表示没有设置(至少大于100) /// public double TargetQmaxDefaultPercent { get; set; } = 0; /// /// 计算汇总数据 :成功返回null, 失败返回错误信息 /// /// 月份 /// /// 是否用缓存 /// /// /// /// public virtual string CalcSumData( int Month, List HourRequests, bool isUseCache, out IStation.Calculation.DispatchAna.Model.DaySumData daySumData, out int ErrorHour, out bool LogAddOriginInfo) { LogAddOriginInfo = false; daySumData = new Model.DaySumData(); daySumData.Qt = 0; ErrorHour = 0; foreach (var hourRequest in HourRequests) { var complex_request_paras = hourRequest.Request; ErrorHour = hourRequest.Hour; if (Month==2 && hourRequest.Hour == 5) { } #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_total_flow = 0; bool isHaveSetPress = true ; foreach (var pipe in complex_request_paras.OutletPipePara) { target_total_flow += pipe.TargetFlow; if (pipe.TargetFlow > 50) { if (!pipe.IsWaterLevel) {//压力 if (pipe.TargetPress < 0.001) { isHaveSetPress = false ; } } else {//水位 if (pipe.TargetPress < 0.1) { isHaveSetPress = false; } } cacheNameBuilder.AppendFormat("Q{0}H{1}", BuildCacheName4Flow(pipe.TargetFlow), BuildCacheName4Press(pipe.TargetPress)); } else { cacheNameBuilder.Append("Q0"); } } if (target_total_flow < 50) {//检查流量 continue; } if (!isHaveSetPress) {//检查压力 continue; } if (complex_request_paras.InletPipePara != null) { foreach (var wl in complex_request_paras.InletPipePara) { cacheNameBuilder.AppendFormat("V{0}", BuildCacheName4Press(wl.Value)); } } #endregion //由于循环调取,所以以前分析数据缓存起来 var cacheName = cacheNameBuilder.ToString(); IStation.Calculation.DispatchAna.Model.AnaScheme opt_anaScheme; if (_dict.ContainsKey(cacheName)) { opt_anaScheme = _dict[cacheName]; } else { #region MyRegion 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 = p.TargetPress * (1.0 + UpOutletPressPercent / 100); } } if (result_anaSchemes == null || result_anaSchemes.Count == 0) { if (string.IsNullOrEmpty(error_info)) { LogAddOriginInfo = true ; 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; #endregion } //汇总 daySumData.Qt = daySumData.Qt + opt_anaScheme.TotalWrkQ; daySumData.Dt = daySumData.Dt + opt_anaScheme.TotalWrkP; // if (!string.IsNullOrEmpty(opt_anaScheme.ResultStatusInfo)) { daySumData.Info = string.Format("{0},{1}时,{2}", daySumData.Info, hourRequest.Hour, opt_anaScheme.ResultStatusInfo); } } daySumData.WP = CalculateWP(daySumData.Dt, daySumData.Qt); return null; } private string BuildCacheName4Press(double press) { if (press < 1) return Math.Round(press, 3).ToString(); if (press < 5) return Math.Round(press, 2).ToString(); if (press < 10) return Math.Round(press, 1).ToString(); return Math.Round(press, 0).ToString(); } private string BuildCacheName4Flow(double flow) { if (flow > 10000) return (100 * (int)(flow / 100) ).ToString(); if (flow > 1000) return (20 * (int)(flow / 20)).ToString(); if (flow > 200) return (10 * (int)(flow / 10)).ToString(); if (flow > 50) return (2 * (int)(flow/2)).ToString(); return BuildCacheName4Press(flow) ; } /// /// /// /// /// 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); } } }