Skip to content
Snippets Groups Projects
Commit ff8f822b authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Prettify

parent 1756dbb3
No related branches found
No related tags found
No related merge requests found
Pipeline #12934 passed
......@@ -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()
],
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment