Exemplo n.º 1
0
        public async Task <CdmaRegionDateView> QueryLastDateStat(DateTime initialDate, string city)
        {
            var beginDate = initialDate.AddDays(-100);
            var endDate   = initialDate.AddDays(1);
            var query     = await _statRepository.GetAllListAsync(beginDate, endDate);

            var regions
                = (await _regionRepository.GetAllListAsync(city)).Select(x => x.Region).Distinct().OrderBy(x => x);
            var result = (from q in query
                          join r in regions
                          on q.Region equals r
                          select q).ToList();

            if (result.Count == 0)
            {
                return(null);
            }
            var maxDate  = result.Max(x => x.StatDate);
            var stats    = result.Where(x => x.StatDate == maxDate).ToList();
            var cityStat = stats.ArraySum();

            cityStat.Region = city;
            stats.Add(cityStat);
            return(new CdmaRegionDateView
            {
                StatDate = maxDate,
                StatViews = Mapper.Map <List <CdmaRegionStat>, List <CdmaRegionStatView> >(stats)
            });
        }
Exemplo n.º 2
0
        public async Task <CdmaRegionStatTrend> QueryStatTrend(DateTime begin, DateTime end, string city)
        {
            var endDate = end.AddDays(1);
            var query   = await _statRepository.GetAllListAsync(begin, endDate);

            var regions
                = (await _optimzeRegionRepository.GetAllListAsync(city)).Select(x => x.Region).Distinct().OrderBy(x => x);
            var result = (from q in query
                          join r in regions
                          on q.Region equals r
                          select q).ToList();

            if (result.Count == 0)
            {
                return(null);
            }
            var dates      = result.Select(x => x.StatDate).Distinct().OrderBy(x => x);
            var regionList = result.Select(x => x.Region).Distinct().ToList();
            var viewList   = GenerateViewList(result, dates, regionList);

            regionList.Add(city);
            return(new CdmaRegionStatTrend
            {
                StatDates = dates.Select(x => x.ToShortDateString()),
                RegionList = regionList,
                ViewList = viewList
            });
        }