Exemplo n.º 1
0
        public ForecastDay GetAverages(string spotName)
        {
            ForecastDay f = new ForecastDay();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(SQL_GetAverages, conn);
                    cmd.Parameters.AddWithValue("@spotName", spotName);


                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        f.HistoricalMaxHeight    = Convert.ToDecimal(reader["historical_max_surf"]);
                        f.HistoricalMaxPrice     = Convert.ToDecimal(reader["historical_max_price"]);
                        f.HistoricalMinHeight    = Convert.ToDecimal(reader["historical_min_surf"]);
                        f.HistoricalMinPrice     = Convert.ToDecimal(reader["historical_min_price"]);
                        f.HistoricalSurfHeight   = Convert.ToDecimal(reader["historical_average_surf"]);
                        f.HistoticalAveragePrice = Convert.ToDecimal(reader["historical_average_price"]);
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }

            return(f);
        }
Exemplo n.º 2
0
        static void GenerateData()
        {
            using (var dbContext = new ForecastDbContext())
            {
                dbContext.Database.EnsureCreated();

                if (!dbContext.ForecastDays.Any())
                {
                    Entities.SolarSystems.MeLi.MeLiSolarSystem meliSolarSystem = new Entities.SolarSystems.MeLi.MeLiSolarSystem();
                    for (int i = 0; i < (365 * 10); i++)
                    {
                        ForecastDay forecastDay = new ForecastDay();
                        forecastDay.Day                     = i;
                        forecastDay.FerengiPosition         = meliSolarSystem.FerengiPlanet.GetPosition(i).ToString();
                        forecastDay.FerengiAngle            = meliSolarSystem.FerengiPlanet.GetAngle(i);
                        forecastDay.BetasoidePosition       = meliSolarSystem.BetasoidePlanet.GetPosition(i).ToString();
                        forecastDay.BetasoideAngle          = meliSolarSystem.BetasoidePlanet.GetAngle(i);
                        forecastDay.VulcanoPosition         = meliSolarSystem.VulcanoPlanet.GetPosition(i).ToString();
                        forecastDay.VulcanoAngle            = meliSolarSystem.VulcanoPlanet.GetAngle(i);
                        forecastDay.AreAlignedWithTheSun    = meliSolarSystem.AreAlignedWithTheSun((uint)i);
                        forecastDay.AreAlignedWithoutTheSun = meliSolarSystem.AreAlignedWithoutTheSun((uint)i);
                        forecastDay.IsSunInside             = meliSolarSystem.IsSunInside((uint)i);
                        forecastDay.Weather                 = meliSolarSystem.GetWeather((uint)i);
                        forecastDay.TrianglePerimeter       = meliSolarSystem.GetTrianglePerimeter((uint)i);
                        dbContext.ForecastDays.Add(forecastDay);
                    }
                    dbContext.SaveChanges();
                }
            }
        }
Exemplo n.º 3
0
 public void SetData(ForecastDay forecast)
 {
     dayLabel.Text       = forecast.date.weekday;
     precipLabel.Text    = forecast.ProbabilityPercipString();
     highTempLabel.Text  = forecast.HighTempString(Settings.UomTemperature, true, true);
     lowTempLabel.Text   = forecast.LowTempString(Settings.UomTemperature, true, true);
     iconImageView.Image = UIImage.FromBundle(forecast.icon);
 }
Exemplo n.º 4
0
        public void ValidStateImagePath()
        {
            var model = new ForecastDay
            {
                Weather_State_Abbr = "lr"
            };

            Assert.IsTrue(model.Weather_State_Image == "https://www.metaweather.com/static/img/weather/png/lr.png");
        }
Exemplo n.º 5
0
        public void ErrorStateImagePath()
        {
            var model = new ForecastDay
            {
                Weather_State_Abbr = "err"
            };

            Assert.IsTrue(model.Weather_State_Image == @"/Images/ErrorImage.png");
        }
Exemplo n.º 6
0
        public void EmptyStateImagePath()
        {
            var model = new ForecastDay
            {
                Weather_State_Abbr = ""
            };

            Assert.IsTrue(model.Weather_State_Image == "");
        }
        //Convert.ToSingle(info needed to be changed to float or w/e num type)

        public WeatherViewModel(ForecastDay forecastDay, Astro astro, Condition condition, Condition2 condition2,
                                Day day, Hour hour, Location location, Forecast forecast)
        {
            DailyMaxTemp = forecastDay.Day.MaxTempF;
            DailyMinTemp = forecastDay.Day.MinTempF;
            DailyAvgTemp = forecastDay.Day.AvgTempF;
            MaxWind      = hour.WindMph;
            TotalPrecip  = hour.PrecipMm;
            AvgHumidity  = day.AvgHumidity;
            Hours        = forecastDay.Hour.ToList();
        }
        public void NonNullForecast()
        {
            var forecast = new ForecastDay
            {
                Weather_State_Abbr = "err",
                Weather_State_Name = "No data available"
            };
            var vm = new ForecastDetailVM();

            vm.LoadForecast(forecast);

            Assert.IsTrue(vm.Forecast != null);
            Assert.IsTrue(vm.Visibility == System.Windows.Visibility.Visible);
        }
Exemplo n.º 9
0
        public ForecastDay Get(uint day)
        {
            ForecastDay result;

            using (var dbContext = new ForecastDbContext())
            {
                dbContext.Database.EnsureCreated();

                result = dbContext.ForecastDays.FirstOrDefault(f => f.Day == day);
                if (result == null)
                {
                    result = new ForecastDay();
                }
            }

            return(result);
        }
Exemplo n.º 10
0
        ////from input
        //public List<ForecastDay> GetForecastDaysFromInput(int minSurfHeight, DateTime departureDate, DateTime returnDate, int maxPrice)
        //{
        //    List<ForecastDay> forecastDays = new List<ForecastDay>();

        //    //if no maxPrice is set (minSurfHeight will automatically be set to 0
        //    if (maxPrice == 0)
        //    {
        //        maxPrice = 99999;
        //    }

        //    try
        //    {
        //        using (SqlConnection conn = new SqlConnection(connectionString))
        //        {
        //            conn.Open();

        //            SqlCommand cmd = new SqlCommand(SQL_GetForecastDaysFromInput, conn);
        //            cmd.Parameters.AddWithValue("@inputMinSurfHeight", minSurfHeight);
        //            cmd.Parameters.AddWithValue("@inputDepartureDate", departureDate);
        //            cmd.Parameters.AddWithValue("@inputReturnDate", returnDate);
        //            cmd.Parameters.AddWithValue("@inputMaxPrice", maxPrice);

        //            SqlDataReader reader = cmd.ExecuteReader();

        //            while (reader.Read())
        //            {
        //                ForecastDay f = new ForecastDay();
        //                f.InputDepartureDate = departureDate;
        //                f.InputMaxPrice = maxPrice;
        //                f.InputMinSurfHeight = minSurfHeight;
        //                f.InputReturnDate = returnDate;
        //                f.LocationName = Convert.ToString(reader["name"]);
        //                f.AverageSurfHeight = Convert.ToDecimal(reader["avg_surf_height"]);
        //                f.NumberOfFlights = Convert.ToInt32(reader["num_of_flights"]);
        //                f.ForecastForDate = Convert.ToDateTime(reader["forecast_for_date"]);
        //                f.SpotName = Convert.ToString(reader["spot_name"]);
        //                f.WindDirection = Convert.ToDecimal(reader["wind_direction"]);

        //                forecastDays.Add(f);
        //            }
        //        }
        //    }
        //    catch (SqlException)
        //    {

        //        throw;
        //    }

        //    return forecastDays;
        //}

        ////no set return date or
        ////no set departure date
        //public List<ForecastDay> GetForecastDaysFromInput(int minSurfHeight, DateTime date, bool isDeparture, int maxPrice)
        //{
        //    List<ForecastDay> forecastDays = new List<ForecastDay>();

        //    //if no maxPrice is set (minSurfHeight will automatically be set to 0
        //    if (maxPrice == 0)
        //    {
        //        maxPrice = 99999;
        //    }

        //    try
        //    {
        //        using (SqlConnection conn = new SqlConnection(connectionString))
        //        {
        //            conn.Open();

        //            SqlCommand cmd = new SqlCommand(SQL_GetForecastDaysFromInput, conn);
        //            cmd.Parameters.AddWithValue("@inputMinSurfHeight", minSurfHeight);
        //            if (isDeparture)
        //            {
        //                cmd.Parameters.AddWithValue("@inputDepartureDate", date);
        //            }
        //            else
        //            {
        //                cmd.Parameters.AddWithValue("@inputReturnDate", date);
        //            }
        //            cmd.Parameters.AddWithValue("@inputMaxPrice", maxPrice);

        //            SqlDataReader reader = cmd.ExecuteReader();

        //            while (reader.Read())
        //            {
        //                ForecastDay f = new ForecastDay();
        //                if (isDeparture)
        //                {
        //                    f.InputDepartureDate = date;
        //                }
        //                else
        //                {
        //                    f.InputReturnDate = date;
        //                }
        //                f.InputMaxPrice = maxPrice;
        //                f.InputMinSurfHeight = minSurfHeight;
        //                f.LocationName = Convert.ToString(reader["name"]);
        //                f.AverageSurfHeight = Convert.ToDecimal(reader["avg_surf_height"]);
        //                f.NumberOfFlights = Convert.ToInt32(reader["num_of_flights"]);
        //                f.ForecastForDate = Convert.ToDateTime(reader["forecast_for_date"]);
        //                f.SpotName = Convert.ToString(reader["spot_name"]);
        //                f.WindDirection = Convert.ToDecimal(reader["wind_direction"]);

        //                forecastDays.Add(f);
        //            }
        //        }
        //    }
        //    catch (SqlException)
        //    {

        //        throw;
        //    }

        //    return forecastDays;
        //}

        ////default
        //public List<ForecastDay> GetForecastDaysDefault()
        //{
        //    List<ForecastDay> forecastDays = new List<ForecastDay>();

        //    try
        //    {
        //        using (SqlConnection conn = new SqlConnection(connectionString))
        //        {
        //            conn.Open();

        //            SqlCommand cmd = new SqlCommand(SQL_GetForecastDaysDefault, conn);
        //            SqlDataReader reader = cmd.ExecuteReader();

        //            while (reader.Read())
        //            {
        //                ForecastDay f = new ForecastDay();
        //                f.LocationName = Convert.ToString(reader["name"]);
        //                f.AverageSurfHeight = Convert.ToDecimal(reader["avg_surf_height"]);
        //                f.NumberOfFlights = Convert.ToInt32(reader["num_of_flights"]);
        //                f.ForecastForDate = Convert.ToDateTime(reader["forecast_for_date"]);
        //                f.SpotName = Convert.ToString(reader["spot_name"]);
        //                f.WindDirection = Convert.ToDecimal(reader["wind_direction"]);

        //                forecastDays.Add(f);
        //            }
        //        }
        //    }
        //    catch (SqlException)
        //    {

        //        throw;
        //    }

        //    return forecastDays;
        //}

        //historical surf height averages

        public List <ForecastDay> GetDetailedForecast(string spotName, string flightId)
        {
            List <ForecastDay> forecastDays = new List <ForecastDay>();
            ForecastDay        f            = new ForecastDay();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(SQL_GetDetailsFromId, conn);
                    cmd.Parameters.AddWithValue("@spotName", spotName);
                    cmd.Parameters.AddWithValue("@flightId", flightId);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        f.SpotName               = Convert.ToString(reader["spot_name"]);
                        f.ForecastForDate        = Convert.ToDateTime(reader["forecast_for_date"]);
                        f.AverageSurfHeight      = Convert.ToDecimal(reader["swell_height_feet"]);
                        f.LocationName           = Convert.ToString(reader["name"]);
                        f.DepartureDate          = Convert.ToDateTime(reader["departure_date"]);
                        f.DestinationAirportCode = Convert.ToString(reader["airport_code"]);
                        f.ReturnDate             = Convert.ToDateTime(reader["return_date"]);
                        f.Price             = Convert.ToDecimal(reader["price"]);
                        f.OriginAirportCode = Convert.ToString(reader["origin_airport_code"]);
                        f.Longitude         = Convert.ToString(reader["longitude"]);
                        f.Latitude          = Convert.ToString(reader["latitude"]);
                        f.FlightId          = Convert.ToInt32(reader["flight_id"]);

                        forecastDays.Add(f);
                    }
                }
                forecastDays.Add(GetAverages(spotName));
            }
            catch (SqlException)
            {
                throw;
            }

            return(forecastDays);
        }
Exemplo n.º 11
0
 public static string ProbabilityPercipString(this ForecastDay forecast) => (forecast?.pop ?? 0).ToPercentString();
Exemplo n.º 12
0
 public static string LowTempString(this ForecastDay forecast, TemperatureUnits units, bool round = false, bool degreeSymbol = false)
 => getTemperatureString(forecast.LowTemp(units, round), degreeSymbol);
Exemplo n.º 13
0
 public static double LowTemp(this ForecastDay forecast, TemperatureUnits units, bool round = false)
 => getValueInUnits(units, forecast?.low?.FahrenheitValue, forecast?.low?.CelsiusValue, round);
Exemplo n.º 14
0
 private static WindAlert AnalyseForecastDay(ForecastDay forecastDay, string descriptor)
 {
     return(forecastDay != null?AnalyseWind(forecastDay.Wind, descriptor) : GetWindAlert());
 }
 public SelectedForecastEventArgs(ForecastDay forecastDay)
 {
     ForecastDay = forecastDay;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Takes an incoming open weather forecast response and transforms it to a WeatherForecast class instance
        /// </summary>
        /// <param name="forecastJson"></param>
        /// <param name="cityName"></param>
        /// <returns></returns>
        public WeatherForecast GetForecastByCity(string forecastJson, string cityName)
        {
            string errMsg = string.Empty;
            var    wf     = new WeatherForecast();

            try
            {
                // Connect to the weather API web service

                /* Params
                 * For temperature in Fahrenheit use units=imperial
                 *  For temperature in Celsius use units=metric
                 *  Temperature in Kelvin is used by default, no need to use units parameter in API call
                 *
                 *  Imperial will return wind in mph, metric in metres per second
                 */
                // TO DO - REMOVE TO SEPARATE MANAGER LAYER
                if (!string.IsNullOrEmpty(forecastJson))
                {
                    var f = JsonHelper <OpenWeatherForecast> .JsonDeserialize(forecastJson); // attempt to map the received data into our forecast model object

                    // Now map the incoming object into a view model before dispatch
                    wf.City = new Location
                    {
                        Country    = f.City.Country,
                        Name       = f.City.Name,
                        Latitude   = f.City.Coord.Latitude.ToString(),
                        Longtitude = f.City.Coord.Longtitude.ToString()
                    };
                    wf.Days = new Dictionary <string, ForecastDay>();

                    // Loop through the 3 hour slices (should be 40) and assign to correct dates; they're returned in date asc order so no need to check...yet
                    foreach (var ts in f.Timeslices)
                    {
                        // incoming time - UTC: "2017-03-13 06:00:00"
                        DateTime dt;
                        if (!DateTime.TryParseExact(ts.ForecastDateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out dt))
                        {
                            errMsg = "Invalid date format specified in received forecast openWeather forecast date - attempt to parse " + ts.ForecastDateTime + " failed";
                            throw new ApplicationException(errMsg);
                        }
                        var sliceDate = dt.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture);

                        // Now build the 3 hour slice
                        WeatherConditionInfo info = (ts.Weather.Count > 0) ? ts.Weather[0] : new WeatherConditionInfo {
                            Description = "No Description Available", Icon = "", Id = -1, Main = ""
                        };
                        string windArrowCode = "";
                        var    windArrows    = new Dictionary <Func <double, bool>, Action>
                        {
                            { x => ((x > 337.5 && x <= 360) || (x >= 0 && x < 22.5)), () => windArrowCode = "&#8593;" }, // north
                            { x => (x >= 22.5 && x < 67.5), () => windArrowCode = "&#8599;" },                           // north east
                            { x => (x >= 67.5 && x < 112.5), () => windArrowCode = "&#8594;" },                          // east
                            { x => (x >= 112.5 && x < 157.5), () => windArrowCode = "&#8600;" },                         // south east
                            { x => (x >= 157.5 && x < 202.5), () => windArrowCode = "&#8595;" },                         // south
                            { x => (x >= 202.5 && x < 247.5), () => windArrowCode = "&#8601;" },                         // south west
                            { x => (x >= 247.5 && x < 292.5), () => windArrowCode = "&#8592;" },                         // west
                            { x => (x >= 292.5 && x <= 337.5), () => windArrowCode = "&#8598;" },                        // north west
                        };
                        windArrows.First(sw => sw.Key(ts.Wind.Degrees)).Value();                                         // trigger a set

                        var slice = new ForecastDay3HourSlice()
                        {
                            CloudCoverPercentage = ts.Clouds.PercentageCloudCover.ToString() + "%",
                            Description          = (ts.Weather.Count > 0) ? ts.Weather[0].Description : "No Description Available",
                            Humidity             = ts.Info.Humidity.ToString() + "%",
                            Icon                   = "http://openweathermap.org/img/w/" + info.Icon + ".png",
                            MaxTemperature         = ts.Info.MaxTemperature.ToString("0") + CONST_degreesFarenheit,
                            MinTemperature         = ts.Info.MinTemperature.ToString("0") + CONST_degreesFarenheit,
                            Period                 = dt.ToString("HH:mm"),
                            Pressure               = ts.Info.Pressure.ToString(),
                            RainVolumeInMm         = ((ts.Rain != null) ? ts.Rain.RainVolumeInMm.ToString() : "0") + "mm",
                            WindDirectionInDegrees = ts.Wind.Degrees.ToString(),                                           // http://htmlarrows.com could be used here.
                            WindSpeed              = ts.Wind.Speed.ToString(),                                             // metres per second
                            WindSummary            = windArrowCode + " " + (ts.Wind.Speed * 2.23694).ToString("0") + "mph" // convert the wind speed from metres per second to mph and round
                        };

                        // If this date already exists, add the new slice to it, otherwise add the date, then the slice
                        ForecastDay fd;
                        if (!wf.Days.ContainsKey(sliceDate))
                        {
                            fd = new ForecastDay
                            {
                                Date       = sliceDate,
                                Timeslices = new Dictionary <string, ForecastDay3HourSlice>()
                            };
                            wf.Days.Add(sliceDate, fd);
                        }
                        fd = wf.Days[sliceDate];
                        // Add the slice period to the date entry
                        fd.Timeslices.Add(slice.Period, slice);
                    } // end timeslice loop
                }     // end strResponse if
            }
            catch (Exception ex)
            {
                if (string.IsNullOrEmpty(errMsg))
                {
                    errMsg = "An unrecoverable system error occurred";
                }
                errorCollection.Add(new Tuple <string, Exception>(errMsg, ex));
                wf.ErrorMessages.Add(errMsg); // return the user friendly messages to the client
                // TO DO - ADD INTERNAL LOGGING
            }
            return(wf);
        }