Skip to content

Commit d8839e0

Browse files
authored
Merge pull request #1 from GNS-Science/feature/hazard_solutions
Feature/hazard solutions
2 parents 019b4d7 + 9e5df9a commit d8839e0

21 files changed

+1817
-7
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
11
ref: https://docs.graphene-python.org/projects/django/en/latest/tutorial-relay/
2+
3+
4+
## Some Useful commands
5+
6+
### build an ERM model
7+
requires graphviz libraries installed `sudo apt install graphviz`
8+
9+
```
10+
poetry run python manage.py graph_models -o nshm_model.png nshm pipeline
11+
```
12+
13+
### Load data using djanog-extension helpers
14+
15+
```
16+
# build the script
17+
poetry run python manage.py dumpscript nshm.OpenquakeHazardTask >scripts/nshm_openquake_hazard_task.py
18+
# edit then run script ...
19+
poetry run python manage.py runscript scripts.nshm_openquake_hazard_task
20+
```
21+
22+
### Dump/Load data to json
23+
24+
```
25+
poetry run python manage.py dumpdata nshm.OpenquakeHazardTask -o pipeline/fixtures/oht.json --indent=2
26+
poetry run python manage.py loaddata pipeline/fixtures/oht.json
27+
```

nshm/admin.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
SourceLogicTree,
66
SourceLogicTreeComponent,
77
SourceLogicTreeWeightedComponent,
8-
GMCMLogicTree
8+
GMCMLogicTree,
9+
LocationList,
10+
HazardSolution,
911
)
1012

1113
class SeismicHazardModelAdmin(admin.ModelAdmin):
12-
fields = ["version", "notes", "source_logic_tree", "gmcm_logic_tree" ]
14+
fields = ["version", "notes", "source_logic_tree", "gmcm_logic_tree"]
15+
list_display = ["version", "notes", "source_logic_tree", "gmcm_logic_tree"]
1316

1417
class SourceLogicTreeAdmin(admin.ModelAdmin):
1518
fields = ["version", "notes"]
@@ -19,12 +22,26 @@ class GMCMLogicTreeAdmin(admin.ModelAdmin):
1922

2023
class SourceLogicTreeComponentAdmin(admin.ModelAdmin):
2124
fields = ["tag", "notes", "inversion_toshi_id", "background_toshi_id", "tectonic_region", "group" ]
25+
list_display = ["tag", "notes", "tectonic_region", "group" ]
26+
list_filter = ["tectonic_region", "group" ]
2227

2328
class SourceLogicTreeWeightedComponentAdmin(admin.ModelAdmin):
2429
fields = ["weight", "source_logic_tree", "source_logic_tree_component"]
2530

31+
class LocationListAdmin(admin.ModelAdmin):
32+
fields = ["list_id", "notes", "length"]
33+
34+
class HazardSolutionAdmin(admin.ModelAdmin):
35+
fields = ["solution_id", "created", "vs30", "notes", "location_lists", "slt_components"]
36+
list_display = ["solution_id", "created", "vs30", "notes"]
37+
list_filter = ["vs30", "created"]
38+
39+
2640
admin.site.register(SeismicHazardModel, SeismicHazardModelAdmin)
2741
admin.site.register(SourceLogicTree, SourceLogicTreeAdmin)
2842
admin.site.register(GMCMLogicTree, GMCMLogicTreeAdmin)
2943
admin.site.register(SourceLogicTreeComponent, SourceLogicTreeComponentAdmin)
30-
admin.site.register(SourceLogicTreeWeightedComponent, SourceLogicTreeWeightedComponentAdmin)
44+
admin.site.register(SourceLogicTreeWeightedComponent, SourceLogicTreeWeightedComponentAdmin)
45+
46+
admin.site.register(LocationList, LocationListAdmin)
47+
admin.site.register(HazardSolution, HazardSolutionAdmin)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Generated by Django 4.2.4 on 2023-08-27 22:19
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('nshm', '0010_rename_gmcm_logictree_gmcmlogictree'),
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name='LocationList',
15+
fields=[
16+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
17+
('list_id', models.CharField(max_length=10)),
18+
('notes', models.TextField(blank=True, null=True)),
19+
('length', models.SmallIntegerField()),
20+
],
21+
),
22+
migrations.CreateModel(
23+
name='HazardSolution',
24+
fields=[
25+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
26+
('solution_id', models.CharField(max_length=50)),
27+
('created', models.DateTimeField()),
28+
('vs30', models.SmallIntegerField()),
29+
('notes', models.TextField(blank=True, null=True)),
30+
('location_lists', models.ManyToManyField(related_name='hazard_solutions', to='nshm.locationlist')),
31+
('slt_components', models.ManyToManyField(related_name='hazard_solutions', to='nshm.sourcelogictreeweightedcomponent')),
32+
],
33+
),
34+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 4.2.4 on 2023-08-28 04:16
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('nshm', '0011_locationlist_hazardsolution'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='OpenquakeHazardTask',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('general_task_id', models.CharField(max_length=50)),
19+
('date', models.DateField()),
20+
('config_info', models.TextField(blank=True, null=True)),
21+
('notes', models.TextField(blank=True, null=True)),
22+
('part_of', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='hazard_tasks', to='nshm.seismichazardmodel')),
23+
],
24+
),
25+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Generated by Django 4.2.4 on 2023-08-28 22:40
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('nshm', '0012_openquakehazardtask'),
10+
]
11+
12+
operations = [
13+
migrations.DeleteModel(
14+
name='OpenquakeHazardTask',
15+
),
16+
]

nshm/models.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ class SourceLogicTree(models.Model):
1313
def __str__(self):
1414
return self.version
1515

16-
1716
class SourceLogicTreeComponent(models.Model):
1817
tag = models.CharField(max_length=50)
1918
notes = models.TextField(null=True, blank=True)
2019
inversion_toshi_id = models.CharField(max_length=50, null=False)
2120
background_toshi_id = models.CharField(max_length=50, null=True)
22-
tectonic_region = models.CharField(choices=TECTONIC_REGIONS.choices, null=False, max_length=10)
21+
tectonic_region = models.CharField(choices=TECTONIC_REGIONS.choices, null=False, max_length=10)
2322
group = models.CharField(choices=SLT_GROUP.choices, null=False, max_length=10)
2423

2524
def __str__(self):
@@ -43,6 +42,7 @@ class GMCMLogicTree(models.Model):
4342
def __str__(self):
4443
return self.version
4544

45+
4646
class SeismicHazardModel(models.Model):
4747
version = models.CharField(max_length=30)
4848
notes = models.TextField(null=True, blank=True)
@@ -55,3 +55,34 @@ class SeismicHazardModel(models.Model):
5555
def __str__(self):
5656
return self.version
5757

58+
class LocationList(models.Model):
59+
list_id = models.CharField(max_length=10)
60+
notes = models.TextField(null=True, blank=True)
61+
length = models.SmallIntegerField()
62+
63+
def __str__(self):
64+
return self.list_id
65+
66+
67+
class HazardSolution(models.Model):
68+
solution_id = models.CharField(max_length=50, null=False)
69+
created = models.DateTimeField(auto_now=False, auto_now_add=False)
70+
vs30 = models.SmallIntegerField()
71+
notes = models.TextField(null=True, blank=True)
72+
location_lists = models.ManyToManyField(
73+
LocationList, related_name='hazard_solutions')
74+
slt_components = models.ManyToManyField(
75+
SourceLogicTreeWeightedComponent,
76+
related_name='hazard_solutions')
77+
78+
79+
# class OpenquakeHazardTask(models.Model):
80+
# general_task_id = models.CharField(max_length=50, null=False)
81+
# date = models.DateField(auto_now=False, auto_now_add=False)
82+
# config_info = models.TextField(null=True, blank=True)
83+
# notes = models.TextField(null=True, blank=True)
84+
# part_of = models.ForeignKey(
85+
# SeismicHazardModel, related_name='hazard_tasks',null=True, blank=True, on_delete=models.SET_NULL)
86+
87+
# def __str__(self):
88+
# return self.general_task_id

nzshm_model_graphql_api/schema.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import graphene
22

33
import nshm.schema
4+
import pipeline.schema
45

5-
class Query(nshm.schema.Query, graphene.ObjectType):
6+
class Query(nshm.schema.Query, pipeline.schema.Query, graphene.ObjectType):
67
# This class will inherit from multiple Queries
78
# as we begin to add more apps to our project
89
pass

nzshm_model_graphql_api/settings.py

+8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
'django.contrib.messages',
3939
'django.contrib.staticfiles',
4040
'nshm',
41+
'pipeline',
4142
'graphene_django',
43+
'django_extensions',
4244
]
4345

4446
MIDDLEWARE = [
@@ -123,3 +125,9 @@
123125
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
124126

125127
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
128+
129+
# https://django-extensions.readthedocs.io/en/latest/graph_models.html
130+
GRAPH_MODELS = {
131+
'all_applications': False,
132+
'group_models': True,
133+
}

pipeline/__init__.py

Whitespace-only changes.

pipeline/admin.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.contrib import admin
2+
3+
from .models import (
4+
OpenquakeHazardTask
5+
)
6+
7+
class OpenquakeHazardTaskAdmin(admin.ModelAdmin):
8+
fields = ["general_task_id", "date", "notes", "config_info", "part_of"]
9+
list_display = ("general_task_id", "date", "notes", "config_info", "part_of")
10+
list_filter = ("date", "part_of")
11+
12+
admin.site.register(OpenquakeHazardTask, OpenquakeHazardTaskAdmin)

pipeline/apps.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class PipelineConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'pipeline'

0 commit comments

Comments
 (0)