From c0f9915265878e56e91ee97f7f8d925db1e12626 Mon Sep 17 00:00:00 2001 From: cloudflight <cloudflight@126.com> Date: 星期六, 02 十二月 2023 18:50:45 +0800 Subject: [PATCH] 2023年12月2日_3 --- Hydro.CommonBase/Helper/SolutionSelector.cs | 212 ++++++++++++++++++++++++++++++++++------------------ 1 files changed, 138 insertions(+), 74 deletions(-) diff --git a/Hydro.CommonBase/Helper/SolutionSelector.cs b/Hydro.CommonBase/Helper/SolutionSelector.cs index 880383e..73cc34a 100644 --- a/Hydro.CommonBase/Helper/SolutionSelector.cs +++ b/Hydro.CommonBase/Helper/SolutionSelector.cs @@ -31,7 +31,18 @@ if (dateTime==default(DateTime)) { dateTime=DateTime.Now; } //string currentDirectory = Directory.GetCurrentDirectory(); string resultPath = GlobalPath.resultPath;// Path.Combine(GlobalPath.resultPath, "result"); - + string currentDirectory = Directory.GetCurrentDirectory(); + //string resultPath = GlobalPath.resultPath; + string userPathFile = resultPath + "UserPath.ini"; + string userPath = null; + if (File.Exists(userPathFile)) + { + userPath = File.ReadAllText(userPathFile); + } + if (userPath == null || !Directory.Exists(userPath)) + { + userPath = resultPath; + } bool flag = false; int lastMinutes = 10; @@ -57,7 +68,8 @@ if (MessageBox.Show("鑷姩閫夋嫨鍘嗗彶杈撳嚭锛焅r\n鏄細鑷姩\r\n鍚︼細鎵嬪姩", "鏂规鎷╀紭", MessageBoxButtons.YesNo) == DialogResult.No) { OpenFileDialog openFileDialog = new OpenFileDialog(); - openFileDialog.InitialDirectory = resultPath; + + openFileDialog.InitialDirectory = userPath; openFileDialog.Filter = "JSON Files (*.json)|*.json"; openFileDialog.Multiselect = true; @@ -76,10 +88,10 @@ DateTime tenMinutesAgo = currentTime.AddMinutes(-lastMinutes); // 鏌ユ壘鐩綍涓嬬殑鎵�鏈�.json鏂囦欢锛屽苟鏍规嵁淇敼鏃堕棿杩涜绛涢�� - string[] jsonFiles = Directory.GetFiles(resultPath, "*.json") + string[] jsonFiles = Directory.GetFiles(userPath, "*.json") .Where(file => File.GetLastWriteTime(file) >= tenMinutesAgo && File.GetLastWriteTime(file) <= currentTime) .ToArray(); - string[] inputFiles = Directory.GetFiles(resultPath, "*.input") + string[] inputFiles = Directory.GetFiles(userPath, "*.input") .Where(file => File.GetLastWriteTime(file) >= tenMinutesAgo && File.GetLastWriteTime(file) <= currentTime) .ToArray(); files = jsonFiles.ToList(); @@ -96,12 +108,12 @@ DateTime tenMinutesAgo = currentTime.AddMinutes(-lastMinutes); // 鏌ユ壘鐩綍涓嬬殑鎵�鏈�.json鏂囦欢锛屽苟鏍规嵁淇敼鏃堕棿杩涜绛涢�� - string[] jsonFiles = Directory.GetFiles(resultPath, "*.json") + string[] jsonFiles = Directory.GetFiles(userPath, "*.json") .Where(file => getTimeByFileName(file) >= tenMinutesAgo && getTimeByFileName(file) <= currentTime) .OrderBy(file =>file) .ToArray(); - string[] inputFiles = Directory.GetFiles(resultPath, "*.input") + string[] inputFiles = Directory.GetFiles(userPath, "*.input") .Where(file => getTimeByFileName(file) >= tenMinutesAgo && getTimeByFileName(file) <= currentTime) .OrderBy(file=>file) .ToArray(); @@ -115,7 +127,11 @@ List<PointF3D> points = new List<PointF3D>(); DataTable dt = new DataTable(); dt.Columns.Add("鏃堕棿", typeof(DateTime)); - if (Inputfiles.Count!=0) dt.Columns.Add("鎺ュ彛鏂囦欢"); + if (Inputfiles.Count != 0) + { + dt.Columns.Add("鎺ュ彛鏂囦欢"); + dt.Columns.Add("缁撴灉鏂囦欢"); + } List<double> RecentScada=null; if (files.Count>0) { @@ -140,6 +156,13 @@ param = JsonConvert.DeserializeObject<LogicModelParams>(fileContent); } ParamBuffer.dict.TryAdd(name, param.CloneResult()); + if (ParamBuffer.dict.Count> lastMinutes*3) + { + foreach(var key in ParamBuffer.dict.Keys.ToList()) + { + if (getTimeByFileName(key) < DateTime.Now.AddMinutes(-lastMinutes)) ParamBuffer.dict.TryRemove(key,out LogicModelParams v); + } + } } param.dict_ID.TryGetValue(hostID, out variable obj); @@ -148,6 +171,8 @@ dict dict = new dict(); dict.LoadFromString(obj.objListString); RecentScada = getScadaPumpStatusList(dict); + + } else { @@ -170,16 +195,17 @@ } else { - try - { - param = MessageCompressHelper.ReadCompressedBase64FromFile<LogicModelParams>(file_full); - } - catch - { - // 璇诲彇鏂囦欢鍐呭 - string fileContent = File.ReadAllText(file_full); - param = JsonConvert.DeserializeObject<LogicModelParams>(fileContent); - } + //try + //{ + // param = MessageCompressHelper.ReadCompressedBase64FromFile<LogicModelParams>(file_full); + //} + //catch + //{ + + //} + string fileContent = File.ReadAllText(file_full); + param = JsonConvert.DeserializeObject<LogicModelParams>(fileContent); + // 璇诲彇鏂囦欢鍐呭 ParamBuffer.dict.TryAdd(name, param.CloneResult()); } @@ -220,7 +246,11 @@ if (i==files.Count-1 && dt.Rows.Count==0 || (double)dr["绂忔案鐩爣"] < 4000 && 姘存车鏈彉鍖栨椂姘村巶鍘嬪姏鍙樺寲鏄惁姝e父(doubles, int.Parse( dr["寮�鍏抽噺缁村害鍊�"].ToString()))) { points.Add(new PointF3D(doubles[0], doubles[1], doubles[2], dt.Rows.Count)); - if (Inputfiles.Count != 0) dr["鎺ュ彛鏂囦欢"] = Inputfiles[i]; + if (Inputfiles.Count != 0) + { + dr["鎺ュ彛鏂囦欢"] = Inputfiles[i]; + dr["缁撴灉鏂囦欢"] = files[i]; + } dt.Rows.Add(dr); } } @@ -230,7 +260,13 @@ } } dt.Columns.Add("鏍囪"); - if (Inputfiles.Count != 0) dt.Columns["鎺ュ彛鏂囦欢"].SetOrdinal(dt.Columns.Count-1); + if (Inputfiles.Count != 0) + { + dt.Columns["缁撴灉鏂囦欢"].SetOrdinal(dt.Columns.Count - 1); + dt.Columns["鎺ュ彛鏂囦欢"].SetOrdinal(dt.Columns.Count - 1); + + } + if (points.Count <= 0) return new DataTable(); var filterpoints = points; @@ -253,6 +289,7 @@ dt.Rows[p.rowIndex]["鏍囪"] = ""; } dt.Rows[minP.rowIndex]["鏍囪"] = "鈭�"; + ValidNum=filterpoints.Count; return dt; } @@ -274,9 +311,10 @@ static bool 姘存车鏈彉鍖栨椂姘村巶鍘嬪姏鍙樺寲鏄惁姝e父(double[] doubles,int 寮�鍏抽噺) { if (寮�鍏抽噺 != 0) return true; - var 绔嬫柊鍙樺寲= Math.Abs(doubles[0] - doubles[3]); - var 鍑ゅ嚢鍙樺寲 = Math.Abs(doubles[1] - doubles[4]); - if (绔嬫柊鍙樺寲*101.972 > 1.2 || 鍑ゅ嚢鍙樺寲*101.972 > 1.2) return false; + var 绔嬫柊鍙樺寲= doubles[0] - doubles[3]; + var 鍑ゅ嚢鍙樺寲 = doubles[1] - doubles[4]; + + if (绔嬫柊鍙樺寲* 鍑ゅ嚢鍙樺寲<0 && (Math.Abs(绔嬫柊鍙樺寲) *101.972 > 1.2 || Math.Abs(鍑ゅ嚢鍙樺寲) *101.972 > 1.2)) return false; return true; } static DateTime getTimeByFileName(string filename) @@ -413,19 +451,31 @@ double stdDev = Math.Sqrt(sumOfSquares / values.Count); return stdDev; } - + static string getOptString(double x) + { + if (x < 0) return "鍏抽棴"; + else return "寮�鍚�"; + } public static string getOrderTxt(DataView dv, int bestRowIndex) { - + if (bestRowIndex < 0) return null; DataRowView row = dv[bestRowIndex]; int recentRowIndex = dv.Count - 1; double num = (double)dv[bestRowIndex][3]; + + bool isChangePump = false; + if (num<-1000) + { + isChangePump = true; + } string stateTxt = (num > 0) ? "寮�鍚�" : "鍏抽棴"; int num1 = (int)Math.Abs(num); int PumpNum = num1 / 100; string facTxt = (PumpNum <= 5) ? "绔嬫柊" : "鍑ゅ嚢"; int PumpNumShow = PumpNum > 5 ? PumpNum - 5 : PumpNum; - string pumpChangeTxt = num == 0 ? "姘存车寮�鍋滀笉鍙�" : $"{facTxt}{stateTxt}{PumpNumShow}#娉�"; + //string pumpChangeTxt = num == 0 ? "姘存车寮�鍋滀笉鍙�" : $"{facTxt}{stateTxt}{PumpNumShow}#娉�"; + string pumpChangeTxt_lx = ""; + string pumpChangeTxt_fh = ""; var time = DateTime.Now; string PumpStateList_lx0 = ""; string PumpStateList_fh0 = ""; @@ -433,46 +483,58 @@ string PumpStateList_fh1 = ""; for (int i = 1; i <= 5; i++) { - if ((double)dv[bestRowIndex][5 + i] == 1) - { - PumpStateList_lx1 += $"{i}#"; - if (i != PumpNum) - { - PumpStateList_lx0 += $"{i}#"; - } - } - else if (i == PumpNum) - { - PumpStateList_lx0 += $"{i}#"; - } + double d = 0; + if ((d = (double)dv[bestRowIndex][15 + i]) == 1) PumpStateList_lx0 += $"{i}#"; + if ((d = (double)dv[bestRowIndex][20 + i]) == 1) PumpStateList_fh0 += $"{i}#"; + if ((d = (double)dv[bestRowIndex][5 + i]) == 1) PumpStateList_lx1 += $"{i}#"; + if ((d = (double)dv[bestRowIndex][10 + i]) == 1) PumpStateList_fh1 += $"{i}#"; + if ((d=(double)dv[bestRowIndex][25 + i]) != 0) pumpChangeTxt_lx += $"{getOptString(d)}{i}#"; + if ((d = (double)dv[bestRowIndex][30 + i]) != 0) pumpChangeTxt_fh += $"{getOptString(d)}{i}#"; } + if (pumpChangeTxt_lx != "") pumpChangeTxt_lx = "绔嬫柊" + pumpChangeTxt_lx; + if (pumpChangeTxt_fh != "") pumpChangeTxt_fh = "鍑ゅ嚢" + pumpChangeTxt_fh; + //for (int i = 1; i <= 5; i++) + //{ + // if ((double)dv[bestRowIndex][5 + i] == 1) + // { + // PumpStateList_lx1 += $"{i}#"; + // if (i != PumpNum) + // { + // PumpStateList_lx0 += $"{i}#"; + // } + // } + // else if (i == PumpNum) + // { + // PumpStateList_lx0 += $"{i}#"; + // } + //} - PumpNum = PumpNum - 5; - for (int i = 1; i <= 5; i++) - { - if ((double)dv[bestRowIndex][10 + i] == 1) - { - PumpStateList_fh1 += $"{i}#"; - if (i != PumpNum) - { - PumpStateList_fh0 += $"{i}#"; - } - } - else if (i == PumpNum) - { - PumpStateList_fh0 += $"{i}#"; - } - } + //PumpNum = PumpNum - 5; + //for (int i = 1; i <= 5; i++) + //{ + // if ((double)dv[bestRowIndex][10 + i] == 1) + // { + // PumpStateList_fh1 += $"{i}#"; + // if (i != PumpNum) + // { + // PumpStateList_fh0 += $"{i}#"; + // } + // } + // else if (i == PumpNum) + // { + // PumpStateList_fh0 += $"{i}#"; + // } + //} string txt = $@"{time:HH:mm} 鏂规鍐呭锛� 飩� 褰撳墠杩愯鏂规锛� -绔嬫柊锛歿PumpStateList_lx0} 鍑哄巶鍘嬪姏锛歿dv[recentRowIndex][4]}MPa -鍑ゅ嚢锛歿PumpStateList_fh0} 鍑哄巶鍘嬪姏锛歿dv[recentRowIndex][5]}MPa +绔嬫柊锛歿PumpStateList_lx0} 鍑哄巶鍘嬪姏锛歿dv[recentRowIndex][4]:0.000}MPa 鍑哄巶娴侀噺锛歿dv[recentRowIndex][38]:0}m鲁/h +鍑ゅ嚢锛歿PumpStateList_fh0} 鍑哄巶鍘嬪姏锛歿dv[recentRowIndex][5]:0.000}MPa 鍑哄巶娴侀噺锛歿dv[recentRowIndex][39]:0}m鲁/h 飩� 鎺ㄨ崘鏂规锛� -绔嬫柊锛歿PumpStateList_lx1} 鍑哄巶鍘嬪姏锛歿dv[bestRowIndex][1]}MPa -鍑ゅ嚢锛歿PumpStateList_fh1} 鍑哄巶鍘嬪姏锛歿dv[bestRowIndex][2]}MPa -{pumpChangeTxt}锛屽帇鍔涜皟鏁� +绔嬫柊锛歿PumpStateList_lx1} 鍑哄巶鍘嬪姏锛歿dv[bestRowIndex][1]:0.000}MPa 鍑哄巶娴侀噺锛歿dv[recentRowIndex][36]:0}m鲁/h +鍑ゅ嚢锛歿PumpStateList_fh1} 鍑哄巶鍘嬪姏锛歿dv[bestRowIndex][2]:0.000}MPa 鍑哄巶娴侀噺锛歿dv[recentRowIndex][37]:0}m鲁/h +{pumpChangeTxt_lx}{pumpChangeTxt_fh} "; txt = txt.Trim('\n').Trim(' '); return txt; @@ -490,26 +552,28 @@ content = txt } }); - - using (HttpClient client = new HttpClient()) + if (url == null) return "url is null"; + foreach(var url0 in url.Split(';')) { - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - - HttpContent content = new StringContent(param, Encoding.UTF8, "application/json"); - - HttpResponseMessage response = client.PostAsync(url, content).Result; - - if (response.IsSuccessStatusCode) + using (HttpClient client = new HttpClient()) { - // 鍙戦�佹垚鍔� - return null; - } - else - { - // 鍙戦�佸け璐� - return response.ReasonPhrase; + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + + HttpContent content = new StringContent(param, Encoding.UTF8, "application/json"); + + HttpResponseMessage response = client.PostAsync(url0, content).Result; + + if (!response.IsSuccessStatusCode) + { + // 鍙戦�佸け璐� + return response.ReasonPhrase; + } } } + // 鍙戦�佹垚鍔� + return null; + + } } class PointF3D -- Gitblit v1.9.3