From ccf25c56e32fdaa29770cff7aee276f8262a3efa Mon Sep 17 00:00:00 2001 From: Arne de Laat Date: Sun, 27 Oct 2024 15:10:57 +0100 Subject: [PATCH] Enforce latitude and longitude limits in jobs Set value to 0 if is outside valid range. --- publicdb/histograms/jobs.py | 29 ++++++++++++++++++++--------- publicdb/histograms/models.py | 4 ++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/publicdb/histograms/jobs.py b/publicdb/histograms/jobs.py index d4618acb..e254dacd 100644 --- a/publicdb/histograms/jobs.py +++ b/publicdb/histograms/jobs.py @@ -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() diff --git a/publicdb/histograms/models.py b/publicdb/histograms/models.py index 29c26c13..bfc4cf27 100644 --- a/publicdb/histograms/models.py +++ b/publicdb/histograms/models.py @@ -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)