예제 #1
0
        public override AggRawData GetAggRawData(DateTime nowTime)
        {
            if (base.DbHelper == null)
            {
                return(null);
            }

            //if (!rwLocker.TryEnterReadLock(TimeOut))
            //    return null;
            //BaseAggConfig configTmp = ObjectHelper.DeepCopy(this.Config);
            //rwLocker.ExitReadLock();

            DateTime lastWeek = TimeStrategy.GetAggDate(config.Type, config.TimeRange, nowTime);;

            DateTime firstDay  = DateTimeHelper.GetWeekFirstDayMon(lastWeek);
            DateTime lastDay   = DateTimeHelper.GetWeekLastDaySun(lastWeek);
            DateTime beginTime = firstDay.Date;
            DateTime endTime   = lastDay.Date.AddHours(23).AddMinutes(59).AddSeconds(59);

            AggRawData data      = new AggRawData(config.Key, config.ConfigId, this.GetTimeFlg(lastWeek));
            List <int> SensorIds = config.GetSensorIds();

            foreach (int sensorId in SensorIds)
            {
                RawData tempRawData = DbHelper.Accessor.GetWeekAggRawData(sensorId, config.FactorId, config.TimeRange, beginTime, endTime);
                if (tempRawData != null && tempRawData.Values.Count > 0)
                {
                    data.Datas.Add(tempRawData);
                }
            }

            data.LastAggDatas = base.GetLastAggData();
            return(data);
        }
예제 #2
0
        public void WeekDataPoolTester()
        {
            BaseAggConfig config = CreateCommonConfig(AggType.Week);

            config.TimeRange = new AggTimeRange {
                DataBeginHour = 1, DataEndHour = 2, DateBegin = 1, DateEnd = 1
            };

            DataPoolFactory.Init();
            IDataPool dataPool = DataPoolFactory.GetDataPool(config);

            Assert.IsNotNull(dataPool);

            DateTime   time  = new DateTime(2015, 2, 15);
            AggRawData data  = dataPool.GetAggRawData(time);
            int        count = 0;

            foreach (var tmp in data.Datas)
            {
                count += tmp.Values.Count;
            }
            Console.WriteLine(string.Format("共读取{0}条数据", count));
            Assert.IsTrue(data.TimeTag == "2015W7");
            Assert.IsTrue(data.FactorId == config.FactorId);
            Assert.IsTrue(data.Datas.Count > 0);
            //Assert.IsTrue(data.LastAggDatas != null);
        }
예제 #3
0
        public void MonthDataPoolTester()
        {
            BaseAggConfig config = CreateCommonConfig(AggType.Month);

            config.TimeRange = new AggTimeRange {
                DataBeginHour = 1, DataEndHour = 3, DateBegin = 1, DateEnd = 1
            };

            DataPoolFactory.Init();
            IDataPool dataPool = DataPoolFactory.GetDataPool(config);

            Assert.IsNotNull(dataPool);

            DateTime  time = new DateTime(2015, 2, 15);
            Stopwatch sw   = new Stopwatch();

            sw.Start();
            AggRawData data = dataPool.GetAggRawData(time);

            sw.Stop();
            Console.WriteLine(string.Format("MonthDataPoolTester 耗时:{0}ms", sw.ElapsedMilliseconds));
            int count = 0;

            foreach (var tmp in data.Datas)
            {
                count += tmp.Values.Count;
            }
            Console.WriteLine(string.Format("共读取{0}条数据", count));
            Assert.IsTrue(data.TimeTag == "201502");
            Assert.IsTrue(data.FactorId == config.FactorId);
            Assert.IsTrue(data.Datas.Count > 0);
            //Assert.IsTrue(data.LastAggDatas != null);
        }
예제 #4
0
        public virtual AggResult AggProcess(AggRawData datas)
        {
            if (datas == null || datas.Datas.Count == 0 || datas.Datas[0].Values.Count == 0)
            {
                return(null);
            }

            AggResult result = new AggResult(datas.StructId, datas.FactorId, datas.TimeTag, datas.Type, datas.ConfigId);

            result.AggDatas = new List <AggData>();
            int ColNum = datas.Datas[0].Values[0].Count; // 监测数据项个数
            int id     = 0;

            List <double> temp = new List <double>();

            foreach (var aggRawData in datas.Datas)
            {
                if (aggRawData.Values == null)
                {
                    continue;
                }

                id = aggRawData.SensorId;
                AggData aggData = new AggData();
                aggData.SensorId = aggRawData.SensorId;
                for (int i = 0; i < ColNum; i++)
                {
                    if (temp.Count > 0)
                    {
                        temp.Clear();
                    }
                    foreach (var value in aggRawData.Values)
                    {
                        if (i < aggRawData.Values[i].Count)
                        {
                            temp.Add(value[i]);
                        }
                    }
                    if (temp.Count > 0)
                    {
                        aggData.Values.Add(this.GetAggValue(temp));
                    }
                }
                if (aggData.Values.Count > 0)
                {
                    result.AggDatas.Add(aggData);
                }
            }

            result.LastAggDatas = datas.LastAggDatas;
            return(result);
        }
예제 #5
0
        private AggRawData CreateAggRawData()
        {
            AggRawData aggdata = new AggRawData(new AggTaskKey(1, 1, AggType.Day), 1, "201501");

            aggdata.Datas = new List <RawData>();
            RawData data = new RawData();

            data.SensorId = 100;
            data.Values   = new List <List <double> >();

            for (int i = 0; i < 3; i++)
            {
                List <double> item = new List <double>();
                for (int j = 0; j < 3; j++)
                {
                    item.Add((i + 1) * 100);
                }
                data.Values.Add(item);
            }
            aggdata.Datas.Add(data);
            return(aggdata);
        }
예제 #6
0
 public void AddNewData(AggRawData newDatas)
 {
     throw new System.NotImplementedException();
 }
예제 #7
0
        public override AggRawData GetAggRawData(DateTime nowTime)
        {
            if (base.DbHelper == null)
            {
                return(null);
            }

            ///获取配置信息副本
            //if (!rwLocker.TryEnterReadLock(TimeOut))
            //    return null;
            //BaseAggConfig configTmp = ObjectHelper.DeepCopy(this.Config);
            //rwLocker.ExitReadLock();

            DateTime lastMonth = TimeStrategy.GetAggDate(config.Type, config.TimeRange, nowTime);
            int      year      = lastMonth.Year;
            int      month     = lastMonth.Month;
            int      beginDay;
            int      endDay;

            if (config.TimeRange.DateBegin == -1 || config.TimeRange.DateBegin > DateTime.DaysInMonth(year, month))
            {
                beginDay = DateTimeHelper.GetLastDayOfMonth(lastMonth);
            }
            else
            {
                beginDay = config.TimeRange.DateBegin;
            }


            if (config.TimeRange.DateEnd == -1 || config.TimeRange.DateEnd > DateTime.DaysInMonth(year, month))
            {
                endDay = DateTimeHelper.GetLastDayOfMonth(lastMonth);
            }
            else
            {
                endDay = config.TimeRange.DateEnd;
            }


            DateTime beginTime = new DateTime(year, month, beginDay, 0, 0, 0);
            DateTime endTime   = new DateTime(year, month, endDay, 23, 59, 59);

            AggRawData data      = new AggRawData(config.Key, config.ConfigId, GetTimeFlg(lastMonth));
            List <int> SensorIds = config.GetSensorIds();

            foreach (int sensorId in SensorIds)
            {
                RawData tempRawData = DbHelper.Accessor.GetMonthAggRawData(
                    sensorId,
                    config.FactorId,
                    config.TimeRange,
                    beginTime,
                    endTime);
                if (tempRawData != null && tempRawData.Values.Count > 0)
                {
                    data.Datas.Add(tempRawData);
                }
            }
            data.LastAggDatas = base.GetLastAggData();
            return(data);
        }