private WeatherViewData CreateWeatherViewData(WeatherForecastResponse resp)
        {
            var viewData = new WeatherViewData
            {
                Message = resp.Message,
                City    = resp.City.Name,
                Current = new WeatherDTO()
                {
                    Humidity    = resp.List[0].Main.Humidity,
                    Temperature = ConvertToCelsius(resp.List[0].Main.Temp) // Kelvin to Celsius
                },
                DateTime     = resp.List[0].Dt * 1000,
                NextFiveDays = new List <WeatherDTO>()
            };
            // to ms
            const int dataPointsPerDay = 8;

            for (int i = 0; i < 5; i++)
            {
                var dailyWeatherData = resp.List.Skip(i * dataPointsPerDay).Take(dataPointsPerDay).ToList();
                var humidity         = dailyWeatherData.Sum(data => data.Main.Humidity) /
                                       (double)dataPointsPerDay;
                var temp = dailyWeatherData.Sum(data => data.Main.Temp) /
                           (double)dataPointsPerDay;
                var w = new WeatherDTO
                {
                    Humidity    = Math.Round(humidity, 2),
                    Temperature = ConvertToCelsius(temp)  // Kelvin to Celsius
                };
                viewData.NextFiveDays.Add(w);
            }

            return(viewData);
        }
        private WeatherViewData CreateErrResponse(WeatherForecastResponse resp)
        {
            var viewData = new WeatherViewData();

            viewData.Message = resp.Message;
            return(viewData);
        }
        ////////////////////////////////////////
        //
        // Weather Model To View Conversion

        //Converts model object to view object
        protected WeatherViewData Convert(WeatherData weatherData)
        {
            //conditions string to enum
            WeatherConditions conditions = WeatherConditions.Clear;

            if (Enum.IsDefined(typeof(WeatherConditions), weatherData.weatherMainCategory))
            {
                conditions = (WeatherConditions)Enum.Parse(typeof(WeatherConditions), weatherData.weatherMainCategory);
            }

            //kelvin to farenheit
            float temperatureFarenheit = weatherData.temperature * (9f / 5f) - 459.67f;

            //create the view data for the view scripts to use.
            WeatherViewData weatherViewData = new WeatherViewData(conditions, temperatureFarenheit);

            return(weatherViewData);
        }
        protected void OnCurrentWeatherLoaded(WeatherData weatherData)
        {
            WeatherViewData weatherViewData = Convert(weatherData);

            this.weatherManager.SetData(weatherViewData);
        }