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

Chore: 270 schema models #1883

Merged
merged 28 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6127d09
chore: change baseSchema model to jsonSchema
dleard Jun 21, 2024
3fa88d8
test: update tests after base_schema -> json_schema change
dleard Jun 21, 2024
900c5c0
chore: move overlapping records validation into reusable function
dleard Jun 21, 2024
0ad0672
chore: add activity_json_schema model
dleard Jun 21, 2024
cf79ee1
test: refactor tests
dleard Jun 21, 2024
ee3bf87
chore: add activity_json_schema model
dleard Jun 25, 2024
503f2b9
chore: update init.py & fix migrations
dleard Jun 25, 2024
c92d365
chore: add unit, fuel & gas_type json schema intersection tables
dleard Jun 25, 2024
3aa24f8
chore: fix migrations
dleard Jun 25, 2024
0ac1071
chore: make prettier happy
dleard Jun 25, 2024
2fdb11c
chore: json schemas live in separate tables
dleard Jun 26, 2024
6093156
chore: add schema data
dleard Jun 26, 2024
0d8ebaa
chore: merge dependent schemas into source_type schema
dleard Jun 27, 2024
6c47641
chore: make prettier happy
dleard Jun 27, 2024
73e4647
chore: add types to util function paramaters
dleard Jun 28, 2024
1e4bfce
chore: delete migrations before rebase
dleard Jul 2, 2024
ee5d7a0
chore: fix borked rebase
dleard Jul 2, 2024
d07b0b2
chore: add prod & schema data migrations after rebase
dleard Jul 2, 2024
8c7fcd0
chore: make prettier happy
dleard Jul 2, 2024
34d523d
chore: fix defaults & dependencies after rebase
dleard Jul 2, 2024
182761f
chore: fix util function to handle objects without a source_type
dleard Jul 3, 2024
b78963c
test: add activity_json_schema test
dleard Jul 3, 2024
b605243
chore: make prettier happy
dleard Jul 3, 2024
41deaf3
chore: relax typing for save_self variable
dleard Jul 3, 2024
b203bdf
chore: fix copy paste error
dleard Jul 4, 2024
d0becb3
chore: relax typing for util function parameters
dleard Jul 4, 2024
dedd9e5
chore: remove unused import
dleard Jul 4, 2024
72b0ce5
chore: make prettier happy
dleard Jul 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def setUpTestData(cls):
("applicable_to", "applicable to", None, None),
("operations", "operation", None, None),
("configuration_elements", "configuration element", None, None),
("activity_source_type_base_schemas", "activity source type base schema", None, None),
]
cls.test_object = ReportingActivity.objects.create(
name="test activity",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "General stationary combustion",
"type": "object",
"properties": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"type": "object",
"title": "General stationary combustion of fuel or waste with production of useful energy",
"properties": {
"units": {
"type": "array",
"title": "Units",
"items": {
"type": "object",
"properties": {
"gscUnitName": {
"title": "GSC Unit Name",
"maxLength": 200,
"type": "string"
},
"gscUnitType": {
"title": "GSC Unit Type",
"maxLength": 200,
"type": "string"
},
"description": {
"title": "Description",
"default": "",
"type": "string"
},
"fuels": {
"title": "Fuel Data",
"type": "array",
"items": {
"type": "object",
"properties": {
"fuelName": {
"title": "Fuel Name",
"maxLength": 200,
"type": "string"
},
"fuelUnit": {
"title": "Fuel Unit",
"maxLength": 200,
"type": "string"
},
"annualFuelAmount": {
"title": "Annual Fuel Amount",
"type": "number"
},
"emissions": {
"title": "Emission Data",
"type": "array",
"items": {
"type": "object",
"properties": {
"gasType": {
"title": "Gas Type",
"type": "string",
"enum": []
},
"emission": {
"title": "Emission",
"type": "number"
},
"equivalentEmission": {
"title": "Equivalent Emission",
"type": "number"
},
"methodology": {
"title": "Methodology",
"type": "string",
"enum": []
}
}
}
}
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"type": "object",
"title": "General stationary combustion of fuel or waste without production of useful energy",
"properties": {
"units": {
"type": "array",
"title": "Units",
"items": {
"type": "object",
"properties": {
"gscUnitName": {
"title": "GSC Unit Name",
"maxLength": 200,
"type": "string"
},
"gscUnitType": {
"title": "GSC Unit Type",
"maxLength": 200,
"type": "string"
},
"description": {
"title": "Description",
"default": "",
"type": "string"
},
"fuels": {
"title": "Fuel Data",
"type": "array",
"items": {
"type": "object",
"properties": {
"fuelName": {
"title": "Fuel Name",
"maxLength": 200,
"type": "string"
},
"fuelUnit": {
"title": "Fuel Unit",
"maxLength": 200,
"type": "string"
},
"annualFuelAmount": {
"title": "Annual Fuel Amount",
"type": "number"
},
"emissions": {
"title": "Emission Data",
"type": "array",
"items": {
"type": "object",
"properties": {
"gasType": {
"title": "Gas Type",
"type": "string",
"enum": []
},
"emission": {
"title": "Emission",
"type": "number"
},
"equivalentEmission": {
"title": "Equivalent Emission",
"type": "number"
},
"methodology": {
"title": "Methodology",
"type": "string",
"enum": []
}
}
}
}
}
}
}
}
}
}
}
}
101 changes: 63 additions & 38 deletions bc_obps/reporting/migrations/0006_reinit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.6 on 2024-06-28 23:04
# Generated by Django 5.0.6 on 2024-07-02 21:15

import django.contrib.postgres.constraints
import django.contrib.postgres.fields.ranges
Expand All @@ -15,29 +15,6 @@ class Migration(migrations.Migration):
]

operations = [
migrations.CreateModel(
name='BaseSchema',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
(
'slug',
models.CharField(
db_comment='Name of the base schema. Should describe what form it is used to generate and when the base schema took effect. For example: general_stationary_combustion_2024',
max_length=1000,
),
),
(
'schema',
models.JSONField(
db_comment='The base json schema for a form. This schema defines the static set of fields that should be shown on a form, static meaning that they do not dynamically change based on user input.'
),
),
],
options={
'db_table': 'erc"."base_schema',
'db_table_comment': 'This table contains the base json schema data for displaying emission forms. The base schema can be defined by activity and source type and does not change based on user input so it can be stored statically',
},
),
migrations.CreateModel(
name='Configuration',
fields=[
Expand Down Expand Up @@ -243,29 +220,65 @@ class Migration(migrations.Migration):
),
),
migrations.CreateModel(
name='ActivitySourceTypeBaseSchema',
name='ActivityJsonSchema',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
(
'json_schema',
models.JSONField(
db_comment='The json schema for a specific activity. This defines the shape of the data collected for the related activity'
),
),
(
'reporting_activity',
models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING,
related_name='activity_source_type_base_schemas',
related_name='+',
to='registration.reportingactivity',
),
),
],
options={
'db_table': 'erc"."activity_json_schema',
'db_table_comment': 'Intersection table that assigns a json_schema as valid for a period of time given an activity',
},
),
migrations.CreateModel(
name='ActivitySourceTypeJsonSchema',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
(
'json_schema',
models.JSONField(
db_comment='The json schema for a specific activity-source type pair. This defines the shape of the data collected for the source type'
),
),
(
'has_unit',
models.BooleanField(
db_comment='Whether or not this source type should collect unit data. If true, add a unit schema when buidling the form object',
default=True,
),
),
(
'base_schema',
'has_fuel',
models.BooleanField(
db_comment='Whether or not this source type should collect fuel data. If true, add a fuel schema when buidling the form object',
default=True,
),
),
(
'reporting_activity',
models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING,
related_name='activity_source_type_base_schemas',
to='reporting.baseschema',
related_name='+',
to='registration.reportingactivity',
),
),
],
options={
'db_table': 'erc"."activity_source_type_base_schema',
'db_table_comment': 'Intersection table that assigns a base_schema as valid for a period of time given an activity-sourceType pair',
'db_table': 'erc"."activity_source_type_json_schema',
'db_table_comment': 'Intersection table that assigns a json_schema as valid for a period of time given an activity-sourceType pair',
},
),
migrations.AddConstraint(
Expand All @@ -283,14 +296,28 @@ class Migration(migrations.Migration):
),
),
migrations.AddField(
model_name='activitysourcetypebaseschema',
model_name='activitysourcetypejsonschema',
name='valid_from',
field=models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='reporting.configuration'
),
),
migrations.AddField(
model_name='activitysourcetypebaseschema',
model_name='activitysourcetypejsonschema',
name='valid_to',
field=models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='reporting.configuration'
),
),
migrations.AddField(
model_name='activityjsonschema',
name='valid_from',
field=models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='reporting.configuration'
),
),
migrations.AddField(
model_name='activityjsonschema',
name='valid_to',
field=models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='reporting.configuration'
Expand Down Expand Up @@ -349,7 +376,7 @@ class Migration(migrations.Migration):
name='reporting_year',
field=models.ForeignKey(
db_comment='The reporting year, for which this report is filled',
default=1,
default=1900,
on_delete=django.db.models.deletion.DO_NOTHING,
to='reporting.reportingyear',
),
Expand All @@ -365,12 +392,10 @@ class Migration(migrations.Migration):
),
),
migrations.AddField(
model_name='activitysourcetypebaseschema',
model_name='activitysourcetypejsonschema',
name='source_type',
field=models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING,
related_name='activity_source_type_base_schemas',
to='reporting.sourcetype',
on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='reporting.sourcetype'
),
),
]
Loading