private async Task <string> RecommendTripDateBasedOnWeather(Destination destination)
        {
            string         recommendation;
            string         url            = ConvertAddressToWeatherUrl(destination.Address);
            WeatherHistory weatherHistory = await _weatherRequest.GetHistoricalWeather(url);

            List <int> positiveScores = new List <int>();

            foreach (var item in weatherHistory.data.weather)
            {
                if (double.Parse(item.mintempF) > 50 && double.Parse(item.maxtempF) < 90)
                {
                    positiveScores.Add(int.Parse(item.maxtempF));
                }
                else
                {
                    continue;
                }
            }
            if (positiveScores.Count > 500)
            {
                recommendation = "Go during their summer months";
            }
            else
            {
                recommendation = "The weather is too hard to determine right now. We need more time to recommend.";
            }

            return(recommendation);
        }
        public async Task GetWeatherFromFavoritesList()
        {
            var list = await favoriteRepository.GetAll();

            foreach (var item in list)
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?q=" + item.CityName + "&units=metric"
                                                                           + openWatherMapsApiKey);

                var    webResponse = (HttpWebResponse)request.GetResponse();
                var    reader      = new StreamReader(webResponse.GetResponseStream() ?? throw new InvalidOperationException());
                string s           = reader.ReadToEnd();
                var    json        = JsonConvert.DeserializeObject <WeatherJson>(s);
                var    weather     = Mapper.Map <WeatherJson, Weather>(json);
                weather.WindChill = Math.Round(33 + (0.478 + 0.237 * Math.Sqrt(weather.WindSpeed) - 0.0124 * weather.WindSpeed)
                                               * (weather.Temperature - 33)) * 100 / 100;
                foreach (var user in item.Id)
                {
                    WeatherHistory weatherHistory = Mapper.Map <Weather, WeatherHistory>(weather);
                    weatherHistory.Id   = user;
                    weatherHistory.Date = DateTime.Now;
                    await weatherHistoryRepository.Add(weatherHistory);

                    await weatherHistoryRepository.Save();
                }
            }
        }
Exemple #3
0
        public static WeatherHistory GetHistoryItemFromApiResponse(ObservationResponseObservation history)
        {
            if (history == null)
            {
                return(null);
            }
            var historyElement = new WeatherHistory
            {
                Date = ((DateTimeOffset)history.Date).UtcDateTime,
                PrecipitationAmount  = (double)history.Precipitation.Amount,
                PrecipitationUnits   = history.Precipitation.Units,
                RelativeHumidityMax  = (double)history.RelativeHumidity.Max,
                RelativeHumidityMin  = (double)history.RelativeHumidity.Min,
                SolarRadiationAmount = (double)history.Solar.Amount,
                SolarRadiationUnits  = history.Solar.Units,
                TemperatureMax       = (double)history.Temperatures.Max,
                TemperatureMin       = (double)history.Temperatures.Min,
                TemperatureUnits     = history.Temperatures.Units,
                WindAverage          = (double)history.Wind.Average,
                WindUnits            = history.Wind.Units,
                WindDayMax           = (double)history.Wind.DayMax,
                WindMorningMax       = (double)history.Wind.MorningMax
            };

            return(historyElement);
        }
Exemple #4
0
        public async Task AddHistory(Weather model)
        {
            WeatherHistory weatherHistory = Mapper.Map <Weather, WeatherHistory>(model);

            weatherHistory.Date = DateTime.Now;
            weatherHistory.Id   = authRepository.GetUserId();
            await weatherHistoryRepository.Add(weatherHistory);
        }
Exemple #5
0
        /// <summary>
        /// Executes the specified option.
        /// </summary>
        /// <param name="idExecution">The option.</param>
        public void Execute(int idExecution)
        {
            var planets          = PlanetStorage.GetByCriteria(p => p.Galaxy.Id == GalaxyService.DefaultGalaxyId());
            var predictionResult = GalaxyService.PredictWeather(planets, day: idExecution);
            var weatherHistory   = new WeatherHistory {
                Day = idExecution, Weather = predictionResult.WeatherCondition, TrianglePerimeter = predictionResult.TrianglePerimeter
            };

            WeatherHistoryStorage.Save(weatherHistory);
        }
Exemple #6
0
        public async Task <int> SaveItemAsync(WeatherHistory item)
        {
            await Database.InsertAsync(item);

            string sql        = @"select last_insert_rowid()";
            var    insertedId = await Database.ExecuteScalarAsync <long>(sql);

            item.Id = (int)insertedId;
            _internalSourceCache.AddOrUpdate(item);
            return(item.Id);
        }
Exemple #7
0
        public async Task <WeatherHistory> GetHistoricalWeather(string url)
        {
            using HttpClient client = new HttpClient();
            {
                HttpResponseMessage response = await client.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    string json = await response.Content.ReadAsStringAsync();

                    WeatherHistory history = JsonConvert.DeserializeObject <WeatherHistory>(json);
                    return(history);
                }
            }
            return(null);
        }
Exemple #8
0
 public HistoryCellViewModel(WeatherHistory weather)
 {
     Weather = weather;
 }
Exemple #9
0
 public Task <int> DeleteItemAsync(WeatherHistory item)
 {
     return(Database.DeleteAsync(item));
 }
Exemple #10
0
 public WeatherSearchByDateAndCity()
 {
     InitializeComponent();
     CityWeatherHistory = new WeatherHistory();
     BindingContext     = CityWeatherHistory;
 }
Exemple #11
0
 public async Task Add(WeatherHistory model)
 {
     _context.WeatherHistory.Add(model);
     await Save();
 }