PageWindturbineAGC.xaml.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using log4net;
  2. using NEIntelligentControl2.Models.Datas;
  3. using NEIntelligentControl2.Models.Messages;
  4. using NEIntelligentControl2.Models.Pages;
  5. using NEIntelligentControl2.Models.Windturbine;
  6. using NEIntelligentControl2.Service.WebSocket;
  7. using NEIntelligentControl2.Views.Matrix;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Configuration;
  11. using System.Linq;
  12. using System.Security.Policy;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. using System.Windows.Data;
  18. using System.Windows.Documents;
  19. using System.Windows.Input;
  20. using System.Windows.Media;
  21. using System.Windows.Media.Imaging;
  22. using System.Windows.Navigation;
  23. using System.Windows.Shapes;
  24. namespace NEIntelligentControl2.Pages.Home
  25. {
  26. /// <summary>
  27. /// 风机AGC融合页面
  28. /// </summary>
  29. public partial class PageWindturbineAGC : Page
  30. {
  31. private static readonly ILog log = LogManager.GetLogger("File");
  32. private readonly IPageAction _IPageAction;
  33. private readonly WEBHelper _WEBHelper;
  34. private MessageBridge _MessageBridge;// websocket
  35. private WindturbineInfoBridge _WindturbineInfoBridge;// 风机信息数据桥
  36. /// <summary>
  37. /// 矩阵块
  38. /// </summary>
  39. private List<WindBlock> _WindBlocks;
  40. private bool _IsLoaded;
  41. private string RFDLTag = "";
  42. private string MBGLTag = "";
  43. private string SSGLTag = "";
  44. private string YFDLTag = "";
  45. private string NFDLTag = "";
  46. private string LLGLTag = "";
  47. private string _Url = "";
  48. public PageWindturbineAGC(IPageAction action, MessageBridge mb, WEBHelper web)
  49. {
  50. InitializeComponent();
  51. _IPageAction = action;
  52. _MessageBridge = mb;
  53. _WEBHelper = web;
  54. _WindturbineInfoBridge = new WindturbineInfoBridge() { Messaged = OnWindturbineMessage };
  55. _tbtitle1.Text = "信\n友\n一\n线";
  56. _tbtitle2.Text = "信\n友\n二\n线";
  57. _tbtitle3.Text = "信\n友\n三\n线";
  58. _Url = ConfigurationManager.AppSettings["DataServicePathDebug"];
  59. RFDLTag = ConfigurationManager.AppSettings["RFDLTag"];
  60. MBGLTag = ConfigurationManager.AppSettings["MBGLTag"];
  61. SSGLTag = ConfigurationManager.AppSettings["SSGLTag"];
  62. YFDLTag = ConfigurationManager.AppSettings["YFDLTag"];
  63. NFDLTag = ConfigurationManager.AppSettings["NFDLTag"];
  64. LLGLTag = ConfigurationManager.AppSettings["LLGLTag"];
  65. log.Warn($"日月年发");
  66. }
  67. private void OnWindturbineMessage(Dictionary<string, WindturbineInfo> obj)
  68. {
  69. if (!_IsLoaded)
  70. {
  71. InitWindturbine(obj);
  72. return;
  73. }
  74. Dispatcher.Invoke(() =>
  75. {
  76. foreach (var v in _WindBlocks)
  77. {
  78. if (!obj.ContainsKey(v.WindturbineId)) continue;
  79. v.Update(obj[v.WindturbineId]);
  80. }
  81. });
  82. }
  83. private void InitWindturbine(Dictionary<string, WindturbineInfo> obj)
  84. {
  85. if (obj == null || obj.Count == 0) return;
  86. _IsLoaded = true;
  87. _WindBlocks = new List<WindBlock>();
  88. var ls = obj.Values.ToList();
  89. ls.Sort((x, y) => x.ID - y.ID);
  90. Dispatcher.Invoke(() =>
  91. {
  92. foreach (var v in ls)
  93. {
  94. WindBlock bs = new WindBlock(v) { WindturbineId = v.WindturbineId };
  95. bs.Update(v);
  96. _WindBlocks.Add(bs);
  97. if ((v.ID >= 1 && v.ID <= 5) || (v.ID >= 11 && v.ID <= 13))
  98. {
  99. pb1.AddWindturbine(bs);
  100. }
  101. else if ((v.ID >= 6 && v.ID <= 10) || (v.ID >= 16 && v.ID <= 19))
  102. {
  103. pb2.AddWindturbine(bs);
  104. }
  105. else
  106. {
  107. pb3.AddWindturbine(bs);
  108. }
  109. }
  110. });
  111. }
  112. private void Page_Loaded(object sender, RoutedEventArgs e)
  113. {
  114. //var page = _IPageAction["Matrix.PageMatrix"];
  115. //_FrameMatrix.Navigate(page);
  116. var page2 = _IPageAction["AGC.PageAGC"];
  117. _FrameAGC.Navigate(page2);
  118. _MessageBridge.Register(_WindturbineInfoBridge);
  119. Task.Run(RefresData);
  120. }
  121. private async void RefresData()
  122. {
  123. string url = $"{_Url}/ts/latest?keys={RFDLTag},{YFDLTag},{NFDLTag}";
  124. while (true)
  125. {
  126. try
  127. {
  128. //
  129. var vs = GetValues(url);
  130. foreach (var v in vs)
  131. {
  132. log.Warn($"日月年发:{v.Value.Value}");
  133. }
  134. if (vs == null || vs.Count == 0) continue;
  135. var ss = GetValuesSingle(SSGLTag);
  136. log.Warn($"实时:{ss.Value}");
  137. var mb = GetValuesSingle(MBGLTag);
  138. log.Warn($"目标:{mb.Value}");
  139. var ll = GetValuesSingle(LLGLTag);
  140. log.Warn($"理论:{ll.Value}");
  141. Dispatcher.Invoke(() =>
  142. {
  143. try
  144. {
  145. tbps.Text = Math.Round(ss.Value, 2).ToString("0.00");
  146. tbpc.Text = Math.Round(mb.Value, 2).ToString("0.00");
  147. tbllgl.Text = Math.Round(ll.Value, 2).ToString("0.00");
  148. }
  149. catch (Exception e)
  150. {
  151. log.Error($"实时{e.Message}");
  152. }
  153. try
  154. {
  155. foreach (var v in vs)
  156. {
  157. if (v.Key == RFDLTag)
  158. {
  159. tbrf.Text = Math.Round(v.Value.Value, 2).ToString("0.00");
  160. }
  161. if (v.Key == YFDLTag)
  162. {
  163. tbyf.Text = Math.Round(v.Value.Value, 2).ToString("0.00");
  164. }
  165. if (v.Key == NFDLTag)
  166. {
  167. var nval = v.Value.Value;
  168. tbly.Text = Math.Round(nval / 50, 2).ToString("0.00");
  169. tbnf.Text = Math.Round(nval, 2).ToString("0.00");
  170. }
  171. }
  172. var date = DateTime.Parse("2023-2-18");
  173. var time = (int)(DateTime.Now - date).TotalDays;
  174. aqts.Text = $"{619 + time} 天";
  175. }
  176. catch (Exception e)
  177. {
  178. log.Error($"日月年发{e.Message}");
  179. }
  180. });
  181. }
  182. catch (Exception e)
  183. {
  184. log.Error($"右下{e.Message}");
  185. }
  186. await Task.Delay(1000);
  187. }
  188. }
  189. private Dictionary<string, TsData> GetValues(string url)
  190. {
  191. Dictionary<string, TsData> datas = new Dictionary<string, TsData>();
  192. try
  193. {
  194. datas = _WEBHelper.HttpGetJSON<Dictionary<string, TsData>>(url);
  195. }
  196. catch { }
  197. return datas;
  198. }
  199. private TsData GetValuesSingle(string key)
  200. {
  201. var data = new TsData();
  202. var url = $"{_Url}/ts/latest?keys={key}";
  203. try
  204. {
  205. var datas = _WEBHelper.HttpGetJSON<Dictionary<string, TsData>>(url);
  206. if (datas != null && datas.ContainsKey(key))
  207. {
  208. return datas[key];
  209. }
  210. return data;
  211. }
  212. catch { }
  213. return data;
  214. }
  215. }
  216. }