示例#1
0
        public static async Task <UserLatLng> UserLocation(string address)
        {
            UserLatLng userLocation = new UserLatLng();

            var jsonAddress = await GeocodeingAPI.UserAddress(address);

            userLocation.Lat = double.Parse(jsonAddress["results"][0]["geometry"]["location"]["lat"].ToString());
            userLocation.Lng = double.Parse(jsonAddress["results"][0]["geometry"]["location"]["lng"].ToString());

            return(userLocation);
        }
示例#2
0
        public static List <Sensor> OrderedSensors(UserLatLng address)
        {
            List <Sensor> sensors = Sensor.GetSensors();

            try
            {
                var userLocation = address;

                for (int i = 0; i < sensors.Count; i++)
                {
                    sensors[i].Distance = LatLongDistance(userLocation.Lat, userLocation.Lng, sensors[i].Lat, sensors[i].Long);
                }
                List <Sensor> finalList = sensors.OrderBy(x => x.Distance).ToList();

                return(finalList);
            }
            catch (AggregateException)
            {
                sensors.Clear();
                return(sensors);
            }
        }
示例#3
0
        public IActionResult AirQuality(string address)
        {
            //just put the default list in for now.
            if (address == "" || address == null)
            {
                return(RedirectToAction("Test"));
            }
            DisplayToUserInformation UserInfo = new DisplayToUserInformation();
            UserLatLng userLatLng             = Geocode.UserLocation(address).Result;

            List <Sensor> sensors = Geocode.OrderedSensors(userLatLng);

            UserInfo.UserLatitude  = userLatLng.Lat;
            UserInfo.UserLongitude = userLatLng.Lng;

            //List<Sensor> sensors = Sensor.GetSensors();
            Pollutants pollutantAQIs = new Pollutants();

            //going to change this to a loop later, use i to test various sensors.-----------------------------------
            int i = 0;

            UserInfo.SensorName = sensors[i].Name;
            PullSimsData pollutants1Hr = new PullSimsData(sensors[i], -1, configuration);

            pollutants1Hr.AddAQIs();
            UserInfo.AQINO2 = pollutants1Hr.NO2AQI;
            if (pollutants1Hr.NO2Average != null)
            {
                UserInfo.NO2Avg = (double)pollutants1Hr.NO2Average;
            }
            else
            {
                UserInfo.NO2Avg = 0;
            }

            UserInfo.AQISO2 = pollutants1Hr.SO2AQI;

            PullSimsData pollutants8Hr = new PullSimsData(sensors[i], -8, configuration);

            pollutants8Hr.AddAQIs();
            UserInfo.AQICO = pollutants8Hr.COAQI;

            if (pollutants1Hr.COAverage != null)
            {
                UserInfo.COAvg = (double)pollutants8Hr.COAverage;
            }
            else
            {
                UserInfo.COAvg = 0;
            }

            if (pollutants1Hr.O3Average >= 0.125)
            {
                UserInfo.AQIO3 = pollutants8Hr.O3AQI;
            }
            else
            {
                UserInfo.AQIO3 = pollutants1Hr.O3AQI;
            }

            PullSimsData pollutant24Hr = new PullSimsData(sensors[i], -24, configuration);

            pollutant24Hr.AddAQIs();

            UserInfo.AQIPM10 = pollutant24Hr.PM10AQI;
            UserInfo.AQIPM25 = pollutant24Hr.PM25AQI;

            List <FutureAQIs> futureAQIs = getFutureAQIs(UserInfo.O3Avg, UserInfo.COAvg, UserInfo.NO2Avg);

            UserInfo.FutureAQIs = futureAQIs; // sent to view as FutureAQIs object from DisplayToUserInformation model
                                              // 3x3 list index 0 = 1 day, index 1 = 3 day, index 2 = 5 day & .O3, .CO, .NO2
            UserInfo.CalculateHighestAQI();
            UserInfo.Sensor = sensors[0];
            UserInfo.AddColor();

            return(View(UserInfo));
        }