protected override void Sync(SyncDataQueue queue)
        {
            DateTime startTime = new DateTime(queue.Time.Year, queue.Time.Month, 1);
            DateTime endTime   = startTime.AddMonths(1).AddDays(-1);
            List <CityDailyAirQuality> source = Model.CityDailyAirQuality.Where(o => o.Time >= startTime && o.Time <= endTime).ToList();

            if (source.Any())
            {
                List <AirQualityShortTerm>   airQualityShortTermList = source.Select(o => o.ToAirQualityShortTerm()).ToList();
                List <CityMonthlyAirQuality> list       = new List <CityMonthlyAirQuality>();
                AirQualityLongTermCalculator calculator = new AirQualityLongTermCalculator();
                foreach (var cityGroup in airQualityShortTermList.GroupBy(o => o.Code))
                {
                    AirQualityShortTerm first = cityGroup.First();
                    AirQualityLongTerm  item  = new AirQualityLongTerm()
                    {
                        Code = first.Code,
                        Time = startTime,
                        Name = first.Name
                    };
                    calculator.Calculate(cityGroup, item);
                    list.Add(item.ToCityMonthlyAirQuality());
                }
                IQueryable <CityMonthlyAirQuality> oldList = Model.CityMonthlyAirQuality.Where(o => o.Time == startTime);
                Model.CityMonthlyAirQuality.RemoveRange(oldList);
                Model.CityMonthlyAirQuality.AddRange(list);
                queue.Status = true;
            }
            queue.LastTime = DateTime.Now;
        }
Example #2
0
 public static AirQualityShortTermYearOnYear ToAirQualityShortTermYearOnYear(this AirQualityShortTerm source)
 {
     return(new AirQualityShortTermYearOnYear()
     {
         Code = source.Code,
         Time = source.Time,
         Name = source.Name,
         SO2 = source.SO2,
         NO2 = source.NO2,
         PM10 = source.PM10,
         CO = source.CO,
         O3 = source.O3,
         PM25 = source.PM25,
         AQI = source.AQI,
         Type = source.Type,
         PrimaryPollutant = source.PrimaryPollutant,
         SO2R = source.SO2R,
         NO2R = source.NO2R,
         PM10R = source.PM10R,
         COR = source.COR,
         O3R = source.O3R,
         PM25R = source.PM25R,
         AQIR = source.AQIR
     });
 }
Example #3
0
 public static CityDailyAirQuality ToCityDailyAirQuality(this AirQualityShortTerm source)
 {
     return(new CityDailyAirQuality()
     {
         Code = source.Code,
         Time = source.Time,
         Name = source.Name,
         SO2 = source.SO2,
         NO2 = source.NO2,
         PM10 = source.PM10,
         CO = source.CO,
         O3 = source.O3,
         PM25 = source.PM25,
         AQI = source.AQI,
         Type = source.Type,
         PrimaryPollutant = source.PrimaryPollutant
     });
 }
 public List <AirQualityLongTerm> GetCityAnyTimeRangeAirQuality(string token, DateTime startTime, DateTime endTime, string areaCode)
 {
     if (validator.Validate(token, "CityAirQuality", "GetCityAnyTimeRangeAirQuality"))
     {
         IQueryable <CityDailyAirQuality> query = model.CityDailyAirQuality.Where(o => o.Time >= startTime && o.Time <= endTime);
         if (!string.IsNullOrEmpty(areaCode))
         {
             Area area = model.Area.FirstOrDefault(o => o.AreaCode == areaCode);
             if (area == null)
             {
                 query = query.Where(o => false);
             }
             else
             {
                 string[] cityCodes = area.City.Select(o => o.CityCode).ToArray();
                 query = query.Where(o => cityCodes.Contains(o.Code));
             }
         }
         List <AirQualityShortTerm>   source     = query.ToList().Select(o => o.ToAirQualityShortTerm()).ToList();
         AirQualityLongTermCalculator calculator = new AirQualityLongTermCalculator();
         List <AirQualityLongTerm>    list       = new List <AirQualityLongTerm>();
         foreach (var cityGroup in source.GroupBy(o => o.Code))
         {
             AirQualityShortTerm first = cityGroup.First();
             AirQualityLongTerm  item  = new AirQualityLongTerm()
             {
                 Code = first.Code,
                 Time = startTime,
                 Name = first.Name
             };
             calculator.Calculate(cityGroup, item);
             list.Add(item);
         }
         calculator.CalculateRank(list);
         return(list);
     }
     else
     {
         return(null);
     }
 }
Example #5
0
        public List <AirQualityShortTermYearOnYear> Calculate(List <AirQualityShortTerm> list, List <AirQualityShortTerm> baseList)
        {
            List <AirQualityShortTermYearOnYear> newList = new List <AirQualityShortTermYearOnYear>();

            foreach (AirQualityShortTerm item in list)
            {
                AirQualityShortTermYearOnYear newItem  = item.ToAirQualityShortTermYearOnYear();
                AirQualityShortTerm           baseItem = baseList.FirstOrDefault(o => o.Code == item.Code);
                if (baseItem != null)
                {
                    if (item.AQI.HasValue && baseItem.AQI.HasValue)
                    {
                        newItem.AQIYOY = Math.Round((item.AQI.Value - baseItem.AQI.Value) / baseItem.AQI.Value * 100, 2);
                    }
                }
                newList.Add(newItem);
            }
            RankCalculator rankCalculator = new RankCalculator();

            rankCalculator.Calculate(newList, o => o.AQIYOY, (o, rank) => { o.AQIYOYR = rank; });
            return(newList);
        }