Skip to content

Instantly share code, notes, and snippets.

@antw
Last active June 23, 2022 16:25
Show Gist options
  • Save antw/f301c81d0c1c9d985fe372828370435b to your computer and use it in GitHub Desktop.
Save antw/f301c81d0c1c9d985fe372828370435b to your computer and use it in GitHub Desktop.
Active inputs
// 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