Esempio n. 1
0
 def square_text(self, text: str, text_alignment="^") -> None:
     w = self.width - 2 * self._wall_len()
     if not self.started:
         self.started = True
         self.buffer.append(create_line(self.roof_str, self.width))
     else:
         self.buffer.append(
             f"{self.wall_str}{create_line(width=w)}{self.wall_str}")
     self.seperate()
     self.write_text(text, text_alignment=text_alignment)
     self.seperate()
     self.buffer.append(
         f"{self.wall_str}{create_line(width=w)}{self.wall_str}")
Esempio n. 2
0
 def write_text(self,
                text: str,
                text_alignment="<",
                colorizer=None) -> None:
     if not self.started:
         self.buffer.append(create_line(self.roof_str, self.width))
         self.started = True
     self.buffer.append(
         wall_text(text,
                   self.width,
                   self.wall_str,
                   text_alignment=text_alignment,
                   h_padding=self.padding_h,
                   colorizer=colorizer))
Esempio n. 3
0
 def _create_columns(self):
     ch = self.get_column_header()
     t_width = self._text_width()
     if ch.strip() != "":
         self.write_line(ch)
     for row in self.rows:
         l = create_line(".", t_width, row.text)
         for column in self.columns:
             if column in row.marks:
                 l += center_on(row.marks[column],
                                u"[{}]".format(column)) + " "
             else:
                 l += center_on(self.fail_char,
                                u"[{}]".format(column)) + " "
         self.write_line(l[0:self.width])
     enable_stats, stats = self.get_statistics(t_width)
     if enable_stats:
         self.write_line(stats)
Esempio n. 4
0
    def get_statistics(self, text_column_width):
        res = ""
        show_statistics = len(self.columns) > 0
        if show_statistics:
            count = len(self.rows)
            ccounts = defaultdict(int)
            for row in self.rows:
                for column in self.columns:
                    if column in row.marks:
                        if row.marks[column] != self.fail_char:
                            ccounts[column] += 1

            if len(self.columns) > 0:
                res += u"{}".format(
                    create_line(" ", text_column_width, "Statistics:"))
            for c in self.columns:
                text = u"{:.2f}%".format((float(100) / count) * ccounts[c])
                res += center_on(text, u"[{}]".format(c)) + u" "
        return show_statistics, res[0:self.width]
Esempio n. 5
0
 def write_output(self, print_func=print) -> None:
     for line in self.buffer:
         print_func(line)
     print_func(create_line(self.roof_str, self.width))