2021-02-01 22:09:16 +03:00
|
|
|
(* This file is part of the French law library, a collection of functions for computing French taxes
|
|
|
|
and benefits derived from Catala programs. Copyright (C) 2021 Inria, contributor: Denis Merigoux
|
|
|
|
<denis.merigoux@inria.fr>
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
|
|
in compliance with the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
or implied. See the License for the specific language governing permissions and limitations under
|
|
|
|
the License. *)
|
|
|
|
|
2021-05-17 18:45:48 +03:00
|
|
|
module AF = Api.Allocations_familiales
|
2021-03-05 21:16:56 +03:00
|
|
|
open Runtime
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
let random_children (id : int) =
|
|
|
|
{
|
|
|
|
AF.d_identifiant = integer_of_int id;
|
2021-03-05 21:16:56 +03:00
|
|
|
d_remuneration_mensuelle = money_of_units_int (Random.int 2000);
|
2021-01-30 19:54:05 +03:00
|
|
|
d_date_de_naissance =
|
|
|
|
date_of_numbers (2020 - Random.int 22) (1 + Random.int 12) (1 + Random.int 28);
|
2021-03-17 21:35:21 +03:00
|
|
|
d_prise_en_charge =
|
2021-03-23 12:59:43 +03:00
|
|
|
(match Random.int 5 with
|
2021-03-17 21:35:21 +03:00
|
|
|
| 0 -> AF.EffectiveEtPermanente ()
|
|
|
|
| 1 -> AF.GardeAlterneePartageAllocations ()
|
|
|
|
| 2 -> AF.GardeAlterneeAllocataireUnique ()
|
|
|
|
| 3 -> AF.ServicesSociauxAllocationVerseeALaFamille ()
|
2021-03-23 12:59:43 +03:00
|
|
|
| _ -> AF.ServicesSociauxAllocationVerseeAuxServicesSociaux ());
|
2021-03-17 21:35:21 +03:00
|
|
|
d_a_deja_ouvert_droit_aux_allocations_familiales = true;
|
2021-01-30 19:54:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let format_residence (fmt : Format.formatter) (r : AF.collectivite) : unit =
|
|
|
|
Format.fprintf fmt "%s"
|
2021-03-23 12:59:43 +03:00
|
|
|
(match r with
|
2021-01-30 19:54:05 +03:00
|
|
|
| AF.Metropole _ -> "Métropole"
|
|
|
|
| AF.Guyane _ -> "Guyane"
|
|
|
|
| AF.Guadeloupe _ -> "Guadeloupe"
|
|
|
|
| AF.Martinique _ -> "Martinique"
|
|
|
|
| AF.LaReunion _ -> "La Réunion"
|
|
|
|
| AF.SaintBarthelemy _ -> "Saint Barthélemy"
|
|
|
|
| AF.SaintPierreEtMiquelon _ -> "Saint Pierre et Miquelon"
|
|
|
|
| AF.SaintMartin _ -> "Saint Martin"
|
2021-03-23 12:59:43 +03:00
|
|
|
| AF.Mayotte _ -> "Mayotte")
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-17 21:35:21 +03:00
|
|
|
let format_prise_en_charge (fmt : Format.formatter) (g : AF.prise_en_charge) : unit =
|
2021-01-30 19:54:05 +03:00
|
|
|
Format.fprintf fmt "%s"
|
2021-03-23 12:59:43 +03:00
|
|
|
(match g with
|
2021-03-17 21:35:21 +03:00
|
|
|
| AF.EffectiveEtPermanente _ -> "Effective et permanente"
|
|
|
|
| AF.GardeAlterneePartageAllocations _ -> "Garde alternée, allocations partagée"
|
|
|
|
| AF.GardeAlterneeAllocataireUnique _ -> "Garde alternée, allocataire unique"
|
|
|
|
| AF.ServicesSociauxAllocationVerseeALaFamille _ -> "Oui, allocations versée à la famille"
|
|
|
|
| AF.ServicesSociauxAllocationVerseeAuxServicesSociaux _ ->
|
2021-03-23 12:59:43 +03:00
|
|
|
"Oui, allocations versée aux services sociaux")
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
let num_successful = ref 0
|
|
|
|
|
|
|
|
let total_amount = ref 0.
|
|
|
|
|
|
|
|
let run_test () =
|
|
|
|
let num_children = Random.int 7 in
|
|
|
|
let children = Array.init num_children random_children in
|
|
|
|
let income = Random.int 100000 in
|
2021-03-05 21:16:56 +03:00
|
|
|
let current_date = Runtime.date_of_numbers 2020 05 01 in
|
2021-01-30 19:54:05 +03:00
|
|
|
let residence = if Random.bool () then AF.Metropole () else AF.Guadeloupe () in
|
|
|
|
try
|
|
|
|
let amount =
|
2021-05-17 18:45:48 +03:00
|
|
|
Api.compute_allocations_familiales ~current_date ~income ~residence ~children ~is_parent:true
|
|
|
|
~fills_title_I:true
|
2021-01-30 19:54:05 +03:00
|
|
|
in
|
|
|
|
incr num_successful;
|
|
|
|
total_amount := Float.add !total_amount amount
|
|
|
|
with
|
2021-04-03 20:31:33 +03:00
|
|
|
| (NoValueProvided | ConflictError) as err ->
|
|
|
|
Format.printf "%s\n%a\nincome: %d\ncurrent_date: %s\nresidence: %a\n"
|
|
|
|
(match err with
|
|
|
|
| NoValueProvided -> "No value provided somewhere!"
|
|
|
|
| ConflictError -> "Conflict error!"
|
|
|
|
| _ -> failwith "impossible")
|
2021-01-30 19:54:05 +03:00
|
|
|
(Format.pp_print_list (fun fmt child ->
|
2021-03-17 21:35:21 +03:00
|
|
|
Format.fprintf fmt "Child %d:\n income: %.2f\n birth date: %s\n prise en charge: %a"
|
2021-01-30 19:54:05 +03:00
|
|
|
(integer_to_int child.AF.d_identifiant)
|
|
|
|
(money_to_float child.AF.d_remuneration_mensuelle)
|
2021-03-05 21:16:56 +03:00
|
|
|
(Runtime.date_to_string child.AF.d_date_de_naissance)
|
2021-03-17 21:35:21 +03:00
|
|
|
format_prise_en_charge child.AF.d_prise_en_charge))
|
2021-01-30 19:54:05 +03:00
|
|
|
(Array.to_list children) income
|
2021-03-05 21:16:56 +03:00
|
|
|
(Runtime.date_to_string current_date)
|
2021-01-30 19:54:05 +03:00
|
|
|
format_residence residence;
|
|
|
|
exit (-1)
|
|
|
|
| AssertionFailed -> ()
|
|
|
|
|
|
|
|
let bench =
|
|
|
|
Random.init (int_of_float (Unix.time ()));
|
|
|
|
let num_iter = 100000 in
|
|
|
|
let _ =
|
|
|
|
Benchmark.latency1 ~style:Auto ~name:"Allocations familiales" (Int64.of_int num_iter) run_test
|
|
|
|
()
|
|
|
|
in
|
|
|
|
Printf.printf
|
|
|
|
"Successful computations: %d (%.2f%%)\nTotal benefits awarded: %.2f€ (mean %.2f€)\n"
|
|
|
|
!num_successful
|
|
|
|
(Float.mul (Float.div (float_of_int !num_successful) (float_of_int num_iter)) 100.)
|
|
|
|
!total_amount
|
|
|
|
(Float.div !total_amount (float_of_int !num_successful))
|