From 7e3ab2bcf52a6bcfe09ae5019c8d6d98ce2cbcdb Mon Sep 17 00:00:00 2001 From: Vincent Luczkow Date: Wed, 17 Aug 2022 23:36:50 -0700 Subject: [PATCH 1/2] Longitude and latitude added to location table --- .pre-commit-config.yaml | 3 +++ aukpy/create_tables.sql | 6 +++--- aukpy/db.py | 22 +++++++++++++++------- aukpy/queries.py | 1 - tests/perf_test.py | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 00040c1..5598d9e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,6 +4,9 @@ repos: hooks: - id: end-of-file-fixer - id: trailing-whitespace + - id: check-yaml + - id: check-toml + - id: check-added-large-files - repo: https://github.com/psf/black rev: 22.6.0 hooks: diff --git a/aukpy/create_tables.sql b/aukpy/create_tables.sql index a9c4662..19ff685 100644 --- a/aukpy/create_tables.sql +++ b/aukpy/create_tables.sql @@ -6,6 +6,8 @@ CREATE TABLE IF NOT EXISTS location_data ( state_code text, county text, county_code text, + longitude float, + latitude float, locality text, locality_id integer, locality_type text, @@ -13,7 +15,7 @@ CREATE TABLE IF NOT EXISTS location_data ( atlas_block text, bcr_code integer, iba_code text, - UNIQUE(country, country_code, state, state_code, county, county_code, locality, locality_id, locality_type, usfws_code, atlas_block) + UNIQUE(country, state, county, locality_id, usfws_code, atlas_block, longitude, latitude) ); CREATE TABLE IF NOT EXISTS bcrcode (id integer PRIMARY KEY, bcr_code text, UNIQUE(bcr_code)); @@ -63,8 +65,6 @@ CREATE TABLE IF NOT EXISTS sampling_event ( effort_area_ha float, duration_minutes integer, trip_comments text, - latitude float, - longitude float, all_species_reported integer, number_observers integer, UNIQUE(sampling_event_identifier) diff --git a/aukpy/db.py b/aukpy/db.py index 63759a1..9bb7859 100644 --- a/aukpy/db.py +++ b/aukpy/db.py @@ -229,6 +229,8 @@ class LocationWrapper(TableWrapper): "state_code", "county", "county_code", + "longitude", + "latitude", "locality", "locality_id", "locality_type", @@ -238,9 +240,17 @@ class LocationWrapper(TableWrapper): "iba_code", ) insert_query = """INSERT OR IGNORE INTO location_data - ('country', 'country_code', 'state', 'state_code', 'county', 'county_code', 'locality', 'locality_id', 'locality_type', 'usfws_code', 'atlas_block', 'bcr_code', 'iba_code') - VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""" - unique_columns = ("country", "state", "county", "locality_id", "atlas_block") + ('country', 'country_code', 'state', 'state_code', 'county', 'county_code', 'longitude', 'latitude', 'locality', 'locality_id', 'locality_type', 'usfws_code', 'atlas_block', 'bcr_code', 'iba_code') + VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""" + unique_columns = ( + "country", + "state", + "county", + "locality_id", + "atlas_block", + "longitude", + "latitude", + ) @classmethod def df_processing(cls, df: pd.DataFrame) -> pd.DataFrame: @@ -300,14 +310,12 @@ class SamplingWrapper(TableWrapper): "effort_area_ha", "duration_minutes", "trip_comments", - "latitude", - "longitude", "all_species_reported", "number_observers", ) insert_query = """INSERT OR IGNORE INTO sampling_event - (sampling_event_identifier, observation_date, time_observations_started, observer_id, effort_distance_km, effort_area_ha, duration_minutes, trip_comments, latitude, longitude, all_species_reported, number_observers) - VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + (sampling_event_identifier, observation_date, time_observations_started, observer_id, effort_distance_km, effort_area_ha, duration_minutes, trip_comments, all_species_reported, number_observers) + VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """ unique_columns = ("sampling_event_identifier",) diff --git a/aukpy/queries.py b/aukpy/queries.py index 7422e7b..8eb7f5c 100644 --- a/aukpy/queries.py +++ b/aukpy/queries.py @@ -8,7 +8,6 @@ Iterable, List, Optional, - Sequence, Union, Tuple, Any, diff --git a/tests/perf_test.py b/tests/perf_test.py index e56453e..4339c11 100644 --- a/tests/perf_test.py +++ b/tests/perf_test.py @@ -28,7 +28,7 @@ def check_usage(csv_file: Path): print(f"Size of observation: {res}") -@pytest.mark.skip +# @pytest.mark.skip def test_data_usage(): for csv_file in (SMALL, MEDIUM): check_usage(csv_file) From 2813fe7e296fe37eaffef9a1a788f55a185f33a2 Mon Sep 17 00:00:00 2001 From: Vincent Luczkow Date: Wed, 17 Aug 2022 23:40:18 -0700 Subject: [PATCH 2/2] Forgot to mark perf test as skip. Closes #67 --- tests/perf_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/perf_test.py b/tests/perf_test.py index 4339c11..e56453e 100644 --- a/tests/perf_test.py +++ b/tests/perf_test.py @@ -28,7 +28,7 @@ def check_usage(csv_file: Path): print(f"Size of observation: {res}") -# @pytest.mark.skip +@pytest.mark.skip def test_data_usage(): for csv_file in (SMALL, MEDIUM): check_usage(csv_file)