Logging in Python OK

This commit is contained in:
Denis Merigoux 2021-06-26 18:04:36 +02:00
parent 32c2e84a10
commit 0d54b39aa9
No known key found for this signature in database
GPG Key ID: EE99DCFA365C3EE3
7 changed files with 256 additions and 14 deletions

View File

@ -313,7 +313,10 @@ let format_ctx (type_ordering : Scopelang.Dependency.TVertex.t list) (fmt : Form
\t\t\treturn False@\n\
@\n\
\tdef __ne__(self, other: object) -> bool:@\n\
\t\treturn not (self == other)" format_struct_name struct_name
\t\treturn not (self == other)@\n\
@\n\
\tdef __str__(self) -> str:@\n\
\t\t@[<hov 4>return \"%a(%a)\".format(%a)@]" format_struct_name struct_name
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt ", ")
(fun _fmt (struct_field, struct_field_type) ->
@ -331,6 +334,16 @@ let format_ctx (type_ordering : Scopelang.Dependency.TVertex.t list) (fmt : Form
(fun _fmt (struct_field, _) ->
Format.fprintf fmt "self.%a == other.%a" format_struct_field_name struct_field
format_struct_field_name struct_field))
struct_fields format_struct_name struct_name
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt ",")
(fun _fmt (struct_field, _) ->
Format.fprintf fmt "%a={}" format_struct_field_name struct_field))
struct_fields
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt ",@ ")
(fun _fmt (struct_field, _) ->
Format.fprintf fmt "self.%a" format_struct_field_name struct_field))
struct_fields
in
let format_enum_decl fmt (enum_name, enum_cons) =
@ -354,7 +367,10 @@ let format_ctx (type_ordering : Scopelang.Dependency.TVertex.t list) (fmt : Form
@\n\
@\n\
\tdef __ne__(self, other: object) -> bool:@\n\
\t\treturn not (self == other)" format_enum_name enum_name
\t\treturn not (self == other)@\n\
@\n\
\tdef __str__(self) -> str:@\n\
\t\t@[<hov 4>return \"{}({})\".format(self.code, self.value)@]" format_enum_name enum_name
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "@\n")
(fun _fmt (i, enum_cons, enum_cons_type) ->

View File

@ -11,3 +11,6 @@ format:
bench:
python main.py bench
show_log:
python main.py show_log

View File

@ -24,7 +24,7 @@ The Python files generated by the Catala compiler expect the presence of the
used by the generated code.
All theses Python files feature type annotations which can be checked against
using the following command inside this directory (`french_law/python`)
using the following command inside this directory (`french_law/python`):
```
make type
@ -32,13 +32,26 @@ make type
### API
To use the algorithms in `src/`, you can take a look at the example provided in
`main.py`. It is very important to wrap all of the input parameters using
`src/catala.py` conversion functions.
To use the algorithms of this library, you can take a look at the example provided in
`main.py`. All the algorithms are centralized with wrappers in `api.py`, as it is
very important internally to wrap all of the input parameters using `src/catala.py`
conversion functions.
You can benchmark the computation using the following command inside this
directory (`french_law/python`)
directory (`french_law/python`):
```
make bench
```
### Logging
The generated Catala code also features a logging feature that let you inspect
each step of the computation, as well as the values flowing through it. You can
directly retrieve a list of log events just after using a Catala-generated
function, and display this list as you wish. An example of such a display can
be showcases by using the following command inside this directory (`french_law/python`):
```
make show_log
```

View File

@ -4,3 +4,5 @@ mypy
python-dateutil
types-python-dateutil
autopep8
termcolor
types-termcolor

View File

@ -3,8 +3,11 @@
from datetime import date
from src.allocations_familiales import PriseEnCharge_Code, Collectivite_Code
from src.api import allocations_familiales, Enfant
from src.catala import LogEvent, LogEventCode, reset_log, retrieve_log
import timeit
import argparse
from typing import List
from termcolor import colored
def call_allocations_familiales() -> float:
@ -32,6 +35,14 @@ def benchmark_iteration():
assert (money_given == 99.37)
def run_with_log() -> List[LogEvent]:
money_given = call_allocations_familiales()
assert (money_given == 99.37)
log = retrieve_log()
reset_log()
return log
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='French law library in Python')
@ -45,6 +56,25 @@ if __name__ == '__main__':
print("Iterating {} iterations of the family benefits computation. Total time (s):".format(
iterations))
print(timeit.timeit(benchmark_iteration, number=iterations))
elif action == "show_log":
log = run_with_log()
indentation = 0
for log_event in log:
if log_event.code == LogEventCode.BeginCall:
print("{}{} {}".format(
"".ljust(indentation), colored("Begin call:", "yellow"), colored(" >> ".join(log_event.payload), "magenta"))) # type: ignore
indentation += 2
elif log_event.code == LogEventCode.EndCall:
indentation -= 2
print("{}{} {}".format(
"".ljust(indentation), colored("End call:", "yellow"), colored(" >> ".join(log_event.payload), "magenta"))) # type: ignore
elif log_event.code == LogEventCode.VariableDefinition:
headings, value = log_event.payload # type: ignore
print("{}{} {} {} {}".format(
"".ljust(indentation), colored("Variable definition:", "blue"), colored(" >> ".join(headings), "magenta"), colored(":=", "blue"), colored(value, "green"))) # type: ignore
elif log_event.code == LogEventCode.DecisionTaken:
print("{}{} {}".format(
"".ljust(indentation), colored("Decision taken:", "green"), colored("{}".format(log_event.payload), "magenta"))) # type: ignore
else:
print("Action '{}' not recognized!".format(action))
exit(-1)

View File

@ -27,6 +27,9 @@ class PriseEnCharge:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "{}({})".format(self.code, self.value)
class SituationObligationScolaire_Code(Enum):
Avant = 0
@ -48,6 +51,9 @@ class SituationObligationScolaire:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "{}({})".format(self.code, self.value)
class Collectivite_Code(Enum):
Guadeloupe = 0
@ -75,6 +81,9 @@ class Collectivite:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "{}({})".format(self.code, self.value)
class PriseEnCompte_Code(Enum):
Complete = 0
@ -96,6 +105,9 @@ class PriseEnCompte:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "{}({})".format(self.code, self.value)
class VersementAllocations_Code(Enum):
Normal = 0
@ -116,6 +128,9 @@ class VersementAllocations:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "{}({})".format(self.code, self.value)
class ElementPrestationsFamiliales_Code(Enum):
PrestationAccueilJeuneEnfant = 0
@ -142,6 +157,9 @@ class ElementPrestationsFamiliales:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "{}({})".format(self.code, self.value)
class EnfantEntree:
def __init__(self, d_identifiant: Integer, d_remuneration_mensuelle: Money, d_date_de_naissance: Date, d_prise_en_charge: PriseEnCharge, d_a_deja_ouvert_droit_aux_allocations_familiales: bool) -> None:
@ -164,6 +182,12 @@ class EnfantEntree:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "EnfantEntree(d_identifiant={},d_remuneration_mensuelle={},d_date_de_naissance={},d_prise_en_charge={},d_a_deja_ouvert_droit_aux_allocations_familiales={})".format(self.d_identifiant,
self.d_remuneration_mensuelle, self.d_date_de_naissance,
self.d_prise_en_charge,
self.d_a_deja_ouvert_droit_aux_allocations_familiales)
class Enfant:
def __init__(self, identifiant: Integer, obligation_scolaire: SituationObligationScolaire, remuneration_mensuelle: Money, date_de_naissance: Date, age: Integer, prise_en_charge: PriseEnCharge, a_deja_ouvert_droit_aux_allocations_familiales: bool) -> None:
@ -190,6 +214,12 @@ class Enfant:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "Enfant(identifiant={},obligation_scolaire={},remuneration_mensuelle={},date_de_naissance={},age={},prise_en_charge={},a_deja_ouvert_droit_aux_allocations_familiales={})".format(self.identifiant,
self.obligation_scolaire, self.remuneration_mensuelle,
self.date_de_naissance, self.age, self.prise_en_charge,
self.a_deja_ouvert_droit_aux_allocations_familiales)
class SmicOut:
def __init__(self, date_courante_out: Date, residence_out: Collectivite, brut_horaire_out: Money) -> None:
@ -208,6 +238,10 @@ class SmicOut:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "SmicOut(date_courante_out={},residence_out={},brut_horaire_out={})".format(self.date_courante_out,
self.residence_out, self.brut_horaire_out)
class SmicIn:
def __init__(self, date_courante_in: Callable[[Unit], Date], residence_in: Callable[[Unit], Collectivite], brut_horaire_in: Callable[[Unit], Money]) -> None:
@ -226,6 +260,10 @@ class SmicIn:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "SmicIn(date_courante_in={},residence_in={},brut_horaire_in={})".format(self.date_courante_in,
self.residence_in, self.brut_horaire_in)
class PrestationsFamilialesOut:
def __init__(self, droit_ouvert_out: Callable[[Enfant], bool], conditions_hors_age_out: Callable[[Enfant], bool], plafond_l512_3_2_out: Money, age_l512_3_2_out: Integer, regime_outre_mer_l751_1_out: bool, date_courante_out: Date, prestation_courante_out: ElementPrestationsFamiliales, residence_out: Collectivite, base_mensuelle_out: Money) -> None:
@ -256,6 +294,13 @@ class PrestationsFamilialesOut:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "PrestationsFamilialesOut(droit_ouvert_out={},conditions_hors_age_out={},plafond_l512_3_2_out={},age_l512_3_2_out={},regime_outre_mer_l751_1_out={},date_courante_out={},prestation_courante_out={},residence_out={},base_mensuelle_out={})".format(self.droit_ouvert_out,
self.conditions_hors_age_out, self.plafond_l512_3_2_out,
self.age_l512_3_2_out, self.regime_outre_mer_l751_1_out,
self.date_courante_out, self.prestation_courante_out,
self.residence_out, self.base_mensuelle_out)
class PrestationsFamilialesIn:
def __init__(self, droit_ouvert_in: Callable[[Unit], (Callable[[Enfant], bool])], conditions_hors_age_in: Callable[[Unit], (Callable[[Enfant], bool])], plafond_l512_3_2_in: Callable[[Unit], Money], age_l512_3_2_in: Callable[[Unit], Integer], regime_outre_mer_l751_1_in: Callable[[Unit], bool], date_courante_in: Callable[[Unit], Date], prestation_courante_in: Callable[[Unit], ElementPrestationsFamiliales], residence_in: Callable[[Unit], Collectivite], base_mensuelle_in: Callable[[Unit], Money]) -> None:
@ -286,6 +331,13 @@ class PrestationsFamilialesIn:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "PrestationsFamilialesIn(droit_ouvert_in={},conditions_hors_age_in={},plafond_l512_3_2_in={},age_l512_3_2_in={},regime_outre_mer_l751_1_in={},date_courante_in={},prestation_courante_in={},residence_in={},base_mensuelle_in={})".format(self.droit_ouvert_in,
self.conditions_hors_age_in, self.plafond_l512_3_2_in,
self.age_l512_3_2_in, self.regime_outre_mer_l751_1_in,
self.date_courante_in, self.prestation_courante_in, self.residence_in,
self.base_mensuelle_in)
class AllocationFamilialesAvril2008Out:
def __init__(self, age_minimum_alinea_1_l521_3_out: Integer) -> None:
@ -300,6 +352,9 @@ class AllocationFamilialesAvril2008Out:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "AllocationFamilialesAvril2008Out(age_minimum_alinea_1_l521_3_out={})".format(self.age_minimum_alinea_1_l521_3_out)
class AllocationFamilialesAvril2008In:
def __init__(self, age_minimum_alinea_1_l521_3_in: Callable[[Unit], Integer]) -> None:
@ -314,6 +369,9 @@ class AllocationFamilialesAvril2008In:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "AllocationFamilialesAvril2008In(age_minimum_alinea_1_l521_3_in={})".format(self.age_minimum_alinea_1_l521_3_in)
class EnfantLePlusAgeOut:
def __init__(self, enfants_out: List[Enfant], le_plus_age_out: Enfant) -> None:
@ -330,6 +388,10 @@ class EnfantLePlusAgeOut:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "EnfantLePlusAgeOut(enfants_out={},le_plus_age_out={})".format(self.enfants_out,
self.le_plus_age_out)
class EnfantLePlusAgeIn:
def __init__(self, enfants_in: Callable[[Unit], (List[Enfant])], le_plus_age_in: Callable[[Unit], Enfant]) -> None:
@ -346,6 +408,10 @@ class EnfantLePlusAgeIn:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "EnfantLePlusAgeIn(enfants_in={},le_plus_age_in={})".format(self.enfants_in,
self.le_plus_age_in)
class AllocationsFamilialesOut:
def __init__(self, personne_charge_effective_permanente_est_parent_out: bool, personne_charge_effective_permanente_remplit_titre_I_out: bool, ressources_menage_out: Money, residence_out: Collectivite, date_courante_out: Date, enfants_a_charge_out: List[Enfant], enfants_a_charge_droit_ouvert_prestation_familiale_out: List[Enfant], prise_en_compte_out: Callable[[Enfant], PriseEnCompte], versement_out: Callable[[Enfant], VersementAllocations], montant_verse_out: Money, droit_ouvert_base_out: bool, montant_initial_base_out: Money, montant_initial_base_premier_enfant_out: Money, montant_initial_base_deuxieme_enfant_out: Money, montant_initial_base_troisieme_enfant_et_plus_out: Money, rapport_enfants_total_moyen_out: Decimal, nombre_moyen_enfants_out: Decimal, nombre_total_enfants_out: Decimal, montant_avec_garde_alternee_base_out: Money, montant_verse_base_out: Money, droit_ouvert_forfaitaire_out: Callable[[Enfant], bool], montant_verse_forfaitaire_par_enfant_out: Money, montant_verse_forfaitaire_out: Money, droit_ouvert_majoration_out: Callable[[Enfant], bool], montant_initial_metropole_majoration_out: Callable[[Enfant], Money], montant_initial_majoration_out: Callable[[Enfant], Money], montant_avec_garde_alternee_majoration_out: Callable[[Enfant], Money], montant_verse_majoration_out: Money, droit_ouvert_complement_out: bool, montant_base_complement_pour_base_et_majoration_out: Money, complement_degressif_out: Callable[[Money], Money], montant_verse_complement_pour_base_et_majoration_out: Money, montant_verse_complement_pour_forfaitaire_out: Money, nombre_enfants_l521_1_out: Integer, age_minimum_alinea_1_l521_3_out: Callable[[Enfant], Integer], nombre_enfants_alinea_2_l521_3_out: Integer, est_enfant_le_plus_age_out: Callable[[Enfant], bool], plafond_I_d521_3_out: Money, plafond_II_d521_3_out: Money) -> None:
@ -436,6 +502,36 @@ class AllocationsFamilialesOut:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "AllocationsFamilialesOut(personne_charge_effective_permanente_est_parent_out={},personne_charge_effective_permanente_remplit_titre_I_out={},ressources_menage_out={},residence_out={},date_courante_out={},enfants_a_charge_out={},enfants_a_charge_droit_ouvert_prestation_familiale_out={},prise_en_compte_out={},versement_out={},montant_verse_out={},droit_ouvert_base_out={},montant_initial_base_out={},montant_initial_base_premier_enfant_out={},montant_initial_base_deuxieme_enfant_out={},montant_initial_base_troisieme_enfant_et_plus_out={},rapport_enfants_total_moyen_out={},nombre_moyen_enfants_out={},nombre_total_enfants_out={},montant_avec_garde_alternee_base_out={},montant_verse_base_out={},droit_ouvert_forfaitaire_out={},montant_verse_forfaitaire_par_enfant_out={},montant_verse_forfaitaire_out={},droit_ouvert_majoration_out={},montant_initial_metropole_majoration_out={},montant_initial_majoration_out={},montant_avec_garde_alternee_majoration_out={},montant_verse_majoration_out={},droit_ouvert_complement_out={},montant_base_complement_pour_base_et_majoration_out={},complement_degressif_out={},montant_verse_complement_pour_base_et_majoration_out={},montant_verse_complement_pour_forfaitaire_out={},nombre_enfants_l521_1_out={},age_minimum_alinea_1_l521_3_out={},nombre_enfants_alinea_2_l521_3_out={},est_enfant_le_plus_age_out={},plafond_I_d521_3_out={},plafond_II_d521_3_out={})".format(self.personne_charge_effective_permanente_est_parent_out,
self.personne_charge_effective_permanente_remplit_titre_I_out,
self.ressources_menage_out, self.residence_out, self.date_courante_out,
self.enfants_a_charge_out,
self.enfants_a_charge_droit_ouvert_prestation_familiale_out,
self.prise_en_compte_out, self.versement_out, self.montant_verse_out,
self.droit_ouvert_base_out, self.montant_initial_base_out,
self.montant_initial_base_premier_enfant_out,
self.montant_initial_base_deuxieme_enfant_out,
self.montant_initial_base_troisieme_enfant_et_plus_out,
self.rapport_enfants_total_moyen_out, self.nombre_moyen_enfants_out,
self.nombre_total_enfants_out,
self.montant_avec_garde_alternee_base_out, self.montant_verse_base_out,
self.droit_ouvert_forfaitaire_out,
self.montant_verse_forfaitaire_par_enfant_out,
self.montant_verse_forfaitaire_out, self.droit_ouvert_majoration_out,
self.montant_initial_metropole_majoration_out,
self.montant_initial_majoration_out,
self.montant_avec_garde_alternee_majoration_out,
self.montant_verse_majoration_out, self.droit_ouvert_complement_out,
self.montant_base_complement_pour_base_et_majoration_out,
self.complement_degressif_out,
self.montant_verse_complement_pour_base_et_majoration_out,
self.montant_verse_complement_pour_forfaitaire_out,
self.nombre_enfants_l521_1_out, self.age_minimum_alinea_1_l521_3_out,
self.nombre_enfants_alinea_2_l521_3_out,
self.est_enfant_le_plus_age_out, self.plafond_I_d521_3_out,
self.plafond_II_d521_3_out)
class AllocationsFamilialesIn:
def __init__(self, personne_charge_effective_permanente_est_parent_in: Callable[[Unit], bool], personne_charge_effective_permanente_remplit_titre_I_in: Callable[[Unit], bool], ressources_menage_in: Callable[[Unit], Money], residence_in: Callable[[Unit], Collectivite], date_courante_in: Callable[[Unit], Date], enfants_a_charge_in: Callable[[Unit], (List[Enfant])], enfants_a_charge_droit_ouvert_prestation_familiale_in: Callable[[Unit], (List[Enfant])], prise_en_compte_in: Callable[[Unit], (Callable[[Enfant], PriseEnCompte])], versement_in: Callable[[Unit], (Callable[[Enfant], VersementAllocations])], montant_verse_in: Callable[[Unit], Money], droit_ouvert_base_in: Callable[[Unit], bool], montant_initial_base_in: Callable[[Unit], Money], montant_initial_base_premier_enfant_in: Callable[[Unit], Money], montant_initial_base_deuxieme_enfant_in: Callable[[Unit], Money], montant_initial_base_troisieme_enfant_et_plus_in: Callable[[Unit], Money], rapport_enfants_total_moyen_in: Callable[[Unit], Decimal], nombre_moyen_enfants_in: Callable[[Unit], Decimal], nombre_total_enfants_in: Callable[[Unit], Decimal], montant_avec_garde_alternee_base_in: Callable[[Unit], Money], montant_verse_base_in: Callable[[Unit], Money], droit_ouvert_forfaitaire_in: Callable[[Unit], (Callable[[Enfant], bool])], montant_verse_forfaitaire_par_enfant_in: Callable[[Unit], Money], montant_verse_forfaitaire_in: Callable[[Unit], Money], droit_ouvert_majoration_in: Callable[[Unit], (Callable[[Enfant], bool])], montant_initial_metropole_majoration_in: Callable[[Unit], (Callable[[Enfant], Money])], montant_initial_majoration_in: Callable[[Unit], (Callable[[Enfant], Money])], montant_avec_garde_alternee_majoration_in: Callable[[Unit], (Callable[[Enfant], Money])], montant_verse_majoration_in: Callable[[Unit], Money], droit_ouvert_complement_in: Callable[[Unit], bool], montant_base_complement_pour_base_et_majoration_in: Callable[[Unit], Money], complement_degressif_in: Callable[[Unit], (Callable[[Money], Money])], montant_verse_complement_pour_base_et_majoration_in: Callable[[Unit], Money], montant_verse_complement_pour_forfaitaire_in: Callable[[Unit], Money], nombre_enfants_l521_1_in: Callable[[Unit], Integer], age_minimum_alinea_1_l521_3_in: Callable[[Unit], (Callable[[Enfant], Integer])], nombre_enfants_alinea_2_l521_3_in: Callable[[Unit], Integer], est_enfant_le_plus_age_in: Callable[[Unit], (Callable[[Enfant], bool])], plafond_I_d521_3_in: Callable[[Unit], Money], plafond_II_d521_3_in: Callable[[Unit], Money]) -> None:
@ -526,6 +622,34 @@ class AllocationsFamilialesIn:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "AllocationsFamilialesIn(personne_charge_effective_permanente_est_parent_in={},personne_charge_effective_permanente_remplit_titre_I_in={},ressources_menage_in={},residence_in={},date_courante_in={},enfants_a_charge_in={},enfants_a_charge_droit_ouvert_prestation_familiale_in={},prise_en_compte_in={},versement_in={},montant_verse_in={},droit_ouvert_base_in={},montant_initial_base_in={},montant_initial_base_premier_enfant_in={},montant_initial_base_deuxieme_enfant_in={},montant_initial_base_troisieme_enfant_et_plus_in={},rapport_enfants_total_moyen_in={},nombre_moyen_enfants_in={},nombre_total_enfants_in={},montant_avec_garde_alternee_base_in={},montant_verse_base_in={},droit_ouvert_forfaitaire_in={},montant_verse_forfaitaire_par_enfant_in={},montant_verse_forfaitaire_in={},droit_ouvert_majoration_in={},montant_initial_metropole_majoration_in={},montant_initial_majoration_in={},montant_avec_garde_alternee_majoration_in={},montant_verse_majoration_in={},droit_ouvert_complement_in={},montant_base_complement_pour_base_et_majoration_in={},complement_degressif_in={},montant_verse_complement_pour_base_et_majoration_in={},montant_verse_complement_pour_forfaitaire_in={},nombre_enfants_l521_1_in={},age_minimum_alinea_1_l521_3_in={},nombre_enfants_alinea_2_l521_3_in={},est_enfant_le_plus_age_in={},plafond_I_d521_3_in={},plafond_II_d521_3_in={})".format(self.personne_charge_effective_permanente_est_parent_in,
self.personne_charge_effective_permanente_remplit_titre_I_in,
self.ressources_menage_in, self.residence_in, self.date_courante_in,
self.enfants_a_charge_in,
self.enfants_a_charge_droit_ouvert_prestation_familiale_in,
self.prise_en_compte_in, self.versement_in, self.montant_verse_in,
self.droit_ouvert_base_in, self.montant_initial_base_in,
self.montant_initial_base_premier_enfant_in,
self.montant_initial_base_deuxieme_enfant_in,
self.montant_initial_base_troisieme_enfant_et_plus_in,
self.rapport_enfants_total_moyen_in, self.nombre_moyen_enfants_in,
self.nombre_total_enfants_in, self.montant_avec_garde_alternee_base_in,
self.montant_verse_base_in, self.droit_ouvert_forfaitaire_in,
self.montant_verse_forfaitaire_par_enfant_in,
self.montant_verse_forfaitaire_in, self.droit_ouvert_majoration_in,
self.montant_initial_metropole_majoration_in,
self.montant_initial_majoration_in,
self.montant_avec_garde_alternee_majoration_in,
self.montant_verse_majoration_in, self.droit_ouvert_complement_in,
self.montant_base_complement_pour_base_et_majoration_in,
self.complement_degressif_in,
self.montant_verse_complement_pour_base_et_majoration_in,
self.montant_verse_complement_pour_forfaitaire_in,
self.nombre_enfants_l521_1_in, self.age_minimum_alinea_1_l521_3_in,
self.nombre_enfants_alinea_2_l521_3_in, self.est_enfant_le_plus_age_in,
self.plafond_I_d521_3_in, self.plafond_II_d521_3_in)
class InterfaceAllocationsFamilialesOut:
def __init__(self, date_courante_out: Date, enfants_out: List[EnfantEntree], enfants_a_charge_out: List[Enfant], ressources_menage_out: Money, residence_out: Collectivite, montant_verse_out: Money, personne_charge_effective_permanente_est_parent_out: bool, personne_charge_effective_permanente_remplit_titre_I_out: bool) -> None:
@ -554,6 +678,13 @@ class InterfaceAllocationsFamilialesOut:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "InterfaceAllocationsFamilialesOut(date_courante_out={},enfants_out={},enfants_a_charge_out={},ressources_menage_out={},residence_out={},montant_verse_out={},personne_charge_effective_permanente_est_parent_out={},personne_charge_effective_permanente_remplit_titre_I_out={})".format(self.date_courante_out,
self.enfants_out, self.enfants_a_charge_out,
self.ressources_menage_out, self.residence_out, self.montant_verse_out,
self.personne_charge_effective_permanente_est_parent_out,
self.personne_charge_effective_permanente_remplit_titre_I_out)
class InterfaceAllocationsFamilialesIn:
def __init__(self, date_courante_in: Callable[[Unit], Date], enfants_in: Callable[[Unit], (List[EnfantEntree])], enfants_a_charge_in: Callable[[Unit], (List[Enfant])], ressources_menage_in: Callable[[Unit], Money], residence_in: Callable[[Unit], Collectivite], montant_verse_in: Callable[[Unit], Money], personne_charge_effective_permanente_est_parent_in: Callable[[Unit], bool], personne_charge_effective_permanente_remplit_titre_I_in: Callable[[Unit], bool]) -> None:
@ -582,6 +713,13 @@ class InterfaceAllocationsFamilialesIn:
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "InterfaceAllocationsFamilialesIn(date_courante_in={},enfants_in={},enfants_a_charge_in={},ressources_menage_in={},residence_in={},montant_verse_in={},personne_charge_effective_permanente_est_parent_in={},personne_charge_effective_permanente_remplit_titre_I_in={})".format(self.date_courante_in,
self.enfants_in, self.enfants_a_charge_in, self.ressources_menage_in,
self.residence_in, self.montant_verse_in,
self.personne_charge_effective_permanente_est_parent_in,
self.personne_charge_effective_permanente_remplit_titre_I_in)
def smic(smic_in_1: SmicIn):
date_courante_2 = smic_in_1.date_courante_in

View File

@ -14,6 +14,8 @@ import datetime
import dateutil.relativedelta
from typing import NewType, List, Callable, Tuple, Optional, TypeVar, Iterable, Union
from functools import reduce
from enum import Enum
import copy
Alpha = TypeVar('Alpha')
Beta = TypeVar('Beta')
@ -114,7 +116,7 @@ class Decimal:
return False
def __str__(self) -> str:
return self.value.__str__()
return "{}".format(mpfr(self.value))
class Money:
@ -206,6 +208,9 @@ class Date:
else:
return False
def __str__(self) -> str:
return self.value.__str__()
class Duration:
def __init__(self, value: dateutil.relativedelta.relativedelta) -> None:
@ -264,6 +269,9 @@ class Duration:
else:
return False
def __str__(self) -> str:
return self.value.__str__()
class Unit:
def __init__(self) -> None:
@ -281,6 +289,9 @@ class Unit:
else:
return True
def __str__(self) -> str:
return "()"
class SourcePosition:
def __init__(self,
@ -298,8 +309,8 @@ class SourcePosition:
self.law_headings = law_headings
def __str__(self) -> str:
return "in file {}, from {}:{} to {}:{} ({})".format(
self.filename, self.start_line, self.start_column, self.end_line, self.end_column, ", ".join(self.law_headings))
return "in file {}, from {}:{} to {}:{}".format(
self.filename, self.start_line, self.start_column, self.end_line, self.end_column)
# ==========
# Exceptions
@ -514,17 +525,46 @@ def no_input() -> Callable[[Unit], Alpha]:
# =======
class LogEventCode(Enum):
VariableDefinition = 0
BeginCall = 1
EndCall = 2
DecisionTaken = 3
class LogEvent:
def __init__(self, code: LogEventCode, payload: Union[List[str], SourcePosition, Tuple[List[str], Alpha]]) -> None:
self.code = code
self.payload = payload
log: List[LogEvent] = []
def reset_log():
log = []
def retrieve_log() -> List[LogEvent]:
return log
def log_variable_definition(headings: List[str], value: Alpha) -> Alpha:
log.append(LogEvent(LogEventCode.VariableDefinition,
(headings, copy.deepcopy(value))))
return value
def log_begin_call(headings: List[str], f: Callable[[Alpha], Beta], value: Alpha) -> Beta:
log.append(LogEvent(LogEventCode.BeginCall, headings))
return f(value)
def log_end_call(headings: List[str], value: Alpha) -> Alpha:
log.append(LogEvent(LogEventCode.EndCall, headings))
return value
def log_decision_taken(pos: SourcePosition, value: bool) -> bool:
log.append(LogEvent(LogEventCode.DecisionTaken, pos))
return value