Skip to content
Snippets Groups Projects
Commit c46f0478 authored by brydenf's avatar brydenf
Browse files

WIP to include pie chart in separate work sheet

parent 79519070
No related branches found
No related tags found
1 merge request!1Charts
......@@ -19,16 +19,15 @@ class TestOutputParser:
"""
def __init__(self, input_file, output_file):
self.test_entries = []
self.load_file(input_file)
self.api = ""
self.output_file = output_file
self.robot_file_contents = ""
self.load_file(input_file)
def load_file(self, fname):
"""
Load xml file
"""
with open(fname, "r", encoding="utf8") as robot_file:
self.robot_file_contents = robot_file.read()
......@@ -40,6 +39,7 @@ class TestOutputParser:
"""
Run parser, extracting all info to create the test entries
"""
soup = BeautifulSoup(self.robot_file_contents, "lxml")
# Suite information
......@@ -60,6 +60,11 @@ 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()
# And finally, save the work book
excel_writer.save()
def create_test_entry(self, xml_obj):
......
......@@ -6,6 +6,7 @@ from openpyxl import Workbook, load_workbook
from openpyxl.utils import get_column_letter
from openpyxl.styles import Font
from openpyxl.styles.fills import PatternFill
from openpyxl.chart import PieChart, Reference
class ExcelWriter:
"""
......@@ -15,9 +16,9 @@ class ExcelWriter:
PASS_COL = "00FF00"
FAIL_COL = "FF0000"
def __init__(self, output_file):
self.output_file = output_file
self.work_book = self.get_workbook()
self.work_sheet = self.work_book.active
self.output_file = output_file
def get_entry_with_id(self, test_id):
"""
......@@ -42,13 +43,13 @@ class ExcelWriter:
for cell in self.work_sheet["A"]:
if cell.value is None:
return cell.row
return 1
return cell.row + 1
def write_test_entry(self, test_entry):
"""
Write a test entry to the work_sheet
"""
existing_entry_row = self.get_entry_with_id(test_entry.id)
existing_entry_row = self.get_entry_with_id(test_entry.test_id)
last_row = self.get_last_row()
# Use the above two values to pick a row
entry_row = existing_entry_row if existing_entry_row != -1 else last_row
......@@ -78,6 +79,54 @@ 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.
Creates if does not exist
"""
try:
chart_work_sheet = self.work_book["charts"]
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()
# 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")
def write_pie_chart(self):
"""
Writes a pie chart showing PASS/FAIL stats.
Writes the chart to a separate work sheet.
"""
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")
def save(self):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment