def __init__(self, prefix=''): super(IntegratorStochasticForm, self).__init__(prefix) self.noise_choices = get_ui_name_to_noise_dict() default_noise = list(self.noise_choices.values())[0] self.noise = SelectField(Attr(NoiseViewModel, label='Noise', default=default_noise), self, name='noise', choices=self.noise_choices, subform=get_form_for_noise(default_noise))
def set_noise_params(self, **data): session_stored_simulator, is_simulation_copy, is_simulation_load, is_branch = self.context.get_common_params( ) if cherrypy.request.method == POST_REQUEST: form = get_form_for_noise( type(session_stored_simulator.integrator.noise))() form.fill_from_post(data) form.fill_trait(session_stored_simulator.integrator.noise) if isinstance(session_stored_simulator.integrator.noise, AdditiveNoiseViewModel): self.context.add_last_loaded_form_url_to_session( SimulatorWizzardURLs.SET_MONITORS_URL) else: self.context.add_last_loaded_form_url_to_session( SimulatorWizzardURLs.SET_NOISE_EQUATION_PARAMS_URL) rendering_rules = SimulatorFragmentRenderingRules( None, None, SimulatorWizzardURLs.SET_NOISE_PARAMS_URL, is_simulation_copy, is_simulation_load, self.context.last_loaded_fragment_url, cherrypy.request.method) return self.monitors_handler.prepare_next_fragment_after_noise( session_stored_simulator, is_branch, rendering_rules, SimulatorWizzardURLs.SET_MONITORS_URL, SimulatorWizzardURLs.SET_NOISE_EQUATION_PARAMS_URL)
def __init__(self, is_dt_disabled=False): super(IntegratorStochasticForm, self).__init__(is_dt_disabled) self.noise = SelectField(EnumAttr(label='Noise', default=NoiseTypesEnum.ADDITIVE), name='noise', subform=get_form_for_noise( NoiseTypesEnum.ADDITIVE.value))
def set_integrator_params(self, **data): session_stored_simulator, is_simulation_copy, is_simulation_load, is_branch = self.context.get_common_params( ) if cherrypy.request.method == POST_REQUEST: form = get_form_for_integrator( type(session_stored_simulator.integrator))(is_branch) if is_branch: data['dt'] = str(session_stored_simulator.integrator.dt) form.fill_from_post(data) form.fill_trait(session_stored_simulator.integrator) if isinstance(session_stored_simulator.integrator, IntegratorStochasticViewModel): self.context.add_last_loaded_form_url_to_session( SimulatorWizzardURLs.SET_NOISE_PARAMS_URL) else: self.context.add_last_loaded_form_url_to_session( SimulatorWizzardURLs.SET_MONITORS_URL) self.range_parameters.integrator_noise_parameters = None rendering_rules = SimulatorFragmentRenderingRules( None, None, SimulatorWizzardURLs.SET_INTEGRATOR_PARAMS_URL, is_simulation_copy, is_simulation_load, self.context.last_loaded_fragment_url, cherrypy.request.method, is_noise_fragment=False) if not isinstance(session_stored_simulator.integrator, IntegratorStochasticViewModel): return self.monitors_handler.prepare_monitor_fragment( session_stored_simulator, rendering_rules, SimulatorWizzardURLs.SET_MONITORS_URL) integrator_noise_fragment = get_form_for_noise( type(session_stored_simulator.integrator.noise))() if hasattr(integrator_noise_fragment, 'equation'): integrator_noise_fragment.equation.display_subform = False self.range_parameters.integrator_noise_parameters = integrator_noise_fragment.get_range_parameters( ) integrator_noise_fragment.fill_from_trait( session_stored_simulator.integrator.noise) rendering_rules.form = integrator_noise_fragment rendering_rules.form_action_url = SimulatorWizzardURLs.SET_NOISE_PARAMS_URL rendering_rules.is_noise_fragment = True return rendering_rules.to_dict()
def set_integrator_params(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_integrator( type(session_stored_simulator.integrator))() form.fill_from_post(data) form.fill_trait(session_stored_simulator.integrator) if isinstance(session_stored_simulator.integrator, IntegratorStochastic): integrator_noise_fragment = get_form_for_noise( type(session_stored_simulator.integrator.noise))() self.range_parameters.integrator_noise_parameters = integrator_noise_fragment.get_range_parameters( ) integrator_noise_fragment.fill_from_trait( session_stored_simulator.integrator.noise) dict_to_render = copy.deepcopy(self.dict_to_render) dict_to_render[self.FORM_KEY] = integrator_noise_fragment dict_to_render[self.ACTION_KEY] = '/burst/set_noise_params' dict_to_render[ self.PREVIOUS_ACTION_KEY] = '/burst/set_integrator_params' dict_to_render[self.IS_COPY] = is_simulator_copy dict_to_render[self.IS_LOAD] = is_simulator_load return dict_to_render monitor_fragment = SimulatorMonitorFragment( '', common.get_current_project().id) monitor_fragment.fill_from_trait(session_stored_simulator) dict_to_render = copy.deepcopy(self.dict_to_render) dict_to_render[self.FORM_KEY] = monitor_fragment dict_to_render[self.ACTION_KEY] = '/burst/set_monitors' dict_to_render[ self.PREVIOUS_ACTION_KEY] = '/burst/set_integrator_params' dict_to_render[self.IS_COPY] = is_simulator_copy dict_to_render[self.IS_LOAD] = is_simulator_load return dict_to_render
def integrator_parameters_changed(self, dynamic_gid, type, **param): dynamic = self.get_cached_dynamic(dynamic_gid) integrator = dynamic.integrator changed_params = list(param.keys()) if type == SubformHelper.FormToConfigEnum.INTEGRATOR.name: integrator_form_class = get_form_for_integrator(integrator.__class__) integrator_form = integrator_form_class() integrator_form.fill_from_post(param) integrator_form.fill_trait_partially(integrator, changed_params) if type == SubformHelper.FormToConfigEnum.NOISE.name: noise_form_class = get_form_for_noise(integrator.noise.__class__) noise_form = noise_form_class() noise_form.fill_from_post(param) noise_form.fill_trait_partially(integrator.noise, changed_params) if type == SubformHelper.FormToConfigEnum.EQUATION.name: eq_form_class = get_form_for_equation(integrator.noise.b.__class__) eq_form = eq_form_class() eq_form.fill_from_post(param) eq_form.fill_trait_partially(integrator.noise.b, changed_params) self._update_integrator(dynamic, integrator)
def set_noise_params(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_noise( type(session_stored_simulator.integrator.noise))() form.fill_from_post(data) form.fill_trait(session_stored_simulator.integrator.noise) if isinstance(session_stored_simulator.integrator.noise, Additive): monitor_fragment = SimulatorMonitorFragment( '', common.get_current_project().id) monitor_fragment.fill_from_trait(session_stored_simulator) dict_to_render = copy.deepcopy(self.dict_to_render) dict_to_render[self.FORM_KEY] = monitor_fragment dict_to_render[self.ACTION_KEY] = '/burst/set_monitors' dict_to_render[ self.PREVIOUS_ACTION_KEY] = '/burst/set_noise_params' dict_to_render[self.IS_COPY] = is_simulator_copy dict_to_render[self.IS_LOAD] = is_simulator_load return dict_to_render equation_form = get_form_for_equation( type(session_stored_simulator.integrator.noise.b))() equation_form.equation.data = session_stored_simulator.integrator.noise.b.__class__.__name__ dict_to_render = copy.deepcopy(self.dict_to_render) dict_to_render[self.FORM_KEY] = equation_form dict_to_render[self.ACTION_KEY] = '/burst/set_noise_equation_params' dict_to_render[self.PREVIOUS_ACTION_KEY] = '/burst/set_noise_params' dict_to_render[self.IS_COPY] = is_simulator_copy dict_to_render[self.IS_LOAD] = is_simulator_load return dict_to_render