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

Ground observations data #1

Merged
merged 17 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
],
"django": true,
"justMyCode": true,
"env": {
"DJANGO_SETTINGS_MODULE": "core.settings.dev"
}
},
{
"command": "npm run serve",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"label": "React: Install dependencies",
"type": "shell",
"command": "npm install",
"command": "npm install --legacy-peer-deps",
"options": {
"cwd": "${workspaceFolder}/django_project/frontend"
},
Expand Down
29 changes: 28 additions & 1 deletion deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,25 @@ x-common-django:
&default-common-django
image: kartoza/${COMPOSE_PROJECT_NAME:-django_project}:${DJANGO_TAG:-1.0.0}
env_file:
- .env
- .env
environment:
- DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE:-core.settings.dev}

- ADMIN_USERNAME=${ADMIN_USERNAME:-admin}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin}
- ADMIN_EMAIL=${ADMIN_EMAIL:-admin@example.com}

- DATABASE_NAME=${DATABASE_NAME:-django}
- DATABASE_USERNAME=${DATABASE_USERNAME:-docker}
- DATABASE_PASSWORD=${DATABASE_PASSWORD:-docker}
- DATABASE_HOST=${DATABASE_HOST:-db}
- DATABASE_PORT=${DATABASE_PORT:-5432}
- REDIS_HOST=${REDIS_HOST:-redis}
- REDIS_PASSWORD=${REDIS_PASSWORD:-redis_password}

- RABBITMQ_HOST=${RABBITMQ_HOST:-rabbitmq}
- SENTRY_DSN=${SENTRY_DSN:-}
- SECRET_KEY=SECRET_KEY
volumes:
- static-data:/home/web/static
- media-data:/home/web/media
Expand All @@ -36,6 +54,15 @@ services:
- POSTGRES_USER=${DATABASE_USERNAME:-docker}
- POSTGRES_PASS=${DATABASE_PASSWORD:-docker}

dbbackups:
image: kartoza/postgis:14-3.3
volumes:
- data-volume:/backups
environment:
- POSTGRES_DBNAME=${DATABASE_NAME:-django}
- POSTGRES_USER=${DATABASE_USERNAME:-docker}
- POSTGRES_PASS=${DATABASE_PASSWORD:-docker}

django:
<<: *default-common-django
command: 'uwsgi --ini /uwsgi.conf'
Expand Down
9 changes: 7 additions & 2 deletions django_project/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'core.wsgi.application'

# import SECRET_KEY into current namespace
# noinspection PyUnresolvedReferences
from core.settings.secret import SECRET_KEY # noqa

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
Expand Down Expand Up @@ -123,6 +127,7 @@
'django.contrib.staticfiles',
'django.contrib.gis',
'django.contrib.messages',
'ground_observations',
)

SITE_ID = 1
Expand All @@ -143,9 +148,9 @@
LOGIN_URL = '/account/login/'
LOGIN_REDIRECT_URL = '/'

try:
"""try:
SECRET_KEY = os.environ['SECRET_KEY']
if SECRET_KEY in ['', "''"]:
raise Exception('SECRET_KEY is required in env.')
except KeyError:
raise Exception('SECRET_KEY is required in env.')
raise Exception('SECRET_KEY is required in env.')"""
8 changes: 4 additions & 4 deletions django_project/core/settings/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': os.environ['DATABASE_NAME'],
'USER': os.environ['DATABASE_USERNAME'],
'PASSWORD': os.environ['DATABASE_PASSWORD'],
'HOST': os.environ['DATABASE_HOST'],
'NAME': 'django',
'USER': 'docker',
'PASSWORD': 'docker',
'HOST': 'db',
'PORT': 5432,
'TEST_NAME': 'unittests',
}
Expand Down
3 changes: 2 additions & 1 deletion django_project/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"clean-webpack-plugin": "^4.0.0",
"css-loader": "^6.7.3",
"sass": "^1.60.0",
"ts-loader": "^9.4.2"
"ts-loader": "^9.4.2",
"webpack-dev-server": "^4.9.0"
}
}
Empty file.
3 changes: 3 additions & 0 deletions django_project/ground_observations/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions django_project/ground_observations/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class GroundObservationsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
meomancer marked this conversation as resolved.
Show resolved Hide resolved
name = 'ground_observations'
56 changes: 56 additions & 0 deletions django_project/ground_observations/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by Django 4.2.7 on 2024-06-20 07:46

import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Attribute',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('attribute_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('name', models.TextField()),
('description', models.TextField()),
],
),
migrations.CreateModel(
name='Provider',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('provider_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('name', models.TextField()),
('description', models.TextField()),
],
),
migrations.CreateModel(
name='Station',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('station_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('name', models.TextField()),
('country_ISO_A3', models.TextField()),
('geometry', django.contrib.gis.db.models.fields.PointField(srid=4326)),
('provider_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ground_observations.provider', to_field='provider_id')),
],
),
migrations.CreateModel(
name='Measurement',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('date', models.DateField()),
('value', models.FloatField()),
('attribute_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ground_observations.attribute', to_field='attribute_id')),
('station_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ground_observations.station', to_field='station_id')),
],
),
]
Empty file.
92 changes: 92 additions & 0 deletions django_project/ground_observations/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from django.db import models

# Create your models here.

from django.contrib.gis.db import models as gis_models
import uuid
danangmassandy marked this conversation as resolved.
Show resolved Hide resolved

class Provider(models.Model):
"""
Model representing a data provider.

Attributes:
provider_id (UUID): Unique identifier for the provider, generated automatically.
name (str): Name of the provider.
description (str): Description of the provider.
"""
provider_id = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
name = models.TextField()
description = models.TextField()

def __str__(self):
return self.name

class Attribute(models.Model):
"""
Model representing an attribute of a measurement.

Attributes:
attribute_id (UUID): Unique identifier for the attribute, generated automatically.
name (str): Name of the attribute.
description (str): Description of the attribute.
"""
attribute_id = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
name = models.TextField()
description = models.TextField()

def __str__(self):
return self.name

class Country(models.Model):
"""
Model representing a country.

Attributes:
name (str): Name of the country.
country_ISO_A3 (str): ISO A3 country code, unique.
geometry (Polygon): Polygon geometry representing the country boundaries.
"""
name = models.TextField()
country_ISO_A3 = models.TextField(unique=True)
geometry = gis_models.PolygonField(srid=4326)

def __str__(self):
danangmassandy marked this conversation as resolved.
Show resolved Hide resolved
return self.name

class Station(models.Model):
"""
Model representing a ground observation station.

Attributes:
station_id (UUID): Unique identifier for the station, generated automatically.
name (str): Name of the station.
country (ForeignKey): Foreign key referencing the Country model based on country_ISO_A3.
geometry (Point): Point geometry representing the location of the station.
provider_id (ForeignKey): Foreign key referencing the Provider model based on provider_id.
"""
station_id = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
name = models.TextField()
country = models.ForeignKey(Country, on_delete=models.CASCADE, to_field='country_ISO_A3', db_column='country_ISO_A3')
osundwajeff marked this conversation as resolved.
Show resolved Hide resolved
geometry = gis_models.PointField(srid=4326)
provider_id = models.ForeignKey(Provider, on_delete=models.CASCADE, to_field='provider_id')
osundwajeff marked this conversation as resolved.
Show resolved Hide resolved

def __str__(self):
return self.name

class Measurement(models.Model):
"""
Model representing a measurement taken at a station.

Attributes:
date (date): Date of the measurement.
value (float): Value of the measurement.
station_id (ForeignKey): Foreign key referencing the Station model based on station_id.
meomancer marked this conversation as resolved.
Show resolved Hide resolved
attribute_id (ForeignKey): Foreign key referencing the Attribute model based on attribute_id.
"""
date = models.DateField()
value = models.FloatField()
station_id = models.ForeignKey(Station, on_delete=models.CASCADE, to_field='station_id')
attribute_id = models.ForeignKey(Attribute, on_delete=models.CASCADE, to_field='attribute_id')

def __str__(self):
return f'{self.date} - {self.value}'
3 changes: 3 additions & 0 deletions django_project/ground_observations/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 django_project/ground_observations/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.
Loading