Skip to content

Commit

Permalink
Clean migrations and improve query (#131)
Browse files Browse the repository at this point in the history
* Make GGMN as default of download data

* Clean migrations

* Added observed_properties_sensor

* Add time to measures
  • Loading branch information
meomancer authored Jun 3, 2024
1 parent e5a112e commit 1a517ea
Show file tree
Hide file tree
Showing 37 changed files with 125 additions and 1,017 deletions.
4 changes: 2 additions & 2 deletions admin/download_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

class DownloadRequestAdmin(admin.ModelAdmin):
list_display = (
'uuid', 'first_name', 'last_name', 'organization',
'request_at', 'first_name', 'last_name', 'organization',
'organization_types',
'email', 'country', 'request_at', 'age_hours'
'email', 'country', 'data_type', 'age_hours'
)
filter_horizontal = ('countries',)
search_fields = (
Expand Down
78 changes: 52 additions & 26 deletions fixtures/measurement_parameter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"cm",
"m",
"ft"
]
],
"default_unit": "m"
},
"Water depth [from the top of the well]": {
"description": "",
Expand All @@ -19,7 +20,8 @@
"cm",
"m",
"ft"
]
],
"default_unit": "m"
},
"Water level elevation a.m.s.l.": {
"description": "",
Expand All @@ -30,7 +32,8 @@
"cm",
"m",
"ft"
]
],
"default_unit": "m"
},
"EC": {
"description": "Electrical conductivity",
Expand All @@ -40,7 +43,8 @@
"units": [
"S/m",
"μS/cm"
]
],
"default_unit": "S/m"
},
"pH": {
"description": "Acidity",
Expand All @@ -58,7 +62,8 @@
"°C",
"°F",
"°K"
]
],
"default_unit": "°C"
},
"NO₃": {
"description": "Nitrate",
Expand All @@ -68,7 +73,8 @@
"units": [
"mg/L",
"ppm"
]
],
"default_unit": "mg/L"
},
"Cl": {
"description": "Cloride",
Expand All @@ -78,7 +84,8 @@
"units": [
"mg/L",
"ppm"
]
],
"default_unit": "mg/L"
},
"Ca": {
"description": "Calcium",
Expand All @@ -88,7 +95,8 @@
"units": [
"mg/L",
"ppm"
]
],
"default_unit": "mg/L"
},
"Mg": {
"description": "Magnesium",
Expand All @@ -98,7 +106,8 @@
"units": [
"mg/L",
"ppm"
]
],
"default_unit": "mg/L"
},
"Na": {
"description": "Sodium",
Expand All @@ -108,7 +117,8 @@
"units": [
"mg/L",
"ppm"
]
],
"default_unit": "mg/L"
},
"K": {
"description": "Potassium",
Expand All @@ -118,7 +128,8 @@
"units": [
"mg/L",
"ppm"
]
],
"default_unit": "mg/L"
},
"HCO₃": {
"description": "Bicarbonate",
Expand All @@ -128,7 +139,8 @@
"units": [
"mg/L",
"ppm"
]
],
"default_unit": "mg/L"
},
"SO₄": {
"description": "Sulfate",
Expand All @@ -138,7 +150,8 @@
"units": [
"mg/L",
"ppm"
]
],
"default_unit": "mg/L"
},
"TDS": {
"description": "Total dissolved solids",
Expand All @@ -148,7 +161,8 @@
"units": [
"mg/L",
"ppm"
]
],
"default_unit": "mg/L"
},
"FC": {
"description": "Fecal coliforms",
Expand All @@ -158,7 +172,8 @@
"units": [
"cfu per mL",
"cfu per 100 ml"
]
],
"default_unit": "cfu per mL"
},
"FS": {
"description": "Fecal streptococci",
Expand All @@ -168,7 +183,8 @@
"units": [
"cfu per mL",
"cfu per 100 ml"
]
],
"default_unit": "cfu per mL"
},
"E Coli": {
"description": "Escherichia coli",
Expand All @@ -178,7 +194,8 @@
"units": [
"cfu per mL",
"cfu per 100 ml"
]
],
"default_unit": "cfu per mL"
},
"F": {
"description": "Fluoride",
Expand All @@ -189,7 +206,8 @@
"ng/L",
"μg/L",
"mg/L"
]
],
"default_unit": "mg/L"
},
"As": {
"description": "Soluble arsenic",
Expand All @@ -200,7 +218,8 @@
"ng/L",
"μg/L",
"mg/L"
]
],
"default_unit": "mg/L"
},
"U": {
"description": "Soluble uranium",
Expand All @@ -211,7 +230,8 @@
"ng/L",
"μg/L",
"mg/L"
]
],
"default_unit": "mg/L"
},
"NH₄": {
"description": "Ammonium",
Expand All @@ -221,7 +241,8 @@
"units": [
"μg/L",
"mg/L"
]
],
"default_unit": "mg/L"
},
"Fe": {
"description": "Soluble iron",
Expand All @@ -230,7 +251,8 @@
],
"units": [
"mg/L"
]
],
"default_unit": "mg/L"
},
"Mn": {
"description": "Soluble manganese",
Expand All @@ -241,7 +263,8 @@
"ng/L",
"μg/L",
"mg/L"
]
],
"default_unit": "mg/L"
},
"P": {
"description": "orthophosphate",
Expand All @@ -251,7 +274,8 @@
"units": [
"μg/L",
"mg/L"
]
],
"default_unit": "mg/L"
},
"Yield": {
"description": "Yield",
Expand All @@ -263,7 +287,8 @@
"m³/h",
"m³/min",
"m³/s"
]
],
"default_unit": "m³/day"
},
"Spring discharge": {
"description": "Spring discharge",
Expand All @@ -275,6 +300,7 @@
"m³/h",
"m³/min",
"m³/s"
]
],
"default_unit": "m³/day"
}
}
2 changes: 1 addition & 1 deletion management/commands/refresh_materialized_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Command(BaseCommand):
help = 'Refresh materialized views'
views = [
'mv_well_ggmn', 'mv_well', 'mv_well_measurement',
'istsos.measures_group'
'istsos.measures_group', 'istsos.observed_properties_sensor'
]

def handle(self, *args, **options):
Expand Down
6 changes: 6 additions & 0 deletions management/commands/update_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,10 @@ def handle(self, *args, **options):
group.parameters.add(measurement)
units = Unit.objects.filter(name__in=value['units'])
measurement.units.add(*units)
try:
measurement.default_unit = Unit.objects.get(
name=value['default_unit']
)
except (Unit.DoesNotExist, KeyError):
pass
measurement.save()
11 changes: 1 addition & 10 deletions migrations/0002_initial_term_data.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json
import os
from django.db import migrations
from django.core.management import call_command


def import_data(apps, schema_editor):
# TODO :
# call command update_fixtures
pass
from django.db import migrations


class Migration(migrations.Migration):
Expand All @@ -19,5 +11,4 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(import_data),
]
19 changes: 0 additions & 19 deletions migrations/0003_view_well_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,5 @@ class Migration(migrations.Migration):
('gwml2', '0002_initial_term_data'),
]

sql = """
CREATE VIEW well_information AS
select w.id,
w.id as "ggis_id",
w.original_id as "original_id",
w.name as "name",
c.name as "country",
type.name as "feature_type",
hydro.aquifer_name as "aquifer_name",
concat('<a href="/groundwater/well/', w.id, '/edit">edit</a>') as "editor",
w.location
From well as w
LEFT JOIN country c on w.country_id = c.id
LEFT JOIN term_feature_type type on w.feature_type_id = type.id
LEFT JOIN hydrogeology_parameter as hydro on w.hydrogeology_parameter_id = hydro.id;
"""

operations = [
migrations.RunSQL('DROP VIEW IF EXISTS well_information;'),
migrations.RunSQL(sql)
]
18 changes: 0 additions & 18 deletions migrations/0013_view_well_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,5 @@ class Migration(migrations.Migration):
('gwml2', '0012_useruuid'),
]

sql = """
CREATE VIEW well_information AS
select w.id,
w.original_id as "original_id",
w.name as "name",
c.name as "country",
type.name as "feature_type",
admins || editors || viewers as "users",
concat('<a href="/groundwater/well/', w.id, '">detail</a>') as detail,
w.location
from well as w
LEFT JOIN organisation org on w.organisation_id = org.id
LEFT JOIN country c on w.country_id = c.id
LEFT JOIN term_feature_type type on w.feature_type_id = type.id;
"""

operations = [
migrations.RunSQL('DROP VIEW IF EXISTS well_information;'),
migrations.RunSQL(sql)
]
10 changes: 0 additions & 10 deletions migrations/0014_view_well_information_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,5 @@ class Migration(migrations.Migration):
dependencies = [
('gwml2', '0013_view_well_information'),
]

sql = """
CREATE VIEW well_information_uuid AS
select *
from well_information as w
LEFT JOIN user_uuid u ON w.users @> ARRAY [u.user_id];
"""

operations = [
migrations.RunSQL('DROP VIEW IF EXISTS well_information_uuid;'),
migrations.RunSQL(sql)
]
Loading

0 comments on commit 1a517ea

Please sign in to comment.