Пример #1
0
    def set_model_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:
            self.context.add_last_loaded_form_url_to_session(
                SimulatorWizzardURLs.SET_INTEGRATOR_URL)
            form = get_form_for_model(type(
                session_stored_simulator.model))(is_branch)

            if is_branch:
                data['variables_of_interest'] = list(
                    session_stored_simulator.model.variables_of_interest)

            form.fill_from_post(data)
            form.fill_trait(session_stored_simulator.model)

        integrator_fragment = self.algorithm_service.prepare_adapter_form(
            form_instance=SimulatorIntegratorFragment())
        integrator_fragment.integrator.display_subform = False
        integrator_fragment.fill_from_trait(session_stored_simulator)

        rendering_rules = SimulatorFragmentRenderingRules(
            integrator_fragment,
            SimulatorWizzardURLs.SET_INTEGRATOR_URL,
            SimulatorWizzardURLs.SET_MODEL_PARAMS_URL,
            is_simulation_copy,
            is_simulation_load,
            self.context.last_loaded_fragment_url,
            cherrypy.request.method,
            is_branch=is_branch)
        return rendering_rules.to_dict()
Пример #2
0
    def set_model(self, **data):
        session_stored_simulator, is_simulation_copy, is_simulation_load, is_branch = self.context.get_common_params(
        )

        if cherrypy.request.method == POST_REQUEST:
            set_next_wizard = True
            if SimulatorController.KEY_KEEP_SAME_SIM_WIZARD in data:
                set_next_wizard = False
            if set_next_wizard:
                self.context.add_last_loaded_form_url_to_session(
                    SimulatorWizzardURLs.SET_MODEL_PARAMS_URL)
            form = SimulatorModelFragment()
            form.fill_from_post(data)
            form.fill_trait(session_stored_simulator)

        form = self.algorithm_service.prepare_adapter_form(
            form_instance=get_form_for_model(
                type(session_stored_simulator.model))(is_branch))
        self.range_parameters.model_parameters = form.get_range_parameters()
        form.fill_from_trait(session_stored_simulator.model)

        rendering_rules = SimulatorFragmentRenderingRules(
            form, SimulatorWizzardURLs.SET_MODEL_PARAMS_URL,
            SimulatorWizzardURLs.SET_MODEL_URL, is_simulation_copy,
            is_simulation_load, self.context.last_loaded_fragment_url,
            cherrypy.request.method)
        return rendering_rules.to_dict()
Пример #3
0
    def submit(self, dynamic_gid, dynamic_name):
        if dao.get_dynamic_by_name(dynamic_name):
            return {'saved': False, 'msg': 'There is another configuration with the same name'}

        dynamic = self.get_cached_dynamic(dynamic_gid)
        model = dynamic.model
        integrator = dynamic.integrator

        model_parameters = []

        model_form_class = get_form_for_model(type(model))
        for name in model_form_class.get_params_configurable_in_phase_plane():
            value = getattr(model, name)[0]
            model_parameters.append((name, value))

        entity = model_burst.Dynamic(
            dynamic_name,
            common.get_logged_user().id,
            model.__class__.__name__,
            json.dumps(model_parameters, cls=TVBJSONEncoder),
            integrator.__class__.__name__,
            None
            # todo: serialize integrator parameters
            # json.dumps(integrator.raw_ui_integrator_parameters)
        )

        dao.store_entity(entity)
        return {'saved': True}
    def _get_model_parameters_ui_model(model):
        """
        For each model parameter return the representation used by the ui (template & js)
        """
        ret = []
        model_form_class = get_form_for_model(type(model))
        for name in model_form_class.get_params_configurable_in_phase_plane():
            attr = getattr(type(model), name)
            ranger = attr.domain
            if ranger is None:
                DynamicModelController.LOGGER.warning(
                    "Param %s doesn't have a domain specified" % (name))
                continue
            default = float(attr.default)

            ret.append({
                'name': name,
                'label': attr.label,
                'description': attr.doc,
                'min': ranger.lo,
                'max': ranger.hi,
                'step': ranger.step,
                'default': default
            })
        return ret
Пример #5
0
    def set_model_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_model(type(session_stored_simulator.model))()
            form.fill_from_post(data)
            form.fill_trait(session_stored_simulator.model)

        integrator_fragment = SimulatorIntegratorFragment(
            '',
            common.get_current_project().id)
        integrator_fragment.fill_from_trait(session_stored_simulator)

        dict_to_render = copy.deepcopy(self.dict_to_render)
        dict_to_render[self.FORM_KEY] = integrator_fragment
        dict_to_render[self.ACTION_KEY] = '/burst/set_integrator'
        dict_to_render[self.PREVIOUS_ACTION_KEY] = '/burst/set_model_params'
        dict_to_render[self.IS_COPY] = is_simulator_copy
        dict_to_render[self.IS_LOAD] = is_simulator_load
        return dict_to_render
Пример #6
0
    def set_model(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 = SimulatorModelFragment()
            form.fill_from_post(data)
            session_stored_simulator.model = form.model.value()

        form = get_form_for_model(type(session_stored_simulator.model))()
        self.range_parameters.model_parameters = form.get_range_parameters()
        form.fill_from_trait(session_stored_simulator.model)

        dict_to_render = copy.deepcopy(self.dict_to_render)
        dict_to_render[self.FORM_KEY] = form
        dict_to_render[self.ACTION_KEY] = '/burst/set_model_params'
        dict_to_render[self.PREVIOUS_ACTION_KEY] = '/burst/set_model'
        dict_to_render[self.IS_COPY] = is_simulator_copy
        dict_to_render[self.IS_LOAD] = is_simulator_load
        return dict_to_render