From ec22b14b0395df0ab97d1adf5b589a187bb62e59 Mon Sep 17 00:00:00 2001 From: ningshuxia <ningshuxia0927@outlook.com> Date: 星期二, 07 五月 2024 11:24:09 +0800 Subject: [PATCH] 调度接口(60) --- WebApi/IStation.Application.Core/1-dispatch/1-solution/DispatchSolution_Controller.cs | 452 +++++++++++++++----------------------------------------- 1 files changed, 121 insertions(+), 331 deletions(-) diff --git a/WebApi/IStation.Application.Core/1-dispatch/1-solution/DispatchSolution_Controller.cs b/WebApi/IStation.Application.Core/1-dispatch/1-solution/DispatchSolution_Controller.cs index 7380c86..2270f1d 100644 --- a/WebApi/IStation.Application.Core/1-dispatch/1-solution/DispatchSolution_Controller.cs +++ b/WebApi/IStation.Application.Core/1-dispatch/1-solution/DispatchSolution_Controller.cs @@ -1,4 +1,6 @@ -锘縩amespace IStation.Application +锘縰sing Yw.Calculation; + +namespace IStation.Application { /// <summary> /// 璋冨害鏂规 @@ -7,373 +9,161 @@ [ApiDescriptionSettings("Solution", Name = "闄堣璋冨害鏂规", Order = 1)] public class DispatchSolution_Controller : IDynamicApiController { - /// <summary> /// 璁$畻 /// </summary> [AllowAnonymous] [Route("Calculate@V1.0")] [HttpPost] - public async Task<DispatchSolutionOutput> Calculate([Required] StationDispatchInput input) + [NonUnify] + public async Task<StationDispatchOutput> Calculate([Required] StationDispatchInput input) { if (input == null) return null; - string flowId = input.FlowId; - Log.Debug(flowId, JsonHelper.Object2Json(input)); + var receipt_time = DateTime.Now; + Log.Debug(JsonHelper.Object2Json(input)); + //鑾峰彇Scada瀹炴椂鏁版嵁 + //...... - var scadaInput = GetScadaDispatchInput(DateTime.Now.AddSeconds(300), DateTime.Now); - var scadaOutput = await GetRealScada(flowId, scadaInput); - if (scadaOutput == null || scadaOutput.Scadas == null) + var total_flow1 = input.objects["TotalFlow1"]; + var total_pressure1 = input.objects["TotalPressure1"]; + total_pressure1 = Mpa2M(total_pressure1); + var total_flow2 = input.objects["TotalFlow2"]; + var total_pressure2 = input.objects["TotalPressure2"]; + total_pressure2 = Mpa2M(total_pressure2); + + var optimal_combine1 = GetOptimalCombine1(total_flow1, total_pressure1, null, null, null); + var optimal_combine2 = GetOptimalCombine2(total_flow2, total_pressure2, null, null, null); + + var output = new StationDispatchOutput(); + output.objects = new Dictionary<string, double>(); + if (optimal_combine1 == null && optimal_combine2 == null) { - Log.Info(flowId, "Scada:鏁版嵁鑾峰彇澶辫触锛岃皟搴︾粓姝�!"); - throw YOops.Oh(eResultCode.Error, InternalErrorCodes.L001, "Scada:鏁版嵁鑾峰彇澶辫触锛岃皟搴︾粓姝�!"); + output.flag = 0; + output.message = "鍦哄唴璋冨害鏂规鏃犳硶璁$畻!"; + Log.Info("璁$畻澶辫触锛氬満鍐呰皟搴︽柟妗堟棤娉曡绠�!"); } - - return TempOutHelper.GetDispatchSolutionOutput(input.FlowId); - } - - private async Task<ScadaDispatchOutput> GetRealScada(string flowId, ScadaDispatchInput input) - { - if (input == null) + else { - Log.Info(flowId, "ScadaDispatchInput is null"); - return default; - } - - var ws = new ClientWebSocket(); - ws.Options.RemoteCertificateValidationCallback = delegate { return true; }; - await ws.ConnectAsync(new Uri("ws://localhost:5102/api/WebSocket/GetNotReadCount"), CancellationToken.None); - if (ws.State != WebSocketState.Open) - { - Log.Info(flowId, "webSocket:杩炴帴澶辫触!"); - return default; - } - Log.Info(flowId, "webSocket:杩炴帴鎴愬姛!"); - - ScadaDispatchOutput output = null; - var inputJson = JsonHelper.Object2Json(input); - Log.Debug(flowId, inputJson); - var inputBytes = Encoding.UTF8.GetBytes(inputJson); - await ws.SendAsync(inputBytes, WebSocketMessageType.Text, true, CancellationToken.None); - try - { - List<byte> outputBytes = new List<byte>();//鍏ㄩ儴娑堟伅瀹瑰櫒 - var buffer = new byte[1024 * 4];//缂撳啿鍖� - var result = await ws.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None); //鐩戝惉Socket淇℃伅 - while (!result.CloseStatus.HasValue) //鏄惁鍏抽棴 + if (optimal_combine1 != null) { - if (result.MessageType == WebSocketMessageType.Text)//鏂囨湰娑堟伅 + output.objects["1杈撴按鎬绘祦閲�"] = optimal_combine1.Flow; + output.objects["1杈撴按鎬诲帇鍔�"] = M2Mpa(optimal_combine1.Head); + foreach (var combine in optimal_combine1.Combines) { - outputBytes.AddRange(buffer.Take(result.Count)); - if (result.EndOfMessage)//娑堟伅鏄惁宸叉帴鏀跺畬鍏� + foreach (var pump_flag in combine.Flags) { - //鍙戦�佽繃鏉ョ殑娑堟伅 - string outputJson = Encoding.UTF8.GetString(outputBytes.ToArray(), 0, outputBytes.Count); - output = new ScadaDispatchOutput(); - output.Scadas = JsonHelper.Json2Object<Dictionary<string, Dictionary<DateTime, string>>>(outputJson); - break; + output.objects[$"1杈撴按{pump_flag}#棰戠巼"] = combine.Frequency; } } - result = await ws.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);//缁х画鐩戝惉Socket淇℃伅 } - } - catch (Exception ex) - { - Log.Error(flowId, ex.Message); - } - finally - { - try + if (optimal_combine2 != null) { - //鍏抽棴WebSocket - await ws.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "AcknowledgeCloseframe", CancellationToken.None); + output.objects["2杈撴按鎬绘祦閲�"] = optimal_combine2.Flow; + output.objects["2杈撴按鎬诲帇鍔�"] = M2Mpa(optimal_combine2.Head); + foreach (var combine in optimal_combine2.Combines) + { + foreach (var pump_flag in combine.Flags) + { + output.objects[$"2杈撴按{pump_flag}#棰戠巼"] = combine.Frequency; + } + } } - catch (Exception ex) - { - Log.Error(flowId, "鍏抽棴WebSocket寮傚父", ex); - } - ws.Abort(); - ws.Dispose(); + output.flag = 1; + Log.Info("璁$畻鎴愬姛!"); } + output.ReceiptTime = receipt_time; + output.ReturnTime = DateTime.Now; return output; } - private ScadaDispatchInput GetScadaDispatchInput(DateTime startTime, DateTime endTime, double resolution = 300) + private string _data_floder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data"); + private List<IStation.Model.Pump> _station_pumps1 = null; + private List<IStation.Model.Pump> _station_pumps2 = null; + + /// <summary> + /// 鑾峰彇1杈撴按鏈�浼樿皟搴︽柟妗� + /// </summary> + /// <returns></returns> + IStation.Algorithm.OptimalCombine GetOptimalCombine1(double target_flow, double target_head, List<int> current_open_pump_flags, List<int> must_open_pump_flags, List<int> must_not_open_pump_flags) { - - var tagDict = new Dictionary<string, string> + if (_station_pumps1 == null) { - //{ "_0402010204089903001", "闀挎睙姘翠綅" }, - //{ "_0402010204089904009", "浜屽彇姘村墠姹犳恫浣�" }, - //{ "_0402010201030103006", "闄堣姘村簱姘翠綅" }, - //{ "_0402010204012101001", "浜屽彇姘�1鍙锋车鐘舵��" }, - //{ "_0402010204012201001", "浜屽彇姘�2鍙锋车鐘舵��" }, - //{ "_0402010204012301001", "浜屽彇姘�3鍙锋车鐘舵��" }, - //{ "_0402010204012401001", "浜屽彇姘�4鍙锋车鐘舵��" }, - //{ "_0402010204012501001", "浜屽彇姘�5鍙锋车鐘舵��" }, - //{ "_0402010204012103002", "浜屽彇姘�1鍙锋车绱娴侀噺" }, - //{ "_0402010204012203002", "浜屽彇姘�2鍙锋车绱娴侀噺" }, - //{ "_0402010204012303002", "浜屽彇姘�3鍙锋车绱娴侀噺" }, - //{ "_0402010204012403002", "浜屽彇姘�4鍙锋车绱娴侀噺" }, - //{ "_0402010204012503002", "浜屽彇姘�5鍙锋车绱娴侀噺" }, - //{ "_0402010204040193046", "浜屽彇姘�1鍙锋车鏈夊姛鐢佃兘" }, - //{ "_0402010204040193047", "浜屽彇姘�2鍙锋车鏈夊姛鐢佃兘" }, - //{ "_0402010204012308007", "浜屽彇姘�3鍙锋车鏈夊姛鐢佃兘" }, - //{ "_0402010204012408007", "浜屽彇姘�4鍙锋车鏈夊姛鐢佃兘" }, - //{ "_0402010204012508007", "浜屽彇姘�5鍙锋车鏈夊姛鐢佃兘" }, - { "_0402010201090105774", "涓�杈撴按11鍙峰嚭鍙e帇鍔�" }, - { "_0402010201040502031", "涓�杈撴按11鍙锋湁鍔熷姛鐜�" }, - { "_0402010201040502044", "涓�杈撴按11鍙锋湁鍔熺數搴�" }, - { "_0402010201011195062", "涓�杈撴按11鍙锋车杞��" }, - { "_0402010201011101001", "涓�杈撴按11鍙锋车杩愯鐘舵��" }, - { "_0402010201011194012", "涓�杈撴按11鍙锋车棰戠巼" }, - { "_0402010201090105005", "涓�杈撴按12鍙峰嚭鍙e帇鍔�" }, - { "_0402010201041402031", "涓�杈撴按12鍙锋湁鍔熷姛鐜�" }, - { "_0402010201041402044", "涓�杈撴按12鍙锋湁鍔熺數搴�" }, - { "_0402010201011295062", "涓�杈撴按12鍙锋车杞��" }, - { "_0402010201011201001", "涓�杈撴按12鍙锋车杩愯鐘舵��" }, - { "_0402010201011294012", "涓�杈撴按12鍙锋车棰戠巼" }, - { "_0402010201090105776", "涓�杈撴按13鍙峰嚭鍙e帇鍔�" }, - { "_0402010201040602031", "涓�杈撴按13鍙锋湁鍔熷姛鐜�" }, - { "_0402010201040602044", "涓�杈撴按13鍙锋湁鍔熺數搴�" }, - { "_0402010201011395062", "涓�杈撴按13鍙锋车杞��" }, - { "_0402010201011301001", "涓�杈撴按13鍙锋车杩愯鐘舵��" }, - { "_0402010201011394012", "涓�杈撴按13鍙锋车棰戠巼" }, - { "_0402010201090105007", "涓�杈撴按14鍙峰嚭鍙e帇鍔�" }, - { "_0402010201041302031", "涓�杈撴按14鍙锋湁鍔熷姛鐜�" }, - { "_0402010201041302044", "涓�杈撴按14鍙锋湁鍔熺數搴�" }, - { "_0402010201011495062", "涓�杈撴按14鍙锋车杞��" }, - { "_0402010201011401001", "涓�杈撴按14鍙锋车杩愯鐘舵��" }, - { "_0402010201011494012", "涓�杈撴按14鍙锋车棰戠巼" }, - { "_0402010201090105008", "涓�杈撴按15鍙峰嚭鍙e帇鍔�" }, - { "_0402010201040702031", "涓�杈撴按15鍙锋湁鍔熷姛鐜�" }, - { "_0402010201040702044", "涓�杈撴按15鍙锋湁鍔熺數搴�" }, - { "_0402010201011595062", "涓�杈撴按15鍙锋车杞��" }, - { "_0402010201011501003", "涓�杈撴按15鍙锋车杩愯鐘舵��" }, - { "_0402010201090105016", "涓�杈撴按16鍙峰嚭鍙e帇鍔�" }, - { "_0402010201041202031", "涓�杈撴按16鍙锋湁鍔熷姛鐜�" }, - { "_0402010201041202044", "涓�杈撴按16鍙锋湁鍔熺數搴�" }, - { "_0402010201011695062", "涓�杈撴按16鍙锋车杞��" }, - { "_0402010201011601003", "涓�杈撴按16鍙锋车杩愯鐘舵��" }, - { "_0402010201090105017", "涓�杈撴按17鍙峰嚭鍙e帇鍔�" }, - { "_0402010201040802031", "涓�杈撴按17鍙锋湁鍔熷姛鐜�" }, - { "_0402010201040802044", "涓�杈撴按17鍙锋湁鍔熺數搴�" }, - { "_0402010201011795062", "涓�杈撴按17鍙锋车杞��" }, - { "_0402010201011795056", "涓�杈撴按17鍙锋车杩愯鐘舵��" }, - { "_0402010201090105018", "涓�杈撴按18鍙峰嚭鍙e帇鍔�" }, - { "_0402010201041102031", "涓�杈撴按18鍙锋湁鍔熷姛鐜�" }, - { "_0402010201041102044", "涓�杈撴按18鍙锋湁鍔熺數搴�" }, - { "_0402010201011895062", "涓�杈撴按18鍙锋车杞��" }, - { "_0402010201011895056", "涓�杈撴按18鍙锋车杩愯鐘舵��" }, - { "_0402010201090104011", "涓�杈撴按鍓嶆睜娑蹭綅1" }, - { "_0402010201091104123", "涓�杈撴按鍓嶆睜娑蹭綅2" }, - { "_0402010201091104122", "涓�杈撴按鍓嶆睜娑蹭綅3" }, - { "_0402010201090105002", "涓�杈撴按鍢夊畾1绾垮帇鍔�" }, - { "_0402010201030191001", "涓�杈撴按鍢夊畾1绾跨灛鏃舵祦閲�" }, - { "_0402010201030191002", "涓�杈撴按鍢夊畾1绾跨疮璁℃祦閲�" }, - { "_0402010201090105011", "涓�杈撴按鍢夊畾2绾垮帇鍔�" }, - { "_0402010201090199011", "涓�杈撴按鍢夊畾2绾跨灛鏃舵祦閲�" }, - { "_0402010201090199012", "涓�杈撴按鍢夊畾2绾跨疮璁℃祦閲�" }, - { "_0402010201090105784", "涓�杈撴按鍢夊畾3绾垮帇鍔�" }, - { "_0402010201090199311", "涓�杈撴按鍢夊畾3绾跨灛鏃舵祦閲�" }, - { "_0402010201090199312", "涓�杈撴按鍢夊畾3绾跨疮璁℃祦閲�" }, - { "_0402010204012105001", "浜屽彇姘翠竴鍙锋満娉靛嚭鍙e帇鍔�" }, - { "_0402010204012101001", "浜屽彇姘翠竴鍙锋満娉靛紑鍋滅姸鎬�" }, - { "_0402010204040193004", "浜屽彇姘翠竴鍙锋満娉垫湁鍔熷姛鐜�" }, - { "_0402010204040193046", "浜屽彇姘翠竴鍙锋満娉垫湁鍔熺數搴�" }, - { "_0402010204012103001", "浜屽彇姘翠竴鍙锋満娉电灛鏃舵祦閲�" }, - { "_0402010204012103002", "浜屽彇姘翠竴鍙锋満娉电疮璁℃祦閲�" }, - { "_0402010204012305001", "浜屽彇姘翠笁鍙锋満娉靛嚭鍙e帇鍔�" }, - { "_0402010204012301001", "浜屽彇姘翠笁鍙锋満娉靛紑鍋滅姸鎬�" }, - { "_0402010204012308008", "浜屽彇姘翠笁鍙锋満娉垫湁鍔熷姛鐜�" }, - { "_0402010204012308007", "浜屽彇姘翠笁鍙锋満娉垫湁鍔熺數搴�" }, - { "_0402010204012303001", "浜屽彇姘翠笁鍙锋満娉电灛鏃舵祦閲�" }, - { "_0402010204012303002", "浜屽彇姘翠笁鍙锋満娉电疮璁℃祦閲�" }, - { "_0402010204012205001", "浜屽彇姘翠簩鍙锋満娉靛嚭鍙e帇鍔�" }, - { "_0402010204012201001", "浜屽彇姘翠簩鍙锋満娉靛紑鍋滅姸鎬�" }, - { "_0402010204040193005", "浜屽彇姘翠簩鍙锋満娉垫湁鍔熷姛鐜�" }, - { "_0402010204040193047", "浜屽彇姘翠簩鍙锋満娉垫湁鍔熺數搴�" }, - { "_0402010204012203001", "浜屽彇姘翠簩鍙锋満娉电灛鏃舵祦閲�" }, - { "_0402010204012203002", "浜屽彇姘翠簩鍙锋満娉电疮璁℃祦閲�" }, - { "_0402010204012505001", "浜屽彇姘翠簲鍙锋満娉靛嚭鍙e帇鍔�" }, - { "_0402010204012501001", "浜屽彇姘翠簲鍙锋満娉靛紑鍋滅姸鎬�" }, - { "_0402010204012508008", "浜屽彇姘翠簲鍙锋満娉垫湁鍔熷姛鐜�" }, - { "_0402010204012508007", "浜屽彇姘翠簲鍙锋満娉垫湁鍔熺數搴�" }, - { "_0402010204012503001", "浜屽彇姘翠簲鍙锋満娉电灛鏃舵祦閲�" }, - { "_0402010204012503002", "浜屽彇姘翠簲鍙锋満娉电疮璁℃祦閲�" }, - { "_0402010204089904009", "浜屽彇姘村墠姹犳恫浣�" }, - { "_0402010204012405001", "浜屽彇姘村洓鍙锋満娉靛嚭鍙e帇鍔�" }, - { "_0402010204012401001", "浜屽彇姘村洓鍙锋満娉靛紑鍋滅姸鎬�" }, - { "_0402010204012408008", "浜屽彇姘村洓鍙锋満娉垫湁鍔熷姛鐜�" }, - { "_0402010204012408007", "浜屽彇姘村洓鍙锋満娉垫湁鍔熺數搴�" }, - { "_0402010204012403001", "浜屽彇姘村洓鍙锋満娉电灛鏃舵祦閲�" }, - { "_0402010204012403002", "浜屽彇姘村洓鍙锋満娉电疮璁℃祦閲�" }, - { "_0402010201012105001", "浜岃緭姘�21鍙锋车鍑哄彛鍘嬪姏" }, - { "_0402010201040102049", "浜岃緭姘�21鍙锋车鏈夊姛鍔熺巼" }, - { "_0402010201040102187", "浜岃緭姘�21鍙锋车鏈夊姛鐢靛害" }, - { "_0402010201090103901", "浜岃緭姘�21鍙锋车鐬椂娴侀噺" }, - { "_0402010201010294045", "浜岃緭姘�21鍙锋车绱娴侀噺" }, - { "_0402010201012199001", "浜岃緭姘�21鍙锋车杞��" }, - { "_0402010201012193021", "浜岃緭姘�21鍙锋车杩愯鐘舵��" }, - { "_0402010201040102178", "浜岃緭姘�21鍙锋车棰戠巼" }, - { "_0402010201012205001", "浜岃緭姘�22鍙锋车鍑哄彛鍘嬪姏" }, - { "_0402010201040102053", "浜岃緭姘�22鍙锋车鏈夊姛鍔熺巼" }, - { "_0402010201040102213", "浜岃緭姘�22鍙锋车鏈夊姛鐢靛害" }, - { "_0402010201090103001", "浜岃緭姘�22鍙锋车鐬椂娴侀噺" }, - { "_0402010201090103002", "浜岃緭姘�22鍙锋车绱娴侀噺" }, - { "_0402010201012299001", "浜岃緭姘�22鍙锋车杞��" }, - { "_0402010201012201001", "浜岃緭姘�22鍙锋车杩愯鐘舵��" }, - { "_0402010201040102204", "浜岃緭姘�22鍙锋车棰戠巼" }, - { "_0402010201012305001", "浜岃緭姘�23鍙锋车鍑哄彛鍘嬪姏" }, - { "_0402010201040102055", "浜岃緭姘�23鍙锋车鏈夊姛鍔熺巼" }, - { "_0402010201040102136", "浜岃緭姘�23鍙锋车鏈夊姛鐢靛害" }, - { "_0402010201040102054", "浜岃緭姘�23鍙锋车鐢垫祦" }, - { "_0402010201090103003", "浜岃緭姘�23鍙锋车鐬椂娴侀噺" }, - { "_0402010201090103004", "浜岃緭姘�23鍙锋车绱娴侀噺" }, - { "_0402010201012399001", "浜岃緭姘�23鍙锋车杞��" }, - { "_0402010201010194135", "浜岃緭姘�23鍙锋车杩愯鐘舵��" }, - { "_0402010201040102217", "浜岃緭姘�23鍙锋车棰戠巼" }, - { "_0402010201090105003", "浜岃緭姘�2400绠″帇鍔�" }, - { "_0402010201090103017", "浜岃緭姘�2400绠$灛鏃舵祦閲�" }, - { "_0402010201090103018", "浜岃緭姘�2400绠$疮璁℃祦閲�" }, - { "_0402010201012405001", "浜岃緭姘�24鍙锋车鍑哄彛鍘嬪姏" }, - { "_0402010201040102057", "浜岃緭姘�24鍙锋车鏈夊姛鍔熺巼" }, - { "_0402010201040102149", "浜岃緭姘�24鍙锋车鏈夊姛鐢靛害" }, - { "_0402010201090103005", "浜岃緭姘�24鍙锋车鐬椂娴侀噺" }, - { "_0402010201090103006", "浜岃緭姘�24鍙锋车绱娴侀噺" }, - { "_0402010201012499001", "浜岃緭姘�24鍙锋车杞��" }, - { "_0402010201012401001", "浜岃緭姘�24鍙锋车杩愯鐘舵��" }, - { "_0402010201040102140", "浜岃緭姘�24鍙锋车棰戠巼" }, - { "_0402010201012505001", "浜岃緭姘�25鍙锋车鍑哄彛鍘嬪姏" }, - { "_0402010201040202004", "浜岃緭姘�25鍙锋车鏈夊姛鍔熺巼" }, - { "_0402010201040202141", "浜岃緭姘�25鍙锋车鏈夊姛鐢靛害" }, - { "_0402010201090103007", "浜岃緭姘�25鍙锋车鐬椂娴侀噺" }, - { "_0402010201090103008", "浜岃緭姘�25鍙锋车绱娴侀噺" }, - { "_0402010201012599001", "浜岃緭姘�25鍙锋车杞��" }, - { "_0402010201012501001", "浜岃緭姘�25鍙锋车杩愯鐘舵��" }, - { "_0402010201040202132", "浜岃緭姘�25鍙锋车棰戠巼" }, - { "_0402010201012605001", "浜岃緭姘�26鍙锋车鍑哄彛鍘嬪姏" }, - { "_0402010201040202006", "浜岃緭姘�26鍙锋车鏈夊姛鍔熺巼" }, - { "_0402010201040202028", "浜岃緭姘�26鍙锋车鏈夊姛鐢靛害" }, - { "_0402010201090103009", "浜岃緭姘�26鍙锋车鐬椂娴侀噺" }, - { "_0402010201090103010", "浜岃緭姘�26鍙锋车绱娴侀噺" }, - { "_0402010201012699001", "浜岃緭姘�26鍙锋车杞��" }, - { "_0402010201010194152", "浜岃緭姘�26鍙锋车杩愯鐘舵��" }, - { "_0402010201040202145", "浜岃緭姘�26鍙锋车棰戠巼" }, - { "_0402010201090105004", "浜岃緭姘�2700绠″帇鍔�" }, - { "_0402010201090194002", "浜岃緭姘�2700绠$灛鏃舵祦閲�" }, - { "_0402010201090194444", "浜岃緭姘�2700绠$疮璁℃祦閲�" }, - { "_0402010201012705001", "浜岃緭姘�27鍙锋车鍑哄彛鍘嬪姏" }, - { "_0402010201040202012", "浜岃緭姘�27鍙锋车鏈夊姛鍔熺巼" }, - { "_0402010201040202193", "浜岃緭姘�27鍙锋车鏈夊姛鐢靛害" }, - { "_0402010201090103903", "浜岃緭姘�27鍙锋车鐬椂娴侀噺" }, - { "_0402010201090194001", "浜岃緭姘�27鍙锋车绱娴侀噺" }, - { "_0402010201012799001", "浜岃緭姘�27鍙锋车杞��" }, - { "_0402010201012793021", "浜岃緭姘�27鍙锋车杩愯鐘舵��" }, - { "_0402010201040202184", "浜岃緭姘�27鍙锋车棰戠巼" }, - { "_0402010204089903001", "闄堣鍙栨按鍙i暱姹熸恫浣�" }, - { "_0402010201030103006", "闄堣姘村簱娑蹭綅" }, - }; + var filePath = _data_floder + "\\" + "闄堣涓�杈�.json"; + var jsonInfo = File.ReadAllText(filePath); + _station_pumps1 = JsonHelper.Json2Object<List<Model.Pump>>(jsonInfo); + if (_station_pumps1 == null) + { + Log.Error($"鏂囦欢缂哄け:{filePath}"); + return default; + } + } - var input = new ScadaDispatchInput(); - input.search = "history"; - input.starttime = startTime.ToString("G"); - input.endtime = endTime.ToString("G"); - input.Resolution = resolution.ToString(); - input.taglist = tagDict.Select(x => x.Key).ToArray(); - return input; + var flags_part1 = new List<int>() { 11, 12, 13, 14, 16, 17, 18 }; + var flags_part2 = new List<int>() { 15 }; + + var helper = new Algorithm.SchedulingHelper(); + var optimal_combine = helper.AnaOptimalCombine(_station_pumps1, flags_part1, flags_part2, target_flow, target_head, current_open_pump_flags, must_open_pump_flags, must_not_open_pump_flags); + if (optimal_combine == null) + { + Log.Error($"涓�杈撴按鏂规璁$畻澶辫触: optimal_combine1 is null"); + } + return optimal_combine; + } + + /// <summary> + /// 鑾峰彇2杈撴按鏈�浼樿皟搴︽柟妗� + /// </summary> + /// <returns></returns> + IStation.Algorithm.OptimalCombine GetOptimalCombine2(double target_flow, double target_head, List<int> current_open_pump_flags, List<int> must_open_pump_flags, List<int> must_not_open_pump_flags) + { + if (_station_pumps2 == null) + { + var filePath = _data_floder + "\\" + "闄堣浜岃緭.json"; + var jsonInfo = File.ReadAllText(filePath); + _station_pumps2 = JsonHelper.Json2Object<List<Model.Pump>>(jsonInfo); + if (_station_pumps2 == null) + { + Log.Error($"鏂囦欢缂哄け:{filePath}"); + return default; + } + } + + var flags_part1 = new List<int>() { 22, 23, 24, 25, 26 }; + var flags_part2 = new List<int>() { 21, 27 }; + + var helper = new Algorithm.SchedulingHelper(); + var optimal_combine = helper.AnaOptimalCombine(_station_pumps2, flags_part1, flags_part2, target_flow, target_head, current_open_pump_flags, must_open_pump_flags, must_not_open_pump_flags); + if (optimal_combine == null) + { + Log.Error($"浜岃緭姘存柟妗堣绠楀け璐�: optimal_combine1 is null"); + } + return optimal_combine; } + #region Mpa<=>m - //private async Task<ScadaDispatchOutput> GetRealScada(string flowId, ScadaDispatchInput input) - //{ - // if (input == null) - // { - // Log.Info(flowId, "ScadaDispatchInput is null"); - // return default; - // } + /// <summary> + /// Mpa=>m + /// </summary> + public static double Mpa2M(double mpa) + { + return mpa * ConstantParas.WaterDensity / ConstantParas.g; + } - // var ws = await CreateAsync("ws://localhost:5102/api/WebSocket/GetNotReadCount"); - // if (ws == null || ws.State != WebSocketState.Open) - // { - // Log.Info(flowId, "webSocket:杩炴帴澶辫触!"); - // return default; - // } - // Log.Info(flowId, "webSocket:杩炴帴鎴愬姛!"); + /// <summary> + /// m=>Mpa + /// </summary> + public static double M2Mpa(double m) + { + return m * ConstantParas.g / ConstantParas.WaterDensity; + } - // ScadaDispatchOutput output = null; - // var inputJson = JsonHelper.Object2FormatJson(input); - // Log.Debug(flowId, inputJson); - // var inputBytes = Encoding.UTF8.GetBytes(inputJson); - // await ws.SendAsync(inputBytes, WebSocketMessageType.Text, true, CancellationToken.None); - // try - // { - // var buffer = new ArraySegment<byte>(new byte[1024 * 4]); - // WebSocketReceiveResult result = null; - // using (var ms = new MemoryStream()) - // { - // do - // { - // result = await ws.ReceiveAsync(buffer, CancellationToken.None); - // ms.Write(buffer.Array, buffer.Offset, result.Count); - // } - // while (!result.EndOfMessage); - - // ms.Seek(0, SeekOrigin.Begin); - // if (result.MessageType == WebSocketMessageType.Text && !result.CloseStatus.HasValue) - // { - // using (var reader = new StreamReader(ms, Encoding.UTF8)) - // { - // string outputJson = reader.ReadToEnd(); - // output = new ScadaDispatchOutput(); - // output.Scadas = JsonHelper.Json2Object<Dictionary<string, Dictionary<DateTime, string>>>(outputJson); - // } - // } - // } - // } - // catch (Exception ex) - // { - // Log.Error(flowId, ex.Message); - // } - // finally - // { - // try - // { - // //鍏抽棴WebSocket - // await ws.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "AcknowledgeCloseframe", CancellationToken.None); - // } - // catch (Exception ex) - // { - // Log.Error(flowId, "鍏抽棴WebSocket寮傚父", ex); - // } - // ws.Abort(); - // ws.Dispose(); - // } - - // return output; - //} - - ///// <summary> - ///// 鍒涘缓瀹㈡埛绔疄渚� - ///// </summary> - ///// <returns></returns> - //public static async Task<ClientWebSocket> CreateAsync(string ServerUri) - //{ - // var webSocket = new ClientWebSocket(); - // webSocket.Options.RemoteCertificateValidationCallback = delegate { return true; }; - - // await webSocket.ConnectAsync(new Uri(ServerUri), CancellationToken.None); - // if (webSocket.State == WebSocketState.Open) - // { - // return webSocket; - // } - // return null; - //} - + #endregion } } \ No newline at end of file -- Gitblit v1.9.3