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 dictWCFTSpeed; public Dictionary DictWCFTSpeed { get { if (dictWCFTSpeed == null) dictWCFTSpeed = createDictWCFTSpeed(); return dictWCFTSpeed; } } private Dictionary createDictWCFTSpeed() { Dictionary result = new Dictionary(); 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 dictStation; public Dictionary DictStation { get { if (dictStation == null) dictStation = createDictStation(); return dictStation; } } private Dictionary createDictStation() { Dictionary result = new Dictionary(); //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 dictTag = new Dictionary(); #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中对应风向下的数据值,且风机为待机状态,建议风机启动; } } }