-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Klimatbyran/feat/imageTable
CO2 table image
- Loading branch information
Showing
10 changed files
with
2,262 additions
and
52 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
{ | ||
"emissions": [ | ||
{ | ||
"year": "2018", | ||
"scope1": { | ||
"emissions": "1544000", | ||
"unit": "ton CO2e", | ||
"baseYear": "2018" | ||
}, | ||
"scope2": { | ||
"emissions": "1408000", | ||
"unit": "ton CO2e", | ||
"locationBased": "1408000", | ||
"marketBased": "1838000", | ||
"baseYear": "2018" | ||
}, | ||
"scope3": { | ||
"emissions": null, | ||
"unit": null, | ||
"baseYear": "2018", | ||
"categories": {} | ||
}, | ||
"totalEmissions": "Error 500", | ||
"totalUnit": "ton CO2e" | ||
}, | ||
{ | ||
"year": "2019", | ||
"scope1": { | ||
"emissions": "1537000", | ||
"unit": "ton CO2e", | ||
"baseYear": "2019" | ||
}, | ||
"scope2": { | ||
"emissions": "1292000", | ||
"unit": "ton CO2e", | ||
"locationBased": "1292000", | ||
"marketBased": "1661000", | ||
"baseYear": "2019" | ||
}, | ||
"scope3": { | ||
"emissions": "3595000", | ||
"unit": "ton CO2e", | ||
"baseYear": "2019", | ||
"categories": {} | ||
}, | ||
"totalEmissions": "2834000", | ||
"totalUnit": "ton CO2e" | ||
}, | ||
{ | ||
"year": "2020", | ||
"scope1": { | ||
"emissions": "1445000", | ||
"unit": "ton CO2e", | ||
"baseYear": "2020" | ||
}, | ||
"scope2": { | ||
"emissions": "1217000", | ||
"unit": "ton CO2e", | ||
"locationBased": "1217000", | ||
"marketBased": "1436000", | ||
"baseYear": "2020" | ||
}, | ||
"scope3": { | ||
"emissions": "3410000", | ||
"unit": "ton CO2e", | ||
"baseYear": "2020", | ||
"categories": {} | ||
}, | ||
"totalEmissions": "2662000", | ||
"totalUnit": "ton CO2e" | ||
}, | ||
{ | ||
"year": "2021", | ||
"scope1": { | ||
"emissions": "1410000", | ||
"unit": "ton CO2e", | ||
"baseYear": "2021" | ||
}, | ||
"scope2": { | ||
"emissions": "1216000", | ||
"unit": "ton CO2e", | ||
"locationBased": "1216000", | ||
"marketBased": "1462000", | ||
"baseYear": "2021" | ||
}, | ||
"scope3": { | ||
"emissions": null, | ||
"unit": null, | ||
"baseYear": "2021", | ||
"categories": {} | ||
}, | ||
"totalEmissions": "2626000", | ||
"totalUnit": "ton CO2e" | ||
}, | ||
{ | ||
"year": "2022", | ||
"scope1": { | ||
"emissions": "1395000", | ||
"unit": "ton CO2e", | ||
"baseYear": "2022" | ||
}, | ||
"scope2": { | ||
"emissions": "1254000", | ||
"unit": "ton CO2e", | ||
"locationBased": "1254000", | ||
"marketBased": "1499000", | ||
"baseYear": "2022" | ||
}, | ||
"scope3": { | ||
"emissions": null, | ||
"unit": null, | ||
"baseYear": "2022", | ||
"categories": {} | ||
}, | ||
"totalEmissions": "2649000", | ||
"totalUnit": "ton CO2e" | ||
} | ||
], | ||
"companyName": "Essity", | ||
"bransch": "Hygiene and Health Company", | ||
"baseYear": "2016", | ||
"url": "https://essity.com", | ||
"reliability": "High", | ||
"needsReview": true, | ||
"reviewComment": "Scope 3 emissions data is not available for 2018, 2021, and 2022, which impacted the accuracy of the total emissions for those years. Prior year adjustments for Scope 2 are mentioned but not detailed enough to be factored into the analysis. This requires clarification from the company for accurate annual accounting and should be reviewed by the reporting company.", | ||
"reviewStatusCode": "412" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import nodeHtmlToImage from 'node-html-to-image' | ||
import fs from 'fs' | ||
|
||
type YearEmissions = { | ||
year: number | ||
scope1: { | ||
emissions: string | ||
unit: string | ||
baseYear: string | ||
} | ||
scope2: { | ||
emissions: string | ||
unit: string | ||
mb: string | ||
lb: string | ||
baseYear: string | ||
} | ||
scope3: { | ||
emissions: string | ||
unit: string | ||
baseYear: string | ||
categories: { | ||
[key: string]: string | ||
} | ||
} | ||
totalEmissions?: string | ||
totalUnit?: string | ||
} | ||
|
||
type CompanyData = { | ||
companyName: string | ||
bransch?: string | ||
baseYear?: string | ||
url?: string | ||
emissions: Array<YearEmissions> | ||
reliability?: string | ||
needsReview?: boolean | ||
reviewComment?: string | ||
reviewStatusCode?: string | ||
} | ||
|
||
export const scope2Image = async (company: CompanyData) => { | ||
const emissions = company.emissions.sort((a, b) => b.year - a.year) | ||
const template = fs.readFileSync('src/lib/scope2.handlebars', 'utf8') | ||
const image = await nodeHtmlToImage({ | ||
html: template, | ||
content: { ...company, emissions }, | ||
}) | ||
return image | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<style> | ||
body{ | ||
font-family: sans-serif, sans-serif; | ||
font-size: 16px; | ||
line-height: 1.5; | ||
padding: 10px; | ||
color: #333; | ||
} | ||
.container { display: flex; | ||
flex-direction: column; | ||
gap: 32px; | ||
} | ||
.title { | ||
font-size: 1.125rem; | ||
font-weight: bold; | ||
} | ||
table { | ||
width: 100%; | ||
border-collapse: collapse; | ||
margin-top: 8px; | ||
} | ||
th, td { | ||
border: 1px solid #ddd; | ||
padding: 8px; | ||
text-align: left; | ||
} | ||
th { | ||
background-color: #f2f2f2; | ||
} | ||
tr:nth-child(even) td { | ||
background-color: #f2f2f2; | ||
} | ||
.text-left { | ||
text-align: left; | ||
} | ||
td[rowspan] { | ||
vertical-align: top; | ||
} | ||
</style> | ||
<div class='container'> | ||
<div> | ||
<h2 class='title'> | ||
Koldioxidutsläpp (CO<sub>2</sub>e) | ||
</h2> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th colspan='2' class='text-left'>Utsläpp inom scope 1, 2 och 3 (CO<sub | ||
>2</sub>e) och biogena utsläpp (utanför scope) genererade av | ||
{{companyName}}s verksamhet.</th> | ||
{{#each emissions as |emission|}} | ||
<th>{{emission.year}}</th> | ||
{{/each}} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td rowspan='5'>Ton CO<sub>2</sub>e</td> | ||
<td>Scope 1</td> | ||
{{#each emissions as |emission|}} | ||
<td>{{emission.scope1.emissions}}</td> | ||
{{/each}} | ||
</tr> | ||
<tr> | ||
<td>Scope 2<sup>3</sup></td> | ||
{{#each emissions as |emission|}} | ||
<td>{{emission.scope2.emissions}}</td> | ||
{{/each}} | ||
</tr> | ||
<tr> | ||
<td>Platsbaserat tillvägagångssätt</td> | ||
{{#each emissions as |emission|}} | ||
<td>{{emission.scope2.lb}}</td> | ||
{{/each}} | ||
</tr> | ||
<!--<tr> | ||
<td colspan='2'>Förändring jämfört med basår (scope 1 och 2), %</td> | ||
<td>-55</td> | ||
<td>-46</td> | ||
<td>-34</td> | ||
<td>-28</td> | ||
<td>—</td> | ||
</tr> | ||
<tr> | ||
<td colspan='2'>Koldioxidintensitet<sup>4</sup></td> | ||
<td>1,13</td> | ||
<td>1,46</td> | ||
<td>1,67</td> | ||
<td>1,64</td> | ||
<td>2,60</td> | ||
</tr>--> | ||
<tr> | ||
<td>Scope 3</td> | ||
|
||
{{#each emissions as |emission|}} | ||
<td>{{emission.scope3.emissions}}</td> | ||
{{/each}} | ||
</tr> | ||
<!--<tr> | ||
<td colspan='2'>Förändring jämfört med basår (scope 3), %</td> | ||
<td>-13</td> | ||
<td>-12</td> | ||
<td>—</td> | ||
<td>—</td> | ||
<td>—</td> | ||
</tr> | ||
<tr> | ||
<td colspan='2'>Utanför scope<sup>5</sup></td> | ||
<td>33 000</td> | ||
<td>22 000</td> | ||
<td>17 000</td> | ||
<td>20 000</td> | ||
<td>—</td> | ||
</tr>--> | ||
</tbody> | ||
</table> | ||
</div> | ||
<div> | ||
</div> |
Oops, something went wrong.