Example #1
0
        protected override void DataPortal_Insert()
        {
            using (var dalManager = DataFactoryManager.GetManager())
            {
                var dalFactory = dalManager.GetProvider <IHourDataFactory>();

                var data = new HourData();

                using (this.BypassPropertyChecks)
                {
                    this.ModifiedBy   = ((IBusinessIdentity)Csla.ApplicationContext.User.Identity).UserId;
                    this.ModifiedDate = DateTime.Now;
                    this.CreatedBy    = this.ModifiedBy;
                    this.CreatedDate  = this.ModifiedDate;

                    this.Insert(data);

                    data = dalFactory.Insert(data);

                    this.HourId = data.HourId;
                }

                // this.FieldManager.UpdateChildren(data);
            }
        }
Example #2
0
        private void Fetch(Hour hour, HourData hourData)
        {
            DataMapper.Map(hour, hourData);

            hourData.Project   = new ProjectData();
            hourData.ProjectId = hour.Story.ProjectId;
            DataMapper.Map(hour.Story.Project, hourData.Project);

            hourData.Sprint = new SprintData();
            if (hourData.SprintId != 0)
            {
                DataMapper.Map(hour.Story.Sprint, hourData.Sprint);
            }

            hourData.Story = new StoryData();
            DataMapper.Map(hour.Story, hourData.Story);

            hourData.User = new UserData();
            DataMapper.Map(hour.User, hourData.User);

            hourData.CreatedByUser = new UserData();
            DataMapper.Map(hour.CreatedByUser, hourData.CreatedByUser);

            hourData.ModifiedByUser = new UserData();
            DataMapper.Map(hour.ModifiedByUser, hourData.ModifiedByUser);
        }
        internal static Hour FetchHour(HourData data)
        {
            var result = new Hour();

            result.Fetch(data);
            result.MarkOld();

            return(result);
        }
        public HourData Update(HourData data)
        {
            var hour = MockDb.Hours
                       .Where(row => row.HourId == data.HourId)
                       .Single();

            Csla.Data.DataMapper.Map(data, hour);

            return(data);
        }
Example #5
0
        // Dohvata element iz liste sa lokacije <currentIndex>, uz
        // inkrementiranje vrednosti <currentIndex> promenljive.
        // U slucaju da je <currentIndex> vece od <displayHourCount>
        // vrednost currentIndex promenljive se postavlja na 0.
        public HourData GetNextHourInfo()
        {
            HourData hourToDisplay = displayHours.ElementAt(currentIndex++);

            if (currentIndex >= displayHourCount)
            {
                currentIndex = 0;
            }

            return(hourToDisplay);
        }
Example #6
0
 protected void Update(HourData data)
 {
     data.HourId       = this.HourId;
     data.Date         = this.Date;
     data.Duration     = this.Duration;
     data.IsArchived   = this.IsArchived;
     data.Notes        = this.Notes;
     data.StoryId      = this.StoryId;
     data.UserId       = this.UserId;
     data.CreatedBy    = this.CreatedBy;
     data.CreatedDate  = this.CreatedDate;
     data.ModifiedBy   = this.ModifiedBy;
     data.ModifiedDate = this.ModifiedDate;
 }
Example #7
0
 private void LoadData()
 {
     path = Application.persistentDataPath + "/HourData.json";
     if (System.IO.File.Exists(path))
     {
         jsonString = File.ReadAllText(path);
         timeData   = JsonUtility.FromJson <HourData>(jsonString);
         Debug.Log("Hour file exists" + jsonString);
     }
     else
     {
         timeData = new HourData(5);
     }
 }
Example #8
0
 internal static void Map(HourData source, Hour destination)
 {
     destination.HourId       = source.HourId;
     destination.Date         = source.Date;
     destination.Duration     = source.Duration;
     destination.IsArchived   = source.IsArchived;
     destination.Notes        = source.Notes;
     destination.StoryId      = source.StoryId;
     destination.UserId       = source.UserId;
     destination.CreatedBy    = source.CreatedBy;
     destination.CreatedDate  = source.CreatedDate;
     destination.ModifiedBy   = source.ModifiedBy;
     destination.ModifiedDate = source.ModifiedDate;
 }
Example #9
0
 internal static void Map(HourData source, Hour destination)
 {
     destination.HourId = source.HourId;
     destination.Date = source.Date;
     destination.Duration = source.Duration;
     destination.IsArchived = source.IsArchived;
     destination.Notes = source.Notes;
     destination.StoryId = source.StoryId;
     destination.UserId = source.UserId;
     destination.CreatedBy = source.CreatedBy;
     destination.CreatedDate = source.CreatedDate;
     destination.ModifiedBy = source.ModifiedBy;
     destination.ModifiedDate = source.ModifiedDate;
 }
Example #10
0
        public HourData Insert(HourData data)
        {
            if (MockDb.Hours.Count() == 0)
            {
                data.HourId = 1;
            }
            else
            {
                data.HourId = MockDb.Hours.Select(row => row.HourId).Max() + 1;
            }

            MockDb.Hours.Add(data);

            return data;
        }
        public HourData Insert(HourData data)
        {
            if (MockDb.Hours.Count() == 0)
            {
                data.HourId = 1;
            }
            else
            {
                data.HourId = MockDb.Hours.Select(row => row.HourId).Max() + 1;
            }

            MockDb.Hours.Add(data);

            return(data);
        }
Example #12
0
        public HourData Fetch(HourDataCriteria criteria)
        {
            using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities>
                         .GetManager(Database.ApplicationConnection, false))
            {
                var hour = this.Fetch(ctx, criteria)
                    .Single();

                var hourData = new HourData();

                this.Fetch(hour, hourData);

                return hourData;
            }
        }
Example #13
0
        public HourData Fetch(HourDataCriteria criteria)
        {
            using (var ctx = Csla.Data.ObjectContextManager <ApplicationEntities>
                             .GetManager(Database.ApplicationConnection, false))
            {
                var hour = this.Fetch(ctx, criteria)
                           .Single();

                var hourData = new HourData();

                this.Fetch(hour, hourData);

                return(hourData);
            }
        }
Example #14
0
        public HourData Insert(HourData data)
        {
            using (var ctx = Csla.Data.ObjectContextManager <ApplicationEntities>
                             .GetManager(Database.ApplicationConnection, false))
            {
                var hour = new Hour();

                DataMapper.Map(data, hour);

                ctx.ObjectContext.AddToHours(hour);

                ctx.ObjectContext.SaveChanges();

                data.HourId = hour.HourId;

                return(data);
            }
        }
Example #15
0
        public HourData Fetch(HourData data)
        {
            data.Story = MockDb.Stories
               .Where(row => row.StoryId == data.StoryId)
               .Single();

            data.User = MockDb.Users
                .Where(row => row.UserId == data.UserId)
                .Single();

            data.CreatedByUser = MockDb.Users
                .Where(row => row.UserId == data.CreatedBy)
                .Single();

            data.ModifiedByUser = MockDb.Users
                .Where(row => row.UserId == data.ModifiedBy)
                .Single();

            return data;
        }
Example #16
0
        public HourData Update(HourData data)
        {
            using (var ctx = Csla.Data.ObjectContextManager <ApplicationEntities>
                             .GetManager(Database.ApplicationConnection, false))
            {
                var hour =
                    new Hour
                {
                    HourId = data.HourId
                };

                ctx.ObjectContext.Hours.Attach(hour);

                DataMapper.Map(data, hour);

                ctx.ObjectContext.SaveChanges();

                return(data);
            }
        }
        public HourData Fetch(HourData data)
        {
            data.Story = MockDb.Stories
                         .Where(row => row.StoryId == data.StoryId)
                         .Single();

            data.User = MockDb.Users
                        .Where(row => row.UserId == data.UserId)
                        .Single();

            data.CreatedByUser = MockDb.Users
                                 .Where(row => row.UserId == data.CreatedBy)
                                 .Single();

            data.ModifiedByUser = MockDb.Users
                                  .Where(row => row.UserId == data.ModifiedBy)
                                  .Single();

            return(data);
        }
Example #18
0
 protected void Fetch(HourData data)
 {
     this.HourId         = data.HourId;
     this.Date           = data.Date;
     this.Duration       = data.Duration;
     this.IsArchived     = data.IsArchived;
     this.Notes          = data.Notes;
     this.ProjectId      = data.ProjectId;
     this.ProjectName    = data.Project.Name;
     this.SprintId       = data.SprintId;
     this.SprintName     = data.Sprint.Name;
     this.StoryId        = data.StoryId;
     this.UserId         = data.UserId;
     this.UserName       = data.User.Name;
     this.CreatedBy      = data.CreatedBy;
     this.CreatedByName  = data.CreatedByUser.Name;
     this.CreatedDate    = data.CreatedDate;
     this.ModifiedBy     = data.ModifiedBy;
     this.ModifiedByName = data.ModifiedByUser.Name;
     this.ModifiedDate   = data.ModifiedDate;
 }
Example #19
0
        private Dictionary <int, List <ParameterHourData> > Get24HoursData(DateTime time)
        {
            DateTime d2 = time.AddHours(-24);
            //var dataSource = _siteDataRepository.Table.Where(d => d.DurationID == 10 && d.LST_AQI <= time && d.LST_AQI >= d2).Where(d => d.ParameterID == 101 || d.ParameterID == 102 || d.ParameterID == 104 || d.DurationID == 106 || d.ParameterID == 107 || d.ParameterID == 108).OrderBy(d => d.LST_AQI).ToList();

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

            var dataSource = _siteDataRepository.Table.Where(d => d.DurationID == 10 && 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();

            Dictionary <int, List <ParameterHourData> > result = new Dictionary <int, List <ParameterHourData> >();

            foreach (var dataItem in dataSource)
            {
                List <ParameterHourData> phdList = null;
                if (result.ContainsKey(dataItem.SiteID))
                {
                    phdList = result[dataItem.SiteID];
                }
                else
                {
                    phdList = new List <ParameterHourData>();
                    result[dataItem.SiteID] = phdList;
                }
                ParameterHourData theData = phdList.Where(p => p.ParameterId == dataItem.ParameterID).FirstOrDefault();
                if (null == theData)
                {
                    theData = new ParameterHourData()
                    {
                        Parameter = dataItem.Parameter, ParameterId = dataItem.ParameterID.Value, Unit = "ug/m3"
                    };
                    phdList.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);
            }
            return(result);
        }
Example #20
0
        public HourData[] FetchLookupInfoList(HourDataCriteria criteria)
        {
            using (var ctx = Csla.Data.ObjectContextManager <ApplicationEntities>
                             .GetManager(Database.ApplicationConnection, false))
            {
                var hours = this.Fetch(ctx, criteria)
                            .AsEnumerable();

                var hourDataList = new List <HourData>();

                foreach (var hour in hours)
                {
                    var hourData = new HourData();

                    this.Fetch(hour, hourData);

                    hourDataList.Add(hourData);
                }

                return(hourDataList.ToArray());
            }
        }
Example #21
0
        public HourData[] FetchLookupInfoList(HourDataCriteria criteria)
        {
            using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities>
                          .GetManager(Database.ApplicationConnection, false))
            {
                var hours = this.Fetch(ctx, criteria)
                    .AsEnumerable();

                var hourDataList = new List<HourData>();

                foreach (var hour in hours)
                {
                    var hourData = new HourData();

                    this.Fetch(hour, hourData);

                    hourDataList.Add(hourData);
                }

                return hourDataList.ToArray();
            }
        }
Example #22
0
 public HDataReport(DateTime qn, string st, string passwd, string mn, HourData hourData)
     : base(qn, st, passwd, HJ212.HourData, mn)
 {
     ResponseCN = HJ212.DataAck;
     _hourData  = hourData;
 }
Example #23
0
        public HourData Insert(HourData data)
        {
            using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities>
                           .GetManager(Database.ApplicationConnection, false))
            {
                var hour = new Hour();

                DataMapper.Map(data, hour);

                ctx.ObjectContext.AddToHours(hour);

                ctx.ObjectContext.SaveChanges();

                data.HourId = hour.HourId;

                return data;
            }
        }
Example #24
0
 protected void Insert(HourData data)
 {
     this.Update(data);
 }
Example #25
0
        private void Fetch(Hour hour, HourData hourData)
        {
            DataMapper.Map(hour, hourData);

            hourData.Project = new ProjectData();
            hourData.ProjectId = hour.Story.ProjectId;
            DataMapper.Map(hour.Story.Project, hourData.Project);

            hourData.Sprint = new SprintData();
            if (hourData.SprintId != 0)
            {
                DataMapper.Map(hour.Story.Sprint, hourData.Sprint);
            }

            hourData.Story = new StoryData();
            DataMapper.Map(hour.Story, hourData.Story);

            hourData.User = new UserData();
            DataMapper.Map(hour.User, hourData.User);

            hourData.CreatedByUser = new UserData();
            DataMapper.Map(hour.CreatedByUser, hourData.CreatedByUser);

            hourData.ModifiedByUser = new UserData();
            DataMapper.Map(hour.ModifiedByUser, hourData.ModifiedByUser);
        }
Example #26
0
        public HourData Update(HourData data)
        {
            using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities>
                         .GetManager(Database.ApplicationConnection, false))
            {
                var hour =
                    new Hour
                    {
                        HourId = data.HourId
                    };

                ctx.ObjectContext.Hours.Attach(hour);

                DataMapper.Map(data, hour);

                ctx.ObjectContext.SaveChanges();

                return data;
            }
        }
Example #27
0
        private void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (DateTime.Now.Minute == 0)
            {
                //取得一小时内分钟数据
                List <MinuteData> minuteDatas = GetMinuteDatas();
                if (minuteDatas.Count == 0)
                {
                    return;
                }
                //获取监测点污染物
                List <MonitorPointPollutan> monitorPointPollutans = GetMonitorPointPollutans();
                //用于数据库中一小时浓度的添加

                List <HourData> hourDatas = new List <HourData>();
                //用于求一小时的AQI

                List <AvgData> avgDatas = new List <AvgData>();
                DateTime       dateTime = DateTime.Now;
                //循环遍历除AQI之外的监测点污染物
                foreach (MonitorPointPollutan monitorPointPollutan in monitorPointPollutans.Where(m => m.PollutantId != 11))
                {
                    HourData hourData      = new HourData();
                    AvgData  avgData       = new AvgData();
                    var      mpMinuteDatas = minuteDatas.Where(m => m.Monitor_PollutionId == monitorPointPollutan.Id);

                    hourData.Monitor_PollutionId = monitorPointPollutan.Id;
                    hourData.MaxValue            = mpMinuteDatas.Max(m => m.AVGValue);
                    hourData.MinValue            = mpMinuteDatas.Min(m => m.AVGValue);
                    hourData.AVGValue            = mpMinuteDatas.Average(m => m.AVGValue);
                    hourData.MonitorTime         = dateTime;
                    hourDatas.Add(hourData);

                    avgData.AvgValue    = mpMinuteDatas.Average(m => m.AVGValue);
                    avgData.PointID     = monitorPointPollutan.PointId;
                    avgData.PollutantID = monitorPointPollutan.PollutantId;
                    avgDatas.Add(avgData);
                }
                AQICompute aqiCompute = new AQICompute();
                foreach (MonitorPointPollutan monitorPointPollutan in monitorPointPollutans.Where(m => m.PollutantId == 11))
                {
                    HourData hourData = new HourData();
                    hourData.Monitor_PollutionId = monitorPointPollutan.Id;
                    hourData.MonitorTime         = dateTime;
                    decimal pm2  = 0;
                    decimal pm10 = 0;
                    decimal co   = 0;
                    decimal no2  = 0;
                    decimal o3   = 0;
                    decimal so2  = 0;
                    foreach (AvgData avgData in avgDatas)
                    {
                        if (avgData.PointID == monitorPointPollutan.PointId)
                        {
                            switch (avgData.PollutantID)
                            {
                            case 12: pm2 = avgData.AvgValue; break;

                            case 13: co = avgData.AvgValue; break;

                            case 14: no2 = avgData.AvgValue; break;

                            case 15: o3 = avgData.AvgValue; break;

                            case 16: so2 = avgData.AvgValue; break;

                            case 17: pm10 = avgData.AvgValue; break;
                            }
                        }
                    }
                    hourData.AVGValue = Convert.ToDecimal(aqiCompute.GetAQI(pm2, co, no2, o3, so2, pm10));
                    hourDatas.Add(hourData);
                }
                #region 国控站
                string        stations = "[{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"万寿西宫\",\"station_code\":\"1001A\",\"lng\":116.366,\"lat\":39.8673},{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"定陵\",\"station_code\":\"1002A\",\"lng\":116.17,\"lat\":40.2865},{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"东四\",\"station_code\":\"1003A\",\"lng\":116.434,\"lat\":39.9522},{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"天坛\",\"station_code\":\"1004A\",\"lng\":116.434,\"lat\":39.8745},{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"农展馆\",\"station_code\":\"1005A\",\"lng\":116.473,\"lat\":39.9716},{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"官园\",\"station_code\":\"1006A\",\"lng\":116.361,\"lat\":39.9425},{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"海淀区万柳\",\"station_code\":\"1007A\",\"lng\":116.315,\"lat\":39.9934},{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"顺义新城\",\"station_code\":\"1008A\",\"lng\":116.72,\"lat\":40.1438},{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"怀柔镇\",\"station_code\":\"1009A\",\"lng\":116.644,\"lat\":40.3937},{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"昌平镇\",\"station_code\":\"1010A\",\"lng\":116.23,\"lat\":40.1952},{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"奥体中心\",\"station_code\":\"1011A\",\"lng\":116.407,\"lat\":40.0031},{\"city\":\"北京市\",\"city_code\":\"110000\",\"station\":\"古城\",\"station_code\":\"1012A\",\"lng\":116.225,\"lat\":39.9279},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"勤俭道\",\"station_code\":\"1015A\",\"lng\":117.145,\"lat\":39.1654},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"大直沽八号路\",\"station_code\":\"1017A\",\"lng\":117.237,\"lat\":39.1082},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"前进道\",\"station_code\":\"1018A\",\"lng\":117.202,\"lat\":39.0927},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"淮河道\",\"station_code\":\"1019A\",\"lng\":117.1837,\"lat\":39.2133},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"跃进路\",\"station_code\":\"1021A\",\"lng\":117.307,\"lat\":39.0877},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"第四大街\",\"station_code\":\"1023A\",\"lng\":117.707,\"lat\":39.0343},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"永明路\",\"station_code\":\"1024A\",\"lng\":117.457,\"lat\":38.8394},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"汉北路\",\"station_code\":\"1026A\",\"lng\":117.764,\"lat\":39.1587},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"团泊洼\",\"station_code\":\"1027A\",\"lng\":117.157,\"lat\":38.9194},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"河西一经路\",\"station_code\":\"2858A\",\"lng\":117.7918,\"lat\":39.2474},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"津沽路\",\"station_code\":\"2859A\",\"lng\":117.3747,\"lat\":38.9846},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"宾水西道\",\"station_code\":\"2860A\",\"lng\":117.1589,\"lat\":39.0845},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"大理道\",\"station_code\":\"2922A\",\"lng\":117.1941,\"lat\":39.1067},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"中山北路\",\"station_code\":\"3020A\",\"lng\":117.2099,\"lat\":39.16969},{\"city\":\"天津市\",\"city_code\":\"120000\",\"station\":\"西四道\",\"station_code\":\"3051A\",\"lng\":117.3916,\"lat\":39.1495},{\"city\":\"石家庄市\",\"city_code\":\"130100\",\"station\":\"职工医院\",\"station_code\":\"1029A\",\"lng\":114.4548,\"lat\":38.0513},{\"city\":\"石家庄市\",\"city_code\":\"130100\",\"station\":\"高新区\",\"station_code\":\"1030A\",\"lng\":114.6046,\"lat\":38.0398},{\"city\":\"石家庄市\",\"city_code\":\"130100\",\"station\":\"西北水源\",\"station_code\":\"1031A\",\"lng\":114.5019,\"lat\":38.1398},{\"city\":\"石家庄市\",\"city_code\":\"130100\",\"station\":\"西南高教\",\"station_code\":\"1032A\",\"lng\":114.4586111,\"lat\":38.00583333},{\"city\":\"石家庄市\",\"city_code\":\"130100\",\"station\":\"世纪公园\",\"station_code\":\"1033A\",\"lng\":114.5330556,\"lat\":38.01777778},{\"city\":\"石家庄市\",\"city_code\":\"130100\",\"station\":\"人民会堂\",\"station_code\":\"1034A\",\"lng\":114.5214,\"lat\":38.0524},{\"city\":\"石家庄市\",\"city_code\":\"130100\",\"station\":\"封龙山\",\"station_code\":\"1035A\",\"lng\":114.3541,\"lat\":37.9097},{\"city\":\"石家庄市\",\"city_code\":\"130100\",\"station\":\"22中南校区\",\"station_code\":\"2862A\",\"lng\":114.5480556,\"lat\":38.03777778},{\"city\":\"唐山市\",\"city_code\":\"130200\",\"station\":\"供销社\",\"station_code\":\"1036A\",\"lng\":118.1662,\"lat\":39.6308},{\"city\":\"唐山市\",\"city_code\":\"130200\",\"station\":\"雷达站\",\"station_code\":\"1037A\",\"lng\":118.144,\"lat\":39.643},{\"city\":\"唐山市\",\"city_code\":\"130200\",\"station\":\"物资局\",\"station_code\":\"1038A\",\"lng\":118.1853,\"lat\":39.6407},{\"city\":\"唐山市\",\"city_code\":\"130200\",\"station\":\"陶瓷公司\",\"station_code\":\"1039A\",\"lng\":118.2185,\"lat\":39.6679},{\"city\":\"唐山市\",\"city_code\":\"130200\",\"station\":\"十二中\",\"station_code\":\"1040A\",\"lng\":118.1838,\"lat\":39.65782},{\"city\":\"唐山市\",\"city_code\":\"130200\",\"station\":\"小山\",\"station_code\":\"1041A\",\"lng\":118.1997,\"lat\":39.6295},{\"city\":\"秦皇岛市\",\"city_code\":\"130300\",\"station\":\"北戴河环保局\",\"station_code\":\"1042A\",\"lng\":119.5259,\"lat\":39.8283},{\"city\":\"秦皇岛市\",\"city_code\":\"130300\",\"station\":\"第一关\",\"station_code\":\"1043A\",\"lng\":119.7624,\"lat\":40.0181},{\"city\":\"秦皇岛市\",\"city_code\":\"130300\",\"station\":\"监测站\",\"station_code\":\"1044A\",\"lng\":119.6023,\"lat\":39.9567},{\"city\":\"秦皇岛市\",\"city_code\":\"130300\",\"station\":\"建设大厦\",\"station_code\":\"1046A\",\"lng\":119.5369,\"lat\":39.9419},{\"city\":\"秦皇岛市\",\"city_code\":\"130300\",\"station\":\"文明里(启用171012)\",\"station_code\":\"3132A\",\"lng\":119.5967,\"lat\":37.0308},{\"city\":\"邯郸市\",\"city_code\":\"130400\",\"station\":\"环保局\",\"station_code\":\"1047A\",\"lng\":114.5129,\"lat\":36.61763},{\"city\":\"邯郸市\",\"city_code\":\"130400\",\"station\":\"东污水处理厂\",\"station_code\":\"1048A\",\"lng\":114.5426,\"lat\":36.6164},{\"city\":\"邯郸市\",\"city_code\":\"130400\",\"station\":\"矿院\",\"station_code\":\"1049A\",\"lng\":114.5035,\"lat\":36.5776},{\"city\":\"邯郸市\",\"city_code\":\"130400\",\"station\":\"丛台公园\",\"station_code\":\"1050A\",\"lng\":114.4965,\"lat\":36.61981},{\"city\":\"邢台市\",\"city_code\":\"130500\",\"station\":\"达活泉\",\"station_code\":\"1077A\",\"lng\":114.4821,\"lat\":37.0967},{\"city\":\"邢台市\",\"city_code\":\"130500\",\"station\":\"邢师高专\",\"station_code\":\"1078A\",\"lng\":114.5261,\"lat\":37.0533},{\"city\":\"邢台市\",\"city_code\":\"130500\",\"station\":\"路桥公司\",\"station_code\":\"1079A\",\"lng\":114.5331,\"lat\":37.0964},{\"city\":\"邢台市\",\"city_code\":\"130500\",\"station\":\"市环保局\",\"station_code\":\"1080A\",\"lng\":114.4854,\"lat\":37.062},{\"city\":\"保定市\",\"city_code\":\"130600\",\"station\":\"游泳馆\",\"station_code\":\"1051A\",\"lng\":115.493,\"lat\":38.8632},{\"city\":\"保定市\",\"city_code\":\"130600\",\"station\":\"华电二区\",\"station_code\":\"1052A\",\"lng\":115.5223,\"lat\":38.8957},{\"city\":\"保定市\",\"city_code\":\"130600\",\"station\":\"接待中心\",\"station_code\":\"1053A\",\"lng\":115.4713,\"lat\":38.9108},{\"city\":\"保定市\",\"city_code\":\"130600\",\"station\":\"地表水厂\",\"station_code\":\"1054A\",\"lng\":115.4612,\"lat\":38.8416},{\"city\":\"保定市\",\"city_code\":\"130600\",\"station\":\"胶片厂\",\"station_code\":\"1055A\",\"lng\":115.442,\"lat\":38.8756},{\"city\":\"承德市\",\"city_code\":\"130800\",\"station\":\"铁路\",\"station_code\":\"1062A\",\"lng\":117.9664,\"lat\":40.9161},{\"city\":\"承德市\",\"city_code\":\"130800\",\"station\":\"中国银行\",\"station_code\":\"1063A\",\"lng\":117.9525,\"lat\":40.9843},{\"city\":\"承德市\",\"city_code\":\"130800\",\"station\":\"开发区\",\"station_code\":\"1064A\",\"lng\":117.963,\"lat\":40.9359},{\"city\":\"承德市\",\"city_code\":\"130800\",\"station\":\"文化中心\",\"station_code\":\"1065A\",\"lng\":117.8184,\"lat\":40.9733},{\"city\":\"承德市\",\"city_code\":\"130800\",\"station\":\"离宫\",\"station_code\":\"1066A\",\"lng\":117.9384,\"lat\":41.0112},{\"city\":\"沧州市\",\"city_code\":\"130900\",\"station\":\"沧县城建局\",\"station_code\":\"1071A\",\"lng\":116.8854,\"lat\":38.2991},{\"city\":\"沧州市\",\"city_code\":\"130900\",\"station\":\"电视转播站\",\"station_code\":\"1072A\",\"lng\":116.8584,\"lat\":38.3254}]";
                List <Region> regions  = JsonConvert.DeserializeObject <List <Region> >(stations);
                List <MonitorPointPollutan> monitorPoints = GetMonitorPointPollutansby9();
                foreach (Region region in regions)
                {
                    String          querys       = "pubtime=" + DateTime.Now.ToShortDateString() + "+" + (DateTime.Now.Hour - 1).ToString() + "%3A00%3A00&station_code=" + region.station_code;
                    String          bodys        = "";
                    String          url          = host + path;
                    HttpWebRequest  httpRequest  = null;
                    HttpWebResponse httpResponse = null;

                    if (0 < querys.Length)
                    {
                        url = url + "?" + querys;
                    }

                    if (host.Contains("https://"))
                    {
                        ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                        httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
                    }
                    else
                    {
                        httpRequest = (HttpWebRequest)WebRequest.Create(url);
                    }
                    httpRequest.Method = method;
                    httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
                    if (0 < bodys.Length)
                    {
                        byte[] data = Encoding.UTF8.GetBytes(bodys);
                        using (Stream stream = httpRequest.GetRequestStream())
                        {
                            stream.Write(data, 0, data.Length);
                        }
                    }
                    try
                    {
                        httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                    }
                    catch (WebException ex)
                    {
                        httpResponse = (HttpWebResponse)ex.Response;
                    }

                    Stream       st       = httpResponse.GetResponseStream();
                    StreamReader reader   = new StreamReader(st, Encoding.GetEncoding("utf-8"));
                    string       me       = reader.ReadToEnd();
                    message      messagee = JsonConvert.DeserializeObject <message>(me);
                    foreach (MonitorPointPollutan m in monitorPoints.Where(m => m.PointName == messagee.data.station))
                    {
                        HourData hourData = new HourData();
                        hourData.Monitor_PollutionId = m.Id;
                        hourData.MonitorTime         = dateTime;
                        switch (m.PollutantId)
                        {
                        case 11: hourData.AVGValue = messagee.data.AQI == null ? 0 : Convert.ToDecimal(messagee.data.AQI); break;

                        case 12: hourData.AVGValue = messagee.data.PM2_5 == null ? 0 : Convert.ToDecimal(messagee.data.PM2_5); break;

                        case 13: hourData.AVGValue = messagee.data.CO == null ? 0 : Convert.ToDecimal(messagee.data.CO); break;

                        case 14: hourData.AVGValue = messagee.data.NO2 == null ? 0 : Convert.ToDecimal(messagee.data.NO2); break;

                        case 15: hourData.AVGValue = messagee.data.O3 == null ? 0 : Convert.ToDecimal(messagee.data.O3); break;

                        case 16: hourData.AVGValue = messagee.data.SO2 == null ? 0 : Convert.ToDecimal(messagee.data.SO2); break;

                        case 17: hourData.AVGValue = messagee.data.PM10 == null ? 0 : Convert.ToDecimal(messagee.data.PM10); break;
                        }
                        hourDatas.Add(hourData);
                    }
                }
                #endregion
                AddHourData(hourDatas);
            }
        }
Example #28
0
        public HourData Update(HourData data)
        {
            var hour = MockDb.Hours
                .Where(row => row.HourId == data.HourId)
                .Single();

            Csla.Data.DataMapper.Map(data, hour);

            return data;
        }
Example #29
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);
        }
        public async Task <WeatherItem> GetForecastAsync(IOptions <AppSettings> appSettings)
        {
            WeatherItem weatherForecast = new WeatherItem();

            string apiKey = appSettings.Value.DarkSkyAPIKey;

            var darkSky = new DarkSky.Services.DarkSkyService(apiKey);

            var forecast = await darkSky.GetForecast(51.4557, -2.583,
                                                     new OptionalParameters
            {
                MeasurementUnits = "si"
            });

            if (forecast?.IsSuccessStatus == true)
            {
                weatherForecast.CurrentFeelsLikeTemperature = Convert.ToInt32(forecast.Response.Currently.ApparentTemperature);
                weatherForecast.CurrentSummary     = forecast.Response.Currently.Summary;
                weatherForecast.CurrentTemperature = Convert.ToInt32(forecast.Response.Currently.Temperature);
                weatherForecast.CurrentIconPath    = "/images/" + forecast.Response.Currently.Icon.ToString() + ".svg";

                weatherForecast.MinutelySummary = forecast.Response.Minutely.Summary;

                List <HourData> hourData = new List <HourData>();

                foreach (var hour in forecast.Response.Hourly.Data.GetRange(1, 3))
                {
                    HourData hdata = new HourData();
                    hdata.Time    = DateTime.ParseExact(hour.DateTime.TimeOfDay.ToString(), "HH:mm:ss", new CultureInfo("en-GB")).ToString("HH:mm");
                    hdata.Summary = hour.Summary;
                    hdata.Temp    = Convert.ToInt32(hour.Temperature);
                    hdata.Icon    = "/images/" + hour.Icon.ToString() + ".svg";
                    hourData.Add(hdata);
                }

                weatherForecast.Hour = hourData;

                List <DayData> dayData = new List <DayData>();

                foreach (var day in forecast.Response.Daily.Data.GetRange(0, 4))
                {
                    DayData ddata = new DayData();
                    ddata.Day      = DateTime.ParseExact(day.DateTime.Date.ToString(), "dd/MM/yyyy HH:mm:ss", new CultureInfo("en-GB")).ToString("dd.MM yyyy");
                    ddata.Summary  = day.Summary;
                    ddata.Temp     = Convert.ToInt32(day.TemperatureLow);
                    ddata.TempLow  = Convert.ToInt32(day.TemperatureLow);
                    ddata.TempHigh = Convert.ToInt32(day.TemperatureHigh);
                    ddata.Icon     = "images/" + day.Icon.ToString() + ".svg";
                    dayData.Add(ddata);
                }

                weatherForecast.Day = dayData;

                weatherForecast.Alerts = forecast.Response.Alerts;
            }
            else
            {
                weatherForecast.CurrentSummary = "No current weather data";
            }

            return(weatherForecast);
        }