/// <summary>
        /// Returns a specified number of rows from the database.
        /// </summary>
        /// <param name="numberOfRowToRead">Number of row to read.</param>
        /// <returns>Read data.</returns>
        public DataModels GetData(int numberOfRowToRead)
        {
            DataModels Data = new DataModels();

            Data.iddata     = new List <int>();
            Data.humidity   = new List <double>();
            Data.tempreture = new List <double>();
            Data.pressure   = new List <double>();
            Data.dateTime   = new List <DateTime>();
            Data.outdata    = new List <double>();
            Data.iddevice   = new List <int>();
            Data.idregion   = new List <int>();

            int minID = db.data.Where(m => m.iddata >= 0).Max(m => m.iddata);

            minID -= numberOfRowToRead;

            foreach (var item in db.data.Where(m => m.iddata > minID))
            {
                Data.iddata.Add(item.iddata);
                Data.humidity.Add((double)item.humidity);
                Data.tempreture.Add((double)item.tempreture);
                Data.pressure.Add((double)item.pressure);
            }
            return(Data);
        }
 private string TemperaturePrediction(DataModels data)
 {
     if (data.tempreture[0] > data.tempreture[1] && data.tempreture[1] > data.tempreture[2])
     {
         foTemperature = forecastOfTemperature.Bad;
         return("- nadchodzi front chłodny, możliwe pogorszenie pogody.");
     }
     else if (data.tempreture[0] < data.tempreture[1] && data.tempreture[1] < data.tempreture[2])
     {
         foTemperature = forecastOfTemperature.Good;
         return("- zbliżanie się frontu ciepłego.");
     }
     else
     {
         foTemperature = forecastOfTemperature.Normal;
         return("- temperatura w normie.");
     }
 }
        /// <summary>
        /// Calculate weather indicators and return weather forecast and opinion about weather.
        /// </summary>
        /// <returns>String</returns>
        public string[] Prediction()
        {
            string[] result = new string[4] {
                string.Empty, string.Empty, string.Empty, string.Empty
            };
            string opinion = string.Empty;

            ServiceDatabaseModels serviceDB = new ServiceDatabaseModels();
            DataModels            data      = new DataModels();

            data = serviceDB.GetData(3);

            opinion = OpinionPrediction(data);

            result[0] = PressurePrediction(data);
            result[1] = HumidityPrediction(data);
            result[2] = TemperaturePrediction(data);
            result[3] = opinion;

            return(result);
        }
        private string HumidityPrediction(DataModels data)
        {
            string result = string.Empty;

            if (data.humidity[0] > data.humidity[1] && data.humidity[1] > data.humidity[2])
            {
                foHumidity = forecastOfHumidity.Normal;
                return("- wilgotność powietrza maleje,");
            }
            else if (data.humidity[0] < data.humidity[1] && data.humidity[1] < data.humidity[2])
            {
                if ((data.tempreture[0] < data.tempreture[1] && data.tempreture[1] < data.tempreture[2]) && (data.pressure[0] > data.pressure[1] && data.pressure[1] > data.pressure[2]))
                {
                    foHumidity = forecastOfHumidity.Bad;
                    return("- możliwe opady deszczu lub burza,");
                }
                else if (data.tempreture[0] > data.tempreture[1] && data.tempreture[1] > data.tempreture[2])
                {
                    foHumidity = forecastOfHumidity.Bad;
                    return("- możliwe występowanie mgły,");
                }
                else if (data.pressure[0] > data.pressure[1] && data.pressure[1] > data.pressure[2])
                {
                    foHumidity = forecastOfHumidity.Bad;
                    return("- możliwe wystapienie burzy,");
                }
                else
                {
                    foHumidity = forecastOfHumidity.Normal;
                    return("- wilogtność powietrza rosnie,");
                }
            }
            else
            {
                foHumidity = forecastOfHumidity.Normal;
                return("- wilgotnośc powietrza w normie.");
            }
        }
        public DataModels GetAllDatas(int howManyDays, TypeOfMeteorologyData typeOfMeteorologyData)
        {
            DataModels listOfDatas = new DataModels();

            listOfDatas.dateTime = new List <DateTime>();
            DateTime sinceWhen = DateTime.Now.AddDays(-howManyDays + 1);

            if (typeOfMeteorologyData == TypeOfMeteorologyData.Humidity)
            {
                listOfDatas.outdata = new List <double>();
                foreach (var item in db.data.Where(m => m.date >= sinceWhen))
                {
                    listOfDatas.outdata.Add((double)item.humidity);
                    listOfDatas.dateTime.Add((DateTime)item.date);
                }
            }
            else if (typeOfMeteorologyData == TypeOfMeteorologyData.Tempreture)
            {
                listOfDatas.outdata = new List <double>();
                foreach (var item in db.data.Where(m => m.date >= sinceWhen))
                {
                    listOfDatas.outdata.Add((double)item.tempreture);
                    listOfDatas.dateTime.Add((DateTime)item.date);
                }
            }
            else if (typeOfMeteorologyData == TypeOfMeteorologyData.Pressure)
            {
                listOfDatas.outdata = new List <double>();
                foreach (var item in db.data.Where(m => m.date >= sinceWhen))
                {
                    listOfDatas.outdata.Add((double)item.pressure);
                    listOfDatas.dateTime.Add((DateTime)item.date);
                }
            }
            return(listOfDatas);
        }
 private string PressurePrediction(DataModels data)
 {
     if (data.pressure[0] > data.pressure[1] && data.pressure[1] > data.pressure[2])
     {
         double difference = data.pressure[0] - data.pressure[1] + data.pressure[1] - data.pressure[2];
         if (difference >= 2 && difference <= 4)
         {
             foPressure = forecastOfPressure.Bad;
             return("- przednia część niżu, możliwy wzrost prędkości wiatru,");
         }
         else
         {
             foPressure = forecastOfPressure.VeryBad;
             return("- nadciąga niż, możliwe opady, silny wiatr,");
         }
     }
     else if (data.pressure[0] < data.pressure[1] && data.pressure[1] < data.pressure[2])
     {
         double difference = data.pressure[1] - data.pressure[0] + data.pressure[2] - data.pressure[1];
         if (difference >= 4)
         {
             foPressure = forecastOfPressure.Bad;
             return("- przejście frontu chłodnego, możliwy wzrost prędkości wiatru,");
         }
         else
         {
             foPressure = forecastOfPressure.Good;
             return("- nadciąga wyż, możliwa poprawa pogody,");
         }
     }
     else
     {
         foPressure = forecastOfPressure.Normal;
         return("- cieśnienie atmosferyczne w normie,");
     }
 }
        private string OpinionPrediction(DataModels data)
        {
            string goodResult   = "Dobre warunki pogodowe.";
            string badResult    = "Złe warunki, nie przebywać w pobliżu stacji meteo.";
            string normalResult = "Warunki pogodowe w normie.";

            switch (foPressure)
            {
            case forecastOfPressure.Good:
                #region Pressure Good
                switch (foTemperature)
                {
                case forecastOfTemperature.Good:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(normalResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(goodResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                case forecastOfTemperature.Bad:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(badResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(normalResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                case forecastOfTemperature.Normal:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(badResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(goodResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                default:
                    return(normalResult);
                }
                #endregion
                break;

            case forecastOfPressure.Bad:
                #region Pressure Bad
                switch (foTemperature)
                {
                case forecastOfTemperature.Good:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(normalResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(goodResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                case forecastOfTemperature.Bad:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(badResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(badResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                case forecastOfTemperature.Normal:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(badResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(normalResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                default:
                    return(normalResult);
                }
                #endregion
                break;

            case forecastOfPressure.VeryBad:
                #region Pressure Very Bad
                switch (foTemperature)
                {
                case forecastOfTemperature.Good:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(badResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(badResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                case forecastOfTemperature.Bad:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(badResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(badResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                case forecastOfTemperature.Normal:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(badResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(badResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                default:
                    return(normalResult);
                }
                #endregion
                break;

            case forecastOfPressure.Normal:
                #region Pressure Normal
                switch (foTemperature)
                {
                case forecastOfTemperature.Good:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(normalResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(goodResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                case forecastOfTemperature.Bad:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(badResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(normalResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                case forecastOfTemperature.Normal:
                    switch (foHumidity)
                    {
                    case forecastOfHumidity.Bad:
                        return(badResult);

                        break;

                    case forecastOfHumidity.Normal:
                        return(normalResult);

                        break;

                    default:
                        return(normalResult);
                    }
                    break;

                default:
                    return(normalResult);
                }
                #endregion
                break;

            default:
                return(normalResult);
            }
        }