Example #1
0
    def get_reduced_simulator_interface(self):
        """
        Get a simulator interface that only contains the inputs that are marked
        as KEY_PARAMETER_CHECKED in the current session.
        """
        burst_config = common.get_from_session(common.KEY_BURST_CONFIG)
        simulator_config = burst_config.simulator_configuration
        ## Fill with stored defaults, and see if any parameter was checked by user ##
        default_values, any_checked = burst_config.get_all_simulator_values()
        simulator_input_tree = self.cached_simulator_input_tree
        simulator_input_tree = InputTreeManager.fill_defaults(
            simulator_input_tree, default_values)
        ## In case no values were checked just skip tree-cut part and show entire simulator tree ##
        if any_checked:
            simulator_input_tree = InputTreeManager.select_simulator_inputs(
                simulator_input_tree, simulator_config)

        ### Add simulator tree to session to be available in filters
        self.context.add_adapter_to_session(self.cached_simulator_algorithm,
                                            simulator_input_tree,
                                            default_values)

        template_specification = {
            "inputList": simulator_input_tree,
            common.KEY_PARAMETERS_CONFIG: False,
            'draw_hidden_ranges': True
        }
        return self.fill_default_attributes(template_specification)
Example #2
0
 def test_select_simulator_inputs(self):
     """
     Test that given a dictionary of selected inputs as it would arrive from UI, only
     the selected simulator inputs are kept.
     """
     simulator_input_tree = self.flow_service.prepare_adapter(self.test_project.id, self.sim_algorithm)
     child_parameter = ''
     checked_parameters = {simulator_input_tree[0][ABCAdapter.KEY_NAME]: {model.KEY_PARAMETER_CHECKED: True,
                                                                          model.KEY_SAVED_VALUE: 'new_value'},
                           simulator_input_tree[1][ABCAdapter.KEY_NAME]: {model.KEY_PARAMETER_CHECKED: True,
                                                                          model.KEY_SAVED_VALUE: 'new_value'}}
     #Look for a entry from a subtree to add to the selected simulator inputs
     for idx, entry in enumerate(simulator_input_tree):
         found_it = False
         if idx not in (0, 1) and entry.get(ABCAdapter.KEY_OPTIONS, False):
             for option in entry[ABCAdapter.KEY_OPTIONS]:
                 if option[ABCAdapter.KEY_VALUE] == entry[ABCAdapter.KEY_DEFAULT]:
                     if option[ABCAdapter.KEY_ATTRIBUTES]:
                         child_parameter = option[ABCAdapter.KEY_ATTRIBUTES][0][ABCAdapter.KEY_NAME]
                         checked_parameters[entry[ABCAdapter.KEY_NAME]] = {model.KEY_PARAMETER_CHECKED: False,
                                                                           model.KEY_SAVED_VALUE: entry[
                                                                               ABCAdapter.KEY_DEFAULT]}
                         checked_parameters[child_parameter] = {model.KEY_PARAMETER_CHECKED: True,
                                                                model.KEY_SAVED_VALUE: 'new_value'}
                         found_it = True
                         break
         if found_it:
             break
     self.assertTrue(child_parameter != '', "Could not find any sub-tree entry in simulator interface.")
     subtree = InputTreeManager.select_simulator_inputs(simulator_input_tree, checked_parameters)
     #After the select method we expect only the checked parameters entries to remain with
     #the new values updated accordingly.
     expected_outputs = [{ABCAdapter.KEY_NAME: simulator_input_tree[0][ABCAdapter.KEY_NAME],
                          ABCAdapter.KEY_DEFAULT: 'new_value'},
                         {ABCAdapter.KEY_NAME: simulator_input_tree[1][ABCAdapter.KEY_NAME],
                          ABCAdapter.KEY_DEFAULT: 'new_value'},
                         {ABCAdapter.KEY_NAME: child_parameter,
                          ABCAdapter.KEY_DEFAULT: 'new_value'}]
     self.assertEqual(len(expected_outputs), len(subtree),
                      "Some entries that should not have been displayed still are.")
     for idx, entry in enumerate(expected_outputs):
         self.assertEqual(expected_outputs[idx][ABCAdapter.KEY_NAME], subtree[idx][ABCAdapter.KEY_NAME])
         self.assertEqual(expected_outputs[idx][ABCAdapter.KEY_DEFAULT], subtree[idx][ABCAdapter.KEY_DEFAULT],
                          'Default value not update properly.')
Example #3
0
    def get_reduced_simulator_interface(self):
        """
        Get a simulator interface that only contains the inputs that are marked
        as KEY_PARAMETER_CHECKED in the current session.
        """
        burst_config = common.get_from_session(common.KEY_BURST_CONFIG)
        simulator_config = burst_config.simulator_configuration
        ## Fill with stored defaults, and see if any parameter was checked by user ##
        default_values, any_checked = burst_config.get_all_simulator_values()
        simulator_input_tree = self.cached_simulator_input_tree
        simulator_input_tree = InputTreeManager.fill_defaults(simulator_input_tree, default_values)
        ## In case no values were checked just skip tree-cut part and show entire simulator tree ##
        if any_checked:
            simulator_input_tree = InputTreeManager.select_simulator_inputs(simulator_input_tree, simulator_config)

        ### Add simulator tree to session to be available in filters
        self.context.add_adapter_to_session(self.cached_simulator_algorithm, simulator_input_tree, default_values)

        template_specification = {"inputList": simulator_input_tree,
                                  common.KEY_PARAMETERS_CONFIG: False,
                                  'draw_hidden_ranges': True}
        return self.fill_default_attributes(template_specification)