Skip to content

Commit

Permalink
add comments to output of generators
Browse files Browse the repository at this point in the history
  • Loading branch information
fershad committed Oct 23, 2024
1 parent cab18cf commit 21a1a25
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
21 changes: 16 additions & 5 deletions data/functions/generate_average_co2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ const fs = require("fs");
const sourceURL =
"https://ember-data-api-scg3n.ondigitalocean.app/ember/country_overview_yearly.json?_sort=rowid&_shape=array";


/**
* Object to store the grid intensity results for each country.
* @type {Object.<string, number>}
*/
const gridIntensityResults = {};


/**
* Object to store general results including additional country information.
* @type {Object.<string, Object>}
*/
const generalResults = {};


/**
* The type of intensity data being processed (average or marginal).
* @constant {string}
Expand Down Expand Up @@ -115,6 +112,17 @@ const type = "average";
};
});

const jsDocComments = `/**
* @fileoverview Minified average CO2 emissions intensity data for countries.
* @generated Generated by generate_average_co2.js
* @version 1.0.0
*/
/**
* @constant {Object.<string, number>} data - Average CO2 emissions intensity data for various countries.
* @constant {string} type - Type of data being represented.
*/`;

/**
* Saves the country code and emissions data for use in the CO2.js library.
* @type {void}
Expand All @@ -134,7 +142,10 @@ const type = "average";
*/
fs.writeFileSync(
"src/data/average-intensities.min.js",
`const data = ${JSON.stringify(gridIntensityResults)}; const type = "${type}"; export { data, type }; export default { data, type };`
`${jsDocComments}
const data = ${JSON.stringify(
gridIntensityResults
)}; const type = "${type}"; export { data, type }; export default { data, type };`
);

/**
Expand All @@ -145,4 +156,4 @@ const type = "average";
"data/output/average-intensities.json",
JSON.stringify(generalResults, null, " ")
);
})();
})();
21 changes: 13 additions & 8 deletions data/functions/generate_marginal_co2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ const csv = fs.readFileSync(
"data/IFI_Default_Grid_Factors_2021_v3.1_unfccc.csv"
);


/**
* Utility function to parse CSV rows.
* @type {function}
*/
const parseCSVRow = require("../utils/parseCSVRow");


/**
* Utility function to get country codes.
* @type {function}
Expand All @@ -47,21 +45,18 @@ const source = "UNFCCC";
*/
const year = "2021";


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


/**
* Object to store the converted CSV data.
* @type {Object.<string, Object>}
*/
const csvToJsonResult = {};


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

const jsDocComments = `/**
* @fileoverview Minified marginal CO2 emissions intensity data for countries (2021).
* @generated Generated by generate_marginal_co2.js
* @version 1.0.0
*/
/**
* @constant {Object.<string, number>} data - Average CO2 emissions intensity data for various countries.
* @constant {string} type - Type of data being represented.
* @constant {string} year - Year for which the data was collected.
*/`;

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


/**
* Saves a minified version of the data for easy import into the library.
* @type {void}
*/
fs.writeFileSync(
"src/data/marginal-intensities-2021.min.js",
`const data = ${gridIntensityJson}; const type = "${type}"; const year = "${year}"; export { data, type, year }; export default { data, type, year };`
`${jsDocComments}
const data = ${gridIntensityJson}; const type = "${type}"; const year = "${year}"; export { data, type, year }; export default { data, type, year };`
);


/**
* Saves the full data set as a JSON file for reference.
* @type {void}
Expand Down

0 comments on commit 21a1a25

Please sign in to comment.