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 = base.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 = ABCAdapter.prepare_param_names(input_list)
        return {base.KEY_PARAMETERS_CONFIG: False, 'inputList': input_list,
                'applied_equations': context_model_parameters.get_configure_info()}
Esempio n. 2
0
 def prepare_adapter(self, project_id, algo_group):
     """
     Having a given Adapter, specified by Module and ClassName, 
     create a instance of it and return the instance.
     Actually return a Tuple: Adapter Instance, Dictionary for Adapter 
     Interface specification.
     """
     adapter_module = algo_group.module.replace('-', '.')
     adapter_name = algo_group.classname
     try:
         # Prepare Adapter Interface, by populating with existent data,
         # in case of a parameter of type DataType.
         group = dao.find_group(adapter_module, adapter_name,
                                algo_group.init_parameter)
         adapter_instance = self.build_adapter_instance(group)
         interface = adapter_instance.get_input_tree()
         interface = self.prepare_parameters(interface, project_id,
                                             group.fk_category)
         interface = ABCAdapter.prepare_param_names(interface)
         return group, interface
     except Exception, excep:
         self.logger.exception(excep)
         self.logger.error('Not found:' + adapter_name + ' in:' +
                           adapter_module)
         raise OperationException("Could not prepare " + adapter_name)
Esempio n. 3
0
    def get_creator_and_interface(self,
                                  creator_module,
                                  creator_class,
                                  datatype_instance,
                                  lock_midpoint_for_eq=None):
        """
        Returns a Tuple: a creator instance and a dictionary for the creator interface.
        The interface is prepared for rendering, it is populated with existent data, in case of a
        parameter of type DataType. The name of the attributes are also prefixed to identify groups.
        """
        algo_group = self.flow_service.get_algorithm_by_module_and_class(
            creator_module, creator_class)[1]
        group, _ = self.flow_service.prepare_adapter(
            base.get_current_project().id, algo_group)

        #I didn't use the interface(from the above line) returned by the method 'prepare_adapter' from flow service
        # because the selects that display dataTypes will also have the 'All' entry.
        datatype_instance.trait.bound = traited_interface.INTERFACE_ATTRIBUTES_ONLY
        input_list = datatype_instance.interface[
            traited_interface.INTERFACE_ATTRIBUTES]
        if lock_midpoint_for_eq is not None:
            for idx in lock_midpoint_for_eq:
                input_list[idx] = self._lock_midpoints(input_list[idx])
        category = self.flow_service.get_visualisers_category()
        input_list = self.flow_service.prepare_parameters(
            input_list,
            base.get_current_project().id, category.id)
        input_list = ABCAdapter.prepare_param_names(input_list)

        return self.flow_service.build_adapter_instance(group), input_list
Esempio n. 4
0
 def test_multidimensional_array(self):
     """
     Test the generation of a multi-dimensional array.
     """
     input_tree = TraitAdapter().get_input_tree()
     input_tree = ABCAdapter.prepare_param_names(input_tree)
     self.template_specification['inputList'] = input_tree
     resulted_html = _template2string(self.template_specification)
     soup = BeautifulSoup(resulted_html)
     #Find dictionary div which should be dict_+${dict_var_name}
     dict_div = soup.findAll('div', attrs=dict(id="dict_test_dict"))
     self.assertEqual(len(dict_div), 1, 'Dictionary div not found')
     dict_entries = soup.findAll(
         'input', attrs=dict(name=re.compile('^test_dict_parameters*')))
     self.assertEqual(len(dict_entries), 2, 'Not all entries found')
     for i in range(2):
         if dict_entries[i]['name'] == "test_dict_parameters_W":
             self.assertEqual(dict_entries[0]['value'], "-6.0",
                              "Incorrect values")
         if dict_entries[i]['name'] == "test_dict_parameters_V":
             self.assertEqual(dict_entries[1]['value'], "-3.0",
                              "Incorrect values")
     array_entry = soup.findAll('input', attrs=dict(name='test_array'))
     self.assertEqual(len(array_entry), 1, 'Array entry not found')
     self.assertEqual(array_entry[0]['value'], "[[-3.0, -6.0], [3.0, 6.0]]",
                      "Wrong value stored")
    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 = ABCAdapter.prepare_param_names(input_list)
        return {common.KEY_PARAMETERS_CONFIG: False, 'inputList': input_list,
                'applied_equations': context_model_parameters.get_configure_info()}
    def get_select_existent_entities(self, label, entity_type, entity_gid=None):
        """
        Returns the dictionary needed for drawing the select which display all
        the created entities of the specified type.
        """
        project_id = common.get_current_project().id
        category = self.flow_service.get_visualisers_category()

        interface = [{'name': 'existentEntitiesSelect', 'label': label, 'type': entity_type}]
        if entity_gid is not None:
            interface[0]['default'] = entity_gid
        interface = self.flow_service.prepare_parameters(interface, project_id, category.id)
        interface = ABCAdapter.prepare_param_names(interface)

        return interface
Esempio n. 7
0
    def setUp(self):
        """
        Set up any additionally needed parameters.
        """
        super(GenshiTestGroup, self).setUp()

        xml_group_path = os.path.join('tests', 'framework', 'interfaces', 'web', "test_group.xml")
        algo_group = dao.find_group('tvb.tests.framework.adapters.testgroupadapter', 'TestGroupAdapter', xml_group_path)
        self.xml_group_adapter = ABCAdapter.build_adapter(algo_group)
        input_tree = self.xml_group_adapter.get_input_tree()
        input_tree = ABCAdapter.prepare_param_names(input_tree)
        self.template_specification['inputList'] = input_tree
        self.template_specification[common.KEY_PARAMETERS_CONFIG] = False
        resulted_html = _template2string(self.template_specification)
        self.soup = BeautifulSoup(resulted_html)
    def get_select_existent_entities(self, label, entity_type, entity_gid=None):
        """
        Returns the dictionary needed for drawing the select which display all
        the created entities of the specified type.
        """
        project_id = base.get_current_project().id
        category = self.flow_service.get_visualisers_category()

        interface = [{'name': 'existentEntitiesSelect', 'label': label, 'type': entity_type}]
        if entity_gid is not None:
            interface[0]['default'] = entity_gid
        interface = self.flow_service.prepare_parameters(interface, project_id, category.id)
        interface = ABCAdapter.prepare_param_names(interface)

        return interface
Esempio n. 9
0
    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_entity = dao.get_portlet_by_id(
            portlet_configuration.portlet_id)
        if portlet_entity is None:
            raise InvalidPortletConfiguration(
                "No portlet entity located in database with id=%s. "
                "Portlet configuration %s is not valid." %
                (portlet_configuration.portlet_id, portlet_configuration))
        portlet_configurer = PortletConfigurer(portlet_entity)
        portlet_interface = portlet_configurer.get_configurable_interface()
        self.logger.debug("Created interface for portlet " +
                          str([portlet_entity]))

        for adapter_conf in portlet_interface:
            interface = adapter_conf.interface
            interface = FlowService().prepare_parameters(
                interface, project_id, adapter_conf.group.fk_category)
            interface = ABCAdapter.prepare_param_names(interface,
                                                       adapter_conf.prefix)
            adapter_conf.interface = interface

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

        return portlet_interface
Esempio n. 10
0
    def setUp(self):
        """
        Set up any additionally needed parameters.
        """
        super(GenshiTestGroup, self).setUp()

        xml_group_path = os.path.join('tests', 'framework', 'interfaces',
                                      'web', "test_group.xml")
        algo_group = dao.find_group(
            'tvb.tests.framework.adapters.testgroupadapter',
            'TestGroupAdapter', xml_group_path)
        self.xml_group_adapter = ABCAdapter.build_adapter(algo_group)
        input_tree = self.xml_group_adapter.get_input_tree()
        input_tree = ABCAdapter.prepare_param_names(input_tree)
        self.template_specification['inputList'] = input_tree
        self.template_specification[common.KEY_PARAMETERS_CONFIG] = False
        resulted_html = _template2string(self.template_specification)
        self.soup = BeautifulSoup(resulted_html)
    def get_creator_and_interface(self, creator_module, creator_class, datatype_instance, lock_midpoint_for_eq=None):
        """
        Returns a Tuple: a creator instance and a dictionary for the creator interface.
        The interface is prepared for rendering, it is populated with existent data, in case of a
        parameter of type DataType. The name of the attributes are also prefixed to identify groups.
        """
        algo_group = self.flow_service.get_algorithm_by_module_and_class(creator_module, creator_class)[1]
        group, _ = self.flow_service.prepare_adapter(common.get_current_project().id, algo_group)

        #I didn't use the interface(from the above line) returned by the method 'prepare_adapter' from flow service
        # because the selects that display dataTypes will also have the 'All' entry.
        datatype_instance.trait.bound = traited_interface.INTERFACE_ATTRIBUTES_ONLY
        input_list = datatype_instance.interface[traited_interface.INTERFACE_ATTRIBUTES]
        if lock_midpoint_for_eq is not None:
            for idx in lock_midpoint_for_eq:
                input_list[idx] = self._lock_midpoints(input_list[idx])
        category = self.flow_service.get_visualisers_category()
        input_list = self.flow_service.prepare_parameters(input_list, common.get_current_project().id, category.id)
        input_list = ABCAdapter.prepare_param_names(input_list)

        return self.flow_service.build_adapter_instance(group), input_list
Esempio n. 12
0
    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_entity = dao.get_portlet_by_id(portlet_configuration.portlet_id)
        if portlet_entity is None:
            raise InvalidPortletConfiguration(
                "No portlet entity located in database with id=%s. "
                "Portlet configuration %s is not valid." % (portlet_configuration.portlet_id, portlet_configuration)
            )
        portlet_configurer = PortletConfigurer(portlet_entity)
        portlet_interface = portlet_configurer.get_configurable_interface()
        self.logger.debug("Created interface for portlet " + str([portlet_entity]))

        for adapter_conf in portlet_interface:
            interface = adapter_conf.interface
            interface = FlowService().prepare_parameters(interface, project_id, adapter_conf.group.fk_category)
            interface = ABCAdapter.prepare_param_names(interface, adapter_conf.prefix)
            adapter_conf.interface = interface

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

        return portlet_interface
Esempio n. 13
0
 def prepare_adapter(self, project_id, algo_group):
     """
     Having a given Adapter, specified by Module and ClassName, 
     create a instance of it and return the instance.
     Actually return a Tuple: Adapter Instance, Dictionary for Adapter 
     Interface specification.
     """
     adapter_module = algo_group.module.replace('-', '.')
     adapter_name = algo_group.classname
     try:
         # Prepare Adapter Interface, by populating with existent data,
         # in case of a parameter of type DataType.
         group = dao.find_group(adapter_module, adapter_name, algo_group.init_parameter)
         adapter_instance = self.build_adapter_instance(group)
         interface = adapter_instance.get_input_tree()
         interface = self.prepare_parameters(interface, project_id, group.fk_category)
         interface = ABCAdapter.prepare_param_names(interface)
         return group, interface
     except Exception, excep:
         self.logger.exception(excep)
         self.logger.error('Not found:' + adapter_name + ' in:' + adapter_module)
         raise OperationException("Could not prepare " + adapter_name)
Esempio n. 14
0
 def test_multidimensional_array(self):
     """
     Test the generation of a multi-dimensional array.
     """
     input_tree = TraitAdapter().get_input_tree()
     input_tree = ABCAdapter.prepare_param_names(input_tree)
     self.template_specification['inputList'] = input_tree
     resulted_html = _template2string(self.template_specification)
     soup = BeautifulSoup(resulted_html)
     #Find dictionary div which should be dict_+${dict_var_name}
     dict_div = soup.findAll('div', attrs=dict(id="dict_test_dict"))
     self.assertEqual(len(dict_div), 1, 'Dictionary div not found')
     dict_entries = soup.findAll('input', attrs=dict(name=re.compile('^test_dict_parameters*')))
     self.assertEqual(len(dict_entries), 2, 'Not all entries found')
     for i in range(2):
         if dict_entries[i]['name'] == "test_dict_parameters_W":
             self.assertEqual(dict_entries[0]['value'], "-6.0", "Incorrect values")
         if dict_entries[i]['name'] == "test_dict_parameters_V":
             self.assertEqual(dict_entries[1]['value'], "-3.0", "Incorrect values")
     array_entry = soup.findAll('input', attrs=dict(name='test_array'))
     self.assertEqual(len(array_entry), 1, 'Array entry not found')
     self.assertEqual(array_entry[0]['value'], "[[-3.0, -6.0], [3.0, 6.0]]", "Wrong value stored")
Esempio n. 15
0
    def setUp(self):
        """
        Set up any additionally needed parameters.
        """
        super(GenshiTestGroup, self).setUp()

        core_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        self.old_path = cfg.CURRENT_DIR
        cfg.CURRENT_DIR = os.path.dirname(core_path)

        adapters_init.__xml_folders__ = [os.path.join('interfaces', 'web')]
        self.introspector = Introspector("tvb_test")
        self.introspector.introspect(True)

        xml_group_path = os.path.join('interfaces', 'web', "test_group.xml")
        algo_group = dao.find_group('tvb_test.adapters.testgroupadapter',
                                    'TestGroupAdapter', xml_group_path)
        self.xml_group_adapter = ABCAdapter.build_adapter(algo_group)
        input_tree = self.xml_group_adapter.get_input_tree()
        input_tree = ABCAdapter.prepare_param_names(input_tree)
        self.template_specification['inputList'] = input_tree
        self.template_specification[base.KEY_PARAMETERS_CONFIG] = False
        resulted_html = _template2string(self.template_specification)
        self.soup = BeautifulSoup(resulted_html)