123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- using System.Collections.Generic;
- using System.Linq;
- using GDNXFD.Data.Repositories;
- //using log4net;
- using System;
- using GDNXFD.Data;
- using System.Threading;
- using System.Configuration;
- using System.Collections;
- using GDNXFD.WcfService.RealtimeState;
- using WisdomClient;
- namespace GDNXFD.WcfService
- {
- public class PredictCalculator
- {
- #region WindturbineCFTSpeed
- private Dictionary<string, WindturbineCFTSpeed> dictWCFTSpeed;
- public Dictionary<string, WindturbineCFTSpeed> DictWCFTSpeed
- {
- get
- {
- if (dictWCFTSpeed == null)
- dictWCFTSpeed = createDictWCFTSpeed();
- return dictWCFTSpeed;
- }
- }
- private Dictionary<string, WindturbineCFTSpeed> createDictWCFTSpeed()
- {
- Dictionary<string, WindturbineCFTSpeed> result = new Dictionary<string, WindturbineCFTSpeed>();
- var lst = CustomRepository.GetWindturbineCFTSpeed();
- if (lst != null && lst.Count > 0)
- {
- foreach(WindturbineCFTSpeed wcft in lst)
- {
- if (result.ContainsKey(wcft.WindturbineId) == false)
- result.Add(wcft.WindturbineId, wcft);
- }
- }
- return result;
- }
- #endregion
- #region 预测风功率预测数据结构
- private Dictionary<string, StationInfo> dictStation;
- public Dictionary<string, StationInfo> DictStation
- {
- get
- {
- if (dictStation == null)
- dictStation = createDictStation();
- return dictStation;
- }
- }
- private Dictionary<string, StationInfo> createDictStation()
- {
- Dictionary<string, StationInfo> result = new Dictionary<string, StationInfo>();
- //FCFGCDQ0001
- var lst = WindPowerStationRepository.GetStationTestingPointsByUniformCode("FCFGCDQ0001");
- if (lst != null && lst.Count > 0)
- {
- foreach (WindPowerStationTestingPoint tp in lst)
- {
- if (tp.StationId.EndsWith("_FDC") && result.ContainsKey(tp.StationId) == false)
- {
- StationInfo st = new StationInfo();
- st.StationId = tp.StationId;
- TagInfo tagInfo = new TagInfo();
- tagInfo.StationId = st.StationId;
- tagInfo.TagId = tp.Id;
- tagInfo.UniformCode = tp.UniformCode;
- if (dictTag.ContainsKey(tp.StationId) == false)
- dictTag.Add(tp.StationId, tagInfo);
- st.CDQPrdictPower01 = tagInfo;
- st.ListWt = WindTurbineRepository.GetWindTurbinies(st.StationId);
- result.Add(tp.StationId, st);
- }
- }
- }
- return result;
- }
- private Dictionary<string, TagInfo> dictTag = new Dictionary<string, TagInfo>();
- #endregion
- #region 单例模式
- private PredictCalculator()
- {
- }
- public static PredictCalculator Instance
- {
- get { return SingletonCreator.instance; }
- }
- class SingletonCreator
- {
- internal static readonly PredictCalculator instance = new PredictCalculator();
- }
- #endregion
- public void Calc()
- {
- var dictStationInfo = DictStation;
- if (dictTag == null || dictTag.Count == 0)
- return;
- //1. 加载场站风功率预测数据(超短期15分钟)
- string[] tagNames = dictTag.Values.Select(q => q.TagId).ToArray();
- var tsDatas = RestfulClient.findLatestByTagNames(tagNames);
- if (tsDatas == null || tsDatas.Count == 0)
- return;
- foreach(var kv in tsDatas)
- {
- if (dictTag.ContainsKey(kv.Key))
- {
- var tag = dictTag[kv.Key];
- tag.TagData = kv.Value;
- }
- }
- var dictWtInfo = AdviceCache.Instance.dicWindturbineInfo;
- if (dictWtInfo == null || dictWtInfo.Count == 0)
- return;
- var dictCFTData = DictWCFTSpeed;
- if (dictCFTData == null || dictCFTData.Count == 0)
- return;
- //2.遍历dictStation
- foreach (var st in dictStationInfo.Values)
- {
- var tagData = st.CDQPrdictPower01.TagData;
- if (tagData == null || tagData.ts <= st.lastCalcTs)
- break;
- double power = tagData.doubleValue.Value;
- if (st.ListWt != null && st.ListWt.Count > 0)
- {
- foreach(WindTurbine wt in st.ListWt)
- {
- if (dictWtInfo.ContainsKey(wt.Id))
- {
- var wtInfo = dictWtInfo[wt.Id];
- //当预测功率大于对应风向下的临界功率,若风机未启动,建议启动;
- if (wtInfo == null || wtInfo.StatusCode == null || wtInfo.StatusCode.TagData == null || wtInfo.StatusCode.TagData.doubleValue == null
- || wtInfo.WindDirectionCode == null || wtInfo.WindDirectionCode.TagData == null || wtInfo.WindDirectionCode.TagData.doubleValue == null)
- continue;
- //0-停机、 1-上电、2-待机、3-启动、4-并网、5-故障、6-维护、 7-离线
- int wtStatus = (int)wtInfo.StatusCode.TagData.doubleValue.Value;
- if (wtStatus == 0 || wtStatus == 2 )
- {
- double direction = wtInfo.WindDirectionCode.TagData.doubleValue.Value;
- string strDir = HelpperMethod.GetWindDirection(direction);
- var cftSpeed = dictCFTData[wt.Id];
- if (cftSpeed == null)
- continue;
- double limitValue = cftSpeed.GetDirectionValue(strDir);
- if (limitValue > 0 && power > limitValue)
- {
- //推荐启动
- }
-
- }
-
-
- }
- }
- }
- st.lastCalcTs = st.CDQPrdictPower01.TagData.ts;
-
- }
- //1. 加载WindturbineCFTSpeed数据
- //2.
- //3. 加载风速、风向、状态数据
- //4. 如果场站预测功率大于WindturbineCFTSpeed中对应风向下的数据值,且风机为待机状态,建议风机启动;
- }
- }
- }
|