Пример #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()
Пример #2
0
    def add_picture(self):
        """
        Add max. 3 pictures to the chapter.
        """

        captions = self.picture_captions
        picture_name = self.picture_name

        # add pictures that correspond to the given picture file names with the corresponding captions
        for i in range(0, 3):
            Picture.add_picture_and_caption(self.report,
                                            self.picture_paths,
                                            picture_name + str(i + 1),
                                            captions[i],
                                            width=Cm(10))
    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()
    def add_picture(self) -> bool:
        """
        Load a picture from the input files and add it to the report.

        The longest side (height or width) is set to 14 cm and the ratio is kept.
        The picture is added in the center regarding the side margin and spacing at the top and the bottom
        of the picture is set according to the height.

        Returns:
            True if a picture was added, and False if not.
        """

        # find the files that correspond to the picture file name
        for picture_path in self.picture_paths:
            if self.PICTURE_NAME in picture_path:

                try:
                    picture = Image.open(picture_path)

                    # find the longest side and set it to 14 cm when adding the picture
                    # case where the width is the longest side
                    if picture.width >= picture.height:

                        # set the spacing before and after the picture according the height/width ratio
                        if picture.height / picture.width * 14 < 5:
                            space = Cm(5)
                        elif picture.height / picture.width * 14 < 10:
                            space = Cm(3)
                        elif picture.height / picture.width * 14 < 14:
                            space = Cm(1)

                        # add the picture and its caption
                        Picture.add_picture_and_caption(
                            self.report,
                            self.picture_paths,
                            self.PICTURE_NAME,
                            self.picture_caption,
                            width=self.PICTURE_WIDTH,
                            space_before=space,
                            space_after=space)

                    # case where the height is the longest side
                    else:
                        # spacing before and after the picture is always 1 cm because height is always 14 cm
                        space = Cm(1)

                        # add the picture and its caption
                        Picture.add_picture_and_caption(
                            self.report,
                            self.picture_paths,
                            self.PICTURE_NAME,
                            self.picture_caption,
                            width=self.PICTURE_WIDTH,
                            space_before=space,
                            space_after=space)

                    # terminate because a picture was added and return True
                    return True

                # do nothing if the file is not an image
                except UnidentifiedImageError:
                    pass

        # return False because no picture was added
        return False