| 20 | |
| 21 | |
| 22 | class DashGraph(object): |
| 23 | def __init__(self, graph_elem, starting_count, color): |
| 24 | self.graph_current_item = 0 |
| 25 | self.graph_elem = graph_elem # type:sg.Graph |
| 26 | self.prev_value = starting_count |
| 27 | self.max_sent = 1 |
| 28 | self.color = color |
| 29 | self.graph_lines = [] |
| 30 | |
| 31 | def graph_value(self, current_value): |
| 32 | delta = current_value - self.prev_value |
| 33 | self.prev_value = current_value |
| 34 | self.max_sent = max(self.max_sent, delta) |
| 35 | percent_sent = 100 * delta / self.max_sent |
| 36 | line_id = self.graph_elem.draw_line((self.graph_current_item, 0), (self.graph_current_item, percent_sent), color=self.color) |
| 37 | self.graph_lines.append(line_id) |
| 38 | if self.graph_current_item >= GRAPH_WIDTH: |
| 39 | self.graph_elem.delete_figure(self.graph_lines.pop(0)) |
| 40 | self.graph_elem.move(-1, 0) |
| 41 | else: |
| 42 | self.graph_current_item += 1 |
| 43 | return delta |
| 44 | |
| 45 | def graph_percentage_abs(self, value): |
| 46 | self.graph_elem.draw_line((self.graph_current_item, 0), (self.graph_current_item, value), color=self.color) |
| 47 | if self.graph_current_item >= GRAPH_WIDTH: |
| 48 | self.graph_elem.move(-1, 0) |
| 49 | else: |
| 50 | self.graph_current_item += 1 |
| 51 | |
| 52 | |
| 53 | def human_size(bytes, units=(' bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB')): |