CalculationSvc.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Cache;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using EntityDataSet;
  8. using IntelligentControlForsx.Common;
  9. using IntelligentControlForsx.Service.WindturbineControl.Domain;
  10. using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
  11. using WisdomClient;
  12. using WisdomClient.data;
  13. namespace IntelligentControlForsx.Service.CleverRecommend
  14. {
  15. /// <summary>
  16. /// 启停智能计算
  17. /// </summary>
  18. public class CalculationSvc
  19. {
  20. #region 构造方法--单例
  21. private CalculationSvc()
  22. {
  23. }
  24. public static CalculationSvc Instance
  25. {
  26. get { return SingletonCreator.instance; }
  27. }
  28. private class SingletonCreator
  29. {
  30. internal static readonly CalculationSvc instance = new CalculationSvc();
  31. }
  32. #endregion
  33. /// <summary>
  34. /// 推荐控制风机集合 key 风场编号,value为推荐集合
  35. /// </summary>
  36. public static Dictionary<string, IList<RecommendData>> RecommendDic = new Dictionary<string, IList<RecommendData>>();
  37. /// <summary>
  38. /// 风机实时状态 key风场编号,value为风机信息集合
  39. /// </summary>
  40. public static Dictionary<string, IList<WInfo>> InfoDic = new Dictionary<string, IList<WInfo>>();
  41. /// <summary>
  42. /// 风机控制计算方法
  43. /// </summary>
  44. /// <param name="stationId">风场编号</param>
  45. public static void WindturbineCalculation(object stationId)
  46. {
  47. IList<WInfo> infoList = new List<WInfo>();
  48. if (!InfoDic.ContainsKey((string)stationId))
  49. GetWindturbineInfo(stationId);
  50. infoList = InfoDic[(string)stationId];
  51. //风机启动推荐集合 待机状态,60s平均风速大于4.5m/s,非挂牌
  52. IList<WInfo> startList =
  53. infoList.Where(
  54. s => s.Status == WindturbineStatus.Standby && s.WindSpeed.HasValue && s.WindSpeed.Value > 4.5 && s.LimitInvolvement == HungType.UnLock)
  55. .ToList();
  56. //风机停机推荐集合 并网状态,60s平均风速小于4.5m/s,非挂牌
  57. IList<WInfo> stopList = infoList.Where(
  58. s => s.Status == WindturbineStatus.Online && s.WindSpeed.HasValue && s.WindSpeed.Value < 4.5 && s.LimitInvolvement == HungType.UnLock)
  59. .ToList();
  60. //风机复位推荐集合 故障状态,故障情况允许进行复位操作,风机型号不为UP105
  61. IList<WInfo> resetList = infoList.Where(
  62. s => s.Status == WindturbineStatus.Fault && s.LimitInvolvement == HungType.UnLock)
  63. .ToList();
  64. IList<RecommendData> recommendList = new List<RecommendData>();
  65. DateTime time = DateTime.Now;
  66. for (int i = 0; i < startList.Count; i++)
  67. {
  68. RecommendData rdata = new RecommendData();
  69. rdata.WindturbineId = startList[i].WindturbineId;
  70. rdata.RecommendType = CmdType.Start;
  71. rdata.Status = startList[i].Status;
  72. rdata.RecommendTime = time;
  73. rdata.RecommendReason = "--";
  74. recommendList.Add(rdata);
  75. }
  76. for (int i = 0; i < stopList.Count; i++)
  77. {
  78. RecommendData rdata = new RecommendData();
  79. rdata.WindturbineId = stopList[i].WindturbineId;
  80. rdata.RecommendType = CmdType.Stop;
  81. rdata.Status = stopList[i].Status;
  82. rdata.RecommendTime = time;
  83. rdata.RecommendReason = "--";
  84. recommendList.Add(rdata);
  85. }
  86. for (int i = 0; i < resetList.Count; i++)
  87. {
  88. RecommendData rdata = new RecommendData();
  89. rdata.WindturbineId = resetList[i].WindturbineId;
  90. rdata.RecommendType = CmdType.Reset;
  91. rdata.Status = resetList[i].Status;
  92. rdata.RecommendTime = time;
  93. rdata.RecommendReason = "--";
  94. recommendList.Add(rdata);
  95. }
  96. if (RecommendDic.ContainsKey((string)stationId))
  97. RecommendDic[(string)stationId] = recommendList;
  98. else
  99. RecommendDic.Add((string)stationId, recommendList);
  100. }
  101. /// <summary>
  102. /// 获取风机当前信息(风速,状态等)
  103. /// </summary>
  104. /// <param name="stationId"></param>
  105. public static void GetWindturbineInfo(object stationId)
  106. {
  107. if (!InfoDic.ContainsKey((string)stationId))
  108. InitInfoDic((string)stationId);
  109. IList<WInfo> list = InfoDic[(string)stationId];
  110. for (int i = 0; i < list.Count; i++)
  111. {
  112. string[] codeArr = new[]
  113. {
  114. list[i].WindSpeedCode,
  115. list[i].StatusCode,
  116. list[i].LimitInvolvementCode
  117. };
  118. Dictionary<string, TsData> resultDic = RestfulClient.findLatestByThingCodes("windturbine", list[i].WindturbineId, codeArr);
  119. if (resultDic.ContainsKey(list[i].WindSpeedCode))
  120. list[i].WindSpeed = resultDic[list[i].WindSpeedCode].doubleValue.HasValue
  121. ? resultDic[list[i].WindSpeedCode].doubleValue.Value
  122. : 0.0;
  123. if (resultDic.ContainsKey(list[i].StatusCode))
  124. {
  125. if (resultDic[list[i].StatusCode].doubleValue.HasValue)
  126. list[i].Status =
  127. CommonMethod.GetWindturbineStatus(resultDic[list[i].StatusCode].doubleValue.Value);
  128. }
  129. if (resultDic.ContainsKey(list[i].WindSpeedCode))
  130. {
  131. if (resultDic[list[i].WindSpeedCode].doubleValue.HasValue)
  132. {
  133. list[i].WindSpeed = resultDic[list[i].WindSpeedCode].doubleValue;
  134. }
  135. }
  136. if (resultDic.ContainsKey(list[i].LimitInvolvementCode))
  137. {
  138. if (resultDic[list[i].LimitInvolvementCode].doubleValue.HasValue)
  139. {
  140. list[i].LimitInvolvement = CommonMethod.GetHungLock(resultDic[list[i].LimitInvolvementCode].doubleValue.Value);
  141. }
  142. }
  143. }
  144. }
  145. /// <summary>
  146. /// 获取风机当前信息统一编码
  147. /// </summary>
  148. /// <param name="stationId"></param>
  149. public static void InitInfoDic(string stationId)
  150. {
  151. IList<windturbine_uniform_code> list = new List<windturbine_uniform_code>();
  152. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  153. {
  154. list = ctx.windturbine_uniform_code.Where(s => s.station_id == stationId).ToList();
  155. }
  156. IList<WInfo> infoList = new List<WInfo>();
  157. for (int i = 0; i < list.Count; i++)
  158. {
  159. WInfo w = new WInfo();
  160. w.WindturbineId = list[i].windturbine_id;
  161. w.StatusCode = list[i].status_uniform_code;
  162. w.ModelId = list[i].model_id;
  163. w.LimitInvolvementCode = "XDSL";
  164. if (list[i].model_id.Contains("105"))
  165. w.WindSpeedCode = "AI373";//中期平均风速
  166. else
  167. w.WindSpeedCode = "AI024";//60s平均风速
  168. infoList.Add(w);
  169. }
  170. if (!InfoDic.ContainsKey(stationId))
  171. InfoDic.Add(stationId, infoList);
  172. }
  173. }
  174. }