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

Feat/307 activity pulp paper #2153

Merged
merged 13 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "Pulp and paper production",
"type": "object",
"properties": {
"carbonates": {
"type": "array",
"title": "Carbonates",
"items": {
"title": "Carbonates",
"type": "object",
"properties": {
"carbonateName": {
"type": "string",
"title": "Carbonate Name"
},
"annualAmount": {
"type": "number",
"title": "Annual Amount (t)"
},
"purityOfCarbonate": {
"type": "number",
"title": "Purity Of Carbonate (Weight Fraction)"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "object",
"title": "Emissions",
"properties": {
"emissions": {
"type": "array",
"title": "Emissions",
"items": {
"title": "Emission",
"type": "object",
"properties": {
"gasType": {
"type": "string",
"title": "Gas Type",
"enum": []
},
"emission": {
"title": "Emission",
"type": "number"
},
"equivalentEmission": {
"title": "Equivalent Emission",
"type": "number",
"readOnly": true
}
}
}
}
}
}
609 changes: 609 additions & 0 deletions bc_obps/reporting/migrations/0018_pulp_and_paper_production.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from django.test import TestCase
from django.db.models import Count
from registration.models.activity import Activity
from reporting.models.configuration import Configuration
from reporting.models.configuration_element import ConfigurationElement


class PulpAndPaperProduction2024TestCase(TestCase):
def testDataExists(self):
activity = Activity.objects.get(name='Pulp and paper production')
config = Configuration.objects.get(slug='2024')

config_elements = ConfigurationElement.objects.filter(
valid_from__lte=config, valid_to__gte=config, activity=activity
)

# For each gas, the list of methodologies and their associated field's count
gas_config = {
'CO2': {
'Solids-HHV': 6,
'Solids-CC': 4,
'Make-up Chemical Use Methodology': 2,
'Alternative Parameter Methodology': 1,
'Replacement Methodology': 1,
},
'CH4': {
'Solids-HHV': 3,
'Alternative Parameter Methodology': 1,
'Replacement Methodology': 1,
},
'N2O': {
'Solids-HHV': 3,
'Alternative Parameter Methodology': 1,
'Replacement Methodology': 1,
},
}

config = {
'Pulping and chemical recovery': gas_config,
}

self.assertQuerysetEqual(
config_elements.values_list('source_type__name', flat=True).distinct(),
config.keys(),
ordered=False,
msg=f'{activity} contains config for the proper source types',
)

for source_type_name, gas_config in config.items():
self.assertQuerysetEqual(
config_elements.filter(source_type__name=source_type_name)
.values_list('gas_type__chemical_formula', flat=True)
.distinct(),
gas_config.keys(),
ordered=False,
msg=f'{source_type_name} contains config for the proper gas types',
)
for gas_name, methods in gas_config.items():
self.assertQuerysetEqual(
config_elements.filter(source_type__name=source_type_name, gas_type__chemical_formula=gas_name)
.annotate(field_count=Count('reporting_fields'))
.values_list('methodology__name', 'field_count'),
list(methods.items()),
ordered=False,
msg=f'{source_type_name}:{gas_name} contains config for the proper methods and field counts',
)

assert len(config_elements) == 11
3 changes: 3 additions & 0 deletions bc_obps/reporting/tests/models/test_methodology.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def test_methodology_initial_data(self):
'Mass of Output Carbonates',
'Alternative Parameter Methodology',
'Feedstock Material Balance',
'Solids-HHV',
'Solids-CC',
'Make-up Chemical Use Methodology',
]
)
existing_methodologies = sorted(list(Methodology.objects.values_list('name', flat=True)))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { actionHandler } from "@bciers/actions";
import PulpAndPaperProduction from "@reporting/src/app/components/activities/pulpAndPaperProduction";
import { Suspense } from "react";

export default async function Page() {
const reportDate = "2024-04-01"; // This should be passed in once we have a path to this page from starting a report
const activityData = await actionHandler(
`reporting/initial-activity-data?activity_name=Pulp and paper production&report_date=${reportDate}`,
"GET",
"",
);
const activityDataObject = JSON.parse(activityData);

return (
<>
<Suspense fallback="Loading Schema">
<PulpAndPaperProduction
activityData={activityDataObject}
reportDate={reportDate}
/>
</Suspense>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { actionHandler } from "@bciers/actions";
import safeJsonParse from "libs/utils/safeJsonParse";
import PulpAndPaperProduction from "@reporting/src/app/components/activities/pulpAndPaperProduction";
import { Suspense } from "react";

export default async function Page() {
const reportDate = "2024-04-01"; // This should be passed in once we have a path to this page from starting a report
const activityData = await actionHandler(
`reporting/initial-activity-data?activity_name=Pulp and paper production&report_date=${reportDate}`,
"GET",
"",
);
const activityDataObject = safeJsonParse(activityData);

return (
<>
<Suspense fallback="Loading Schema">
<PulpAndPaperProduction
activityData={activityDataObject}
reportDate={reportDate}
/>
</Suspense>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use client";
import ActivityForm from "./ActivityForm";
import uiSchema from "./uiSchemas/pulpAndPaperUiSchema";

interface Props {
activityData: {
activityId: number;
sourceTypeMap: { [key: number]: string };
};
reportDate: string;
}

// 🧩 Main component
export default function PulpAndPaperProduction({
activityData,
reportDate,
}: Readonly<Props>) {
const defaultEmptySourceTypeState = {
emissions: [{}],
};

return (
<div>
<ActivityForm
activityData={activityData}
reportDate={reportDate}
uiSchema={uiSchema}
defaultEmptySourceTypeState={defaultEmptySourceTypeState}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import FieldTemplate from "@bciers/components/form/fields/FieldTemplate";
import SourceTypeBoxTemplate from "@bciers/components/form/fields/SourceTypeBoxTemplate";
import NestedArrayFieldTemplate from "@bciers/components/form/fields/NestedArrayFieldTemplate";
import { InlineFieldTemplate } from "@bciers/components/form/fields";

const uiSchema = {
"ui:FieldTemplate": FieldTemplate,
"ui:classNames": "form-heading-label",
"ui:title": "Pulp and paper production",
carbonates: {
"ui:ArrayFieldTemplate": NestedArrayFieldTemplate,
"ui:FieldTemplate": SourceTypeBoxTemplate,
"ui:options": {
arrayAddLabel: "Add Carbonate",
label: true,
title: "Carbonate",
padding: "p-2",
},
items: {
"ui:order": ["carbonateName", "annualAmount", "purityOfCarbonate"],
},
},
sourceTypes: {
"ui:FieldTemplate": FieldTemplate,
"ui:options": {
label: false,
},
pulpingAndChemicalRecovery: {
"ui:FieldTemplate": SourceTypeBoxTemplate,
emissions: {
"ui:title": "Pulping and Chemical Recovery",
"ui:ArrayFieldTemplate": NestedArrayFieldTemplate,
"ui:FieldTemplate": FieldTemplate,
"ui:options": {
arrayAddLabel: "Add Emission",
label: false,
title: "Emission",
padding: "p-2",
},
items: {
equivalentEmission: {
"ui:FieldTemplate": InlineFieldTemplate,
},
},
},
},
},
};

export default uiSchema;
12 changes: 7 additions & 5 deletions bciers/libs/components/src/form/fields/SourceTypeBoxTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
IconButton,
Paper,
} from "@mui/material";
import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
import ArrowDropUpIcon from "@mui/icons-material/ArrowDropUp";
import ExpandLessIcon from "@mui/icons-material/ExpandLess";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import { useState } from "react";

function SourceTypeBoxTemplate({
Expand All @@ -26,7 +26,7 @@ function SourceTypeBoxTemplate({
<>
<Paper className={classNames} sx={{ marginBottom: "10px" }}>
<Card style={{ textAlign: "left" }}>
<Grid container spacing={1}>
<Grid container spacing={1} sx={{ justifyContent: "space-between" }}>
<Grid item xs={10}>
<CardHeader
sx={{ color: "blue" }}
Expand All @@ -35,9 +35,11 @@ function SourceTypeBoxTemplate({
/>
</Grid>
<Grid item xs={1}>
<CardActions>
<CardActions
sx={{ justifyContent: "flex-end", marginRight: "30px" }}
>
<IconButton onClick={() => setExpand(!expand)}>
{expand ? <ArrowDropUpIcon /> : <ArrowDropDownIcon />}
{expand ? <ExpandLessIcon /> : <ExpandMoreIcon />}
</IconButton>
</CardActions>
</Grid>
Expand Down