Skip to content
Snippets Groups Projects
Select Git revision
  • 570c07901d80355d30487c21c08a9c7753ac0072
  • master default protected
  • ajout_ppa_rsa_budgetaire
  • 365-ouvrir-l-onglet-employeur-ou-taxes-carburant-quand-c-est-le-cas-pour-un-dispositif
  • 381-pb-affichage-labels-des-parametres-sur-plus-de-3-lignes
  • ajoute-duplicate-aide-logement
  • poc_castype_ia
  • parametres-editables-budget
  • ui-parametres
  • 366-signe-a-cote-du-droit-en-vigueur-sur-l-ui-pour-indiquer-que-la-reforme-a-eu-lieu-mais-qu-elle-n
  • 355-les-dispositifs-prestations-sociales-du-graphique-se-cachent-montrent-en-meme-temps-2
  • 358-les-variables-dont-le-montant-est-nul-apparaissent-en-bleu-et-non-cliquables
  • 356-ajuster-la-largeur-sur-les-graphiques-budgetaires
  • incoherence_cas_type_0
  • fix-ui-suppression-tranches-baremes
  • ajout-agregat-cehr-version-plf
  • impact_carbone
  • xlsx
  • header_revamp
  • 270-concevoir-la-page-d-accueil-leximpact
  • 219-conversion-des-montants-min-et-max-de-l-axe-des-x-en-smic
  • 0.0.1123
  • 0.0.1122
  • 0.0.1121
  • 0.0.1120
  • 0.0.1119
  • 0.0.1118
  • 0.0.1117
  • 0.0.1116
  • 0.0.1115
  • 0.0.1114
  • 0.0.1113
  • 0.0.1112
  • 0.0.1111
  • 0.0.1110
  • 0.0.1109
  • 0.0.1108
  • 0.0.1107
  • 0.0.1106
  • 0.0.1105
  • 0.0.1104
41 results

shared.svelte.ts

Blame
  • generate_openfisca_tests_yaml.ts 14.69 KiB
    import type { Situation } from "@openfisca/json-model"
    import commandLineArgs from "command-line-args"
    import fs from "fs-extra"
    import path from "path"
    import YAML from "js-yaml"
    import testCasesCoreUnknown from "@leximpact/socio-fiscal-openfisca-json/test_cases.json"
    import {
      summaryCalculatedVariablesName,
      otherCalculatedVariablesName,
      variableSummaryByName,
    } from "$lib/variables"
    import { nonVirtualVariablesName } from "$lib/decompositions"
    import type { EntityByKey, Entity, GroupEntity } from "@openfisca/json-model"
    import { entityByKey } from "$lib/entities"
    
    type JsonObject = { [key: string]: any }
    
    const optionsDefinitions = [
      {
        alias: "s",
        help: "don't log anything",
        name: "silent",
        type: Boolean,
      },
      {
        alias: "v",
        help: "verbose logs",
        name: "verbose",
        type: Boolean,
      },
      {
        alias: "y",
        help: "Year to ask as simulation output",
        name: "year",
        type: Number,
      },
      {
        defaultOption: true,
        help: "Directory to write OpenFisca test YAML files",
        name: "outdir",
        type: String,
      },
    ]
    const options = commandLineArgs(optionsDefinitions)
    
    async function fetchWithRetries(
      url: string,
      options: RequestInit,
      maxRetries = 5,
      delay = 10000,
    ) {
      for (let attempt = 1; attempt <= maxRetries; attempt++) {
        try {
          const response = await fetch(url, options)
    
          if (response.ok) {
            return response
          }
    
          console.warn(
            `Calling Openfisca API. Attempt ${attempt} : Failed with status ${response.status}`,
          )
        } catch (error) {
          console.error(`Error on attempt ${attempt} :`, error)
        }
    
        if (attempt < maxRetries) {
          console.log(`New attempt in ${delay / 1000}s...`)
          await new Promise((res) => setTimeout(res, delay))
        }