コード例 #1
0
        /// <summary>
        /// 统计某年某个测点各时段内值和
        /// </summary>
        /// <param name="plants"></param>
        /// <param name="chartname"></param>
        /// <param name="YYYYMM"></param>
        /// <param name="chartType"></param>
        /// <param name="unit"></param>
        /// <param name="monitorCode"></param>
        /// <param name="intervalMins"></param>
        /// <param name="weidu"></param>
        /// <returns></returns>
        public ChartData PlantYearSectionCountChart(IList<Plant> plants, string chartname, int YYYY, string chartType, string unit, int monitorCode, int intervalMins, int weidu)
        {
            //ChartData resChartData = null;
            //for (int i = 1; i <= months; i++)
            //{
            //    ChartData chartData = PlantMonthSectionCountChart(plants, chartname, YYYY + i.ToString("00"), chartType, unit, monitorCode, intervalMins, weidu);
            //    if (resChartData == null)
            //    {
            //        resChartData = chartData;
            //    }
            //    else
            //    {
            //        mergeHash(resChartData.series[0].data, chartData.series[0].data);
            //        mergeHash(resChartData.series[1].data, chartData.series[1].data);
            //    }
            //}
            //return resChartData;
            ChartData resChartData = null;
            //电费维度轴
            YData feeyData = new YData();
            YData[] newSeries = new YData[2];
            string[] newCategories = new string[4 + 1] { "峰", "平", "谷", "尖", "合计" };
            ///要进行多个电站累计,因为电站配置的
            float?[] newValues = new float?[5] { 0, 0, 0, 0, 0 };
            float?[] newFeeValues = new float?[5]{0,0,0,0,0};
            foreach (Plant plant in plants)
            {
                if (plant.allFactUnits == null || plant.allFactUnits.Count < 1) continue;
                Hashtable dataHash = CollectorYearDataService.GetInstance().GetYearDatasByUnits(plant.allFactUnits);
                if (dataHash == null || dataHash.Count < 1) continue;

                //取出本月数据
                object v = dataHash[YYYY.ToString()];
                float energy = v == null ? 0 : (float)v;

                //按照既定比率分拆
                ElecPrice[] sections = plant.ElecPriceList.ToArray();

                float rate = 0;
                ElecPrice x = null;
                //float max = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (sections == null || i >= sections.Length)
                    {
                        if (i == 0)
                        {//峰
                            rate = 0.4f;
                            x = new ElecPrice() { fromHm = "08:00", toHm = "12:00", price = "0.6" };
                        }
                        else if (i == 1)
                        {//平
                            rate = 0.45f;
                            x = new ElecPrice() { fromHm = "12:00", toHm = "18:00", price = "0.5" };
                        }
                        else if (i == 2)
                        {//谷
                            rate = 0.1f;
                            x = new ElecPrice() { fromHm = "18:00", toHm = "23:00", price = "0.2" };
                        }
                        else
                        {//尖
                            rate = 0.05f;
                            x = new ElecPrice() { fromHm = "01:00", toHm = "08:00", price = "0.4" };
                        }
                    }
                    else
                    {
                        x = sections[i];
                        if (string.IsNullOrEmpty(x.fromHm))
                        {
                            if (i == 0)
                            {//峰
                                rate = 0.4f;
                                x = new ElecPrice() { fromHm = "08:00", toHm = "12:00", price = "0.6" };
                            }
                            else if (i == 1)
                            {//平
                                rate = 0.45f;
                                x = new ElecPrice() { fromHm = "12:00", toHm = "18:00", price = "0.5" };
                            }
                            else if (i == 2)
                            {//谷
                                rate = 0.1f;
                                x = new ElecPrice() { fromHm = "18:00", toHm = "23:00", price = "0.2" };
                            }
                            else
                            {//尖
                                rate = 0.05f;
                                x = new ElecPrice() { fromHm = "01:00", toHm = "08:00", price = "0.4" };
                            }
                        }
                    }
                    newValues[i] = (newValues[i] == 0 ? 0 : newValues[i]) + energy * rate;
                    if (newValues[i] < 0) newValues[i] = 0;
                }

                //合计总发电量
                float? value = 0;
                for (int k = 0; k < 4; k++)
                {
                    value += newValues[k];
                }

                newValues[4] = value;

                //总=(峰电费+平电费+谷电费+尖电费)+(峰发电量 + 平发电量 + 谷发电量 + 尖发电量)*基础电价
                float? total = 0;
                for (int k = 0; k < 4; k++)
                {
                    newFeeValues[k] = newValues[k] * StringUtil.stringtoFloat(x.price);
                    total += newFeeValues[k];
                }
                //总电费
                newFeeValues[4] = total + value * plant.basePrice;//1是基础电价

                if (resChartData == null)
                {
                    YData yData = null;
                    resChartData = new ChartData();
                    resChartData.name = "年度峰平谷尖发电量和收入";
                    resChartData.isHasData = true;
                    yData = new YData();
                    yData.data = new float?[] { 0, 0, 0, 0, 0 };
                    yData.name = "发电量[kWh]";
                    yData.yAxis = "0";
                    yData.type = chartType;
                    yData.color = "#EF5808";

                    feeyData = new YData();
                    //将新的结果重新放到结果对象中
                    resChartData.categories = newCategories;
                    yData.data = newValues;
                    feeyData.data = newFeeValues;
                    feeyData.name = "收入[元]";
                    feeyData.yAxis = "1";
                    feeyData.type = chartType;
                    feeyData.color = "#4682B4";
                    //feeyData.max = max;
                    newSeries[0] = yData;
                    newSeries[1] = feeyData;
                    resChartData.series = newSeries;
                    resChartData.names = new String[] { "发电量", "收入" };
                    resChartData.units = new String[] { "kWh", "元" };
                    resChartData.colors = new String[] { "#EF5808", "#4682B4" };
                    resChartData.serieNo = DateTime.Now.ToString("ddhhmmss") + new Random().Next(1000);
                    TempDataUtil.putChartData(resChartData.serieNo, resChartData);
                }
                else
                {
                    mergeHash(resChartData.series[0].data, newValues);
                    mergeHash(resChartData.series[1].data, newFeeValues);
                }
            }
            if (resChartData == null) return new ChartData() { isHasData = false };
            //计算最大值
            float max = 0;
            for (int k = 0; k < 5; k++)
            {
                if (resChartData.series[0].data[k] > max) max = resChartData.series[0].data[k].Value;
            }
            resChartData.series[0].max = max * 1.2f;

            max = 0;
            for (int k = 0; k < 5; k++)
            {
                if (resChartData.series[1].data[k] > max) max = resChartData.series[1].data[k].Value;
            }
            resChartData.series[1].max = max * 1.2f;
            return resChartData;
        }
コード例 #2
0
 public int Insert(ElecPrice eprice)
 {
     return _elecPriceDao.Insert(eprice);
 }
コード例 #3
0
        /// <summary>
        /// 统计某天某个测点各时段内值和
        /// </summary>
        /// <param name="plants"></param>
        /// <param name="chartname"></param>
        /// <param name="YYYYMMDD"></param>
        /// <param name="chartType"></param>
        /// <param name="unit"></param>
        /// <param name="monitorCode"></param>
        /// <param name="intervalMins"></param>
        /// <param name="sections">时间段集合,需要按照</param>
        /// <returns></returns>
        public ChartData PlantDaySectionCountChart(IList<Plant> plants, string chartname, string YYYYMMDD, string chartType, string unit, int monitorCode, int intervalMins, int weidu)
        {
            ChartData resChartData = null;
            //电费维度轴
            YData feeyData = new YData();
            YData[] newSeries = new YData[2];
            string[] newCategories = new string[4 + 1]{"峰","平","谷","尖","合计"};
            ///要进行多个电站累计,因为电站配置的
            float?[] newValues = new float?[5] { 0, 0, 0, 0, 0 };
            float?[] newFeeValues = new float?[5] { 0, 0, 0, 0, 0 };
            foreach (Plant plant in plants)
            {
                ChartData chartData = PlantDayChart(plant, chartname, YYYYMMDD + "00", YYYYMMDD + "23", chartType, unit, monitorCode, intervalMins);
                //按照时段进行分拆
                int day = int.Parse(YYYYMMDD.Substring(4, 2));
                ElecPrice[] sections = plant.ElecPriceList.ToArray();

                string key = null;
                ElecPrice x = null;
                for (int i = 0; i < 4; i++)
                {
                    if (sections == null || i >= sections.Length)
                    {
                        if (i == 0)//峰
                            x = new ElecPrice() { fromHm = "08:00", toHm = "12:00", price = "0.6" };
                        else if (i == 1)//平
                            x = new ElecPrice() { fromHm = "12:00", toHm = "18:00", price = "0.5" };
                        else if (i == 2)//谷
                            x = new ElecPrice() { fromHm = "18:00", toHm = "23:00", price = "0.2" };
                        else//尖
                            x = new ElecPrice() { fromHm = "01:00", toHm = "08:00", price = "0.4" };
                    }
                    else
                    {
                        x = sections[i];
                        if (string.IsNullOrEmpty(x.fromHm))
                        {
                            if (i == 0)//峰
                                x = new ElecPrice() { fromHm = "08:00", toHm = "12:00", price = "0.6" };
                            else if (i == 1)//平
                                x = new ElecPrice() { fromHm = "12:00", toHm = "18:00", price = "0.5" };
                            else if (i == 2)//谷
                                x = new ElecPrice() { fromHm = "18:00", toHm = "23:00", price = "0.2" };
                            else//尖
                                x = new ElecPrice() { fromHm = "01:00", toHm = "08:00", price = "0.4" };
                        }
                    }

                    key = getKeyPointWithMid(intervalMins, x.fromHm.Replace(":",""),":");

                    //从数据中取出对应坐标的值
                    int index = getIndexinArr(chartData.categories, key);
                    //通过下标从数据数据中找到数据
                    float? startValue = chartData.isHasData?getValueinArr(chartData.series[0].data, index, false):0;
                    key = getKeyPointWithMid(intervalMins, x.toHm.Replace(":", ""), ":");
                    //从数据中取出对应坐标的值
                    index = getIndexinArr(chartData.categories, key);
                    float? endValue = chartData.isHasData?getValueinArr(chartData.series[0].data, index, true):0;
                    newValues[i] = (newValues[i] == 0 ? 0 : newValues[i]) + (endValue == null ? 0 : endValue) - (startValue == null ? 0 : startValue);
                    if (newValues[i] < 0) newValues[i] = 0;
                }

                //合计总发电量
                float? value = 0;
                for (int k = 0; k < 4; k++)
                {
                    value += newValues[k];
                }

                newValues[4] = value;

                //总=(峰电费+平电费+谷电费+尖电费)+(峰发电量 + 平发电量 + 谷发电量 + 尖发电量)*基础电价
                float? total = 0;
                for (int k = 0; k < 4; k++)
                {
                    newFeeValues[k] = newValues[k] * StringUtil.stringtoFloat(x.price);
                    total += newFeeValues[k];
                }
                //总电费
                newFeeValues[4] = total + value * plant.basePrice;//1是基础电价

                if(resChartData==null){
                    YData yData = null;
                    resChartData = chartData;
                    resChartData.name = "日峰平谷尖发电量和收入";
                    if (!chartData.isHasData)
                    {
                        yData = new YData();
                        yData.data = new float?[] {0,0,0,0,0};
                        yData.name = "发电量[kWh]";
                        yData.yAxis = "0";
                        yData.type = chartType;
                    }
                    else {
                        yData = chartData.series[0];
                    }
                    feeyData = new YData();
                    //将新的结果重新放到结果对象中
                    resChartData.categories = newCategories;
                    yData.data = newValues;
                    feeyData.data = newFeeValues;
                    feeyData.name = "收入[元]";
                    feeyData.yAxis = "1";
                    feeyData.type = chartType;
                    newSeries[0] = yData;
                    newSeries[1] = feeyData;
                    resChartData.series = newSeries;
                    resChartData.names = new String[] { "发电量", "收入" };
                    resChartData.units = new String[] { "kWh","元"};
                    resChartData.colors = new String[] { "#EF5808", "#4682B4" };
                    resChartData.serieNo = DateTime.Now.ToString("ddhhmmss") + new Random().Next(1000);
                    TempDataUtil.putChartData(resChartData.serieNo, resChartData);
                }else{

                    mergeHash(resChartData.series[0].data, newValues);
                    mergeHash(resChartData.series[1].data, newFeeValues);
                }
                if (chartData.isHasData && !resChartData.isHasData)
                {
                    resChartData.isHasData = true;
                }
            }
            if (resChartData == null) return new ChartData() { isHasData=false};
            //计算最大值
            float max = 0;
            for (int k = 0; k < 5; k++)
            {
                if (resChartData.series[0].data[k] > max) max = resChartData.series[0].data[k].Value;
            }
            resChartData.series[0].max = max * 1.2f;

            max = 0;
            for (int k = 0; k < 5; k++)
            {
                if (resChartData.series[1].data[k] > max) max = resChartData.series[1].data[k].Value;
            }
            resChartData.series[1].max = max * 1.2f;
            return resChartData;
        }