Skip to content

Commit e535f1b

Browse files
committed
Squashed commit of the following:
commit 668d8e4 Merge: 33c66d7 21a1a25 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Wed Oct 23 10:15:46 2024 +0200 Add JSDoc comments to data generation scripts and output files commit 21a1a25 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Wed Oct 23 16:11:01 2024 +0800 add comments to output of generators commit cab18cf Author: fershad <27988517+fershad@users.noreply.github.com> Date: Wed Oct 23 16:05:24 2024 +0800 add comments about constants in source files commit 33c66d7 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Mon Oct 14 15:46:00 2024 +0800 add note about commenting commit 5e58971 Author: Malay Kumar <malaykumar2003@gmail.com> Date: Sat Oct 12 19:01:39 2024 +0530 Add JsDoc comments to marginal-intensities-2021 commit 6b000a0 Author: Malay Kumar <malaykumar2003@gmail.com> Date: Sat Oct 12 19:01:19 2024 +0530 Add JsDoc comments to average-intensities commit 29b6755 Author: Malay Kumar <malaykumar2003@gmail.com> Date: Sat Oct 12 18:59:08 2024 +0530 Add JsDoc comments to generate_marginal_co2 commit eb4e9ff Author: Malay Kumar <malaykumar2003@gmail.com> Date: Sat Oct 12 18:58:53 2024 +0530 Add JsDoc comments to generate_average_co2 commit c238d96 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Wed Sep 11 10:30:41 2024 +0800 v0.16.1 commit d5d3156 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Tue Sep 10 15:44:34 2024 +0800 0.16.1 commit 4b10930 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Tue Sep 10 15:43:51 2024 +0800 v0.16.1 commit 8339284 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Tue Sep 10 15:38:33 2024 +0800 update jsr export commit 6c0f991 Merge: 8f9097c ed2d8ab Author: fershad <27988517+fershad@users.noreply.github.com> Date: Tue Sep 10 15:35:05 2024 +0800 Add basic JSR support commit ed2d8ab Author: fershad <27988517+fershad@users.noreply.github.com> Date: Tue Sep 10 15:20:27 2024 +0800 update average grid intensities commit 8f9097c Author: fershad <27988517+fershad@users.noreply.github.com> Date: Tue Sep 10 15:17:29 2024 +0800 update test constants commit ce1ada5 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Tue Sep 10 15:11:41 2024 +0800 update version commit 2962ca1 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Tue Sep 10 15:06:52 2024 +0800 create hosting module commit 2dd34ec Author: fershad <27988517+fershad@users.noreply.github.com> Date: Tue Sep 10 15:03:33 2024 +0800 add mod.ts for jsr commit 870e621 Merge: 7adac52 87d0e62 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Fri Sep 6 14:35:09 2024 +0800 [AUTOMATED] Update average annual grid intensities commit 87d0e62 Author: fershad <fershad@users.noreply.github.com> Date: Tue Sep 3 10:10:55 2024 +0000 Update average annual grid intensities commit 7adac52 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Wed Aug 21 12:55:39 2024 +0800 update test constant commit 344a513 Merge: 4541319 d080a36 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Wed Aug 14 21:36:04 2024 +0200 [AUTOMATED] Update average annual grid intensities commit d080a36 Author: fershad <fershad@users.noreply.github.com> Date: Sat Aug 3 10:09:23 2024 +0000 Update average annual grid intensities commit 4541319 Merge: 8f95399 c19da59 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Wed Jul 31 22:38:58 2024 +0200 Export classes inside of the individual models commit c19da59 Author: fershad <27988517+fershad@users.noreply.github.com> Date: Thu Jul 11 22:02:57 2024 +0100 export classes inside of the CO2 class
1 parent 2474b1c commit e535f1b

16 files changed

+289
-123
lines changed

CONTRIBUTING.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ Thank you for considering contributing to CO2.js. Open source is at the heart of
99
**NB** Changes/commits that are not linked to an issue will not be accepted.
1010

1111
### New issues
12-
- Our issue template provides you with a scaffold to follow when raising a new issue. There are three formats to choose from:
13-
1. *Bugs* - clearly describe the problem you're facing including steps to reproduce it. Please also be sure to include the information about the environment your code was running in (e.g. NodeJS, Deno, Edge Worker, Browser etc).
14-
1. *New features* - clearly describe the new feature you'd like to see added and provide a reason for why it should be added. eg what will be improved/possible as a result of making your suggested change.
15-
1. *Request addition of carbon estimation model to CO2.js* - please provide as much information about the model as possible including links to additional documentation and information about how the model is licensed.
16-
1712

13+
- Our issue template provides you with a scaffold to follow when raising a new issue. There are three formats to choose from:
14+
1. _Bugs_ - clearly describe the problem you're facing including steps to reproduce it. Please also be sure to include the information about the environment your code was running in (e.g. NodeJS, Deno, Edge Worker, Browser etc).
15+
1. _New features_ - clearly describe the new feature you'd like to see added and provide a reason for why it should be added. eg what will be improved/possible as a result of making your suggested change.
16+
1. _Request addition of carbon estimation model to CO2.js_ - please provide as much information about the model as possible including links to additional documentation and information about how the model is licensed.
1817

1918
## Making Changes
2019

2120
- Fork the repository on GitHub.
2221
- Create a topic branch from where you want to base your work. This branch should usually be based off `main`.
22+
- Remember to add JSDoc comments to any new functions or variables that you are introducing into the codebase.
2323
- Make commits of logical units.
2424
- Make commit messages clear and understandable.
2525

@@ -28,10 +28,10 @@ Thank you for considering contributing to CO2.js. Open source is at the heart of
2828
- Push the changes made in your branch to your fork of this repository.
2929
- Submit a [pull request](https://github.com/thegreenwebfoundation/co2.js/pulls) to the CO2.js repository in the `thegreenwebfoundation` organization.
3030
- When opening a new pull request, you'll see a template. Please follow it. It asks you to state:
31-
- the type of change (choose from a list)
32-
- link to the related issue
33-
- what documentation needs updating as a result (choose from a list)
34-
- what your changes are - be sure to clearly explain the changes you've made, any new files, dependencies, or network requests that have been added, and provide any additional context to help reviewers understand the changes made.
31+
- the type of change (choose from a list)
32+
- link to the related issue
33+
- what documentation needs updating as a result (choose from a list)
34+
- what your changes are - be sure to clearly explain the changes you've made, any new files, dependencies, or network requests that have been added, and provide any additional context to help reviewers understand the changes made.
3535
- Your pull request will be reviewed by a maintainer from Green Web Foundation.
3636
- After feedback has been given we expect responses within two weeks. After two weeks we may close the pull request if it isn't showing any activity.
3737

@@ -43,4 +43,4 @@ Please note that this project is released with a [Contributor Code of Conduct](h
4343

4444
## Thank you
4545

46-
Again, thank you for your contributions. We appreciate your help improving CO2.js, and we look forward to your future contributions!
46+
Again, thank you for your contributions. We appreciate your help improving CO2.js, and we look forward to your future contributions!

data/functions/generate_average_co2.js

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,43 @@
1+
/**
2+
* @fileoverview This script generates average CO2 emissions intensity data for countries using the Ember API.
3+
* It processes the data and saves it in various formats for use in the CO2.js library.
4+
* @author Chris Adams
5+
* @version 1.0.0
6+
*/
7+
18
const fs = require("fs");
29

3-
// This URL from Ember returns ALL the data for the country_overview_yearly table
10+
/**
11+
* The URL for the Ember API that provides country overview data on a yearly basis.
12+
* @constant {string}
13+
*/
414
const sourceURL =
515
"https://ember-data-api-scg3n.ondigitalocean.app/ember/country_overview_yearly.json?_sort=rowid&_shape=array";
16+
17+
/**
18+
* Object to store the grid intensity results for each country.
19+
* @type {Object.<string, number>}
20+
*/
621
const gridIntensityResults = {};
22+
23+
/**
24+
* Object to store general results including additional country information.
25+
* @type {Object.<string, Object>}
26+
*/
727
const generalResults = {};
28+
29+
/**
30+
* The type of intensity data being processed (average or marginal).
31+
* @constant {string}
32+
*/
833
const type = "average";
934

1035
/**
11-
* This function generates the average CO2 emissions data for each country.
12-
* It reads the data from the Ember API and saves it in the data/output folder.
13-
* It also saves the data as a minified file in the src/data folder, so that it can be imported into the library.
36+
* Fetches data from the Ember API, processes it to extract the latest average CO2 emissions
37+
* intensity data for each country, and saves the results in various formats.
38+
* @async
39+
* @function
40+
* @returns {Promise<void>}
1441
*/
1542

1643
// Use async/await
@@ -31,7 +58,10 @@ const type = "average";
3158
}
3259
const data = await response.json();
3360

34-
// Group data by country_code
61+
/**
62+
* Groups the API data by country code.
63+
* @type {Object.<string, Array>}
64+
*/
3565
const groupedData = await data.reduce((acc, item) => {
3666
const key =
3767
item.country_code === "" ? item.country_or_region : item.country_code;
@@ -42,7 +72,10 @@ const type = "average";
4272
return acc;
4373
}, {});
4474

45-
// Loop through the grouped data and find the latest year
75+
/**
76+
* Extracts the latest year's data for each country.
77+
* @type {Object.<string, Object>}
78+
*/
4679
const latestData = await Object.keys(groupedData).reduce((acc, key) => {
4780
// Find the last year in the array with emissions intensity data
4881
const latestYear = groupedData[key].reduce((acc, item, index) => {
@@ -87,7 +120,20 @@ const type = "average";
87120
fs.mkdirSync("data/output", { recursive: true });
88121
fs.mkdirSync("src/data", { recursive: true });
89122

90-
// This saves the country code and emissions data only, for use in the CO2.js library
123+
const jsDocComments = `/**
124+
* @fileoverview Minified average CO2 emissions intensity data for countries.
125+
* @generated Generated by generate_average_co2.js
126+
* @version 1.0.0
127+
*/
128+
/**
129+
* @constant {Object.<string, number>} data - Average CO2 emissions intensity data for various countries.
130+
* @constant {string} type - Type of data being represented.
131+
*/`;
132+
133+
/**
134+
* Saves the country code and emissions data for use in the CO2.js library.
135+
* @type {void}
136+
*/
91137
fs.writeFileSync(
92138
"data/output/average-intensities.js",
93139
`const data = ${JSON.stringify(gridIntensityResults, null, " ")};
@@ -96,18 +142,28 @@ const type = "average";
96142
export default { data, type };
97143
`
98144
);
99-
// Save a minified version to the src folder so that it can be easily imported into the library
145+
146+
/**
147+
* Saves a minified version of the data for easy import into the library.
148+
* @type {void}
149+
*/
100150
fs.writeFileSync(
101151
"src/data/average-intensities.min.js",
102-
`const data = ${JSON.stringify(gridIntensityResults)}; const type = "${type}"; export { data, type }; export default { data, type };`
152+
`${jsDocComments}
153+
const data = ${JSON.stringify(
154+
gridIntensityResults
155+
)}; const type = "${type}"; export { data, type }; export default { data, type };`
103156
);
104157

105-
// This saves the full data set as a JSON file for reference.
158+
/**
159+
* Saves the full data set as a JSON file for reference.
160+
* @type {void}
161+
*/
106162
fs.writeFileSync(
107163
"data/output/average-intensities.json",
108164
JSON.stringify(generalResults, null, " ")
109165
);
110166
} catch (error) {
111167
console.error("Error fetching or processing data:", error);
112168
}
113-
})();
169+
})();

data/functions/generate_marginal_co2.js

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,66 @@
1+
/**
2+
* @fileoverview This script generates marginal CO2 emissions intensity data for countries using UNFCCC data.
3+
* It processes the data from a CSV file and saves it in various formats for use in the CO2.js library.
4+
* @author Chris Adams
5+
* @version 1.0.0
6+
*/
7+
18
const fs = require("fs");
9+
10+
/**
11+
* Reads the UNFCCC CSV file containing grid factors data.
12+
* @type {Buffer}
13+
*/
214
const csv = fs.readFileSync(
315
"data/IFI_Default_Grid_Factors_2021_v3.1_unfccc.csv"
416
);
17+
18+
/**
19+
* Utility function to parse CSV rows.
20+
* @type {function}
21+
*/
522
const parseCSVRow = require("../utils/parseCSVRow");
23+
24+
/**
25+
* Utility function to get country codes.
26+
* @type {function}
27+
*/
628
const getCountryCodes = require("../utils/getCountryCodes");
29+
30+
/**
31+
* The type of intensity data being processed (marginal).
32+
* @constant {string}
33+
*/
734
const type = "marginal";
35+
36+
/**
37+
* The source of the data (UNFCCC).
38+
* @constant {string}
39+
*/
840
const source = "UNFCCC";
41+
42+
/**
43+
* The year of the data.
44+
* @constant {string}
45+
*/
946
const year = "2021";
1047

48+
/**
49+
* Converts the CSV data to an array of strings, each representing a row.
50+
* @type {string[]}
51+
*/
1152
const array = csv.toString().split("\n");
1253

13-
/* Store the converted result into an array */
54+
/**
55+
* Object to store the converted CSV data.
56+
* @type {Object.<string, Object>}
57+
*/
1458
const csvToJsonResult = {};
59+
60+
/**
61+
* Object to store the grid intensity results for each country.
62+
* @type {Object.<string, string>}
63+
*/
1564
const gridIntensityResults = {};
1665

1766
/* Store the CSV column headers into seprate variable */
@@ -79,20 +128,45 @@ for (let currentArrayString of array.slice(5)) {
79128
const json = JSON.stringify(csvToJsonResult);
80129
const gridIntensityJson = JSON.stringify(gridIntensityResults);
81130

82-
// This saves the country code and emissions data only, for use in the CO2.js library
131+
const jsDocComments = `/**
132+
* @fileoverview Minified marginal CO2 emissions intensity data for countries (2021).
133+
* @generated Generated by generate_marginal_co2.js
134+
* @version 1.0.0
135+
*/
136+
137+
/**
138+
* @constant {Object.<string, number>} data - Average CO2 emissions intensity data for various countries.
139+
* @constant {string} type - Type of data being represented.
140+
* @constant {string} year - Year for which the data was collected.
141+
*/`;
142+
143+
/**
144+
* Saves the country code and emissions data for use in the CO2.js library.
145+
* @type {void}
146+
*/
83147
fs.writeFileSync(
84148
"data/output/marginal-intensities-2021.js",
85-
`const data = ${gridIntensityJson};
149+
`
150+
const data = ${gridIntensityJson};
86151
const type = "${type}";
87-
const year = "${year}";
88-
export { data, type, year };
89-
export default { data, type, year };`
152+
const year = "${year}";
153+
export { data, type, year };
154+
export default { data, type, year };
155+
`
90156
);
91-
// Save a minified version to the src folder so that it can be easily imported into the library
157+
158+
/**
159+
* Saves a minified version of the data for easy import into the library.
160+
* @type {void}
161+
*/
92162
fs.writeFileSync(
93163
"src/data/marginal-intensities-2021.min.js",
94-
`const data = ${gridIntensityJson}; const type = "${type}"; const year = "${year}"; export { data, type, year }; export default { data, type, year };`
164+
`${jsDocComments}
165+
const data = ${gridIntensityJson}; const type = "${type}"; const year = "${year}"; export { data, type, year }; export default { data, type, year };`
95166
);
96167

97-
// This saves the full data set as a JSON file for reference.
168+
/**
169+
* Saves the full data set as a JSON file for reference.
170+
* @type {void}
171+
*/
98172
fs.writeFileSync("data/output/marginal-intensities-2021.json", json);

0 commit comments

Comments
 (0)