using Mapster;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yw.Pump;
using Yw.WinFrmUI.Phart;
namespace HStation.WinFrmUI
{
///
/// 水泵分析辅助类
///
public class SimulationPrintPumpAnalyHelper
{
///
/// 创建
///
public static SimulationPrintPumpAnalyViewModel Create
(
Yw.Model.HydroModelInfo hydroInfo,
Yw.Vmo.HydroWorkingVmo working,
HydroCalcuResult calcuResult = null,
bool isHead = false,
List allEvaluationList = null
)
{
var vm = new SimulationPrintPumpAnalyViewModel();
//验证
if (hydroInfo == null)
{
return vm;
}
if (working == null)
{
return vm;
}
//赋值模型信息,避免干扰
//var newHydroInfo = hydroInfo.Adapt();
//newHydroInfo.UpdateWorkingInfo(working.WorkingInfo);
if (hydroInfo.Pumps == null || hydroInfo.Pumps.Count < 1)
{
return vm;
}
//计算结果
if (calcuResult == null)
{
calcuResult = hydroInfo.Calcu(Yw.EPAnet.CalcuMode.MinorLoss, isHead, allEvaluationList);
if (!calcuResult.Succeed)
{
return vm;
}
}
var allCalcuVisualDict = calcuResult.GetVisualDict();
//遍历水泵
vm.Items = new List();
foreach (var pump in hydroInfo.Pumps)
{
var item = new SimulationPrintPumpAnalyItemViewModel();
vm.Items.Add(item);
item.BeginGroup = string.IsNullOrEmpty(pump.BeginGroup) ? string.Empty : pump.BeginGroup;
item.Name = pump.Name;
item.Code = pump.Code;
item.RatedQ = pump.RatedQ;
item.RatedH = pump.RatedH;
item.RatedP = pump.RatedP;
item.RatedN = pump.RatedN;
item.RatedHz = pump.RatedHz;
var curveqh = hydroInfo.Curves?.Find(x => x.Code == pump.CurveQH);
if (curveqh != null)
{
var qh_pts = curveqh.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
if (qh_pts != null && qh_pts.Count > 3)
{
item.RatedCurveQH = qh_pts;
}
}
var curveqp = hydroInfo.Curves?.Find(x => x.Code == pump.CurveQP);
if (curveqp != null)
{
var qp_pts = curveqp.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
if (qp_pts != null && qp_pts.Count > 3)
{
item.RatedCurveQP = qp_pts;
}
}
var curveqe = hydroInfo.Curves?.Find(x => x.Code == pump.CurveQE);
if (curveqe != null)
{
var qe_pts = curveqe.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
if (qe_pts != null && qe_pts.Count > 3)
{
item.RatedCurveQE = qe_pts;
}
}
item.LinkStatus = pump.LinkStatus;
if (item.LinkStatus == Yw.Hydro.LinkStatus.Open)
{
item.CurrentN = Math.Round(item.RatedN * pump.SpeedRatio, 1);
item.CurrentHz = Math.Round(item.RatedHz * pump.SpeedRatio, 1);
var calcuPumpResult = allCalcuVisualDict?.GetValue(pump.Code) as HydroCalcuPumpResult;
if (calcuPumpResult != null)
{
item.CurrentQ = calcuPumpResult.CalcuQ;
item.CurrentH = calcuPumpResult.CalcuH;
item.CurrentP = calcuPumpResult.CalcuP;
item.CurrentE = calcuPumpResult.CalcuE;
}
if (item.RatedCurveQH != null)
{
var qh_pts = item.RatedCurveQH;
var qh_run_pts = qh_pts.GetQHPointListByN(item.RatedHz, item.CurrentHz);
item.CurrentCurveQH = qh_run_pts;
}
if (item.RatedCurveQP != null)
{
var qp_pts = item.RatedCurveQP;
var qp_run_pts = qp_pts.GetQPPointListByN(item.RatedHz, item.CurrentHz);
item.CurrentCurveQP = qp_pts;
}
if (item.RatedCurveQE != null)
{
var qe_pts = item.RatedCurveQE;
var qe_run_pts = qe_pts.GetQEPointListByN(item.RatedHz, item.CurrentHz);
item.CurrentCurveQE = qe_run_pts;
}
}
}
return vm;
}
}
}