Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Python, simplify simulation initialisation #729

Merged
merged 2 commits into from
Oct 2, 2018
Merged

Conversation

fpagnoux
Copy link
Member

@fpagnoux fpagnoux commented Oct 2, 2018

Fixes #726

In Python, simplify simulation initialisation:

Before:

simulation = ...
holder = simulation.persons.get_holder('salary')
holder.set_input('2018-08', [4000])

Now:

simulation = ...
simulation.set_input('salary', '2018-08', [4000])

@bonjourmauko bonjourmauko changed the title Set input In Python, simplify simulation initialisation Oct 2, 2018
@bonjourmauko
Copy link
Member

bonjourmauko commented Oct 2, 2018

Hi @fpagnoux, I have just one question about scope: is this just about scenario initialisation or set_input in general? For example in scenarios.py:

        if test_case is None:
            if self.input_variables is not None:
                # Note: For set_input to work, handle days, before months, before years => use sorted().
                for variable_name, array_by_period in sorted(self.input_variables.items()):
                    holder = simulation.get_variable_entity(variable_name).get_holder(variable_name)
                    entity = holder.entity
                    for period, array in array_by_period.items():
                        if entity.count == 0:
                            entity.count = len(array)
                            entity.ids = range(entity.count)
                        holder.set_input(period, array)

Should this be refactored to the following?

        if test_case is None:
            if self.input_variables is not None:
                # Note: For set_input to work, handle days, before months, before years => use sorted().
                for variable_name, array_by_period in sorted(self.input_variables.items()):
                    entity = simulation.get_variable_entity(variable_name)
                    for period, array in array_by_period.items():
                        if entity.count == 0:
                            entity.count = len(array)
                            entity.ids = range(entity.count)
                        simulation.set_input(variable_name, period, array)

:param value: the input value for the variable
:param period: the period at which the value is setted

Exemple :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> Example

Copy link
Member

@bonjourmauko bonjourmauko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's just :

  • one typo that'll fix myself.
  • cleanup to be done that do not block the PR.

Good job!

@bonjourmauko bonjourmauko added the kind:refactor Refactoring and code cleanup label Oct 2, 2018
@bonjourmauko bonjourmauko assigned bonjourmauko and unassigned fpagnoux Oct 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:refactor Refactoring and code cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants