当前位置: 首页>>代码示例>>Python>>正文


Python input_tree.InputTreeManager类代码示例

本文整理汇总了Python中tvb.core.adapters.input_tree.InputTreeManager的典型用法代码示例。如果您正苦于以下问题:Python InputTreeManager类的具体用法?Python InputTreeManager怎么用?Python InputTreeManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了InputTreeManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_portlet_interface

    def build_portlet_interface(self, portlet_configuration, project_id):
        """
        From a portlet_id and a project_id, first build the portlet
        entity then get it's configurable interface. 
        
        :param portlet_configuration: a portlet configuration entity. It holds at the
            least the portlet_id, and in case any default parameters were saved
            they can be rebuilt from the analyzers // visualizer parameters
        :param project_id: the id of the current project   
            
        :returns: the portlet interface will be of the following form::
            [{'interface': adapter_interface, 
            'prefix': prefix_for_parameter_names, 
            'subalg': {algorithm_field_name: default_algorithm_value},
            'algo_group': algorithm_group,
            'alg_ui_name': displayname},
            ......]
            A list of dictionaries for each adapter that makes up the portlet.
            
        """
        portlet_configurer = self._get_portlet_configurer(portlet_configuration.portlet_id)
        portlet_interface = portlet_configurer.get_configurable_interface()

        for adapter_conf in portlet_interface:
            interface = adapter_conf.interface
            itree_mngr = InputTreeManager()
            interface = itree_mngr.fill_input_tree_with_options(interface, project_id,
                                                                adapter_conf.stored_adapter.fk_category)
            adapter_conf.interface = itree_mngr.prepare_param_names(interface)

        portlet_configurer.update_default_values(portlet_interface, portlet_configuration)
        portlet_configurer.prefix_adapters_parameters(portlet_interface)

        return portlet_interface
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:34,代码来源:burst_service.py

示例2: get_template_for_adapter

    def get_template_for_adapter(self, project_id, step_key, stored_adapter, submit_url, session_reset=True, is_burst=True):
        """ Get Input HTML Interface template or a given adapter """
        try:
            if session_reset:
                self.context.clean_from_session()

            group = None
            # Cache some values in session, for performance
            previous_tree = self.context.get_current_input_tree()
            previous_sub_step = self.context.get_current_substep()
            if not session_reset and previous_tree is not None and previous_sub_step == stored_adapter.id:
                adapter_interface = previous_tree
            else:
                adapter_interface = self.flow_service.prepare_adapter(project_id, stored_adapter)
                self.context.add_adapter_to_session(stored_adapter, adapter_interface)

            category = self.flow_service.get_category_by_id(step_key)
            title = "Fill parameters for step " + category.displayname.lower()
            if group:
                title = title + " - " + group.displayname

            current_defaults = self.context.get_current_default()
            if current_defaults is not None:
                #Change default values in tree, according to selected input
                adapter_interface = InputTreeManager.fill_defaults(adapter_interface, current_defaults)

            template_specification = dict(submitLink=submit_url, inputList=adapter_interface, title=title)
            self._populate_section(stored_adapter, template_specification, is_burst)
            return template_specification
        except OperationException, oexc:
            self.logger.error("Inconsistent Adapter")
            self.logger.exception(oexc)
            common.set_warning_message('Inconsistent Adapter!  Please review the link (development problem)!')
开发者ID:transpersonify,项目名称:tvb-framework,代码行数:33,代码来源:flow_controller.py

示例3: prepare_param_names

 def prepare_param_names(attributes_list, prefix=None, add_option_prefix=False):
     """
     For a given attribute list, change the name of the attributes where needed.
     Changes refer to adding a prefix, to identify groups.
     Will be used on parameters page GET.
     """
     return InputTreeManager.prepare_param_names(attributes_list, prefix, add_option_prefix)
开发者ID:amitsaroj001,项目名称:tvb-framework,代码行数:7,代码来源:abcadapter.py

示例4: get_surface_model_parameters_data

    def get_surface_model_parameters_data(self, default_selected_model_param=None):
        """
        Returns a dictionary which contains all the data needed for drawing the
        model parameters.
        """
        context_model_parameters = common.get_from_session(KEY_CONTEXT_MPS)
        if default_selected_model_param is None:
            default_selected_model_param = context_model_parameters.prepared_model_parameter_names.values()[0]

        equation_displayer = EquationDisplayer()
        equation_displayer.trait.bound = interface.INTERFACE_ATTRIBUTES_ONLY
        input_list = equation_displayer.interface[interface.INTERFACE_ATTRIBUTES]
        input_list[0] = self._lock_midpoints(input_list[0])

        options = []
        for original_param, modified_param in context_model_parameters.prepared_model_parameter_names.items():
            attributes = deepcopy(input_list)
            self._fill_default_values(attributes, modified_param)
            option = {'name': original_param, 'value': modified_param, 'attributes': attributes}
            options.append(option)

        input_list = [{'name': 'model_param', 'type': 'select', 'default': default_selected_model_param,
                       'label': 'Model param', 'required': True, 'options': options}]
        input_list = InputTreeManager.prepare_param_names(input_list)
        return {common.KEY_PARAMETERS_CONFIG: False, 'inputList': input_list,
                'applied_equations': context_model_parameters.get_configure_info()}
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:26,代码来源:surface_model_parameters_controller.py

示例5: get_configurable_interface

    def get_configurable_interface(self):
        """
        Given an algorithm identifier, go trough the adapter chain, and merge
        their input tree with the declared overwrites 
        """
        chain_adapters = self.reader.get_adapters_chain(self.algo_identifier)
        result = []
        for adapter_declaration in chain_adapters:

            adapter_instance, algorithm_group = self.build_adapter_from_declaration(adapter_declaration)

            algorithm_field = adapter_declaration[KEY_FIELD]
            if algorithm_field:
                default_algorithm = adapter_declaration[ABCAdapter.KEY_DEFAULT]
            else:
                default_algorithm = ''

            all_portlet_defined_params = self.reader.get_inputs(self.algo_identifier)
            specific_adapter_overwrites = [entry for entry in all_portlet_defined_params
                                           if ATT_OVERWRITE in entry and entry[ATT_OVERWRITE] ==
                                              adapter_declaration[ABCAdapter.KEY_NAME]]

            if default_algorithm:
                alg_inputs = adapter_instance.xml_reader.get_inputs(default_algorithm)
                prefix = InputTreeManager.form_prefix(algorithm_field, None, default_algorithm)
            else:
                alg_inputs = adapter_instance.get_input_tree()
                prefix = ''

            replace_values = self._prepare_input_tree(alg_inputs, specific_adapter_overwrites, prefix)
            adapter_configuration = AdapterConfiguration(replace_values, algorithm_group, prefix=prefix,
                                                         subalgorithm_field=algorithm_field,
                                                         subalgorithm_value=default_algorithm)
            result.append(adapter_configuration)
        return result
开发者ID:boegel,项目名称:tvb-framework,代码行数:35,代码来源:portlet_configurer.py

示例6: load_region_stimulus

    def load_region_stimulus(self, region_stimulus_gid, from_step=None):
        """
        Loads the interface for the selected region stimulus.
        """
        selected_region_stimulus = ABCAdapter.load_entity_by_gid(region_stimulus_gid)
        temporal_eq = selected_region_stimulus.temporal
        spatial_eq = selected_region_stimulus.spatial
        connectivity = selected_region_stimulus.connectivity
        weights = selected_region_stimulus.weight

        temporal_eq_type = temporal_eq.__class__.__name__
        spatial_eq_type = spatial_eq.__class__.__name__
        default_dict = {'temporal': temporal_eq_type, 'spatial': spatial_eq_type,
                        'connectivity': connectivity.gid, 'weight': json.dumps(weights)}
        for param in temporal_eq.parameters:
            prepared_name = 'temporal_parameters_option_' + str(temporal_eq_type)
            prepared_name = prepared_name + '_parameters_parameters_' + str(param)
            default_dict[prepared_name] = str(temporal_eq.parameters[param])
        for param in spatial_eq.parameters:
            prepared_name = 'spatial_parameters_option_' + str(spatial_eq_type) + '_parameters_parameters_' + str(param)
            default_dict[prepared_name] = str(spatial_eq.parameters[param])

        input_list = self.get_creator_and_interface(REGION_STIMULUS_CREATOR_MODULE,
                                                    REGION_STIMULUS_CREATOR_CLASS, StimuliRegion())[1]
        input_list = InputTreeManager.fill_defaults(input_list, default_dict)
        context = common.get_from_session(KEY_REGION_CONTEXT)
        context.reset()
        context.update_from_interface(input_list)
        context.equation_kwargs[DataTypeMetaData.KEY_TAG_1] = selected_region_stimulus.user_tag_1
        context.set_active_stimulus(region_stimulus_gid)

        return self.do_step(from_step)
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:32,代码来源:region_stimulus_controller.py

示例7: prepare_ui_inputs

 def prepare_ui_inputs(self, kwargs, validation_required=True):
     """
     Prepare the inputs received from a HTTP Post in a form that will be
     used by the Python adapter.
     """
     algorithm_inputs = self.get_input_tree()
     algorithm_inputs = InputTreeManager.prepare_param_names(algorithm_inputs)
     self.tree_manager.append_required_defaults(kwargs, algorithm_inputs)
     return self.convert_ui_inputs(kwargs, validation_required=validation_required)
开发者ID:transpersonify,项目名称:tvb-framework,代码行数:9,代码来源:abcadapter.py

示例8: __init__

 def __init__(self):
     # It will be populate with key from DataTypeMetaData
     self.meta_data = {DataTypeMetaData.KEY_SUBJECT: DataTypeMetaData.DEFAULT_SUBJECT}
     self.file_handler = FilesHelper()
     self.storage_path = '.'
     # Will be populate with current running operation's identifier
     self.operation_id = None
     self.user_id = None
     self.log = get_logger(self.__class__.__module__)
     self.tree_manager = InputTreeManager()
开发者ID:the-virtual-brain,项目名称:tvb-framework,代码行数:10,代码来源:abcadapter.py

示例9: _get_stimulus_interface

 def _get_stimulus_interface(self):
     """
     Returns a dictionary which contains the interface for a surface stimulus.
     """
     context = common.get_from_session(KEY_SURFACE_CONTEXT)
     input_list = self.get_creator_and_interface(SURFACE_STIMULUS_CREATOR_MODULE,
                                                 SURFACE_STIMULUS_CREATOR_CLASS, StimuliSurface(),
                                                 lock_midpoint_for_eq=[1])[1]
     input_list = InputTreeManager.fill_defaults(input_list, context.equation_kwargs)
     input_list, focal_points_list = self._remove_focal_points(input_list)
     input_list = self.prepare_entity_interface(input_list)
     input_list['selectedFocalPoints'] = focal_points_list
     return self._add_extra_fields_to_interface(input_list)
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:13,代码来源:surface_stimulus_controller.py

示例10: get_reduced_simulator_interface

    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)
开发者ID:maedoc,项目名称:tvb-framework,代码行数:22,代码来源:burst_controller.py

示例11: _get_stimulus_interface

 def _get_stimulus_interface(self):
     """
     Returns a dictionary which contains the data needed
     for creating the interface for a stimulus.
     """
     context = common.get_from_session(KEY_REGION_CONTEXT)
     input_list = self.get_creator_and_interface(REGION_STIMULUS_CREATOR_MODULE,
                                                 REGION_STIMULUS_CREATOR_CLASS, StimuliRegion())[1]
     context.equation_kwargs.update({SCALING_PARAMETER: context.get_weights()})
     input_list = InputTreeManager.fill_defaults(input_list, context.equation_kwargs)
     input_list, any_scaling = self._remove_scaling(input_list)
     template_specification = {'inputList': input_list, common.KEY_PARAMETERS_CONFIG: False}
     return self._add_extra_fields_to_interface(template_specification), any_scaling
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:13,代码来源:region_stimulus_controller.py

示例12: index

    def index(self):
        dynamic_gid = utils.generate_guid()
        adapter = _LeftFragmentAdapter(self.available_models)
        input_tree = adapter.get_input_tree()
        #WARN: If this input tree will contain data type references then to render it correctly we have to use fill_input_tree_with_options
        input_tree = InputTreeManager.prepare_param_names(input_tree)

        integrator_adapter = _IntegratorFragmentAdapter()
        integrator_input_tree = integrator_adapter.get_input_tree()
        integrator_input_tree  = InputTreeManager.prepare_param_names(integrator_input_tree)

        params = {
            'title': "Dynamic model",
            'mainContent': 'burst/dynamic',
            'input_tree': input_tree,
            'integrator_input_tree': integrator_input_tree,
            'dynamic_gid': dynamic_gid
        }
        self.fill_default_attributes(params)

        dynamic = self.get_cached_dynamic(dynamic_gid)
        self._configure_integrator_noise(dynamic.integrator, dynamic.model)
        return params
开发者ID:gummadhav,项目名称:tvb-framework,代码行数:23,代码来源:dynamic_model_controller.py

示例13: update_default_values

    def update_default_values(portlet_interface, portlet_configuration):
        """
        :param portlet_interface: a list of AdapterConfiguration entities.
        :param portlet_configuration: a PortletConfiguration entity.
        
        Update the defaults from each AdapterConfiguration entity with the 
        values stored in the corresponding workflow step held in the 
        PortletConfiguration entity.
        """
        # Check for any defaults first in analyzer steps
        if portlet_configuration.analyzers:
            for adapter_idx in xrange(len(portlet_interface[:-1])):
                saved_configuration = portlet_configuration.analyzers[adapter_idx]
                replaced_defaults_dict = InputTreeManager.fill_defaults(portlet_interface[adapter_idx].interface,
                                                                        saved_configuration.static_param)
                portlet_interface[adapter_idx].interface = replaced_defaults_dict

        # Check for visualization defaults
        if portlet_configuration.visualizer:
            saved_configuration = portlet_configuration.visualizer
            replaced_defaults_dict = InputTreeManager.fill_defaults(portlet_interface[-1].interface,
                                                                    saved_configuration.static_param)
            portlet_interface[-1].interface = replaced_defaults_dict
开发者ID:gummadhav,项目名称:tvb-framework,代码行数:23,代码来源:portlet_configurer.py

示例14: test_select_simulator_inputs

 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.')
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:44,代码来源:burst_service_test.py

示例15: index

    def index(self):
        """Get on burst main page"""
        # todo : reuse load_burst here for consistency.
        template_specification = dict(mainContent="burst/main_burst", title="Simulation Cockpit",
                                      baseUrl=TvbProfile.current.web.BASE_URL,
                                      includedResources='project/included_resources')
        portlets_list = self.burst_service.get_available_portlets()
        session_stored_burst = common.get_from_session(common.KEY_BURST_CONFIG)
        if session_stored_burst is None or session_stored_burst.id is None:
            if session_stored_burst is None:
                session_stored_burst = self.burst_service.new_burst_configuration(common.get_current_project().id)
                common.add2session(common.KEY_BURST_CONFIG, session_stored_burst)

            adapter_interface = self.cached_simulator_input_tree
            if session_stored_burst is not None:
                current_data = session_stored_burst.get_all_simulator_values()[0]
                adapter_interface = InputTreeManager.fill_defaults(adapter_interface, current_data, True)
                ### Add simulator tree to session to be available in filters
                self.context.add_adapter_to_session(self.cached_simulator_algorithm, adapter_interface, current_data)
            template_specification['inputList'] = adapter_interface

        selected_portlets = session_stored_burst.update_selected_portlets()
        template_specification['burst_list'] = self.burst_service.get_available_bursts(common.get_current_project().id)
        template_specification['portletList'] = portlets_list
        template_specification['selectedPortlets'] = json.dumps(selected_portlets)
        template_specification['draw_hidden_ranges'] = True
        template_specification['burstConfig'] = session_stored_burst

        ### Prepare PSE available metrics
        ### We put here all available algorithms, because the metrics select area is a generic one, 
        ### and not loaded with every Burst Group change in history.
        algorithm = self.flow_service.get_algorithm_by_module_and_class(MEASURE_METRICS_MODULE, MEASURE_METRICS_CLASS)
        adapter_instance = ABCAdapter.build_adapter(algorithm)
        if adapter_instance is not None and hasattr(adapter_instance, 'available_algorithms'):
            template_specification['available_metrics'] = [metric_name for metric_name
                                                           in adapter_instance.available_algorithms.keys()]
        else:
            template_specification['available_metrics'] = []

        template_specification[common.KEY_PARAMETERS_CONFIG] = False
        template_specification[common.KEY_SECTION] = 'burst'
        return self.fill_default_attributes(template_specification)
开发者ID:maedoc,项目名称:tvb-framework,代码行数:42,代码来源:burst_controller.py


注:本文中的tvb.core.adapters.input_tree.InputTreeManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。