public void MetStation_Construct_WithDB()
        {
            // Set up params for constructor
            int    rowID       = 1;
            string climwatid   = "ClimwatID";
            string stationName = "StationName";
            string countryID   = "CountryID";
            string countryName = "CountryName";
            double longitude   = 1.2;
            double latitude    = 3.4;
            double altitude    = 5.6;

            // Construct
            MetStation ms = new MetStation(rowID, climwatid, stationName, countryID, countryName, longitude, latitude, altitude);

            // Assert
            Assert.AreEqual(rowID, ms.rowid);
            Assert.AreEqual(climwatid, ms.climwatID);
            Assert.AreEqual(stationName, ms.stationName);
            Assert.AreEqual(countryID, ms.countryID);
            Assert.AreEqual(countryName, ms.countryName);
            Assert.AreEqual(longitude, ms.longitude);
            Assert.AreEqual(latitude, ms.latitude);
            Assert.AreEqual(altitude, ms.altitude);
        }
        public void MetStation_SeaLevelAdjust_NegHundredAltitude()
        {
            // Dumby MetStation
            MetStation ms       = new MetStation("a", "b", "c", "d", 1, 2, 0);
            double     altitude = -100;
            double     temp     = 5;
            double     adjusted = ms.AdjustTempForSeaLevel(temp, altitude);

            Assert.AreEqual(5.65, adjusted);
        }
        public void MetStation_AvgTemp_NoTempData()
        {
            MetStation m = new MetStation();

            // Add no weather data

            try {
                double avgMin = m.AvgTemp(m.weatherData);
                Assert.Fail("Excepted Exception");
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
        public void MetStation_AvgTemp_MoreThan12Months()
        {
            MetStation  m  = new MetStation();
            WeatherData wd = new WeatherData();

            // Add less than 12 weather data points
            for (int i = 1; i <= 13; i++)
            {
                m.weatherData.Add(wd);
            }

            try {
                double avgMin = m.AvgTemp(m.weatherData);
                Assert.Fail("Excepted Exception");
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
        public void MetStation_AvgTemp_12Months()
        {
            MetStation  m  = new MetStation("a", "b", "c", "d", 1, 2, 3);
            WeatherData wd = new WeatherData();

            wd.tempAvg = 2;
            // Add less than 12 weather data points
            for (int i = 1; i <= 12; i++)
            {
                m.weatherData.Add(wd);
            }

            try {
                double avgMin = m.AvgTemp(m.weatherData);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                Assert.Fail("No Exception Expected");
            }
        }
        public void MetStation_AvgTemp_AvgTestSimple()
        {
            MetStation  m  = new MetStation();
            WeatherData wd = new WeatherData();

            wd.tempAvg = 2;
            // Add less than 12 weather data points
            for (int i = 1; i <= 12; i++)
            {
                m.weatherData.Add(wd);
            }

            try {
                double avgMin = m.AvgTemp(m.weatherData);
                Assert.AreEqual(2, avgMin);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                Assert.Fail("No Exception Expected");
            }
        }
示例#7
0
        public MetStation GetMetStation(string stationName)
        {
            try {
                this.OpenConnection();
                string query = "SELECT * FROM stations WHERE station_name='" + stationName.Trim().ToUpper() + "'";

                MetStation       station = null;
                SqliteDataReader reader  = this.ExecuteQuery(query);

                while (reader.Read())
                {
                    station = new MetStation(reader.GetInt32(0), reader.GetString(1), reader.GetString(2),
                                             reader.GetString(3), reader.GetString(4), reader.GetDouble(5),
                                             reader.GetDouble(6), reader.GetDouble(7));
                }

                // Close Reader and Connection.
                // Important to do it here because GetWeatherData will Open/Close
                // Its own DB connection
                this.CloseConnection();
                reader.Close();
                reader = null;

                // No rows returned
                if (station == null)
                {
                    throw new Exception("No MetSations match those parameters.");
                }
                else
                {
                    // Get weather station data
                    ArrayList dataList = this.GetWeatherData(station.rowid);
                    station.weatherData = dataList;

                    return(station);
                }
            } catch (Exception e) {             // Could not connect to DB
                throw e;
            }
        }
示例#8
0
        public ArrayList GetMetStation(Polygon extreme)
        {
            // Set X/Y Min/Max based on extreme coords poly
            // Loop through for more redundancy
            double maxX = 0;
            double minX = 200;
            double maxY = 0;
            double minY = 200;


            // TODO: Refactor this statement
            foreach (Coord c in extreme.coords)
            {
                // Test min X
                if (c.X < minX)
                {
                    minX = c.X;
                }
                // Test max X
                if (c.X > maxX)
                {
                    maxX = c.X;
                }
                // Test min Y
                if (c.Y < minY)
                {
                    minY = c.Y;
                }
                // Test max Y
                if (c.Y > maxY)
                {
                    maxY = c.Y;
                }
            }

            // Set up Query
            string query = "SELECT * FROM stations WHERE (longitude BETWEEN " + minY + " AND " + maxY + ") AND (latitude BETWEEN " + minX + " AND " + maxX + ");";

            ArrayList  list    = new ArrayList();
            MetStation station = null;

            try {
                this.OpenConnection();
                SqliteDataReader reader = this.ExecuteQuery(query);

                while (reader.Read())
                {
                    station = new MetStation(reader.GetInt32(0), reader.GetString(1), reader.GetString(2),
                                             reader.GetString(3), reader.GetString(4), reader.GetDouble(5),
                                             reader.GetDouble(6), reader.GetDouble(7));
                    list.Add(station);
                }

                // Close reader and connection
                reader.Close();
                reader = null;
                this.CloseConnection();

                // No rows returned
                if (station == null)
                {
                    throw new Exception("No MetSations match those parameters.");
                }
                else                     // Add weather data to each station
                {
                    foreach (MetStation ms in list)
                    {
                        ms.weatherData = this.GetWeatherData(ms.rowid);
                    }
                }

                return(list);
            } catch (Exception e) {
                throw e;
            }
        }