diff --git a/py-scripts/lf_csv.py b/py-scripts/lf_csv.py new file mode 100644 index 00000000..e69de29b diff --git a/py-scripts/lf_graph.py b/py-scripts/lf_graph.py index 169a7d4b..61ad7cdd 100755 --- a/py-scripts/lf_graph.py +++ b/py-scripts/lf_graph.py @@ -25,6 +25,7 @@ import pandas as pd import pdfkit import math from matplotlib.colors import ListedColormap +from lf_csv import LfCSV # internal candela references included during intial phases, to be deleted at future date @@ -36,7 +37,8 @@ class lf_bar_graph(): _yaxis_name="y-axis", _xaxis_categories=[1, 2, 3, 4, 5], _xaxis_label=["a", "b", "c", "d", "e"], - _step_size=5, + _graph_title="", + _title_size=16, _graph_image_name="image_name", _label=["bi-downlink", "bi-uplink", 'uplink'], _color=None, @@ -49,14 +51,17 @@ class lf_bar_graph(): _xaxis_step=5, _xticks_font = None, _grp_title = "", - _dpi=96): + _dpi=96, + _enable_csv=True): +>>>>>>> 6dd9cef... lf_csv - creates csv for graph data self.data_set = _data_set self.xaxis_name = _xaxis_name self.yaxis_name = _yaxis_name self.xaxis_categories = _xaxis_categories self.xaxis_label = _xaxis_label - self.step_size = _step_size + self.title = _graph_title + self.title_size = _title_size self.graph_image_name = _graph_image_name self.label = _label self.color = _color @@ -69,6 +74,8 @@ class lf_bar_graph(): self.xaxis_step = _xaxis_step self.xticks_font = _xticks_font self.grp_title = _grp_title + self.enable_csv = _enable_csv + self.lf_csv = LfCSV() def build_bar_graph(self): if self.color is None: @@ -106,24 +113,27 @@ class lf_bar_graph(): i = i + 1 plt.xlabel(self.xaxis_name, fontweight='bold', fontsize=15) plt.ylabel(self.yaxis_name, fontweight='bold', fontsize=15) - """plt.xticks([r + self.bar_width for r in range(len(self.data_set[0]))], - self.xaxis_categories)""" - plt.xticks(np.arange(0, len(self.xaxis_categories), step=self.step_size), labels=self.xaxis_label) - plt.legend() - if self.xaxis_categories[0] == 0: plt.xticks(np.arange(0, len(self.xaxis_categories), step=self.xaxis_step),fontsize = self.xticks_font) else: plt.xticks(np.arange(0, len(self.data_set[0]), step=self.xaxis_step), self.xaxis_categories, fontsize = self.xticks_font) - plt.legend() + plt.suptitle(self.title, fontsize=self.title_size) plt.title(self.grp_title) fig = plt.gcf() plt.savefig("%s.png" % self.graph_image_name, dpi=96) plt.close() print("{}.png".format(self.graph_image_name)) - + if self.enable_csv: + if self.data_set is not None: + self.lf_csv.columns = self.label + self.lf_csv.rows = self.data_set + self.lf_csv.filename = f"{self.graph_image_name}.csv" + self.lf_csv.generate_csv() + else: + print("No Dataset Found") + print("{}.csv".format(self.graph_image_name)) return "%s.png" % self.graph_image_name @@ -135,9 +145,10 @@ class lf_scatter_graph(): _xaxis_name="x-axis", _yaxis_name="y-axis", _label=["num1", "num2"], - _graph_image_name="image_name", + _graph_image_name="image_name1", _color=["r", "y"], - _figsize=(9, 4)): + _figsize=(9, 4), + _enable_csv=True): self.x_data_set = _x_data_set self.y_data_set = _y_data_set self.xaxis_name = _xaxis_name @@ -147,6 +158,8 @@ class lf_scatter_graph(): self.color = _color self.label = _label self.values = _values + self.enable_csv = _enable_csv + self.lf_csv = LfCSV() def build_scatter_graph(self): if self.color is None: @@ -171,6 +184,11 @@ class lf_scatter_graph(): plt.savefig("%s.png" % self.graph_image_name, dpi=96) plt.close() print("{}.png".format(self.graph_image_name)) + if self.enable_csv: + self.lf_csv.columns = self.label + self.lf_csv.rows = self.y_data_set + self.lf_csv.filename = f"{self.graph_image_name}.csv" + self.lf_csv.generate_csv() return "%s.png" % self.graph_image_name @@ -181,9 +199,10 @@ class lf_stacked_graph(): _xaxis_name="Stations", _yaxis_name="Numbers", _label=['Success', 'Fail'], - _graph_image_name="image_name", + _graph_image_name="image_name2", _color=["b", "g"], - _figsize=(9, 4)): + _figsize=(9, 4), + _enable_csv=True): self.data_set = _data_set # [x_axis,y1_axis,y2_axis] self.xaxis_name = _xaxis_name self.yaxis_name = _yaxis_name @@ -191,6 +210,8 @@ class lf_stacked_graph(): self.graph_image_name = _graph_image_name self.label = _label self.color = _color + self.enable_csv = _enable_csv + self.lf_csv = LfCSV() def build_stacked_graph(self): fig = plt.subplots(figsize=self.figsize) @@ -208,7 +229,11 @@ class lf_stacked_graph(): plt.savefig("%s.png" % (self.graph_image_name), dpi=96) plt.close() print("{}.png".format(self.graph_image_name)) - + if self.enable_csv: + self.lf_csv.columns = self.label + self.lf_csv.rows = self.data_set + self.lf_csv.filename = f"{self.graph_image_name}.csv" + self.lf_csv.generate_csv() return "%s.png" % (self.graph_image_name) @@ -221,10 +246,11 @@ class lf_horizontal_stacked_graph(): _unit="%", _xaxis_name="Stations", _label=['Success', 'Fail'], - _graph_image_name="image_name", + _graph_image_name="image_name3", _color=["success", "Fail"], _figsize=(9, 4), - _disable_xaxis=False): + _disable_xaxis=False, + _enable_csv=True): self.unit = _unit self.seg = _seg self.xaxis_set1 = _xaxis_set1 @@ -236,6 +262,8 @@ class lf_horizontal_stacked_graph(): self.label = _label self.color = _color self.disable_xaxis = _disable_xaxis + self.enable_csv = _enable_csv + self.lf_csv = LfCSV() def build_horizontal_stacked_graph(self): def sumzip(items): @@ -277,7 +305,11 @@ class lf_horizontal_stacked_graph(): plt.savefig("%s.png" % self.graph_image_name, dpi=96) plt.close() print("{}.png".format(self.graph_image_name)) - + # if self.enable_csv: + # self.lf_csv.columns = self.label + # self.lf_csv.rows = self.data_set + # self.lf_csv.filename = f"{self.graph_image_name}.csv" + # self.lf_csv.generate_csv() return "%s.png" % self.graph_image_name diff --git a/py-scripts/lf_report.py b/py-scripts/lf_report.py index 2486c905..46c1dd15 100755 --- a/py-scripts/lf_report.py +++ b/py-scripts/lf_report.py @@ -146,6 +146,8 @@ class lf_report(): print("graph_src_file: {}".format(graph_src_file)) print("graph_dst_file: {}".format(graph_dst_file)) shutil.move(graph_src_file, graph_dst_file) + def move_csv_file(self): + csv_src_file = str(self.fil) def set_path(self,_path): self.path = _path diff --git a/py-scripts/lf_report_test.py b/py-scripts/lf_report_test.py index a9340f34..a89c2bb7 100755 --- a/py-scripts/lf_report_test.py +++ b/py-scripts/lf_report_test.py @@ -96,7 +96,7 @@ if __name__ == "__main__": _xaxis_categories=x_axis_values, _graph_image_name="Bi-single_radio_2.4GHz", _label=["bi-downlink", "bi-uplink", 'uplink'], - _color=None, + _color=['darkorange', 'forestgreen','blueviolet'], _color_edge='red') graph_png = graph.build_bar_graph() diff --git a/py-scripts/throughput_qos_report.py b/py-scripts/throughput_qos_report.py deleted file mode 100644 index 0da8b9ee..00000000 --- a/py-scripts/throughput_qos_report.py +++ /dev/null @@ -1,142 +0,0 @@ -''' ------------------------------------------------------------------------------------- -Throughput QOS report evaluates the throughput for a number of clients which are running -traffic with a particular type of service Video | Voice | BE | BK ------------------------------------------------------------------------------------- -''' -import matplotlib.pyplot as plt -import matplotlib as mpl -import numpy as np -import pandas as pd -import pdfkit -from lf_report import lf_report -from lf_graph import lf_bar_graph - - -def table(report, title, data): - # creating table - report.set_table_title(title) - report.build_table_title() - report.set_table_dataframe(data) - report.build_table() - - -def grph(report, data_set=None, xaxis_name="stations", yaxis_name="Throughput 2 (Mbps)", - xaxis_categories=None, label=None, graph_image_name=""): - # creating bar graph - report.set_graph_title(graph_image_name) - report.build_graph_title() - graph = lf_bar_graph(_data_set=data_set, - _xaxis_name=xaxis_name, - _yaxis_name=yaxis_name, - _xaxis_categories=xaxis_categories, - _graph_image_name=graph_image_name, - _label=label, - _color=None, - _color_edge='red') - graph_png = graph.build_bar_graph() - print("graph name {}".format(graph_png)) - report.set_graph_image(graph_png) - report.move_graph_image() - report.build_graph() - - -def generate_report(util, sta_num, bps_rx_a, bps_rx_b, tbl_title, grp_title, upload=1000000, download=1000000): - # report generation main function - rx_a = [] - rx_b = [] - pas_fail_up = [] - pas_fail_down = [] - thrp_b = upload * len(sta_num) # get overall upload values - thrp_a = download * len(sta_num) ## get overall download values - print(f"given upload--{thrp_b} and download--{thrp_a} values") - index = -1 - for a in bps_rx_a: - index += 1 - if len(a): - rx_a.append(f'min: {min(a)} | max: {max(a)} | avg: {sum(a) / len(a)}') - if thrp_a: - print( - f"getting overall download values '{index}'----- {sum(a)} \n {(thrp_a / 100) * (100 - int(util[index]))}") - if (thrp_a / 100) * (100 - int(util[index])) <= sum(a): - pas_fail_down.append("PASS") - else: - pas_fail_down.append("FAIL") - else: - pas_fail_down.append("NA") - rx_a.append(0) - - if len(bps_rx_b[index]): - rx_b.append(f'min: {min(bps_rx_b[index])} | max: {max(bps_rx_b[index])} | ' - f'avg: {(sum(bps_rx_b[index]) / len(bps_rx_b[index])):.2f}') - - if thrp_b: - print( - f"getting overall upload values '{index}'----- {sum(bps_rx_b[index])} \n {(thrp_b / 100) * (100 - int(util[index]))}") - if (thrp_b / 100) * (100 - int(util[index])) <= sum(bps_rx_b[index]): - pas_fail_up.append("PASS") - else: - pas_fail_up.append("FAIL") - else: - pas_fail_up.append("NA") - rx_b.append(0) - - util[index] = f'{util[index]}%' # append % to the util values - - overall_tab = pd.DataFrame({ - 'Channel Utilization (%)': util, "No.of.clients": [len(sta_num)] * len(util), - 'Speed (mbps)': [f'upload: {upload} | download: {download}'] * len(util), - 'Upload (mbps)': rx_b, 'Download (mbps)': rx_a - }) - print(f"overall table \n{overall_tab}") - - pasfail_tab = pd.DataFrame({ - 'Channel Utilization (%)': util, - 'Upload': pas_fail_up, - 'Download': pas_fail_down - }) - print(f"pass-fail table \n {pasfail_tab}") - - report = lf_report() - report_path = report.get_path() - report_path_date_time = report.get_path_date_time() - print("path: {}".format(report_path)) - print("path_date_time: {}".format(report_path_date_time)) - report.set_title(tbl_title) - report.build_banner() - - # objective title and description - report.set_obj_html(_obj_title="Objective", - _obj="Through this test we can evaluate the throughput for given number of clients which" - "are running the traffic with a particular TOS i.e BK,BE,VI,VO") - report.build_objective() - - table(report, "Overall throughput", overall_tab) - table(report, "Throughput Pass/Fail", pasfail_tab) - - if download: - grph(report, - data_set=[[min(i) for i in bps_rx_a], [max(i) for i in bps_rx_a], [sum(i) / len(i) for i in bps_rx_a]], - xaxis_name="Load", yaxis_name="Throughput (Mbps)", - xaxis_categories=util, label=["min", "max", 'avg'], graph_image_name="Throughput_download") - if upload: - grph(report, - data_set=[[min(i) for i in bps_rx_b], [max(i) for i in bps_rx_b], [sum(i) / len(i) for i in bps_rx_b]], - xaxis_name="Load", yaxis_name="Throughput (Mbps)", - xaxis_categories=util, label=["min", "max", 'avg'], graph_image_name="Throughput_upload") - - for i in range(len(util)): - if download: - grph(report, data_set=[bps_rx_a[i]], xaxis_name="stations", - yaxis_name="Throughput (Mbps)", xaxis_categories=range(0, len(sta_num)), - label=[util[i]], graph_image_name=f"client-Throughput-download_{i}") - if upload: - grph(report, data_set=[bps_rx_b[i]], xaxis_name="stations", - yaxis_name="Throughput (Mbps)", xaxis_categories=range(0, len(sta_num)), - label=[util[i]], graph_image_name=f"client-Throughput-upload_{i}") - - html_file = report.write_html() - print("returned file {}".format(html_file)) - report.write_pdf() - - # report.generate_report()