/// <summary> /// 比较多个设备的年度数据 /// </summary> /// <param name="chartName"></param> /// <param name="devices"></param> /// <param name="years"></param> /// <returns></returns> public ChartData compareYearsMultiDeviceMultiMonitor(string chartName, IList <DeviceStuct> devices, IList <string> years) { string reportData = string.Empty; //chartName = chartName+" from "+years[0]+" to "+years[years.Count-1]; IList <KeyValuePair <string, float?[]> > datas = new List <KeyValuePair <string, float?[]> >(); string[] chartTypes = new string[devices.Count]; string[] units = new string[devices.Count]; string[] ynames = new string[devices.Count]; string[] compareObjs = new string[devices.Count]; DeviceStuct deviceStuct = null; bool hasData = false; for (int i = 0; i < devices.Count; i++) { ///所有子站累加 deviceStuct = devices[i]; int monitorCode = deviceStuct.monitorType.code; string deviceId = deviceStuct.deviceId; chartTypes[i] = deviceStuct.chartType; compareObjs[i] = deviceStuct.comareObj; ynames[i] = ""; units[i] = deviceStuct.unit; Hashtable dataHash = null; string curName = ""; if (deviceStuct.deviceType == ChartDeviceType.PLANT || deviceStuct.deviceType == ChartDeviceType.UNIT) { //电站 IList <PlantUnit> plantUnits = getUnitsBydeviceIDs(deviceId, deviceStuct.deviceType); curName = deviceStuct.name; dataHash = CollectorYearDataService.GetInstance().GetYearDatasByUnits(plantUnits); } else { //设备 Device device = DeviceService.GetInstance().get(int.Parse(deviceId)); curName = deviceStuct.name; dataHash = DeviceYearDataService.GetInstance().GetTotalDatasByDevice(device); } //如果有多个设备进行编辑,没有数据的时候也显示 //if (dataHash.Count > 0) //{ KeyValuePair <string, float?[]> data = base.GenerateChartData(curName, years.ToArray(), dataHash, deviceStuct.rate); datas.Add(data); //} //如果有数据则将有数据标识为true if (dataHash.Count > 0) { hasData = true; } } //如果所有设备都没数据才清空数据,即图表中显示无数据提示 if (!hasData) { datas.Clear(); } string[] xAxis = years.ToArray <string>(); return(ReportBuilder.createMultiJsonChartXY(chartName, xAxis, datas, ynames, chartTypes, units, compareObjs, false)); }
/// <summary> /// 根据自定义图表,构造设备比较结构 /// </summary> /// <param name="crt"></param> /// <returns></returns> private List<DeviceStuct> GetDeviceStucts(CustomChart crt) { List<DeviceStuct> list = new List<DeviceStuct>(); string[] ss = crt.product.Split(';'); foreach (string ssssss in ss) { if (string.IsNullOrEmpty(ssssss)) continue; string[] ssa = ssssss.Split(','); DeviceStuct dev = new DeviceStuct(); dev.chartType = crt.subType; dev.intervalMins = 5; dev.rate = 1F; foreach (string s in ssa) { string[] ss0 = s.Split('&'); if (ss0.Length == 2) { switch (ss0[1]) { case "subType": dev.chartType = ss0[0]; break; case "cVal": dev.cVal = int.Parse(ss0[0]); break; case "Unit": dev.unit = ss0[0]; break; case "valueType": dev.monitorType = MonitorType.getMonitorTypeByCode(int.Parse(ss0[0])); break; case "0":///DeviceData.PLANT_CODE.ToString() dev.deviceType = ChartDeviceType.PLANT; dev.deviceId = ss0[0]; Plant plant = PlantService.GetInstance().GetPlantInfoById(int.Parse(dev.deviceId)); dev.comareObj = plant.name; break; default: dev.deviceType = ChartDeviceType.DEVICE; dev.deviceId = ss0[0]; Device device = DeviceService.GetInstance().get(int.Parse(dev.deviceId)); dev.comareObj = device.fullName; break; } } } if (!(dev.monitorType.code != MonitorType.PLANT_MONITORITEM_ENERGY_CODE && !crt.timeInterval.Equals("Hour"))) { list.Add(dev); } } return list; }
/// <summary> /// 比较多个设备多测点的天时数据 /// </summary> /// <param name="chartName"></param> /// <param name="devices"></param> /// <param name="startYearMMDDHH"></param> /// <param name="endYearMMDDHH"></param> /// <param name="intervalMins"></param> /// <param name="rate">值的换算率</param> /// <param name="computeType">计算类型</param> /// <returns></returns> public ChartData compareDayHHMultiDeviceMultiMonitor(string chartName, IList <DeviceStuct> devices, string startYearMMDDHH, string endYearMMDDHH, int minIntervalMins, int computeType) { string reportData = string.Empty; //chartName = chartName + " from " + startYearMMDDHH + " to " + endYearMMDDHH; IList <KeyValuePair <string, float?[]> > datas = new List <KeyValuePair <string, float?[]> >(); string[] ic = base.getXseriesFromYYYYMMDDHH(startYearMMDDHH, endYearMMDDHH, minIntervalMins).ToArray(); string[] xAxis = formatXaxis(ic, this.fromApp ? ChartTimeType.Hour : ChartTimeType.Day); IList <string> chartTypes = new List <string>(); IList <string> units = new List <string>(); IList <string> ynames = new List <string>(); IList <string> compareObjs = new List <string>(); DeviceStuct deviceStuct = null; bool hasData = false; for (int i = 0; i < devices.Count; i++) { ///所有子站累加 deviceStuct = devices[i]; int monitorCode = deviceStuct.monitorType.code; string deviceId = deviceStuct.deviceId; Hashtable dataHash = null; string startYearMM = startYearMMDDHH.Substring(0, 6); string endYearMM = endYearMMDDHH.Substring(0, 6); string curName = deviceStuct.name; string[] tmpIc = base.getXseriesFromYYYYMMDDHH(startYearMMDDHH, endYearMMDDHH, deviceStuct.intervalMins).ToArray(); if (deviceStuct.deviceType == ChartDeviceType.PLANT || deviceStuct.deviceType == ChartDeviceType.COLLECTOR) { //电站 IList <PlantUnit> plantUnits; if (deviceStuct.deviceType == ChartDeviceType.PLANT) { KeyValuePair <string, float?[]> alldata = new KeyValuePair <string, float?[]>(); string[] plantIDArr = deviceId.Split(','); foreach (string plantID in plantIDArr) { if (string.IsNullOrEmpty(plantID)) { continue; } Plant plant = PlantService.GetInstance().GetPlantInfoById(int.Parse(plantID)); ///结果需要按时间先后排序 IList <PlantUnit> ounits = monitorCode == MonitorType.PLANT_MONITORITEM_LINGT_CODE ? plant.sunUnits : plant.plantUnits; dataHash = CollectorDayDataService.GetInstance().GetUnitDaydataList(tmpIc, ounits, startYearMMDDHH, endYearMMDDHH, deviceStuct.intervalMins, monitorCode); //if (dataHash.Count > 0) //{ chartTypes.Add(deviceStuct.chartType); compareObjs.Add(deviceStuct.comareObj); units.Add(deviceStuct.unit); ynames.Add(""); //先屏蔽了,因为两天跨度的中间部分平滑有问题,但不是对原来是否有影响测试后才知道 //base.FirstHandleChartData(tmpIc, dataHash); KeyValuePair <string, float?[]> data = base.GenerateChartData(curName, ic, dataHash, deviceStuct.rate); if (alldata.Key == null) { alldata = data; } else { alldata = new KeyValuePair <string, float?[]>(alldata.Key, mergeHash(alldata.Value, data.Value)); } //} //如果有数据则将有数据标识为true if (dataHash.Count > 0) { hasData = true; } } //如果有多个设备进行编辑,没有数据的时候也显示 //if (alldata.Key != null) { datas.Add(alldata); //} } else { plantUnits = new List <PlantUnit>() { new PlantUnit() { collector = new Collector() { id = int.Parse(deviceId) } } }; dataHash = CollectorDayDataService.GetInstance().GetUnitDaydataList(tmpIc, plantUnits, startYearMMDDHH, endYearMMDDHH, deviceStuct.intervalMins, monitorCode); //如果有多个设备进行编辑,没有数据的时候也显示 //if (dataHash.Count > 0) //{ chartTypes.Add(deviceStuct.chartType); compareObjs.Add(deviceStuct.comareObj); units.Add(deviceStuct.unit); ynames.Add(""); //先屏蔽了,因为两天跨度的中间部分平滑有问题,但不是对原来是否有影响测试后才知道 //base.FirstHandleChartData(tmpIc, dataHash); KeyValuePair <string, float?[]> data = base.GenerateChartData(curName, ic, dataHash, deviceStuct.rate); datas.Add(data); //} //如果有数据则将有数据标识为true if (dataHash.Count > 0) { hasData = true; } } } else { //设备 Device device = DeviceService.GetInstance().get(int.Parse(deviceId)); dataHash = DeviceDayDataService.GetInstance().GetDaydataList(tmpIc, device, startYearMMDDHH, endYearMMDDHH, deviceStuct.intervalMins, monitorCode); //如果有多个设备进行编辑,没有数据的时候也显示 //if (dataHash.Count > 0 || devices.Count > 1) //{ chartTypes.Add(deviceStuct.chartType); compareObjs.Add(deviceStuct.comareObj); units.Add(deviceStuct.unit); ynames.Add(""); //先屏蔽了,因为两天跨度的中间部分平滑有问题,但不是对原来是否有影响测试后才知道 //base.FirstHandleChartData(tmpIc, dataHash); KeyValuePair <string, float?[]> data = base.GenerateChartData(curName, ic, dataHash, deviceStuct.rate); datas.Add(data); //} //如果有数据则将有数据标识为true if (dataHash.Count > 0) { hasData = true; } } } if (!hasData) //如果所有设备都没数据才清空数据,即图表中显示无数据提示 { datas.Clear(); } //如果有计算类型,就要追究相应计算维度,时间间隔不同的是不能有计算类型处理的 if (computeType != ComputeType.None && datas.Count > 0) { float?[] newDataArr = computeByType(ic, datas, computeType); KeyValuePair <string, float?[]> newdata = new KeyValuePair <string, float?[]>(LanguageUtil.getDesc("AVERAGE"), newDataArr); datas.Add(newdata); chartTypes.Add(chartTypes[0]); units.Add(units[0]); ynames.Add(LanguageUtil.getDesc("AVERAGE")); compareObjs.Add(""); string[] colors = new string[units.Count + 1]; colors[colors.Length - 1] = "#EE0000"; return(ReportBuilder.createMultiJsonChartXY(chartName, xAxis, datas, ynames.ToArray(), chartTypes.ToArray(), units.ToArray(), compareObjs.ToArray(), colors, fromApp)); } else { return(ReportBuilder.createMultiJsonChartXY(chartName, xAxis, datas, ynames.ToArray(), chartTypes.ToArray(), units.ToArray(), compareObjs.ToArray(), fromApp)); } }
/// <summary> /// 比较多个设备多测点的月天数据 /// </summary> /// <param name="chartName"></param> /// <param name="devices"></param> /// <param name="startYearMMDD"></param> /// <param name="endYearMMDD"></param> /// <returns></returns> public ChartData compareMMDDMultiDeviceMultiMonitor(string chartName, IList <DeviceStuct> devices, string startYearMMDD, string endYearMMDD, int computeType) { string reportData = string.Empty; //chartName = chartName + " from " + startYearMMDD + "to" + endYearMMDD; IList <KeyValuePair <string, float?[]> > datas = new List <KeyValuePair <string, float?[]> >(); string[] ic = base.getXseriesFromYYYYMMDD(startYearMMDD, endYearMMDD).ToArray(); string[] xAxis = formatXaxis(ic, ChartTimeType.MonthDay); string[] chartTypes = new string[devices.Count]; string[] units = new string[devices.Count]; string[] ynames = new string[devices.Count]; string[] compareObjs = new string[devices.Count]; DeviceStuct deviceStuct = null; bool hasData = false; for (int i = 0; i < devices.Count; i++) { ///所有子站累加 deviceStuct = devices[i]; int monitorCode = deviceStuct.monitorType.code; string deviceId = deviceStuct.deviceId; chartTypes[i] = deviceStuct.chartType; compareObjs[i] = deviceStuct.comareObj; ynames[i] = ""; units[i] = deviceStuct.unit; Hashtable dataHash = null; string startYearMM = startYearMMDD.Substring(0, 6); string endYearMM = endYearMMDD.Substring(0, 6); string curName = ""; if (deviceStuct.deviceType == ChartDeviceType.PLANT || deviceStuct.deviceType == ChartDeviceType.UNIT) { //电站 IList <PlantUnit> plantUnits = getUnitsBydeviceIDs(deviceId, deviceStuct.deviceType); curName = deviceStuct.name; dataHash = CollectorMonthDayDataService.GetInstance().GetUnitBetweenMonthData(plantUnits, startYearMM, endYearMM); } else { //设备 Device device = DeviceService.GetInstance().get(int.Parse(deviceId)); curName = deviceStuct.name; dataHash = DeviceMonthDayDataService.GetInstance().DeviceYearMMDDList(device, startYearMMDD, endYearMMDD); } //如果有多个设备进行编辑,没有数据的时候也显示 //if (dataHash.Count > 0) //{ KeyValuePair <string, float?[]> data = base.GenerateChartData(curName, ic, dataHash, deviceStuct.rate); datas.Add(data); //} //如果有数据则将有数据标识为true if (dataHash.Count > 0) { hasData = true; } } //如果所有设备都没数据才清空数据,即图表中显示无数据提示 if (!hasData) { datas.Clear(); } //如果有计算类型,就要追究相应计算维度 if (computeType != ComputeType.None && datas.Count > 0) { float?[] newDataArr = computeByType(xAxis.ToArray(), datas, computeType); KeyValuePair <string, float?[]> newdata = new KeyValuePair <string, float?[]>(LanguageUtil.getDesc("AVERAGE"), newDataArr); datas.Add(newdata); string[] newChartTypes = new string[chartTypes.Length + 1]; string[] newUnits = new string[units.Length + 1]; string[] newYnames = new string[ynames.Length + 1]; string[] newCompareObjs = new string[compareObjs.Length + 1]; string[] colors = new string[units.Length + 1]; ynames.CopyTo(newYnames, 0); newYnames[newYnames.Length - 1] = LanguageUtil.getDesc("AVERAGE"); units.CopyTo(newUnits, 0); newUnits[newUnits.Length - 1] = units[0]; chartTypes.CopyTo(newChartTypes, 0); newChartTypes[newChartTypes.Length - 1] = chartTypes[0]; newCompareObjs.CopyTo(newCompareObjs, 0); newCompareObjs[newCompareObjs.Length - 1] = ""; colors[colors.Length - 1] = "#EE0000"; return(ReportBuilder.createMultiJsonChartXY(chartName, xAxis, datas, newYnames, newChartTypes, newUnits, newCompareObjs, colors, fromApp)); } else { return(ReportBuilder.createMultiJsonChartXY(chartName, xAxis, datas, ynames, chartTypes, units, compareObjs, fromApp)); } //return ReportBuilder.createMultiJsonChartXY(chartName, xAxis.ToArray(), datas, ynames, chartTypes, units, compareObjs); }