Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce situations example #23

Merged
merged 5 commits into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

### 0.1.0 [#23](https://github.com/openfisca/tutorial/pull/23)

* Add a Python situation generator script for OpenFisca-France in `python/scripts/generate_situation_examples`.
* Details :
- introduces "ready to use" examples of situations
- the `json` files situated in the `python/scripts/generate_situation_examples/situation_examples/` directory can be used with the Web API
- a usage example can be found in `python/scripts/generate_situation_examples/try_situation_example/`
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,23 @@ Just click here to start:

## Python

Tutorials in [python](https://www.python.org) programming language for [reforms](http://openfisca.org/doc/reforms.html) creation on the French tax and benefit system.
### [Python tutorials for OpenFisca-France](./python/)

With the Python [Tutorials](./python/) (in French), you will learn how to:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redondant ?

- use the python API to run calculations
- get results on the current legislation as well as on reforms
- export results to .csv files

### [Situations for OpenFisca-France](./python/situations)

This directory contains pre-filled input data, called situations, extracted from the French ["Livret du pouvoir d'achat"](https://www.economie.gouv.fr/files/files/PLF2018/bro-pouvoir-achat-bat-web-10h.pdf).

You can use them 'as is' in the web API or import them in the python API as shown in the python tutorials.

### [Python scripts for OpenFisca-France](./python/scripts)

- [`openfisca_json_customizer.py`](./python/scripts/openfisca_json_customizer.py) takes in an OpenFisca situation and customizes it thanks to a few helper methods.
- [`clean_mes_aides_situation.py`](./python/scripts/clean_mes_aides_situation.py) takes in a [Mes Aides](https://mes-aides.gouv.fr) situation and turns it into an OpenFisca-France situation.
- [`generate_situation_example`](./python/scripts/generate_situation_examples) contains the `situation_example package`, along with the `try_situation_examples.py` script. The `situation_examples` package contains complete cookie cutter situations (single, couple, roommates) that are ready to use in the python API, and the web API (in their json form)

To run one of the following scripts, go to its directory an call it with the `python` command.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-

import json
import os


DIR_PATH = os.path.dirname(os.path.abspath(__file__))


def parse(file_name):
file_path = os.path.join(DIR_PATH, file_name)
with open(file_path, 'r') as file:
return json.loads(file.read())


celibataire = parse('celibataire.json')
couple = parse('couple.json')
colocation = parse('colocation.json')
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"individus": {
"Alicia": {
"date_naissance": {
"ETERNITY": "1990-01-01"
}
}
},
"familles": {
"_": {
"parents": ["Alicia"]
}
},
"foyers_fiscaux": {
"_": {
"declarants": ["Alicia"]
}
},
"menages": {
"_": {
"personne_de_reference": ["Alicia"],
"revenu_disponible": {
"2017": null
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"individus": {
"Alicia": {
"date_naissance": {
"ETERNITY": "1990-01-01"
},
"salaire_net": {
"2017-01": 4000
}
},
"Bob": {
"date_naissance": {
"ETERNITY": "1991-06-01"
},
"salaire_net": {
"2017-01": 2500
}
}
},
"familles": {
"Alicia": {
"parents": ["Alicia"]
},
"Bob": {
"parents": ["Bob"]
}
},
"foyers_fiscaux": {
"Alicia": {
"declarants": ["Alicia"]
},
"Bob": {
"declarants": ["Bob"]
}
},
"menages": {
"_": {
"personne_de_reference": ["Alicia"],
"conjoint": ["Bob"],
"revenu_disponible": {
"2017": null
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"individus": {
"Alicia": {
"date_naissance": {
"ETERNITY": "1990-01-01"
},
"salaire_net": {
"2017-01": 4000
}
},
"Bob": {
"date_naissance": {
"ETERNITY": "1991-06-01"
},
"salaire_net": {
"2017-01": 2500
}
}
},
"familles": {
"_": {
"parents": ["Alicia", "Bob"]
}
},
"foyers_fiscaux": {
"_": {
"declarants": ["Alicia", "Bob"]
}
},
"menages": {
"_": {
"personne_de_reference": ["Alicia"],
"conjoint": ["Bob"],
"revenu_disponible": {
"2017": null
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-

from openfisca_france import CountryTaxBenefitSystem
from openfisca_core.simulations import Simulation
from situation_examples import celibataire

tax_benefit_system = CountryTaxBenefitSystem()
simulation = Simulation(tax_benefit_system = tax_benefit_system, simulation_json = celibataire)

print (simulation.calculate('revenu_disponible', '2016'))