using IStation.Epanet;
|
using IStation.Epanet.Enums;
|
using System.Text;
|
using Yw.Untity;
|
|
namespace IStation.Test.Init
|
{
|
public class ScadaScheduleHelper
|
{
|
private static readonly Service.ScheduleRequest _service_schedule_request = new();
|
private static readonly Service.ScheduleScada _service_schedule_scada = new();
|
private static readonly Service.ScheduleRule _service_schedule_rule = new();
|
private static readonly Service.ScheduleConclusion _service_schedule_conclusion = new();
|
private static readonly Service.SchedulePump _service_schedule_pump = new();
|
|
private static readonly Service.Station _service_station = new();
|
private static readonly Service.ScheduleConfig _service_schedule_config = new();
|
private static readonly string _model_file = System.IO.Path.Combine(Settings.ParasHelper.LocalFile.DataFolderDirectory, "ch2_v3_ 20240801(Clear).inp");
|
|
#region dict
|
|
private static readonly Dictionary<string, string> _flow_id_mapping_dict1 = new Dictionary<string, string>()
|
{
|
{"Pjd1","SFJD1"},
|
{"Pjd2","SFJD2"},
|
{"Pjd3","SFJD3"},
|
};
|
|
private static readonly Dictionary<string, string> _pressure_id_mapping_dict1 = new Dictionary<string, string>()
|
{
|
{"Jjd1","SPJD1"},
|
{"Jjd2","SPJD2"},
|
{"Jjd3","SPJD3"},
|
{"Jpump11","SPPump11" },
|
{"Jpump12","SPPump12" },
|
{"Jpump13","SPPump13" },
|
{"Jpump14","SPPump14" },
|
{"Jpump15","SPPump15" },
|
{"Jpump16","SPPump16" },
|
{"Jpump17","SPPump17" },
|
{"Jpump18","SPPump18" }
|
};
|
|
private static readonly Dictionary<string, string> _pump_id_mapping_dict1 = new Dictionary<string, string>(){
|
{ "Pump11" , "Pump11"},
|
{ "Pump12" , "Pump12"},
|
{ "Pump13" , "Pump13"},
|
{ "Pump14" , "Pump14"},
|
{ "Pump15" , "Pump15"},
|
{ "Pump16" , "Pump16"},
|
{ "Pump17" , "Pump17"},
|
{ "Pump18" , "Pump18"},
|
|
};
|
|
private static readonly Dictionary<int, string> _flag_pattern_dict1 = new(){
|
{ GlobalHelper.Flag11 , "Pump11"},
|
{ GlobalHelper.Flag12 , "Pump12"},
|
{ GlobalHelper.Flag13 , "Pump13"},
|
{ GlobalHelper.Flag14 , "Pump14"},
|
{ GlobalHelper.Flag15 , "Pump15"},
|
{ GlobalHelper.Flag16 , "Pump16"},
|
{ GlobalHelper.Flag17 , "Pump17"},
|
{ GlobalHelper.Flag18 , "Pump18"},
|
};
|
|
private static readonly Dictionary<string, string> _flow_id_mapping_dict2 = new Dictionary<string, string>()
|
{
|
{"Pdn2400","SFDN2400"},
|
{"Pdn2700","SFDN2700"},
|
{"Ppump21","SFPump21"},
|
{"Ppump22","SFPump22"},
|
{"Ppump23","SFPump23"},
|
{"Ppump24","SFPump24"},
|
{"Ppump25","SFPump25"},
|
{"Ppump26","SFPump26"},
|
{"Ppump27","SFPump27"}
|
};
|
|
private static readonly Dictionary<string, string> _pressure_id_mapping_dict2 = new Dictionary<string, string>()
|
{
|
{"Jdn2400","SPDN2400"},
|
{"Jdn2700","SPDN2700"},
|
{"Jpump21","SPPump21"},
|
{"Jpump22","SPPump22"},
|
{"Jpump23","SPPump23"},
|
{"Jpump24","SPPump24"},
|
{"Jpump25","SPPump25"},
|
{"Jpump26","SPPump26"},
|
{"Jpump27","SPPump27"}
|
};
|
|
private static readonly Dictionary<string, string> _pump_id_mapping_dict2 = new Dictionary<string, string>(){
|
{ "Pump21" , "Pump21"},
|
{ "Pump22" , "Pump22"},
|
{ "Pump23" , "Pump23"},
|
{ "Pump24" , "Pump24"},
|
{ "Pump25" , "Pump25"},
|
{ "Pump26" , "Pump26"},
|
{ "Pump27" , "Pump27"}
|
};
|
|
private static readonly Dictionary<int, string> _flag_pattern_dict2 = new(){
|
{ GlobalHelper.Flag21 ,"Pump21" },
|
{ GlobalHelper.Flag22 ,"Pump22" },
|
{ GlobalHelper.Flag23 ,"Pump23" },
|
{ GlobalHelper.Flag24 ,"Pump24" },
|
{ GlobalHelper.Flag25 ,"Pump25" },
|
{ GlobalHelper.Flag26 ,"Pump26" },
|
{ GlobalHelper.Flag27 ,"Pump27" }
|
};
|
|
#endregion
|
|
//调度
|
public static string Schedule()
|
{
|
var msg = string.Empty;
|
var day_value_list = DayValueHelper.GetDayValues();
|
if (day_value_list == null || !day_value_list.Any())
|
{
|
msg = "无法加载日期数据!";
|
return msg;
|
}
|
//try
|
//{
|
Console.WriteLine("开始分析");
|
Yw.LogHelper.Info("开始分析");
|
foreach (var day_value in day_value_list)
|
{
|
var date = day_value.Year + "-" + day_value.Month + "-" + day_value.Day;
|
Console.WriteLine($"开始调度{date}...");
|
Yw.LogHelper.Info($"开始调度{date}...");
|
|
msg = Schedule(
|
new List<DayValue>() { day_value },
|
true,
|
true,
|
out List<Station1ScadaSchedule> all_station1_scada_schedule_list,
|
out List<Station2ScadaSchedule> all_station2_scada_schedule_list);
|
|
|
if ((!all_station1_scada_schedule_list.Any()) && (!all_station2_scada_schedule_list.Any()))
|
{
|
Console.WriteLine($"跳过{date}... {msg}");
|
Yw.LogHelper.Info($"跳过{date}... {msg}");
|
continue;
|
}
|
|
var count = all_station1_scada_schedule_list.Count();
|
var schedule_request_list = new List<Model.ScheduleRequest>();
|
var schedule_conclusion_list = new List<Model.ScheduleConclusion>();
|
var schedule_pump_list = new List<Model.SchedulePump>();
|
|
Console.WriteLine($"开始插入{count}条数据...");
|
Yw.LogHelper.Info($"开始插入{count}条数据...");
|
|
for (int i = 0; i < count; i++)
|
{
|
var station1 = all_station1_scada_schedule_list.ElementAt(i);
|
var station2 = all_station2_scada_schedule_list.ElementAt(i);
|
|
var schedule_status1 = !string.IsNullOrEmpty(station1.RunFlagsM);
|
var schedule_status2 = !string.IsNullOrEmpty(station2.RunFlagsM);
|
|
var request_id = Yw.YitIdHelper.NextId();
|
var schedule_request = new Model.ScheduleRequest
|
{
|
ID = request_id,
|
TargetFlow1 = station1.TotalFlow,
|
TargetPressure1 = Curve.PumpCalculateHelper.M2Mpa(station1.TotalHead),
|
TargetFlow2 = station2.TotalFlow,
|
TargetPressure2 = Curve.PumpCalculateHelper.M2Mpa(station2.TotalHead),
|
ScheduleStatus1 = schedule_status1,
|
ScheduleStatus2 = schedule_status2,
|
TotalTimeSpent = 0,
|
ReceptionTime = station1.Time
|
};
|
schedule_request_list.Add(schedule_request);
|
|
if (schedule_status1)
|
{
|
station1.ScheduleConclusion.RequestID = request_id;
|
station1.SchedulePumpList.ForEach(x => x.RequestID = request_id);
|
|
schedule_conclusion_list.Add(station1.ScheduleConclusion);
|
schedule_pump_list.AddRange(station1.SchedulePumpList);
|
}
|
|
if (schedule_status2)
|
{
|
station2.ScheduleConclusion.RequestID = request_id;
|
station2.SchedulePumpList.ForEach(x => x.RequestID = request_id);
|
|
schedule_conclusion_list.Add(station2.ScheduleConclusion);
|
schedule_pump_list.AddRange(station2.SchedulePumpList);
|
}
|
}
|
|
var bol = _service_schedule_request.Inserts(schedule_request_list);
|
if (!bol)
|
{
|
Console.WriteLine("schedule_request_list 插入异常");
|
Yw.LogHelper.Info("schedule_request_list 插入异常");
|
|
}
|
else
|
{
|
Console.WriteLine("schedule_request_list 插入成功");
|
Yw.LogHelper.Info("schedule_request_list 插入成功");
|
}
|
|
bol = _service_schedule_conclusion.Inserts(schedule_conclusion_list);
|
if (!bol)
|
{
|
Console.WriteLine("schedule_conclusion_list 插入异常");
|
Yw.LogHelper.Info("schedule_conclusion_list 插入异常");
|
|
}
|
else
|
{
|
Console.WriteLine("schedule_conclusion_list 插入成功");
|
Yw.LogHelper.Info("schedule_conclusion_list 插入成功");
|
|
}
|
|
bol = _service_schedule_pump.Inserts(schedule_pump_list);
|
if (!bol)
|
{
|
Console.WriteLine("schedule_pump_list 插入异常");
|
Yw.LogHelper.Info("schedule_pump_list 插入异常");
|
}
|
else
|
{
|
Console.WriteLine("schedule_pump_list 插入成功");
|
Yw.LogHelper.Info("schedule_pump_list 插入成功");
|
|
}
|
|
Console.WriteLine($"结束调度{date}...");
|
Yw.LogHelper.Info($"结束调度{date}...");
|
|
}
|
Console.WriteLine("结束分析...");
|
Yw.LogHelper.Info("结束分析...");
|
|
//}
|
//catch (Exception ex)
|
//{
|
// Console.WriteLine(ex.Message);
|
// Yw.LogHelper.Error(ex.Message);
|
//}
|
return msg;
|
}
|
|
//调度
|
public static string Schedule(
|
List<DayValue> day_value_list,
|
bool use_station1,
|
bool use_station2,
|
out List<Station1ScadaSchedule> all_station1_scada_schedule_list,
|
out List<Station2ScadaSchedule> all_station2_scada_schedule_list,
|
bool limit_is=false)
|
{
|
var msg = string.Empty;
|
all_station1_scada_schedule_list = new List<Station1ScadaSchedule>();
|
all_station2_scada_schedule_list = new List<Station2ScadaSchedule>();
|
if (day_value_list == null || !day_value_list.Any())
|
{
|
return msg;
|
}
|
|
AnalysisDeviationHelper.OutScadaScheduleVmList(
|
day_value_list,
|
out all_station1_scada_schedule_list,
|
out all_station2_scada_schedule_list,
|
limit_is);
|
|
|
if ((!all_station1_scada_schedule_list.Any()) && (!all_station2_scada_schedule_list.Any()))
|
{
|
return "存在单管流量为0的情况!";
|
}
|
|
var station_info = _service_station.Get();
|
var station1 = station_info.Station1;
|
var station2 = station_info.Station2;
|
var station1_schedule_config = _service_schedule_config.GetStation1();
|
var station2_schedule_config = _service_schedule_config.GetStation2();
|
var station1_flag_list = GlobalHelper.Station1FlagList;
|
var station2_flag_list = GlobalHelper.Station2FlagList;
|
|
|
var err = EpanetMethods.ENopen(_model_file, "", "");
|
if (err != ErrorCode.Ok)
|
return "err != ErrorCode.Ok";
|
|
err = EpanetMethods.ENopenH();
|
if (err != ErrorCode.Ok)
|
return "err != ErrorCode.Ok";
|
|
var model_id_build = new StringBuilder(31);
|
EpanetMethods.ENgetcount(CountType.Link, out int link_count);
|
EpanetMethods.ENgetcount(CountType.Node, out int node_count);
|
|
var helper = new IStation.Algorithm.ScheduleHelper();
|
if (use_station1)
|
{
|
var scada_power_list = new List<double>();
|
var model_power_list = new List<double>();
|
var head_diff_jd1_list = new List<double?>();
|
var head_diff_jd2_list = new List<double?>();
|
var head_diff_jd3_list = new List<double?>();
|
|
var scada_total_flow = 0d;
|
var model_total_flow = 0d;
|
foreach (var station1_scada_schedule in all_station1_scada_schedule_list)
|
{
|
var time = station1_scada_schedule.Time;
|
//if (!(time.Hour == 12 && time.Minute == 0 && time.Second == 0))
|
//{
|
// continue;
|
//}
|
var run_flags = station1_scada_schedule.RunFlags;
|
var target_flow = station1_scada_schedule.TotalFlow;
|
var target_head = station1_scada_schedule.TotalHead;
|
|
var flag_inlet_water_level_dict = station1_scada_schedule.ToFlagInletWaterLevelDict();
|
var open_flag_list = IntListHelper.ToList(run_flags);
|
|
helper.Initial(open_flag_list, station1_schedule_config);
|
|
var optimal_combine = helper.GetOptAnaCombine(station1, flag_inlet_water_level_dict, target_flow, target_head);
|
if (optimal_combine == null)
|
{
|
station1_scada_schedule.Set();
|
continue;
|
}
|
if (!run_flags.Equals(optimal_combine.Remark))
|
{
|
|
}
|
|
station1_scada_schedule.ScheduleConclusion = new Model.ScheduleConclusion
|
{
|
ID = Yw.YitIdHelper.NextId(),
|
RequestID = 0,
|
Station = IStation.eDockingStation.Ch1s,
|
TotalFlow = optimal_combine.TotalFlow,
|
TotalPressure = optimal_combine.TotalPressure,
|
TotalPower = optimal_combine.TotalPower,
|
TotalEfficiency = optimal_combine.TotalEfficiency,
|
WP = optimal_combine.WP,
|
UWP = optimal_combine.UWP,
|
Flags = IntListHelper.ToString(optimal_combine.Flags),
|
MeritRatio = optimal_combine.MeritRatio
|
};
|
station1_scada_schedule.SchedulePumpList = new List<Model.SchedulePump>();
|
foreach (var fre_pump in optimal_combine.AnaFrePumps)
|
{
|
var schedule_pump = new Model.SchedulePump
|
{
|
RequestID = 0,
|
Station = IStation.eDockingStation.Ch1s,
|
Flag = fre_pump.Flag,
|
Flow = fre_pump.Flow,
|
Head = fre_pump.Head,
|
PressureDiff = fre_pump.PressureDiff,
|
Power = fre_pump.Power,
|
Efficiency = fre_pump.Eff,
|
Hz = fre_pump.Frequency,
|
Rpm = fre_pump.Speed
|
};
|
station1_scada_schedule.SchedulePumpList.Add(schedule_pump);
|
}
|
|
var pattern_dict = station1_scada_schedule.ToModelPatternDict();
|
|
var ana_fre_pump_list = optimal_combine.AnaFrePumps;
|
foreach (var item in _flag_pattern_dict1)
|
{
|
var flag = item.Key;
|
var pattern_id = item.Value;
|
var speed_ratio = 0f;
|
|
var ana_fre_pump = ana_fre_pump_list.Find(x => x.Flag == flag);
|
if (ana_fre_pump != null)
|
{
|
speed_ratio = (float)(ana_fre_pump.Frequency / 50);
|
station1_scada_schedule.TotalPowerM += ana_fre_pump.Power;
|
}
|
pattern_dict[pattern_id] = new float[] { speed_ratio };
|
}
|
|
var model_value_dict = OutModelDict(link_count, node_count, model_id_build, pattern_dict, _pump_id_mapping_dict1, _flow_id_mapping_dict1, _pressure_id_mapping_dict1);
|
if (model_value_dict == null)
|
{
|
continue;
|
}
|
|
station1_scada_schedule.JD1PM = model_value_dict["SPJD1"];
|
station1_scada_schedule.JD2PM = model_value_dict["SPJD2"];
|
station1_scada_schedule.JD3PM = model_value_dict["SPJD3"];
|
station1_scada_schedule.Pump11PM = model_value_dict["SPPump11"];
|
station1_scada_schedule.Pump12PM = model_value_dict["SPPump12"];
|
station1_scada_schedule.Pump13PM = model_value_dict["SPPump13"];
|
station1_scada_schedule.Pump14PM = model_value_dict["SPPump14"];
|
station1_scada_schedule.Pump15PM = model_value_dict["SPPump15"];
|
station1_scada_schedule.Pump16PM = model_value_dict["SPPump16"];
|
station1_scada_schedule.Pump17PM = model_value_dict["SPPump17"];
|
station1_scada_schedule.Pump18PM = model_value_dict["SPPump18"];
|
|
station1_scada_schedule.JD1FM = model_value_dict["SFJD1"];
|
station1_scada_schedule.JD2FM = model_value_dict["SFJD2"];
|
station1_scada_schedule.JD3FM = model_value_dict["SFJD3"];
|
|
station1_scada_schedule.Pump11M = model_value_dict["Pump11"];
|
station1_scada_schedule.Pump12M = model_value_dict["Pump12"];
|
station1_scada_schedule.Pump13M = model_value_dict["Pump13"];
|
station1_scada_schedule.Pump14M = model_value_dict["Pump14"];
|
station1_scada_schedule.Pump15M = model_value_dict["Pump15"];
|
station1_scada_schedule.Pump16M = model_value_dict["Pump16"];
|
station1_scada_schedule.Pump17M = model_value_dict["Pump17"];
|
station1_scada_schedule.Pump18M = model_value_dict["Pump18"];
|
station1_scada_schedule.Set();
|
|
if (string.IsNullOrEmpty(station1_scada_schedule.RunFlagsM))
|
{
|
continue;
|
}
|
scada_power_list.Add(station1_scada_schedule.TotalPower);
|
model_power_list.Add(station1_scada_schedule.TotalPowerM);
|
head_diff_jd1_list.Add(station1_scada_schedule.JD1PDiff);
|
head_diff_jd2_list.Add(station1_scada_schedule.JD2PDiff);
|
head_diff_jd3_list.Add(station1_scada_schedule.JD3PDiff);
|
|
|
scada_total_flow += station1_scada_schedule.TotalFlow;
|
model_total_flow += optimal_combine.TotalFlow;
|
|
}
|
|
if (head_diff_jd1_list.Any())
|
{
|
var scada_power_sum = scada_power_list.Sum();
|
var model_power_sum = model_power_list.Sum();
|
|
var energy_saving_ratio = (model_power_sum - scada_power_sum) / scada_power_sum;
|
var flow_loss_ratio = (model_total_flow - scada_total_flow) / scada_total_flow;
|
var head_diff_jd1 = head_diff_jd1_list.Average(x => Math.Abs(x ?? 0));
|
var head_diff_jd2 = head_diff_jd2_list.Average(x => Math.Abs(x ?? 0));
|
var head_diff_jd3 = head_diff_jd3_list.Average(x => Math.Abs(x ?? 0));
|
|
flow_loss_ratio = Math.Round(flow_loss_ratio * 100, 2);
|
energy_saving_ratio = Math.Round(energy_saving_ratio * 100, 2);
|
head_diff_jd1 = Math.Round(head_diff_jd1, 4);
|
head_diff_jd2 = Math.Round(head_diff_jd2, 4);
|
head_diff_jd3 = Math.Round(head_diff_jd3, 4);
|
msg = $"1输: 总功率:{energy_saving_ratio}% 流量:{flow_loss_ratio}% 嘉定1:{head_diff_jd1} 嘉定2:{head_diff_jd2} 嘉定3:{head_diff_jd3}";
|
|
}
|
else
|
{
|
msg = "1输:无效数据";
|
}
|
|
|
msg += "\r\n";
|
}
|
else
|
{
|
all_station1_scada_schedule_list.ForEach(x => x.Set());
|
}
|
|
if (use_station2)
|
{
|
var scada_power_list = new List<double>();
|
var model_power_list = new List<double>();
|
var head_diff_dn2400_list = new List<double?>();
|
var head_diff_dn2700_list = new List<double?>();
|
|
var scada_total_flow = 0d;
|
var model_total_flow = 0d;
|
foreach (var station2_scada_schedule in all_station2_scada_schedule_list)
|
{
|
var time = station2_scada_schedule.Time;
|
var run_flags = station2_scada_schedule.RunFlags;
|
var target_flow = station2_scada_schedule.TotalFlow;
|
var target_head = station2_scada_schedule.TotalHead;
|
|
var flag_inlet_water_level_dict = station2_scada_schedule.ToFlagInletWaterLevelDict();
|
var open_flag_list = IntListHelper.ToList(run_flags);
|
|
helper.Initial(open_flag_list, station2_schedule_config);
|
var optimal_combine = helper.GetOptAnaCombine(station2, flag_inlet_water_level_dict, target_flow, target_head);
|
if (optimal_combine == null)
|
{
|
continue;
|
}
|
|
|
|
station2_scada_schedule.ScheduleConclusion = new Model.ScheduleConclusion
|
{
|
ID = Yw.YitIdHelper.NextId(),
|
RequestID = 0,
|
Station = IStation.eDockingStation.Ch2s,
|
TotalFlow = optimal_combine.TotalFlow,
|
TotalPressure = optimal_combine.TotalPressure,
|
TotalPower = optimal_combine.TotalPower,
|
TotalEfficiency = optimal_combine.TotalEfficiency,
|
WP = optimal_combine.WP,
|
UWP = optimal_combine.UWP,
|
Flags = IntListHelper.ToString(optimal_combine.Flags),
|
MeritRatio = optimal_combine.MeritRatio
|
};
|
station2_scada_schedule.SchedulePumpList = new List<Model.SchedulePump>();
|
foreach (var fre_pump in optimal_combine.AnaFrePumps)
|
{
|
var schedule_pump = new Model.SchedulePump
|
{
|
RequestID = 0,
|
Station = IStation.eDockingStation.Ch2s,
|
Flag = fre_pump.Flag,
|
Flow = fre_pump.Flow,
|
Head = fre_pump.Head,
|
PressureDiff = fre_pump.PressureDiff,
|
Power = fre_pump.Power,
|
Efficiency = fre_pump.Eff,
|
Hz = fre_pump.Frequency,
|
Rpm = fre_pump.Speed
|
};
|
station2_scada_schedule.SchedulePumpList.Add(schedule_pump);
|
}
|
|
var pattern_dict = station2_scada_schedule.ToModelPatternDict();
|
|
var ana_fre_pump_list = optimal_combine.AnaFrePumps;
|
foreach (var item in _flag_pattern_dict2)
|
{
|
var flag = item.Key;
|
var pattern_id = item.Value;
|
var speed_ratio = 0f;
|
|
var ana_fre_pump = ana_fre_pump_list.Find(x => x.Flag == flag);
|
if (ana_fre_pump != null)
|
{
|
speed_ratio = (float)(ana_fre_pump.Frequency / 50);
|
}
|
pattern_dict[pattern_id] = new float[] { speed_ratio };
|
}
|
|
|
var model_value_dict = OutModelDict(link_count, node_count, model_id_build, pattern_dict, _pump_id_mapping_dict2, _flow_id_mapping_dict2, _pressure_id_mapping_dict2);
|
if (model_value_dict == null)
|
{
|
continue;
|
}
|
|
station2_scada_schedule.TotalPowerM += optimal_combine.TotalPower;
|
station2_scada_schedule.DN2400PM = model_value_dict["SPDN2400"];
|
station2_scada_schedule.DN2700PM = model_value_dict["SPDN2700"];
|
station2_scada_schedule.Pump21PM = model_value_dict["SPPump21"];
|
station2_scada_schedule.Pump22PM = model_value_dict["SPPump22"];
|
station2_scada_schedule.Pump23PM = model_value_dict["SPPump23"];
|
station2_scada_schedule.Pump24PM = model_value_dict["SPPump24"];
|
station2_scada_schedule.Pump25PM = model_value_dict["SPPump25"];
|
station2_scada_schedule.Pump26PM = model_value_dict["SPPump26"];
|
station2_scada_schedule.Pump27PM = model_value_dict["SPPump27"];
|
|
station2_scada_schedule.DN2400FM = model_value_dict["SFDN2400"];
|
station2_scada_schedule.DN2700FM = model_value_dict["SFDN2700"];
|
station2_scada_schedule.Pump21FM = model_value_dict["SFPump21"];
|
station2_scada_schedule.Pump22FM = model_value_dict["SFPump22"];
|
station2_scada_schedule.Pump23FM = model_value_dict["SFPump23"];
|
station2_scada_schedule.Pump24FM = model_value_dict["SFPump24"];
|
station2_scada_schedule.Pump25FM = model_value_dict["SFPump25"];
|
station2_scada_schedule.Pump26FM = model_value_dict["SFPump26"];
|
station2_scada_schedule.Pump27FM = model_value_dict["SFPump27"];
|
|
station2_scada_schedule.Pump21M = model_value_dict["Pump21"];
|
station2_scada_schedule.Pump22M = model_value_dict["Pump22"];
|
station2_scada_schedule.Pump23M = model_value_dict["Pump23"];
|
station2_scada_schedule.Pump24M = model_value_dict["Pump24"];
|
station2_scada_schedule.Pump25M = model_value_dict["Pump25"];
|
station2_scada_schedule.Pump26M = model_value_dict["Pump26"];
|
station2_scada_schedule.Pump27M = model_value_dict["Pump27"];
|
station2_scada_schedule.Set();
|
|
if (string.IsNullOrEmpty(station2_scada_schedule.RunFlagsM))
|
{
|
continue;
|
}
|
|
scada_power_list.Add(station2_scada_schedule.TotalPower);
|
model_power_list.Add(station2_scada_schedule.TotalPowerM);
|
head_diff_dn2400_list.Add(station2_scada_schedule.DN2400PDiff);
|
head_diff_dn2700_list.Add(station2_scada_schedule.DN2700PDiff);
|
|
scada_total_flow += station2_scada_schedule.TotalFlow;
|
model_total_flow += optimal_combine.TotalFlow;
|
}
|
|
if (head_diff_dn2400_list.Any())
|
{
|
var scada_power_sum = scada_power_list.Sum();
|
var model_power_sum = model_power_list.Sum();
|
|
var energy_saving_ratio = (model_power_sum - scada_power_sum) / scada_power_sum;
|
var flow_loss_ratio = (model_total_flow - scada_total_flow) / scada_total_flow;
|
var head_diff_dn2400 = head_diff_dn2400_list.Average(x => Math.Abs(x ?? 0));
|
var head_diff_dn2700 = head_diff_dn2700_list.Average(x => Math.Abs(x ?? 0));
|
|
flow_loss_ratio = Math.Round(flow_loss_ratio * 100, 2);
|
energy_saving_ratio = Math.Round(energy_saving_ratio * 100, 2);
|
head_diff_dn2400 = Math.Round(head_diff_dn2400, 4);
|
head_diff_dn2700 = Math.Round(head_diff_dn2700, 4);
|
|
msg += $"2输: 总功率:{energy_saving_ratio}% 流量:{flow_loss_ratio}% DN2400:{head_diff_dn2400} DN2700:{head_diff_dn2700}";
|
|
}
|
else
|
{
|
msg += $"2输: 无效数据";
|
}
|
}
|
else
|
{
|
all_station2_scada_schedule_list.ForEach(x => x.Set());
|
}
|
|
EpanetMethods.ENcloseH();
|
EpanetMethods.ENclose();
|
|
return msg;
|
}
|
|
|
|
//调度
|
public static string Schedule(
|
List<DayValue> day_value_list,
|
out List<Station1ScadaSchedule> all_station1_scada_schedule_list,
|
out List<Station2ScadaSchedule> all_station2_scada_schedule_list)
|
{
|
var msg = string.Empty;
|
all_station1_scada_schedule_list = new List<Station1ScadaSchedule>();
|
all_station2_scada_schedule_list = new List<Station2ScadaSchedule>();
|
if (day_value_list == null || !day_value_list.Any())
|
{
|
return msg;
|
}
|
|
AnalysisDeviationHelper.OutScadaScheduleVmList(
|
day_value_list,
|
out all_station1_scada_schedule_list,
|
out all_station2_scada_schedule_list);
|
|
|
if ((!all_station1_scada_schedule_list.Any()) && (!all_station2_scada_schedule_list.Any()))
|
{
|
return "存在单管流量为0的情况!";
|
}
|
|
|
var err = EpanetMethods.ENopen(_model_file, "", "");
|
if (err != ErrorCode.Ok)
|
return "err != ErrorCode.Ok";
|
|
err = EpanetMethods.ENopenH();
|
if (err != ErrorCode.Ok)
|
return "err != ErrorCode.Ok";
|
|
|
var model_id_build = new StringBuilder(31);
|
EpanetMethods.ENgetcount(CountType.Link, out int link_count);
|
EpanetMethods.ENgetcount(CountType.Node, out int node_count);
|
|
var all_request_list = _service_schedule_request.GetAll();
|
var request_ids = all_request_list.Select(x => x.ID).ToList();
|
|
var all_conclusion_list = _service_schedule_conclusion.GetByRequestIds(request_ids);
|
var all_pump_list = _service_schedule_pump.GetByRequestIds(request_ids);
|
|
{
|
var scada_power_list = new List<double>();
|
var model_power_list = new List<double>();
|
var head_diff_jd1_list = new List<double?>();
|
var head_diff_jd2_list = new List<double?>();
|
var head_diff_jd3_list = new List<double?>();
|
|
var scada_total_flow = 0d;
|
var model_total_flow = 0d;
|
|
foreach (var station1_scada_schedule in all_station1_scada_schedule_list)
|
{
|
var request = all_request_list.Find(x => x.ReceptionTime == station1_scada_schedule.Time);
|
if (request == null)
|
{
|
continue;
|
}
|
if (!request.ScheduleStatus1)
|
{
|
continue;
|
}
|
var request_id = request.ID;
|
var request_conclusion_list = all_conclusion_list.Where(x => x.RequestID == request_id).ToList();
|
var request_conclusion = request_conclusion_list.Find(x => x.Station == eDockingStation.Ch1s);
|
|
var request_pump_list = all_pump_list.Where(x => x.RequestID == request_id).ToList();
|
var ana_fre_pump_list = request_pump_list.Where(x => x.Station == eDockingStation.Ch1s).ToList();
|
|
|
var pattern_dict = station1_scada_schedule.ToModelPatternDict();
|
foreach (var item in _flag_pattern_dict1)
|
{
|
var flag = item.Key;
|
var pattern_id = item.Value;
|
var speed_ratio = 0f;
|
|
var ana_fre_pump = ana_fre_pump_list.Find(x => x.Flag == flag);
|
if (ana_fre_pump != null)
|
{
|
speed_ratio = (float)(ana_fre_pump.Hz / 50);
|
station1_scada_schedule.TotalPowerM += ana_fre_pump.Power;
|
}
|
pattern_dict[pattern_id] = new float[] { speed_ratio };
|
}
|
|
var model_value_dict = OutModelDict(link_count, node_count, model_id_build, pattern_dict, _pump_id_mapping_dict1, _flow_id_mapping_dict1, _pressure_id_mapping_dict1);
|
if (model_value_dict == null)
|
{
|
continue;
|
}
|
|
station1_scada_schedule.JD1PM = model_value_dict["SPJD1"];
|
station1_scada_schedule.JD2PM = model_value_dict["SPJD2"];
|
station1_scada_schedule.JD3PM = model_value_dict["SPJD3"];
|
station1_scada_schedule.Pump11PM = model_value_dict["SPPump11"];
|
station1_scada_schedule.Pump12PM = model_value_dict["SPPump12"];
|
station1_scada_schedule.Pump13PM = model_value_dict["SPPump13"];
|
station1_scada_schedule.Pump14PM = model_value_dict["SPPump14"];
|
station1_scada_schedule.Pump15PM = model_value_dict["SPPump15"];
|
station1_scada_schedule.Pump16PM = model_value_dict["SPPump16"];
|
station1_scada_schedule.Pump17PM = model_value_dict["SPPump17"];
|
station1_scada_schedule.Pump18PM = model_value_dict["SPPump18"];
|
|
station1_scada_schedule.JD1FM = model_value_dict["SFJD1"];
|
station1_scada_schedule.JD2FM = model_value_dict["SFJD2"];
|
station1_scada_schedule.JD3FM = model_value_dict["SFJD3"];
|
|
station1_scada_schedule.Pump11M = model_value_dict["Pump11"];
|
station1_scada_schedule.Pump12M = model_value_dict["Pump12"];
|
station1_scada_schedule.Pump13M = model_value_dict["Pump13"];
|
station1_scada_schedule.Pump14M = model_value_dict["Pump14"];
|
station1_scada_schedule.Pump15M = model_value_dict["Pump15"];
|
station1_scada_schedule.Pump16M = model_value_dict["Pump16"];
|
station1_scada_schedule.Pump17M = model_value_dict["Pump17"];
|
station1_scada_schedule.Pump18M = model_value_dict["Pump18"];
|
station1_scada_schedule.Set();
|
|
if (string.IsNullOrEmpty(station1_scada_schedule.RunFlagsM))
|
{
|
continue;
|
}
|
scada_power_list.Add(station1_scada_schedule.TotalPower);
|
model_power_list.Add(station1_scada_schedule.TotalPowerM);
|
head_diff_jd1_list.Add(station1_scada_schedule.JD1PDiff);
|
head_diff_jd2_list.Add(station1_scada_schedule.JD2PDiff);
|
head_diff_jd3_list.Add(station1_scada_schedule.JD3PDiff);
|
|
|
scada_total_flow += station1_scada_schedule.TotalFlow;
|
model_total_flow += request_conclusion.TotalFlow;
|
}
|
|
if (head_diff_jd1_list.Any())
|
{
|
var scada_power_sum = scada_power_list.Sum();
|
var model_power_sum = model_power_list.Sum();
|
|
var energy_saving_ratio = (model_power_sum - scada_power_sum) / scada_power_sum;
|
var flow_loss_ratio = (model_total_flow - scada_total_flow) / scada_total_flow;
|
var head_diff_jd1 = head_diff_jd1_list.Average(x => Math.Abs(x ?? 0));
|
var head_diff_jd2 = head_diff_jd2_list.Average(x => Math.Abs(x ?? 0));
|
var head_diff_jd3 = head_diff_jd3_list.Average(x => Math.Abs(x ?? 0));
|
|
flow_loss_ratio = Math.Round(flow_loss_ratio * 100, 2);
|
energy_saving_ratio = Math.Round(energy_saving_ratio * 100, 2);
|
head_diff_jd1 = Math.Round(head_diff_jd1, 4);
|
head_diff_jd2 = Math.Round(head_diff_jd2, 4);
|
head_diff_jd3 = Math.Round(head_diff_jd3, 4);
|
msg = $"1输: 总功率:{energy_saving_ratio}% 流量:{flow_loss_ratio}% 嘉定1:{head_diff_jd1} 嘉定2:{head_diff_jd2} 嘉定3:{head_diff_jd3}";
|
|
}
|
else
|
{
|
msg = "1输:无效数据";
|
}
|
msg += "\r\n";
|
}
|
|
{
|
var scada_power_list = new List<double>();
|
var model_power_list = new List<double>();
|
var head_diff_dn2400_list = new List<double?>();
|
var head_diff_dn2700_list = new List<double?>();
|
|
var scada_total_flow = 0d;
|
var model_total_flow = 0d;
|
foreach (var station2_scada_schedule in all_station2_scada_schedule_list)
|
{
|
var request = all_request_list.Find(x => x.ReceptionTime == station2_scada_schedule.Time);
|
if (request == null)
|
{
|
continue;
|
}
|
if (!request.ScheduleStatus2)
|
{
|
continue;
|
}
|
var request_id = request.ID;
|
var request_conclusion_list = all_conclusion_list.Where(x => x.RequestID == request_id).ToList();
|
var request_pump_list = all_pump_list.Where(x => x.RequestID == request_id).ToList();
|
var request_conclusion = request_conclusion_list.Find(x => x.Station == eDockingStation.Ch2s);
|
var ana_fre_pump_list = request_pump_list.Where(x => x.Station == eDockingStation.Ch2s).ToList();
|
|
|
var pattern_dict = station2_scada_schedule.ToModelPatternDict();
|
foreach (var item in _flag_pattern_dict2)
|
{
|
var flag = item.Key;
|
var pattern_id = item.Value;
|
var speed_ratio = 0f;
|
|
var ana_fre_pump = ana_fre_pump_list.Find(x => x.Flag == flag);
|
if (ana_fre_pump != null)
|
{
|
speed_ratio = (float)(ana_fre_pump.Hz / 50);
|
}
|
pattern_dict[pattern_id] = new float[] { speed_ratio };
|
}
|
|
|
var model_value_dict = OutModelDict(link_count, node_count, model_id_build, pattern_dict, _pump_id_mapping_dict2, _flow_id_mapping_dict2, _pressure_id_mapping_dict2);
|
if (model_value_dict == null)
|
{
|
continue;
|
}
|
|
station2_scada_schedule.TotalPowerM += request_conclusion.TotalPower;
|
station2_scada_schedule.DN2400PM = model_value_dict["SPDN2400"];
|
station2_scada_schedule.DN2700PM = model_value_dict["SPDN2700"];
|
station2_scada_schedule.Pump21PM = model_value_dict["SPPump21"];
|
station2_scada_schedule.Pump22PM = model_value_dict["SPPump22"];
|
station2_scada_schedule.Pump23PM = model_value_dict["SPPump23"];
|
station2_scada_schedule.Pump24PM = model_value_dict["SPPump24"];
|
station2_scada_schedule.Pump25PM = model_value_dict["SPPump25"];
|
station2_scada_schedule.Pump26PM = model_value_dict["SPPump26"];
|
station2_scada_schedule.Pump27PM = model_value_dict["SPPump27"];
|
|
station2_scada_schedule.DN2400FM = model_value_dict["SFDN2400"];
|
station2_scada_schedule.DN2700FM = model_value_dict["SFDN2700"];
|
station2_scada_schedule.Pump21FM = model_value_dict["SFPump21"];
|
station2_scada_schedule.Pump22FM = model_value_dict["SFPump22"];
|
station2_scada_schedule.Pump23FM = model_value_dict["SFPump23"];
|
station2_scada_schedule.Pump24FM = model_value_dict["SFPump24"];
|
station2_scada_schedule.Pump25FM = model_value_dict["SFPump25"];
|
station2_scada_schedule.Pump26FM = model_value_dict["SFPump26"];
|
station2_scada_schedule.Pump27FM = model_value_dict["SFPump27"];
|
|
station2_scada_schedule.Pump21M = model_value_dict["Pump21"];
|
station2_scada_schedule.Pump22M = model_value_dict["Pump22"];
|
station2_scada_schedule.Pump23M = model_value_dict["Pump23"];
|
station2_scada_schedule.Pump24M = model_value_dict["Pump24"];
|
station2_scada_schedule.Pump25M = model_value_dict["Pump25"];
|
station2_scada_schedule.Pump26M = model_value_dict["Pump26"];
|
station2_scada_schedule.Pump27M = model_value_dict["Pump27"];
|
station2_scada_schedule.Set();
|
|
if (string.IsNullOrEmpty(station2_scada_schedule.RunFlagsM))
|
{
|
continue;
|
}
|
|
scada_power_list.Add(station2_scada_schedule.TotalPower);
|
model_power_list.Add(station2_scada_schedule.TotalPowerM);
|
head_diff_dn2400_list.Add(station2_scada_schedule.DN2400PDiff);
|
head_diff_dn2700_list.Add(station2_scada_schedule.DN2700PDiff);
|
|
scada_total_flow += station2_scada_schedule.TotalFlow;
|
model_total_flow += request_conclusion.TotalFlow;
|
}
|
|
if (head_diff_dn2400_list.Any())
|
{
|
var scada_power_sum = scada_power_list.Sum();
|
var model_power_sum = model_power_list.Sum();
|
|
var energy_saving_ratio = (model_power_sum - scada_power_sum) / scada_power_sum;
|
var flow_loss_ratio = (model_total_flow - scada_total_flow) / scada_total_flow;
|
var head_diff_dn2400 = head_diff_dn2400_list.Average(x => Math.Abs(x ?? 0));
|
var head_diff_dn2700 = head_diff_dn2700_list.Average(x => Math.Abs(x ?? 0));
|
|
flow_loss_ratio = Math.Round(flow_loss_ratio * 100, 2);
|
energy_saving_ratio = Math.Round(energy_saving_ratio * 100, 2);
|
head_diff_dn2400 = Math.Round(head_diff_dn2400, 4);
|
head_diff_dn2700 = Math.Round(head_diff_dn2700, 4);
|
|
msg += $"2输: 总功率:{energy_saving_ratio}% 流量:{flow_loss_ratio}% DN2400:{head_diff_dn2400} DN2700:{head_diff_dn2700}";
|
|
}
|
else
|
{
|
msg += $"2输: 无效数据";
|
}
|
|
}
|
|
EpanetMethods.ENcloseH();
|
EpanetMethods.ENclose();
|
return msg;
|
}
|
|
|
//调度
|
public static string Schedule(
|
out List<Station1ScadaSchedule> all_station1_scada_schedule_list,
|
out List<Station2ScadaSchedule> all_station2_scada_schedule_list)
|
{
|
var msg = string.Empty;
|
all_station1_scada_schedule_list = new List<Station1ScadaSchedule>();
|
all_station2_scada_schedule_list = new List<Station2ScadaSchedule>();
|
|
|
var all_request_list = _service_schedule_request.GetAll();
|
var request_ids = all_request_list.Select(x => x.ID).ToList();
|
var all_scada_list = _service_schedule_scada.GetAll();
|
var limited_speed_ratio = 0.1;
|
var limited_min_flow = 100;
|
foreach (var request in all_request_list)
|
{
|
var scada_list = all_scada_list.Where(x => x.RequestID == request.ID).ToList();
|
if (scada_list == null || !scada_list.Any())
|
{
|
continue;
|
}
|
var scada_value_dict = scada_list.ToDictionary(x => x.Code, x => x.Value);
|
|
var vm1 = new Station1ScadaSchedule();
|
vm1.Time = request.ReceptionTime;
|
vm1.R1 = scada_value_dict[GlobalHelper.一输_新前池液位];
|
vm1.R2 = scada_value_dict[GlobalHelper.一输_老前池北侧液位];
|
vm1.R3 = scada_value_dict[GlobalHelper.一输_老前池南侧液位];
|
|
vm1.JD1P = scada_value_dict[GlobalHelper.嘉定1线_压力_长江管网图]/1000;
|
vm1.JD2P = scada_value_dict[GlobalHelper.嘉定2线_压力_长江管网图]/1000;
|
vm1.JD3P = scada_value_dict[GlobalHelper.嘉定3线_压力_长江管网图] / 1000;
|
vm1.Pump11P = scada_value_dict[GlobalHelper.一输11泵_出口压力]/1000;
|
vm1.Pump12P = scada_value_dict[GlobalHelper.一输12泵_出口压力]/1000;
|
vm1.Pump13P = scada_value_dict[GlobalHelper.一输13泵_出口压力]/1000;
|
vm1.Pump14P = scada_value_dict[GlobalHelper.一输14泵_出口压力]/1000;
|
vm1.Pump15P = scada_value_dict[GlobalHelper.一输15泵_出口压力]/1000;
|
vm1.Pump16P = scada_value_dict[GlobalHelper.一输16泵_出口压力]/1000;
|
vm1.Pump17P = scada_value_dict[GlobalHelper.一输17泵_出口压力]/1000;
|
vm1.Pump18P = scada_value_dict[GlobalHelper.一输18泵_出口压力] / 1000;
|
|
|
vm1.JD1P =Curve.PumpCalculateHelper.Mpa2M(vm1.JD1P ?? 0);
|
vm1.JD2P = Curve.PumpCalculateHelper.Mpa2M(vm1.JD2P ?? 0);
|
vm1.JD3P = Curve.PumpCalculateHelper.Mpa2M(vm1.JD3P ?? 0);
|
vm1.Pump11P = Curve.PumpCalculateHelper.Mpa2M(vm1.Pump11P??0);
|
vm1.Pump12P = Curve.PumpCalculateHelper.Mpa2M(vm1.Pump12P??0);
|
vm1.Pump13P = Curve.PumpCalculateHelper.Mpa2M(vm1.Pump13P??0);
|
vm1.Pump14P = Curve.PumpCalculateHelper.Mpa2M(vm1.Pump14P??0);
|
vm1.Pump15P = Curve.PumpCalculateHelper.Mpa2M(vm1.Pump15P??0);
|
vm1.Pump16P = Curve.PumpCalculateHelper.Mpa2M(vm1.Pump16P??0);
|
vm1.Pump17P = Curve.PumpCalculateHelper.Mpa2M(vm1.Pump17P??0);
|
vm1.Pump18P = Curve.PumpCalculateHelper.Mpa2M(vm1.Pump18P ?? 0);
|
|
vm1.JD1F = scada_value_dict[GlobalHelper.嘉定1线_瞬时流量_长江管网图];
|
vm1.JD2F = scada_value_dict[GlobalHelper.嘉定2线_瞬时流量_长江管网图];
|
vm1.JD3F = scada_value_dict[GlobalHelper.嘉定3线_瞬时流量_长江管网图];
|
|
vm1.Pump11 = scada_value_dict[GlobalHelper.一输11泵_转速] / 590;
|
vm1.Pump12 = scada_value_dict[GlobalHelper.一输12泵_转速] / 590;
|
vm1.Pump13 = scada_value_dict[GlobalHelper.一输13泵_转速] / 590;
|
vm1.Pump14 = scada_value_dict[GlobalHelper.一输14泵_转速] / 590;
|
vm1.Pump15 = scada_value_dict[GlobalHelper.一输15泵_运行状态];
|
vm1.Pump16 = scada_value_dict[GlobalHelper.一输16泵_运行状态];
|
vm1.Pump17 = scada_value_dict[GlobalHelper.一输17泵_转速] / 590;
|
vm1.Pump18 = scada_value_dict[GlobalHelper.一输18泵_转速] / 590;
|
|
var power11 = scada_value_dict[GlobalHelper.一输11泵_有功功率];
|
var power12 = scada_value_dict[GlobalHelper.一输12泵_有功功率];
|
var power13 = scada_value_dict[GlobalHelper.一输13泵_有功功率];
|
var power14 = scada_value_dict[GlobalHelper.一输14泵_有功功率];
|
var power15 = scada_value_dict[GlobalHelper.一输15泵_有功功率];
|
var power16 = scada_value_dict[GlobalHelper.一输16泵_有功功率];
|
var power17 = scada_value_dict[GlobalHelper.一输17泵_有功功率];
|
var power18 = scada_value_dict[GlobalHelper.一输18泵_有功功率];
|
|
vm1.TotalPower = (double)(power11 + power12 + power13 + power14 + power15 + power16 + power17 + power18);
|
|
vm1.Pump11 = vm1.Pump11 < limited_speed_ratio ? 0 : vm1.Pump11;
|
vm1.Pump12 = vm1.Pump12 < limited_speed_ratio ? 0 : vm1.Pump12;
|
vm1.Pump13 = vm1.Pump13 < limited_speed_ratio ? 0 : vm1.Pump13;
|
vm1.Pump14 = vm1.Pump14 < limited_speed_ratio ? 0 : vm1.Pump14;
|
vm1.Pump15 = vm1.Pump15 < limited_speed_ratio ? 0 : vm1.Pump15;
|
vm1.Pump16 = vm1.Pump16 < limited_speed_ratio ? 0 : vm1.Pump16;
|
vm1.Pump17 = vm1.Pump17 < limited_speed_ratio ? 0 : vm1.Pump17;
|
vm1.Pump18 = vm1.Pump18 < limited_speed_ratio ? 0 : vm1.Pump18;
|
|
var vm2 = new Station2ScadaSchedule();
|
vm2.Time = request.ReceptionTime;
|
vm2.RPump21 = scada_value_dict[GlobalHelper.二输21泵_泵井液位];
|
vm2.RPump22 = scada_value_dict[GlobalHelper.二输22泵_泵井液位];
|
vm2.RPump23 = scada_value_dict[GlobalHelper.二输23泵_泵井液位];
|
vm2.RPump24 = scada_value_dict[GlobalHelper.二输24泵_泵井液位];
|
vm2.RPump25 = scada_value_dict[GlobalHelper.二输25泵_泵井液位];
|
vm2.RPump26 = scada_value_dict[GlobalHelper.二输26泵_泵井液位];
|
vm2.RPump27 = scada_value_dict[GlobalHelper.二输27泵_泵井液位];
|
|
vm2.DN2400P = scada_value_dict[GlobalHelper.DN2700_出厂压力_长江管网图];
|
vm2.DN2700P = scada_value_dict[GlobalHelper.DN2400_出厂压力_长江管网图];
|
vm2.Pump21P = scada_value_dict[GlobalHelper.二输21泵_出水压力];
|
vm2.Pump22P = scada_value_dict[GlobalHelper.二输22泵_出水压力];
|
vm2.Pump23P = scada_value_dict[GlobalHelper.二输23泵_出水压力];
|
vm2.Pump24P = scada_value_dict[GlobalHelper.二输24泵_出水压力];
|
vm2.Pump25P = scada_value_dict[GlobalHelper.二输25泵_出水压力];
|
vm2.Pump26P = scada_value_dict[GlobalHelper.二输26泵_出水压力];
|
vm2.Pump27P = scada_value_dict[GlobalHelper.二输27泵_出水压力];
|
|
vm2.DN2400P = Curve.PumpCalculateHelper.Mpa2M(vm2.DN2400P ?? 0);
|
vm2.DN2700P = Curve.PumpCalculateHelper.Mpa2M(vm2.DN2700P ?? 0);
|
vm2.Pump21P = Curve.PumpCalculateHelper.Mpa2M(vm2.Pump21P?? 0);
|
vm2.Pump22P = Curve.PumpCalculateHelper.Mpa2M(vm2.Pump22P?? 0);
|
vm2.Pump23P = Curve.PumpCalculateHelper.Mpa2M(vm2.Pump23P?? 0);
|
vm2.Pump24P = Curve.PumpCalculateHelper.Mpa2M(vm2.Pump24P?? 0);
|
vm2.Pump25P = Curve.PumpCalculateHelper.Mpa2M(vm2.Pump25P?? 0);
|
vm2.Pump26P = Curve.PumpCalculateHelper.Mpa2M(vm2.Pump26P?? 0);
|
vm2.Pump27P = Curve.PumpCalculateHelper.Mpa2M(vm2.Pump27P?? 0);
|
|
vm2.DN2700F = scada_value_dict[GlobalHelper.DN2700总管_瞬时流量_长江管网图];
|
vm2.DN2400F = scada_value_dict[GlobalHelper.DN2400总管_瞬时流量_长江管网图];
|
vm2.Pump21F = scada_value_dict[GlobalHelper.二输21泵_瞬时流量];
|
vm2.Pump22F = scada_value_dict[GlobalHelper.二输22泵_瞬时流量];
|
vm2.Pump23F = scada_value_dict[GlobalHelper.二输23泵_瞬时流量];
|
vm2.Pump24F = scada_value_dict[GlobalHelper.二输24泵_瞬时流量];
|
vm2.Pump25F = scada_value_dict[GlobalHelper.二输25泵_瞬时流量];
|
vm2.Pump26F = scada_value_dict[GlobalHelper.二输26泵_瞬时流量];
|
vm2.Pump27F = scada_value_dict[GlobalHelper.二输27泵_瞬时流量];
|
|
vm2.Pump21 = scada_value_dict[GlobalHelper.二输21泵_转速] / 740;
|
vm2.Pump22 = scada_value_dict[GlobalHelper.二输22泵_转速] / 495;
|
vm2.Pump23 = scada_value_dict[GlobalHelper.二输23泵_转速] / 495;
|
vm2.Pump24 = scada_value_dict[GlobalHelper.二输24泵_转速] / 495;
|
vm2.Pump25 = scada_value_dict[GlobalHelper.二输25泵_转速] / 495;
|
vm2.Pump26 = scada_value_dict[GlobalHelper.二输26泵_转速] / 495;
|
vm2.Pump27 = scada_value_dict[GlobalHelper.二输27泵_转速] / 740;
|
|
var power21 = scada_value_dict[GlobalHelper.二输21泵_有功功率];
|
var power22 = scada_value_dict[GlobalHelper.二输22泵_有功功率];
|
var power23 = scada_value_dict[GlobalHelper.二输23泵_有功功率];
|
var power24 = scada_value_dict[GlobalHelper.二输24泵_有功功率];
|
var power25 = scada_value_dict[GlobalHelper.二输25泵_有功功率];
|
var power26 = scada_value_dict[GlobalHelper.二输26泵_有功功率];
|
var power27 = scada_value_dict[GlobalHelper.二输27泵_有功功率];
|
|
vm2.TotalPower = (double)(power21 + power22 + power23 + power24 + power25 + power26 + power27);
|
|
vm2.Pump21 = vm2.Pump21 < limited_speed_ratio ? 0 : vm2.Pump21;
|
vm2.Pump22 = vm2.Pump22 < limited_speed_ratio ? 0 : vm2.Pump22;
|
vm2.Pump23 = vm2.Pump23 < limited_speed_ratio ? 0 : vm2.Pump23;
|
vm2.Pump24 = vm2.Pump24 < limited_speed_ratio ? 0 : vm2.Pump24;
|
vm2.Pump25 = vm2.Pump25 < limited_speed_ratio ? 0 : vm2.Pump25;
|
vm2.Pump26 = vm2.Pump26 < limited_speed_ratio ? 0 : vm2.Pump26;
|
vm2.Pump27 = vm2.Pump27 < limited_speed_ratio ? 0 : vm2.Pump27;
|
|
if (vm1.JD1F < limited_min_flow || vm1.JD2F < limited_min_flow || vm1.JD3F < limited_min_flow)
|
{
|
continue;
|
}
|
|
if (vm2.DN2400F < limited_min_flow || vm2.DN2700F < limited_min_flow)
|
{
|
continue;
|
}
|
|
vm1.Sum();
|
vm2.Sum();
|
all_station1_scada_schedule_list.Add(vm1);
|
all_station2_scada_schedule_list.Add(vm2);
|
}
|
|
|
if ((!all_station1_scada_schedule_list.Any()) && (!all_station2_scada_schedule_list.Any()))
|
{
|
return "存在单管流量为0的情况!";
|
}
|
|
|
var err = EpanetMethods.ENopen(_model_file, "", "");
|
if (err != ErrorCode.Ok)
|
return "err != ErrorCode.Ok";
|
|
err = EpanetMethods.ENopenH();
|
if (err != ErrorCode.Ok)
|
return "err != ErrorCode.Ok";
|
|
|
var model_id_build = new StringBuilder(31);
|
EpanetMethods.ENgetcount(CountType.Link, out int link_count);
|
EpanetMethods.ENgetcount(CountType.Node, out int node_count);
|
|
|
|
var all_conclusion_list = _service_schedule_conclusion.GetByRequestIds(request_ids);
|
var all_pump_list = _service_schedule_pump.GetByRequestIds(request_ids);
|
|
{
|
var scada_power_list = new List<double>();
|
var model_power_list = new List<double>();
|
var head_diff_jd1_list = new List<double?>();
|
var head_diff_jd2_list = new List<double?>();
|
var head_diff_jd3_list = new List<double?>();
|
|
var scada_total_flow = 0d;
|
var model_total_flow = 0d;
|
|
foreach (var station1_scada_schedule in all_station1_scada_schedule_list)
|
{
|
var request = all_request_list.Find(x => x.ReceptionTime == station1_scada_schedule.Time);
|
if (request == null)
|
{
|
continue;
|
}
|
if (!request.ScheduleStatus1)
|
{
|
continue;
|
}
|
var request_id = request.ID;
|
var request_conclusion_list = all_conclusion_list.Where(x => x.RequestID == request_id).ToList();
|
var request_conclusion = request_conclusion_list.Find(x => x.Station == eDockingStation.Ch1s);
|
|
var request_pump_list = all_pump_list.Where(x => x.RequestID == request_id).ToList();
|
var ana_fre_pump_list = request_pump_list.Where(x => x.Station == eDockingStation.Ch1s).ToList();
|
|
|
var pattern_dict = station1_scada_schedule.ToModelPatternDict();
|
foreach (var item in _flag_pattern_dict1)
|
{
|
var flag = item.Key;
|
var pattern_id = item.Value;
|
var speed_ratio = 0f;
|
|
var ana_fre_pump = ana_fre_pump_list.Find(x => x.Flag == flag);
|
if (ana_fre_pump != null)
|
{
|
speed_ratio = (float)(ana_fre_pump.Hz / 50);
|
station1_scada_schedule.TotalPowerM += ana_fre_pump.Power;
|
}
|
pattern_dict[pattern_id] = new float[] { speed_ratio };
|
}
|
|
var model_value_dict = OutModelDict(link_count, node_count, model_id_build, pattern_dict, _pump_id_mapping_dict1, _flow_id_mapping_dict1, _pressure_id_mapping_dict1);
|
if (model_value_dict == null)
|
{
|
continue;
|
}
|
|
station1_scada_schedule.JD1PM = model_value_dict["SPJD1"];
|
station1_scada_schedule.JD2PM = model_value_dict["SPJD2"];
|
station1_scada_schedule.JD3PM = model_value_dict["SPJD3"];
|
station1_scada_schedule.Pump11PM = model_value_dict["SPPump11"];
|
station1_scada_schedule.Pump12PM = model_value_dict["SPPump12"];
|
station1_scada_schedule.Pump13PM = model_value_dict["SPPump13"];
|
station1_scada_schedule.Pump14PM = model_value_dict["SPPump14"];
|
station1_scada_schedule.Pump15PM = model_value_dict["SPPump15"];
|
station1_scada_schedule.Pump16PM = model_value_dict["SPPump16"];
|
station1_scada_schedule.Pump17PM = model_value_dict["SPPump17"];
|
station1_scada_schedule.Pump18PM = model_value_dict["SPPump18"];
|
|
station1_scada_schedule.JD1FM = model_value_dict["SFJD1"];
|
station1_scada_schedule.JD2FM = model_value_dict["SFJD2"];
|
station1_scada_schedule.JD3FM = model_value_dict["SFJD3"];
|
|
station1_scada_schedule.Pump11M = model_value_dict["Pump11"];
|
station1_scada_schedule.Pump12M = model_value_dict["Pump12"];
|
station1_scada_schedule.Pump13M = model_value_dict["Pump13"];
|
station1_scada_schedule.Pump14M = model_value_dict["Pump14"];
|
station1_scada_schedule.Pump15M = model_value_dict["Pump15"];
|
station1_scada_schedule.Pump16M = model_value_dict["Pump16"];
|
station1_scada_schedule.Pump17M = model_value_dict["Pump17"];
|
station1_scada_schedule.Pump18M = model_value_dict["Pump18"];
|
station1_scada_schedule.Set();
|
|
if (string.IsNullOrEmpty(station1_scada_schedule.RunFlagsM))
|
{
|
continue;
|
}
|
scada_power_list.Add(station1_scada_schedule.TotalPower);
|
model_power_list.Add(station1_scada_schedule.TotalPowerM);
|
head_diff_jd1_list.Add(station1_scada_schedule.JD1PDiff);
|
head_diff_jd2_list.Add(station1_scada_schedule.JD2PDiff);
|
head_diff_jd3_list.Add(station1_scada_schedule.JD3PDiff);
|
|
|
scada_total_flow += station1_scada_schedule.TotalFlow;
|
model_total_flow += request_conclusion.TotalFlow;
|
}
|
|
if (head_diff_jd1_list.Any())
|
{
|
var scada_power_sum = scada_power_list.Sum();
|
var model_power_sum = model_power_list.Sum();
|
|
var energy_saving_ratio = (model_power_sum - scada_power_sum) / scada_power_sum;
|
var flow_loss_ratio = (model_total_flow - scada_total_flow) / scada_total_flow;
|
var head_diff_jd1 = head_diff_jd1_list.Average(x => Math.Abs(x ?? 0));
|
var head_diff_jd2 = head_diff_jd2_list.Average(x => Math.Abs(x ?? 0));
|
var head_diff_jd3 = head_diff_jd3_list.Average(x => Math.Abs(x ?? 0));
|
|
flow_loss_ratio = Math.Round(flow_loss_ratio * 100, 2);
|
energy_saving_ratio = Math.Round(energy_saving_ratio * 100, 2);
|
head_diff_jd1 = Math.Round(head_diff_jd1, 4);
|
head_diff_jd2 = Math.Round(head_diff_jd2, 4);
|
head_diff_jd3 = Math.Round(head_diff_jd3, 4);
|
msg = $"1输: 总功率:{energy_saving_ratio}% 流量:{flow_loss_ratio}% 嘉定1:{head_diff_jd1} 嘉定2:{head_diff_jd2} 嘉定3:{head_diff_jd3}";
|
|
}
|
else
|
{
|
msg = "1输:无效数据";
|
}
|
msg += "\r\n";
|
}
|
|
{
|
var scada_power_list = new List<double>();
|
var model_power_list = new List<double>();
|
var head_diff_dn2400_list = new List<double?>();
|
var head_diff_dn2700_list = new List<double?>();
|
|
var scada_total_flow = 0d;
|
var model_total_flow = 0d;
|
foreach (var station2_scada_schedule in all_station2_scada_schedule_list)
|
{
|
var request = all_request_list.Find(x => x.ReceptionTime == station2_scada_schedule.Time);
|
if (request == null)
|
{
|
continue;
|
}
|
if (!request.ScheduleStatus2)
|
{
|
continue;
|
}
|
var request_id = request.ID;
|
var request_conclusion_list = all_conclusion_list.Where(x => x.RequestID == request_id).ToList();
|
var request_pump_list = all_pump_list.Where(x => x.RequestID == request_id).ToList();
|
var request_conclusion = request_conclusion_list.Find(x => x.Station == eDockingStation.Ch2s);
|
var ana_fre_pump_list = request_pump_list.Where(x => x.Station == eDockingStation.Ch2s).ToList();
|
|
|
var pattern_dict = station2_scada_schedule.ToModelPatternDict();
|
foreach (var item in _flag_pattern_dict2)
|
{
|
var flag = item.Key;
|
var pattern_id = item.Value;
|
var speed_ratio = 0f;
|
|
var ana_fre_pump = ana_fre_pump_list.Find(x => x.Flag == flag);
|
if (ana_fre_pump != null)
|
{
|
speed_ratio = (float)(ana_fre_pump.Hz / 50);
|
}
|
pattern_dict[pattern_id] = new float[] { speed_ratio };
|
}
|
|
|
var model_value_dict = OutModelDict(link_count, node_count, model_id_build, pattern_dict, _pump_id_mapping_dict2, _flow_id_mapping_dict2, _pressure_id_mapping_dict2);
|
if (model_value_dict == null)
|
{
|
continue;
|
}
|
|
station2_scada_schedule.TotalPowerM += request_conclusion.TotalPower;
|
station2_scada_schedule.DN2400PM = model_value_dict["SPDN2400"];
|
station2_scada_schedule.DN2700PM = model_value_dict["SPDN2700"];
|
station2_scada_schedule.Pump21PM = model_value_dict["SPPump21"];
|
station2_scada_schedule.Pump22PM = model_value_dict["SPPump22"];
|
station2_scada_schedule.Pump23PM = model_value_dict["SPPump23"];
|
station2_scada_schedule.Pump24PM = model_value_dict["SPPump24"];
|
station2_scada_schedule.Pump25PM = model_value_dict["SPPump25"];
|
station2_scada_schedule.Pump26PM = model_value_dict["SPPump26"];
|
station2_scada_schedule.Pump27PM = model_value_dict["SPPump27"];
|
|
station2_scada_schedule.DN2400FM = model_value_dict["SFDN2400"];
|
station2_scada_schedule.DN2700FM = model_value_dict["SFDN2700"];
|
station2_scada_schedule.Pump21FM = model_value_dict["SFPump21"];
|
station2_scada_schedule.Pump22FM = model_value_dict["SFPump22"];
|
station2_scada_schedule.Pump23FM = model_value_dict["SFPump23"];
|
station2_scada_schedule.Pump24FM = model_value_dict["SFPump24"];
|
station2_scada_schedule.Pump25FM = model_value_dict["SFPump25"];
|
station2_scada_schedule.Pump26FM = model_value_dict["SFPump26"];
|
station2_scada_schedule.Pump27FM = model_value_dict["SFPump27"];
|
|
station2_scada_schedule.Pump21M = model_value_dict["Pump21"];
|
station2_scada_schedule.Pump22M = model_value_dict["Pump22"];
|
station2_scada_schedule.Pump23M = model_value_dict["Pump23"];
|
station2_scada_schedule.Pump24M = model_value_dict["Pump24"];
|
station2_scada_schedule.Pump25M = model_value_dict["Pump25"];
|
station2_scada_schedule.Pump26M = model_value_dict["Pump26"];
|
station2_scada_schedule.Pump27M = model_value_dict["Pump27"];
|
station2_scada_schedule.Set();
|
|
if (string.IsNullOrEmpty(station2_scada_schedule.RunFlagsM))
|
{
|
continue;
|
}
|
|
scada_power_list.Add(station2_scada_schedule.TotalPower);
|
model_power_list.Add(station2_scada_schedule.TotalPowerM);
|
head_diff_dn2400_list.Add(station2_scada_schedule.DN2400PDiff);
|
head_diff_dn2700_list.Add(station2_scada_schedule.DN2700PDiff);
|
|
scada_total_flow += station2_scada_schedule.TotalFlow;
|
model_total_flow += request_conclusion.TotalFlow;
|
}
|
|
if (head_diff_dn2400_list.Any())
|
{
|
var scada_power_sum = scada_power_list.Sum();
|
var model_power_sum = model_power_list.Sum();
|
|
var energy_saving_ratio = (model_power_sum - scada_power_sum) / scada_power_sum;
|
var flow_loss_ratio = (model_total_flow - scada_total_flow) / scada_total_flow;
|
var head_diff_dn2400 = head_diff_dn2400_list.Average(x => Math.Abs(x ?? 0));
|
var head_diff_dn2700 = head_diff_dn2700_list.Average(x => Math.Abs(x ?? 0));
|
|
flow_loss_ratio = Math.Round(flow_loss_ratio * 100, 2);
|
energy_saving_ratio = Math.Round(energy_saving_ratio * 100, 2);
|
head_diff_dn2400 = Math.Round(head_diff_dn2400, 4);
|
head_diff_dn2700 = Math.Round(head_diff_dn2700, 4);
|
|
msg += $"2输: 总功率:{energy_saving_ratio}% 流量:{flow_loss_ratio}% DN2400:{head_diff_dn2400} DN2700:{head_diff_dn2700}";
|
|
}
|
else
|
{
|
msg += $"2输: 无效数据";
|
}
|
|
}
|
|
EpanetMethods.ENcloseH();
|
EpanetMethods.ENclose();
|
return msg;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
private static Dictionary<string, double> OutModelDict(
|
int link_count,
|
int node_count,
|
StringBuilder model_id_build,
|
Dictionary<string, float[]> pattern_dict,
|
Dictionary<string, string> pump_id_mapping_dict,
|
Dictionary<string, string> flow_id_mapping_dict,
|
Dictionary<string, string> pressure_id_mapping_dict)
|
{
|
var pattern_init = true;
|
foreach (var pattern in pattern_dict)
|
{
|
var pattern_id = pattern.Key;
|
var pattern_factor_array = pattern.Value;
|
var pattern_factor_array_count = pattern_factor_array.Length == 0 ? 1 : pattern_factor_array.Length;
|
var err = EpanetMethods.ENgetpatternindex(pattern_id, out int pattern_index);
|
if (err != ErrorCode.Ok)
|
{
|
pattern_init = false;
|
continue;
|
}
|
err = EpanetMethods.ENsetpattern(pattern_index, pattern_factor_array, pattern_factor_array_count);
|
if (err != ErrorCode.Ok)
|
{
|
pattern_init = false;
|
continue;
|
}
|
}
|
if (!pattern_init)
|
return default;
|
|
EpanetMethods.ENinitH(0);
|
EpanetMethods.ENrunH(out _);
|
|
var model_value_dict = new Dictionary<string, double>();
|
for (int link_index = 1; link_index <= link_count; link_index++)
|
{
|
if (EpanetMethods.ENgetlinkid(link_index, model_id_build) != ErrorCode.Ok)
|
continue;
|
var model_id = model_id_build.ToString();
|
if (flow_id_mapping_dict.ContainsKey(model_id))
|
{
|
EpanetMethods.ENgetlinkvalue(link_index, LinkValue.Flow, out float model_flow);
|
var scada_id = flow_id_mapping_dict[model_id];
|
model_value_dict.Add(scada_id, model_flow);
|
}
|
|
EpanetMethods.ENgetlinktype(link_index, out LinkType linkType);
|
if (linkType == LinkType.Pump)
|
{
|
if (pump_id_mapping_dict.ContainsKey(model_id))
|
{
|
EpanetMethods.ENgetlinkvalue(link_index, LinkValue.Setting, out float model_pump);
|
var scada_id = pump_id_mapping_dict[model_id];
|
model_value_dict.Add(scada_id, model_pump);
|
}
|
}
|
}
|
|
for (int node_index = 1; node_index <= node_count; node_index++)
|
{
|
if (EpanetMethods.ENgetnodeid(node_index, model_id_build) != ErrorCode.Ok)
|
continue;
|
var model_id = model_id_build.ToString();
|
if (pressure_id_mapping_dict.ContainsKey(model_id))
|
{
|
EpanetMethods.ENgetnodevalue(node_index, NodeValue.Head, out float model_head);
|
var scada_id = pressure_id_mapping_dict[model_id];
|
model_value_dict.Add(scada_id, model_head);
|
}
|
}
|
|
return model_value_dict;
|
}
|
|
|
}
|
}
|