/// <summary> /// 取得采集器日数据列表 /// </summary> /// <returns></returns> public void GetCollectorDaydataList() { //将单元头部的发电量加入历史测点数据map中,然后统一处理 historyMonitorMap[MonitorType.PLANT_MONITORITEM_ENERGY_CODE] = messageHeader.DayEnergy; historyMonitorMap[MonitorType.PLANT_MONITORITEM_POWER_CODE] = messageHeader.Power; int collectorID = GetCollectorId(); //根据历史测点数据构建设备天数据 //这里需要改进为依据设备时间,防止设备数据的时间和采集器的时间是不一致的 CollectorDayData mdd; string mapObjectKey; //遍历测点数据 foreach (int key in historyMonitorMap.Keys) { mapObjectKey = CacheKeyUtil.buildCollectorDayDataKey(collectorID, messageHeader.year + messageHeader.month, int.Parse(messageHeader.day), key); if (!collectordayDataMap.ContainsKey(mapObjectKey)) { //先从缓存中取得 mdd = CollectorDayDataService.GetInstance().getCollectorDayData(collectorID, key, int.Parse(messageHeader.day), int.Parse(messageHeader.year), int.Parse(messageHeader.month)); if (mdd == null) { mdd = new CollectorDayData() { collectorID = collectorID, sendDay = int.Parse(messageHeader.day), monitorCode = key, yearmonth = messageHeader.year + messageHeader.month } } ; collectordayDataMap[mapObjectKey] = mdd; } else { mdd = collectordayDataMap[mapObjectKey]; } float newValue = historyMonitorMap[key] == null?0:float.Parse(historyMonitorMap[key].ToString()); mdd.dataContent += "#" + messageHeader.hour + messageHeader.minute + messageHeader.second + ":" + newValue; mdd.sendtime = messageHeader.TimeNow; mdd.localAcceptTime = DateTime.Now; mdd.yearmonth = messageHeader.year + messageHeader.month; mdd.changed = true; //将功率和关照的最大发生时间记录下来.稍后优化下 if (key == MonitorType.PLANT_MONITORITEM_POWER_CODE) { //if (collectorID >= 189 && collectorID < 199) //{ // LogUtil.writeline(messageHeader.TimeNow + "-" + newValue); //} collectorDataCount = new DeviceDataCount() { deviceId = collectorID, monitorCode = key, year = int.Parse(messageHeader.year), month = int.Parse(messageHeader.month), day = int.Parse(messageHeader.day), deviceTable = TableUtil.PLANT, maxValue = newValue, maxTime = messageHeader.TimeNow, localAcceptTime = DateTime.Now }; } } }
/// <summary> /// 取得电站的日图表数据 /// </summary> /// <param name="pId">电站id</param> /// <param name="startTime">开始时间,格式:yyyyMMddhh 2011111105</param> /// <param name="endTime">截止时间,格式:yyyyMMddhh 2011111223</param> /// <param name="app_key">第三方应用唯一key</param> /// <param name="call_id">请求序号</param> /// <param name="sig">签名</param> /// <param name="v">api版本</param> /// <param name="format">返回结果格式,暂时值支持json</param> /// <param name="lan">语言环境,暂时只支持中英文</param> /// <returns>图表封装的数据</returns> public ActionResult plantDayChartData(int pId, string startDate, string endDate, string app_key, string call_id, string sig, string v, string format, string lan) { setlan(lan); string chartType = ChartType.column; string reportCode = string.Empty; Plant plant = PlantService.GetInstance().GetPlantInfoById(pId); string intervalMins = "5,5"; string[] intervals = intervalMins.Split(','); if (plant != null && plant.plantUnits.Count > 0) { IList <DeviceStuct> devices = new List <DeviceStuct>(); string deviceId = plant.id.ToString(); string[] chartTypes = chartType.Split(','); devices.Add(new DeviceStuct() { deviceId = deviceId, rate = 1.0F, comareObj = plant.name, chartType = chartTypes[0], monitorType = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_POWER_CODE), cVal = ComputeType.Avg, deviceType = ChartDeviceType.PLANT, intervalMins = int.Parse(intervals[0]) }); //判断该测点是否有数据,有数据则增加关照对比 Hashtable dataHash = CollectorDayDataService.GetInstance().GetUnitDaydataList(plant.plantUnits, startDate, endDate, int.Parse(intervals[0]), MonitorType.PLANT_MONITORITEM_POWER_CODE); if (dataHash.Count > 0) { float rate = 1F; MonitorType mt = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_LINGT_CODE); devices.Add(new DeviceStuct() { deviceId = plant.id.ToString(), rate = rate, comareObj = plant.name, name = mt.name, unit = "", chartType = chartTypes[0], monitorType = mt, cVal = ComputeType.Avg, deviceType = ChartDeviceType.PLANT, intervalMins = int.Parse(intervals[1]) }); } else { return(Content("error:" + Resources.SunResource.NODATA)); } string chartName = LanguageUtil.getDesc("PLANT_CHART_DAY_POWER_SUNLIGHT_COMPARE_CHART"); //取得用户年度发电量图表数据 Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = CompareChartService.GetInstance().compareDayHHMultiDeviceMultiMonitor(chartName, devices, startDate, endDate, int.Parse(intervals[0])); reportCode = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData)); } return(Content(reportCode)); }
/// <summary> /// 将数据放入缓存 /// </summary> /// <param name="tcpmessage"></param> public static void CacheData() { try { DateTime curdt = DateTime.Now; //将采集器天数据批量加入缓存 CollectorDayDataService.GetInstance().batchToCache(BaseMessage.collectordayDataMap); LogUtil.writeline("memcached collectordayDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds)); } catch (Exception e) { LogUtil.error("batch Cache day data error:" + e.Message); } try { DateTime curdt = DateTime.Now; //DeviceDayDataService.GetInstance().batchToCache(BaseMessage.devicedayDataMapList); ////将设备天数据批量放入缓存 DeviceDayDataCacheHandler ddch = null; for (int i = 0; i < 50; i++) { if (cacheDayOjectMap.ContainsKey(i)) { ddch = cacheDayOjectMap[i]; } else { ddch = new DeviceDayDataCacheHandler(i); cacheDayOjectMap[i] = ddch; } Thread m_thread = new Thread(new ThreadStart(ddch.batchToCacheList)); m_thread.Name = "memcache Handel Thread-" + i; m_thread.Start(); } int times = 0; bool iswork = isWork(); //如果线程都在工作并且持续时间一分钟之内继续循环,否则跳出循环,进行以后动作,add by qhb in 20120927 for 解析其中有个现场死了,整个程序 //就停在这里了。 while (iswork && times < 60) { times++; iswork = isWork(); Thread.Sleep(1000); } LogUtil.writeline("memcached devicedayDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds)); } catch (Exception e) { LogUtil.error("batch Cache device day data error:" + e.Message); } try { DateTime curdt = DateTime.Now; //缓存采集器实时数据 CollectorRunDataService.GetInstance().batchCache(BaseMessage.collectorRunDataMap.Values); LogUtil.writeline("memcached collectorRunDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds)); } catch (Exception e) { LogUtil.error("batch Cache run data error:" + e.Message); } try { DateTime curdt = DateTime.Now; //批量保存设备实时数据到缓存 DeviceRunDataService.GetInstance().BatchCache(BaseMessage.deviceRunDataMap.Values); LogUtil.writeline("memcached deviceRunDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds)); } catch (Exception e) { LogUtil.error("batch Cache device run data error:" + e.Message); } try { FaultService.GetInstance().batchSave(BaseMessage.faultList); BaseMessage.faultList.Clear(); } catch (Exception e) { LogUtil.info("batch Cache fualt error:" + e.Message); } try { DateTime curdt = DateTime.Now; //将设备最大值统计数据放入缓存 DeviceDataCountService.GetInstance().batchCache(BaseMessage.deviceDataCounts); BaseMessage.deviceDataCounts.Clear(); LogUtil.writeline("memcached deviceDataCounts用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds)); } catch (Exception e) { LogUtil.error("save max value error:" + e.Message); } //将本地内存数据放入缓存后,就要清理本地内存,否有内存溢出问题 //clearDayDataMap(); //每次缓存后 同时将同步到memcahced if (syndata != null && syndata.Equals("true")) { SynDataService.GetInstance().synRunData(); } }
public static void peristentData() { Console.WriteLine("开始持久化"); //持久化设备天数据 try { DeviceDayDataService.GetInstance().batchSave(BaseMessage.devicedayDataMapList); } catch (Exception ee) { LogUtil.error("持久化设备天数据异常:" + ee.Message); } //持久化采集器天数据 try { CollectorDayDataService.GetInstance().batchSave(BaseMessage.collectordayDataMap); } catch (Exception ee) { LogUtil.error("持久化采集器天数据异常:" + ee.Message); } //持久化设备实时数据 try{ DeviceRunDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备实时数据数据异常:" + ee.Message); } //持久化采集器实时数据 try { LogUtil.writeline("start 持久化采集器实时数据"); CollectorRunDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器实时数据异常:" + ee.Message); } //持久化最大值统计 try{ DeviceDataCountService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化最大值统计异常:" + ee.Message); } //持久化设备月天数据 try{ DeviceMonthDayDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备月天数据异常:" + ee.Message); } //持久化采集器月天数据 try{ CollectorMonthDayDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器月天数据异常:" + ee.Message); } //持久化设备年月数据 try{ DeviceYearMonthDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备年月数据异常:" + ee.Message); //DeviceYearMonthDataService.GetInstance().batchSave(); } //持久化采集器年月数据 try{ CollectorYearMonthDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器年月数据异常:" + ee.Message); } //持久化设备总体数据 try{ DeviceYearDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器年月数据异常:" + ee.Message); } //持久化采集器总体数据 try { CollectorYearDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器总体数据异常:" + ee.Message); } //add by qhb in 20120415 for 2.0协议持久化电站信息,持久化后不删除, try { PlantService.GetInstance().batchSave(BaseMessage.plantInfoMap); } catch (Exception ee) { LogUtil.error("持久化电站信息数据异常:" + ee.Message); } //add by qhb in 20120715 for 2.0协议持久化设备信息,持久化后不删除, try { DeviceService.GetInstance().batchSave(BaseMessage.deviceInfoMap); } catch (Exception ee) { LogUtil.error("持久化设备信息数据异常:" + ee.Message); } }
public void peristentData() { Console.WriteLine("开始持久化"); //持久化设备天数据 try { DeviceDayDataService.GetInstance().batchSave(BaseMessage.devicedayDataMapList); } catch (Exception ee) { LogUtil.error("持久化设备天数据异常:" + ee.Message); } //持久化采集器天数据 try { CollectorDayDataService.GetInstance().batchSave(BaseMessage.collectordayDataMap); } catch (Exception ee) { LogUtil.error("持久化采集器天数据异常:" + ee.Message); } //持久化设备实时数据 try{ DeviceRunDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备实时数据数据异常:" + ee.Message); } //持久化采集器实时数据 try { LogUtil.writeline("start 持久化采集器实时数据"); CollectorRunDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器实时数据异常:" + ee.Message); } //持久化最大值统计 try{ DeviceDataCountService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化最大值统计异常:" + ee.Message); } //持久化设备月天数据 try{ DeviceMonthDayDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备月天数据异常:" + ee.Message); } //持久化采集器月天数据 try{ CollectorMonthDayDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器月天数据异常:" + ee.Message); } //持久化设备年月数据 try{ DeviceYearMonthDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备年月数据异常:" + ee.Message); DeviceYearMonthDataService.GetInstance().batchSave(); } //持久化采集器年月数据 try{ CollectorYearMonthDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器年月数据异常:" + ee.Message); } //持久化设备总体数据 try{ DeviceYearDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器年月数据异常:" + ee.Message); } //持久化采集器总体数据 try { CollectorYearDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器总体数据异常:" + ee.Message); } }
/// <summary> /// 将数据放入缓存 /// </summary> /// <param name="tcpmessage"></param> public static void CacheData() { try { DateTime curdt = DateTime.Now; //将采集器天数据批量加入缓存 CollectorDayDataService.GetInstance().batchToCache(BaseMessage.collectordayDataMap); LogUtil.writeline("memcached collectordayDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds)); } catch (Exception e) { LogUtil.error("batch Cache day data error:" + e.Message); } try { DateTime curdt = DateTime.Now; //DeviceDayDataService.GetInstance().batchToCache(BaseMessage.devicedayDataMapList); ////将设备天数据批量放入缓存 DeviceDayDataCacheHandler ddch = null; for (int i = 0; i < 50; i++) { if (cacheDayOjectMap.ContainsKey(i)) { ddch = cacheDayOjectMap[i]; } else { ddch = new DeviceDayDataCacheHandler(i); cacheDayOjectMap[i] = ddch; } Thread m_thread = new Thread(new ThreadStart(ddch.batchToCacheList)); m_thread.Name = "memcache Handel Thread-" + i; m_thread.Start(); } while (isWork()) { Thread.Sleep(1000); } LogUtil.writeline("memcached devicedayDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds)); } catch (Exception e) { LogUtil.error("batch Cache device day data error:" + e.Message); } try { DateTime curdt = DateTime.Now; //缓存采集器实时数据 CollectorRunDataService.GetInstance().batchCache(BaseMessage.collectorRunDataMap.Values); LogUtil.writeline("memcached collectorRunDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds)); } catch (Exception e) { LogUtil.error("batch Cache run data error:" + e.Message); } try { DateTime curdt = DateTime.Now; //批量保存设备实时数据到缓存 DeviceRunDataService.GetInstance().BatchCache(BaseMessage.deviceRunDataMap.Values); LogUtil.writeline("memcached deviceRunDataMap用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds)); } catch (Exception e) { LogUtil.error("batch Cache device run data error:" + e.Message); } try { FaultService.GetInstance().batchSave(BaseMessage.faultList); BaseMessage.faultList.Clear(); } catch (Exception e) { LogUtil.info("batch Cache fualt error:" + e.Message); } try { DateTime curdt = DateTime.Now; //将设备最大值统计数据放入缓存 DeviceDataCountService.GetInstance().batchCache(BaseMessage.deviceDataCounts); BaseMessage.deviceDataCounts.Clear(); LogUtil.writeline("memcached deviceDataCounts用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds)); } catch (Exception e) { LogUtil.error("save max value error:" + e.Message); } clearDayDataMap(); }
/// <summary> /// 取得采集器日数据列表 /// </summary> /// <returns></returns> public void GetCollectorDaydataList() { //如果没有数据则直接返回,增加for2.0协议,分包发送消息的情况 if (!messageHeader.hasData) { return; } //将单元头部的发电量加入历史测点数据map中,然后统一处理 if (!messageHeader.issub)//只有电站数据加入者两个电站测点 { if (messageHeader.DayEnergy != null) { historyMonitorMap[MonitorType.PLANT_MONITORITEM_ENERGY_CODE] = messageHeader.DayEnergy; } if (messageHeader.Power != null) { historyMonitorMap[MonitorType.PLANT_MONITORITEM_POWER_CODE] = messageHeader.Power; } } int collectorID = GetCollectorId(); //根据历史测点数据构建设备天数据 //这里需要改进为依据设备时间,防止设备数据的时间和采集器的时间是不一致的 CollectorDayData mdd; string mapObjectKey; //遍历测点数据 foreach (int key in historyMonitorMap.Keys) { mapObjectKey = CacheKeyUtil.buildCollectorDayDataKey(collectorID, messageHeader.year + messageHeader.month, int.Parse(messageHeader.day), key); if (!collectordayDataMap.ContainsKey(mapObjectKey)) { //先从缓存中取得 mdd = CollectorDayDataService.GetInstance().getCollectorDayData(collectorID, key, int.Parse(messageHeader.day), int.Parse(messageHeader.year), int.Parse(messageHeader.month)); if (mdd == null) { mdd = new CollectorDayData() { collectorID = collectorID, sendDay = int.Parse(messageHeader.day), monitorCode = key, yearmonth = messageHeader.year + messageHeader.month } } ; collectordayDataMap[mapObjectKey] = mdd; } else { mdd = collectordayDataMap[mapObjectKey]; } float newValue = historyMonitorMap[key] == null?0:float.Parse(historyMonitorMap[key].ToString()); string tmpStr = "#" + messageHeader.hour + messageHeader.minute + messageHeader.second + ":" + newValue; if (mdd.dataContent != null) {//避免数据串有重复数据过大 if (!mdd.dataContent.Contains(tmpStr)) { mdd.dataContent += tmpStr; } } else { mdd.dataContent = tmpStr; } mdd.sendtime = messageHeader.TimeNow; mdd.localAcceptTime = DateTime.Now; mdd.yearmonth = messageHeader.year + messageHeader.month; mdd.changed = true; //add by qhb in 20121028 for 会写到memcahced 以便持久化能取到改数据.采集器天数据集中缓存处有点问题,和设备天数据一样的问题。 //导致曲线数据有丢失现象 try { MemcachedClientSatat.getInstance().Set(mapObjectKey, mdd); } catch (Exception e) { Console.WriteLine("set collector day data to memecached error:" + e.Message); //出现错误,可能是mdd太大,所以整理下mdd,去掉重复数据,减少size,因为memached内存有2m限制 } //将功率和关照的最大发生时间记录下来.稍后优化下 if (key == MonitorType.PLANT_MONITORITEM_POWER_CODE) { //if (collectorID >= 189 && collectorID < 199) //{ // LogUtil.writeline(messageHeader.TimeNow + "-" + newValue); //} //LogUtil.warn("collectorDataCount = new DeviceDataCount(): collectorID is " + collectorID + "-" + messageHeader.year.ToString() + messageHeader + ""); collectorDataCount = new DeviceDataCount() { deviceId = collectorID, monitorCode = key, year = int.Parse(messageHeader.year), month = int.Parse(messageHeader.month), day = int.Parse(messageHeader.day), deviceTable = TableUtil.PLANT, maxValue = newValue, maxTime = messageHeader.TimeNow, localAcceptTime = DateTime.Now }; } } }