Exemplo n.º 1
0
        private SiteData GetCityRealtimeAqi(DateTime time)
        {
            var dataSource = _groupDataRepository.Table.Where(d => d.DurationID == 10 && d.GroupID == 102 && d.LST_AQI == time).Where(d => d.AQIItemID == 100 || d.AQIItemID == 101 || d.AQIItemID == 102 || d.AQIItemID == 107 || d.AQIItemID == 104 || d.AQIItemID == 106 || d.ParameterID == 108).ToList();

            SiteData result = new SiteData()
            {
                Name       = "郑州市",
                UpdateTime = time.ToString("HH:mm")
            };

            foreach (var dataItem in dataSource)
            {
                if (dataItem.AQIItemID == 100)
                {
                    var primaryData     = dataItem;
                    PrimaryParameter pp = new PrimaryParameter()
                    {
                        Aqi           = primaryData.AQI.Value,
                        Value         = Math.Round(primaryData.Value.Value, 2),
                        ParameterId   = primaryData.ParameterID.Value,
                        ParameterName = primaryData.Parameter
                    };
                    result.Primary = pp;
                    result.Aqi     = pp.Aqi;
                    result.Grade   = _aqiGradeService.CalcGrade(pp.Aqi);
                }
                else
                {
                    ParameterData pd = new ParameterData();
                    pd.Name  = dataItem.Parameter;
                    pd.Value = null != dataItem.Value ? (Math.Round(dataItem.Value.Value, 2) + "ug/m3") : "";
                    result.OtherParameters.Add(pd);
                }
            }

            DateTime d2                 = time.AddHours(-24);
            var      hourData           = _groupDataRepository.Table.Where(d => d.DurationID == 10 && d.GroupID == 102 && d.LST_AQI <= time && d.LST_AQI >= d2).Where(d => d.AQIItemID == 100 || d.AQIItemID == 101 || d.AQIItemID == 102 || d.AQIItemID == 107 || d.AQIItemID == 104 || d.AQIItemID == 106 || d.ParameterID == 108).OrderBy(d => d.LST_AQI).ToList();
            List <ParameterHourData> hp = new List <ParameterHourData>();

            foreach (var dataItem in hourData)
            {
                ParameterHourData theData = hp.Where(p => p.ParameterId == dataItem.ParameterID).FirstOrDefault();
                if (null == theData)
                {
                    theData = new ParameterHourData()
                    {
                        Parameter = dataItem.Parameter, ParameterId = dataItem.ParameterID.Value, Unit = "ug/m3"
                    };
                    hp.Add(theData);
                }
                HourData hd = new HourData()
                {
                    Aqi = dataItem.AQI.Value, Value = Math.Round(dataItem.Value.Value, 2), DateTime = dataItem.LST_AQI
                };
                theData.Data.Add(hd);
            }
            result.Hours = hp;
            d2           = time.AddDays(-30);

            var dayData = _groupDataRepository.Table.Where(d => d.DurationID == 11 && d.GroupID == 102 && d.LST_AQI <= time && d.LST_AQI >= d2 && d.ParameterID == 0).OrderBy(d => d.LST_AQI).ToList();

            foreach (var dataItem in dayData)
            {
                DayAqi dayAqi = new DayAqi();
                dayAqi.Aqi     = dataItem.AQI.Value;
                dayAqi.Level   = dataItem.Grade.Value;
                dayAqi.DayTime = dataItem.LST_AQI;
                result.Days.Add(dayAqi);
            }
            if (result.Days.Count == 0)
            {
                result.Days.AddRange(createExampleDayAqi(time));
            }
            result.Forecast.AddRange(createExampleForecast(DateTime.Now));
            return(result);
        }
Exemplo n.º 2
0
        public Dictionary <int, SiteData> BuildAllSiteRealTimeAqi()
        {
            var time = _updateTimeRepository.Table.Where(t => t.Name == "AQINow").FirstOrDefault();

            if (time == null)
            {
                return(null);
            }
            //var dataSource = _siteDataRepository.Table.Where(d => d.DurationID == 10 && d.LST_AQI == time.Time).Where(d => d.ParameterID == 101 || d.ParameterID == 102 || d.ParameterID == 104 || d.ParameterID == 106 || d.ParameterID == 107 || d.ParameterID == 108).ToList();

            //var dataSource = _siteDataRepository.Table.Where(d => d.DurationID == 10 && d.LST_AQI == time.Time).Where(d => d.ParameterID == 1 || d.ParameterID == 2 || d.ParameterID == 6 || d.ParameterID == 7 || d.ParameterID == 8 || d.ParameterID == 21).ToList();

            var dataSource = _siteDataRepository.Table.Where(d => d.DurationID == 10 && d.LST_AQI == time.Time).Where(d => d.AQIItemID == 100 || d.AQIItemID == 101 || d.AQIItemID == 102 || d.AQIItemID == 107 || d.AQIItemID == 104 || d.AQIItemID == 106 || d.ParameterID == 108).ToList();
            Dictionary <int, List <DataRTSite> > siteData = new Dictionary <int, List <DataRTSite> >();

            Dictionary <int, SiteData> result = new Dictionary <int, SiteData>();

            Dictionary <int, List <ParameterHourData> > hourData = Get24HoursData(time.Time);
            Dictionary <int, List <DayAqi> >            dayData  = Get30DayAqi(time.Time);

            var siteService = EngineContext.Current.Resolve <ISiteService>();

            foreach (var dataItem in dataSource)
            {
                List <DataRTSite> sList = null;
                if (siteData.ContainsKey(dataItem.SiteID))
                {
                    sList = siteData[dataItem.SiteID];
                }
                else
                {
                    sList = new List <DataRTSite>();
                    siteData[dataItem.SiteID] = sList;
                }
                sList.Add(dataItem);
            }

            foreach (int siteId in siteData.Keys)
            {
                var pData = siteData[siteId];
                //var primaryData = pData.OrderByDescending(s => s.AQI).FirstOrDefault();
                //PrimaryParameter pp = new PrimaryParameter()
                //{
                //    Aqi = primaryData.AQI.Value,
                //    Value = primaryData.Value.Value,
                //    ParameterId = primaryData.ParameterID.Value,
                //    ParameterName = primaryData.Parameter
                //};

                var theSite = siteService.GetById(siteId);

                SiteData sd = new SiteData();
                if (null != theSite)
                {
                    sd.Name = theSite.Name;
                }
                sd.UpdateTime = time.Time.ToString("HH:mm");
                foreach (var pd in pData)
                {
                    if (pd.AQIItemID == 100)
                    {
                        var primaryData     = pd;
                        PrimaryParameter pp = new PrimaryParameter()
                        {
                            Aqi           = primaryData.AQI.Value,
                            Value         = Math.Round(primaryData.Value.Value, 2),
                            ParameterId   = primaryData.ParameterID.Value,
                            ParameterName = primaryData.Parameter
                        };
                        sd.Primary = pp;
                        sd.Aqi     = pp.Aqi;
                        sd.Grade   = _aqiGradeService.CalcGrade(pp.Aqi);
                    }
                    else
                    {
                        ParameterData parameterData = new ParameterData();
                        parameterData.Value = pd.Value != null ? (Math.Round(pd.Value.Value, 2) + "ug/m3") : "";
                        parameterData.Name  = pd.Parameter;
                        sd.OtherParameters.Add(parameterData);
                    }
                }

                if (hourData.ContainsKey(siteId))
                {
                    sd.Hours = hourData[siteId];
                }

                if (dayData.ContainsKey(siteId))
                {
                    sd.Days = dayData[siteId];
                }
                if (sd.Days == null || sd.Days.Count == 0)
                {
                    sd.Days = createExampleDayAqi(time.Time);
                }
                sd.Forecast.AddRange(createExampleForecast(DateTime.Now));
                result[siteId] = sd;
            }
            result[0] = GetCityRealtimeAqi(time.Time);
            return(result);
        }
Exemplo n.º 3
0
        private void fillHourToSiteData(SiteData siteData, List <StationOrCityMeasuredData> hourData, RankingData rd)
        {
            var newestData = hourData[hourData.Count - 1];

            PrimaryParameter pp = new PrimaryParameter();

            pp.Aqi           = int.Parse(newestData.AQI);
            pp.ParameterName = newestData.PrimaryPol.ToUpper();
            pp.Value         = switchPpValue(newestData);

            siteData.Primary = pp;
            siteData.Grade   = _aqiGradeService.CalcGrade(pp.Aqi);
            siteData.Aqi     = pp.Aqi;

            siteData.UpdateTime = newestData.DateTime.ToString("yyyy-MM-dd HH:00");

            fillRankingData(rd, newestData, siteData.Name, pp.Aqi);

            siteData.OtherParameters.Add(new ParameterData()
            {
                Name = "SO2", Value = parseStringToDecimal(newestData.SO2) + "ug/m3"
            });
            siteData.OtherParameters.Add(new ParameterData()
            {
                Name = "NO2", Value = parseStringToDecimal(newestData.NO2) + "ug/m3"
            });
            siteData.OtherParameters.Add(new ParameterData()
            {
                Name = "PM10", Value = parseStringToDecimal(newestData.PM10) + "ug/m3"
            });
            siteData.OtherParameters.Add(new ParameterData()
            {
                Name = "PM2.5", Value = parseStringToDecimal(newestData.PM25) + "ug/m3"
            });
            siteData.OtherParameters.Add(new ParameterData()
            {
                Name = "CO", Value = parseStringToDecimal(newestData.CO) + "mg/m3"
            });
            siteData.OtherParameters.Add(new ParameterData()
            {
                Name = "O3", Value = parseStringToDecimal(newestData.O3) + "ug/m3"
            });

            ParameterHourData so2 = new ParameterHourData()
            {
                Parameter = "SO2", Unit = "ug/m3"
            };
            ParameterHourData no2 = new ParameterHourData()
            {
                Parameter = "NO2", Unit = "ug/m3"
            };
            ParameterHourData pm10 = new ParameterHourData()
            {
                Parameter = "PM10", Unit = "ug/m3"
            };
            ParameterHourData pm25 = new ParameterHourData()
            {
                Parameter = "PM2.5", Unit = "ug/m3"
            };
            ParameterHourData co = new ParameterHourData()
            {
                Parameter = "CO", Unit = "mg/m3"
            };
            ParameterHourData o3 = new ParameterHourData()
            {
                Parameter = "O3", Unit = "ug/m3"
            };

            foreach (var h in hourData)
            {
                so2.Data.Add(new HourData()
                {
                    Aqi = parseStringToInt(h.SO2IAQI), Value = parseStringToDecimal(h.SO2), DateTime = h.DateTime
                });
                no2.Data.Add(new HourData()
                {
                    Aqi = parseStringToInt(h.NO2IAQI), Value = parseStringToDecimal(h.NO2), DateTime = h.DateTime
                });
                pm10.Data.Add(new HourData()
                {
                    Aqi = parseStringToInt(h.PM10IAQI), Value = parseStringToDecimal(h.PM10), DateTime = h.DateTime
                });
                pm25.Data.Add(new HourData()
                {
                    Aqi = parseStringToInt(h.PM25IAQI), Value = parseStringToDecimal(h.PM25), DateTime = h.DateTime
                });
                co.Data.Add(new HourData()
                {
                    Aqi = parseStringToInt(h.COIAQI), Value = parseStringToDecimal(h.CO), DateTime = h.DateTime
                });
                o3.Data.Add(new HourData()
                {
                    Aqi = parseStringToInt(h.O3IAQI), Value = parseStringToDecimal(h.O3), DateTime = h.DateTime
                });
            }
            siteData.Hours.AddRange(new ParameterHourData[] { so2, no2, pm10, pm25, co, o3 });
        }