Skip to content

Commit

Permalink
fix: show max possible incentive for product, update incentive segment
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Jun 3, 2020
1 parent a6513f6 commit f2b21e1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 19 deletions.
2 changes: 2 additions & 0 deletions app/containers/Incentives/IncentiveCalculatorContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ export const IncentiveCalculator: React.FunctionComponent<Props> = ({
<th>Emission Intensity</th>
<th>Benchmark</th>
<th>Eligibility Threshold</th>
<th>Threshold Chart</th>
<th>Incentive Ratio</th>
<th>Incentive Multiplier</th>
<th>Payment Allocation</th>
<th>Calculated Incentive (CAD)</th>
<th>Maximum Incentive (CAD)</th>
</tr>
</thead>
<tbody>
Expand Down
32 changes: 14 additions & 18 deletions app/containers/Incentives/IncentiveSegmentContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import getConfig from 'next/config';
import React from 'react';
import {createFragmentContainer, graphql} from 'react-relay';
import MathJax from 'react-mathjax2';
import {IncentiveSegmentContainer_ciipIncentiveByProduct} from 'IncentiveSegmentContainer_ciipIncentiveByProduct.graphql';
import BenchmarkChart from 'components/Incentives/BenchmarkChart';

Expand All @@ -15,37 +13,33 @@ const IncentiveSegmentContainer: React.FunctionComponent<Props> = ({
const {
productName,
incentiveProduct,
incentiveProductMax,
benchmark,
eligibilityThreshold,
incrementalCarbonTax,
incentiveRatio,
incentiveMultiplier,
paymentAllocationFactor,
emissionIntensity
} = ciipIncentiveByProduct;

const formula = `
1 - \\left({ ${emissionIntensity} - ${benchmark}
\\over
${eligibilityThreshold} - ${benchmark}
}\\right) \\times ${incrementalCarbonTax}`;

return (
<tr>
<td>{productName}</td>
<td>
{process.env.NO_MATHJAX ||
getConfig()?.publicRuntimeConfig.NO_MATHJAX ? null : (
<MathJax.Context input="tex">
<MathJax.Node>{formula}</MathJax.Node>
</MathJax.Context>
)}
</td>
<td>CAD {incentiveProduct} </td>
<td>{Number.parseFloat(Number(emissionIntensity).toFixed(4))}</td>
<td>{Number.parseFloat(Number(benchmark).toFixed(4))}</td>
<td>{Number.parseFloat(Number(eligibilityThreshold).toFixed(4))}</td>
<td>
<BenchmarkChart
emissionIntensity={Number(emissionIntensity)}
benchmark={Number(benchmark)}
eligibilityThreshold={Number(eligibilityThreshold)}
/>
</td>
<td>{Number.parseFloat(Number(incentiveRatio).toFixed(4))}</td>
<td>{Number.parseFloat(Number(incentiveMultiplier).toFixed(4))}</td>
<td>{Number.parseFloat(Number(paymentAllocationFactor).toFixed(4))}</td>
<td>{Number(incentiveProduct).toFixed(2)}</td>
<td>{Number(incentiveProductMax).toFixed(2)}</td>
<style jsx>
{`
td {
Expand All @@ -65,9 +59,11 @@ export default createFragmentContainer(IncentiveSegmentContainer, {
incentiveMultiplier
paymentAllocationFactor
incentiveProduct
incentiveProductMax
emissionIntensity
benchmark
eligibilityThreshold
incrementalCarbonTax
}
`
});
1 change: 1 addition & 0 deletions app/server/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,7 @@ type CiipIncentiveByProduct {
emissionIntensity: BigFloat
incentiveMultiplier: BigFloat
incentiveProduct: BigFloat
incentiveProductMax: BigFloat
incentiveRatio: BigFloat
incrementalCarbonTax: BigFloat
paymentAllocationFactor: BigFloat
Expand Down
12 changes: 12 additions & 0 deletions app/server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23085,6 +23085,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "incentiveProductMax",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "BigFloat",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "incentiveRatio",
"description": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ returns setof ggircs_portal.ciip_incentive_by_product as $function$
intensity_range numeric;
incentive_ratio numeric;
incentive_product numeric;
incentive_product_max numeric;
app_reporting_year int;
incremental_carbon_tax_facility numeric;
payment_allocation_factor numeric; -- The portion of the facility's carbon tax allocated to the current product
Expand Down Expand Up @@ -177,6 +178,11 @@ returns setof ggircs_portal.ciip_incentive_by_product as $function$
payment_allocation_factor *
incremental_carbon_tax_facility, 0);

incentive_product_max = coalesce (
benchmark_data.incentive_multiplier *
payment_allocation_factor *
incremental_carbon_tax_facility, 0);

select into product_return
row_number() over (),
product_data.id,
Expand All @@ -186,8 +192,9 @@ returns setof ggircs_portal.ciip_incentive_by_product as $function$
incentive_ratio,
benchmark_data.incentive_multiplier,
payment_allocation_factor,
incremental_carbon_tax_facility,
incremental_carbon_tax_facility as incremental_carbon_tax,
incentive_product,
incentive_product_max,
em_intensity,
benchmark_data.benchmark,
benchmark_data.eligibility_threshold;
Expand Down
1 change: 1 addition & 0 deletions schema/deploy/types/ciip_incentive_by_product.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ create type ggircs_portal.ciip_incentive_by_product as (
payment_allocation_factor numeric,
incremental_carbon_tax numeric,
incentive_product numeric,
incentive_product_max numeric,
emission_intensity numeric,
benchmark numeric,
eligibility_threshold numeric
Expand Down

0 comments on commit f2b21e1

Please sign in to comment.