Ejemplo n.º 1
0
    def write_chapter(self):
        """
        Write the whole chapter 'Transitions', including plot.
        """

        decision_table_index = self.tables.index(self.DECISION_TABLE)
        decision = DropDownLists.get_from_table(self.text_input_soup,
                                                decision_table_index)

        if decision[0] == 'Yes':
            self.makes_plot()

            transitions = ResultsChapter(self.report, self.text_input,
                                         self.text_input_soup, self.TITLE,
                                         self.tables, self.picture_paths,
                                         self.parameters)

            self.report.add_paragraph(self.TITLE, self.TITLE_STYLE)

            try:
                Picture.add_picture_and_caption(self.report,
                                                [self.HEAT_MAP_FIGURE_PATH],
                                                self.HEAT_MAP_FIGURE_PATH,
                                                self.CAPTION,
                                                width=Cm(12))
            except FileNotFoundError:  # do nothing if no cGOM data is provided
                pass

            self.report.add_paragraph(self.DISCUSSION_TITLE,
                                      self.DISCUSSION_STYLE)
            transitions.write_chapter()
Ejemplo n.º 2
0
    def standard_wanted_terms(self, standard_name: str) -> List[str]:
        """
        Args:
            standard_name: Name of the standard of which we want the terms that have to be defined.

        Returns:
            List of all terms that have to be defined for this standard.
        """

        # select the table that have the information for this standard
        for table_index, table in enumerate(self.list_of_tables):
            if standard_name in table:

                # create a list of 'Yes' or 'No' stored in dropdown lists in the table of this standard
                list_of_yes_no = DropDownLists.get_from_table(
                    self.text_input_soup, table_index)

                # create a list of all possible terms that can be defined in this standard
                list_of_terms = []
                for row in self.text_input.tables[table_index].rows:
                    for cell in row.cells:
                        if cell.text:
                            list_of_terms.append(cell.text)

                # create a list of all terms that have to be defined for this standard
                list_of_defined_terms = []
                for index, term in enumerate(list_of_terms):
                    if list_of_yes_no[index] == 'Yes':
                        list_of_defined_terms.append(term)

                return list_of_defined_terms
    def chapter_parameters(self) -> List[str]:
        """
        Returns:
            List of parameters needed to be writen in the chapter.
        """

        return DropDownLists.get_from_table(self.text_input_soup,
                                            self.tables.index('{} parameter table'.format(self.title))
                                            )
    def plot_type(self) -> str:
        """
        Returns:
            Dropdown list value of the parameter table corresponding to the plot type,
            i.e. 'Bar plot' or 'Box plot'.
        """

        plot_type_list = DropDownLists.get_from_table(
            self.text_input_soup, self.tables.index(self.PLOT_TYPE_TABLE))
        return plot_type_list[0]
    def write_chapter(self):
        """
        Write the whole chapter 'Average fixation', including the chosen plot.
        """

        decision_table_index = self.tables.index(self.DECISION_TABLE)
        decision = DropDownLists.get_from_table(self.text_input_soup,
                                                decision_table_index)

        if decision[0] == 'Yes':
            self.make_plots()

            time_on_tasks = ResultsChapter(self.report, self.text_input,
                                           self.text_input_soup, self.TITLE,
                                           self.tables, self.picture_paths,
                                           self.parameters)

            self.report.add_paragraph(self.TITLE, self.TITLE_STYLE)

            # add bar plot or box plot depending on the choice of plot type or do nothing if no cGOM data is provided
            try:
                if self.plot_type == 'Bar plot':
                    Picture.add_picture_and_caption(
                        self.report, [self.BAR_PLOT_FIGURE_PATH],
                        self.BAR_PLOT_FIGURE_PATH,
                        self.BAR_PLOT_CAPTION,
                        width=Cm(12))
                if self.plot_type == 'Box plot':
                    Picture.add_picture_and_caption(
                        self.report, [self.BOX_PLOT_FIGURE_PATH],
                        self.BOX_PLOT_FIGURE_PATH,
                        self.BOX_PLOT_CAPTION,
                        width=Cm(12))
            except FileNotFoundError:
                pass

            self.report.add_paragraph(self.DISCUSSION_TITLE,
                                      self.DISCUSSION_STYLE)
            time_on_tasks.write_chapter()
Ejemplo n.º 6
0
    def get_from_problems_table(self):
        """
        Read the parameters from the problems table and stored them in the dictionary.

        The problems table differs from the standard table because it has 3 columns and contains dropdown lists.
        """

        problems_table_index = self.tables.index(self.PROBLEMS_TABLE)
        problems_table = self.text_input.tables[problems_table_index]
        problem_types = DropDownLists.get_from_table(self.text_input_soup,
                                                     problems_table_index)

        # return the index of a row when nothing was written in it to get the number of problems
        problems_number = 0
        for idx, problem_type in enumerate(problem_types):
            if '-' in problem_type:
                problems_number = idx
                break

        self.dictionary['Number of problems'] = problems_number

        # cells are not recognized as cells by word if they contain a dropdown list,
        # so here is a work around to get the values

        # list of the text of all cells, except those ones containing dropdown list
        list_of_text = []

        # stores the text of every relevant cell in the list
        if problems_number != 0:
            stop = False
            while not stop:
                for i in range(1, problems_number + 1):
                    for cell in problems_table.rows[i].cells:
                        text = cell.text
                        if text or len(list_of_text) == (problems_number *
                                                         2) - 1:
                            list_of_text.append(text)
                        else:
                            list_of_text.pop()
                            stop = True

        # delete the last item to ensure that there is no key without a corresponding value
        if len(list_of_text) % 2 != 0:
            list_of_text.pop()

        value = 0

        # stores the keys and corresponding values in the dictionary
        for i in range(len(list_of_text)):

            # the problem number appears every two items
            if i % 2 == 0:

                # problem types
                problem_number = list_of_text[i]
                type_key = problem_number + ' type'
                self.dictionary[type_key] = problem_types[value]

                # problem descriptions
                description = list_of_text[i + 1]
                description_key = problem_number + ' description'
                self.dictionary[description_key] = description

                value += 1
def main():

    main_start = time.time()

    # file name of the report
    report_file = 'Report.docx'

    # create the report document
    report = Document()

    # path of the input files
    text_input_path = 'Inputs/Text_input_form.docx'
    definitions_path = 'Inputs/Terms_definitions.docx'

    # load text input files with python-docx
    text_input = Document(text_input_path)
    definitions = Document(definitions_path)

    # path to the pictures that must be added to the report
    picture_paths = Picture.get_picture_paths()

    # soup of the text input form document
    text_input_soup = DropDownLists.get_soup(text_input_path)

    # list of all tables in the order they appear in the text input document,
    # this is used to get the index of a table in the document
    tables = [
        'Study table', 'Title table', 'Approval table',
        'Cover page caption table', 'Header table', 'Purpose text table',
        'Purpose parameter table', 'Purpose caption table',
        'Background text table', 'Background parameter table',
        'Background caption table', 'Scope text table',
        'Scope parameter table', 'Scope caption table',
        'EU Regulation 2017/745 definitions table',
        'IEC 62366-1 definitions table', 'FDA Guidance definitions table',
        'Ethics statement text table', 'Ethics statement parameter table',
        'Ethics statement caption table', 'Device specifications text table',
        'Device specifications parameter table',
        'Device specifications caption table', 'Goal text table',
        'Goal parameter table', 'Goal caption table',
        'Participants text table', 'Participants parameter table',
        'Participants caption table', 'Use environment text table',
        'Use environment parameter table', 'Use environment caption table',
        'Use scenarios text table', 'Use scenarios parameter table',
        'Use scenarios caption table', 'Setup text table',
        'Setup parameter table', 'Setup caption table',
        'Critical tasks description table',
        'Effectiveness analysis decision table',
        'Effectiveness analysis tasks and problems table',
        'Effectiveness analysis problem type table',
        'Effectiveness analysis text table',
        'Effectiveness analysis parameter table',
        'Effectiveness analysis caption table', 'Time on tasks decision table',
        'Time on tasks plot type table', 'Time on tasks table',
        'Time on tasks text table', 'Time on tasks parameter table',
        'Time on tasks caption table',
        'Dwell times and revisits decision table',
        'Dwell times and revisits text table',
        'Dwell times and revisits parameter table',
        'Dwell times and revisits caption table',
        'Average fixation decision table', 'Average fixation plot type table',
        'Average fixation text table', 'Average fixation parameter table',
        'Average fixation caption table', 'Transitions decision table',
        'Transitions text table', 'Transitions parameter table',
        'Transitions caption table', 'Conclusion text table',
        'Conclusion parameter table', 'Conclusion caption table',
        'Participants characteristics table'
    ]

    # parameters needed to write the report
    parameters = Parameters.get_all(text_input, text_input_soup, tables)

    # list of data frames that contain the cGOM data
    cGOM_dataframes = cGOM.make_dataframes_list()

    # data frame that contain the Tobii data
    tobii_data = TobiiData.make_main_dataframe(parameters)

    # define all styles used in the document
    Layout.define_all_styles(report)

    ######   COVER PAGE   ######

    section1 = report.sections[0]
    Layout.define_page_format(section1)

    cover_page_start = time.time()
    cover_page = CoverPage(report, text_input, tables, picture_paths,
                           parameters)
    cover_page.create()
    '''
    cover_page_end = time.time()
    print('Cover page added in %.2f seconds' % (cover_page_end - cover_page_start))
    '''

    ######   TABLE OF CONTENT   ######

    report.add_page_break()

    TableOfContent.write(report)

    ######   CHAPTERS   ######

    section2 = report.add_section(WD_SECTION.NEW_PAGE)
    Layout.define_page_format(section2)

    footer = Footer(section2)
    footer.write()

    header = Header(section2, parameters)
    header.write()

    purpose = Chapter(report, text_input, text_input_soup, 'Purpose', tables,
                      picture_paths, parameters)
    purpose.write_chapter()

    background = Chapter(report, text_input, text_input_soup, 'Background',
                         tables, picture_paths, parameters)
    background.write_chapter()

    scope = Chapter(report, text_input, text_input_soup, 'Scope', tables,
                    picture_paths, parameters)
    scope.write_chapter()

    Definitions.write_all_definitions(report, text_input, text_input_soup,
                                      definitions, tables)

    ethics = Chapter(report, text_input, text_input_soup, 'Ethics statement',
                     tables, picture_paths, parameters)
    ethics.write_chapter()

    device = Chapter(report, text_input, text_input_soup,
                     'Device specifications', tables, picture_paths,
                     parameters)
    device.write_chapter()

    report.add_paragraph('Test procedure', 'Heading 1')

    goal = Chapter(report, text_input, text_input_soup, 'Goal', tables,
                   picture_paths, parameters)
    goal.write_chapter()

    participants = Chapter(report, text_input, text_input_soup, 'Participants',
                           tables, picture_paths, parameters)
    participants.write_chapter()

    environment = Chapter(report, text_input, text_input_soup,
                          'Use environment', tables, picture_paths, parameters)
    environment.write_chapter()

    scenarios = UseScenarios(report, text_input, text_input_soup,
                             'Use scenarios', tables, picture_paths,
                             parameters)
    scenarios.write_chapter()

    setup = Chapter(report, text_input, text_input_soup, 'Setup', tables,
                    picture_paths, parameters)
    setup.write_chapter()

    report.add_paragraph('Results', 'Heading 1')

    start1 = time.time()
    effectiveness_analysis = EffectivenessAnalysis(report, text_input,
                                                   text_input_soup, tables,
                                                   picture_paths, parameters)
    effectiveness_analysis.write_chapter()
    end1 = time.time()
    print('Effectiveness analysis: ', end1 - start1)

    start2 = time.time()
    time_on_tasks = TimeOnTasks(report, text_input, text_input_soup, tables,
                                picture_paths, parameters, tobii_data)
    time_on_tasks.write_chapter()
    end2 = time.time()
    print('Time on tasks: ', end2 - start2)

    start3 = time.time()
    dwell_times_and_revisits = DwellTimesAndRevisits(report, text_input,
                                                     text_input_soup, tables,
                                                     picture_paths, parameters,
                                                     cGOM_dataframes)
    dwell_times_and_revisits.write_chapter()
    end3 = time.time()
    print('Dwell times: ', end3 - start3)

    start4 = time.time()
    average_fixation = AverageFixation(report, text_input, text_input_soup,
                                       tables, picture_paths, parameters,
                                       cGOM_dataframes)
    average_fixation.write_chapter()
    end4 = time.time()
    print('Average fixation: ', end4 - start4)

    start5 = time.time()
    transitions = Transitions(report, text_input, text_input_soup, tables,
                              picture_paths, parameters, cGOM_dataframes)
    transitions.write_chapter()
    end5 = time.time()
    print('Transitions: ', end5 - start5)

    conclusion = Chapter(report, text_input, text_input_soup, 'Conclusion',
                         tables, picture_paths, parameters)
    conclusion.write_chapter()

    DocumentHistory.write(report)

    ######   APPENDIX   ######

    report.add_page_break()

    report.add_paragraph('Appendix', 'Heading 1')

    Definitions.write_references(report, text_input, text_input_soup,
                                 definitions, tables)

    report.add_page_break()

    Picture.add_figures_list(report)

    report.add_page_break()

    ParticipantsCharacteristics.write(report, text_input, tables, parameters)

    # save the report
    report.save(report_file)

    # error message for the image files that were not added to the report
    '''Picture.error_message(picture_paths)'''

    start6 = time.time()
    # update the table of content
    update(report_file)
    end6 = time.time()
    print('Update: ', end6 - start6)

    # open the report with the default application for .docx (Word)
    os.startfile(report_file)

    end = time.time()
    print(end - main_start)