コード例 #1
0
        public void GetWorstCloudyWeather()
        {
            string json    = "{\"cod\":\"200\",\"message\":0.0074,\"cnt\":40,\"list\":[{\"dt\":1562662800,\"main\":{\"temp\":289.15,\"temp_min\":289.15,\"temp_max\":289.3,\"pressure\":1014.16,\"sea_level\":1014.16,\"grnd_level\":983.85,\"humidity\":47,\"temp_kf\":-0.15},\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02d\"}],\"clouds\":{\"all\":18},\"wind\":{\"speed\":3.98,\"deg\":34.536},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-09 09:00:00\"},{\"dt\":1562673600,\"main\":{\"temp\":292.25,\"temp_min\":292.25,\"temp_max\":292.363,\"pressure\":1014.1,\"sea_level\":1014.1,\"grnd_level\":983.48,\"humidity\":38,\"temp_kf\":-0.11},\"weather\":[{\"id\":802,\"main\":\"Clouds\",\"description\":\"scattered clouds\",\"icon\":\"03d\"}],\"clouds\":{\"all\":32},\"wind\":{\"speed\":3.53,\"deg\":38.008},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-09 12:00:00\"},{\"dt\":1562684400,\"main\":{\"temp\":292.66,\"temp_min\":292.66,\"temp_max\":292.732,\"pressure\":1013.35,\"sea_level\":1013.35,\"grnd_level\":982.83,\"humidity\":38,\"temp_kf\":-0.07},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":3},\"wind\":{\"speed\":2.96,\"deg\":38.436},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019 - 07 - 09 15:00:00\"},{\"dt\":1562695200,\"main\":{\"temp\":290.8,\"temp_min\":290.8,\"temp_max\":290.832,\"pressure\":1013.73,\"sea_level\":1013.73,\"grnd_level\":983.38,\"humidity\":52,\"temp_kf\":-0.04},\"weather\":[{\"id\":802,\"main\":\"Clouds\",\"description\":\"scattered clouds\",\"icon\":\"03d\"}],\"clouds\":{\"all\":32},\"wind\":{\"speed\":1.26,\"deg\":25.08},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-09 18:00:00\"},{\"dt\":1562706000,\"main\":{\"temp\":286.032,\"temp_min\":286.032,\"temp_max\":286.032,\"pressure\":1014.25,\"sea_level\":1014.25,\"grnd_level\":983.85,\"humidity\":71,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":92},\"wind\":{\"speed\":2.04,\"deg\":351.245},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2019-07 - 09 21:00:00\"},{\"dt\":1562716800,\"main\":{\"temp\":282.9,\"temp_min\":282.9,\"temp_max\":282.9,\"pressure\":1014.48,\"sea_level\":1014.48,\"grnd_level\":984.05,\"humidity\":81,\"temp_kf\":0},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":79},\"wind\":{\"speed\":2.15,\"deg\":321.144},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2019 - 07 - 10 00:00:00\"},{\"dt\":1562727600,\"main\":{\"temp\":283.3,\"temp_min\":283.3,\"temp_max\":283.3,\"pressure\":1014.12,\"sea_level\":1014.12,\"grnd_level\":983.5,\"humidity\":76,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":1.79,\"deg\":294.001},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-10 03:00:00\"},{\"dt\":1562738400,\"main\":{\"temp\":289.3,\"temp_min\":289.3,\"temp_max\":289.3,\"pressure\":1013.31,\"sea_level\":1013.31,\"grnd_level\":983.04,\"humidity\":55,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":90},\"wind\":{\"speed\":1.99,\"deg\":357.286},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-10 06:00:00\"},{\"dt\":1562749200,\"main\":{\"temp\":293,\"temp_min\":293,\"temp_max\":293,\"pressure\":1012.91,\"sea_level\":1012.91,\"grnd_level\":982.98,\"humidity\":43,\"temp_kf\":0},\"weather\":[{\"id\":802,\"main\":\"Clouds\",\"description\":\"scattered clouds\",\"icon\":\"03d\"}],\"clouds\":{\"all\":38},\"wind\":{\"speed\":2.79,\"deg\":42.715},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019 - 07 - 10 09:00:00\"},{\"dt\":1562760000,\"main\":{\"temp\":295.2,\"temp_min\":295.2,\"temp_max\":295.2,\"pressure\":1012.05,\"sea_level\":1012.05,\"grnd_level\":982.36,\"humidity\":35,\"temp_kf\":0},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":63},\"wind\":{\"speed\":2.29,\"deg\":50.335},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-10 12:00:00\"},{\"dt\":1562770800,\"main\":{\"temp\":294.6,\"temp_min\":294.6,\"temp_max\":294.6,\"pressure\":1011.42,\"sea_level\":1011.42,\"grnd_level\":981.73,\"humidity\":37,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":99},\"wind\":{\"speed\":1.43,\"deg\":73.305},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-10 15:00:00\"},{\"dt\":1562781600,\"main\":{\"temp\":292.042,\"temp_min\":292.042,\"temp_max\":292.042,\"pressure\":1011.39,\"sea_level\":1011.39,\"grnd_level\":981.38,\"humidity\":52,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":87},\"wind\":{\"speed\":1.1,\"deg\":174.951},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-10 18:00:00\"},{\"dt\":1562792400,\"main\":{\"temp\":288.5,\"temp_min\":288.5,\"temp_max\":288.5,\"pressure\":1011.96,\"sea_level\":1011.96,\"grnd_level\":981.97,\"humidity\":59,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":95},\"wind\":{\"speed\":0.51,\"deg\":100.113},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2019-07-10 21:00:00\"},{\"dt\":1562803200,\"main\":{\"temp\":285.412},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":77},\"wind\":{\"speed\":1.51,\"deg\":292.055},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2019-07-11 00:00:00\"},{\"dt\":1562814000,\"main\":{\"temp\":286.093},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":81},\"wind\":{\"speed\":1.53,\"deg\":301.446},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-11 03:00:00\"},{\"dt\":1562824800,\"main\":{\"temp\":288.815},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":90},\"wind\":{\"speed\":0.93,\"deg\":321.119},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019 - 07 - 11 06:00:00\"},{\"dt\":1562835600,\"main\":{\"temp\":292.9},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":95},\"wind\":{\"speed\":1.49,\"deg\":82.306},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-11 09:00:00\"},{\"dt\":1562846400,\"main\":{\"temp\":294},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":87},\"wind\":{\"speed\":2.43,\"deg\":159.751},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-11 12:00:00\"},{\"dt\":1562857200,\"main\":{\"temp\":294.1},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":91},\"wind\":{\"speed\":1.76,\"deg\":128.665},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-11 15:00:00\"},{\"dt\":1562868000,\"main\":{\"temp\":291.6},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":84},\"wind\":{\"speed\":3.93,\"deg\":128.557},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-11 18:00:00\"},{\"dt\":1562878800,\"main\":{\"temp\":285.847},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":75},\"wind\":{\"speed\":2.78,\"deg\":102.477},\"rain\":{\"3h\":0.188},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2019-07-11 21:00:00\"}],\"city\":{\"id\":2696650,\"name\":\"Alvik\",\"coord\":{\"lat\":60.7477,\"lon\":14.8746},\"country\":\"SE\",\"population\":5861,\"timezone\":7200}}";
            var    weather = ForecastAPI.GetWorstWeather("Alvik", json, 1).Weather;

            Assert.AreEqual("Clouds", weather);
        }
コード例 #2
0
        public void GetWorstRainyWeather()
        {
            string json    = "{\"cod\":\"200\",\"message\":0.0074,\"cnt\":40,\"list\":[{\"dt\":1562673600,\"main\":{\"temp\":292.25},\"weather\":[{\"id\":600,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":9},\"wind\":{\"speed\":3.53,\"deg\":38.008},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-09 12:00:00\"},{\"dt\":1562695200,\"main\":{\"temp\":290.8},\"weather\":[{\"id\":601,\"main\":\"Clouds\",\"description\":\"scattered clouds\",\"icon\":\"03d\"}],\"clouds\":{\"all\":32},\"wind\":{\"speed\":1.26,\"deg\":25.08},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-09 13:00:00\"},{\"dt\":1562706000,\"main\":{\"temp\":286.032,\"temp_min\":286.032,\"temp_max\":286.032,\"pressure\":1014.25,\"sea_level\":1014.25,\"grnd_level\":983.85,\"humidity\":71,\"temp_kf\":0},\"weather\":[{\"id\":602,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":92},\"wind\":{\"speed\":2.04,\"deg\":351.245},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2019-07-09 14:00:00\"},{\"dt\":1562716800,\"main\":{\"temp\":282.9,\"temp_min\":282.9,\"temp_max\":282.9,\"pressure\":1014.48,\"sea_level\":1014.48,\"grnd_level\":984.05,\"humidity\":81,\"temp_kf\":0},\"weather\":[{\"id\":603,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":79},\"wind\":{\"speed\":2.15,\"deg\":321.144},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2019-07-10 15:00:00\"},{\"dt\":1562727600,\"main\":{\"temp\":283.3,\"temp_min\":283.3,\"temp_max\":283.3,\"pressure\":1014.12,\"sea_level\":1014.12,\"grnd_level\":983.5,\"humidity\":76,\"temp_kf\":0},\"weather\":[{\"id\":604,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":1.79,\"deg\":294.001},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-10 16:00:00\"},{\"dt\":1562749200,\"main\":{\"temp\":293,\"temp_min\":293,\"temp_max\":293,\"pressure\":1012.91,\"sea_level\":1012.91,\"grnd_level\":982.98,\"humidity\":43,\"temp_kf\":0},\"weather\":[{\"id\":605,\"main\":\"Clouds\",\"description\":\"scattered clouds\",\"icon\":\"03d\"}],\"clouds\":{\"all\":38},\"wind\":{\"speed\":2.79,\"deg\":42.715},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-11 17:00:00\"},{\"dt\":1562760000,\"main\":{\"temp\":295.2,\"temp_min\":295.2,\"temp_max\":295.2,\"pressure\":1012.05,\"sea_level\":1012.05,\"grnd_level\":982.36,\"humidity\":35,\"temp_kf\":0},\"weather\":[{\"id\":607,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":63},\"wind\":{\"speed\":2.29,\"deg\":50.335},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2019-07-11 19:00:00\"},{\"dt\":1562878800,\"main\":{\"temp\":285.847},\"weather\":[{\"id\":608,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":75},\"wind\":{\"speed\":2.78,\"deg\":102.477},\"rain\":{\"3h\":0.188},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2019-07-11 20:00:00\"}],\"city\":{\"id\":2696650,\"name\":\"Alvik\",\"coord\":{\"lat\":60.7477,\"lon\":14.8746},\"country\":\"SE\",\"population\":5861,\"timezone\":7200}}";
            var    weather = ForecastAPI.GetWorstWeather("Alvik", json, 1).Weather;

            Assert.AreEqual("Rain", weather);
        }
コード例 #3
0
        /// <summary>
        /// Uses WebClient to get the right URL to Open Weather Map and uses the Locate method to get the latitude and longitude from Google
        /// maps API, if the destination can't be found in Open Weather Maps API we uses the coordinate from googlemaps API and uses them in Open Weather Maps API to get the worst posible weather for a timeframe.
        /// we have choosen by the daysrange slider in the frontend, at least 8 times. We return the first worst weather we find in the selected timeframe.
        /// </summary>
        /// <param name="destination"></param>
        /// <returns></returns>
        public JsonResult GetWorstWeatherForecast(string Destination, string DaysRange)
        {
            Geolocation geolocation = new Geolocation();

            geolocation = MapFunctions.Locate(Destination);
            string json      = "";
            int    daysrange = int.Parse(DaysRange);

            using (WebClient web = new WebClient())
            {
                try
                {
                    var query = "http://api.openweathermap.org/data/2.5/forecast?lat=" + geolocation.Latitude + "&lon=" + geolocation.Longitude + "&appid=" + APIKEY;
                    json = web.DownloadString(query);
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                }
            }

            return(Json(ForecastAPI.GetWorstWeather(Destination, json, daysrange), JsonRequestBehavior.AllowGet));
        }