This commit is contained in:
Denis Merigoux 2022-09-26 19:19:15 +02:00
parent e6ba0980d8
commit 89dab52caa
No known key found for this signature in database
GPG Key ID: EE99DCFA365C3EE3
4 changed files with 22 additions and 29 deletions

View File

@ -25,13 +25,12 @@ def run_catala_by_converting_cnaf_input(sample_input: CnafSimulatorInput) -> flo
infos_specifiques: InfosSpecifiques
if isinstance(sample_input.logement, AppartementOuMaison):
mode_occupation = (ModeOccupation_Code.Locataire if sample_input.logement.typ(
) == AppartementOuMaisonType.Location else ModeOccupation_Code.SousLocataire)
mode_occupation = AppartementOuMaisonType.Location
infos_specifiques = InfosLocation(
loyer_principal=sample_input.loyer,
beneficiaire_aide_adulte_ou_enfant_handicapes=False,
logement_est_chambre=False,
colocation=False,
colocation=sample_input.logement.typ_v == AppartementOuMaisonType.Colocation,
agees_ou_handicap_adultes_hebergees_onereux_particuliers=False,
logement_meuble_d842_2=sample_input.logement.meuble_v,
ancien_loyer_et_apl_relogement=None,

View File

@ -1,23 +1,12 @@
from input import CnafSimulatorInput
from cnaf_to_catala import run_catala_by_converting_cnaf_input
from pupeteer import run_simulator
from input import AppartementOuMaison, AppartementOuMaisonType, CnafSimulatorInput, Enfant, SeulOuCouple, Zone
from random_input_generator import generate_random_input
# Output identical to the JS test of the housing benefits
sample_input = CnafSimulatorInput(
zone=Zone.Zone2,
logement=AppartementOuMaison(
AppartementOuMaisonType.Location, meuble=False),
loyer=450,
seul_ou_couple=SeulOuCouple.EnCouple,
enfants=[Enfant(age=7, remuneration_derniere_annee=0),
Enfant(age=8, remuneration_derniere_annee=0)],
revenu_pris_en_compte=11_500
)
sample_input = generate_random_input()
print("🏡 Description du ménage")
print(sample_input)
housing_benefits_catala = run_catala_by_converting_cnaf_input(sample_input)

View File

@ -10,7 +10,7 @@ HOME_PAGE = 'https://wwwd.caf.fr/wps/portal/caffr/aidesetservices/lesservicesenl
def run_simulator(input: CnafSimulatorInput) -> int:
with sync_playwright() as p:
browser = p.firefox.launch(headless=True, slow_mo=100)
browser = p.firefox.launch(headless=False, slow_mo=100)
page = browser.new_page()
# Go to the CNAF simulator
@ -104,6 +104,7 @@ def run_simulator(input: CnafSimulatorInput) -> int:
raise RuntimeError
salaires_input.fill("{}".format(
int(float(input.revenu_pris_en_compte) / 0.9)))
salaires_input.wait_for_element_state(state="stable")
# We divide by 0.9 because salaries have a 10% franchise
# Now if the salary is too low you have to click another button
status_selector = "input[id=\"sitro_0_SITPRO_ACT_INCONNUE\"]"
@ -184,18 +185,21 @@ def run_simulator(input: CnafSimulatorInput) -> int:
raise RuntimeError
continuer_button.click(force=True)
# Retrieve the amount
page.wait_for_selector('section[id="resultat"]')
result = page.locator('text=/\\d+ € par mois/').text_content()
if result is None:
raise RuntimeError
# Wait for result page
page.wait_for_selector("section[id=\"resultat\"]")
match = re.search("(\\d+) € par mois", result)
if match is None:
raise RuntimeError
housing_benefits = match.group(1)
if housing_benefits is None:
raise RuntimeError
# Retrieve the amount
result = page.query_selector('text=/\\d+ € par mois/').text_content()
if result is None:
# Then no benefits!
housing_benefits = 0
else:
match = re.search("(\\d+) € par mois", result)
if match is None:
raise RuntimeError
housing_benefits = match.group(1)
if housing_benefits is None:
raise RuntimeError
browser.close()
return int(housing_benefits)

View File

@ -4,7 +4,8 @@ from input import AppartementOuMaison, AppartementOuMaisonType, CnafSimulatorInp
def generate_random_child() -> Enfant:
age = random.randint(0, 25)
remuneration_derniere_annee = random.randint(0, 12 * 1500)
# For now we don't put income for children for simplicity
remuneration_derniere_annee = random.randint(0, 0)
return Enfant(age, remuneration_derniere_annee)