Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
clallemand committed Sep 4, 2023
1 parent b91b2b2 commit 0727e64
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
28 changes: 25 additions & 3 deletions openfisca_france_data/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import numpy as np
import pandas as pd
import pkg_resources

import os
from datetime import datetime

from openfisca_survey_manager.aggregates import AbstractAggregates
from openfisca_france_data import AGGREGATES_DEFAULT_VARS # type: ignore
Expand Down Expand Up @@ -39,7 +40,7 @@ def __init__(self, survey_scenario = None, target_source = None):

def load_actual_data(self, year = None):
target_source = self.target_source
assert target_source in ["ines", "taxipp"], "les options possible pour source_cible sont ines ou taxipp"
assert target_source in ["ines", "taxipp", "france_entiere"], "les options possible pour source_cible sont ines, taxipp ou france_entiere"
assert year is not None

if target_source == "taxipp":
Expand Down Expand Up @@ -120,10 +121,31 @@ def load_actual_data(self, year = None):
with open(ines_aggregates_file, 'r') as f:
data = json.load(f)

result = pd.DataFrame(data['data']).drop(['source', 'notes'], axis = 1)
result = pd.DataFrame(data['data']).drop(['source'], axis = 1)
result['actual_beneficiaries'] = result. actual_beneficiaries / self.beneficiaries_unit
result['actual_amount'] = result. actual_amount / self.amount_unit

result = result[["variable","actual_amount","actual_beneficiaries"]].set_index("variable")

return result

def to_csv(self, path = None, absolute = True, amount = True, beneficiaries = True, default = 'actual',
relative = True, target = "reform"):
"""Saves the table to csv."""
assert path is not None

if os.path.isdir(path):
now = datetime.now()
file_path = os.path.join(path, 'Aggregates_%s_%s_%s.%s' % (self.target_source,self.year,now.strftime('%d-%m-%Y'), "csv"))
else:
file_path = path

df = self.get_data_frame(
absolute = absolute,
amount = amount,
beneficiaries = beneficiaries,
default = default,
relative = relative,
target = target,
)
df.to_csv(file_path, index = False, header = True)
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
},
{
"variable":"apl",
"actual_beneficiaries": 6743703175,
"actual_amount": 0,
"actual_beneficiaries": 0,
"actual_amount": 6743703175,
"source": "Rapport du Directeur comptable et financier sur les comptes de l'exercice 2021, CAF (https://www.caf.fr/sites/default/files/medias/cnaf/Nous_connaitre/qui%20sommes%20nous/presentation/Comptes-et-financements/2021/Rapport_Dcf_comptes_exercice2021.pdf)"
},
{
Expand Down
4 changes: 2 additions & 2 deletions openfisca_france_data/model/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def formula(individu, period):
class csg_retraite(Variable):
value_type = float
entity = Individu
label = 'Contribution sociale généralisée sur les non salariés'
label = 'CSG sur les retraites'
definition_period = YEAR
def formula(individu, period):
csg_imposable_retraite = individu('csg_imposable_retraite', period, options = [ADD])
Expand All @@ -110,7 +110,7 @@ def formula(individu, period):
class csg_chomage(Variable):
value_type = float
entity = Individu
label = 'Contribution sociale généralisée sur les non salariés'
label = 'CSG sur le chomage'
definition_period = YEAR
def formula(individu, period):
csg_imposable_chomage = individu('csg_imposable_chomage', period, options = [ADD])
Expand Down

0 comments on commit 0727e64

Please sign in to comment.