diff --git a/measures/__init__.py b/measures/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/measures/admin.py b/measures/admin.py new file mode 100644 index 0000000..b6c58e2 --- /dev/null +++ b/measures/admin.py @@ -0,0 +1,7 @@ +from django.contrib import admin +from .models import Measurement + +# Register your models here. +admin.site.register(Measurement) + + diff --git a/measures/apps.py b/measures/apps.py new file mode 100644 index 0000000..066c995 --- /dev/null +++ b/measures/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MeasureConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'measures' diff --git a/measures/migrations/0001_initial.py b/measures/migrations/0001_initial.py new file mode 100644 index 0000000..b3c9fca --- /dev/null +++ b/measures/migrations/0001_initial.py @@ -0,0 +1,42 @@ +# Generated by Django 4.2.16 on 2024-10-03 16:36 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('devices', '0001_initial'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Measurement', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('latitude', models.FloatField()), + ('longitude', models.FloatField()), + ('altitude', models.FloatField(blank=True, null=True)), + ('values', models.JSONField()), + ('dateTime', models.DateTimeField()), + ('accuracy', models.FloatField(blank=True, help_text='Accuracy of the measurement', null=True)), + ('unit', models.CharField(blank=True, help_text='Unit of measurement (e.g., Sieverts)', max_length=20, null=True)), + ('notes', models.TextField(blank=True, help_text='Optional notes or comments on the measurement', null=True)), + ('weather', models.JSONField(blank=True, help_text='Weather conditions during the measurement (if available)', null=True)), + ('measurement_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)), + ('device', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='devices.device')), + ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': 'Measurement', + 'verbose_name_plural': 'Measurements', + 'ordering': ['-dateTime'], + }, + ), + ] diff --git a/measures/migrations/__init__.py b/measures/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/measures/models.py b/measures/models.py new file mode 100644 index 0000000..1257bc8 --- /dev/null +++ b/measures/models.py @@ -0,0 +1,29 @@ +from django.db import models +from django.contrib.auth.models import User +from devices.models import Device +import uuid + +class Measurement(models.Model): + """ + Represents a measurement of gamma radiation performed by a device. + """ + device = models.ForeignKey('devices.Device', on_delete=models.CASCADE) # Link to the device used for the measurement + user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True) # User who performed the measurement + latitude = models.FloatField() # Latitude of the measurement + longitude = models.FloatField() # Longitude of the measurement + altitude = models.FloatField(blank=True, null=True) # Optional: Altitude of the measurement (if relevant) + values = models.JSONField() # JSON field to store radiation measurement values + dateTime = models.DateTimeField() # Time the measurement was taken + accuracy = models.FloatField(blank=True, null=True, help_text="Accuracy of the measurement") # Optional: Accuracy of the measurement + unit = models.CharField(max_length=20, blank=True, null=True, help_text="Unit of measurement (e.g., Sieverts)") # Optional: Unit of measurement + notes = models.TextField(blank=True, null=True, help_text="Optional notes or comments on the measurement") # Optional: Additional notes + weather = models.JSONField(blank=True, null=True, help_text="Weather conditions during the measurement (if available)") # Optional: Weather info + measurement_id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) # Unique ID for tracking the measurement + + def __str__(self): + return f"Measurement by {self.device} at {self.dateTime}" + + class Meta: + verbose_name = "Measurement" + verbose_name_plural = "Measurements" + ordering = ['-dateTime'] diff --git a/measures/tests.py b/measures/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/measures/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/measures/views.py b/measures/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/measures/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/openred/settings.py b/openred/settings.py index 02f335a..84aa572 100644 --- a/openred/settings.py +++ b/openred/settings.py @@ -49,6 +49,7 @@ # Custom apps 'devices', + 'measures', ] MIDDLEWARE = [