private void addToTable(string cityName) { try { LocationForecast lf = forecast.getLocationForecast(cityName); if (table != null) { table.initializeTableRows(); table.fillListBox(); } customNotifier.notifier.ShowSuccess($"The city {StringHandler.capitalize(lf.Name)} was added to the table!"); } catch { if (cityName == "") { customNotifier.notifier.ShowWarning("You did not enter a city name!"); } else { customNotifier.notifier.ShowWarning($"City '{StringHandler.capitalize(cityName)}' does not exist!"); } } searchText.Clear(); }
public LocationForecast Get() { var rng = new Random(); LocationForecast location = new LocationForecast(rng.Next(-85, 85), rng.Next(-180, 180)); return(location); }
public LocationForecast GetForecast(string location) { Stopwatch sw = Stopwatch.StartNew(); LocationForecast forecast = _innerWeatherService.GetForecast(location); sw.Stop(); long elapsedMillis = sw.ElapsedMilliseconds; _logger.LogWarning($"Retrieved weather data for {location} - Elapsed ms: {elapsedMillis} {forecast}"); return(forecast); }
private void addLocationDailyWeatherToForecast(LocationForecast lf, int forecastNum) { int cnt = 0; foreach (LocationDailyWeather ldw in lf.ForecastDict.Values) { LocationDaylyForecasts.Add(ldw); if (++cnt == forecastNum) { break; } } }
public LocationForecast getLocationForecast(string cityName) { JSONForecast jsonObject = JSONtoJSONObject(cityName); LocationForecast lf = new LocationForecast(); lf.Name = StringHandler.toUTFString(jsonObject.city.name); foreach (var lo in jsonObject.list) { lf.ForecastDict.Add(UnixToDatetime.UnixTimeStampToDateTime(lo.dt), getSingle(lf.Name, lo)); } return(lf); }
private LocationForecast MapForecastResponse(ForecastResponse openWeatherApiResponse) { var locationForecast = new LocationForecast() { Success = true, ErrorMessage = String.Empty, Location = new ForecastLocation() { Name = openWeatherApiResponse.Location.Name, Latitude = openWeatherApiResponse.Location.Coordinates.Latitude, Longitude = openWeatherApiResponse.Location.Coordinates.Longitude }, FetchTime = DateTime.Now }; foreach (var openWeatherForecast in openWeatherApiResponse.ForecastPoints) { WeatherForecast forecast = new() { Conditions = openWeatherForecast.Conditions.FirstOrDefault()?.main, ConditionsDescription = openWeatherForecast.Conditions.FirstOrDefault()?.description, Temperature = openWeatherForecast.WeatherData.Temperature, Humidity = openWeatherForecast.WeatherData.Humidity, Pressure = openWeatherForecast.WeatherData.pressure * 0.0295301, // Pressure always comes back in millibars, even when imperial requested, ForecastTime = DateTimeOffset.FromUnixTimeSeconds(openWeatherForecast.Date + openWeatherApiResponse.Location.TimezoneOffset).DateTime, CloudCover = openWeatherForecast.Clouds.CloudCover, WindSpeed = openWeatherForecast.Wind.WindSpeed, WindDirectionDegrees = openWeatherForecast.Wind.WindDirectionDegrees, WindDirection = CompassDirection.GetDirection(openWeatherForecast.Wind.WindDirectionDegrees), ExpectedRainfall = (openWeatherForecast.Rain?.RainfallThreeHours ?? 0.0) * 0.03937008, ExpectedSnowfall = (openWeatherForecast.Snow?.SnowfallThreeHours ?? 0.0) * 0.03937008 }; locationForecast.Forecasts.Add(forecast); } return(locationForecast); }
private KeyValuePair <string, double>[] getReducedKeyValuePairs(LocationForecast locationForecast, string graphData) { int maxNum = geMaxNum(); int interval = getInterval(); List <KeyValuePair <string, double> > retVal = new List <KeyValuePair <string, double> >(); int cnt = 0; int addedNumber = 0; foreach (var pair in locationForecast.ForecastDict) { if (cnt++ % interval == 0) { retVal.Add(new KeyValuePair <string, double>(pair.Key.ToString("ddd dd/MM h tt"), getAttributeValueByName(graphData, pair.Value))); addedNumber++; } if (addedNumber == maxNum - 1) { break; } } return(retVal.ToArray()); }
public IActionResult Forecast(string location = "Chicago") { LocationForecast forecast = _weatherService.GetForecast(location); return(View(forecast)); }
private KeyValuePair <string, double>[] getAllKeyValuePairs(LocationForecast locationForecast, string graphData) { return(locationForecast.ForecastDict .Select(pair => new KeyValuePair <string, double>(pair.Key.ToString("ddd dd/MM h tt"), getAttributeValueByName(graphData, pair.Value))) .ToArray()); }