using IStation.CalcModel;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Security.Permissions;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation
|
{
|
public class CalcPrjHelper
|
{
|
//bool isLimitLevel = false;
|
|
private List<Model.ElecPriceMonthSetting> _elePriceMonthList = null;
|
private List<IStation.CalcModel.PumpInfo> _allCalcPumpInfos;
|
|
public CalcPrjHelper()
|
{ }
|
|
public string Calc(IStation.CalcModel.AnaRequest anaRequest, out AnaPrj optPrj)
|
{
|
if (!InitalPumpInfo())
|
{
|
optPrj = null;
|
return "数据初始化失败";
|
}
|
if(! InitialElePrice())
|
{
|
optPrj = null;
|
return "ElecPrice 为空";
|
}
|
var calcHelper = GetCalcHelper(anaRequest);
|
|
string error_info;
|
optPrj = calcHelper.CalcOptPrj(out error_info);
|
|
if (!string.IsNullOrEmpty(error_info) || optPrj == null)
|
{
|
optPrj = null;
|
return error_info;
|
}
|
//anaPrjs.Sort(new AnaPrj.Comparer(anaRequest.CalcOptType));
|
//optPrj = anaPrjs.First();
|
|
//
|
double maxHeight = 0;
|
DateTime maxHeightTime = optPrj.StartTime;
|
if (optPrj.BlockTimes != null)
|
{
|
foreach (var bt in optPrj.BlockTimes)
|
{
|
if (bt.OpenPumpIndexs == null)
|
continue;
|
|
if (bt.PointTimes != null)
|
{
|
foreach (var bt2 in bt.PointTimes)
|
{
|
if (maxHeight < bt2.WaterLevelH)
|
{
|
maxHeight = bt2.WaterLevelH;
|
//maxHeight = Math.Max(maxHeight, bt2.WaterLevelH);
|
maxHeightTime = bt2.Time;
|
}
|
}
|
}
|
}
|
}
|
optPrj.MaxWaterLevelH = maxHeight;
|
optPrj.MaxWaterLevelTime = maxHeightTime;
|
|
return null;
|
}
|
|
/// <summary>
|
/// 构建计算辅助类
|
/// </summary>
|
/// <param name="isIgnoreOpenLimitAble"></param>
|
/// <returns></returns>
|
private IStation.Calc.ErQuCalcBaseHelper GetCalcHelper(IStation.CalcModel.AnaRequest anaRequest)
|
{
|
IStation.Calc.ErQuCalcBaseHelper calcHelper = IStation.Calc.ErQuCalcBaseHelper.Build(anaRequest);
|
calcHelper.MinOpenPumpMinute = IStation.AnaGlobalParas.Setting.MinOpenTimeMinute;
|
calcHelper.MinSwitchPumpMinute = IStation.AnaGlobalParas.Setting.MinSwitchTimeMinute;
|
calcHelper.SetOptimalPumpIndexs(
|
IStation.AnaGlobalParas.Setting.OptimalPumpIndexSequence,
|
IStation.AnaGlobalParas.Setting.UnablePumpIndexArray);
|
|
calcHelper.CalcSpaceMinute = IStation.AnaGlobalParas.Setting.CalcSpaceMinute;
|
calcHelper.MaxPumpSwitchCount = IStation.AnaGlobalParas.Setting.MaxPumpSwitchCount;
|
|
DateTime rangeStartTime = anaRequest.StartTime;
|
DateTime rangeEndTime = anaRequest.EndTime;
|
calcHelper.SetPumpInfo(_allCalcPumpInfos);
|
calcHelper.SetCalcTimeRange(rangeStartTime, rangeEndTime, IStation.AnaGlobalParas.Setting.CalcSpaceMinute);
|
|
calcHelper.ElecPrice = _elePriceMonthList;
|
|
calcHelper.IsDispDebug = false;
|
calcHelper.OnShowDebugInfo += (info) =>
|
{
|
//if (tabPageDebug.PageVisible)
|
// this.listBoxDebug.Items.Add(info);
|
};
|
|
//不许切泵时间
|
if (IStation.AnaGlobalParas.Setting.SwitchPumpIgnoreTimes != null && IStation.AnaGlobalParas.Setting.SwitchPumpIgnoreTimes.Count > 0)
|
{
|
List<IStation.CalcModel.TimeRange> limit_times = new List<IStation.CalcModel.TimeRange>();
|
foreach (var t in IStation.AnaGlobalParas.Setting.SwitchPumpIgnoreTimes)
|
{
|
if (t.IsUse == false)
|
continue;
|
|
int ed_h = t.EndHour;
|
int st_h = t.StartHour;
|
|
IStation.CalcModel.TimeRange v = new IStation.CalcModel.TimeRange();
|
|
if (ed_h <= rangeStartTime.Hour)
|
{
|
var nextDay = rangeStartTime.AddDays(1);
|
v.Start = new DateTime(nextDay.Year, nextDay.Month,
|
nextDay.Day, st_h, t.StartMinute, 0);
|
}
|
else
|
{
|
v.Start = new DateTime(rangeStartTime.Year, rangeStartTime.Month,
|
rangeStartTime.Day, st_h, t.StartMinute, 0);
|
}
|
|
bool isNext = ed_h > 23 ? true : false;
|
if (isNext)
|
{
|
var nextDay = v.Start.AddDays(1);
|
v.End = new DateTime(nextDay.Year, nextDay.Month,
|
nextDay.Day, ed_h - 24, t.EndMinute, 0);
|
}
|
else
|
{
|
v.End = new DateTime(v.Start.Year, v.Start.Month,
|
v.Start.Day, ed_h, t.EndMinute, 0);
|
}
|
if (v.End > v.Start)
|
{
|
limit_times.Add(v);
|
}
|
}
|
calcHelper.LimitSwitchPumpTimes = limit_times;
|
}
|
|
|
CalcLimitOpenPumpTime(ref calcHelper, anaRequest);
|
|
|
calcHelper.SetAnaRequest(anaRequest);
|
|
return calcHelper;
|
}
|
|
//不许开泵时间
|
private void CalcLimitOpenPumpTime(ref IStation.Calc.ErQuCalcBaseHelper calcHelper, IStation.CalcModel.AnaRequest anaRequest)
|
{
|
calcHelper.LimitOpenPumpTimes = null;
|
|
if (IStation.AnaGlobalParas.Setting.OpenPumpTimes == null)
|
return;
|
|
if (IStation.AnaGlobalParas.Setting.OpenPumpTimes.Count == 0)
|
return;
|
var listUse = (from x in IStation.AnaGlobalParas.Setting.OpenPumpTimes where x.IsUse select x).ToList();
|
if (listUse.Count == 0)
|
return;
|
//LogHelper.Info("Json转换" + JsonHelper.Object2Json(listUse));
|
|
DateTime rangeStartTime = anaRequest.StartTime;
|
DateTime rangeEndTime = anaRequest.EndTime;
|
|
List<IStation.CalcModel.TimeRange> limit_times = new List<IStation.CalcModel.TimeRange>();
|
IStation.CalcModel.TimeRange last_range = null;
|
for (DateTime dt = rangeStartTime; dt <= rangeEndTime; dt = dt.AddMinutes(5))
|
{
|
var ttt = dt.Hour * 60 + dt.Minute;
|
bool isOkOpen = false;
|
foreach (var openTime in listUse)
|
{
|
if (ttt >= openTime.StartHour * 60 + openTime.StartMinute && ttt <= openTime.EndHour * 60 + openTime.EndMinute)
|
{
|
isOkOpen = true;
|
break;
|
}
|
}
|
if (!isOkOpen)
|
{//限制开泵
|
if (last_range == null)
|
{
|
last_range = new TimeRange();
|
last_range.Start = dt;
|
}
|
}
|
else
|
{
|
if (last_range != null)
|
{
|
last_range.End = dt;
|
limit_times.Add(new IStation.CalcModel.TimeRange(last_range));
|
last_range = null;
|
}
|
}
|
}
|
|
calcHelper.LimitOpenPumpTimes = limit_times;
|
|
if (limit_times.Count > 0)
|
{
|
//LogHelper.Info("limit_times[0].Start时间:" + limit_times[0].Start.ToString());
|
//LogHelper.Info("rangeStartTime时间:" + rangeStartTime.ToString());
|
if (limit_times[0].Start == rangeStartTime)
|
{
|
if (anaRequest.StartOpenPumpIndexArray != null)
|
anaRequest.StartOpenPumpIndexArray.Clear();
|
else
|
anaRequest.StartOpenPumpIndexArray = new List<int>();
|
anaRequest.IsKnownStartOpenPump = true;//不考虑 ???
|
}
|
}
|
}
|
|
#region 初始化
|
|
/// <summary>
|
///
|
/// </summary>
|
private bool InitalPumpInfo()
|
{
|
var allCurveList = IStation.Common.PumpCurve.GetAll();
|
if (allCurveList == null)
|
return false;
|
var allPumpMapList = IStation.Common.PumpCurveMapping.GetAll();
|
var allPumpList = IStation.Common.Product.GetAllPump();
|
if (allPumpList == null)
|
return false;
|
_allCalcPumpInfos = new List<IStation.CalcModel.PumpInfo>();
|
foreach (var pump in allPumpList)
|
{
|
var curve_wrk_map = (from x in allPumpMapList where x.PumpID == pump.ID && x.IsWorking select x).FirstOrDefault();
|
if (curve_wrk_map == null)
|
{
|
IStation.LogHelper.Info(pump.Name + "未设置工作曲线");
|
return false;
|
}
|
var curve = allCurveList.Find(x => x.ID == curve_wrk_map.CurveID);
|
|
IStation.CalcModel.PumpInfo calcPumpInfo = new IStation.CalcModel.PumpInfo();
|
calcPumpInfo.Product = pump;
|
calcPumpInfo.ID = pump.ID;
|
calcPumpInfo.Name = pump.Name;
|
calcPumpInfo.CurveInfo = curve.CurveInfo;
|
calcPumpInfo.RatedParas = pump.RatedParas;
|
|
_allCalcPumpInfos.Add(calcPumpInfo);
|
}
|
return true;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
private bool InitialElePrice()
|
{
|
var allPrices = IStation.Common.ElecPrice.GetAll();
|
if(allPrices == null)
|
{
|
IStation.LogHelper.Error("ElecPrice 为空");
|
return false;
|
}
|
_elePriceMonthList = allPrices.First().Settings.MonthList;
|
return true;
|
}
|
|
#endregion 初始化
|
}
|
}
|