static void Main(string[] args) { FileReader fileReader = new FileReader(); Meteorologist meteorologist = new Meteorologist(); WeatherResults weatherResults = new WeatherResults(); ApiReader apiReader = new ApiReader(); //Console.WriteLine("Hello! Please write the file where your temperature data is stored and separator in the file seperated with a ','."); //string input = Console.ReadLine(); //string[] userInput = input.Split(','); //List<TemperatureData> temperatureList = fileReader.CSVReader(userInput[0], Convert.ToChar(userInput[1])); //weatherResults.WarmestDataEntry = meteorologist.GetWarmestTemperature(temperatureList); //weatherResults.FirstSubZeroEntry = meteorologist.GetFirstBelowZero(temperatureList); //weatherResults.MeanValues = meteorologist.GetMeanTemperature(temperatureList); //weatherResults.ColdestDataEntry = meteorologist.GetColdestTemperature(temperatureList); //Console.WriteLine(weatherResults.GetWeatherResult(temperatureList[0].TimeStamp, temperatureList[temperatureList.Count() - 1].TimeStamp)); var apiString = $"https://opendata-download-metobs.smhi.se/api/version/latest/parameter/1.json"; var response = apiReader.GetAsyncFromApi(apiString); var simpleStationList = fileReader.ReadAirTempRespons(response).GetAwaiter().GetResult(); string stationJsonArray = JsonConvert.SerializeObject(simpleStationList); System.IO.File.WriteAllText(@"C:\Users\li.wirstrom\Documents\Code is King\FFCG.CodeIsKing\Meteorologist\src\stations.json", stationJsonArray); }
protected async override Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { try { for (int i = 0; i < _cities.Length; i++) { _weatherTasks[i] = GetWeatherAsync(_cities[i]); } var responseContainer = new WeatherResults { Weathers = new OpenWeather[_cities.Length] }; await Task.WhenAll(_weatherTasks); for (int i = 0; i < _weatherTasks.Length; i++) { responseContainer.Weathers[i] = _weatherTasks[i].Result; } _cache.Set(Constants.LATEST_FORECAST_CACHE_KEY, responseContainer); await Task.Delay(TimeSpan.FromMinutes(5)); } catch (Exception ex) { _logger.LogError($"Unexpected error fetching weather data: {ex.Data}"); } } }
private async void CoordinateButton_Clicked(object sender, EventArgs e) { // Checks if there is an entry and then displays weather information if (!String.IsNullOrEmpty(LatitudeEntry.Text) && !String.IsNullOrEmpty(LongitudeEntry.Text)) { Weather weather = await WeatherResults.GetCoordinatesWeather(LatitudeEntry.Text, LongitudeEntry.Text); // Binds weather results to the page BindingContext = weather; GetWeatherButton.Text = "Enter Coordinates"; } }
private async void GetWeatherButton_Clicked(object sender, EventArgs e) { // Checks if there is an entry and displays using either zip or city if (!String.IsNullOrEmpty(ZipOrCity.Text)) { Weather weather = await WeatherResults.GetWeather(ZipOrCity.Text); // Binds weather results to the page BindingContext = weather; GetWeatherButton.Text = "Enter Zip or City"; } }
public static WeatherResults FormatWeather(RawWeather rw) { var weatherResults = new WeatherResults { Sunrise = DateTime.UnixEpoch.AddSeconds(rw.current.sunrise).ToShortTimeString(), Sunset = DateTime.UnixEpoch.AddSeconds(rw.current.sunset).ToShortTimeString(), Temperature = Math.Round(rw.current.temp - 273.15), RealFeel = Math.Round(rw.current.feels_like - 273.15), Humidity = rw.current.humidity, UvIndex = rw.current.uvi, WindSpeed = rw.current.wind_speed }; return(weatherResults); }
private async void CoordinateButton_Clicked(object sender, EventArgs e) { if (!String.IsNullOrEmpty(LatitudeEntry.Text) && !String.IsNullOrEmpty(LongitudeEntry.Text)) { ObservableCollection <Forecast> forecast = new ObservableCollection <Forecast>(); forecast = await WeatherResults.GetCoordinateForecast(LatitudeEntry.Text, LongitudeEntry.Text); // Binds data to page BindingContext = forecast.First(); CoordinateButton.Text = "Coordinates"; // Displays forecast collection ListViewItem.ItemsSource = forecast; } }
private async void GetForecastButton_Clicked(object sender, EventArgs e) { if (!String.IsNullOrEmpty(ZipOrCity.Text)) { ObservableCollection <Forecast> forecast = new ObservableCollection <Forecast>(); forecast = await WeatherResults.GetForecast(ZipOrCity.Text); // Binds data to page BindingContext = forecast.First(); GetWeatherButton.Text = "Enter Zip or City"; //Displys forecast collection ListViewItem.ItemsSource = forecast; } }
private void ListCityResult_SelectionChanged(object sender, SelectionChangedEventArgs e) { var crListView = sender as ListView; UserSelectedCityResult = crListView.SelectedItem as CityResult; crListView.Visibility = Visibility.Collapsed; var cityKey = UserSelectedCityResult.ID; var w = wd.GetWeatherFor5Days(cityKey); foreach (var res in w) { WeatherResults.Add(res); } var wListView = sender as ListView; Weather = wListView.SelectedItem as WeatherResult; ListWeatherResult.Visibility = Visibility.Visible; }