using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
namespace IStation.Dispatch
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public class CalculatorOptAnaBase : CalculatorBase
|
{
|
/// <summary>
|
/// 计算最优方案
|
/// </summary>
|
/// <param name="complex_request_paras"></param>
|
/// <param name="machine_run_status"></param>
|
/// <param name="error_info"></param>
|
/// <returns></returns>
|
protected virtual List<Dispatch.Model.AnaScheme> CalcSchemes压力(
|
IStation.Dispatch.Model.RequestParasComplex complex_request_paras,
|
IStation.Dispatch.Model.MachineRunPara machine_run_status,
|
out string error_info)
|
{
|
error_info = "未实例化";
|
return null;
|
}
|
|
Dictionary<string, IStation.Dispatch.Model.AnaScheme> _dict = new Dictionary<string, Model.AnaScheme>();
|
/// <summary>
|
/// 提升出口压力每次提升的百分率
|
/// </summary>
|
public double UpOutletPressPercent { get; set; } = 0;
|
/// <summary>
|
/// 提升出口压力次数
|
/// </summary>
|
public int UpOutletPressCount { get; set; } = 0;
|
|
/// <summary>
|
/// 流量范围最大百分比 0 表示没有设置(至少大于100)
|
/// </summary>
|
public double TargetQmaxDefaultPercent { get; set; } = 0;
|
|
/// <summary>
|
/// 计算汇总数据 :成功返回null, 失败返回错误信息
|
/// </summary>
|
/// <param name="Month">月份</param>
|
/// <param name="HourRequests"></param>
|
/// <param name="isUseCache">是否用缓存</param>
|
/// <param name="daySumData"></param>
|
/// <param name="ErrorHour"></param>
|
/// <param name="LogAddOriginInfo"></param>
|
/// <returns></returns>
|
public virtual string CalcSumData(
|
int Month,
|
List<Model.HourRequest> HourRequests,
|
bool isUseCache,
|
out IStation.Dispatch.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.Dispatch.Model.AnaScheme opt_anaScheme;
|
if (_dict.ContainsKey(cacheName))
|
{
|
opt_anaScheme = _dict[cacheName];
|
}
|
else
|
{
|
#region MyRegion
|
string error_info = "";
|
List<Dispatch.Model.AnaScheme> 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);
|
}
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="pipes"></param>
|
/// <returns></returns>
|
protected static double CalcConnectPipeEta(List<IStation.Dispatch.Model.AnaScheme> 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);
|
}
|
}
|
}
|