Exemplo n.º 1
0
        /// <summary>
        /// 获取当前采集器下指定时间发电量
        /// </summary>
        /// <param name="cid">采集器编号</param>
        /// <param name="startyyyyMMdd">开始时间</param>
        /// <param name="endyyyyMMdd">结束时间</param>
        /// <returns></returns>
        public double GetEnergy(int cid, string startyyyyMMdd, string endyyyyMMdd)
        {
            //20111130    20111130
            double   returnValue = 0;
            DateTime startTime   = DateTime.Parse(startyyyyMMdd);
            DateTime endTime     = DateTime.Parse(endyyyyMMdd);
            IList <CollectorYearMonthData> cymds = new List <CollectorYearMonthData>();
            int yyyy = startTime.Year;

            while (yyyy <= endTime.Year)//计算开始到结束时间的所在年发电量
            {
                cymds.Add(CollectorYearMonthDataService.GetInstance().GetCollectorYearMonthData(cid, yyyy));
                yyyy++;
            }
            //计算开始到结束时间内的所有发电量
            foreach (CollectorYearMonthData cymd in cymds)
            {
                if (cymd.year.Equals(startTime.Year) && startTime.AddMonths(1) < endTime)
                {
                    returnValue += cymd.count(startTime.Month + 1, 12);
                }
                else
                if (cymd.year.Equals(endTime.Year) && endTime.AddMonths(-1) > startTime)
                {
                    returnValue += cymd.count(1, endTime.Month - 1);
                }
                else
                if (startTime.Year.Equals(endTime.Year) == false)
                {
                    returnValue += cymd.count();
                }
            }
            CollectorMonthDayData cmdd = null;

            //计算边缘月的发电量
            if (!(startTime.Year.Equals(endTime.Year) && startTime.Month.Equals(endTime.Month)))
            {
                cmdd         = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(startTime.Year, cid, startTime.Month);
                returnValue += cmdd.count(startTime.Day, 31);

                cmdd         = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(startTime.Year, cid, endTime.Month);
                returnValue += cmdd.count(1, endTime.Day);
            }
            else
            {
                cmdd         = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(startTime.Year, cid, endTime.Month);
                returnValue += cmdd.count(startTime.Day, endTime.Day);
            }
            return(returnValue);
        }
Exemplo n.º 2
0
        public ActionResult Units_Output(int id)
        {
            Plant             plant      = FindPlant(id);
            IList <PlantUnit> plantUnits = PlantUnitService.GetInstance().GetAllPlantUnitsByPlantId(id);
            CsvStreamWriter   writer     = new CsvStreamWriter();
            IList <string>    listData   = new List <string>();

            listData.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},", Resources.SunResource.PLANT_UNIT_LIST_STATUS, Resources.SunResource.PLANT_UNIT_DATA_SOURCE_CODE
                                       , Resources.SunResource.PLANT_UNIT_LIST_UNIT_NAME,
                                       Resources.SunResource.PLANT_UNIT_LIST_POWER + "(kW)",
                                       Resources.SunResource.PLANT_UNIT_LIST_YEAR_ENERGY + "(kWh)",
                                       Resources.SunResource.PLANT_UNIT_LIST_ENERGY + "(kWh)",
                                       Resources.SunResource.PLANT_UNIT_LIST_MONTH_ENERGY + "(kWh)",
                                       Resources.SunResource.PLANT_UNIT_LIST_MONTH_ENERGY_KWP + "(kWh/kWp)",
                                       Resources.SunResource.PLANT_UNIT_LIST_YEAR_ENERGY_KWP + "(kWh/kWp)"
                                       ));

            CollectorMonthDayData cmData = null;
            CollectorYearData     cyData = null;

            foreach (PlantUnit unit in plantUnits)
            {
                float currentMonthEnergy = 0;
                float currentYearEnergy  = 0;
                cmData             = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(DateTime.Now.Year, unit.collector.id, DateTime.Now.Month);
                currentMonthEnergy = cmData == null ? 0 : cmData.count();
                cyData             = CollectorYearDataService.GetInstance().GetCollectorYearData(unit.collector.id, DateTime.Now.Year);
                currentYearEnergy  = cyData == null ? 0 : cyData.dataValue;
                listData.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},", unit.isWork(plant.timezone) ? Resources.SunResource.MONITORITEM_WORKING : Resources.SunResource.MONITORITEM_STOPPED, string.Format("\t{0}", unit.collector.code)
                                           , string.Format("\t{0}", unit.displayname),
                                           unit.TodayPower(plant.timezone).ToString(),
                                           currentYearEnergy.ToString(),
                                           unit.displayTotalEnergy.ToString(),
                                           currentMonthEnergy.ToString(),
                                           Math.Round(currentMonthEnergy / unit.chartPower, 2).Equals(double.NaN) ? "0" : Math.Round(currentMonthEnergy / unit.chartPower, 2).ToString(),
                                           Math.Round(currentYearEnergy / unit.chartPower, 2).Equals(double.NaN) ? "0" : Math.Round(currentYearEnergy / unit.chartPower, 2).ToString()
                                           ));
            }

            writer.AddStrDataList(listData);


            string fullFile = Server.MapPath("/") + "tempexportfile\\" + Resources.SunResource.PLANT_UNIT_LIST_FILENAME + ".csv";

            writer.Save(fullFile);
            //转化为csv格式的字符串
            ActionResult tmp = File(fullFile, "text/csv; charset=UTF-8", urlcode(Resources.SunResource.PLANT_UNIT_LIST_FILENAME) + ".csv");

            return(tmp);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 缓存采集器发电量统计
        /// 要进行修正缓存丢失
        ///
        /// </summary>
        /// <param name="tcpmessage"></param>
        private static void CacheCollectorEnergyData(IDictionary <string, double?> collectorEnergyMap)
        {
            int collectorID;

            string[]  keyArr;
            int       year;
            int       month;
            int       day;
            float?    data;
            Collector collector = null;

            //string[] keys = collectorEnergyMap.Keys.ToArray();
            foreach (string ekey in collectorEnergyMap.Keys)
            {
                try
                {
                    keyArr = ekey.Split(':');

                    collectorID = int.Parse(keyArr[0]);
                    //原来是通过消息头部取得,现在改为
                    data = collectorEnergyMap[ekey] == null ? 0 : float.Parse(collectorEnergyMap[ekey].ToString());
                    if (data == 0)//如果头部未传或者为0则再从设备累计下看看
                    {
                        //现在改为通过采集器的设备的今日电量来累加
                        collector = CollectorInfoService.GetInstance().Get(collectorID);
                        if (keyArr.Length < 4 || (string.IsNullOrEmpty(keyArr[1]) || string.IsNullOrEmpty(keyArr[2]) || string.IsNullOrEmpty(keyArr[3])))
                        {
                            continue;
                        }
                        data = collector.deviceTodayEnergy(keyArr[1] + keyArr[2] + keyArr[3]);
                    }
                    year  = int.Parse(keyArr[1]);
                    month = int.Parse(keyArr[2]);
                    day   = int.Parse(keyArr[3]);
                    string d_column = "d_" + day;

                    //取得月天数据对象
                    CollectorMonthDayData collectorMonthDayData = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(year, collectorID, month);
                    collectorMonthDayData.curDay = day;
                    //给相应属性赋值
                    if (collectorMonthDayData != null)
                    {
                        object ovalue = ReflectionUtil.getProperty(collectorMonthDayData, d_column);
                        if (ovalue == null || float.Parse(ovalue.ToString()) < data)
                        {
                            ReflectionUtil.setProperty(collectorMonthDayData, d_column, data);
                        }
                    }
                    CollectorMonthDayDataService.GetInstance().Cache(collectorMonthDayData);

                    //更新年月发电量数据
                    //统计年月
                    string m_column = "m_" + month;
                    float? m_value  = collectorMonthDayData.count();
                    CollectorYearMonthData ymdData = CollectorYearMonthDataService.GetInstance().GetCollectorYearMonthData(collectorID, year);;
                    ymdData.curMonth = month;
                    //给年月数据对象相应属性赋值
                    if (ymdData != null)
                    {
                        object ovalue = ReflectionUtil.getProperty(ymdData, m_column);
                        if (ovalue == null || float.Parse(ovalue.ToString()) < m_value)
                        {
                            ReflectionUtil.setProperty(ymdData, m_column, m_value);
                        }
                    }
                    CollectorYearMonthDataService.GetInstance().Cache(ymdData);

                    //统计总体发电量
                    float?            y_value = ymdData.count();
                    CollectorYearData yd      = CollectorYearDataService.GetInstance().GetCollectorYearData(collectorID, year);
                    if (yd == null)
                    {
                        yd = new CollectorYearData()
                        {
                            dataValue = 0, collectorID = collectorID, year = year
                        }
                    }
                    ;
                    yd.localAcceptTime = DateTime.Now;
                    //给年月数据对象相应属性赋值
                    if (yd != null)
                    {
                        object ovalue = yd.dataValue;
                        if (ovalue == null || float.Parse(ovalue.ToString()) < y_value)
                        {
                            yd.dataValue = y_value == null ? 0 : float.Parse(y_value.ToString());
                        }
                    }
                    CollectorYearDataService.GetInstance().Cache(yd);
                }
                catch (Exception onee) {//捕获单个异常,保证一个错误不影响其他采集器数据处理
                    LogUtil.error("Cache collectorEnergyMap of ekey is " + ekey + " error:" + onee.Message);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 缓存采集器发电量统计
        /// 要进行修正缓存丢失
        ///
        /// </summary>
        /// <param name="tcpmessage"></param>
        private static void CacheCollectorEnergyData(IDictionary <string, double> collectorEnergyMap)
        {
            int collectorID;

            string[]  keyArr;
            int       year;
            int       month;
            int       day;
            float?    data;
            Collector collector = null;

            //string[] keys = collectorEnergyMap.Keys.ToArray();
            foreach (string ekey in collectorEnergyMap.Keys)
            {
                //原来是通过消息头部取得,现在改为
                //data = float.Parse(collectorEnergyMap[ekey].ToString());
                //现在改为通过采集器的设备的今日电量来累加
                keyArr      = ekey.Split(':');
                collectorID = int.Parse(keyArr[0]);
                collector   = CollectorInfoService.GetInstance().Get(collectorID);
                data        = collector.TodayEnergy(keyArr[1] + keyArr[2] + keyArr[3]);

                //改为通过所含设备的
                year  = int.Parse(keyArr[1]);
                month = int.Parse(keyArr[2]);
                day   = int.Parse(keyArr[3]);
                string d_column = "d_" + day;

                //取得月天数据对象
                CollectorMonthDayData collectorMonthDayData = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(year, collectorID, month);
                collectorMonthDayData.curDay = day;
                //给相应属性赋值
                if (collectorMonthDayData != null)
                {
                    object ovalue = ReflectionUtil.getProperty(collectorMonthDayData, d_column);
                    //if (ovalue == null || float.Parse(ovalue.ToString()) < data)
                    //{
                    ReflectionUtil.setProperty(collectorMonthDayData, d_column, data);
                    //}
                }
                CollectorMonthDayDataService.GetInstance().Cache(collectorMonthDayData);

                //更新年月发电量数据
                //统计年月
                string m_column = "m_" + month;
                float? m_value  = collectorMonthDayData.count();
                CollectorYearMonthData ymdData = CollectorYearMonthDataService.GetInstance().GetCollectorYearMonthData(collectorID, year);;
                ymdData.curMonth = month;
                //给年月数据对象相应属性赋值
                if (ymdData != null)
                {
                    object ovalue = ReflectionUtil.getProperty(ymdData, m_column);
                    if (ovalue == null || float.Parse(ovalue.ToString()) < m_value)
                    {
                        ReflectionUtil.setProperty(ymdData, m_column, m_value);
                    }
                }
                CollectorYearMonthDataService.GetInstance().Cache(ymdData);

                //统计总体发电量
                float?            y_value = ymdData.count();
                CollectorYearData yd      = CollectorYearDataService.GetInstance().GetCollectorYearData(collectorID, year);
                if (yd == null)
                {
                    yd = new CollectorYearData()
                    {
                        dataValue = 0, collectorID = collectorID, year = year
                    }
                }
                ;
                yd.localAcceptTime = DateTime.Now;
                //给年月数据对象相应属性赋值
                if (yd != null)
                {
                    object ovalue = yd.dataValue;
                    if (ovalue == null || float.Parse(ovalue.ToString()) < y_value)
                    {
                        yd.dataValue = y_value == null ? 0 : float.Parse(y_value.ToString());
                    }
                }
                CollectorYearDataService.GetInstance().Cache(yd);
            }
        }
    }