Esempio n. 1
0
        public void BuildCurrentView(WeatherModel weather, DateTime localTime)
        {
            // finds the wind direction.
            var windDirection = (weather.currentWeather.windBearing * 2) <= 360 ? weather.currentWeather.windBearing * 2 : (weather.currentWeather.windBearing * 2) - 360;
            string cardinalDirection = FindCardinalDirection(weather.currentWeather.windBearing);

            ViewBag.ApparentTemperature = Convert.ToInt32(weather.currentWeather.apparentTemperature) + "° F";
            ViewBag.Temperature = Convert.ToInt32(weather.currentWeather.temperature) + "° F";
            ViewBag.CardinalDirection = weather.currentWeather.windSpeed + " mph winds from the " + cardinalDirection;
            ViewBag.CloudCover = weather.currentWeather.cloudCover + "%";
            ViewBag.DewPoint = Convert.ToInt32(weather.currentWeather.dewPoint) + "° F";
            ViewBag.Humidity = weather.currentWeather.humidity + "%";
            ViewBag.Icon = weather.currentWeather.icon;
            //ViewBag.NearestStormBearing = weather.currentWeather.nearestStormBearing;
            //ViewBag.NearestStormDistance = weather.currentWeather.nearestStormDistance + " mi";
            //ViewBag.Ozone = weather.currentWeather.ozone;
            //ViewBag.PrecipIntensity = weather.currentWeather.precipIntensity + " in/hr";
            //ViewBag.PrecipProbablity = weather.currentWeather.precipProbablity + " %";
            ViewBag.Pressure = weather.currentWeather.pressure + " mb";
            ViewBag.Summary = weather.currentWeather.summary;
            ViewBag.Time = localTime;
            ViewBag.Visibility = weather.currentWeather.visibility + " mi";
            ViewBag.WindBearing = windDirection + "°. ";
            ViewBag.WindSpeed = weather.currentWeather.windSpeed + " mph";
        }
Esempio n. 2
0
 public void BuildWeatherDisplay(WeatherModel weather)
 {
     ViewBag.Temp = Convert.ToInt32(weather.currentWeather.temperature) + "°F / " + ConvertToCelsius(weather.currentWeather.temperature) + "°C";
     ViewBag.Max = Convert.ToInt32(weather.day0.apparentTemperatureMax) + "°F / " + ConvertToCelsius(weather.day0.apparentTemperatureMax) + "°C at " + Convert.ToDateTime(weather.day0.temperatureMaxTime).ToLongTimeString();
     ViewBag.Min = Convert.ToInt32(weather.day0.apparentTemperatureMin) + "°F / " + ConvertToCelsius(weather.day0.apparentTemperatureMin) + "°C at " + Convert.ToDateTime(weather.day0.temperatureMinTime).ToLongTimeString();
     ViewBag.Summary = weather.currentWeather.summary;
     ViewBag.Sunrise = weather.day0.SunriseTime.ToLongTimeString();
     ViewBag.Sunset = weather.day0.SunsetTime.ToLongTimeString();
     ViewBag.ClassName = iconClassName(weather.currentWeather.icon);
 }
Esempio n. 3
0
        public void BuildDailyView(WeatherModel weather, Helpers.GoogleTimeZone UTCOffSet)
        {
            var windDirection = (weather.day0.windBearing * 2) <= 360 ? weather.day0.windBearing * 2 : (weather.day0.windBearing * 2) - 360;
            string cardinalDirection = FindCardinalDirection(weather.day0.windBearing);

            // Day 0
            ViewBag.Day0ApparentTemperatureMax = Convert.ToInt32(weather.day0.apparentTemperatureMax) + "° F";
            ViewBag.Day0TemperatureMax = Convert.ToInt32(weather.day0.temperatureMax) + "° F";
            ViewBag.Day0CardinalDirection = weather.day0.windSpeed + " mph winds from the " + cardinalDirection;
            ViewBag.Day0CloudCover = weather.day0.cloudCover + "%";
            ViewBag.Day0DayOfWeek = (weather.day0.time.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset)).DayOfWeek;
            ViewBag.Day0DewPoint = Convert.ToInt32(weather.day0.dewPoint) + "° F";
            ViewBag.Day0Humidity = weather.day0.humidity + "%";
            //ViewBag.Day0Icon = weather.day0.icon;
            //ViewBag.Day0MoonPhase = weather.day0.moonPhase;
            //ViewBag.Day0Ozone = weather.day0.ozone;
            //ViewBag.Day0PrecipIntensity = weather.day0.precipIntensity + " in/hr";
            //ViewBag.Day0PrecipProbablity = weather.day0.precipProbablity + " %";
            ViewBag.Day0Pressure = weather.day0.pressure + " mb";
            ViewBag.Day0Sunrise = weather.day0.SunriseTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day0Sunset = weather.day0.SunsetTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day0TemperatureMaxTime = weather.day0.temperatureMaxTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day0TemperatureMin = Convert.ToInt32(weather.day0.temperatureMin) + "° F";
            ViewBag.Day0TemperatureMinTime = weather.day0.temperatureMinTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day0Summary = weather.day0.summary;
            ViewBag.Day0Time = (weather.day0.time.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset)).ToString("MM/dd/yyyy");
            ViewBag.Day0Visibility = weather.day0.visibility + " mi";
            ViewBag.Day0WindBearing = windDirection + "°. ";
            ViewBag.Day0WindSpeed = weather.day0.windSpeed + " mph";

            // Day 1
            windDirection = (weather.day1.windBearing * 2) <= 360 ? weather.day1.windBearing * 2 : (weather.day1.windBearing * 2) - 360;
            cardinalDirection = FindCardinalDirection(weather.day1.windBearing);

            ViewBag.Day1ApparentTemperatureMax = Convert.ToInt32(weather.day1.apparentTemperatureMax) + "° F";
            ViewBag.Day1TemperatureMax = Convert.ToInt32(weather.day1.temperatureMax) + "° F";
            ViewBag.Day1CardinalDirection = weather.day1.windSpeed + " mph winds from the " + cardinalDirection;
            ViewBag.Day1CloudCover = weather.day1.cloudCover + "%";
            ViewBag.Day1DayOfWeek = (weather.day1.time.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset)).DayOfWeek;
            ViewBag.Day1DewPoint = Convert.ToInt32(weather.day1.dewPoint) + "° F";
            ViewBag.Day1Humidity = weather.day1.humidity + "%";
            //ViewBag.Day1Icon = weather.day1.icon;
            //ViewBag.Day1MoonPhase = weather.day1.moonPhase;
            //ViewBag.Day1Ozone = weather.day1.ozone;
            //ViewBag.Day1PrecipIntensity = weather.day1.precipIntensity + " in/hr";
            //ViewBag.Day1PrecipProbablity = weather.day1.precipProbablity + " %";
            ViewBag.Day1Pressure = weather.day1.pressure + " mb";
            ViewBag.Day1Sunrise = weather.day1.SunriseTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day1Sunset = weather.day1.SunsetTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day1TemperatureMaxTime = weather.day1.temperatureMaxTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day1TemperatureMin = Convert.ToInt32(weather.day1.temperatureMin) + "° F";
            ViewBag.Day1TemperatureMinTime = weather.day1.temperatureMinTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day1Summary = weather.day1.summary;
            ViewBag.Day1Time = (weather.day1.time.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset)).ToString("MM/dd/yyyy");
            ViewBag.Day1Visibility = weather.day1.visibility + " mi";
            ViewBag.Day1WindBearing = windDirection + "°. ";
            ViewBag.Day1WindSpeed = weather.day1.windSpeed + " mph";

            // Day 2
            windDirection = (weather.day2.windBearing * 2) <= 360 ? weather.day2.windBearing * 2 : (weather.day2.windBearing * 2) - 360;
            cardinalDirection = FindCardinalDirection(weather.day2.windBearing);

            ViewBag.Day2ApparentTemperatureMax = Convert.ToInt32(weather.day2.apparentTemperatureMax) + "° F";
            ViewBag.Day2TemperatureMax = Convert.ToInt32(weather.day2.temperatureMax) + "° F";
            ViewBag.Day2CardinalDirection = weather.day2.windSpeed + " mph winds from the " + cardinalDirection;
            ViewBag.Day2CloudCover = weather.day2.cloudCover + "%";
            ViewBag.Day2DayOfWeek = (weather.day2.time.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset)).DayOfWeek;
            ViewBag.Day2DewPoint = Convert.ToInt32(weather.day2.dewPoint) + "° F";
            ViewBag.Day2Humidity = weather.day2.humidity + "%";
            //ViewBag.Day2Icon = weather.day2.icon;
            //ViewBag.Day2MoonPhase = weather.day2.moonPhase;
            //ViewBag.Day2Ozone = weather.day2.ozone;
            //ViewBag.Day2PrecipIntensity = weather.day2.precipIntensity + " in/hr";
            //ViewBag.Day2PrecipProbablity = weather.day2.precipProbablity + " %";
            ViewBag.Day2Pressure = weather.day2.pressure + " mb";
            ViewBag.Day2Summary = weather.day2.summary;
            ViewBag.Day2Sunrise = weather.day2.SunriseTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day2Sunset = weather.day2.SunsetTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day2TemperatureMaxTime = weather.day2.temperatureMaxTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day2TemperatureMin = Convert.ToInt32(weather.day2.temperatureMin) + "° F";
            ViewBag.Day2TemperatureMinTime = weather.day2.temperatureMinTime.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset);
            ViewBag.Day2Time = (weather.day2.time.AddSeconds(UTCOffSet.rawOffset + UTCOffSet.dstOffset)).ToString("MM/dd/yyyy");
            ViewBag.Day2Visibility = weather.day2.visibility + " mi";
            ViewBag.Day2WindBearing = windDirection + "°. ";
            ViewBag.Day2WindSpeed = weather.day2.windSpeed + " mph";
        }
Esempio n. 4
0
        public ActionResult Index(WeatherModel model)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            string address = model.Address;
            double lat;
            double lon;

            if (address != null || address.Length != 0)
                GetGeocode(address, out lat, out lon);
            else
                return View(model);

            WeatherModel weather = GetForecast((float)lat, (float)lon);
            Helpers.GoogleTimeZone UTCOffset = GetLocalDateTime(lat, lon, weather.currentWeather.time);
            DateTime localTime = weather.currentWeather.time.AddSeconds(UTCOffset.rawOffset + UTCOffset.dstOffset);
            BuildCurrentView(weather, localTime);
            BuildDailyView(weather, UTCOffset);
            stopwatch.Stop();
            ViewBag.StopWatch = "Elapsed Time: " + stopwatch.ElapsedMilliseconds;

            ViewBag.CurrentCity = address + " (" + string.Format("{0:00.00000}, {1:00.00000}", lat, lon) + ")";
            return View(model);
        }
Esempio n. 5
0
        // Get Forecast information for a location using "Forecast.io" API
        // We are using Forecast.io.45 wrapper library to contact Forecast.io API
        public WeatherModel GetForecast(float lat, float lon)
        {
            // ForecastIORequest(API key, lat, lon, measurement unit)
            var request = new ForecastIORequest("d1d02d9b39d4125af3216ea665368a5c", lat, lon, Unit.us);
            var response = request.Get();

            WeatherModel weather = new WeatherModel(response);
            return weather;
        }
Esempio n. 6
0
        public WeatherModel GetLocalForecast(float lat, float lon)
        {
            var request = new ForecastIORequest("d1d02d9b39d4125af3216ea665368a5c", lat, lon, Unit.us);
            var response = request.Get();

            WeatherModel weather = new WeatherModel(response);
            return weather;
        }