def run(self, variables: dict): '''Print back system graphs if log volume has changed significantly.''' start_time = variables.get('start_time', None) end_time = variables.get('end_time', None) max_width = variables.get('MaxPluginOutputWidth', None) file_line_counts = self.get_line_counts(start_time, end_time) g = Grapher() result = '' for file_path, timestamped_values in file_line_counts: if not timestamped_values: continue values = [value for timestamp, value in timestamped_values.items()] if not fossor.utils.anomaly_detection.abnormal_distribution( values, ignore_zero=True): continue if statistics.mean(values) < 10: continue graph = g.asciigraph(values=timestamped_values, max_width=max_width, max_height=7, label=True) tmp = f"{file_path}:\n{graph}" result = '\n'.join([result, tmp]) return result
def test_draw_graph_with_labels(): g = Grapher() values = [x % 3 for x in range(100)] non_graph_lines = 3 # 1 extra line above the graph, 2 extra lines below the graph for height in range(20, 30): for width in range(70, 100): graph = g.asciigraph(values=values, max_height=height, max_width=width, label=True) graph_split = graph.splitlines() assert len(graph_split) - non_graph_lines == height assert 'Upper value' in graph assert '***' in graph assert 'Mean' in graph assert 'Std Dev' in graph for line in graph.splitlines(): assert len(line) == width