Skip to content

Commit

Permalink
Enforce latitude and longitude limits in jobs
Browse files Browse the repository at this point in the history
Set value to 0 if is outside valid range.
  • Loading branch information
153957 committed Oct 27, 2024
1 parent c113041 commit ccf25c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
29 changes: 20 additions & 9 deletions publicdb/histograms/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,16 +581,27 @@ def update_config(summary):

for config in configs[summary.num_config :]:
new_config = Configuration(summary=summary)
for var in vars(new_config):
if var in ['summary', 'id', 'summary_id'] or var[0] == '_':
pass
elif var in ['mas_version', 'slv_version']:
vars(new_config)[var] = blobs[config[var]]
elif var == 'timestamp':
ts = datetime.datetime.utcfromtimestamp(config[var])
vars(new_config)[var] = ts
for field in new_config._meta.get_fields():
field_name = field.name
if field_name in ['summary', 'id']:
continue
elif field_name in ['mas_version', 'slv_version']:
value = blobs[config[field_name]]
elif field_name == 'timestamp':
value = datetime.datetime.utcfromtimestamp(config[field_name])
elif field_name == 'gps_latitude':
if -90 <= config[field_name] <= 90:
value = config[field_name]
else:
value = 0
elif field_name == 'gps_longitude':
if -360 <= config[field_name] <= 360:
value = config[field_name]
else:
value = 0
else:
vars(new_config)[var] = config[var]
value = config[field_name]
setattr(new_config, field_name, value)
django.db.close_old_connections()
new_config.save()

Expand Down
4 changes: 2 additions & 2 deletions publicdb/histograms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def get_absolute_url(self):
class Configuration(models.Model):
summary = models.ForeignKey(Summary, models.CASCADE, related_name='configurations')
timestamp = models.DateTimeField()
gps_latitude = models.FloatField(min_value=-90, max_value=90)
gps_longitude = models.FloatField(min_value=-360, max_value=360)
gps_latitude = models.FloatField()
gps_longitude = models.FloatField()
gps_altitude = models.FloatField()
mas_version = models.CharField(max_length=40)
slv_version = models.CharField(max_length=40)
Expand Down

0 comments on commit ccf25c5

Please sign in to comment.