Example #1
0
def test_add_two_axes(persons):
    simulation_builder = SimulationBuilder()
    simulation_builder.add_person_entity(persons, {'Alicia': {}})
    simulation_builder.register_variable('salary', persons)
    simulation_builder.add_parallel_axis({'count': 3, 'name': 'salary', 'min': 0, 'max': 3000, 'period': '2018-11'})
    simulation_builder.add_parallel_axis({'count': 3, 'name': 'pension', 'min': 0, 'max': 2000, 'period': '2018-11'})
    simulation_builder.expand_axes()
    assert simulation_builder.get_input('salary', '2018-11') == pytest.approx([0, 1500, 3000])
    assert simulation_builder.get_input('pension', '2018-11') == pytest.approx([0, 1000, 2000])
Example #2
0
def test_add_person_values_with_default_period_old_syntax(persons):
    persons_json = {'Alicia': {'salary': 3000}, 'Javier': {}}
    simulation_builder = SimulationBuilder()
    simulation_builder.set_default_period('month:2018-11')
    simulation_builder.add_person_entity(persons, persons_json)
    tools.assert_near(simulation_builder.get_input('salary', '2018-11'),
                      [3000, 0])
Example #3
0
def test_add_axis_with_group_int_period(persons):
    simulation_builder = SimulationBuilder()
    simulation_builder.add_person_entity(persons, {'Alicia': {}, 'Javier': {}})
    simulation_builder.register_variable('salary', persons)
    simulation_builder.add_parallel_axis({'count': 2, 'name': 'salary', 'min': 0, 'max': 3000, 'period': 2018})
    simulation_builder.add_parallel_axis({'count': 2, 'name': 'salary', 'min': 0, 'max': 3000, 'period': 2018, 'index': 1})
    simulation_builder.expand_axes()
    assert simulation_builder.get_input('salary', '2018') == pytest.approx([0, 0, 3000, 3000])
Example #4
0
def test_add_variable_value_as_expression(persons):
    salary = persons.get_variable('salary')
    instance_index = 0
    simulation_builder = SimulationBuilder()
    simulation_builder.entity_counts['persons'] = 1
    simulation_builder.add_variable_value(persons, salary, instance_index,
                                          'Alicia', '2018-11', '3 * 1000')
    input_array = simulation_builder.get_input('salary', '2018-11')
    assert input_array[instance_index] == pytest.approx(3000)
Example #5
0
def test_add_axis_on_an_existing_variable_with_input(persons):
    simulation_builder = SimulationBuilder()
    simulation_builder.add_person_entity(persons, {'Alicia': {'salary': {'2018-11': 1000}}})
    simulation_builder.register_variable('salary', persons)
    simulation_builder.add_parallel_axis({'count': 3, 'name': 'salary', 'min': 0, 'max': 3000, 'period': '2018-11'})
    simulation_builder.expand_axes()
    assert simulation_builder.get_input('salary', '2018-11') == pytest.approx([0, 1500, 3000])
    assert simulation_builder.get_count('persons') == 3
    assert simulation_builder.get_ids('persons') == ['Alicia0', 'Alicia1', 'Alicia2']
Example #6
0
def test_add_axis_on_households(persons, households):
    simulation_builder = SimulationBuilder()
    simulation_builder.add_person_entity(persons, {'Alicia': {}, 'Javier': {}, 'Tom': {}})
    simulation_builder.add_group_entity('persons', ['Alicia', 'Javier', 'Tom'], households, {
        'housea': {'parents': ['Alicia', 'Javier']},
        'houseb': {'parents': ['Tom']},
        })
    simulation_builder.register_variable('rent', households)
    simulation_builder.add_parallel_axis({'count': 2, 'name': 'rent', 'min': 0, 'max': 3000, 'period': '2018-11'})
    simulation_builder.expand_axes()
    assert simulation_builder.get_count('households') == 4
    assert simulation_builder.get_ids('households') == ['housea0', 'houseb1', 'housea2', 'houseb3']
    assert simulation_builder.get_input('rent', '2018-11') == pytest.approx([0, 0, 3000, 0])
Example #7
0
def test_add_person_entity_with_values(persons):
    persons_json = {'Alicia': {'salary': {'2018-11': 3000}}, 'Javier': {}}
    simulation_builder = SimulationBuilder()
    simulation_builder.add_person_entity(persons, persons_json)
    tools.assert_near(simulation_builder.get_input('salary', '2018-11'),
                      [3000, 0])