private void RunTestInt32(CsPrng csprng, Action <CsPrng, Int32[]> core, out double average, out TimeSpan timeSpan) { var output = new Int32[Iterations]; var sw = new Stopwatch(); sw.Start(); core(csprng, output); sw.Stop(); timeSpan = sw.Elapsed; average = output.Average(); }
private async void GetWeather() { ColorSnow.Color = Color.FromArgb(255, 255, 255, 255); ColorRain.Color = Color.FromArgb(255, 16, 155, 251); Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.f") + " - Request Weather Data..."); WebRequest W_wrGETURL = WebRequest.Create("http://api.wunderground.com/api/877361112ea5ac9f/geolookup/conditions/hourly/q/Switzerland/Winterthur.json"); WebResponse W_response = await W_wrGETURL.GetResponseAsync(); Stream W_dataStream = W_response.GetResponseStream(); StreamReader W_reader = new StreamReader(W_dataStream); string W_sResponse = W_reader.ReadToEnd(); Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.f") + " - ...Data received"); Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.f") + " - Loading Weather Data Stream"); WeatherRootObject WeatherObj = JsonConvert.DeserializeObject <WeatherRootObject>(W_sResponse); Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.f") + " - Parsing Weather Data Stream"); Double[] temp_raw = new Double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Double[] rain_raw = new Double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Double vAvg, vScale; Label_Time1.Text = WeatherObj.hourly_forecast[3].FCTTIME.hour_padded + ":00"; Label_Time2.Text = WeatherObj.hourly_forecast[6].FCTTIME.hour_padded + ":00"; Label_Time3.Text = WeatherObj.hourly_forecast[9].FCTTIME.hour_padded + ":00"; Label_Time4.Text = WeatherObj.hourly_forecast[12].FCTTIME.hour_padded + ":00"; Label_Time5.Text = WeatherObj.hourly_forecast[15].FCTTIME.hour_padded + ":00"; Label_Time6.Text = WeatherObj.hourly_forecast[18].FCTTIME.hour_padded + ":00"; Label_Temp1.Text = String.Format("{0:N0}°C", WeatherObj.hourly_forecast[3].temp.metric); Label_Temp2.Text = String.Format("{0:N0}°C", WeatherObj.hourly_forecast[6].temp.metric); Label_Temp3.Text = String.Format("{0:N0}°C", WeatherObj.hourly_forecast[9].temp.metric); Label_Temp4.Text = String.Format("{0:N0}°C", WeatherObj.hourly_forecast[12].temp.metric); Label_Temp5.Text = String.Format("{0:N0}°C", WeatherObj.hourly_forecast[15].temp.metric); Label_Temp6.Text = String.Format("{0:N0}°C", WeatherObj.hourly_forecast[18].temp.metric); image1.Source = new BitmapImage(new Uri("ms-appx:///Assets/Weather/" + WeatherObj.hourly_forecast[3].fctcode + ".png")); image2.Source = new BitmapImage(new Uri("ms-appx:///Assets/Weather/" + WeatherObj.hourly_forecast[6].fctcode + ".png")); image3.Source = new BitmapImage(new Uri("ms-appx:///Assets/Weather/" + WeatherObj.hourly_forecast[9].fctcode + ".png")); image4.Source = new BitmapImage(new Uri("ms-appx:///Assets/Weather/" + WeatherObj.hourly_forecast[12].fctcode + ".png")); image5.Source = new BitmapImage(new Uri("ms-appx:///Assets/Weather/" + WeatherObj.hourly_forecast[15].fctcode + ".png")); image6.Source = new BitmapImage(new Uri("ms-appx:///Assets/Weather/" + WeatherObj.hourly_forecast[18].fctcode + ".png")); for (byte i = 0; i <= 21; i++) { temp_raw[i] = Convert.ToInt32(WeatherObj.hourly_forecast[i].temp.metric); } vAvg = temp_raw.Average(); vScale = 20 / (Math.Abs(temp_raw.Max()) - Math.Abs(temp_raw.Min())); for (byte i = 0; i <= 21; i++) { double x_old = TempLine.Points.ElementAt(i + 1).X; y_temp_set[i] = 120 - Convert.ToInt32(Convert.ToInt32(WeatherObj.hourly_forecast[i].temp.metric) * vScale); TempLine.Points.RemoveAt(i + 1); TempLine.Points.Insert(i + 1, AsPoint(Convert.ToInt32(x_old), y_temp_set[i])); } Label_Temp1.SetValue(Canvas.TopProperty, (y_temp_set[3] - 25)); image1.SetValue(Canvas.TopProperty, (y_temp_set[3] - 70)); Label_Temp2.SetValue(Canvas.TopProperty, (y_temp_set[6] - 25)); image2.SetValue(Canvas.TopProperty, (y_temp_set[6] - 70)); Label_Temp3.SetValue(Canvas.TopProperty, (y_temp_set[9] - 25)); image3.SetValue(Canvas.TopProperty, (y_temp_set[9] - 70)); Label_Temp4.SetValue(Canvas.TopProperty, (y_temp_set[12] - 25)); image4.SetValue(Canvas.TopProperty, (y_temp_set[12] - 70)); Label_Temp5.SetValue(Canvas.TopProperty, (y_temp_set[15] - 25)); image5.SetValue(Canvas.TopProperty, (y_temp_set[15] - 70)); Label_Temp6.SetValue(Canvas.TopProperty, (y_temp_set[18] - 25)); image6.SetValue(Canvas.TopProperty, (y_temp_set[18] - 70)); Rect_Rain11.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[0].pop)); Rect_Rain11.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[0].pop)); Rect_Rain12.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[1].pop)); Rect_Rain12.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[1].pop)); Rect_Rain13.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[2].pop)); Rect_Rain13.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[2].pop)); Rect_Rain21.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[3].pop)); Rect_Rain21.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[3].pop)); Rect_Rain22.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[4].pop)); Rect_Rain22.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[4].pop)); Rect_Rain23.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[5].pop)); Rect_Rain23.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[5].pop)); Rect_Rain31.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[6].pop)); Rect_Rain31.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[6].pop)); Rect_Rain32.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[7].pop)); Rect_Rain32.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[7].pop)); Rect_Rain33.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[8].pop)); Rect_Rain33.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[8].pop)); Rect_Rain41.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[9].pop)); Rect_Rain41.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[9].pop)); Rect_Rain42.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[10].pop)); Rect_Rain42.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[10].pop)); Rect_Rain43.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[11].pop)); Rect_Rain43.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[11].pop)); Rect_Rain51.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[12].pop)); Rect_Rain51.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[12].pop)); Rect_Rain52.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[13].pop)); Rect_Rain52.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[13].pop)); Rect_Rain53.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[14].pop)); Rect_Rain53.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[14].pop)); Rect_Rain61.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[15].pop)); Rect_Rain61.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[15].pop)); Rect_Rain62.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[16].pop)); Rect_Rain62.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[16].pop)); Rect_Rain63.SetValue(Canvas.HeightProperty, Convert.ToInt32(WeatherObj.hourly_forecast[17].pop)); Rect_Rain63.SetValue(Canvas.TopProperty, 100 - Convert.ToInt32(WeatherObj.hourly_forecast[17].pop)); // Current Weather image_cur.Source = new BitmapImage(new Uri("ms-appx:///Assets/Weather/big/" + WeatherObj.current_observation.icon + ".png")); Label_CurTemp.Text = WeatherObj.current_observation.temp_c + "°C"; Label_CurFeel.Text = "Feels like " + WeatherObj.current_observation.feelslike_c + "°C"; Label_CurPerc.Text = "The weather is " + WeatherObj.current_observation.weather.ToLower() + " with a forecasted percipitation of " + WeatherObj.current_observation.precip_today_metric + "mm. " + "The wind blows from " + WeatherObj.current_observation.wind_dir.ToLower() + " direction with " + WeatherObj.current_observation.wind_kph + "kmh."; Int32[] rain_forecast = new Int32[] { Convert.ToInt32(WeatherObj.hourly_forecast[0].pop), Convert.ToInt32(WeatherObj.hourly_forecast[1].pop), Convert.ToInt32(WeatherObj.hourly_forecast[2].pop), Convert.ToInt32(WeatherObj.hourly_forecast[3].pop), Convert.ToInt32(WeatherObj.hourly_forecast[4].pop), Convert.ToInt32(WeatherObj.hourly_forecast[5].pop), Convert.ToInt32(WeatherObj.hourly_forecast[6].pop), Convert.ToInt32(WeatherObj.hourly_forecast[7].pop), Convert.ToInt32(WeatherObj.hourly_forecast[8].pop), Convert.ToInt32(WeatherObj.hourly_forecast[9].pop), Convert.ToInt32(WeatherObj.hourly_forecast[10].pop), Convert.ToInt32(WeatherObj.hourly_forecast[11].pop) }; Int32[] wind_forecast = new Int32[] { Convert.ToInt32(WeatherObj.hourly_forecast[0].wspd.metric), Convert.ToInt32(WeatherObj.hourly_forecast[1].wspd.metric), Convert.ToInt32(WeatherObj.hourly_forecast[2].wspd.metric), Convert.ToInt32(WeatherObj.hourly_forecast[3].wspd.metric), Convert.ToInt32(WeatherObj.hourly_forecast[4].wspd.metric), Convert.ToInt32(WeatherObj.hourly_forecast[5].wspd.metric), Convert.ToInt32(WeatherObj.hourly_forecast[6].wspd.metric), Convert.ToInt32(WeatherObj.hourly_forecast[7].wspd.metric), Convert.ToInt32(WeatherObj.hourly_forecast[8].wspd.metric), Convert.ToInt32(WeatherObj.hourly_forecast[9].wspd.metric), Convert.ToInt32(WeatherObj.hourly_forecast[10].wspd.metric), Convert.ToInt32(WeatherObj.hourly_forecast[11].wspd.metric) }; if (DateTime.Now.Hour < 12) { s1 = "Good morning! "; } else { s1 = "Hi there! "; } if (rain_forecast.Max() > 20) { s2 = "Stay dry, it might rain"; if (wind_forecast.Average() > 10) { s3 = " and look out for flying cows, it's windy!"; } else { s3 = "."; } } else { s2 = "A dry day is forcasted, enjoy"; if (wind_forecast.Average() > 10) { s3 = ". But look out for flying cows, it's windy!"; } else { s3 = "."; } } Label_CurPerc.Text = s1 + s2 + s3; }