Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Code With Us QaQc Dashboard Dec 2023 #2097

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*.tar
*.zip
!regional_areas.zip
!qaqc_well_data.zip

# Logs and databases #
######################
Expand Down
32 changes: 28 additions & 4 deletions app/backend/aquifers/fixtures/aquifers.json
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,13 @@
"hydro_fracturing_yield_increase": null,
"decommission_sealant_material": "CONCRETE",
"decommission_backfill_material": "test",
"geom": "POINT(-125.376319 52.528545)"
"geom": "POINT(-125.376319 52.528545)",
"distance_to_pid": "123.45",
"geocode_distance": "543.21",
"score_address": "78.90",
"score_city": "56.78",
"cross_referenced": false,
"natural_resource_region": "Northeast"
}
},
{
Expand Down Expand Up @@ -1109,7 +1115,13 @@
"hydro_fracturing_yield_increase": null,
"decommission_sealant_material": "CONCRETE",
"decommission_backfill_material": "test",
"geom": "POINT(-125.351850 52.461419)"
"geom": "POINT(-125.351850 52.461419)",
"distance_to_pid": "234.56",
"geocode_distance": "654.32",
"score_address": "89.01",
"score_city": "67.89",
"cross_referenced": true,
"natural_resource_region": "Northeast"
}
},
{
Expand Down Expand Up @@ -1234,7 +1246,13 @@
"hydro_fracturing_yield_increase": null,
"decommission_sealant_material": "CONCRETE",
"decommission_backfill_material": "test",
"geom": "POINT(-125.361842 52.476454)"
"geom": "POINT(-125.361842 52.476454)",
"distance_to_pid": "345.67",
"geocode_distance": "765.43",
"score_address": "90.12",
"score_city": "78.90",
"cross_referenced": false,
"natural_resource_region": "Northeast"
}
},
{
Expand Down Expand Up @@ -1358,7 +1376,13 @@
"hydro_fracturing_yield_increase": null,
"decommission_sealant_material": "CONCRETE",
"decommission_backfill_material": "test",
"geom": "POINT(-125.381245 52.466459)"
"geom": "POINT(-125.381245 52.466459)",
"distance_to_pid": "456.78",
"geocode_distance": "876.54",
"score_address": "12.34",
"score_city": "89.01",
"cross_referenced": true,
"natural_resource_region": "Northeast"
}
},
{
Expand Down
48 changes: 42 additions & 6 deletions app/backend/gwells/fixtures/wellsearch.json
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,13 @@
"decommission_method": null,
"decommission_details": null,
"water_quality_characteristics": [],
"geom": "POINT(-122.540000 49.260000)"
"geom": "POINT(-122.540000 49.260000)",
"distance_to_pid": "123.45",
"geocode_distance": "543.21",
"score_address": "78.90",
"score_city": "56.78",
"cross_referenced": false,
"natural_resource_region": "Northeast"
}
},
{
Expand Down Expand Up @@ -966,7 +972,13 @@
"drawdown": "190.00",
"hydro_fracturing_performed": false,
"hydro_fracturing_yield_increase": null,
"geom": "POINT(-122.540000 49.200000)"
"geom": "POINT(-122.540000 49.200000)",
"distance_to_pid": "234.56",
"geocode_distance": "654.32",
"score_address": "89.01",
"score_city": "67.89",
"cross_referenced": true,
"natural_resource_region": "Northeast"
}
},
{
Expand Down Expand Up @@ -1087,7 +1099,13 @@
"drawdown": null,
"hydro_fracturing_performed": false,
"hydro_fracturing_yield_increase": null,
"geom": "POINT(-122.580000 49.230000)"
"geom": "POINT(-122.580000 49.230000)",
"distance_to_pid": "345.67",
"geocode_distance": "765.43",
"score_address": "90.12",
"score_city": "78.90",
"cross_referenced": false,
"natural_resource_region": "Northeast"
}
},
{
Expand Down Expand Up @@ -1208,7 +1226,13 @@
"drawdown": null,
"hydro_fracturing_performed": false,
"hydro_fracturing_yield_increase": null,
"geom": "POINT(-122.590000 49.250000)"
"geom": "POINT(-122.590000 49.250000)",
"distance_to_pid": "456.78",
"geocode_distance": "876.54",
"score_address": "12.34",
"score_city": "89.01",
"cross_referenced": true,
"natural_resource_region": "Northeast"
}
},
{
Expand Down Expand Up @@ -1332,7 +1356,13 @@
"hydro_fracturing_yield_increase": null,
"decommission_sealant_material": "CONCRETE",
"decommission_backfill_material": "test",
"geom": "POINT(-125.360830 52.456449)"
"geom": "POINT(-125.360830 52.456449)",
"distance_to_pid": "567.89",
"geocode_distance": "987.65",
"score_address": "23.45",
"score_city": "90.12",
"cross_referenced": false,
"natural_resource_region": "South Coast"
}
},
{
Expand Down Expand Up @@ -1479,7 +1509,13 @@
],
"decommission_backfill_material": null,
"decommission_sealant_material": null,
"geom": null
"geom": null,
"distance_to_pid": "678.90",
"geocode_distance": "109.87",
"score_address": "34.56",
"score_city": "12.34",
"cross_referenced": true,
"natural_resource_region": "Kootenay"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions app/backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ geojson==2.4.1
MarkupSafe>=2.0.1
djangorestframework-simplejwt==4.4.0
pyjwt>=2.0,<=2.4.0
thefuzz==0.19.0
geopandas==0.9.0
33 changes: 33 additions & 0 deletions app/backend/wells/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,36 @@
WELL_TAGS = []
WELL_TAGS.extend(WELL_TAGS_PUBLIC.copy())
WELL_TAGS.extend(WELL_TAGS_PRIVATE.copy())

# bc geocoder endpoint of interest
GEOCODER_ENDPOINT = "https://geocoder.api.gov.bc.ca/sites/nearest.json"
ADDRESS_COLUMNS = [
"fullAddress",
"siteName",
"unitDesignator",
"unitNumber",
"unitNumberSuffix",
"civicNumber",
"civicNumberSuffix",
"streetName",
"streetType",
"isStreetTypePrefix",
"streetDirection",
"isStreetDirectionPrefix",
"streetQualifier",
"localityName",
"localityType",
"electoralArea",
"provinceCode",
"locationPositionalAccuracy",
"locationDescriptor",
"siteID",
"blockID",
"fullSiteDescriptor",
"accessNotes",
"siteStatus",
"siteRetireDate",
"changeDate",
"isOfficial",
"distance",
]
Binary file added app/backend/wells/fixtures/qaqc_well_data.zip
Binary file not shown.
9 changes: 8 additions & 1 deletion app/backend/wells/fixtures/well_detail_fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,12 @@
"construction_start_date": null,
"well_status": null,
"filter_pack_thickness": null,
"well_yield": null}}
"well_yield": null,
"distance_to_pid": "123.45",
"geocode_distance": "543.21",
"score_address": "78.90",
"score_city": "56.78",
"cross_referenced": false,
"natural_resource_region": "Northeast"
}}
]
46 changes: 46 additions & 0 deletions app/backend/wells/migrations/0146_auto_20240105_qaqc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 2.2.28 on 2024-01-05 02:20

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import uuid


class Migration(migrations.Migration):

dependencies = [
('wells', '0145_auto_20231127_2105'),
]

operations = [
migrations.AddField(
model_name='well',
name='distance_to_pid',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, verbose_name='Distance to PID'),
),
migrations.AddField(
model_name='well',
name='geocode_distance',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, verbose_name='Geocode Distance'),
),
migrations.AddField(
model_name='well',
name='score_address',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, verbose_name='Score for Address'),
),
migrations.AddField(
model_name='well',
name='score_city',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True, verbose_name='Score for City'),
),
migrations.AddField(
model_name='well',
name='cross_referenced',
field=models.BooleanField(default=False, verbose_name='Cross Referenced'),
),
migrations.AddField(
model_name='well',
name='natural_resource_region',
field=models.CharField(default='', max_length=200),
),
]
55 changes: 55 additions & 0 deletions app/backend/wells/migrations/0147_auto_20240105_qaqc_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Generated by Django 2.2.28 on 2024-01-05 02:22

from django.db import migrations
import csv
import zipfile
import os

def import_well_data(apps, schema_editor):
Well = apps.get_model('wells', 'Well')
well_count = Well.objects.count()

# Dev well count threshold
dev_threshold = 100

if well_count < dev_threshold:
print("Skipping migration as it seems to be a non-production environment.")
return

wells_to_update = []

migration_dir = os.path.dirname(__file__)
with zipfile.ZipFile(os.path.join(migration_dir, '../fixtures/qaqc_well_data.zip'), 'r') as zip_file:
csv_filename = zip_file.namelist()[0]
with zip_file.open(csv_filename, 'r') as csvfile:
reader = csv.DictReader(csvfile.read().decode('utf-8').splitlines())

for row in reader:
try:
well = Well.objects.get(well_tag_number=row['well_tag_number'])
try:
well.geocode_distance = float(row['distance_geocode']) if row['distance_geocode'] else None
well.distance_to_pid = float(row['distance_to_matching_pid']) if row['distance_to_matching_pid'] else None
well.score_address = float(row['score_address']) if row['score_address'] else None
well.score_city = float(row['score_city']) if row['score_city'] else None
well.cross_referenced = row['xref_ind'] == 'True'
well.natural_resource_region = row['nr_region_name'] if row['nr_region_name'] else None
wells_to_update.append(well)
except ValueError as e:
print(f"Error processing well {row['well_tag_number']}: {e}")
print(row)
except Well.DoesNotExist:
print(f"Well with tag number {row['well_tag_number']} not found.")

Well.objects.bulk_update(wells_to_update, ['geocode_distance', 'distance_to_pid', 'score_address', 'score_city', 'cross_referenced', 'natural_resource_region'])


class Migration(migrations.Migration):

dependencies = [
('wells', '0146_auto_20240105_qaqc'),
]

operations = [
migrations.RunPython(import_well_data),
]
Loading