public void CodesTest() { WeatherCodes.Init(); var icon = WeatherCodes.Instance.GetWeatherIcon(800); Assert.AreEqual("http://openweathermap.org/img/w/01d.png", icon); }
public Startup(IConfiguration configuration) { Configuration = configuration; using (var client = new NewsContext()) { client.Database.EnsureDeleted(); client.Database.EnsureCreated(); NewsController.SeedTheCategories(); // NewsController.SeedTheAuthors(); } WeatherCodes.Init(); //Initializing the weathercodes dictionary. }
private Forecast CalculateDailyForecast(IGrouping <DateTime, Forecast> grp) { double temperature = 0; string description = null; string icon = null; WeatherCodes code = default(WeatherCodes); DateTime forecastDate = default(DateTime); temperature = grp.Average(g => g.Temperature); description = grp.First().WeatherDescription; icon = grp.First().WeatherIconUrl; code = grp.First().WeatherCode; forecastDate = grp.Key.Date; var forecast = new Forecast(grp.First().Location, temperature, description, icon, code, forecastDate); return(forecast); }
public TodaysForecast(Location location, double temperature, string weatherDescription, string weatherIconUrl, WeatherCodes code, DateTime forecastDate, int humidity, int pressure, int windSpeed, DateTime sunrise, DateTime sunset) : base(location, temperature, weatherDescription, weatherIconUrl, code, forecastDate) { this.Humidity = humidity; this.Pressure = pressure; this.Sunrise = sunrise; this.Sunset = sunset; this.WindSpeed = windSpeed; }
public async Task <IEnumerable <Condition> > GetConditionsAffectedByWeatherAsync(WeatherCodes weather, double temperature) { List <Condition> conditions = new List <Condition>(); string mappedWeatherCondition = ""; if (temperature < 278.15) { // < 5 degrees we will class as cold. mappedWeatherCondition = "cold"; } else { //Map weather codes to well-known weather conditions in our API - consider that the API may not know about as in-depth weather as the client.. switch (weather) { case WeatherCodes.snow: case WeatherCodes.shower_rain: case WeatherCodes.light_rain: mappedWeatherCondition = "cold"; break; default: mappedWeatherCondition = ""; break; } } if (string.IsNullOrEmpty(mappedWeatherCondition)) { return(Enumerable.Empty <Condition>()); } HttpClient client = new HttpClient(); client.BaseAddress = new Uri(this.baseAddress); var response = await client.PostAsync($"/conditions/triggered-by/weather/{mappedWeatherCondition}?temperature={temperature}", new StringContent("")); if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { return(Enumerable.Empty <Condition>()); } response.EnsureSuccessStatusCode(); var json = await response.Content.ReadAsStringAsync(); //[{"Condition":"Common Cold","Suggestions":["Reduce phsyical activity"]},{"Condition":"Rhinorrhea","Suggestions":["Consider taking decongestants"]},{"Condition":"Asthma","Suggestions":["Increase dosage","Reduce phsyical activity"]}] JArray result = JsonConvert.DeserializeObject <JArray>(json); foreach (var condition in result) { conditions.Add(new Condition(condition.Value <string>("Condition"), condition.Value <string>("Id"))); } return(conditions); }
public Forecast(Location location, double temperature, string weatherDescription, string weatherIconUrl, WeatherCodes code, DateTime forecastDate) { this.WeatherIconUrl = weatherIconUrl; this.WeatherCode = code; this.WeatherDescription = weatherDescription; this.Temperature = temperature; this.ForecastDate = forecastDate; this.Location = location; }