Exemple #1
0
        public string ForecastSummary(ForecastData fc)
        {
            List <DateTime> days = new List <DateTime>();

            days = containsDays(fc);
            DateTime      nowtime      = DateTime.Now;
            bool          today        = false;
            StringBuilder returnString = new StringBuilder();

            foreach (var day in days)
            {
                if (day.Day == nowtime.Day)
                {
                    today = true;
                    returnString.AppendLine(string.Format("The average temperature for {1} today will be {0:f1} Degrees C.", CalcAverageForecastTemp(fc, day), AtLocation(fc)));
                    returnString.AppendLine(string.Format("The forecast for later today will be {0} .", CalcForecastMain(fc, day)));
                }
            }
            if (today)
            {
                returnString.AppendLine(string.Format("The weather for {1} tommorow is {0}.", CalcForecastMain(fc, days[1]), AtLocation(fc)));
                returnString.AppendLine(string.Format("The average temperature tomorrow will be {0:f1} Degrees C", CalcAverageForecastTemp(fc, days[1])));
            }
            else
            {
                returnString.AppendLine(string.Format("The weather for {1:dddd} is {0}", CalcForecastMain(fc, days[0]), days[0]));
                returnString.AppendLine(string.Format("The average temperature for {1:dddd} will be {0:f1} Degrees C", CalcAverageForecastTemp(fc, days[0]), days[0]));
            }
            return(returnString.ToString());
        }
Exemple #2
0
        public double CalcAverageForecastTemp(ForecastData forecastData, DateTime date)
        {
            bool   flag   = false;
            double total  = 0;
            int    length = forecastData.cnt;
            double items  = 0;

            for (int i = 0; i < length - 1; i++)
            {
                if (Convert.ToDateTime(forecastData.list[i].dt_txt).Day == date.Day)
                {
                    if (flag == false)
                    {
                        flag = true;
                    }
                    total += (forecastData.list[i].main.temp);
                    items++;
                }
            }
            if (flag)
            {
                return((total / items) - 273.15);
            }
            else
            {
                return(double.NaN);
            }
        }
Exemple #3
0
        public double CalcAverageForecastTemp(ForecastData forecastData)
        {
            double total  = 0;
            int    length = forecastData.cnt;

            for (int i = 0; i < length - 1; i++)
            {
                total += forecastData.list[i].main.temp;
            }
            return((total / length) - 273.15);
        }
Exemple #4
0
        public List <DateTime> containsDays(ForecastData forecastData)
        {
            List <int>      daylist    = new List <int>();
            List <DateTime> returnDays = new List <DateTime>();
            int             length     = forecastData.cnt;

            for (int i = 0; i < length - 1; i++)
            {
                int day = Convert.ToDateTime(forecastData.list[i].dt_txt).Day;
                if (!daylist.Contains(day))
                {
                    daylist.Add(day);
                    returnDays.Add(Convert.ToDateTime(forecastData.list[i].dt_txt));
                }
            }
            return(returnDays);
        }
        private static void speakWeather(Mouth mouth, Interpreter interpreter, OWMForecast oWMForecast, OWMCurrent oWM)
        {
            ForecastData fc = oWMForecast.ForeCastWeahterData("cv5", "GB", "Coventry", 1);


            try
            {
                //var returned = oWM.GetCurrent("cv5", "GB", "Coventry", 1);
                var returned = oWM.GetCurrent("cv5", "GB", "Coventry", 2);
                mouth.speakMsg(string.Format(interpreter.CurrentSummary(returned)));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            mouth.speakMsg(interpreter.ForecastSummary(fc));
        }
Exemple #6
0
        public string CalcForecastMain(ForecastData forecastData, DateTime date)
        {
            List <string> commonList = new List <string>();
            string        mostCommon;
            bool          flag   = false;
            int           length = forecastData.cnt;

            for (int i = 0; i < length - 1; i++)
            {
                if (Convert.ToDateTime(forecastData.list[i].dt_txt).Day == date.Day)
                {
                    if (flag == false)
                    {
                        flag = true;
                    }
                    //Console.WriteLine(forecastData.list[i].weather[0].description);
                    commonList.Add(forecastData.list[i].weather[0].description);
                }
            }
            if (flag)
            {
                var groupsWithCounts = from s in commonList
                                       group s by s into g
                                       select new
                {
                    Item  = g.Key,
                    Count = g.Count()
                };

                var groupsSorted = groupsWithCounts.OrderByDescending(g => g.Count);
                mostCommon = groupsSorted.First().Item;
                return(mostCommon);
            }
            else
            {
                return(string.Empty);
            }
        }
Exemple #7
0
 public string AtLocation(ForecastData forecastData)
 {
     return(forecastData.city.name);
 }