Skip to content

Commit f605694

Browse files
authored
Merge pull request #219 from Mosquito-Alert/enhance_fix_masking
Ensure fixes are being masked before save.
2 parents c61ca61 + 3d2b383 commit f605694

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 2.2.7 on 2024-03-15 14:13
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('tigaserver_app', '0051_report_non_editable'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='fix',
15+
name='masked_lat',
16+
field=models.FloatField(help_text='Latitude rounded down to nearest 0.025 decimal degree.'),
17+
),
18+
migrations.AlterField(
19+
model_name='fix',
20+
name='masked_lon',
21+
field=models.FloatField(help_text='Longitude rounded down to nearest 0.025 decimal degree.'),
22+
),
23+
]

tigaserver_app/models.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,6 +2885,9 @@ class Fix(TimeZoneModelMixin, models.Model):
28852885
"""
28862886
Location fix uploaded by user.
28872887
"""
2888+
2889+
GRID_SIZE = 0.025
2890+
28882891
user_coverage_uuid = models.CharField(blank=True, null=True, max_length=36, help_text='UUID randomly generated on '
28892892
'phone to identify each unique user, '
28902893
'but only within the coverage data so '
@@ -2903,9 +2906,8 @@ class Fix(TimeZoneModelMixin, models.Model):
29032906
'as ECMA '
29042907
'262 date time string (e.g. "2014-05-17T12:34:56'
29052908
'.123+01:00".')
2906-
masked_lon = models.FloatField(help_text='Longitude rounded down to nearest 0.5 decimal degree (floor(lon/.5)*.5)'
2907-
'.')
2908-
masked_lat = models.FloatField(help_text='Latitude rounded down to nearest 0.5 decimal degree (floor(lat/.5)*.5).')
2909+
masked_lon = models.FloatField(help_text=f'Longitude rounded down to nearest {GRID_SIZE} decimal degree.')
2910+
masked_lat = models.FloatField(help_text=f'Latitude rounded down to nearest {GRID_SIZE} decimal degree.')
29092911
mask_size = models.FloatField(null=True, blank=True, help_text='size of location mask used')
29102912
power = models.FloatField(null=True, blank=True, help_text='Power level of phone at time fix recorded, '
29112913
'expressed as proportion of full charge. Range: 0-1.')
@@ -2923,6 +2925,12 @@ def _get_latitude_for_timezone(self):
29232925
def _get_longitude_for_timezone(self):
29242926
return self.masked_lon
29252927

2928+
def save(self, *args, **kwargs):
2929+
# Force masking of lat/lon
2930+
self.masked_lon = round(floor(self.masked_lon / self.GRID_SIZE) * self.GRID_SIZE, 5)
2931+
self.masked_lat = round(floor(self.masked_lat / self.GRID_SIZE) * self.GRID_SIZE, 5)
2932+
2933+
super().save(*args, **kwargs)
29262934

29272935
class Meta:
29282936
verbose_name = "fix"

0 commit comments

Comments
 (0)