mother fucking sensors

This commit is contained in:
Alessio 2025-08-02 11:53:58 +02:00
parent 98794751d0
commit 789640998a
8 changed files with 902 additions and 5 deletions

View file

@ -44,6 +44,13 @@ class DataOverlay(TitledMixin, AccessRestrictionMixin, models.Model):
verbose_name=_('Editor Access Restriction'),
on_delete=models.PROTECT)
# Generic sensor data configuration
data_source_url = models.URLField(blank=True, null=True, verbose_name=_('Data Source URL'),
help_text=_('URL to scrape sensor data from'))
sensor_config: Optional[dict] = SchemaField(schema=dict, blank=True, null=True,
verbose_name=_('Sensor Configuration'),
help_text=_('JSON configuration for sensor data mapping and processing'))
class Meta:
verbose_name = _('Data Overlay')
verbose_name_plural = _('Data Overlays')
@ -72,6 +79,22 @@ class DataOverlayFeature(TitledMixin, LevelGeometryMixin, models.Model):
null=True,
default=None,
verbose_name=_('extra data (JSON object)'))
# Generic sensor fields
sensor_id = models.CharField(max_length=100, blank=True, null=True, verbose_name=_('Sensor ID'))
sensor_type = models.CharField(max_length=50, blank=True, null=True, verbose_name=_('Sensor Type'),
help_text=_('Type of sensor: temperature, humidity, co2, etc.'))
sensor_value = models.FloatField(blank=True, null=True, verbose_name=_('Sensor Value'))
sensor_unit = models.CharField(max_length=20, blank=True, null=True, verbose_name=_('Sensor Unit'),
help_text=_('Unit of measurement: °C, %, ppm, etc.'))
coordinates_x = models.FloatField(blank=True, null=True, verbose_name=_('X Coordinate'),
help_text=_('X coordinate in c3nav coordinate system'))
coordinates_y = models.FloatField(blank=True, null=True, verbose_name=_('Y Coordinate'),
help_text=_('Y coordinate in c3nav coordinate system'))
last_updated = models.DateTimeField(blank=True, null=True, verbose_name=_('Last Updated'))
sensor_data: Optional[dict] = SchemaField(schema=dict, blank=True, null=True,
verbose_name=_('Raw Sensor Data'),
help_text=_('Raw data from sensor for debugging and additional info'))
def to_geojson(self, instance=None) -> dict:
result = {