Last active
June 23, 2022 16:25
-
-
Save antw/f301c81d0c1c9d985fe372828370435b to your computer and use it in GitHub Desktop.
Active inputs
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
// Fetch all the inputs. | |
const inputs = await ( | |
await fetch("https://engine.energytransitionmodel.com/api/v3/scenarios/925016/inputs") | |
).json(); | |
// Fetch the scenario data, which contains the user_values. | |
const scenario = await ( | |
await fetch("https://engine.energytransitionmodel.com/api/v3/scenarios/925016?detailed=true") | |
).json(); | |
const activeKeys = new Set(Object.keys(scenario.user_values)); | |
// activeInputs will contain the inputs data for only those inputs where a value was set in | |
// the scenario. | |
const activeInputs = Object.keys(inputs).reduce((acc, key) => { | |
if (activeKeys.has(key)) { | |
acc[key] = inputs[key] | |
} | |
return acc; | |
}, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment