From 21a1a25598ecb19f4a3cd356bad41ea91b77d51c Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:11:01 +0800 Subject: [PATCH] add comments to output of generators --- data/functions/generate_average_co2.js | 21 ++++++++++++++++----- data/functions/generate_marginal_co2.js | 21 +++++++++++++-------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/data/functions/generate_average_co2.js b/data/functions/generate_average_co2.js index afb8995..3441a00 100644 --- a/data/functions/generate_average_co2.js +++ b/data/functions/generate_average_co2.js @@ -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.} */ const gridIntensityResults = {}; - /** * Object to store general results including additional country information. * @type {Object.} */ const generalResults = {}; - /** * The type of intensity data being processed (average or marginal). * @constant {string} @@ -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.} 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} @@ -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 };` ); /** @@ -145,4 +156,4 @@ const type = "average"; "data/output/average-intensities.json", JSON.stringify(generalResults, null, " ") ); -})(); \ No newline at end of file +})(); diff --git a/data/functions/generate_marginal_co2.js b/data/functions/generate_marginal_co2.js index ebf1f45..a592ad5 100644 --- a/data/functions/generate_marginal_co2.js +++ b/data/functions/generate_marginal_co2.js @@ -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} @@ -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.} */ const csvToJsonResult = {}; - /** * Object to store the grid intensity results for each country. * @type {Object.} @@ -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.} 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. @@ -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}