def handle_next_fragment_for_monitors(self, context, rendering_rules, current_monitor, next_monitor, is_noise_form, form_action_url, if_bold_url): simulator, _, _, is_branch = context.get_common_params() if isinstance(current_monitor, BoldViewModel) and is_noise_form is False: return self._prepare_next_fragment_if_bold(current_monitor, rendering_rules, if_bold_url) if not next_monitor: rendering_rules.is_branch = is_branch return SimulatorFinalFragment.prepare_final_fragment( simulator, context.burst_config, context.project.id, rendering_rules, SimulatorWizzardURLs.SETUP_PSE_URL) next_form = get_form_for_monitor(type(next_monitor))(simulator, is_branch) next_form = AlgorithmService().prepare_adapter_form( form_instance=next_form, project_id=context.project.id) next_form.fill_from_trait(next_monitor) monitor_name = self.prepare_monitor_legend( simulator.is_surface_simulation, next_monitor) rendering_rules.form = next_form rendering_rules.form_action_url = form_action_url rendering_rules.monitor_name = monitor_name return rendering_rules.to_dict()
def set_monitor_equation(self, **data): session_stored_simulator = common.get_from_session( common.KEY_SIMULATOR_CONFIG) is_simulator_copy = common.get_from_session( common.KEY_IS_SIMULATOR_COPY) is_simulator_load = common.get_from_session( common.KEY_IS_SIMULATOR_LOAD) if cherrypy.request.method == 'POST': is_simulator_copy = False form = get_form_for_monitor( type(session_stored_simulator.monitors[0]))() form.fill_from_post(data) form.fill_trait(session_stored_simulator.monitor.hrf_kernel) next_form = SimulatorLengthFragment() dict_to_render = copy.deepcopy(self.dict_to_render) dict_to_render[self.FORM_KEY] = next_form dict_to_render[self.ACTION_KEY] = '/burst/set_simulation_length' dict_to_render[ self.PREVIOUS_ACTION_KEY] = '/burst/set_monitor_equation' dict_to_render[self.IS_COPY] = is_simulator_copy dict_to_render[self.IS_LOAD] = is_simulator_load if is_simulator_load: dict_to_render[self.ACTION_KEY] = '' dict_to_render[self.IS_LAST_FRAGMENT_KEY] = True return dict_to_render
def set_monitor_params(self, current_monitor_name, **data): session_stored_simulator, is_simulation_copy, is_simulator_load, is_branch = self.context.get_common_params() current_monitor, next_monitor = self.monitors_handler.get_current_and_next_monitor_form( current_monitor_name, session_stored_simulator) if cherrypy.request.method == POST_REQUEST: form = get_form_for_monitor(type(current_monitor))(session_stored_simulator, is_branch) if is_branch: data['period'] = str(current_monitor.period) data['variables_of_interest'] = [session_stored_simulator.model.variables_of_interest[i] for i in current_monitor.variables_of_interest] form.fill_from_post(data) form.fill_trait(current_monitor) last_loaded_form_url = self.get_url_after_monitors( current_monitor, current_monitor_name, next_monitor) self.context.add_last_loaded_form_url_to_session(last_loaded_form_url) previous_form_action_url = self.build_monitor_url(SimulatorWizzardURLs.SET_MONITOR_PARAMS_URL, current_monitor_name) rendering_rules = SimulatorFragmentRenderingRules( is_simulation_copy=is_simulation_copy, is_simulation_readonly_load=is_simulator_load, last_request_type=cherrypy.request.method, last_form_url=self.context.last_loaded_fragment_url, previous_form_action_url=previous_form_action_url) form_action_url, if_bold_url = self.get_urls_for_next_monitor_fragment(next_monitor, current_monitor) self.monitors_handler.update_monitor(current_monitor) return self.monitors_handler.handle_next_fragment_for_monitors(self.context, rendering_rules, current_monitor, next_monitor, False, form_action_url, if_bold_url)
def set_monitors(self, **data): session_stored_simulator = common.get_from_session( common.KEY_SIMULATOR_CONFIG) is_simulator_copy = common.get_from_session( common.KEY_IS_SIMULATOR_COPY) is_simulator_load = common.get_from_session( common.KEY_IS_SIMULATOR_LOAD) if cherrypy.request.method == 'POST': is_simulator_copy = False # TODO: handle multiple monitors fragment = SimulatorMonitorFragment() fragment.fill_from_post(data) session_stored_simulator.monitors = [fragment.monitor.value()] monitor = session_stored_simulator.monitors[0] form = get_form_for_monitor(type(monitor))( '', common.get_current_project().id) form.fill_from_trait(monitor) dict_to_render = copy.deepcopy(self.dict_to_render) dict_to_render[self.FORM_KEY] = form dict_to_render[self.ACTION_KEY] = '/burst/set_monitor_params' dict_to_render[self.PREVIOUS_ACTION_KEY] = '/burst/set_monitors' dict_to_render[self.IS_COPY] = is_simulator_copy dict_to_render[self.IS_LOAD] = is_simulator_load return dict_to_render
def get_fragment_after_monitors(simulator, burst_config, project_id, is_branch, rendering_rules, setup_pse_url): first_monitor = simulator.first_monitor if first_monitor is None: rendering_rules.is_branch = is_branch return SimulatorFinalFragment.prepare_final_fragment( simulator, burst_config, project_id, rendering_rules, setup_pse_url) form = get_form_for_monitor(type(first_monitor))(simulator, is_branch) form = AlgorithmService().prepare_adapter_form(form_instance=form) form.fill_from_trait(first_monitor) monitor_name = MonitorsWizardHandler.prepare_monitor_legend( simulator.is_surface_simulation, first_monitor) rendering_rules.monitor_name = monitor_name rendering_rules.form = form return rendering_rules.to_dict()