using System;
|
using System.Collections.Generic;
|
using System.IO.Pipelines;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.Calculation.DispatchAna
|
{
|
/// <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<Calculation.DispatchAna.Model.AnaScheme> 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<string, IStation.Calculation.DispatchAna.Model.AnaScheme> _dict = new Dictionary<string, Model.AnaScheme>();
|
|
/// <summary>
|
/// 计算汇总数据 :成功返回null, 失败返回错误信息
|
/// </summary>
|
/// <param name="Month">月份</param>
|
/// <param name="HourRequests"></param>
|
/// <param name="isUseCache">是否用缓存</param>
|
/// <param name="daySumData"></param>
|
/// <returns></returns>
|
public virtual string CalcSumData(
|
int Month,
|
List<Model.HourRequest> 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;
|
var result_anaSchemes = CalcSchemes压力(complex_request_paras, null, out error_info);
|
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;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="pipes"></param>
|
/// <returns></returns>
|
protected static double CalcConnectPipeEta(List<IStation.Calculation.DispatchAna.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);
|
}
|
}
|
}
|