def edit_noise_parameters(self):
        """
        Main method, to initialize Model-Parameter visual-set.
        """
        model, integrator, connectivity, _ = self.get_data_from_burst_configuration(
        )

        connectivity_viewer_params = self.get_connectivity_parameters(
            connectivity)
        context_noise_config = ContextNoiseParameters(connectivity, model,
                                                      integrator)
        param_names, param_data = self.get_data_for_param_sliders(
            '0', context_noise_config)
        base.add2session(KEY_CONTEXT_NC, context_noise_config)

        template_specification = dict(title="Simulation - Noise configuration")
        template_specification[
            'submit_parameters_url'] = '/spatial/noiseconfiguration/submit_noise_configuration'
        template_specification['parametersNames'] = param_names
        template_specification['paramSlidersData'] = param_data
        template_specification['isSingleMode'] = True
        template_specification.update(connectivity_viewer_params)
        template_specification[
            'mainContent'] = 'spatial/noise_configuration_main'
        template_specification['displayDefaultSubmitBtn'] = True
        return self.fill_default_attributes(template_specification)
Exemplo n.º 2
0
 def submit_model_parameters(self):
     """
     Collects the model parameters values from all the models used for the surface vertices.
     """
     context_model_parameters = base.get_from_session(KEY_CONTEXT_MPS)
     burst_configuration = base.get_from_session(base.KEY_BURST_CONFIG)
     for original_param, modified_param in context_model_parameters.prepared_model_parameter_names.items(
     ):
         full_name = PARAMS_MODEL_PATTERN % (
             context_model_parameters.model_name, original_param)
         param_data = context_model_parameters.get_data_for_model_param(
             original_param, modified_param)
         if isinstance(param_data, dict):
             equation = param_data[KEY_EQUATION]
             param_data[KEY_EQUATION] = equation.to_json(equation)
             param_data[KEY_FOCAL_POINTS] = json.dumps(
                 param_data[KEY_FOCAL_POINTS])
             param_data = json.dumps(param_data)
         burst_configuration.update_simulation_parameter(
             full_name, param_data)
     ### Clean from session drawing context
     base.remove_from_session(KEY_CONTEXT_MPS)
     ### Update in session BURST configuration for burst-page.
     base.add2session(base.KEY_BURST_CONFIG, burst_configuration.clone())
     raise cherrypy.HTTPRedirect("/burst/")
Exemplo n.º 3
0
 def reset_burst(self):
     """
     Called when click on "New Burst" entry happens from UI.
     This will generate an empty new Burst Configuration.
     """
     new_burst = self.burst_service.new_burst_configuration(base.get_current_project().id)
     base.add2session(base.KEY_BURST_CONFIG, new_burst)
Exemplo n.º 4
0
 def index(self, **data):
     """
     Login page (with or without messages).
     """
     template_specification = dict(mainContent="login",
                                   title="Login",
                                   data=data)
     if cherrypy.request.method == 'POST':
         form = LoginForm()
         try:
             data = form.to_python(data)
             username = data[KEY_USERNAME]
             password = data[KEY_PASSWORD]
             user = self.user_service.check_login(username, password)
             if user is not None:
                 basecontroller.add2session(basecontroller.KEY_USER, user)
                 basecontroller.set_info_message('Welcome ' + username)
                 self.logger.debug("User " + username +
                                   " has just logged in!")
                 if user.selected_project is not None:
                     prj = user.selected_project
                     prj = ProjectService().find_project(prj)
                     self._mark_selected(prj)
                 raise cherrypy.HTTPRedirect('/user/profile')
             else:
                 basecontroller.set_error_message(
                     'Wrong username/password, or user not yet validated...'
                 )
                 self.logger.debug("Wrong username " + username + " !!!")
         except formencode.Invalid, excep:
             template_specification[
                 basecontroller.KEY_ERRORS] = excep.unpack_errors()
    def edit_model_parameters(self):
        """
        Main method, to initialize Model-Parameter visual-set.
        """
        model, integrator, connectivity, _ = self.get_data_from_burst_configuration(
        )

        connectivity_viewer_params = self.get_connectivity_parameters(
            connectivity)
        context_model_parameters = ContextModelParameters(
            connectivity, model, integrator)
        data_for_param_sliders = self.get_data_for_param_sliders(
            '0', context_model_parameters)
        base.add2session(KEY_CONTEXT_MPR, context_model_parameters)

        template_specification = dict(
            title="Spatio temporal - Model parameters")
        template_specification[
            'submit_parameters_url'] = '/spatial/modelparameters/regions/submit_model_parameters'
        template_specification[
            'parametersNames'] = context_model_parameters.model_parameter_names
        template_specification['isSingleMode'] = True
        template_specification['paramSlidersData'] = json.dumps(
            data_for_param_sliders)
        template_specification.update(connectivity_viewer_params)
        template_specification[
            'mainContent'] = 'spatial/model_param_region_main'
        template_specification['displayDefaultSubmitBtn'] = True
        template_specification.update(
            context_model_parameters.phase_plane_params)
        return self.fill_default_attributes(template_specification)
Exemplo n.º 6
0
 def settings(self, save_settings=False, **data):
     """Main settings page submit and get"""
     template_specification = dict(
         mainContent="../settings/system_settings", title="System Settings")
     if save_settings:
         try:
             form = SettingsForm()
             data = form.to_python(data)
             isrestart, isreset = self.settingsservice.save_settings(**data)
             if isrestart:
                 thread = threading.Thread(target=self._restart_services,
                                           kwargs={'should_reset': isreset})
                 thread.start()
                 bc.add2session(bc.KEY_IS_RESTART, True)
                 bc.set_info_message(
                     'Please wait until TVB is restarted properly!')
                 raise cherrypy.HTTPRedirect('/tvb')
             # Here we will leave the same settings page to be displayed.
             # It will continue reloading when CherryPy restarts.
         except formencode.Invalid, excep:
             template_specification[bc.KEY_ERRORS] = excep.unpack_errors()
         except InvalidSettingsException, excep:
             self.logger.error(
                 'Invalid settings!  Exception %s was raised' %
                 (str(excep)))
             bc.set_error_message(excep.message)
Exemplo n.º 7
0
    def save_parameters(self, index_in_tab, **data):
        """
        Save parameters
        
        :param tab_nr: the index of the selected tab
        :param index_in_tab: the index of the configured portlet in the selected tab
        :param data: the {name:value} dictionary configuration of the current portlet
        
        Having these inputs, update the configuration of the portletin the 
        corresponding tab position form the burst configuration .
        """
        burst_config = base.get_from_session(base.KEY_BURST_CONFIG)
        tab_nr = burst_config.selected_tab
        old_portlet_config = burst_config.tabs[int(tab_nr)].portlets[int(
            index_in_tab)]

        # Replace all void entries with 'None'
        for entry in data:
            if data[entry] == '':
                data[entry] = None

        need_relaunch = self.burst_service.update_portlet_configuration(
            old_portlet_config, data)
        if need_relaunch:
            #### Reset Burst Configuration into an entity not persisted (id = None for all)
            base.add2session(base.KEY_BURST_CONFIG, burst_config.clone())
            return "relaunchView"
        else:
            self.workflow_service.store_workflow_step(
                old_portlet_config.visualizer)
            return "noRelaunch"
    def add_adapter_to_session(self,
                               algo_group,
                               input_tree,
                               default_data=None):
        """
        Put in session information about currently selected adapter.
        Will be used by filters and efficiency load.
        """
        previous_algo = self.get_current_substep()
        current_algo = algo_group.id if algo_group is not None else (
            default_data[base.KEY_ADAPTER]
            if default_data is not None else None)
        if current_algo is None or str(current_algo) != str(previous_algo):
            self.clean_from_session()
            adapter_info = {}
        else:
            adapter_info = base.get_from_session(self.KEY_CURRENT_ADAPTER_INFO)

        if default_data is not None:
            adapter_info[self._KEY_SELECTED_DATA] = default_data
        if input_tree is not None:
            adapter_info[self._KEY_INPUT_TREE] = input_tree
        if algo_group is not None:
            adapter_info[self._KEY_CURRENT_STEP] = algo_group.fk_category
            adapter_info[self._KEY_CURRENT_SUBSTEP] = algo_group.id

        base.add2session(self.KEY_CURRENT_ADAPTER_INFO, adapter_info)
Exemplo n.º 9
0
    def edit_model_parameters(self):
        """
        Main method, to initialize Model-Parameter visual-set.
        """
        model, integrator, connectivity, surface = self.get_data_from_burst_configuration(
        )
        context_model_parameters = SurfaceContextModelParameters(
            surface, connectivity, model, integrator)
        base.add2session(KEY_CONTEXT_MPS, context_model_parameters)

        template_specification = dict(
            title="Spatio temporal - Model parameters")
        template_specification.update(self.display_surface(surface.gid))
        model_params_data = self.get_surface_model_parameters_data()
        model_params_data = self._add_entra_equation_entries(model_params_data)
        template_specification.update(model_params_data)
        template_specification[
            'submit_parameters_url'] = '/spatial/modelparameters/surface/submit_model_parameters'
        template_specification[
            'mainContent'] = 'spatial/model_param_surface_main'
        template_specification[
            'equationViewerUrl'] = '/spatial/modelparameters/surface/get_equation_chart'
        template_specification['equationsPrefixes'] = json.dumps(
            self.plotted_equations_prefixes)
        template_specification['submitSurfaceParametersBtn'] = True
        return self.fill_default_attributes(template_specification)
 def copy_configuration(self, from_node, to_nodes):
     from_node = int(from_node)
     to_nodes = json.loads(to_nodes)
     if from_node < 0 or not len(to_nodes):
         return
     context_model_parameters = base.get_from_session(KEY_CONTEXT_NC)
     context_model_parameters.set_noise_connectivity_nodes(
         from_node, to_nodes)
     base.add2session(KEY_CONTEXT_NC, context_model_parameters)
Exemplo n.º 11
0
 def copy_burst(self, burst_id):
     """
     When currently selected entry is a valid Burst, create a clone of that Burst.
     """
     base_burst = self.burst_service.load_burst(burst_id)[0]
     if (base_burst is None) or (base_burst.id is None):
         return self.reset_burst()
     base.add2session(base.KEY_BURST_CONFIG, base_burst.clone())
     return base_burst.name
Exemplo n.º 12
0
    def index(self):
        """Get on burst main page"""
        template_specification = dict(
            mainContent="burst/main_burst",
            title="Simulation Cockpit",
            baseUrl=cfg.BASE_URL,
            includedResources='project/included_resources')
        portlets_list = self.burst_service.get_available_portlets()
        session_stored_burst = base.get_from_session(base.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(
                    base.get_current_project().id)
                base.add2session(base.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 = ABCAdapter.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_algo_group, 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(
                base.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.
        algo_group = self.flow_service.get_algorithm_by_module_and_class(
            MEASURE_METRICS_MODULE, MEASURE_METRICS_CLASS)[1]
        adapter_instance = ABCAdapter.build_adapter(algo_group)
        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[base.KEY_PARAMETERS_CONFIG] = False
        template_specification[base.KEY_SECTION] = 'burst'
        return self.fill_default_attributes(template_specification)
 def load_local_connectivity(self, local_connectivity_gid, from_step=None):
     """
     Loads the interface for an existing local connectivity.
     """
     context = base.get_from_session(KEY_LCONN_CONTEXT)
     context.selected_entity = local_connectivity_gid
     base.add2session(
         base.KEY_MESSAGE, "Successfully loaded existent entity gid=%s" %
         (local_connectivity_gid, ))
     if int(from_step) == 1:
         return self.step_1()
     if int(from_step) == 2:
         return self.step_2()
Exemplo n.º 14
0
 def step_1_submit(self, next_step, do_reset=0, **kwargs):
     """
     Any submit from the first step should be handled here. Update the context then
     go to the next step as required. In case a reset is needed create a clear context.
     """
     if int(do_reset) == 1:
         new_context = SurfaceStimulusContext()
         base.add2session(KEY_SURFACE_CONTEXT, new_context)
     context = base.get_from_session(KEY_SURFACE_CONTEXT)
     if kwargs.get(SURFACE_PARAMETER) != context.get_session_surface():
         context.set_focal_points('[]')
     context.update_eq_kwargs(kwargs)
     return self.do_step(next_step)
 def step_1_submit(self, next_step, do_reset=0, **kwargs):
     """
     Any submit from the first step should be handled here. Update the context then
     go to the next step as required. In case a reset is needed create a clear context.
     """
     if int(do_reset) == 1:
         new_context = RegionStimulusContext()
         base.add2session(KEY_REGION_CONTEXT, new_context)
     context = base.get_from_session(KEY_REGION_CONTEXT)
     if kwargs.get(
             CONNECTIVITY_PARAMETER) != context.get_session_connectivity():
         context.set_weights([])
     context.equation_kwargs = kwargs
     return self.do_step(next_step)
    def copy_model(self, from_node, to_nodes):
        """
        Replace the model of the nodes 'to_nodes' with the model of the node 'from_node'.

        ``from_node``: the index of the node from where will be copied the model
        ``to_nodes``: a list with the nodes indexes for which will be replaced the model
        """
        from_node = int(from_node)
        to_nodes = json.loads(to_nodes)
        if from_node < 0 or not len(to_nodes):
            return
        context_model_parameters = base.get_from_session(KEY_CONTEXT_MPR)
        context_model_parameters.set_model_for_connectivity_nodes(from_node, to_nodes)
        base.add2session(KEY_CONTEXT_MPR, context_model_parameters)
 def submit_model_parameters(self):
     """
     Collects the model parameters values from all the models used for the connectivity nodes.
     """
     context_model_parameters = base.get_from_session(KEY_CONTEXT_MPR)
     burst_configuration = base.get_from_session(base.KEY_BURST_CONFIG)
     for param_name in context_model_parameters.model_parameter_names:
         full_name = PARAMS_MODEL_PATTERN % (context_model_parameters.model_name, param_name)
         full_values = context_model_parameters.get_values_for_parameter(param_name)
         burst_configuration.update_simulation_parameter(full_name, full_values) 
     ### Clean from session drawing context
     base.remove_from_session(KEY_CONTEXT_MPR)
     ### Update in session BURST configuration for burst-page. 
     base.add2session(base.KEY_BURST_CONFIG, burst_configuration.clone())
     raise cherrypy.HTTPRedirect("/burst/")
Exemplo n.º 18
0
 def cached_simulator_input_tree(self):
     """
     Cache Simulator's input tree, for performance issues.
     Anyway, without restart, the introspected tree will not be different on multiple executions.
     :returns: Simulator's Input Tree (copy from cache or just loaded)
     """
     cached_simulator_tree = base.get_from_session(
         base.KEY_CACHED_SIMULATOR_TREE)
     if cached_simulator_tree is None:
         cached_simulator_tree = self.flow_service.prepare_adapter(
             base.get_current_project().id,
             self.cached_simulator_algo_group)[1]
         base.add2session(base.KEY_CACHED_SIMULATOR_TREE,
                          cached_simulator_tree)
     return copy.deepcopy(cached_simulator_tree)
Exemplo n.º 19
0
 def reload_burst_operation(self, operation_id, is_group, **_):
     """
     Find out from which burst was this operation launched. Set that burst as the selected one and 
     redirect to the burst page.
     """
     is_group = int(is_group)
     if not is_group:
         operation = self.flow_service.load_operation(int(operation_id))
     else:
         op_group = ProjectService.get_operation_group_by_id(operation_id)
         first_op = ProjectService.get_operations_in_group(op_group)[0]
         operation = self.flow_service.load_operation(int(first_op.id))
     operation.burst.prepare_after_load()
     base.add2session(base.KEY_BURST_CONFIG, operation.burst)
     raise cherrypy.HTTPRedirect("/burst/")
Exemplo n.º 20
0
 def get_visualizers_for_operation_id(self, op_id, width, height):
     """
     Method called from parameters exploration page in case a burst with a range of parameters
     for the simulator was launched. 
     :param op_id: the selected operation id from the parameter space exploration.
     :param width: the width of the right side display
     :param height: the height of the right side display
     
     Given these parameters first get the workflow to which op_id belongs, then load the portlets
     from that workflow as the current burst configuration. Width and height are used to get the
     proper sizes for the visualization iFrames. 
     """
     burst_config = base.get_from_session(base.KEY_BURST_CONFIG)
     burst_config = self.burst_service.load_tab_configuration(burst_config, op_id)
     base.add2session(base.KEY_BURST_CONFIG, burst_config)
     return self.load_configured_visualizers(width, height)
Exemplo n.º 21
0
    def __get_operations_filters(self):
        """
        Filters for VIEW_ALL_OPERATIONS page.
        Get from session currently selected filters, or build a new set of filters.
        """
        session_filtes = bc.get_from_session(self.KEY_OPERATION_FILTERS)
        if session_filtes:
            return session_filtes

        else:
            sim_group = self.flow_service.get_algorithm_by_module_and_class(
                SIMULATOR_MODULE, SIMULATOR_CLASS)[1]
            new_filters = StaticFiltersFactory.build_operations_filters(
                sim_group,
                bc.get_logged_user().id)
            bc.add2session(self.KEY_OPERATION_FILTERS, new_filters)
            return new_filters
 def update_model_parameter_for_nodes(self, param_name, new_param_value, connectivity_node_indexes):
     """
     Updates the specified model parameter for the first node from the 'connectivity_node_indexes'
     list and after that replace the model of each node from the 'connectivity_node_indexes' list
     with the model of the first node from the list.
     """
     connectivity_node_indexes = json.loads(connectivity_node_indexes)
     if not len(connectivity_node_indexes):
         return
     context_model_parameters = base.get_from_session(KEY_CONTEXT_MPR)
     first_node_index = connectivity_node_indexes[0]
     context_model_parameters.update_model_parameter(first_node_index, param_name, new_param_value)
     if len(connectivity_node_indexes) > 1:
         #eliminate the first node
         connectivity_node_indexes = connectivity_node_indexes[1: len(connectivity_node_indexes)]
         context_model_parameters.set_model_for_connectivity_nodes(first_node_index, connectivity_node_indexes)
     base.add2session(KEY_CONTEXT_MPR, context_model_parameters)
 def submit_noise_configuration(self):
     """
     Collects the model parameters values from all the models used for the connectivity nodes.
     """
     context_noise_config = base.get_from_session(KEY_CONTEXT_NC)
     burst_configuration = base.get_from_session(base.KEY_BURST_CONFIG)
     _, simulator_group = FlowService().get_algorithm_by_module_and_class(
         SIMULATOR_MODULE, SIMULATOR_CLASS)
     simulator_adapter = ABCAdapter.build_adapter(simulator_group)
     for param_name in simulator_adapter.noise_configurable_parameters():
         burst_configuration.update_simulation_parameter(
             param_name, str(context_noise_config.noise_values))
     ### Clean from session drawing context
     base.remove_from_session(KEY_CONTEXT_NC)
     ### Update in session BURST configuration for burst-page.
     base.add2session(base.KEY_BURST_CONFIG, burst_configuration.clone())
     raise cherrypy.HTTPRedirect("/burst/")
    def reset_model_parameters_for_nodes(self, connectivity_node_indexes):
        """
        Resets the model parameters, of the specified connectivity nodes, to their default values.
        """
        connectivity_node_indexes = json.loads(connectivity_node_indexes)
        if not len(connectivity_node_indexes):
            return

        context_model_parameters = base.get_from_session(KEY_CONTEXT_MPR)
        context_model_parameters.reset_model_parameters_for_nodes(connectivity_node_indexes)
        context_model_parameters.load_model_for_connectivity_node(connectivity_node_indexes[0])
        data_for_param_sliders = self.get_data_for_param_sliders(connectivity_node_indexes[0], context_model_parameters)
        base.add2session(KEY_CONTEXT_MPR, context_model_parameters)

        template_specification = dict()
        template_specification['paramSlidersData'] = json.dumps(data_for_param_sliders)
        template_specification['parametersNames'] = data_for_param_sliders['all_param_names']
        return template_specification
Exemplo n.º 25
0
 def load_burst(self, burst_id):
     """
     Given a clicked burst from the history and the selected tab, load all 
     the required data from that burst. Return a value specifying if it was a result
     of a range launch (OperationGroup) or not.
     """
     try:
         old_burst = base.get_from_session(base.KEY_BURST_CONFIG)
         burst, group_gid = self.burst_service.load_burst(burst_id)
         burst.selected_tab = old_burst.selected_tab
         base.add2session(base.KEY_BURST_CONFIG, burst)
         return {'status': burst.status, 'group_gid': group_gid, 'selected_tab': burst.selected_tab}
     except Exception, excep:
         ### Most probably Burst was removed. Delete it from session, so that client 
         ### has a good chance to get a good response on refresh
         self.logger.error(excep)
         base.remove_from_session(base.KEY_BURST_CONFIG)
         raise excep
Exemplo n.º 26
0
 def apply_equation(self, **kwargs):
     """
     Applies an equations for computing a model parameter.
     """
     submitted_data = ABCAdapter.collapse_arrays(kwargs, ['model_param'])
     model_param, equation = self._compute_equation(submitted_data)
     context_model_parameters = base.get_from_session(KEY_CONTEXT_MPS)
     context_model_parameters.apply_equation(model_param, equation)
     base.add2session(KEY_CONTEXT_MPS, context_model_parameters)
     template_specification = self.get_surface_model_parameters_data(
         model_param)
     template_specification = self._add_entra_equation_entries(
         template_specification, kwargs['min_x'], kwargs['max_x'])
     template_specification[
         'equationViewerUrl'] = '/spatial/modelparameters/surface/get_equation_chart'
     template_specification['equationsPrefixes'] = json.dumps(
         self.plotted_equations_prefixes)
     return self.fill_default_attributes(template_specification)
    def display_surface(surface_gid):
        """
        Generates the HTML for displaying the surface with the given ID.
        """
        surface = ABCAdapter.load_entity_by_gid(surface_gid)
        base.add2session(PARAM_SURFACE, surface_gid)
        url_vertices_pick, url_normals_pick, url_triangles_pick = surface.get_urls_for_pick_rendering()
        url_vertices, url_normals, url_triangles, alphas, alphas_indices = surface.get_urls_for_rendering(True, None)

        template_specification = dict()
        template_specification['urlVerticesPick'] = json.dumps(url_vertices_pick)
        template_specification['urlTrianglesPick'] = json.dumps(url_triangles_pick)
        template_specification['urlNormalsPick'] = json.dumps(url_normals_pick)
        template_specification['urlVertices'] = json.dumps(url_vertices)
        template_specification['urlTriangles'] = json.dumps(url_triangles)
        template_specification['urlNormals'] = json.dumps(url_normals)
        template_specification['alphas'] = json.dumps(alphas)
        template_specification['alphas_indices'] = json.dumps(alphas_indices)
        template_specification['brainCenter'] = json.dumps(surface.center())
        return template_specification
Exemplo n.º 28
0
 def profile(self, logout=False, save=False, **data):
     """
     Display current user's profile page.
     On POST: logout, or save password/email.
     """
     if cherrypy.request.method == 'POST' and logout:
         raise cherrypy.HTTPRedirect('/user/logout')
     template_specification = dict(mainContent="profile",
                                   title="User Profile")
     if cherrypy.request.method == 'POST' and save:
         try:
             form = EditUserForm()
             data = form.to_python(data)
             user = basecontroller.get_logged_user()
             if KEY_PASSWORD in data and data[KEY_PASSWORD]:
                 user.password = md5(data[KEY_PASSWORD]).hexdigest()
             if KEY_EMAIL in data and data[KEY_EMAIL]:
                 user.email = data[KEY_EMAIL]
             old_password = None
             if 'old_password' in data and data['old_password']:
                 old_password = md5(data['old_password']).hexdigest()
             self.user_service.edit_user(user, old_password)
             if old_password:
                 basecontroller.set_info_message("Changes Submitted!")
             else:
                 basecontroller.set_info_message(
                     "Submitted!  No password changed.")
         except formencode.Invalid, excep:
             template_specification[
                 basecontroller.KEY_ERRORS] = excep.unpack_errors()
         except UsernameException, excep:
             self.logger.exception(excep)
             user = basecontroller.get_logged_user()
             basecontroller.add2session(
                 basecontroller.KEY_USER,
                 self.user_service.get_user_by_id(user.id))
             basecontroller.set_error_message(
                 "Could not save changes. Probably wrong old password!!")
 def step_1(self, do_reset=0, **kwargs):
     """
     Generate the html for the first step of the local connectivity page. 
     :param kwargs: not actually used, but parameters are still submitted from UI since we just
         use the same js function for this. TODO: do this in a smarter way
     """
     if int(do_reset) == 1:
         new_context = ContextLocalConnectivity()
         base.add2session(KEY_LCONN_CONTEXT, new_context)
     context = base.get_from_session(KEY_LCONN_CONTEXT)
     right_side_interface = self._get_lconn_interface()
     left_side_interface = self.get_select_existent_entities(
         'Load Local Connectivity', LocalConnectivity,
         context.selected_entity)
     #add interface to session, needed for filters
     self.add_interface_to_session(left_side_interface,
                                   right_side_interface['inputList'])
     template_specification = dict(title="Surface - Local Connectivity")
     template_specification[
         'mainContent'] = 'spatial/local_connectivity_step1_main'
     template_specification.update(right_side_interface)
     template_specification['displayCreateLocalConnectivityBtn'] = True
     template_specification['loadExistentEntityUrl'] = LOAD_EXISTING_URL
     template_specification['resetToDefaultUrl'] = RELOAD_DEFAULT_PAGE_URL
     template_specification[
         'existentEntitiesInputList'] = left_side_interface
     template_specification[
         'submit_parameters_url'] = '/spatial/localconnectivity/create_local_connectivity'
     template_specification[
         'equationViewerUrl'] = '/spatial/localconnectivity/get_equation_chart'
     template_specification['equationsPrefixes'] = json.dumps(
         self.plotted_equations_prefixes)
     template_specification[
         'next_step_url'] = '/spatial/localconnectivity/step_2'
     template_specification['displayedMessage'] = base.get_from_session(
         base.KEY_MESSAGE)
     return self.fill_default_attributes(template_specification)
Exemplo n.º 30
0
 def view_stimulus(self, focal_points):
     """
     Just create the stimulus to view the actual data, don't store to db.
     Hold the entity in session without the surface, so the next time you need
     data just get from that one.
     """
     try:
         context = base.get_from_session(KEY_SURFACE_CONTEXT)
         context.set_focal_points(focal_points)
         kwargs = copy.deepcopy(context.equation_kwargs)
         surface_stimulus_creator = self.get_creator_and_interface(SURFACE_STIMULUS_CREATOR_MODULE,
                                                                   SURFACE_STIMULUS_CREATOR_CLASS, StimuliSurface())[0]
         min_time = float(kwargs.get('min_tmp_x', 0))
         max_time = float(kwargs.get('max_tmp_x', 100))
         kwargs = surface_stimulus_creator.prepare_ui_inputs(kwargs)
         stimulus = surface_stimulus_creator.launch(**kwargs)
         surface_gid = base.get_from_session(PARAM_SURFACE)
         surface = ABCAdapter.load_entity_by_gid(surface_gid)
         stimulus.surface = surface
         stimulus.configure_space()
         time = numpy.arange(min_time, max_time, 1)
         time = time[numpy.newaxis, :]
         stimulus.configure_time(time)
         data = []
         max_value = numpy.max(stimulus())
         for i in range(min(CHUNK_SIZE, stimulus.temporal_pattern.shape[1])):
             step_data = stimulus(i).tolist()
             data.append(step_data)
         stimulus.surface = surface.gid
         base.add2session(KEY_STIMULUS, stimulus)
         result = {'status': 'ok', 'max': max_value, 'data': data, "time_min": min_time, "time_max": max_time,
                   "chunk_size": CHUNK_SIZE}
         return result
     except (NameError, ValueError, SyntaxError), ex:
         return {'status': 'error',
                 'errorMsg': "Could not generate stimulus data. Some of the parameters hold invalid characters."}