Commit 9dddb2a0 authored by Christophe Benz's avatar Christophe Benz

Rename subtypes by dedicated attributes

parent 3f2bfd43
......@@ -39,10 +39,10 @@ def calculate(calculee_variable_names=[], saisie_variables={}):
nb_calculee_variable_names_requested = len(calculee_variable_names)
if not calculee_variable_names:
calculee_variable_names = variables_definitions.filter_by_subtype('restituee')
calculee_variable_names = variables_definitions.filter_calculees(kind='restituee')
else:
for calculee_variable_name in calculee_variable_names:
if not variables_definitions.has_subtype(calculee_variable_name, 'restituee'):
if not variables_definitions.is_calculee(calculee_variable_name, kind='restituee'):
warning_messages_by_section['saisies'].append(
'Variable "{}" is not a variable of type "calculee restituee"'.format(calculee_variable_name)
)
......
......@@ -170,7 +170,7 @@ $verifs
formula_name=variable_name,
)
if variables_definitions.is_calculee(variable_name):
if not variables_definitions.has_subtype(variable_name, 'base'):
if not variables_definitions.is_calculee(variable_name, kind='base'):
log.debug('Variable {!r} is declared in tgvH file but has no formula'.format(variable_name))
return python_source_visitors.make_formula_source(
expression='0',
......
......@@ -3,8 +3,6 @@
from . import loaders
from toolz.curried import keyfilter
class VariablesDefinitions(object):
"""Query `variables_definitions.json` file in a more convenient way."""
......@@ -13,11 +11,12 @@ class VariablesDefinitions(object):
self.constants = constants or loaders.load_constants()
self.definition_by_variable_name = definition_by_variable_name or loaders.load_variables_definitions()
def filter_by_subtype(self, subtype):
return list(keyfilter(
lambda variable_name: self.has_subtype(variable_name, subtype),
self.definition_by_variable_name,
).keys())
def filter_calculees(self, kind=None):
return [
variable_name
for variable_name, definition in self.definition_by_variable_name.items()
if self.is_calculee(variable_name, kind=kind)
]
def get_description(self, variable_name, strict=False):
default = None if strict else {}
......@@ -27,13 +26,9 @@ class VariablesDefinitions(object):
default = None if strict else {}
return self.definition_by_variable_name.get(variable_name, default).get('type')
def has_subtype(self, variable_name, subtype, strict=False):
default = None if strict else {}
return subtype in self.definition_by_variable_name.get(variable_name, default).get('subtypes', [])
def is_calculee(self, variable_name, subtype=None):
def is_calculee(self, variable_name, kind=None):
return self.get_type(variable_name) == 'variable_calculee' and \
(True if subtype is None else self.has_subtype(variable_name, subtype))
(True if kind is None else self.definition_by_variable_name[variable_name].get(kind))
def is_constant(self, variable_name):
return variable_name in self.constants
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment