using IStation.Curve;
|
using System.Linq;
|
using Yw;
|
using static IStation.Algorithm.ScheduleHelper;
|
|
namespace IStation
|
{
|
/// <summary>
|
/// Scada 模型验证
|
/// </summary>
|
public class ScadaModelValidHelper
|
{
|
#region 实时数据 Analysis
|
|
public static bool Analysis()
|
{
|
var model_file_path = $"{AppDomain.CurrentDomain.BaseDirectory}Data\\HydraulicModel.inp";
|
if (!File.Exists(model_file_path))
|
return false;
|
|
var data_foler_path = $"{AppDomain.CurrentDomain.BaseDirectory}Data\\实时数据";
|
if (!Directory.Exists(data_foler_path))
|
{
|
return false;
|
}
|
var data_file_path_list = Directory.GetFiles(data_foler_path);
|
if (data_file_path_list == null || !data_file_path_list.Any())
|
{
|
return false;
|
}
|
var now = DateTime.Now;
|
|
var zy_scada_day_dict = new Dictionary<DateTime, Dictionary<DateTime, List<Model.ZyScada>>>();
|
var zy_scada_dict = new Dictionary<DateTime, List<Model.ZyScada>>();
|
foreach (var file_path in data_file_path_list)
|
{
|
var file_json = File.ReadAllText(file_path);
|
var zy_scada_list = JsonHelper.Json2Object<List<Model.ZyScada>>(file_json);
|
if (zy_scada_list == null || !zy_scada_list.Any())
|
{
|
continue;
|
}
|
var file_name = Path.GetFileNameWithoutExtension(file_path);
|
var split_name = file_name.Split("-").Select(x => int.Parse(x)).ToArray();
|
|
var time = new DateTime(now.Year, now.Month, now.Day, split_name[0], split_name[1], split_name[2]);
|
if (zy_scada_dict.Any())
|
{
|
var last = zy_scada_dict.Last().Value.Find(x => x.Code == "10157");
|
var current = zy_scada_list.Find(x => x.Code == "10157");
|
if (last?.Value == current?.Value)
|
{
|
continue;
|
}
|
}
|
zy_scada_dict.Add(time, zy_scada_list);
|
}
|
zy_scada_day_dict.Add(now, zy_scada_dict);
|
|
//var hydraulic_record_list_dict = IStation.Hydraulic.ModeVerifyHelper.Verify(1, model_file_path, zy_scada_day_dict);
|
|
//Console.WriteLine("Scada代入模型验证");
|
//Console.WriteLine("Time Jd1 Jd2 Jd3 dn2400 dn2700");
|
//foreach (var item in hydraulic_record_list_dict)
|
//{
|
// var time = item.Key;
|
// var diff_dict = item.Value.ToDictionary(x => x.ModelId, y => Math.Round(y.DifferenceValue ?? -999, 4));
|
// Console.WriteLine($"{time:T} {diff_dict["Jjd1"]} {diff_dict["Jjd2"]} {diff_dict["Jjd3"]} {diff_dict["Jdn2400"]} {diff_dict["Jdn2700"]}");
|
//}
|
|
|
IStation.Service.Station _service_station = new();
|
IStation.Service.ScheduleConfig _service_schedule_config = new();
|
var station_info = _service_station.Get();
|
|
var station1 = station_info.Station1;
|
var station2 = station_info.Station2;
|
var station1_same_type_flag_group_first = GlobalHelper.Station1SameTypeFlagGroupFirst;
|
var station2_same_type_flag_group_first = GlobalHelper.Station2SameTypeFlagGroupFirst;
|
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;
|
|
Console.WriteLine("time flag wl scada ana diff ");
|
|
List<Tuple<DateTime, int, double, double, double, double>> ana_pump_value_list = new List<Tuple<DateTime, int, double, double, double, double>>();
|
foreach (var zy_scada_day in zy_scada_day_dict)
|
{
|
var time = zy_scada_day.Key;
|
foreach (var item in zy_scada_day.Value)
|
{
|
var time2 = item.Key;
|
var zy_scada_list = item.Value;
|
if (!OutTarget(zy_scada_list, out double target_flow1, out double target_head1, out double target_flow2, out double target_head2))
|
{
|
continue;
|
}
|
if (!OutRpm(zy_scada_list, out Dictionary<int, double> station1_flag_rpm_dict, out Dictionary<int, double> station2_flag_rpm_dict))
|
{
|
continue;
|
}
|
|
if (!OutHead(zy_scada_list, out Dictionary<int, double> station1_flag_head_dict, out Dictionary<int, double> station2_flag_head_dict))
|
{
|
continue;
|
}
|
|
|
if (!OutFlow(zy_scada_list, out Dictionary<int, double> station1_flag_flow_dict, out Dictionary<int, double> station2_flag_flow_dict))
|
{
|
continue;
|
}
|
|
GlobalHelper.GetFlagInletWaterLevelDict(zy_scada_list, out Dictionary<int, double> station1_flag_inlet_water_level_dict, out Dictionary<int, double> station2_flag_inlet_water_level_dict);
|
|
var ana_pump_list2 = GetOptAnaPumpListByFlow(station2, station2_flag_rpm_dict, station2_flag_flow_dict);
|
foreach (var ana_pump in ana_pump_list2)
|
{
|
var flag = ana_pump.Flag;
|
var wl = station2_flag_inlet_water_level_dict[flag];
|
var scada_head = station2_flag_head_dict[flag];
|
var ana_head = ana_pump.Head;
|
var diff_head = ana_head - (scada_head - wl);
|
|
ana_pump_value_list.Add(new(time2, flag, wl, scada_head, ana_head, diff_head));
|
// Console.WriteLine($"{time:T} {flag} {wl:N2} {scada_head:N4} {ana_head:N4} {diff_head:N4}");
|
}
|
|
#region 调度
|
|
|
//if (station1_maintenance_flag_list != null && station1_maintenance_flag_list.Any())
|
// station1_schedule_config.MustCloseFlagList.AddRange(station1_maintenance_flag_list);
|
|
//if (station2_maintenance_flag_list != null && station2_maintenance_flag_list.Any())
|
// station2_schedule_config.MustCloseFlagList.AddRange(station2_maintenance_flag_list);
|
|
//var helper = new Algorithm.ScheduleHelper();
|
//helper.Initial(station1_open_flag_list, station1_schedule_config);
|
//var optimal_combine1 = helper.GetOptAnaCombine(station1, station1_same_type_flag_group_first, station1_flag_inlet_water_level_dict, station1_flag_cumulative_run_time_dict, target_flow1, target_head1);
|
|
|
|
//helper.Initial(station2_open_flag_list, station2_schedule_config);
|
//var optimal_combine2 = helper.GetOptAnaCombine(station2, station2_same_type_flag_group_first, station2_flag_inlet_water_level_dict, station2_flag_cumulative_run_time_dict, target_flow2, target_head2);
|
|
#endregion
|
|
}
|
}
|
|
|
var group = ana_pump_value_list.GroupBy(x => x.Item2);
|
foreach (var item in group)
|
{
|
var flag = item.Key;
|
foreach (var item2 in item)
|
{
|
Console.WriteLine($"{item2.Item1:T} {flag} {item2.Item3:N2} {item2.Item4:N4} {item2.Item5:N4} {item2.Item6:N4}");
|
}
|
Console.WriteLine();
|
Console.WriteLine();
|
Console.WriteLine();
|
}
|
|
Console.WriteLine();
|
Console.WriteLine();
|
Console.WriteLine();
|
foreach (var item in group)
|
{
|
var flag = item.Key;
|
var value = item.Average(x => x.Item6);
|
Console.WriteLine($"{flag} {value} ");
|
}
|
|
return true;
|
}
|
|
|
private static bool OutTarget(List<Model.ZyScada> zy_scada_list, out double target_flow1, out double target_head1, out double target_flow2, out double target_head2)
|
{
|
var scada_dict = zy_scada_list.ToDictionary(x => x.Code, y => y.Value);
|
|
var jd1_flow = scada_dict[GlobalHelper.嘉定1线_瞬时流量_长江管网图];
|
var jd2_flow = scada_dict[GlobalHelper.嘉定2线_瞬时流量_长江管网图];
|
var jd3_flow = scada_dict[GlobalHelper.嘉定3线_瞬时流量_长江管网图];
|
|
var jd1_pressure = scada_dict[GlobalHelper.嘉定1线_压力_长江管网图];
|
var jd2_pressure = scada_dict[GlobalHelper.嘉定2线_压力_长江管网图];
|
var jd3_pressure = scada_dict[GlobalHelper.嘉定3线_压力_长江管网图];
|
|
var dn24_flow = scada_dict[GlobalHelper.DN2400总管_瞬时流量_长江管网图];
|
var dn27_flow = scada_dict[GlobalHelper.DN2700总管_瞬时流量_长江管网图];
|
|
var dn24_pressure = scada_dict[GlobalHelper.DN2400_出厂压力_长江管网图];
|
var dn27_pressure = scada_dict[GlobalHelper.DN2700_出厂压力_长江管网图];
|
|
|
target_flow1 = 0;
|
target_head1 = 0;
|
target_flow2 = 0;
|
target_head2 = 0;
|
|
if (jd1_flow < 0 || jd2_flow < 0 || jd3_flow < 0)
|
{
|
return false;
|
}
|
|
if (dn24_flow < 0 || dn27_flow < 0)
|
{
|
return false;
|
}
|
|
|
if (jd1_pressure < 0 || jd2_pressure < 0 || jd3_pressure < 0)
|
{
|
return false;
|
}
|
|
if (dn24_pressure < 0 || dn27_pressure < 0)
|
{
|
return false;
|
}
|
|
var max_pressure1 = new List<double?>() { jd1_pressure, jd2_pressure, jd3_pressure }.Max();
|
var head1 = IStation.Curve.PumpCalculateHelper.Mpa2M(max_pressure1.Value);
|
|
var max_pressure2 = new List<double?>() { dn24_pressure, dn27_pressure }.Max();
|
var head2 = IStation.Curve.PumpCalculateHelper.Mpa2M(max_pressure2.Value);
|
|
target_flow1 = jd1_flow.Value + jd2_flow.Value + jd3_flow.Value;
|
target_head1 = head1;
|
target_flow2 = dn24_flow.Value + dn27_flow.Value;
|
target_head2 = head2;
|
|
return true;
|
|
}
|
|
private static bool OutRpm(List<Model.ZyScada> zy_scada_list, out Dictionary<int, double> station1_flag_rpm_dict, out Dictionary<int, double> station2_flag_rpm_dict)
|
{
|
|
station1_flag_rpm_dict = new Dictionary<int, double>();
|
station2_flag_rpm_dict = new Dictionary<int, double>();
|
|
foreach (var mapping in GlobalHelper.FlagNrMappingDict1)
|
{
|
var code = mapping.Value;
|
var zy_scada = zy_scada_list.Find(x => x.Code == code);
|
if (zy_scada == null)
|
continue;
|
station1_flag_rpm_dict.Add(mapping.Key, zy_scada.Value ?? 0);
|
}
|
|
|
foreach (var mapping in GlobalHelper.FlagNrMappingDict2)
|
{
|
var code = mapping.Value;
|
var zy_scada = zy_scada_list.Find(x => x.Code == code);
|
if (zy_scada == null)
|
continue;
|
station2_flag_rpm_dict.Add(mapping.Key, zy_scada.Value ?? 0);
|
}
|
|
return true;
|
|
}
|
|
private static bool OutHead(List<Model.ZyScada> zy_scada_list, out Dictionary<int, double> station1_flag_head_dict, out Dictionary<int, double> station2_flag_head_dict)
|
{
|
|
station1_flag_head_dict = new Dictionary<int, double>();
|
station2_flag_head_dict = new Dictionary<int, double>();
|
|
foreach (var mapping in GlobalHelper.FlagOutletPressureMappingDict1)
|
{
|
var code = mapping.Value;
|
var zy_scada = zy_scada_list.Find(x => x.Code == code);
|
if (zy_scada == null)
|
continue;
|
var value = (zy_scada.Value ?? 0) / 1000;
|
var head = IStation.Curve.PumpCalculateHelper.Mpa2M(value);
|
station1_flag_head_dict.Add(mapping.Key, head);
|
}
|
|
|
foreach (var mapping in GlobalHelper.FlagOutletPressureMappingDict2)
|
{
|
var code = mapping.Value;
|
var zy_scada = zy_scada_list.Find(x => x.Code == code);
|
if (zy_scada == null)
|
continue;
|
var value = (zy_scada.Value ?? 0);
|
var head = IStation.Curve.PumpCalculateHelper.Mpa2M(value);
|
station2_flag_head_dict.Add(mapping.Key, head);
|
}
|
|
return true;
|
|
}
|
|
private static bool OutFlow(List<Model.ZyScada> zy_scada_list, out Dictionary<int, double> station1_flag_flow_dict, out Dictionary<int, double> station2_flag_flow_dict)
|
{
|
station1_flag_flow_dict = new Dictionary<int, double>();
|
station2_flag_flow_dict = new Dictionary<int, double>();
|
foreach (var mapping in GlobalHelper.FlagOutletFlowMappingDict2)
|
{
|
var code = mapping.Value;
|
var zy_scada = zy_scada_list.Find(x => x.Code == code);
|
if (zy_scada == null)
|
continue;
|
station2_flag_flow_dict.Add(mapping.Key, zy_scada.Value ?? 0);
|
}
|
|
return true;
|
}
|
|
private static List<AnaFrePump> GetOptAnaPumpListByFlow(
|
List<Model.Pump> pumps,
|
Dictionary<int, double> flag_rpm_dic,
|
Dictionary<int, double> flag_flow_dic
|
)
|
{
|
if (pumps == null || !pumps.Any())
|
{
|
return default;
|
}
|
|
if (flag_rpm_dic == null || !flag_rpm_dic.Any())
|
{
|
return default;
|
}
|
|
double total_flow = 0;
|
double total_power = 0;
|
var ana_fre_pump_list = new List<AnaFrePump>();
|
foreach (var item in flag_rpm_dic)
|
{
|
var pump = pumps.Find(x => x.Flag == item.Key);
|
if (pump == null)
|
continue;
|
var rpm = Math.Round(item.Value, 1);
|
if (rpm == 0)
|
continue;
|
if (rpm<1)
|
{
|
continue;
|
}
|
var curveQH = Curve.PumpCalculateHelper.CalculateSimilarQH(pump.CurveQH, pump.Nr, rpm);
|
var curveQP = Curve.PumpCalculateHelper.CalculateSimilarQP(pump.CurveQP, pump.Nr, rpm);
|
|
double flow = 0, head = 0;
|
|
if (flag_flow_dic != null && flag_flow_dic.ContainsKey(pump.Flag))
|
{
|
flow = flag_flow_dic[pump.Flag];
|
}
|
|
|
head = curveQH.GetFitPointY(flow);
|
if (head < 0)
|
continue;
|
|
var fre_pump = new AnaFrePump();
|
fre_pump.Flag = item.Key;
|
fre_pump.Flow = flow;
|
fre_pump.Head = head;
|
fre_pump.Power = curveQP.GetFitPointY(flow);
|
fre_pump.Efficiency = Curve.PumpCalculateHelper.CalculateE(fre_pump.Flow, fre_pump.Head, fre_pump.Power);
|
fre_pump.Frequency = rpm / pump.Nr * 50;
|
fre_pump.Speed = rpm;
|
|
|
total_flow += flow;
|
total_power += fre_pump.Power;
|
ana_fre_pump_list.Add(fre_pump);
|
}
|
|
|
return ana_fre_pump_list;
|
}
|
|
#endregion
|
|
#region 实时数据 Analysis
|
|
public static bool Analysis2()
|
{
|
var dt = new DateTime(2024, 2, 7);
|
var day_value = IStation.DayValueHelper.GetDayValue(dt);
|
if (day_value == null)
|
return false;
|
var time_value_list = day_value.TimeValueList;
|
|
var pressure_id_mapping_dict = 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" },
|
|
{"Jdn2400","SPDN2400"},
|
{"Jdn2700","SPDN2700"},
|
{"Jpump21","SPPump21"},
|
{"Jpump22","SPPump22"},
|
{"Jpump23","SPPump23"},
|
{"Jpump24","SPPump24"},
|
{"Jpump25","SPPump25"},
|
{"Jpump26","SPPump26"},
|
{"Jpump27","SPPump27"}
|
};
|
var flow_id_mapping_dict = new Dictionary<string, string>()
|
{
|
{"Pjd1","SFJD1"},
|
{"Pjd2","SFJD2"},
|
{"Pjd3","SFJD3"},
|
|
{"Pdn2400","SFDN2400"},
|
{"Pdn2700","SFDN2700"},
|
{"Ppump21","SFPump21"},
|
{"Ppump22","SFPump22"},
|
{"Ppump23","SFPump23"},
|
{"Ppump24","SFPump24"},
|
{"Ppump25","SFPump25"},
|
{"Ppump26","SFPump26"},
|
{"Ppump27","SFPump27"}
|
};
|
var pattern_id_mapping_dict = new Dictionary<string, string>()
|
{
|
{"R3", "R3"},
|
{"R2", "R2"},
|
{"R1", "R1"},
|
{"Pump11", "Pump11"},
|
{"Pump12", "Pump12"},
|
{"Pump13", "Pump13"},
|
{"Pump14", "Pump14"},
|
{"Pump15", "Pump15"},
|
{"Pump16", "Pump16"},
|
{"Pump17", "Pump17"},
|
{"Pump18", "Pump18"},
|
{"SFJD1", "SFJD1"},
|
{"SFJD2", "SFJD2"},
|
{"SFJD3", "SFJD3"},
|
|
{"RPump21", "RPump21"},
|
{"RPump22", "RPump22"},
|
{"RPump23", "RPump23"},
|
{"RPump24", "RPump24"},
|
{"RPump25", "RPump25"},
|
{"RPump26", "RPump26"},
|
{"RPump27", "RPump27"},
|
{"Pump21", "Pump21"},
|
{"Pump22", "Pump22"},
|
{"Pump23", "Pump23"},
|
{"Pump24", "Pump24"},
|
{"Pump25", "Pump25"},
|
{"Pump26", "Pump26"},
|
{"Pump27", "Pump27"},
|
{"SFPump21", "SFPump21"},
|
{"SFPump22", "SFPump22"},
|
{"SFPump23", "SFPump23"},
|
{"SFPump24", "SFPump24"},
|
{"SFPump25", "SFPump25"},
|
{"SFPump26", "SFPump26"},
|
{"SFPump27", "SFPump27"},
|
{"SFDN2400", "SFDN2400"},
|
{"SFDN2700", "SFDN2700"},
|
};
|
|
IStation.Service.Station _service_station = new();
|
IStation.Service.ScheduleConfig _service_schedule_config = new();
|
var station_info = _service_station.Get();
|
|
var station1 = station_info.Station1;
|
var station2 = station_info.Station2;
|
var station1_same_type_flag_group_first = GlobalHelper.Station1SameTypeFlagGroupFirst;
|
var station2_same_type_flag_group_first = GlobalHelper.Station2SameTypeFlagGroupFirst;
|
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;
|
|
Console.WriteLine("time flag wl scada ana diff ");
|
|
List<Tuple<DateTime, int, double, double, double, double>> ana_pump_value_list = new List<Tuple<DateTime, int, double, double, double, double>>();
|
foreach (var zy_scada_day in time_value_list)
|
{
|
var time = zy_scada_day.Time;
|
var zy_scada_dict = zy_scada_day.Value;
|
|
if (!OutTarget(zy_scada_dict, out double target_flow1, out double target_head1, out double target_flow2, out double target_head2))
|
{
|
continue;
|
}
|
if (!OutRpm(zy_scada_dict, out Dictionary<int, double> station1_flag_rpm_dict, out Dictionary<int, double> station2_flag_rpm_dict))
|
{
|
continue;
|
}
|
|
if (!OutHead(zy_scada_dict, out Dictionary<int, double> station1_flag_head_dict, out Dictionary<int, double> station2_flag_head_dict))
|
{
|
continue;
|
}
|
|
|
if (!OutFlow(zy_scada_dict, out Dictionary<int, double> station1_flag_flow_dict, out Dictionary<int, double> station2_flag_flow_dict))
|
{
|
continue;
|
}
|
OutWaterLevel(zy_scada_dict, out Dictionary<int, double> station1_flag_inlet_water_level_dict, out Dictionary<int, double> station2_flag_inlet_water_level_dict);
|
|
|
//var ana_pump_list1 = GetOptAnaPumpListByFlow(station1, station1_flag_rpm_dict, station1_flag_flow_dict);
|
//foreach (var ana_pump in ana_pump_list1)
|
//{
|
// var flag = ana_pump.Flag;
|
// var wl = station1_flag_inlet_water_level_dict[flag];
|
// var scada_head = station1_flag_head_dict[flag];
|
// var ana_head = ana_pump.Head;
|
// var diff_head = ana_head - (scada_head - wl);
|
|
// ana_pump_value_list.Add(new(time, flag, wl, scada_head, ana_head, diff_head));
|
//}
|
|
var ana_pump_list2 = GetOptAnaPumpListByFlow(station2, station2_flag_rpm_dict, station2_flag_flow_dict);
|
foreach (var ana_pump in ana_pump_list2)
|
{
|
var flag = ana_pump.Flag;
|
var wl = station2_flag_inlet_water_level_dict[flag];
|
var scada_head = station2_flag_head_dict[flag];
|
var ana_head = ana_pump.Head;
|
var diff_head = ana_head - (scada_head - wl);
|
|
ana_pump_value_list.Add(new(time, flag, wl, scada_head, ana_head, diff_head));
|
}
|
}
|
|
|
var group = ana_pump_value_list.GroupBy(x => x.Item2);
|
foreach (var item in group)
|
{
|
var flag = item.Key;
|
foreach (var item2 in item)
|
{
|
Console.WriteLine($"{item2.Item1:T} {flag} {item2.Item3:N2} {item2.Item4:N4} {item2.Item5:N4} {item2.Item6:N4}");
|
}
|
Console.WriteLine();
|
Console.WriteLine();
|
Console.WriteLine();
|
}
|
|
Console.WriteLine("平均数");
|
Console.WriteLine();
|
Console.WriteLine();
|
foreach (var item in group)
|
{
|
|
var flag = item.Key;
|
var value = item.Average(x => x.Item6);
|
Console.WriteLine($"{flag}: {value} ");
|
}
|
|
Console.WriteLine();
|
Console.WriteLine();
|
Console.WriteLine("众数");
|
Console.WriteLine();
|
Console.WriteLine();
|
foreach (var item in group)
|
{
|
//Console.WriteLine($"{flag}: {value} ");
|
var flag = item.Key;
|
var value = item.Average(x => x.Item6);
|
var nums = item.Select(x => Math.Round(x.Item6, 2)).ToArray();
|
|
var array = ModeHelper.ModeOf(nums);
|
Console.WriteLine($"{flag}:");
|
foreach (var vls in array)
|
{
|
Console.WriteLine(" " + vls);
|
}
|
}
|
|
|
return true;
|
}
|
|
public static bool Analysis3()
|
{
|
var pressure_id_mapping_dict = 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" },
|
|
{"Jdn2400","SPDN2400"},
|
{"Jdn2700","SPDN2700"},
|
{"Jpump21","SPPump21"},
|
{"Jpump22","SPPump22"},
|
{"Jpump23","SPPump23"},
|
{"Jpump24","SPPump24"},
|
{"Jpump25","SPPump25"},
|
{"Jpump26","SPPump26"},
|
{"Jpump27","SPPump27"}
|
};
|
var flow_id_mapping_dict = new Dictionary<string, string>()
|
{
|
{"Pjd1","SFJD1"},
|
{"Pjd2","SFJD2"},
|
{"Pjd3","SFJD3"},
|
|
{"Pdn2400","SFDN2400"},
|
{"Pdn2700","SFDN2700"},
|
{"Ppump21","SFPump21"},
|
{"Ppump22","SFPump22"},
|
{"Ppump23","SFPump23"},
|
{"Ppump24","SFPump24"},
|
{"Ppump25","SFPump25"},
|
{"Ppump26","SFPump26"},
|
{"Ppump27","SFPump27"}
|
};
|
var pattern_id_mapping_dict = new Dictionary<string, string>()
|
{
|
{"R3", "R3"},
|
{"R2", "R2"},
|
{"R1", "R1"},
|
{"Pump11", "Pump11"},
|
{"Pump12", "Pump12"},
|
{"Pump13", "Pump13"},
|
{"Pump14", "Pump14"},
|
{"Pump15", "Pump15"},
|
{"Pump16", "Pump16"},
|
{"Pump17", "Pump17"},
|
{"Pump18", "Pump18"},
|
{"SFJD1", "SFJD1"},
|
{"SFJD2", "SFJD2"},
|
{"SFJD3", "SFJD3"},
|
|
{"RPump21", "RPump21"},
|
{"RPump22", "RPump22"},
|
{"RPump23", "RPump23"},
|
{"RPump24", "RPump24"},
|
{"RPump25", "RPump25"},
|
{"RPump26", "RPump26"},
|
{"RPump27", "RPump27"},
|
{"Pump21", "Pump21"},
|
{"Pump22", "Pump22"},
|
{"Pump23", "Pump23"},
|
{"Pump24", "Pump24"},
|
{"Pump25", "Pump25"},
|
{"Pump26", "Pump26"},
|
{"Pump27", "Pump27"},
|
{"SFPump21", "SFPump21"},
|
{"SFPump22", "SFPump22"},
|
{"SFPump23", "SFPump23"},
|
{"SFPump24", "SFPump24"},
|
{"SFPump25", "SFPump25"},
|
{"SFPump26", "SFPump26"},
|
{"SFPump27", "SFPump27"},
|
{"SFDN2400", "SFDN2400"},
|
{"SFDN2700", "SFDN2700"},
|
};
|
|
IStation.Service.Station _service_station = new();
|
IStation.Service.ScheduleConfig _service_schedule_config = new();
|
var station_info = _service_station.Get();
|
|
var station1 = station_info.Station1;
|
var station2 = station_info.Station2;
|
var station1_same_type_flag_group_first = GlobalHelper.Station1SameTypeFlagGroupFirst;
|
var station2_same_type_flag_group_first = GlobalHelper.Station2SameTypeFlagGroupFirst;
|
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;
|
|
//Console.WriteLine("time flag wl scada ana diff ");
|
|
|
var day_value_list = IStation.DayValueHelper.GetDayValues();
|
day_value_list = day_value_list?.Where(x=>x.Month==6&&x.Day==5).ToList();
|
if (day_value_list == null)
|
return false;
|
|
List<Tuple<DateTime, string, int, double, double, double, double>> ana_pump_value_list = new List<Tuple<DateTime, string, int, double, double, double, double>>();
|
foreach (var day_value in day_value_list)
|
{
|
var time_value_list = day_value.TimeValueList;
|
foreach (var zy_scada_day in time_value_list)
|
{
|
var time = zy_scada_day.Time;
|
var zy_scada_dict = zy_scada_day.Value;
|
|
if (!OutTarget(zy_scada_dict, out double target_flow1, out double target_head1, out double target_flow2, out double target_head2))
|
{
|
continue;
|
}
|
if (!OutRpm(zy_scada_dict, out Dictionary<int, double> station1_flag_rpm_dict, out Dictionary<int, double> station2_flag_rpm_dict))
|
{
|
continue;
|
}
|
|
if (!OutHead(zy_scada_dict, out Dictionary<int, double> station1_flag_head_dict, out Dictionary<int, double> station2_flag_head_dict))
|
{
|
continue;
|
}
|
|
|
if (!OutFlow(zy_scada_dict, out Dictionary<int, double> station1_flag_flow_dict, out Dictionary<int, double> station2_flag_flow_dict))
|
{
|
continue;
|
}
|
OutWaterLevel(zy_scada_dict, out Dictionary<int, double> station1_flag_inlet_water_level_dict, out Dictionary<int, double> station2_flag_inlet_water_level_dict);
|
|
//没有单泵流量计
|
//var ana_pump_list1 = GetOptAnaPumpListByFlow(station1, station1_flag_rpm_dict, station1_flag_flow_dict);
|
//foreach (var ana_pump in ana_pump_list1)
|
//{
|
// var flag = ana_pump.Flag;
|
// var wl = station1_flag_inlet_water_level_dict[flag];
|
// var scada_head = station1_flag_head_dict[flag];
|
// var ana_head = ana_pump.Head;
|
// var diff_head = ana_head - (scada_head - wl);
|
|
// ana_pump_value_list.Add(new(time, flag, wl, scada_head, ana_head, diff_head));
|
//}
|
|
var ana_pump_list2 = GetOptAnaPumpListByFlow(station2, station2_flag_rpm_dict, station2_flag_flow_dict);
|
var flags = ana_pump_list2.Select(x => x.Flag).OrderBy(x => x).ToList();
|
var flags_str = Yw.Untity.IntListHelper.ToString(flags);
|
foreach (var ana_pump in ana_pump_list2)
|
{
|
var flag = ana_pump.Flag;
|
var wl = station2_flag_inlet_water_level_dict[flag];
|
var scada_head = station2_flag_head_dict[flag];
|
var ana_head = ana_pump.Head;
|
var diff_head = ana_head - (scada_head - wl);
|
|
ana_pump_value_list.Add(new(time, flags_str, flag, wl, scada_head, ana_head, diff_head));
|
}
|
}
|
}
|
|
var combine_group_list = ana_pump_value_list.GroupBy(x => x.Item2);
|
|
foreach (var combine_group in combine_group_list)
|
{
|
var flags = combine_group.Key;
|
Console.WriteLine();
|
Console.WriteLine($"---------------{flags}--------------");
|
var group = combine_group.GroupBy(x => x.Item3);
|
//foreach (var item in group)
|
//{
|
// var flag = item.Key;
|
// foreach (var item2 in item)
|
// {
|
// Console.WriteLine($"{item2.Item1:T} {flag} {item2.Item3:N2} {item2.Item4:N4} {item2.Item5:N4} {item2.Item6:N4}");
|
// }
|
// Console.WriteLine();
|
//}
|
|
Console.WriteLine("平均数");
|
foreach (var item in group)
|
{
|
var flag = item.Key;
|
var value = item.Average(x => x.Item7);
|
var min = item.Min(x => x.Item7);
|
var max = item.Max(x => x.Item7);
|
Console.WriteLine($"{flag}: {value} {min} {max}");
|
}
|
|
Console.WriteLine();
|
Console.WriteLine("众数");
|
foreach (var item in group)
|
{
|
//Console.WriteLine($"{flag}: {value} ");
|
var flag = item.Key;
|
var value = item.Average(x => x.Item7);
|
var nums = item.Select(x => Math.Round(x.Item7, 2)).ToArray();
|
|
var array = ModeHelper.ModeOf(nums);
|
Console.WriteLine($"{flag}:");
|
foreach (var vls in array)
|
{
|
Console.WriteLine(" " + vls);
|
}
|
}
|
|
}
|
return true;
|
}
|
|
|
|
private static bool OutTarget(Dictionary<string,double> scada_dict, out double target_flow1, out double target_head1, out double target_flow2, out double target_head2)
|
{
|
|
var jd1_flow = scada_dict["SFJD1"];
|
var jd2_flow = scada_dict["SFJD2"];
|
var jd3_flow = scada_dict["SFJD3"];
|
|
var jd1_head = scada_dict["SPJD1"];
|
var jd2_head = scada_dict["SPJD2"];
|
var jd3_head = scada_dict["SPJD3"];
|
|
var dn24_flow = scada_dict["SFDN2400"];
|
var dn27_flow = scada_dict["SFDN2700"];
|
|
var dn24_head = scada_dict["SPDN2400"];
|
var dn27_head = scada_dict["SPDN2700"];
|
|
target_flow1 = 0;
|
target_head1 = 0;
|
target_flow2 = 0;
|
target_head2 = 0;
|
|
if (jd1_flow < 0 || jd2_flow < 0 || jd3_flow < 0)
|
{
|
return false;
|
}
|
|
if (dn24_flow < 0 || dn27_flow < 0)
|
{
|
return false;
|
}
|
|
|
if (jd1_head < 0 || jd2_head < 0 || jd3_head < 0)
|
{
|
return false;
|
}
|
|
if (dn24_head < 0 || dn27_head < 0)
|
{
|
return false;
|
}
|
|
var max_head = new List<double>() { jd1_head, jd2_head, jd3_head }.Max();
|
var head1 = max_head;
|
|
var max_pressure2 = new List<double>() { dn24_head, dn27_head }.Max();
|
var head2 = max_pressure2;
|
|
target_flow1 = jd1_flow + jd2_flow + jd3_flow;
|
target_head1 = head1;
|
target_flow2 = dn24_flow + dn27_flow;
|
target_head2 = head2;
|
|
return true;
|
|
}
|
|
public static void OutWaterLevel(Dictionary<string, double> scada_dict, out Dictionary<int, double> station1_flag_inlet_water_level_dict, out Dictionary<int, double> station2_flag_inlet_water_level_dict)
|
{
|
station1_flag_inlet_water_level_dict = new Dictionary<int, double>();
|
station1_flag_inlet_water_level_dict.Add(11, scada_dict["R3"]);
|
station1_flag_inlet_water_level_dict.Add(12,scada_dict["R3"]);
|
station1_flag_inlet_water_level_dict.Add(13,scada_dict["R3"]);
|
station1_flag_inlet_water_level_dict.Add(14,scada_dict["R2"]);
|
station1_flag_inlet_water_level_dict.Add(15,scada_dict["R2"]);
|
station1_flag_inlet_water_level_dict.Add(16,scada_dict["R1"]);
|
station1_flag_inlet_water_level_dict.Add(17,scada_dict["R1"]);
|
station1_flag_inlet_water_level_dict.Add(18, scada_dict["R1"]);
|
station2_flag_inlet_water_level_dict = new Dictionary<int, double>();
|
station2_flag_inlet_water_level_dict.Add(21, scada_dict["RPump21"]);
|
station2_flag_inlet_water_level_dict.Add(22, scada_dict["RPump22"]);
|
station2_flag_inlet_water_level_dict.Add(23, scada_dict["RPump23"]);
|
station2_flag_inlet_water_level_dict.Add(24, scada_dict["RPump24"]);
|
station2_flag_inlet_water_level_dict.Add(25, scada_dict["RPump25"]);
|
station2_flag_inlet_water_level_dict.Add(26, scada_dict["RPump26"]);
|
station2_flag_inlet_water_level_dict.Add(27, scada_dict["RPump27"]);
|
|
}
|
|
private static bool OutRpm(Dictionary<string, double> scada_dict, out Dictionary<int, double> station1_flag_rpm_dict, out Dictionary<int, double> station2_flag_rpm_dict)
|
{
|
var FlagNrMappingDict1 = new Dictionary<string,int>(){
|
{ "Pump11",11},
|
{ "Pump12",12},
|
{ "Pump13",13},
|
{ "Pump14",14},
|
{ "Pump15",15},
|
{ "Pump16",16},
|
{ "Pump17",17},
|
{ "Pump18",18}
|
};
|
|
var FlagNrMappingDict2 = new Dictionary<string, int>(){
|
{ "Pump21",21},
|
{ "Pump22",22},
|
{ "Pump23",23},
|
{ "Pump24",24},
|
{ "Pump25",25},
|
{ "Pump26",26},
|
{ "Pump27",27}
|
};
|
|
|
station1_flag_rpm_dict = new Dictionary<int, double>();
|
station2_flag_rpm_dict = new Dictionary<int, double>();
|
|
foreach (var mapping in FlagNrMappingDict1)
|
{
|
var code = mapping.Key;
|
if (scada_dict.ContainsKey(code))
|
{
|
var value = scada_dict[code];
|
var hz = GlobalHelper.ModelPumpNrDict[code];
|
if (code != "Pump15" && code != "Pump16")
|
{
|
hz = value * GlobalHelper.ModelPumpNrDict[code];
|
}
|
station1_flag_rpm_dict.Add(mapping.Value, hz);
|
}
|
}
|
|
|
foreach (var mapping in FlagNrMappingDict2)
|
{
|
var code = mapping.Key;
|
if (scada_dict.ContainsKey(code))
|
{
|
var value = scada_dict[code];
|
var hz = value * GlobalHelper.ModelPumpNrDict[code];
|
station2_flag_rpm_dict.Add(mapping.Value, hz);
|
}
|
}
|
|
return true;
|
|
}
|
|
private static bool OutHead(Dictionary<string, double> scada_dict, out Dictionary<int, double> station1_flag_head_dict, out Dictionary<int, double> station2_flag_head_dict)
|
{
|
|
station1_flag_head_dict = new Dictionary<int, double>();
|
station2_flag_head_dict = new Dictionary<int, double>();
|
|
var FlagOutletPressureMappingDict1 = new Dictionary<string, int>()
|
{
|
{"SPPump11" ,11},
|
{"SPPump12" ,12},
|
{"SPPump13" ,13},
|
{"SPPump14" ,14},
|
{"SPPump15" ,15},
|
{"SPPump16" ,16},
|
{"SPPump17" ,17},
|
{"SPPump18" ,18},
|
};
|
|
|
var FlagOutletPressureMappingDict2 = new Dictionary<string, int>()
|
{
|
{"SPPump21" ,21},
|
{"SPPump22" ,22},
|
{"SPPump23" ,23},
|
{"SPPump24" ,24},
|
{"SPPump25" ,25},
|
{"SPPump26" ,26},
|
{"SPPump27" ,27}
|
};
|
|
|
foreach (var mapping in FlagOutletPressureMappingDict1)
|
{
|
var code = mapping.Key;
|
if (scada_dict.ContainsKey(code))
|
{
|
var value = scada_dict[code];
|
station1_flag_head_dict.Add(mapping.Value, value);
|
}
|
}
|
|
|
foreach (var mapping in FlagOutletPressureMappingDict2)
|
{
|
var code = mapping.Key;
|
if (scada_dict.ContainsKey(code))
|
{
|
var value = scada_dict[code];
|
station2_flag_head_dict.Add(mapping.Value, value);
|
}
|
}
|
|
return true;
|
|
}
|
|
private static bool OutFlow(Dictionary<string, double> scada_dict, out Dictionary<int, double> station1_flag_flow_dict, out Dictionary<int, double> station2_flag_flow_dict)
|
{
|
station1_flag_flow_dict = new Dictionary<int, double>();
|
station2_flag_flow_dict = new Dictionary<int, double>();
|
|
|
|
var flow_id_mapping_dict2 = new Dictionary<string, int>()
|
{
|
{"SFPump21",21},
|
{"SFPump22",22},
|
{"SFPump23",23},
|
{"SFPump24",24},
|
{"SFPump25",25},
|
{"SFPump26",26},
|
{"SFPump27",27}
|
};
|
|
foreach (var mapping in flow_id_mapping_dict2)
|
{
|
var code = mapping.Key;
|
if (scada_dict.ContainsKey(code))
|
{
|
var value = scada_dict[code];
|
station2_flag_flow_dict.Add(mapping.Value, value);
|
}
|
}
|
|
return true;
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|