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

[GWELLS-2011] FEATURE** Create file count in database for searching #2057

Merged
merged 13 commits into from
Nov 20, 2023
Merged
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,35 @@ Then, run the application with Docker:
cd gwells
docker-compose up
```
### Connecting to Minio

For gwells to interact with your local instance of Min.IO add the appropriate settings to your local machines `HOSTS` file:

For gwells to interact with your local instance of Min.IO add the appropriate settings to your local machines HOSTS file:
```
127.0.0.1 minio-public
127.0.0.1 minio-private
```

### Connecting to PGAdmin

> Information in this section reflects docker-compose as of `Nov 8th, 2023`

PG Admin is setup in the `docker-compose up` and requires no additional installations

Steps:
1. connect to Pgadmin through [localhost](http://localhost:5050)
1. Login using username: `[email protected]`, password: `admin`.
1. Right click `Server` -> `Register` -> `Server`
1. Enter any meaningful name in `Name`
1. Under the `Connection` tab supply the following values

|Field|Value|
| --- | --- |
| Host name / address | `db`
| Port | `5432` |
| Username | `gwells` |
| Password | `test1` |

Visit the following links to browse the API and frontend applications:

* Django REST API development server: http://localhost:8000/gwells/api/
Expand Down
28 changes: 28 additions & 0 deletions app/backend/aquifers/fixtures/aquifers.json
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,13 @@
"geom": "POINT(-125.376319 52.528545)"
}
},
{
"model": "wells.wellattachment",
"pk": 100123,
"fields": {
"well_tag_number": 100123
}
},
{
"model": "wells.well",
"pk": 100124,
Expand Down Expand Up @@ -1105,6 +1112,13 @@
"geom": "POINT(-125.351850 52.461419)"
}
},
{
"model": "wells.wellattachment",
"pk": 100124,
"fields": {
"well_tag_number": 100124
}
},
{
"model": "wells.well",
"pk": 100125,
Expand Down Expand Up @@ -1223,6 +1237,13 @@
"geom": "POINT(-125.361842 52.476454)"
}
},
{
"model": "wells.wellattachment",
"pk": 100125,
"fields": {
"well_tag_number": 100125
}
},
{
"model": "wells.well",
"pk": 117042,
Expand Down Expand Up @@ -1340,6 +1361,13 @@
"geom": "POINT(-125.381245 52.466459)"
}
},
{
"model": "wells.wellattachment",
"pk": 117042,
"fields": {
"well_tag_number": 117042
}
},
{
"model": "aquifers.verticalaquiferextent",
"pk": "1",
Expand Down
42 changes: 42 additions & 0 deletions app/backend/gwells/fixtures/wellsearch.json
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,13 @@
"geom": "POINT(-122.540000 49.260000)"
}
},
{
"model": "wells.wellattachment",
"pk": 123,
"fields": {
"well_tag_number": 123
}
},
{
"model": "wells.well",
"pk": 112316,
Expand Down Expand Up @@ -962,6 +969,13 @@
"geom": "POINT(-122.540000 49.200000)"
}
},
{
"model": "wells.wellattachment",
"pk": 112316,
"fields": {
"well_tag_number": 112316
}
},
{
"model": "wells.well",
"pk": 113169,
Expand Down Expand Up @@ -1076,6 +1090,13 @@
"geom": "POINT(-122.580000 49.230000)"
}
},
{
"model": "wells.wellattachment",
"pk": 113169,
"fields": {
"well_tag_number": 113169
}
},
{
"model": "wells.well",
"pk": 112286,
Expand Down Expand Up @@ -1190,6 +1211,13 @@
"geom": "POINT(-122.590000 49.250000)"
}
},
{
"model": "wells.wellattachment",
"pk": 112286,
"fields": {
"well_tag_number": 112286
}
},
{
"model": "wells.well",
"pk": 20143,
Expand Down Expand Up @@ -1307,6 +1335,13 @@
"geom": "POINT(-125.360830 52.456449)"
}
},
{
"model": "wells.wellattachment",
"pk": 20143,
"fields": {
"well_tag_number": 20143
}
},
{
"model": "wells.well",
"pk": 216265,
Expand Down Expand Up @@ -1446,5 +1481,12 @@
"decommission_sealant_material": null,
"geom": null
}
},
{
"model": "wells.wellattachment",
"pk": 216265,
"fields": {
"well_tag_number": 216265
}
}
]
4 changes: 3 additions & 1 deletion app/backend/wells/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
WaterQualityColour,
FilterPackMaterialSizeCode,
FilterPackMaterialCode,
Well
Well,
WellAttachment
)
from gwells.models.lithology import (
LithologyColourCode, LithologyHardnessCode,
Expand All @@ -39,3 +40,4 @@
admin.site.register(FilterPackMaterialSizeCode)
admin.site.register(FilterPackMaterialCode)
admin.site.register(Well)
admin.site.register(WellAttachment)
24 changes: 24 additions & 0 deletions app/backend/wells/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
MAX_EXPORT_COUNT = 999999
MAX_LOCATION_COUNT = 999999

WELL_TAGS_PUBLIC = [
{ "text": "Well Construction Report", "value": "Well Construction" },
{ "text": "Well Alteration Report", "value": "Well Alteration" },
{ "text": "Well Decommission Report", "value": "Well Decommission" },
{ "text": "Pictures/Photos", "value": "Photo" },
{ "text": "Well Pump Installation Report", "value": "Well Pump Installation" },
{ "text": "Pumping Test Report", "value": "Pumping Test" },
{ "text": "Map(s)", "value": "Map" },
{ "text": "Other", "value": "Additional Well Details" },
]


WELL_TAGS_PRIVATE = [
{ "text": "Well Inspection Report", "value": "Well Inspection" },
{ "text": "Confirmation/Alternative Specifications", "value": "Alternative Specs" },
{ "text": "Water Quality Report", "value": "Water Quality" },
{ "text": "Health Authority Report", "value": "Health Authority" },
{ "text": "Consultant's Report", "value": "Consultants Report" },
]

WELL_TAGS = []
WELL_TAGS.extend(WELL_TAGS_PUBLIC.copy())
WELL_TAGS.extend(WELL_TAGS_PRIVATE.copy())
36 changes: 36 additions & 0 deletions app/backend/wells/migrations/0142_auto_20231109_2145.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 2.2.28 on 2023-11-09 21:45

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('wells', '0141_add_drinking_water_protection_area_ind'),
]

operations = [
migrations.CreateModel(
name='WellAttachment',
fields=[
('well_construction', models.PositiveSmallIntegerField(default=0)),
('well_alteration', models.PositiveSmallIntegerField(default=0)),
('well_decommission', models.PositiveSmallIntegerField(default=0)),
('photo', models.PositiveSmallIntegerField(default=0)),
('well_pump_installation', models.PositiveSmallIntegerField(default=0)),
('pumping_test', models.PositiveSmallIntegerField(default=0)),
('map', models.PositiveSmallIntegerField(default=0)),
('additional_well_details', models.PositiveSmallIntegerField(default=0)),
('well_inspection', models.PositiveSmallIntegerField(default=0)),
('alternative_specs', models.PositiveSmallIntegerField(default=0)),
('water_quality', models.PositiveSmallIntegerField(default=0)),
('health_authority', models.PositiveSmallIntegerField(default=0)),
('consultants_report', models.PositiveSmallIntegerField(default=0)),
('well_tag_number', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.PROTECT, to='wells.Well')),
],
options={
'db_table': 'well_attachment_count',
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.db import migrations, models

def populate_wells_with_attachment_table(apps, schema_editor):
A = apps.get_model('wells', 'Well')
B = apps.get_model('wells', 'WellAttachment')

for a_instance in A.objects.all():
if B.objects.filter(well_tag_number=a_instance):
pass # This entry already has a well attachment associated with it
else:
B.objects.create(well_tag_number=a_instance)

class Migration(migrations.Migration):

dependencies = [
('wells', '0142_auto_20231109_2145'),
]
operations = [
migrations.RunPython(populate_wells_with_attachment_table),
]
41 changes: 40 additions & 1 deletion app/backend/wells/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
WELL_STATUS_CODE_ALTERATION = 'ALTERATION'
WELL_STATUS_CODE_OTHER = 'OTHER'


class DecommissionMethodCode(CodeTableModel):
decommission_method_code = models.CharField(primary_key=True, max_length=10, editable=False,
verbose_name="Code")
Expand Down Expand Up @@ -2596,3 +2595,43 @@ def as_dict(self):
"analysis_method": self.analysis_method,
"comments": self.comments
}

class WellAttachment(models.Model):
well_tag_number = models.ForeignKey(Well, on_delete=models.PROTECT, blank=True, null = False)
# Public Tags
well_construction = models.PositiveSmallIntegerField(default=0)
well_alteration = models.PositiveSmallIntegerField(default=0)
well_decommission = models.PositiveSmallIntegerField(default=0)
photo = models.PositiveSmallIntegerField(default=0)
well_pump_installation = models.PositiveSmallIntegerField(default=0)
pumping_test = models.PositiveSmallIntegerField(default=0)
map = models.PositiveSmallIntegerField(default=0)
additional_well_details = models.PositiveSmallIntegerField(default=0)
# Private Tags
well_inspection = models.PositiveSmallIntegerField(default=0)
alternative_specs = models.PositiveSmallIntegerField(default=0)
water_quality = models.PositiveSmallIntegerField(default=0)
health_authority = models.PositiveSmallIntegerField(default=0)
consultants_report = models.PositiveSmallIntegerField(default=0)
class Meta:
db_table = "well_attachment_count"


def __str__(self):
template = "{} File count: {}\n"
return_string = "Files for WTN: {}\n".format(self.well_tag_number)
return_string += template.format('Well Construction',self.well_construction)
return_string += template.format('Well Alteration',self.well_alteration)
return_string += template.format('Well Decommission',self.well_decommission)
return_string += template.format('Well Photos',self.photo)
return_string += template.format('Well Pump Installations',self.well_pump_installation)
return_string += template.format('Pumping Test',self.pumping_test)
return_string += template.format('Map',self.map)
return_string += template.format('Additional Detail',self.additional_well_details)
return_string += template.format('Well Inspections',self.well_inspection)
return_string += template.format('Alternative Specs',self.alternative_specs)
return_string += template.format('Water Quality',self.water_quality)
return_string += template.format('Health Authority',self.health_authority)
return_string += "{} File count: {}".format('Consultants Report',self.consultants_report)

return return_string
4 changes: 3 additions & 1 deletion app/backend/wells/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
WELL_ACTIVITY_CODE_CONSTRUCTION, WELL_ACTIVITY_CODE_DECOMMISSION, WELL_ACTIVITY_CODE_LEGACY,\
WELL_ACTIVITY_CODE_STAFF_EDIT
import submissions.serializers
from wells.models import Well, ActivitySubmission, ActivitySubmissionLinerPerforation, FieldsProvided, \
from wells.models import Well, ActivitySubmission, ActivitySubmissionLinerPerforation, FieldsProvided, WellAttachment, \
WellStatusCode, WELL_STATUS_CODE_CONSTRUCTION,\
WELL_STATUS_CODE_DECOMMISSION, WELL_STATUS_CODE_ALTERATION, WELL_STATUS_CODE_OTHER, LithologyDescription,\
Casing, Screen, LinerPerforation, DecommissionDescription, LithologyDescription, AquiferParameters
Expand Down Expand Up @@ -212,11 +212,13 @@ def process(self, filing_number) -> Well:
create_user=submission.create_user,
create_date=submission.create_date,
update_date=submission.update_date)

# If there's no well as yet - then this necessarily has to be the 1st submission, so we just
# re-query it as a collection, and call stack.
submissions = ActivitySubmission.objects.filter(filing_number=filing_number)
well = self._stack(submissions, well)
submission.well = well
WellAttachment.objects.create(well_tag_number=well)
submission.save()
return well

Expand Down
4 changes: 4 additions & 0 deletions app/backend/wells/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
url(api_path_prefix() + r'/wells/(?P<tag>[0-9]+)/files$',
never_cache(views.ListFiles.as_view()), name='file-list'),

# Increment/Decrement count of files for a given well during uploads
url(api_path_prefix() + r'/wells/(?P<tag>[0-9]+)/sum$',
never_cache(views.FileSumView.as_view()), name='file-sums'),

# Extract files
url(api_path_prefix() + r'/wells/extracts$', views.ListExtracts.as_view(), name='extract-list'),

Expand Down
Loading