-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter out reports in the ocean or in the polar circle
- Loading branch information
Showing
5 changed files
with
147 additions
and
8 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
tigaserver_app/migrations/0074_add_report_location_is_masked.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Generated by Django 3.2.25 on 2024-12-18 16:05 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
from django.db.models.expressions import Func | ||
from django.db.models.functions import Abs | ||
|
||
|
||
def populate_report_location_is_masked(apps, schema_editor): | ||
|
||
Report = apps.get_model('tigaserver_app', 'Report') | ||
|
||
Report.objects.alias( | ||
latitude=Func( | ||
models.F('point'), | ||
function='ST_Y', | ||
output_field=models.FloatField() | ||
) | ||
).annotate( | ||
latitude_abs=Abs('latitude') | ||
).filter( | ||
models.Q(point__isnull=False) | ||
& ( | ||
models.Q(latitude_abs__gt=settings.POLAR_CIRCLE_LATITUDE) | ||
| models.Q(point__within=settings.OCEAN_GEOM) | ||
) | ||
).update( | ||
location_is_masked=True | ||
) | ||
|
||
|
||
def populate_report_history_location_is_masked(apps, schema_editor): | ||
Report = apps.get_model('tigaserver_app', 'Report') | ||
HistoricalReport = apps.get_model("tigaserver_app", "HistoricalReport") | ||
|
||
HistoricalReport.objects.filter( | ||
version_UUID__in=models.Subquery( | ||
Report.objects.filter(location_is_masked=True).values('pk') | ||
) | ||
).update( | ||
location_is_masked=True | ||
) | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('tigaserver_app', '0073_tigauser_lastlocation'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='report', | ||
name='location_is_masked', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.RunPython(populate_report_location_is_masked, migrations.RunPython.noop), | ||
migrations.AddField( | ||
model_name='historicalreport', | ||
name='location_is_masked', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.RunPython(populate_report_history_location_is_masked, migrations.RunPython.noop), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters