Skip to content

Commit 21a1a25

Browse files
committed
add comments to output of generators
1 parent cab18cf commit 21a1a25

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

data/functions/generate_average_co2.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,18 @@ const fs = require("fs");
1414
const sourceURL =
1515
"https://ember-data-api-scg3n.ondigitalocean.app/ember/country_overview_yearly.json?_sort=rowid&_shape=array";
1616

17-
1817
/**
1918
* Object to store the grid intensity results for each country.
2019
* @type {Object.<string, number>}
2120
*/
2221
const gridIntensityResults = {};
2322

24-
2523
/**
2624
* Object to store general results including additional country information.
2725
* @type {Object.<string, Object>}
2826
*/
2927
const generalResults = {};
3028

31-
3229
/**
3330
* The type of intensity data being processed (average or marginal).
3431
* @constant {string}
@@ -115,6 +112,17 @@ const type = "average";
115112
};
116113
});
117114

115+
const jsDocComments = `/**
116+
* @fileoverview Minified average CO2 emissions intensity data for countries.
117+
* @generated Generated by generate_average_co2.js
118+
* @version 1.0.0
119+
*/
120+
121+
/**
122+
* @constant {Object.<string, number>} data - Average CO2 emissions intensity data for various countries.
123+
* @constant {string} type - Type of data being represented.
124+
*/`;
125+
118126
/**
119127
* Saves the country code and emissions data for use in the CO2.js library.
120128
* @type {void}
@@ -134,7 +142,10 @@ const type = "average";
134142
*/
135143
fs.writeFileSync(
136144
"src/data/average-intensities.min.js",
137-
`const data = ${JSON.stringify(gridIntensityResults)}; const type = "${type}"; export { data, type }; export default { data, type };`
145+
`${jsDocComments}
146+
const data = ${JSON.stringify(
147+
gridIntensityResults
148+
)}; const type = "${type}"; export { data, type }; export default { data, type };`
138149
);
139150

140151
/**
@@ -145,4 +156,4 @@ const type = "average";
145156
"data/output/average-intensities.json",
146157
JSON.stringify(generalResults, null, " ")
147158
);
148-
})();
159+
})();

data/functions/generate_marginal_co2.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ const csv = fs.readFileSync(
1515
"data/IFI_Default_Grid_Factors_2021_v3.1_unfccc.csv"
1616
);
1717

18-
1918
/**
2019
* Utility function to parse CSV rows.
2120
* @type {function}
2221
*/
2322
const parseCSVRow = require("../utils/parseCSVRow");
2423

25-
2624
/**
2725
* Utility function to get country codes.
2826
* @type {function}
@@ -47,21 +45,18 @@ const source = "UNFCCC";
4745
*/
4846
const year = "2021";
4947

50-
5148
/**
5249
* Converts the CSV data to an array of strings, each representing a row.
5350
* @type {string[]}
5451
*/
5552
const array = csv.toString().split("\n");
5653

57-
5854
/**
5955
* Object to store the converted CSV data.
6056
* @type {Object.<string, Object>}
6157
*/
6258
const csvToJsonResult = {};
6359

64-
6560
/**
6661
* Object to store the grid intensity results for each country.
6762
* @type {Object.<string, string>}
@@ -133,6 +128,17 @@ for (let currentArrayString of array.slice(5)) {
133128
const json = JSON.stringify(csvToJsonResult);
134129
const gridIntensityJson = JSON.stringify(gridIntensityResults);
135130

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+
*/`;
136142

137143
/**
138144
* Saves the country code and emissions data for use in the CO2.js library.
@@ -149,17 +155,16 @@ fs.writeFileSync(
149155
`
150156
);
151157

152-
153158
/**
154159
* Saves a minified version of the data for easy import into the library.
155160
* @type {void}
156161
*/
157162
fs.writeFileSync(
158163
"src/data/marginal-intensities-2021.min.js",
159-
`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 };`
160166
);
161167

162-
163168
/**
164169
* Saves the full data set as a JSON file for reference.
165170
* @type {void}

0 commit comments

Comments
 (0)