Пример #1
0
    def _process_command_queue(self, data_state):
        """
        Process the command queue sequentially as FIFO structure

        @param data_state: the data state.
        @return: a SANSState object.
        """
        file_name = data_state.sample_scatter
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            file_name)

        # If we have a clean instruction in there, then we should apply it to all commands
        self._apply_clean_if_required()

        # Evaluate all commands which adds them to the _processed_state_settings dictionary,
        # except for DataCommands which we deal with separately
        for command in self._commands:
            if isinstance(command, DataCommand):
                continue
            command_id = command.command_id
            process_function = self._method_map[command_id]
            process_function(command)

        user_commands = CommandInterfaceAdapter(
            data_info=data_state,
            processed_state=self._processed_state_settings)
        run_data_parser = StateRunDataBuilder(
            file_information=file_information)

        self._state_director = StateBuilder(i_state_parser=user_commands,
                                            run_data_builder=run_data_parser)
        return self._state_director.get_all_states()
Пример #2
0
    def _process_command_queue(self):
        """
        Process the command queue sequentially as FIFO structure

        @param data_state: the data state.
        @return: a SANSState object.
        """
        file_name = self._data_info.sample_scatter
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            file_name)

        # If we have a clean instruction in there, then we should apply it to all commands
        self._apply_clean_if_required()

        # Evaluate all commands which adds them to the _processed_state_settings dictionary,
        # except for DataCommands which we deal with separately
        for command in self._commands:
            if isinstance(command, DataCommand):
                continue

            command_id = command.command_id
            if NParameterCommandId.USER_FILE in command_id:
                self._processed_state_obj = self._process_user_file(
                    command, file_information=file_information)
                continue

            process_function = self._method_map[command_id]
            process_function(command)

        state_builder_adapter = CommandInterfaceAdapter(
            file_information=file_information,
            processed_state=self._processed_state_settings,
            existing_state_obj=self._processed_state_obj)
        states = state_builder_adapter.get_all_states(
            file_information=file_information)
        states.data = self._data_info
        return states
Пример #3
0
    def _process_user_file(self, command, file_information):
        """
        Processes a user file and retain the parased tags

        @param command: the command with the user file path
        """
        file_name = command.values[0]

        if file_name.casefold().endswith(".toml".casefold()):
            toml_file_reader = TomlParser()
            new_state_entries = toml_file_reader.parse_toml_file(
                toml_file_path=file_name, file_information=file_information)
        else:
            # Now comes the fun part where we try to coerce this to put out a State* object
            user_file_reader = UserFileReader(file_name)
            old_param_mapping = user_file_reader.read_user_file()
            command_adapter = CommandInterfaceAdapter(
                processed_state=old_param_mapping,
                file_information=file_information)
            new_state_entries = command_adapter.get_all_states(
                file_information=file_information)

        new_state_entries.data = self._data_info
        return new_state_entries
Пример #4
0
    def create_state(self, row_entry, file_lookup=True, user_file=""):
        # 1. Get the data settings, such as sample_scatter, etc... and create the data state.
        if file_lookup:
            file_information = row_entry.file_information
        else:
            file_information = SANSFileInformationBlank()

        data_builder = get_data_builder(self._facility, file_information)

        self._set_data_entry(data_builder.set_sample_scatter,
                             row_entry.sample_scatter)
        self._set_data_period_entry(data_builder.set_sample_scatter_period,
                                    row_entry.sample_scatter_period)
        self._set_data_entry(data_builder.set_sample_transmission,
                             row_entry.sample_transmission)
        self._set_data_period_entry(
            data_builder.set_sample_transmission_period,
            row_entry.sample_transmission_period)  # noqa
        self._set_data_entry(data_builder.set_sample_direct,
                             row_entry.sample_direct)
        self._set_data_period_entry(data_builder.set_sample_direct_period,
                                    row_entry.sample_direct_period)
        self._set_data_entry(data_builder.set_can_scatter,
                             row_entry.can_scatter)
        self._set_data_period_entry(data_builder.set_can_scatter_period,
                                    row_entry.can_scatter_period)
        self._set_data_entry(data_builder.set_can_transmission,
                             row_entry.can_transmission)
        self._set_data_period_entry(data_builder.set_can_transmission_period,
                                    row_entry.can_transmission_period)
        self._set_data_entry(data_builder.set_can_direct, row_entry.can_direct)
        self._set_data_period_entry(data_builder.set_can_direct_period,
                                    row_entry.can_direct_period)

        data = data_builder.build()

        # 2. Add elements from the options column
        state_gui_model = copy.deepcopy(self._state_gui_model)
        self._apply_column_options_to_state(row_entry, state_gui_model)

        # 3. Add other columns
        output_name = row_entry.output_name
        if output_name:
            state_gui_model.output_name = output_name

        if row_entry.sample_thickness:
            state_gui_model.sample_thickness = float(
                row_entry.sample_thickness)
        if row_entry.sample_height:
            state_gui_model.sample_height = float(row_entry.sample_height)
        if row_entry.sample_width:
            state_gui_model.sample_width = float(row_entry.sample_width)
        if row_entry.sample_shape:
            state_gui_model.sample_shape = row_entry.sample_shape

        # 4. Create the rest of the state based on the builder.
        settings = copy.deepcopy(state_gui_model.settings)
        command_interface = CommandInterfaceAdapter(data_info=data,
                                                    processed_state=settings)
        run_data_builder = StateRunDataBuilder(
            file_information=file_information)

        state = StateBuilder(
            run_data_builder=run_data_builder,
            i_state_parser=command_interface).get_all_states()
        return state
Пример #5
0
 def create_model(user_file, file_information=None):
     adapter = CommandInterfaceAdapter(file_information=file_information,
                                       processed_state=user_file)
     model_under_test = SettingsAdjustmentModel(
         adapter.get_all_states(file_information=file_information))
     return model_under_test