Skip to content

Commit

Permalink
Added models and admin for measures
Browse files Browse the repository at this point in the history
  • Loading branch information
frasanz committed Oct 3, 2024
1 parent b3c6681 commit eb4304a
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 0 deletions.
Empty file added measures/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions measures/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from .models import Measurement

# Register your models here.
admin.site.register(Measurement)


6 changes: 6 additions & 0 deletions measures/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class MeasureConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'measures'
42 changes: 42 additions & 0 deletions measures/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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'],
},
),
]
Empty file added measures/migrations/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions measures/models.py
Original file line number Diff line number Diff line change
@@ -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']
3 changes: 3 additions & 0 deletions measures/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions measures/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
1 change: 1 addition & 0 deletions openred/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

# Custom apps
'devices',
'measures',
]

MIDDLEWARE = [
Expand Down

0 comments on commit eb4304a

Please sign in to comment.