def stop_burst_operation(self, operation_id, is_group, remove_after_stop=False): """ For a given operation id that is part of a burst just stop the given burst. """ operation_id = int(operation_id) if int(is_group) == 0: operation = self.flow_service.load_operation(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)) try: burst_service = BurstService() burst_service.stop_burst(operation.burst) if remove_after_stop: current_burst = base.get_from_session(base.KEY_BURST_CONFIG) if current_burst and current_burst.id == operation.burst.id: base.remove_from_session(base.KEY_BURST_CONFIG) burst_service.remove_burst(operation.burst.id) return True except Exception, ex: self.logger.exception(ex) return False
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/")
def invokeadaptermethod(self, adapter_id, method_name, **data): """ Public web method, to be used when invoking specific methods from external Adapters/Algorithms. """ algo_group = self.flow_service.get_algo_group_by_identifier(adapter_id) try: adapter_instance = self.flow_service.build_adapter_instance( algo_group) result = self.flow_service.fire_operation( adapter_instance, base.get_logged_user(), base.get_current_project().id, method_name, **data) base.set_info_message("Submit OK!") if isinstance(adapter_instance, ABCDisplayer) and isinstance( result, dict): base.remove_from_session(base.KEY_MESSAGE) result[ABCDisplayer.KEY_IS_ADAPTER] = True result[base.KEY_DISPLAY_MENU] = True result[base.KEY_OPERATION_ID] = adapter_instance.operation_id result[base.KEY_ADAPTER] = adapter_id if KEY_CONTROLLS not in result: result[KEY_CONTROLLS] = None return self.fill_default_attributes(result, algo_group) except OperationException, excep: base.set_warning_message('Problem when submitting data!') self.logger.error( "Invalid method, or wrong parameters when invoking external method on post!" ) self.logger.exception(excep)
def reset_burst(self): """ Called when click on "New Burst" entry happens from UI. This will generate an empty new Burst Configuration. """ base.remove_from_session(base.KEY_CACHED_SIMULATOR_TREE) new_burst = self.burst_service.new_burst_configuration( base.get_current_project().id) base.add2session(base.KEY_BURST_CONFIG, new_burst)
def copy_burst(self, burst_id): """ When currently selected entry is a valid Burst, create a clone of that Burst. """ base.remove_from_session(base.KEY_CACHED_SIMULATOR_TREE) 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
def logout(self): """ Logging out user and clean session """ user = basecontroller.remove_from_session(basecontroller.KEY_USER) if user is not None: self.logger.debug("User " + user.username + " is just logging out!") basecontroller.remove_from_session(basecontroller.KEY_PROJECT) basecontroller.remove_from_session(basecontroller.KEY_BURST_CONFIG) basecontroller.set_info_message( "Thank you for using The Virtual Brain!") raise cherrypy.HTTPRedirect("/user")
def editone(self, project_id=None, cancel=False, save=False, delete=False, **data): """ Create or change Project. When project_id is empty we create a new entity, otherwise we are to edit and existent one. """ if cherrypy.request.method == 'POST' and cancel: raise cherrypy.HTTPRedirect('/project') if cherrypy.request.method == 'POST' and delete: self._remove_project(project_id) raise cherrypy.HTTPRedirect('/project/viewall') current_user = bc.get_logged_user() is_create = False if project_id is None or not int(project_id): is_create = True data["administrator"] = current_user.username else: current_project = self.project_service.find_project(project_id) if not save: # Only when we do not have submitted data, # populate fields with initial values for edit. data = dict(name=current_project.name, description=current_project.description) data["administrator"] = current_project.administrator.username self._mark_selected(current_project) data["project_id"] = project_id template_specification = dict( mainContent="project/editone", data=data, isCreate=is_create, title="Create new project" if is_create else "Edit " + data["name"], editUsersEnabled=(current_user.username == data['administrator'])) try: if cherrypy.request.method == 'POST' and save: bc.remove_from_session(bc.KEY_PROJECT) bc.remove_from_session(bc.KEY_CACHED_SIMULATOR_TREE) self._persist_project(data, project_id, is_create, current_user) raise cherrypy.HTTPRedirect('/project/viewall') except formencode.Invalid, excep: self.logger.debug(str(excep)) template_specification[bc.KEY_ERRORS] = excep.unpack_errors()
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/")
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 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
except ServicesBaseException, excep: self.logger.warning(excep.message) bc.set_error_message(excep.message) raise cherrypy.HTTPRedirect('/project/viewall') def _remove_project(self, project_id): """Private method for removing project.""" try: self.project_service.remove_project(project_id) except ServicesBaseException, exc: self.logger.error("Could not delete project!") self.logger.exception(exc) bc.set_error_message(exc.message) prj = bc.get_current_project() if prj is not None and prj.id == int(project_id): bc.remove_from_session(bc.KEY_PROJECT) def _persist_project(self, data, project_id, is_create, current_user): """Private method to persist""" data = EditForm().to_python(data) saved_project = self.project_service.store_project( current_user, is_create, project_id, **data) selected_project = bc.get_current_project() if len( self.project_service.retrieve_projects_for_user( current_user.id, 1)) == 1: selected_project = saved_project if selected_project is None or (saved_project.id == selected_project.id): self._mark_selected(saved_project)
def clean_from_session(self): """ Remove info about selected algo from session """ base.remove_from_session(self.KEY_CURRENT_ADAPTER_INFO)