Exemplo n.º 1
0
 private IList <PlantUnit> getUnitsBydeviceIDs(string deviceIds, int chartDeviceType)
 {
     if (chartDeviceType == ChartDeviceType.PLANT)
     {
         string[]      deviceIdArr = deviceIds.Split(',');
         IList <Plant> plants      = new List <Plant>();
         foreach (string deviceId in deviceIdArr)
         {
             if (string.IsNullOrEmpty(deviceId))
             {
                 continue;
             }
             Plant plant = PlantService.GetInstance().GetPlantInfoById(int.Parse(deviceId));
             plants.Add(plant);
         }
         return(getUnitsByPlantList(plants));
     }
     else if (chartDeviceType == ChartDeviceType.UNIT)
     {
         IList <PlantUnit> units       = new List <PlantUnit>();
         string[]          deviceIdArr = deviceIds.Split(',');
         foreach (string deviceId in deviceIdArr)
         {
             if (string.IsNullOrEmpty(deviceId))
             {
                 continue;
             }
             PlantUnit unit = PlantUnitService.GetInstance().GetPlantUnitById(int.Parse(deviceId));
             units.Add(unit);
         }
         return(units);
     }
     return(new List <PlantUnit>());
 }
Exemplo n.º 2
0
        private Hashtable construtPlantReportObj(int plantid, int type, string dataitem)
        {
            Hashtable    table     = new Hashtable();
            string       plantName = PlantService.GetInstance().GetPlantInfoById(plantid).name + " ";
            DefineReport report1   = new DefineReport()
            {
                ReportType = type,
                ReportName = plantName + "-" + DataReportType.getNameByCode(type),
                SaveTime   = DateTime.Now,
                dataitem   = dataitem,
                PlantId    = plantid
            };
            ReportConfig config1 = new ReportConfig()
            {
                sendFormat = "html",
                email      = "",
                sendMode   = "2",
                reportId   = 0,
                plantId    = plantid
            };

            table.Add(0, report1);
            table.Add(1, config1);
            return(table);
        }
Exemplo n.º 3
0
        /// <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));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 合并某个电站的所有采集器的值记录
        /// </summary>
        /// <param name="plantId"></param>
        /// <param name="plantRecordList"></param>
        private void mergeRecord2Cache(string countCacheKey, DeviceDataCount collectorDataCount)
        {
            IDictionary <string, float> maxDictionary = new Dictionary <string, float>();
            //平滑用,统一标准坐标
            string daystr = collectorDataCount.year.ToString("00") + collectorDataCount.month.ToString("00") + collectorDataCount.day.ToString("00");

            string[] tmpIc = base.getXseriesFromYYYYMMDDHH(daystr + "00", daystr + "23", 5).ToArray();
            //给电站的采集器集合增加为完整的所有的采集器集合,以便每次都能统计所有采集器累计的最大发生值

            Plant             plant           = PlantService.GetInstance().GetPlantInfoById(collectorDataCount.deviceId);
            string            tmpcachkey      = "";
            IList <Hashtable> plantRecordList = new List <Hashtable>();

            foreach (PlantUnit unit in plant.plantUnits)
            {
                tmpcachkey = CacheKeyUtil.buildCollectorDataCountKey(collectorDataCount.year, collectorDataCount.month, collectorDataCount.day, unit.collectorID, collectorDataCount.monitorCode);
                //取得采集器日统计记录
                object obj = MemcachedClientSatat.getInstance().Get(tmpcachkey);
                if (obj == null)
                {
                    continue;
                }
                plantRecordList.Add((Hashtable)obj);
            }

            foreach (Hashtable tmpMap in plantRecordList)
            {
                //先平滑
                base.FirstHandleChartData(tmpIc, tmpMap);
                foreach (string key in tmpMap.Keys)
                {
                    if (maxDictionary.ContainsKey(key))
                    {
                        maxDictionary[key] = maxDictionary[key] + (float)tmpMap[key];
                    }
                    else
                    {
                        maxDictionary[key] = (float)tmpMap[key];
                    }
                }
            }

            //取得所有时间点中最大值
            float  maxValue   = 0;
            string maxTimeKey = "000000";
            float  tmpValue;

            foreach (string key in maxDictionary.Keys)
            {
                tmpValue = maxDictionary[key];
                if (tmpValue > maxValue)
                {
                    maxValue   = tmpValue;
                    maxTimeKey = key;
                }
            }
            //
            collectorDataCount.maxTime  = new DateTime(collectorDataCount.maxTime.Year, collectorDataCount.maxTime.Month, collectorDataCount.maxTime.Day, int.Parse(maxTimeKey.Substring(2, 2)), int.Parse(maxTimeKey.Substring(4, 2)), 0);
            collectorDataCount.maxValue = maxValue;
            LogUtil.writeline("plant max count" + collectorDataCount.deviceId + "-" + collectorDataCount.maxTime + "-" + maxValue);
            Cache(collectorDataCount);
        }