Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
leximpact-socio-fiscal-api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leximpact
Simulateur socio-fiscal
leximpact-socio-fiscal-api
Commits
ff8f822b
Commit
ff8f822b
authored
Feb 6, 2024
by
Emmanuel Raviart
Browse files
Options
Downloads
Patches
Plain Diff
Prettify
parent
1756dbb3
No related branches found
No related tags found
No related merge requests found
Pipeline
#12934
passed
Feb 6, 2024
Stage: build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
leximpact_socio_fiscal_api/routers/simulations.py
+114
-73
114 additions, 73 deletions
leximpact_socio_fiscal_api/routers/simulations.py
with
114 additions
and
73 deletions
leximpact_socio_fiscal_api/routers/simulations.py
+
114
−
73
View file @
ff8f822b
...
...
@@ -57,17 +57,17 @@ class Evaluation(BaseModel):
description
=
"
The name of the entity that the variable belongs to
"
)
name
:
str
=
Field
(
description
=
"
Variable name
"
)
value
:
list
[
bool
]
|
list
[
float
]
|
list
[
int
]
|
list
[
str
]
=
"
Vector of calculated value of variable
"
value
:
list
[
bool
]
|
list
[
float
]
|
list
[
int
]
|
list
[
str
]
=
(
"
Vector of calculated value of variable
"
)
class
EvaluationStep
(
BaseModel
):
name
:
str
=
Field
(
description
=
"
Variable name
"
)
period
:
str
=
Field
(
description
=
"
period at which the variable was evaluated
"
)
value
:
list
[
bool
]
|
list
[
float
]
|
list
[
int
]
|
list
[
str
]
=
"
Vector of calculated value of variable
"
value
:
list
[
bool
]
|
list
[
float
]
|
list
[
int
]
|
list
[
str
]
=
(
"
Vector of calculated value of variable
"
)
class
CalculateResult
(
BaseModel
):
...
...
@@ -107,9 +107,9 @@ def apply_parametric_reform(parameters, parameter_change_by_name):
# doesn't work => Use children instead.
children
=
getattr
(
parameter
,
"
children
"
,
None
)
if
children
is
None
:
errors
[
name
]
=
f
"
Parameter
{
id
}
doesn
'
t exist, because parent has no children
"
errors
[
name
]
=
(
f
"
Parameter
{
id
}
doesn
'
t exist, because parent has no children
"
)
break
parameter
=
children
.
get
(
id
)
if
parameter
is
None
:
...
...
@@ -143,10 +143,14 @@ def apply_parametric_reform(parameters, parameter_change_by_name):
value_key
=
(
"
amount
"
if
any
(
"
amount
"
in
bracket
.
children
for
bracket
in
brackets
)
else
"
average_rate
"
if
any
(
"
average_rate
"
in
bracket
.
children
for
bracket
in
brackets
)
else
(
"
average_rate
"
if
any
(
"
average_rate
"
in
bracket
.
children
for
bracket
in
brackets
)
else
"
rate
"
)
)
brackets_change
=
[]
for
bracket
in
change
[
"
scale
"
]:
...
...
@@ -154,9 +158,9 @@ def apply_parametric_reform(parameters, parameter_change_by_name):
threshold
=
bracket
[
"
threshold
"
]
if
threshold
==
"
expected
"
:
errors
[
name
]
=
"
Brackets with
'
expected
'
values are not supported.
"
errors
[
name
]
=
(
"
Brackets with
'
expected
'
values are not supported.
"
)
break
value
=
threshold
[
"
value
"
]
if
value
is
None
:
...
...
@@ -167,33 +171,33 @@ def apply_parametric_reform(parameters, parameter_change_by_name):
if
value_key
==
"
amount
"
:
amount
=
bracket
[
"
amount
"
]
if
amount
==
"
expected
"
:
errors
[
name
]
=
"
Brackets with
'
expected
'
values are not supported.
"
errors
[
name
]
=
(
"
Brackets with
'
expected
'
values are not supported.
"
)
break
bracket_change
[
"
amount
"
]
=
amount
[
"
value
"
]
elif
value_key
==
"
average_rate
"
:
rate
=
bracket
[
"
rate
"
]
if
rate
==
"
expected
"
:
errors
[
name
]
=
"
Brackets with
'
expected
'
values are not supported.
"
errors
[
name
]
=
(
"
Brackets with
'
expected
'
values are not supported.
"
)
break
bracket_change
[
"
average_rate
"
]
=
rate
[
"
value
"
]
else
:
base
=
bracket
.
get
(
"
base
"
)
if
base
is
not
None
:
if
base
==
"
expected
"
:
errors
[
name
]
=
"
Brackets with
'
expected
'
values are not supported.
"
errors
[
name
]
=
(
"
Brackets with
'
expected
'
values are not supported.
"
)
break
bracket_change
[
"
base
"
]
=
base
[
"
value
"
]
rate
=
bracket
[
"
rate
"
]
if
rate
==
"
expected
"
:
errors
[
name
]
=
"
Brackets with
'
expected
'
values are not supported.
"
errors
[
name
]
=
(
"
Brackets with
'
expected
'
values are not supported.
"
)
break
bracket_change
[
"
rate
"
]
=
rate
[
"
value
"
]
brackets_change
.
append
(
bracket_change
)
...
...
@@ -357,16 +361,22 @@ async def calculate(
simulation
.
calculate
(
variable_name
,
period
)
if
variable
.
definition_period
is
ETERNITY
or
variable
.
definition_period
is
YEAR
else
simulation
.
calculate_add
(
variable_name
,
period
)
else
(
simulation
.
calculate_add
(
variable_name
,
period
)
if
variable
.
calculate_output
is
calculate_output_add
or
variable
.
calculate_output
is
calculate_output_divide
or
variable
.
set_input
is
set_input_divide_by_period
else
simulation
.
calculate
(
variable_name
,
period
.
first_day
)
else
(
simulation
.
calculate
(
variable_name
,
period
.
first_day
)
if
variable
.
definition_period
is
DAY
else
simulation
.
calculate
(
variable_name
,
period
.
first_month
)
else
(
simulation
.
calculate
(
variable_name
,
period
.
first_month
)
if
variable
.
definition_period
is
MONTH
else
simulation
.
calculate
(
variable_name
,
period
)
)
)
)
)
population
=
simulation
.
get_variable_population
(
variable_name
)
entity
=
population
.
entity
# entity_count = simulation_builder.entity_counts[entity.plural]
...
...
@@ -397,13 +407,19 @@ async def calculate(
entity
=
entity
.
key
,
name
=
variable_name
,
value
=
[
(
item
.
decode
()
if
isinstance
(
item
,
bytes
)
else
item
.
isoformat
()
else
(
item
.
isoformat
()
if
isinstance
(
item
,
date
)
else
0
else
(
0
if
isinstance
(
item
,
float
)
and
math
.
isnan
(
item
)
else
item
)
)
)
for
item
in
value
.
tolist
()
],
)
...
...
@@ -425,13 +441,19 @@ async def calculate(
name
=
step
.
name
,
period
=
str
(
step
.
period
),
value
=
[
(
item
.
decode
()
if
isinstance
(
item
,
bytes
)
else
item
.
isoformat
()
else
(
item
.
isoformat
()
if
isinstance
(
item
,
date
)
else
0
else
(
0
if
isinstance
(
item
,
float
)
and
math
.
isnan
(
item
)
else
item
)
)
)
for
item
in
step
.
value
.
tolist
()
],
)
...
...
@@ -606,16 +628,22 @@ async def calculate_webocket(
simulation
.
calculate
(
variable_name
,
period
)
if
variable
.
definition_period
is
ETERNITY
or
variable
.
definition_period
is
YEAR
else
simulation
.
calculate_add
(
variable_name
,
period
)
else
(
simulation
.
calculate_add
(
variable_name
,
period
)
if
variable
.
calculate_output
is
calculate_output_add
or
variable
.
calculate_output
is
calculate_output_divide
or
variable
.
set_input
is
set_input_divide_by_period
else
simulation
.
calculate
(
variable_name
,
period
.
first_day
)
else
(
simulation
.
calculate
(
variable_name
,
period
.
first_day
)
if
variable
.
definition_period
is
DAY
else
simulation
.
calculate
(
variable_name
,
period
.
first_month
)
else
(
simulation
.
calculate
(
variable_name
,
period
.
first_month
)
if
variable
.
definition_period
is
MONTH
else
simulation
.
calculate
(
variable_name
,
period
)
)
)
)
)
population
=
simulation
.
get_variable_population
(
variable_name
)
entity
=
population
.
entity
# entity_count = simulation_builder.entity_counts[entity.plural]
...
...
@@ -647,13 +675,19 @@ async def calculate_webocket(
name
=
variable_name
,
token
=
token
,
value
=
[
(
item
.
decode
()
if
isinstance
(
item
,
bytes
)
else
item
.
isoformat
()
else
(
item
.
isoformat
()
if
isinstance
(
item
,
date
)
else
0
else
(
0
if
isinstance
(
item
,
float
)
and
math
.
isnan
(
item
)
else
item
)
)
)
for
item
in
value
.
tolist
()
],
)
...
...
@@ -671,13 +705,20 @@ async def calculate_webocket(
name
=
step
.
name
,
period
=
str
(
step
.
period
),
value
=
[
(
item
.
decode
()
if
isinstance
(
item
,
bytes
)
else
item
.
isoformat
()
else
(
item
.
isoformat
()
if
isinstance
(
item
,
date
)
else
0
if
isinstance
(
item
,
float
)
and
math
.
isnan
(
item
)
else
(
0
if
isinstance
(
item
,
float
)
and
math
.
isnan
(
item
)
else
item
)
)
)
for
item
in
step
.
value
.
tolist
()
],
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment