diff --git a/parse_test_results.py b/parse_test_results.py index 30c1393e6cd4000506447599f5360e1f65f54148..a1b36340816c246007618843499afaad0f897669 100644 --- a/parse_test_results.py +++ b/parse_test_results.py @@ -60,9 +60,9 @@ class TestOutputParser: excel_writer = ExcelWriter(self.output_file) for entry in self.test_entries: excel_writer.write_test_entry(entry) - + # Write chart - excel_writer.write_pie_chart() + excel_writer.write_pie_chart_data() # And finally, save the work book excel_writer.save() diff --git a/write_excel.py b/write_excel.py index be7ca930486da407b0610d389bfb7df9540a1195..1591275ffc04ca33f6a0eae0b067df32a175192a 100644 --- a/write_excel.py +++ b/write_excel.py @@ -79,7 +79,7 @@ class ExcelWriter: work_book = Workbook() init_workbook(work_book) return work_book - + def get_chart_work_sheet(self): """ Returns work sheet where charts will be drawn to. @@ -90,43 +90,54 @@ class ExcelWriter: return chart_work_sheet except KeyError: return self.work_book.create_sheet("charts") - + def write_pie_chart_data(self): """ Writes pie chart data (the charts sheet) required to construct the pie chart later """ chart_work_sheet = self.get_chart_work_sheet() + # Format data from main work sheet and insert into charts sheet + + # Titles + chart_work_sheet["A2"] = "PASS" + chart_work_sheet["A3"] = "FAIL" + + #Data + data = self.get_pass_fail_counts() + chart_work_sheet.cell(row=2, column=2).value = data[0] + chart_work_sheet.cell(row=3, column=2).value = data[1] + # Get data from main work sheet - last_row = self.get_last_row() - data = Reference(self.work_sheet, min_col=3, max_col=3, min_row=2, max_row=last_row) + data = Reference(chart_work_sheet, min_col=2, max_col=2, min_row=2, max_row=3) + labels = Reference(chart_work_sheet, min_col=1, max_col=1, min_row=2, max_row=3) # Construct pie chart pie = PieChart() - pie.add_data(data, titles_from_data=True) - #pie.set_categories(labels) + pie.add_data(data)#, titles_from_data=True) + pie.set_categories(labels) pie.title = "PASS/FAIL Distribution" - chart_work_sheet.add_chart(pie, "A1") - - def write_pie_chart(self): + chart_work_sheet.add_chart(pie, "E1") + + def get_pass_fail_counts(self): """ - Writes a pie chart showing PASS/FAIL stats. - Writes the chart to a separate work sheet. + Return PASS/FAIL stats as tuple (# of PASS, # of FAIL) """ - chart_work_sheet = self.get_chart_work_sheet() # Get data from main work sheet last_row = self.get_last_row() - data = Reference(self.work_sheet, min_col=3, max_col=3, min_row=2, max_row=last_row) - - # Construct pie chart - pie = PieChart() - pie.add_data(data, titles_from_data=True) - #pie.set_categories(labels) - pie.title = "PASS/FAIL Distribution" - - chart_work_sheet.add_chart(pie, "A1") + pass_count = 0 + fail_count = 0 + for row in self.work_sheet.iter_rows(min_col=3, max_col=3, min_row=2, max_row=last_row - 1): + for cell in row: + if cell.value == "PASS": + pass_count += 1 + elif cell.value == "FAIL": + fail_count += 1 + else: + print("ERROR: unknown value {}".format(cell.value)) + return (pass_count, fail_count) def save(self): """