Skip to content
Snippets Groups Projects
Select Git revision
  • c6c4bf34c5ea91ef62d5d9f8615c55fff8d25130
  • master default protected
  • Dorine-master-patch-14456
  • 4.0.0
  • 3.4.0
  • 3.3.0
  • 3.2.0
  • 3.1.3
  • 3.1.2
  • 3.1.1
  • 3.1.0
  • 3.0.16
  • 3.0.15
  • 3.0.14
  • 3.0.13
  • 3.0.12
  • 3.0.11
  • 3.0.10
  • 3.0.9
  • 3.0.6
  • 3.0.5
  • 3.0.4
  • 3.0.3
23 results

openfisca-json-model

OpenFisca JSON Model

Library & tools to handle informations extracted in JSON or YAML format from OpenFisca parameters, variables, etc

This model is used by LexImpact Tax-Benefit System Simulator

Notes on Parameters Data Format

OpenFisca & LexImpact use several formats to store OpenFisca parameters:

  • The raw unprocessed YAML format is used to store the parameters in OpenFisca country packages repositories (typically in the parameters directory). This format is (currently) loosely defined (=> easy to edit manually, but harder to process).
  • The Python format is the format used internally by OpenFisca. It is obtained when an OpenFisca tax-benefit system loads the raw unprocessed YAML parameters in RAM, convert them to Python objects, pre-process them, etc. A Python script in this repository is able to export this Python data back to YAML (or JSON) format, but its output may not be exactly the same as the original raw unprocessed YAML data, because some parameters may have been created or modified during tax-benefit system pre-processing. This JSON/YAML data generated by the script are called raw processed JSON or YAML.
  • The OpenFisca Web API publishes OpenFisca internal data (aka Python format) using a specific JSON format. This Web API format is different from both the JSON/YAML format & the Python format. It is used by some tools like the OpenFisca legislation explorer, but it is not used by LexImpact.
  • The editable format is another data structure optimized for the edition of the parameters. It is much more strictly defined (and validated) than the raw YAML format. It is the format used by Leximpact socio-fiscal UI. The editable format can be generated from both the raw unprocessed YAML format and the raw processed YAML/JSON format: the editable unprocessed format allows OpenFisca contributors to use Leximpact socio-fiscal UI to add or modify parameters directly in the repositories of OpenFisca country packages, while the editable processed format is used when Leximpact socio-fiscal UI users want to simulate immediately the impact of a parametric reform.

The library @openfisca/json-model and the tools in @openfisca/json-model-tools (both present in this mono-repository are able to convert parameters in raw (unprocessed and processed) JSON or YAML format to editable format and back. They are also able to validate data in both formats.

Installation

git clone https://git.leximpact.dev/leximpact/openfisca-json-model.git
cd openfisca-json-model/packages/extractor/
poetry install --extras france-with-indirect-taxation
cd ../tools/
npm install
npm run build
cd ../

Usage

France

Single Script

cd packages/tools/
node build/scripts/extract_openfisca_json.js
cd ../../

Detailed Scripts

cd packages/extractor
poetry shell
python -m openfisca_json_extractor.scripts.export_tax_benefit_system --country-package openfisca_france_with_indirect_taxation --data-dir ../../../leximpact-socio-fiscal-openfisca-json
python -m openfisca_json_extractor.scripts.export_reforms --country-package openfisca_france_with_indirect_taxation --data-dir ../../../leximpact-socio-fiscal-openfisca-json
exit
cd ../tools/

# node build/scripts/validate_raw_unprocessed_parameters.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/convert_raw_unprocessed_parameters_to_editable_to_raw.js ../../../leximpact-socio-fiscal-openfisca-json/


node build/scripts/convert_raw_processed_parameters_to_editable.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/validate_editable_processed_parameters.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/add_parameters_and_variables_to_formulas.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/add_referring_variables.js ../../../leximpact-socio-fiscal-openfisca-json/

# Adapt file `../../../leximpact-socio-fiscal-openfisca-json/custom/customizations.json` if needed, then
node build/scripts/customize_variables.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/extract_decompositions.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/extract_decompositions.js --customizations ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/customize_decompositions.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/add_unit_to_decomposition_variables.js ../../../leximpact-socio-fiscal-openfisca-json/

node build/scripts/diff_reforms_parameters.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/diff_reforms_variables.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/merge_variables_summaries.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/diff_reforms_decompositions.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/merge_reforms.js ../../../leximpact-socio-fiscal-openfisca-json/
node build/scripts/merge_test_cases.js ../../../leximpact-socio-fiscal-openfisca-json/

node build/scripts/clean_metadata.js ../../../leximpact-socio-fiscal-openfisca-json/

Development

cd openfisca-json-model/packages/extractor/
poetry update

poetry show --outdated
poetry add openfisca-france-with-indirect-taxation@latest --optional

poetry install --extras france-with-indirect-taxation

cd ../../