Skip to content

Commit

Permalink
feat(product): add EIO emissions as a product
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard authored Apr 22, 2020
1 parent c384167 commit 8d22f60
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 24 deletions.
7 changes: 5 additions & 2 deletions app/containers/Products/ProductRowItemContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
product.subtractGeneratedElectricityEmissions,
newSubtractGeneratedHeatEmissions:
product.subtractGeneratedHeatEmissions,
newRequiresProductAmount: product.requiresProductAmount
newRequiresProductAmount: product.requiresProductAmount,
newAddEmissionsFromEios: product.addEmissionsFromEios
}
};
const response = await saveProductMutation(relay.environment, variables);
Expand Down Expand Up @@ -212,7 +213,8 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
e.formData.subtractGeneratedElectricityEmissions,
newSubtractGeneratedHeatEmissions:
e.formData.subtractGeneratedHeatEmissions,
newRequiresProductAmount: e.formData.requiresProductAmount
newRequiresProductAmount: e.formData.requiresProductAmount,
newAddEmissionsFromEios: e.formData.addEmissionsFromEios
}
};
const response = await saveProductMutation(relay.environment, variables);
Expand Down Expand Up @@ -490,6 +492,7 @@ export default createFragmentContainer(ProductRowItemComponent, {
subtractExportedHeatEmissions
subtractGeneratedElectricityEmissions
subtractGeneratedHeatEmissions
addEmissionsFromEios
requiresProductAmount
benchmarksByProductId {
edges {
Expand Down
10 changes: 10 additions & 0 deletions app/containers/Products/product-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
"enumNames": [" Yes", " No"],
"default": false
},
"addEmissionsFromEios": {
"type": "boolean",
"title": "Emissions from EIOs are added to facility emissions",
"enumNames": [" Yes", " No"],
"default": false
},
"requiresProductAmount": {
"type": "boolean",
"title": "Production amount needs to be reported",
Expand All @@ -79,6 +85,7 @@
"subtractExportedHeatEmissions",
"subtractGeneratedElectricityEmissions",
"subtractGeneratedHeatEmissions",
"addEmissionsFromEios",
"requiresProductAmount"
]
},
Expand Down Expand Up @@ -119,6 +126,9 @@
},
"subtractGeneratedHeatEmissions": {
"ui:widget": "radio"
},
"addEmissionsFromEios": {
"ui:widget": "radio"
}
}
}
3 changes: 3 additions & 0 deletions app/cypress/integration/product-benchmark.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ describe('The products and benchmark page', () => {
cy.get(
'#root_subtractGeneratedHeatEmissions > :nth-child(1) > label > :nth-child(1) > input'
).click();
cy.get(
'#root_addEmissionsFromEios > :nth-child(1) > label > :nth-child(1) > input'
).click();
cy.contains('Add Product').click();
cy.get('tr')
.its('length')
Expand Down
24 changes: 24 additions & 0 deletions app/server/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9615,6 +9615,12 @@ type PageInfo {

"""Table containing the information for a CIIP product"""
type Product implements Node {
"""
Boolean value indicates if EIO facility emissions should be added to the
facility emissions when calculating the product emission intensity
"""
addEmissionsFromEios: Boolean!

"""
Boolean value indicates if purchased electricity emissions should be added to
the facility emissions when calculating the product emission intensity
Expand Down Expand Up @@ -9758,6 +9764,9 @@ type Product implements Node {
A condition to be used against `Product` object types. All fields are tested for equality and combined with a logical ‘and.’
"""
input ProductCondition {
"""Checks for equality with the object’s `addEmissionsFromEios` field."""
addEmissionsFromEios: Boolean

"""
Checks for equality with the object’s `addPurchasedElectricityEmissions` field.
"""
Expand Down Expand Up @@ -9838,6 +9847,12 @@ input ProductCondition {

"""An input for mutations affecting `Product`"""
input ProductInput {
"""
Boolean value indicates if EIO facility emissions should be added to the
facility emissions when calculating the product emission intensity
"""
addEmissionsFromEios: Boolean

"""
Boolean value indicates if purchased electricity emissions should be added to
the facility emissions when calculating the product emission intensity
Expand Down Expand Up @@ -9935,6 +9950,12 @@ input ProductInput {
Represents an update to a `Product`. Fields that are set will be updated.
"""
input ProductPatch {
"""
Boolean value indicates if EIO facility emissions should be added to the
facility emissions when calculating the product emission intensity
"""
addEmissionsFromEios: Boolean

"""
Boolean value indicates if purchased electricity emissions should be added to
the facility emissions when calculating the product emission intensity
Expand Down Expand Up @@ -10056,6 +10077,8 @@ type ProductsEdge {

"""Methods to use when ordering `Product`."""
enum ProductsOrderBy {
ADD_EMISSIONS_FROM_EIOS_ASC
ADD_EMISSIONS_FROM_EIOS_DESC
ADD_PURCHASED_ELECTRICITY_EMISSIONS_ASC
ADD_PURCHASED_ELECTRICITY_EMISSIONS_DESC
ADD_PURCHASED_HEAT_EMISSIONS_ASC
Expand Down Expand Up @@ -11590,6 +11613,7 @@ input SaveProductMutationChainInput {
payload verbatim. May be used to track mutations by the client.
"""
clientMutationId: String
newAddEmissionsFromEios: Boolean
newAddPurchasedElectricityEmissions: Boolean
newAddPurchasedHeatEmissions: Boolean
newDescription: String
Expand Down
68 changes: 68 additions & 0 deletions app/server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11885,6 +11885,22 @@
"name": "Product",
"description": "Table containing the information for a CIIP product",
"fields": [
{
"name": "addEmissionsFromEios",
"description": "Boolean value indicates if EIO facility emissions should be added to the facility emissions when calculating the product emission intensity",
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "addPurchasedElectricityEmissions",
"description": "Boolean value indicates if purchased electricity emissions should be added to the facility emissions when calculating the product emission intensity (applies only to products where requires_emission_allocation is false)",
Expand Down Expand Up @@ -22337,6 +22353,16 @@
"description": "A condition to be used against `Product` object types. All fields are tested for equality and combined with a logical ‘and.’",
"fields": null,
"inputFields": [
{
"name": "addEmissionsFromEios",
"description": "Checks for equality with the object’s `addEmissionsFromEios` field.",
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
},
"defaultValue": null
},
{
"name": "addPurchasedElectricityEmissions",
"description": "Checks for equality with the object’s `addPurchasedElectricityEmissions` field.",
Expand Down Expand Up @@ -22564,6 +22590,18 @@
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "ADD_EMISSIONS_FROM_EIOS_ASC",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "ADD_EMISSIONS_FROM_EIOS_DESC",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "ADD_PURCHASED_ELECTRICITY_EMISSIONS_ASC",
"description": null,
Expand Down Expand Up @@ -34907,6 +34945,16 @@
"description": "An input for mutations affecting `Product`",
"fields": null,
"inputFields": [
{
"name": "addEmissionsFromEios",
"description": "Boolean value indicates if EIO facility emissions should be added to the facility emissions when calculating the product emission intensity",
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
},
"defaultValue": null
},
{
"name": "addPurchasedElectricityEmissions",
"description": "Boolean value indicates if purchased electricity emissions should be added to the facility emissions when calculating the product emission intensity (applies only to products where requires_emission_allocation is false)",
Expand Down Expand Up @@ -40416,6 +40464,16 @@
},
"defaultValue": null
},
{
"name": "newAddEmissionsFromEios",
"description": null,
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
},
"defaultValue": null
},
{
"name": "newAddPurchasedElectricityEmissions",
"description": null,
Expand Down Expand Up @@ -46400,6 +46458,16 @@
"description": "Represents an update to a `Product`. Fields that are set will be updated.",
"fields": null,
"inputFields": [
{
"name": "addEmissionsFromEios",
"description": "Boolean value indicates if EIO facility emissions should be added to the facility emissions when calculating the product emission intensity",
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
},
"defaultValue": null
},
{
"name": "addPurchasedElectricityEmissions",
"description": "Boolean value indicates if purchased electricity emissions should be added to the facility emissions when calculating the product emission intensity (applies only to products where requires_emission_allocation is false)",
Expand Down
3 changes: 2 additions & 1 deletion schema/data/prod/product.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ values
(37, 'Purchased electricity', 'GWh', 'active' ,true, true),
(38, 'Purchased heat', 'GJ', 'active' ,true, true),
(39, 'Generated electricity', 'GWh', 'active' ,true, true),
(40, 'Generated heat', 'GJ', 'active' ,true, true)
(40, 'Generated heat', 'GJ', 'active' ,true, true),
(41, 'Emissions from EIOs', 'GJ', 'active' ,true, true)
on conflict(id) do update
set
name=excluded.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ returns setof ggircs_portal.ciip_incentive_by_product as $function$
and _product.name = 'Exported heat'
);
end if;
if product_data.add_emissions_from_eios then
em_product = em_product + (
select p.product_emissions
from unnest(reported_products) p
join ggircs_portal.product _product on
p.product_id = _product.id
and _product.name = 'Emissions from EIOs'
);
end if;
end if;

-- Calculate Emission Intensity
Expand Down
4 changes: 3 additions & 1 deletion schema/deploy/mutations/save_product_mutation_chain.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ begin;
create or replace function ggircs_portal.save_product_mutation_chain(prev_id int, new_name varchar(1000), new_units varchar(1000), new_description varchar(1000),
new_state varchar(1000), new_parent int[], new_requires_emission_allocation boolean, new_is_ciip_product boolean, new_add_purchased_electricity_emissions boolean, new_subtract_exported_electricity_emissions boolean,
new_add_purchased_heat_emissions boolean, new_subtract_exported_heat_emissions boolean, new_subtract_generated_electricity_emissions boolean, new_subtract_generated_heat_emissions boolean,
new_requires_product_amount boolean)
new_add_emissions_from_eios boolean, new_requires_product_amount boolean)
returns ggircs_portal.product
as $function$
declare
Expand All @@ -29,6 +29,7 @@ begin
subtract_exported_heat_emissions,
subtract_generated_electricity_emissions,
subtract_generated_heat_emissions,
add_emissions_from_eios,
requires_product_amount)
values (new_name,
new_description,
Expand All @@ -43,6 +44,7 @@ begin
new_subtract_exported_heat_emissions,
new_subtract_generated_electricity_emissions,
new_subtract_generated_heat_emissions,
new_add_emissions_from_eios,
new_requires_product_amount) returning id into new_id;

update ggircs_portal.benchmark
Expand Down
4 changes: 2 additions & 2 deletions schema/deploy/search_functions/search_products.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ returns setof ggircs_portal.product as
select
id, name, description, units,
state, parent, requires_emission_allocation, is_ciip_product, requires_product_amount, subtract_exported_electricity_emissions, subtract_exported_electricity_emissions, subtract_exported_heat_emissions, subtract_exported_heat_emissions,
subtract_generated_electricity_emissions, subtract_generated_heat_emissions, created_at, created_by, updated_at, updated_by, deleted_at, deleted_by
subtract_generated_electricity_emissions, subtract_generated_heat_emissions, add_emissions_from_eios, created_at, created_by, updated_at, updated_by, deleted_at, deleted_by
from outerTable
where
state != ''deprecated''
Expand All @@ -56,7 +56,7 @@ returns setof ggircs_portal.product as
select
id, name, description, units, state, parent,
requires_emission_allocation, is_ciip_product, requires_product_amount, subtract_exported_electricity_emissions, subtract_exported_electricity_emissions, subtract_exported_heat_emissions, subtract_exported_heat_emissions,
subtract_generated_electricity_emissions, subtract_generated_heat_emissions, created_at, created_by, updated_at, updated_by, deleted_at, deleted_by from outerTable
subtract_generated_electricity_emissions, subtract_generated_heat_emissions, add_emissions_from_eios, created_at, created_by, updated_at, updated_by, deleted_at, deleted_by from outerTable
where
state != ''deprecated'' and '|| search_field || '::text ilike ''%' || search_value || '%''
and
Expand Down
2 changes: 2 additions & 0 deletions schema/deploy/tables/product.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ create table ggircs_portal.product (
subtract_exported_heat_emissions boolean not null default false,
subtract_generated_electricity_emissions boolean not null default false,
subtract_generated_heat_emissions boolean not null default false,
add_emissions_from_eios boolean not null default false,
created_at timestamp with time zone not null default now(),
created_by int references ggircs_portal.ciip_user,
updated_at timestamp with time zone not null default now(),
Expand Down Expand Up @@ -85,6 +86,7 @@ comment on column ggircs_portal.product.add_purchased_heat_emissions is 'Boolea
comment on column ggircs_portal.product.subtract_exported_heat_emissions is 'Boolean value indicates if exported heat emissions should be subtracted from the facility emissions when calculating the product emission intensity (applies only to products where requires_emission_allocation is false)';
comment on column ggircs_portal.product.subtract_generated_electricity_emissions is 'Boolean value indicates if generated electricity emissions should be subtracted from the facility emissions when calculating the product emission intensity (applies only to products where requires_emission_allocation is false)';
comment on column ggircs_portal.product.subtract_generated_heat_emissions is 'Boolean value indicates if generated heat emissions should be subtracted from the facility emissions when calculating the product emission intensity (applies only to products where requires_emission_allocation is false)';
comment on column ggircs_portal.product.add_emissions_from_eios is 'Boolean value indicates if EIO facility emissions should be added to the facility emissions when calculating the product emission intensity';
comment on column ggircs_portal.product.state is 'The current state of the product within the lifecycle (created, split, merged, redefined, archived, unarchived)';
comment on column ggircs_portal.product.parent is 'The parent ID(s) (previous state) of the product';
comment on column ggircs_portal.product.created_at is 'Creation date of row';
Expand Down
Loading

0 comments on commit 8d22f60

Please sign in to comment.