Skip to content

Instantly share code, notes, and snippets.

@MattiSG
Created April 24, 2017 10:54
Show Gist options
  • Save MattiSG/1fba8cec45fa7d01673adb3954971495 to your computer and use it in GitHub Desktop.
Save MattiSG/1fba8cec45fa7d01673adb3954971495 to your computer and use it in GitHub Desktop.
Evaluate valid OpenFisca names from a list
var ressourceTypes = [
'aah',
'aeeh',
'af',
'aide_logement',
'allocationsChomage',
'allocationSecurisationPro',
'asf',
'asi',
'aspa',
'ass',
'autresRevenusTns',
'bourseEnseignementSup',
'bourseRecherche',
'caAutoEntrepreneur',
'caMicroEntreprise',
'cf',
'complementAAH',
'dedommagementAmiante',
'gainsExceptionnels',
'indChomagePartiel',
'indJourAccidentDuTravail',
'indJourMaladie',
'indJourMaladieProf',
'indJourMaternite',
'indVolontariat',
'mva',
'paje_base',
'paje_clca',
'paje_prepare',
'pch',
'pensionsAlimentaires',
'pensionsAlimentairesVersees',
'pensionsInvalidite',
'pensionsRetraitesRentes',
'ppa',
'prestationCompensatoire',
'primeRepriseActivite',
'retraiteCombattant',
'revenusAgricolesTns',
'revenusDuCapital',
'revenusLocatifs',
'revenusSalarie',
'revenusStageFormationPro',
'rsa',
'stage',
'primes',
'indFinDeContrat',
// rnc
'rncRevenusActivite',
'rncAutresRevenus',
'rncPensionsRetraitesRentes',
'fraisReelsDeductibles',
'rncPensionsAlimentaires',
'rncPensionsAlimentairesVersees'
];
// Once https://github.com/openfisca/openfisca-web-api/issues/125 is fixed.
var valid = [],
invalid = [];
ressourceTypes.forEach(id => {
require('https').get(`https://api-test.openfisca.fr/variable/${id}`, res => {
(res.statusCode == 200 ? valid : invalid).push(id);
});
console.log('\nVALID OPENFISCA NAMES (total', valid.length, ')');
console.log(valid.join('\n'));
console.log('\nINVALID OPENFISCA NAMES (total', invalid.length, ')');
console.log(invalid.join('\n'));
const VARIABLES = require('./variables.json').variables; // download this file from https://api.openfisca.fr/api/1/variables/
var valid = [],
invalid = [];
ressourceTypes.forEach(id => {
(VARIABLES.some(variable => variable.name == id) ? valid : invalid).push(id);
});
console.log('\nVALID OPENFISCA NAMES (total', valid.length, ')');
console.log(valid.join('\n'));
console.log('\nINVALID OPENFISCA NAMES (total', invalid.length, ')');
console.log(invalid.join('\n'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment