123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Cache;
- using System.Text;
- using System.Threading.Tasks;
- using EntityDataSet;
- using IntelligentControlForsx.Common;
- using IntelligentControlForsx.Service.WindturbineControl.Domain;
- using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
- using WisdomClient;
- using WisdomClient.data;
- namespace IntelligentControlForsx.Service.CleverRecommend
- {
- /// <summary>
- /// 启停智能计算
- /// </summary>
- public class CalculationSvc
- {
- #region 构造方法--单例
- private CalculationSvc()
- {
- }
- public static CalculationSvc Instance
- {
- get { return SingletonCreator.instance; }
- }
- private class SingletonCreator
- {
- internal static readonly CalculationSvc instance = new CalculationSvc();
- }
- #endregion
- /// <summary>
- /// 推荐控制风机集合 key 风场编号,value为推荐集合
- /// </summary>
- public static Dictionary<string, IList<RecommendData>> RecommendDic = new Dictionary<string, IList<RecommendData>>();
- /// <summary>
- /// 风机实时状态 key风场编号,value为风机信息集合
- /// </summary>
- public static Dictionary<string, IList<WInfo>> InfoDic = new Dictionary<string, IList<WInfo>>();
- /// <summary>
- /// 风机控制计算方法
- /// </summary>
- /// <param name="stationId">风场编号</param>
- public static void WindturbineCalculation(object stationId)
- {
- IList<WInfo> infoList = new List<WInfo>();
- if (!InfoDic.ContainsKey((string)stationId))
- GetWindturbineInfo(stationId);
- infoList = InfoDic[(string)stationId];
- //风机启动推荐集合 待机状态,60s平均风速大于4.5m/s,非挂牌
- IList<WInfo> startList =
- infoList.Where(
- s => s.Status == WindturbineStatus.Standby && s.WindSpeed.HasValue && s.WindSpeed.Value > 4.5 && s.LimitInvolvement == HungType.UnLock)
- .ToList();
- //风机停机推荐集合 并网状态,60s平均风速小于4.5m/s,非挂牌
- IList<WInfo> stopList = infoList.Where(
- s => s.Status == WindturbineStatus.Online && s.WindSpeed.HasValue && s.WindSpeed.Value < 4.5 && s.LimitInvolvement == HungType.UnLock)
- .ToList();
- //风机复位推荐集合 故障状态,故障情况允许进行复位操作,风机型号不为UP105
- IList<WInfo> resetList = infoList.Where(
- s => s.Status == WindturbineStatus.Fault && s.LimitInvolvement == HungType.UnLock)
- .ToList();
- IList<RecommendData> recommendList = new List<RecommendData>();
- DateTime time = DateTime.Now;
- for (int i = 0; i < startList.Count; i++)
- {
- RecommendData rdata = new RecommendData();
- rdata.WindturbineId = startList[i].WindturbineId;
- rdata.RecommendType = CmdType.Start;
- rdata.Status = startList[i].Status;
- rdata.RecommendTime = time;
- rdata.RecommendReason = "--";
- recommendList.Add(rdata);
- }
- for (int i = 0; i < stopList.Count; i++)
- {
- RecommendData rdata = new RecommendData();
- rdata.WindturbineId = stopList[i].WindturbineId;
- rdata.RecommendType = CmdType.Stop;
- rdata.Status = stopList[i].Status;
- rdata.RecommendTime = time;
- rdata.RecommendReason = "--";
- recommendList.Add(rdata);
- }
- for (int i = 0; i < resetList.Count; i++)
- {
- RecommendData rdata = new RecommendData();
- rdata.WindturbineId = resetList[i].WindturbineId;
- rdata.RecommendType = CmdType.Reset;
- rdata.Status = resetList[i].Status;
- rdata.RecommendTime = time;
- rdata.RecommendReason = "--";
- recommendList.Add(rdata);
- }
- if (RecommendDic.ContainsKey((string)stationId))
- RecommendDic[(string)stationId] = recommendList;
- else
- RecommendDic.Add((string)stationId, recommendList);
- }
- /// <summary>
- /// 获取风机当前信息(风速,状态等)
- /// </summary>
- /// <param name="stationId"></param>
- public static void GetWindturbineInfo(object stationId)
- {
- if (!InfoDic.ContainsKey((string)stationId))
- InitInfoDic((string)stationId);
- IList<WInfo> list = InfoDic[(string)stationId];
- for (int i = 0; i < list.Count; i++)
- {
- string[] codeArr = new[]
- {
- list[i].WindSpeedCode,
- list[i].StatusCode,
- list[i].LimitInvolvementCode
- };
- Dictionary<string, TsData> resultDic = RestfulClient.findLatestByThingCodes("windturbine", list[i].WindturbineId, codeArr);
- if (resultDic.ContainsKey(list[i].WindSpeedCode))
- list[i].WindSpeed = resultDic[list[i].WindSpeedCode].doubleValue.HasValue
- ? resultDic[list[i].WindSpeedCode].doubleValue.Value
- : 0.0;
- if (resultDic.ContainsKey(list[i].StatusCode))
- {
- if (resultDic[list[i].StatusCode].doubleValue.HasValue)
- list[i].Status =
- CommonMethod.GetWindturbineStatus(resultDic[list[i].StatusCode].doubleValue.Value);
- }
- if (resultDic.ContainsKey(list[i].WindSpeedCode))
- {
- if (resultDic[list[i].WindSpeedCode].doubleValue.HasValue)
- {
- list[i].WindSpeed = resultDic[list[i].WindSpeedCode].doubleValue;
- }
- }
- if (resultDic.ContainsKey(list[i].LimitInvolvementCode))
- {
- if (resultDic[list[i].LimitInvolvementCode].doubleValue.HasValue)
- {
- list[i].LimitInvolvement = CommonMethod.GetHungLock(resultDic[list[i].LimitInvolvementCode].doubleValue.Value);
- }
- }
- }
- }
- /// <summary>
- /// 获取风机当前信息统一编码
- /// </summary>
- /// <param name="stationId"></param>
- public static void InitInfoDic(string stationId)
- {
- IList<windturbine_uniform_code> list = new List<windturbine_uniform_code>();
- using (wisdom_cs_entity ctx = new wisdom_cs_entity())
- {
- list = ctx.windturbine_uniform_code.Where(s => s.station_id == stationId).ToList();
- }
- IList<WInfo> infoList = new List<WInfo>();
- for (int i = 0; i < list.Count; i++)
- {
- WInfo w = new WInfo();
- w.WindturbineId = list[i].windturbine_id;
- w.StatusCode = list[i].status_uniform_code;
- w.ModelId = list[i].model_id;
- w.LimitInvolvementCode = "XDSL";
- if (list[i].model_id.Contains("105"))
- w.WindSpeedCode = "AI373";//中期平均风速
- else
- w.WindSpeedCode = "AI024";//60s平均风速
- infoList.Add(w);
- }
- if (!InfoDic.ContainsKey(stationId))
- InfoDic.Add(stationId, infoList);
- }
- }
- }
|