Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Eva readers with known aliases #31

Merged
merged 8 commits into from
Aug 12, 2024
31 changes: 30 additions & 1 deletion src/evagram/website/backend/api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Generated by Django 4.2.10 on 2024-07-20 15:05

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

Expand Down Expand Up @@ -42,6 +44,16 @@ class Migration(migrations.Migration):
'db_table': 'owners',
},
),
migrations.CreateModel(
name='Readers',
fields=[
('reader_id', models.AutoField(primary_key=True, serialize=False)),
('reader_name', models.CharField(unique=True)),
],
options={
'db_table': 'readers',
},
),
migrations.CreateModel(
name='Variables',
fields=[
Expand All @@ -59,27 +71,44 @@ class Migration(migrations.Migration):
fields=[
('experiment_id', models.AutoField(primary_key=True, serialize=False)),
('experiment_name', models.CharField(default='null')),
('create_date', models.DateTimeField(auto_now_add=True)),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.owners')),
],
options={
'db_table': 'experiments',
'unique_together': {('experiment_name', 'owner')},
},
),
migrations.CreateModel(
name='Aliases',
fields=[
('alias_id', models.AutoField(primary_key=True, serialize=False)),
('alias_name', models.CharField()),
('alias_value', models.CharField()),
('reader', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.readers')),
],
options={
'db_table': 'aliases',
},
),
migrations.CreateModel(
name='Plots',
fields=[
('plot_id', models.AutoField(primary_key=True, serialize=False)),
('plot_type', models.CharField(choices=[('SC', 'Scatter'), ('MS', 'Map Scatter'), ('MG', 'Map Gridded'), ('DN', 'Density'), ('HG', 'Histogram'), ('LN', 'Line')], default='SC', max_length=2)),
('div', models.CharField(blank=True, null=True)),
('script', models.CharField(blank=True, null=True)),
('begin_cycle_time', models.DateTimeField()),
('end_cycle_time', models.DateTimeField(null=True)),
('experiment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.experiments')),
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.groups')),
('observation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.observations')),
('reader', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.readers')),
('variable', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.variables')),
],
options={
'db_table': 'plots',
'unique_together': {('experiment', 'group', 'observation', 'variable')},
'unique_together': {('experiment', 'reader', 'observation', 'variable', 'group')},
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 4.2.10 on 2024-07-25 15:29

from django.db import migrations

READERS = [
'ioda_obs_space',
'soca_restart',
'jedi_log_space'
]

ALIASES = {
'ioda_obs_space': [
('Observation', 'Observation'),
('Group', 'Plots'),
('Variable', 'Variable'),
],
'soca_restart': [
('Observation', 'SOCA'),
('Group', 'SocaVars'),
('Variable', 'Variable'),
],
'jedi_log_space': [
('Observation', 'JediLog'),
('Group', 'Log Options'),
('Variable', 'Variable'),
],
}

def populate_readers_and_aliases(apps, schema_editor):
Reader = apps.get_model('api', 'Readers')
Alias = apps.get_model('api', 'Aliases')

for reader_name in READERS:
reader, created = Reader.objects.get_or_create(reader_name=reader_name)
for alias_name, alias_value in ALIASES[reader_name]:
Alias.objects.get_or_create(alias_name=alias_name, alias_value=alias_value, reader=reader)

class Migration(migrations.Migration):

dependencies = [
('api', '0001_initial'),
]

operations = [
migrations.RunPython(populate_readers_and_aliases, reverse_code=migrations.RunPython.noop),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.2.10 on 2024-07-29 14:09

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('api', '0002_populate_readers_and_aliases'),
]

operations = [
migrations.AlterField(
model_name='experiments',
name='create_date',
field=models.DateTimeField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name='experiments',
name='owner',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.owners'),
),
migrations.AlterField(
model_name='plots',
name='plot_type',
field=models.CharField(choices=[('scatter', 'Scatter Plot'), ('map_scatter', 'Map Scatter Plot'), ('map_gridded', 'Map Gridded'), ('density', 'Density Graph'), ('histogram', 'Histogram'), ('line', 'Line Graph')], null=True),
),
migrations.AddConstraint(
model_name='plots',
constraint=models.CheckConstraint(check=models.Q(('plot_type__in', ['scatter', 'map_scatter', 'map_gridded', 'density', 'histogram', 'line'])), name='valid_plot_type'),
),
]
84 changes: 62 additions & 22 deletions src/evagram/website/backend/api/models.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
from django.db import models
from django.utils import timezone
from django.db.models import Q


class Owners(models.Model):
owner_id = models.AutoField(primary_key=True)
first_name = models.CharField(null=True)
last_name = models.CharField(null=True)
username = models.CharField(null=False, unique=True, default="null")

class Meta:
db_table = 'owners'


class Experiments(models.Model):
experiment_id = models.AutoField(primary_key=True)
experiment_name = models.CharField(null=False, default="null")
owner = models.ForeignKey('Owners', models.CASCADE)
create_date = models.DateTimeField(default=timezone.now)
owner = models.ForeignKey('Owners', on_delete=models.PROTECT)

class Meta:
db_table = 'experiments'
unique_together = (('experiment_name', 'owner'),)


class Groups(models.Model):
group_id = models.AutoField(primary_key=True)
group_name = models.CharField(unique=True, null=False, default="null")
class Readers(models.Model):
reader_id = models.AutoField(primary_key=True)
reader_name = models.CharField(null=False, unique=True)

class Meta:
db_table = 'groups'
db_table = 'readers'


class Observations(models.Model):
observation_id = models.AutoField(primary_key=True)
observation_name = models.CharField(null=False, unique=True, default="null")

class Meta:
db_table = 'observations'


class Variables(models.Model):
Expand All @@ -29,33 +50,52 @@ class Meta:
unique_together = (('variable_name', 'channel'),)


class Observations(models.Model):
observation_id = models.AutoField(primary_key=True)
observation_name = models.CharField(null=False, unique=True, default="null")
class Groups(models.Model):
group_id = models.AutoField(primary_key=True)
group_name = models.CharField(unique=True, null=False, default="null")

class Meta:
db_table = 'observations'
db_table = 'groups'


class Owners(models.Model):
owner_id = models.AutoField(primary_key=True)
first_name = models.CharField(null=True)
last_name = models.CharField(null=True)
username = models.CharField(null=False, unique=True, default="null")

class Meta:
db_table = 'owners'
class PlotType(models.TextChoices):
SCATTER = ("scatter", "Scatter Plot")
MAP_SCATTER = ("map_scatter", "Map Scatter Plot")
MAP_GRIDDED = ("map_gridded", "Map Gridded")
DENSITY = ("density", "Density Graph")
HISTOGRAM = ("histogram", "Histogram")
LINE = ("line", "Line Graph")


class Plots(models.Model):
plot_id = models.AutoField(primary_key=True)
plot_type = models.CharField(choices=PlotType.choices, null=True)
div = models.CharField(blank=True, null=True)
script = models.CharField(blank=True, null=True)
experiment = models.ForeignKey(Experiments, models.CASCADE)
group = models.ForeignKey(Groups, models.CASCADE)
observation = models.ForeignKey(Observations, models.CASCADE)
variable = models.ForeignKey(Variables, models.CASCADE)
begin_cycle_time = models.DateTimeField(null=False)
brandonzhu09 marked this conversation as resolved.
Show resolved Hide resolved
end_cycle_time = models.DateTimeField(null=True)
experiment = models.ForeignKey(Experiments, on_delete=models.CASCADE)
reader = models.ForeignKey(Readers, on_delete=models.CASCADE)
observation = models.ForeignKey(Observations, on_delete=models.CASCADE)
variable = models.ForeignKey(Variables, on_delete=models.CASCADE)
group = models.ForeignKey(Groups, on_delete=models.CASCADE)

class Meta:
db_table = 'plots'
unique_together = (('experiment', 'group', 'observation', 'variable'),)
unique_together = (('experiment', 'reader', 'observation', 'variable', 'group'),)
constraints = [
models.CheckConstraint(
check=Q(plot_type__in=PlotType.values),
name='valid_plot_type'
),
]


class Aliases(models.Model):
alias_id = models.AutoField(primary_key=True)
alias_name = models.CharField(null=False)
alias_value = models.CharField(null=False)
reader = models.ForeignKey(Readers, on_delete=models.CASCADE)

class Meta:
db_table = 'aliases'
21 changes: 16 additions & 5 deletions src/evagram/website/backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class OwnerSerializer(serializers.ModelSerializer):
key = serializers.ModelField(model_field=Owners()._meta.get_field('owner_id'))
value = serializers.ModelField(model_field=Owners()._meta.get_field('owner_id'))
content = serializers.ModelField(model_field=Owners()._meta.get_field('username'))
type = models.CharField(default='owner')
serial_type = models.CharField(default='owners')

class Meta:
model = Owners
Expand All @@ -19,18 +19,29 @@ class ExperimentSerializer(serializers.ModelSerializer):
key = serializers.ModelField(model_field=Experiments()._meta.get_field('experiment_id'))
value = serializers.ModelField(model_field=Experiments()._meta.get_field('experiment_id'))
content = serializers.ModelField(model_field=Experiments()._meta.get_field('experiment_name'))
type = models.CharField(default='experiment')
serial_type = models.CharField(default='experiments')

class Meta:
model = Experiments
fields = ['key', 'value', 'content', 'experiment_id', 'experiment_name']


class ReaderSerializer(serializers.ModelSerializer):
key = serializers.ModelField(model_field=Readers()._meta.get_field('reader_id'))
value = serializers.ModelField(model_field=Readers()._meta.get_field('reader_id'))
content = serializers.ModelField(model_field=Readers()._meta.get_field('reader_name'))
serial_type = models.CharField(default='readers')

class Meta:
model = Readers
fields = ['key', 'value', 'content', 'reader_id', 'reader_name']


class ObservationSerializer(serializers.ModelSerializer):
key = serializers.ModelField(model_field=Observations()._meta.get_field('observation_id'))
value = serializers.ModelField(model_field=Observations()._meta.get_field('observation_id'))
content = serializers.ModelField(model_field=Observations()._meta.get_field('observation_name'))
type = models.CharField(default='observation')
serial_type = models.CharField(default='observations')

class Meta:
model = Observations
Expand All @@ -41,7 +52,7 @@ class VariableSerializer(serializers.ModelSerializer):
key = serializers.ModelField(model_field=Variables()._meta.get_field('variable_id'))
value = serializers.ModelField(model_field=Variables()._meta.get_field('variable_id'))
content = serializers.ModelField(model_field=Variables()._meta.get_field('variable_name'))
type = models.CharField(default='variable')
serial_type = models.CharField(default='variables')

class Meta:
model = Variables
Expand All @@ -52,7 +63,7 @@ class GroupSerializer(serializers.ModelSerializer):
key = serializers.ModelField(model_field=Groups()._meta.get_field('group_id'))
value = serializers.ModelField(model_field=Groups()._meta.get_field('group_id'))
content = serializers.ModelField(model_field=Groups()._meta.get_field('group_name'))
type = models.CharField(default='group')
serial_type = models.CharField(default='groups')

class Meta:
model = Groups
Expand Down
Loading
Loading