Ejemplo n.º 1
0
        //public static void BuildStations(List<Station> newStations)
        //{
        //    SQLiteConnection db = DatabaseCon.GetConnection();
        //    db.Open();
        //    SQLiteTransaction trans = db.BeginTransaction();
        //    try
        //    {
        //        for (int i = 0; i < newStations.Count; i++)
        //        {
        //            string adddataQuery = $"INSERT INTO Stations (Name, Identifier, Lattitude, Longitude) VALUES ('{newStations[i].Name}', {newStations[i].Identifier}, 1, 1)";
        //            db.Execute(adddataQuery, transaction: trans);
        //            //trans.Commit();
        //        }
        //        trans.Commit();
        //        Logging.Log("Stations added to the database");
        //    }
        //    catch(Exception ex)
        //    {
        //        Logging.LogEr("Station insertion Error", ex.Message);
        //        trans.Rollback();
        //    }
        //}
        public static void BuildReadings(List <ReadingDatav2> Buildlist)
        {
            SQLiteConnection db = DatabaseCon.GetConnection();

            db.Open();
            SQLiteTransaction trans = db.BeginTransaction();

            try
            {
                long LastDate;
                if (Database.CheckTableEmpty("Brisbane") == 0)
                {
                    LastDate = 0;
                }
                else
                {
                    LastDate = Database.QueryLastReading();
                }

                int count = 0;
                for (int i = Buildlist.Count - 1; i > 0; i--)
                {
                    ReadingDatav2 newData = new ReadingDatav2();
                    newData = Buildlist[i];
                    if (newData.ReadingTimeIdent > LastDate || LastDate == 0)
                    {
                        string insertLine = $"INSERT INTO Brisbane (StationID, StationName, ReadingTimeIdent, ReadingYear, ReadingMonth, ReadingDay, ReadingTime, ApparentTemperature, DeltaT, WindGustKmh, WindGustKt, ActualTemperature, DewPoint, PressureHpa, RainFallmm, RelativeHumidity, BasicForecast, WindDirection, WindSpeedKmh, WindSpeedKts)" +
                                            $" VALUES ({newData.StationID}, '{newData.StationName}', {newData.ReadingTimeIdent}, {newData.ReadingYear}, {newData.ReadingMonth}, {newData.ReadingDay}, {newData.ReadingTime}, {newData.ApparentTemperature}, {newData.DeltaT}, {newData.WindGustKmh}, {newData.WindGustKt}, {newData.ActualTemperature}, {newData.DewPoint}, {newData.PressureHpa}, '{newData.RainFallmm}', {newData.RelativeHumidity}, '{newData.BasicForecast}', '{newData.WindDirection}', {newData.WindSpeedKmh}, {newData.WindSpeedKt})";
                        db.Execute(insertLine);
                        count++;
                    }
                }
                trans.Commit();
                if (count == 0)
                {
                    Console.WriteLine("The database is up to date");
                    Logging.Log("The Database is up to date");
                }
                else
                {
                    Console.WriteLine(count + " Entries added to the database");
                    Logging.Log(count + " Entries added to the database");
                }
                Console.Read();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Logging.LogEr("Reading Insertion Error", ex.Message);
                trans.Rollback();
            }
        }
Ejemplo n.º 2
0
        public List <ReadingDatav2> MessyConversion(List <RawReadingData> RawList)
        {
            try
            {
                foreach (RawReadingData reading in RawList)
                {
                    ReadingDatav2 BetterReading  = new ReadingDatav2();
                    string        datetimeNumber = "";
                    BetterReading.StationID        = Convert.ToInt32(reading.wmo);
                    BetterReading.StationName      = reading.name;
                    BetterReading.ReadingTimeIdent = Convert.ToInt64(reading.aifstime_local);
                    datetimeNumber             = BetterReading.ReadingTimeIdent.ToString();
                    BetterReading.ReadingYear  = Convert.ToInt16(datetimeNumber.Substring(0, 4));
                    BetterReading.ReadingMonth = Convert.ToInt16(datetimeNumber.Substring(4, 2));
                    BetterReading.ReadingDay   = Convert.ToInt16(datetimeNumber.Substring(6, 2));
                    if (datetimeNumber.Substring(10, 1).Equals("0"))
                    {
                        BetterReading.ReadingTime = Convert.ToDouble(datetimeNumber.Substring(8, 2));
                    }
                    else
                    {
                        BetterReading.ReadingTime  = Convert.ToDouble(datetimeNumber.Substring(8, 2));
                        BetterReading.ReadingTime += 0.5;
                    }
                    if (reading.apparent_t == null || reading.apparent_t.Equals(""))
                    {
                        BetterReading.ApparentTemperature = 0.0f;
                    }
                    else
                    {
                        BetterReading.ApparentTemperature = float.Parse(reading.apparent_t);
                    }
                    if (reading.delta_t == null || reading.delta_t.Equals(""))
                    {
                        BetterReading.DeltaT = 0.0f;
                    }
                    else
                    {
                        BetterReading.DeltaT = float.Parse(reading.delta_t);
                    }
                    BetterReading.WindGustKmh = Convert.ToInt32(reading.gust_kmh);
                    BetterReading.WindGustKt  = Convert.ToInt32(reading.gust_kt);
                    if (reading.air_temp == null || reading.air_temp.Equals(""))
                    {
                        BetterReading.ActualTemperature = 0.0f;
                    }
                    else
                    {
                        BetterReading.ActualTemperature = float.Parse(reading.air_temp);
                    }
                    if (reading.dewpt == null || reading.dewpt.Equals(""))
                    {
                        BetterReading.DewPoint = 0.0f;
                    }
                    else
                    {
                        BetterReading.DewPoint = float.Parse(reading.dewpt);
                    }
                    if (reading.press == null || reading.press.Equals(""))
                    {
                        BetterReading.PressureHpa = 0.0f;
                    }
                    else
                    {
                        BetterReading.PressureHpa = float.Parse(reading.press);
                    }

                    string[] Rainfallsplit = reading.rain_trace.Split('"');
                    BetterReading.RainFallmm       = Convert.ToDouble(Rainfallsplit[0]);
                    BetterReading.RelativeHumidity = Convert.ToInt32(reading.rel_hum);
                    BetterReading.BasicForecast    = reading.weather;
                    BetterReading.WindDirection    = reading.wind_dir;
                    BetterReading.WindSpeedKmh     = Convert.ToInt32(reading.wind_spd_kmh);
                    BetterReading.WindSpeedKt      = Convert.ToInt32(reading.wind_spd_kt);
                    BetterList.Add(BetterReading);
                }
                Database.BuildReadings(BetterList);
                return(BetterList);
            }
            catch (Exception ex)
            {
                Logging.LogEr("MessyConversion ERROR", ex.Message);
                throw;
            }
        }