Skip to content

Commit

Permalink
Merge pull request #131 from ImperialCollegeLondon/new_meas2
Browse files Browse the repository at this point in the history
Adds the new Measurement model
  • Loading branch information
dalonsoa authored Jan 22, 2024
2 parents ee5ebb7 + e6c32c7 commit ef2bf4b
Show file tree
Hide file tree
Showing 5 changed files with 497 additions and 20 deletions.
16 changes: 14 additions & 2 deletions measurement/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin

from .models import Report
from .models import Measurement, Report

admin.site.site_header = "Paricia Administration - Measurements"

Expand All @@ -12,5 +12,17 @@ class MeasurementBaseAdmin(admin.ModelAdmin):

@admin.register(Report)
class ReportAdmin(MeasurementBaseAdmin):
list_display = ["report_type"] + MeasurementBaseAdmin.list_display
list_display = ["id", "report_type"] + MeasurementBaseAdmin.list_display[1:]
list_filter = ["report_type"] + MeasurementBaseAdmin.list_filter


@admin.register(Measurement)
class MeasurementAdmin(MeasurementBaseAdmin):
list_display = [
"id",
"is_validated",
"is_active",
"overwritten",
] + MeasurementBaseAdmin.list_display[1:]
list_filter = ["is_validated", "is_active"] + MeasurementBaseAdmin.list_filter
readonly_fields = [r for r in dir(Measurement) if r.startswith("raw_")]
160 changes: 160 additions & 0 deletions measurement/migrations/0006_measurement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Generated by Django 4.2.7 on 2024-01-17 15:08

import django.db.models.deletion
import timescale.db.models.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("station", "0003_alter_station_timezone"),
("variable", "0001_initial"),
("measurement", "0005_report"),
]

operations = [
migrations.CreateModel(
name="Measurement",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"time",
timescale.db.models.fields.TimescaleDateTimeField(interval="1 day"),
),
(
"value",
models.DecimalField(
decimal_places=6, max_digits=14, verbose_name="value"
),
),
(
"maximum",
models.DecimalField(
decimal_places=6,
max_digits=14,
null=True,
verbose_name="maximum",
),
),
(
"minimum",
models.DecimalField(
decimal_places=6,
max_digits=14,
null=True,
verbose_name="minimum",
),
),
(
"depth",
models.PositiveSmallIntegerField(null=True, verbose_name="depth"),
),
(
"direction",
models.DecimalField(
decimal_places=6,
max_digits=14,
null=True,
verbose_name="direction",
),
),
(
"raw_value",
models.DecimalField(
decimal_places=6,
editable=False,
max_digits=14,
null=True,
verbose_name="raw value",
),
),
(
"raw_maximum",
models.DecimalField(
decimal_places=6,
editable=False,
max_digits=14,
null=True,
verbose_name="raw maximum",
),
),
(
"raw_minimum",
models.DecimalField(
decimal_places=6,
editable=False,
max_digits=14,
null=True,
verbose_name="raw minimum",
),
),
(
"raw_direction",
models.DecimalField(
decimal_places=6,
editable=False,
max_digits=14,
null=True,
verbose_name="raw direction",
),
),
(
"raw_depth",
models.PositiveSmallIntegerField(
editable=False, null=True, verbose_name="raw depth"
),
),
(
"used_for_hourly",
models.BooleanField(
default=False,
verbose_name="Has data been used already for an hourly report?",
),
),
(
"is_validated",
models.BooleanField(
default=False, verbose_name="Has data been validated?"
),
),
(
"is_active",
models.BooleanField(default=True, verbose_name="Is data active?"),
),
(
"station",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="station.station",
verbose_name="Station",
),
),
(
"variable",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="variable.variable",
verbose_name="Variable",
),
),
],
options={
"abstract": False,
"default_permissions": (),
"indexes": [
models.Index(
fields=["station", "time", "variable"],
name="measurement_station_322060_idx",
)
],
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Generated by Django 4.2.7 on 2024-01-17 15:28

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("measurement", "0006_measurement"),
]

operations = [
migrations.AlterField(
model_name="measurement",
name="depth",
field=models.PositiveSmallIntegerField(
blank=True, null=True, verbose_name="depth"
),
),
migrations.AlterField(
model_name="measurement",
name="direction",
field=models.DecimalField(
blank=True,
decimal_places=6,
max_digits=14,
null=True,
verbose_name="direction",
),
),
migrations.AlterField(
model_name="measurement",
name="is_active",
field=models.BooleanField(default=True, verbose_name="Active?"),
),
migrations.AlterField(
model_name="measurement",
name="is_validated",
field=models.BooleanField(default=False, verbose_name="Validated?"),
),
migrations.AlterField(
model_name="measurement",
name="maximum",
field=models.DecimalField(
blank=True,
decimal_places=6,
max_digits=14,
null=True,
verbose_name="maximum",
),
),
migrations.AlterField(
model_name="measurement",
name="minimum",
field=models.DecimalField(
blank=True,
decimal_places=6,
max_digits=14,
null=True,
verbose_name="minimum",
),
),
migrations.AlterField(
model_name="measurement",
name="raw_depth",
field=models.PositiveSmallIntegerField(
blank=True, editable=False, null=True, verbose_name="raw depth"
),
),
migrations.AlterField(
model_name="measurement",
name="raw_direction",
field=models.DecimalField(
blank=True,
decimal_places=6,
editable=False,
max_digits=14,
null=True,
verbose_name="raw direction",
),
),
migrations.AlterField(
model_name="measurement",
name="raw_maximum",
field=models.DecimalField(
blank=True,
decimal_places=6,
editable=False,
max_digits=14,
null=True,
verbose_name="raw maximum",
),
),
migrations.AlterField(
model_name="measurement",
name="raw_minimum",
field=models.DecimalField(
blank=True,
decimal_places=6,
editable=False,
max_digits=14,
null=True,
verbose_name="raw minimum",
),
),
migrations.AlterField(
model_name="measurement",
name="raw_value",
field=models.DecimalField(
blank=True,
decimal_places=6,
editable=False,
max_digits=14,
null=True,
verbose_name="raw value",
),
),
migrations.AlterField(
model_name="measurement",
name="used_for_hourly",
field=models.BooleanField(default=False, verbose_name="Used for hourly?"),
),
migrations.AlterField(
model_name="report",
name="maximum",
field=models.DecimalField(
blank=True,
decimal_places=6,
max_digits=14,
null=True,
verbose_name="maximum",
),
),
migrations.AlterField(
model_name="report",
name="minimum",
field=models.DecimalField(
blank=True,
decimal_places=6,
max_digits=14,
null=True,
verbose_name="minimum",
),
),
migrations.AlterField(
model_name="report",
name="used_for_daily",
field=models.BooleanField(default=False, verbose_name="Used for daily?"),
),
migrations.AlterField(
model_name="report",
name="used_for_monthly",
field=models.BooleanField(default=False, verbose_name="Used for monthly?"),
),
]
Loading

0 comments on commit ef2bf4b

Please sign in to comment.