PredictCalculator.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using GDNXFD.Data.Repositories;
  4. //using log4net;
  5. using System;
  6. using GDNXFD.Data;
  7. using System.Threading;
  8. using System.Configuration;
  9. using System.Collections;
  10. using GDNXFD.WcfService.RealtimeState;
  11. using WisdomClient;
  12. namespace GDNXFD.WcfService
  13. {
  14. public class PredictCalculator
  15. {
  16. #region WindturbineCFTSpeed
  17. private Dictionary<string, WindturbineCFTSpeed> dictWCFTSpeed;
  18. public Dictionary<string, WindturbineCFTSpeed> DictWCFTSpeed
  19. {
  20. get
  21. {
  22. if (dictWCFTSpeed == null)
  23. dictWCFTSpeed = createDictWCFTSpeed();
  24. return dictWCFTSpeed;
  25. }
  26. }
  27. private Dictionary<string, WindturbineCFTSpeed> createDictWCFTSpeed()
  28. {
  29. Dictionary<string, WindturbineCFTSpeed> result = new Dictionary<string, WindturbineCFTSpeed>();
  30. var lst = CustomRepository.GetWindturbineCFTSpeed();
  31. if (lst != null && lst.Count > 0)
  32. {
  33. foreach(WindturbineCFTSpeed wcft in lst)
  34. {
  35. if (result.ContainsKey(wcft.WindturbineId) == false)
  36. result.Add(wcft.WindturbineId, wcft);
  37. }
  38. }
  39. return result;
  40. }
  41. #endregion
  42. #region 预测风功率预测数据结构
  43. private Dictionary<string, StationInfo> dictStation;
  44. public Dictionary<string, StationInfo> DictStation
  45. {
  46. get
  47. {
  48. if (dictStation == null)
  49. dictStation = createDictStation();
  50. return dictStation;
  51. }
  52. }
  53. private Dictionary<string, StationInfo> createDictStation()
  54. {
  55. Dictionary<string, StationInfo> result = new Dictionary<string, StationInfo>();
  56. //FCFGCDQ0001
  57. var lst = WindPowerStationRepository.GetStationTestingPointsByUniformCode("FCFGCDQ0001");
  58. if (lst != null && lst.Count > 0)
  59. {
  60. foreach (WindPowerStationTestingPoint tp in lst)
  61. {
  62. if (tp.StationId.EndsWith("_FDC") && result.ContainsKey(tp.StationId) == false)
  63. {
  64. StationInfo st = new StationInfo();
  65. st.StationId = tp.StationId;
  66. TagInfo tagInfo = new TagInfo();
  67. tagInfo.StationId = st.StationId;
  68. tagInfo.TagId = tp.Id;
  69. tagInfo.UniformCode = tp.UniformCode;
  70. if (dictTag.ContainsKey(tp.StationId) == false)
  71. dictTag.Add(tp.StationId, tagInfo);
  72. st.CDQPrdictPower01 = tagInfo;
  73. st.ListWt = WindTurbineRepository.GetWindTurbinies(st.StationId);
  74. result.Add(tp.StationId, st);
  75. }
  76. }
  77. }
  78. return result;
  79. }
  80. private Dictionary<string, TagInfo> dictTag = new Dictionary<string, TagInfo>();
  81. #endregion
  82. #region 单例模式
  83. private PredictCalculator()
  84. {
  85. }
  86. public static PredictCalculator Instance
  87. {
  88. get { return SingletonCreator.instance; }
  89. }
  90. class SingletonCreator
  91. {
  92. internal static readonly PredictCalculator instance = new PredictCalculator();
  93. }
  94. #endregion
  95. public void Calc()
  96. {
  97. var dictStationInfo = DictStation;
  98. if (dictTag == null || dictTag.Count == 0)
  99. return;
  100. //1. 加载场站风功率预测数据(超短期15分钟)
  101. string[] tagNames = dictTag.Values.Select(q => q.TagId).ToArray();
  102. var tsDatas = RestfulClient.findLatestByTagNames(tagNames);
  103. if (tsDatas == null || tsDatas.Count == 0)
  104. return;
  105. foreach(var kv in tsDatas)
  106. {
  107. if (dictTag.ContainsKey(kv.Key))
  108. {
  109. var tag = dictTag[kv.Key];
  110. tag.TagData = kv.Value;
  111. }
  112. }
  113. var dictWtInfo = AdviceCache.Instance.dicWindturbineInfo;
  114. if (dictWtInfo == null || dictWtInfo.Count == 0)
  115. return;
  116. var dictCFTData = DictWCFTSpeed;
  117. if (dictCFTData == null || dictCFTData.Count == 0)
  118. return;
  119. //2.遍历dictStation
  120. foreach (var st in dictStationInfo.Values)
  121. {
  122. var tagData = st.CDQPrdictPower01.TagData;
  123. if (tagData == null || tagData.ts <= st.lastCalcTs)
  124. break;
  125. double power = tagData.doubleValue.Value;
  126. if (st.ListWt != null && st.ListWt.Count > 0)
  127. {
  128. foreach(WindTurbine wt in st.ListWt)
  129. {
  130. if (dictWtInfo.ContainsKey(wt.Id))
  131. {
  132. var wtInfo = dictWtInfo[wt.Id];
  133. //当预测功率大于对应风向下的临界功率,若风机未启动,建议启动;
  134. if (wtInfo == null || wtInfo.StatusCode == null || wtInfo.StatusCode.TagData == null || wtInfo.StatusCode.TagData.doubleValue == null
  135. || wtInfo.WindDirectionCode == null || wtInfo.WindDirectionCode.TagData == null || wtInfo.WindDirectionCode.TagData.doubleValue == null)
  136. continue;
  137. //0-停机、 1-上电、2-待机、3-启动、4-并网、5-故障、6-维护、 7-离线
  138. int wtStatus = (int)wtInfo.StatusCode.TagData.doubleValue.Value;
  139. if (wtStatus == 0 || wtStatus == 2 )
  140. {
  141. double direction = wtInfo.WindDirectionCode.TagData.doubleValue.Value;
  142. string strDir = HelpperMethod.GetWindDirection(direction);
  143. var cftSpeed = dictCFTData[wt.Id];
  144. if (cftSpeed == null)
  145. continue;
  146. double limitValue = cftSpeed.GetDirectionValue(strDir);
  147. if (limitValue > 0 && power > limitValue)
  148. {
  149. //推荐启动
  150. }
  151. }
  152. }
  153. }
  154. }
  155. st.lastCalcTs = st.CDQPrdictPower01.TagData.ts;
  156. }
  157. //1. 加载WindturbineCFTSpeed数据
  158. //2.
  159. //3. 加载风速、风向、状态数据
  160. //4. 如果场站预测功率大于WindturbineCFTSpeed中对应风向下的数据值,且风机为待机状态,建议风机启动;
  161. }
  162. }
  163. }