private static async Task Test() { ForeCast foreCast = await ForecastService.ForecastRunAsync(); ShowProduct(foreCast); Console.ReadLine(); }
public List <ForeCast> GetForecast(string ParkCode) { List <ForeCast> fiveDayForeCast = new List <ForeCast>(); try { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand(SQL_GetForecast, connection); cmd.Parameters.AddWithValue("@ParkCode", ParkCode); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { ForeCast f = new ForeCast(); f.FiveDayForecastValue = Convert.ToInt32(reader["fiveDayForecastValue"]); f.Low = Convert.ToInt32(reader["low"]); f.High = Convert.ToInt32(reader["high"]); f.Forecast = Convert.ToString(reader["forecast"]); fiveDayForeCast.Add(f); } } return(fiveDayForeCast); } catch (SqlException) { throw; } }
private async Task GetForecast() { ForeCast foreCast = await ForecastService.ForecastRunAsync().ConfigureAwait(false); var WeatherText = new WeatherText(foreCast); ShowProduct(foreCast); }
private static void ShowProduct(ForeCast product) { Console.WriteLine($"Approved Time: {product.approvedTime}"); Console.WriteLine($"Reference Time: {product.referenceTime}"); Console.WriteLine($"Long: {product.geometry.coordinates[0][0]}"); Console.WriteLine($"Lat: {product.geometry.coordinates[0][1]}"); ShowAllParameters(product); }
public WeatherText(ForeCast forecast) { morning = TimeSpan.Parse("06:00"); day = TimeSpan.Parse("12:00"); evening = TimeSpan.Parse("18:00"); todaysWeather = forecast.timeSeries.Where(ts => Convert.ToDateTime(ts.validTime).Date.Equals(DateTime.Today)).ToList(); tomorrowsWeather = forecast.timeSeries.Where(ts => Convert.ToDateTime(ts.validTime).Date.Equals(DateTime.Today.AddDays(1))).ToList(); }
private static async Task <ForeCast> GetProductAsync(string path) { ForeCast product = null; HttpResponseMessage response = await client.GetAsync(path).ConfigureAwait(false); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); product = JsonConvert.DeserializeObject <ForeCast>(content); } return(product); }
/* public void GridViewPresentation() * { * GridLayout layout = FindViewById<GridLayout>(Resource.Id.gridLayout1); * * //Img * ImageView imgView = new ImageView(this); * GridLayout.LayoutParams param = new GridLayout.LayoutParams(); * param.Height = GridLayout.LayoutParams.WrapContent; * param.Width = GridLayout.LayoutParams.WrapContent; * param.SetMargins(5, 5, 5, 5); * param.SetGravity(Android.Views.GravityFlags.Center); * * //param.ColumnSpec = GridLayout.Spec; * //param.rowSpec = GridLayout.spec(r);; * imgView.LayoutParameters = param; * layout.AddView(imgView); * * //Time * TextView timeTextView = new TextView(this); * timeTextView.Text = "Test"; * GridLayout.LayoutParams param1 = new GridLayout.LayoutParams(); * param1.Height = GridLayout.LayoutParams.WrapContent; * param1.Width = GridLayout.LayoutParams.WrapContent; * param1.SetMargins(5, 5, 5, 5); * param1.SetGravity(Android.Views.GravityFlags.Center); * * timeTextView.LayoutParameters = param1; * layout.AddView(timeTextView); * * //Temp * * * //Wind * * * //precipitation * * * //Text * }*/ private void ShowProduct(ForeCast product) { //label1.Text = ($"Approved Time: {product.approvedTime}"); //label2.Text = ($"Reference Time: {product.referenceTime}"); //label3.Text = ($"Long: {product.geometry.coordinates[0][0]}"); //label4.Text = ($"Lat: {product.geometry.coordinates[0][1]}"); TableLayout tableLayout = FindViewById <TableLayout>(Resource.Id.tableLayout1); foreach (var timeSerie in product.timeSeries) { DateTime parsedTime = Convert.ToDateTime(timeSerie.validTime); TimeSpan start = TimeSpan.Parse("12:00"); if (parsedTime.TimeOfDay == start) { TableRow tableRow = new TableRow(this); var culture = new System.Globalization.CultureInfo("sv-SE"); var day = culture.DateTimeFormat.GetDayName(parsedTime.DayOfWeek).ToUpperInvariant(); // 23 Sat Saturday AddTextView($"{day}", TextView.BufferType.Normal, tableRow); //AddTextView($"Count: {timeSerie.parameters.Count}", TextView.BufferType.Normal, tableRow); ForecastParameters parameters = new ForecastParameters(timeSerie); var AirTemperature = timeSerie.parameters.FirstOrDefault(x => x.name == "t").values[0]; TextView AirTemperatureTv = new TextView(this); AddTextView($"{parameters.AirTemperature} C°", TextView.BufferType.Normal, tableRow); AddTextView($"{WeatherSymbol.WeatherSymbolDictionary[parameters.WeatherSymbol]}", TextView.BufferType.Normal, tableRow); AddTextView($"{parameters.MinimumPrecipitationIntensity} - {parameters.MaximumPrecipitationIntensity} mm", TextView.BufferType.Normal, tableRow); //AddTextView($"{parameters.WindDirection}", TextView.BufferType.Normal, tableRow); AddTextView($"{parameters.WindSpeed} m/s", TextView.BufferType.Normal, tableRow); AddTextView($"{parameters.WindGustSpeed}", TextView.BufferType.Normal, tableRow); //AddTextView($"{ PrecipitationCategory.PrecipitationCategoryDictionary[parameters.PrecipitationCategory]}", TextView.BufferType.Normal, tableRow); //label4.Text = ($"AirPressure: {parameters.AirPressure}"); // Console.WriteLine($"PrecipitationCategory: {PrecipitationCategory.PrecipitationCategoryDictionary[parameters.PrecipitationCategory]}"); //Console.WriteLine($"HorizontalVisibility: {parameters.HorizontalVisibility}"); //Console.WriteLine($"MeanValueOfHighLevelCloudCover: {parameters.MeanValueOfHighLevelCloudCover}"); //Console.WriteLine($"MeanValueOfLowLevelCloudCover: {parameters.MeanValueOfLowLevelCloudCover}"); //Console.WriteLine($"PercentOfPrecipitationInFrozenForm: {parameters.PercentOfPrecipitationInFrozenForm}"); //label1.Text = ($"RelativeHumidity: {parameters.RelativeHumidity}"); //Console.WriteLine($"ThunderProbability: {parameters.ThunderProbability}"); tableLayout.AddView(tableRow); } } }
public static async Task <ForeCast> ForecastRunAsync() { client.BaseAddress = new Uri("https://opendata-download-metfcst.smhi.se"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { // Get the product ForeCast product = await GetProductAsync("/api/category/pmp3g/version/2/geotype/point/lon/16/lat/58/data.json").ConfigureAwait(false); return(product); } catch (Exception e) { //Console.WriteLine(e.Message); } return(null); }
private static void ShowAllParameters(ForeCast product) { foreach (var timeSerie in product.timeSeries) { Console.WriteLine(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"validTime: {timeSerie.validTime}"); Console.WriteLine($"validTime: {timeSerie.parameters.Count}"); Console.ForegroundColor = ConsoleColor.White; ForecastParameters parameters = new ForecastParameters(timeSerie); var AirTemperature = timeSerie.parameters.FirstOrDefault(x => x.name == "t").values[0]; Console.WriteLine($"AirTemperature: {parameters.AirTemperature}"); Console.WriteLine($"AirPressure: {parameters.AirPressure}"); // Console.WriteLine($"PrecipitationCategory: {PrecipitationCategory.PrecipitationCategoryDictionary[parameters.PrecipitationCategory]}"); //Console.WriteLine($"HorizontalVisibility: {parameters.HorizontalVisibility}"); //Console.WriteLine($"MeanValueOfHighLevelCloudCover: {parameters.MeanValueOfHighLevelCloudCover}"); //Console.WriteLine($"MeanValueOfLowLevelCloudCover: {parameters.MeanValueOfLowLevelCloudCover}"); Console.WriteLine($"PercentOfPrecipitationInFrozenForm: {parameters.PercentOfPrecipitationInFrozenForm}"); Console.WriteLine($"RelativeHumidity: {parameters.RelativeHumidity}"); Console.WriteLine($"ThunderProbability: {parameters.ThunderProbability}"); Console.WriteLine($"WindDirection: {parameters.WindDirection}"); Console.WriteLine($"WindSpeed: {parameters.WindSpeed}"); Console.WriteLine($"WindGustSpeed: {parameters.WindGustSpeed}"); Console.WriteLine($"WeatherSymbol: {WeatherSymbol.WeatherSymbolDictionary[parameters.WeatherSymbol]}"); //foreach (var p in timeSerie.parameters) //{ // Console.WriteLine($"name: {p.name}"); // //Console.WriteLine($"level: {p.level}"); // //Console.WriteLine($"leveltype: {p.levelType}"); // //foreach (var v in p.values) // //{ // // Console.WriteLine($"values: {v.ToString()}"); // //} //} } }
private static void TestInfo(ForeCast product) { foreach (var timeSerie in product.timeSeries) { Console.WriteLine($"validTime: {timeSerie.validTime}"); Console.WriteLine($"validTime: {timeSerie.parameters.Count}"); //foreach (var p in timeSerie.parameters) //{ // Console.WriteLine($"name: {p.name}"); // Console.WriteLine($"level: {p.level}"); // Console.WriteLine($"leveltype: {p.levelType}"); // foreach (var v in p.values) // { // Console.WriteLine($"values: {v.ToString()}"); // } //} } }
public void GetWeatherTextToday(ForeCast forecast) { }