public PrecipitationCondition GetPrecipitation(CurrentForecast forecast) { PrecipitationCondition precipitation = PrecipitationCondition.None; if (forecast.HasPrecipitation) { if (forecast.PrecipitationType == "Rain") { precipitation = PrecipitationCondition.Rain; } else if (forecast.PrecipitationType == "Snow") { precipitation = PrecipitationCondition.Snow; } else if (forecast.PrecipitationType == "Ice") { precipitation = PrecipitationCondition.Ice; } else if (forecast.PrecipitationType == "Mixed") { precipitation = PrecipitationCondition.Mixed; } } return(precipitation); }
// ILocationUpdate Handler methods public async void OnLocationChanged(Location newLocation) { CurrentForecast forecast = await Interactor.GetCurrentForecast(newLocation.Latitude, newLocation.Longitude); View.RenderWeatherSummary(forecast.icon, forecast.temperature, forecast.summary); View.RenderLocationName(newLocation.CityName, newLocation.SubLocalityName); View.StopLoadingIndicator(); View.HideLabels(false); }
public Others GetOthers(CurrentForecast forecast) { Others others; if (forecast.RealFeelTemperature.Metric.Value >= 15 && forecast.HasPrecipitation == false && forecast.HasSnow == false && forecast.Wind.Speed.Value <= 10 && forecast.IsDayTime == true) { others = Others.ADayAtThePark; } else if (forecast.RealFeelTemperature.Metric.Value >= 10 && forecast.HasPrecipitation == false && forecast.Visibility.Metric.Value > 40 && forecast.Wind.Speed.Value <= 20) { others = Others.GoodForWalking; } else if (forecast.Temperature.Metric.Value >= -3 && 3 <= forecast.Temperature.Metric.Value && forecast.Wind.Speed.Value >= 20 && forecast.HasPrecipitation == true && forecast.Visibility.Metric.Value < 30) { others = Others.PoorDrivingConditions; } else if (forecast.Temperature.Metric.Value <= -10 || forecast.HasPrecipitation == true) { others = Others.PreferableToDrive; } else if (forecast.Temperature.Metric.Value >= -6 && 6 <= forecast.Temperature.Metric.Value && forecast.HasSnow == true) { others = Others.GoodForSki; } else if (forecast.Temperature.Metric.Value >= -3 && 3 <= forecast.Temperature.Metric.Value || forecast.HasPrecipitation == true) { others = Others.SlipperyForDriving; } else if (forecast.Temperature.Metric.Value < -10 && forecast.HasSnow == true && forecast.Visibility.Metric.Value < 20 && forecast.Wind.Speed.Value > 40) { others = Others.PoorWeatherConditions; } else { others = Others.IgnoreThis; } return(others); }
public Probabilities GetProbabilities(CurrentForecast forecast) { Probabilities probabilities; if (forecast.HasPrecipitation) { probabilities = Probabilities.Rain; } else { probabilities = Probabilities.NotEvaluated; } return(probabilities); }
static async Task <CurrentForecast> GetCurrentAsync(string path) { CurrentForecast product = null; HttpResponseMessage response = await client.GetAsync(path); if (response.IsSuccessStatusCode) { // OTKOMENTARISATI KADA SE NAPRAVI KLASA CurrentForecast // product = await response.Content.ReadAsAsync<CurrentForecast>(); string yeet = await response.Content.ReadAsStringAsync(); product = JsonConvert.DeserializeObject <CurrentForecast>(yeet); } return(product); }
/// <summary> /// Gets api response for current weather forecast and converts it into JSON object /// </summary> private async Task GetCurrentForecast(string cityName) { // get response from API for current weather forecast string uri = "https://api.openweathermap.org/data/2.5/weather?q=" + cityName + "&units=metric&appid=" + Credentials.OpenWeatherMapApiKey; try { _currentApiResponse = await _httpClient.GetStringAsync(uri); _currentForecast = JsonConvert.DeserializeObject <CurrentForecast>(_currentApiResponse); } catch (HttpRequestException e) { await new MessageDialog(e.Message).ShowAsync(); } }
public WeatherCondition GetWeatherCondition(CurrentForecast forecast) { WeatherCondition weather; if (forecast.HasPrecipitation) { weather = WeatherCondition.Rain; } else { weather = WeatherCondition.None; } if (forecast.HasSnow) { weather = WeatherCondition.Snow; } else { weather = WeatherCondition.NoSnow; } if (forecast.Temperature.Metric.Value < -10) { weather = WeatherCondition.Freezing; } if (forecast.Temperature.Metric.Value >= -10 && 8 >= forecast.Temperature.Metric.Value) { weather = WeatherCondition.Cold; } else if (forecast.Temperature.Metric.Value > 8 && 14 > forecast.Temperature.Metric.Value) { weather = WeatherCondition.Cool; } else { weather = WeatherCondition.Warm; } return(weather); }
public async void OnUserRefresh() { Location currentLocation = LocationInteractor.GetCurrentLocation(); /* * Is this the best way to check, or would an async getter be better? * Currently, bailing here achieves the same result, as the UI is updated * by the ILocationUpdateHandler. But I'm not quite sure if bailing * here is antipattern or not. */ if (currentLocation == null) { return; } CurrentForecast forecast = await Interactor.GetCurrentForecast(currentLocation.Latitude, currentLocation.Longitude); View.RenderWeatherSummary(forecast.icon, forecast.temperature, forecast.summary); View.StopLoadingIndicator(); }
public WindCondition GetWindCondition(CurrentForecast forecast) { WindCondition windCondition; if (forecast.Wind.Speed.Value >= 20) { windCondition = WindCondition.StrongWinds; } else { if (forecast.Wind.Speed.Value >= 10 && 24 >= forecast.Wind.Speed.Value) { windCondition = WindCondition.LightWinds; } else { windCondition = WindCondition.Calm; } } return(windCondition); }