mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-03 04:07:52 +00:00
lf_graph.py lf_report_test.py : pep8 complience
Signed-off-by: Chuck SmileyRekiere <chuck.smileyrekiere@candelatech.com>
This commit is contained in:
@@ -31,9 +31,12 @@ sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
|
|||||||
lf_csv = importlib.import_module("py-scripts.lf_csv")
|
lf_csv = importlib.import_module("py-scripts.lf_csv")
|
||||||
lf_csv = lf_csv.lf_csv
|
lf_csv = lf_csv.lf_csv
|
||||||
|
|
||||||
# internal candela references included during intial phases, to be deleted at future date
|
# internal candela references included during intial phases, to be deleted
|
||||||
|
# at future date
|
||||||
|
|
||||||
# graph reporting classes
|
# graph reporting classes
|
||||||
|
|
||||||
|
|
||||||
class lf_bar_graph():
|
class lf_bar_graph():
|
||||||
def __init__(self, _data_set=[[30.4, 55.3, 69.2, 37.1], [45.1, 67.2, 34.3, 22.4], [22.5, 45.6, 12.7, 34.8]],
|
def __init__(self, _data_set=[[30.4, 55.3, 69.2, 37.1], [45.1, 67.2, 34.3, 22.4], [22.5, 45.6, 12.7, 34.8]],
|
||||||
_xaxis_name="x-axis",
|
_xaxis_name="x-axis",
|
||||||
@@ -132,11 +135,19 @@ class lf_bar_graph():
|
|||||||
plt.xlabel(self.xaxis_name, fontweight='bold', fontsize=15)
|
plt.xlabel(self.xaxis_name, fontweight='bold', fontsize=15)
|
||||||
plt.ylabel(self.yaxis_name, fontweight='bold', fontsize=15)
|
plt.ylabel(self.yaxis_name, fontweight='bold', fontsize=15)
|
||||||
if self.xaxis_categories[0] == 0:
|
if self.xaxis_categories[0] == 0:
|
||||||
plt.xticks(np.arange(0, len(self.xaxis_categories), step=self.xaxis_step),fontsize = self.xticks_font)
|
plt.xticks(np.arange(0,
|
||||||
|
len(self.xaxis_categories),
|
||||||
|
step=self.xaxis_step),
|
||||||
|
fontsize=self.xticks_font)
|
||||||
else:
|
else:
|
||||||
plt.xticks([i + self._xaxis_value_location for i in np.arange(0, len(self.data_set[0]), step=self.xaxis_step)],
|
plt.xticks([i + self._xaxis_value_location for i in np.arange(0, len(self.data_set[0]), step=self.xaxis_step)],
|
||||||
self.xaxis_categories, fontsize=self.xticks_font)
|
self.xaxis_categories, fontsize=self.xticks_font)
|
||||||
plt.legend(handles=self.legend_handles, loc=self.legend_loc, bbox_to_anchor=self.legend_box, ncol=self.legend_ncol, fontsize=self.legend_fontsize)
|
plt.legend(
|
||||||
|
handles=self.legend_handles,
|
||||||
|
loc=self.legend_loc,
|
||||||
|
bbox_to_anchor=self.legend_box,
|
||||||
|
ncol=self.legend_ncol,
|
||||||
|
fontsize=self.legend_fontsize)
|
||||||
plt.suptitle(self.title, fontsize=self.title_size)
|
plt.suptitle(self.title, fontsize=self.title_size)
|
||||||
plt.title(self.grp_title)
|
plt.title(self.grp_title)
|
||||||
fig = plt.gcf()
|
fig = plt.gcf()
|
||||||
@@ -155,7 +166,8 @@ class lf_bar_graph():
|
|||||||
self.lf_csv.filename = f"{self.graph_image_name}.csv"
|
self.lf_csv.filename = f"{self.graph_image_name}.csv"
|
||||||
self.lf_csv.generate_csv()
|
self.lf_csv.generate_csv()
|
||||||
else:
|
else:
|
||||||
raise ValueError("Length and x-axis values and y-axis values should be same.")
|
raise ValueError(
|
||||||
|
"Length and x-axis values and y-axis values should be same.")
|
||||||
else:
|
else:
|
||||||
print("No Dataset Found")
|
print("No Dataset Found")
|
||||||
print("{}.csv".format(self.graph_image_name))
|
print("{}.csv".format(self.graph_image_name))
|
||||||
@@ -188,20 +200,38 @@ class lf_scatter_graph():
|
|||||||
|
|
||||||
def build_scatter_graph(self):
|
def build_scatter_graph(self):
|
||||||
if self.color is None:
|
if self.color is None:
|
||||||
self.color = ["orchid", "lime", "aquamarine", "royalblue", "darkgray", "maroon"]
|
self.color = [
|
||||||
|
"orchid",
|
||||||
|
"lime",
|
||||||
|
"aquamarine",
|
||||||
|
"royalblue",
|
||||||
|
"darkgray",
|
||||||
|
"maroon"]
|
||||||
fig = plt.subplots(figsize=self.figsize)
|
fig = plt.subplots(figsize=self.figsize)
|
||||||
if self.values is None:
|
if self.values is None:
|
||||||
plt.scatter(self.x_data_set, self.y_data_set[0], color=self.color[0], label=self.label[0])
|
plt.scatter(
|
||||||
|
self.x_data_set,
|
||||||
|
self.y_data_set[0],
|
||||||
|
color=self.color[0],
|
||||||
|
label=self.label[0])
|
||||||
if len(self.y_data_set) > 1:
|
if len(self.y_data_set) > 1:
|
||||||
for i in range(1, len(self.y_data_set)):
|
for i in range(1, len(self.y_data_set)):
|
||||||
plt.scatter(self.x_data_set, self.y_data_set[i], color=self.color[i], label=self.label[i])
|
plt.scatter(
|
||||||
|
self.x_data_set,
|
||||||
|
self.y_data_set[i],
|
||||||
|
color=self.color[i],
|
||||||
|
label=self.label[i])
|
||||||
plt.xlabel(self.xaxis_name, fontweight='bold', fontsize=15)
|
plt.xlabel(self.xaxis_name, fontweight='bold', fontsize=15)
|
||||||
plt.ylabel(self.yaxis_name, fontweight='bold', fontsize=15)
|
plt.ylabel(self.yaxis_name, fontweight='bold', fontsize=15)
|
||||||
plt.gcf().autofmt_xdate()
|
plt.gcf().autofmt_xdate()
|
||||||
plt.legend()
|
plt.legend()
|
||||||
else:
|
else:
|
||||||
colours = ListedColormap(self.color)
|
colours = ListedColormap(self.color)
|
||||||
scatter = plt.scatter(self.x_data_set, self.y_data_set, c=self.values, cmap=colours)
|
scatter = plt.scatter(
|
||||||
|
self.x_data_set,
|
||||||
|
self.y_data_set,
|
||||||
|
c=self.values,
|
||||||
|
cmap=colours)
|
||||||
plt.xlabel(self.xaxis_name, fontweight='bold', fontsize=15)
|
plt.xlabel(self.xaxis_name, fontweight='bold', fontsize=15)
|
||||||
plt.ylabel(self.yaxis_name, fontweight='bold', fontsize=15)
|
plt.ylabel(self.yaxis_name, fontweight='bold', fontsize=15)
|
||||||
plt.gcf().autofmt_xdate()
|
plt.gcf().autofmt_xdate()
|
||||||
@@ -241,9 +271,19 @@ class lf_stacked_graph():
|
|||||||
def build_stacked_graph(self):
|
def build_stacked_graph(self):
|
||||||
fig = plt.subplots(figsize=self.figsize)
|
fig = plt.subplots(figsize=self.figsize)
|
||||||
if self.color is None:
|
if self.color is None:
|
||||||
self.color = ["darkred", "tomato", "springgreen", "skyblue", "indigo", "plum"]
|
self.color = [
|
||||||
|
"darkred",
|
||||||
|
"tomato",
|
||||||
|
"springgreen",
|
||||||
|
"skyblue",
|
||||||
|
"indigo",
|
||||||
|
"plum"]
|
||||||
plt.bar(self.data_set[0], self.data_set[1], color=self.color[0])
|
plt.bar(self.data_set[0], self.data_set[1], color=self.color[0])
|
||||||
plt.bar(self.data_set[0], self.data_set[2], bottom=self.data_set[1], color=self.color[1])
|
plt.bar(
|
||||||
|
self.data_set[0],
|
||||||
|
self.data_set[2],
|
||||||
|
bottom=self.data_set[1],
|
||||||
|
color=self.color[1])
|
||||||
if len(self.data_set) > 3:
|
if len(self.data_set) > 3:
|
||||||
for i in range(3, len(self.data_set)):
|
for i in range(3, len(self.data_set)):
|
||||||
plt.bar(self.data_set[0], self.data_set[i],
|
plt.bar(self.data_set[0], self.data_set[i],
|
||||||
@@ -303,8 +343,19 @@ class lf_horizontal_stacked_graph():
|
|||||||
ind = np.arange(n) + .15
|
ind = np.arange(n) + .15
|
||||||
width = 0.3
|
width = 0.3
|
||||||
|
|
||||||
rects1 = plt.barh(ind, values1, width, color=self.color[0], label=self.label[0])
|
rects1 = plt.barh(
|
||||||
rects2 = plt.barh(ind, values2, width, left=sumzip(values1), color=self.color[1], label=self.label[1])
|
ind,
|
||||||
|
values1,
|
||||||
|
width,
|
||||||
|
color=self.color[0],
|
||||||
|
label=self.label[0])
|
||||||
|
rects2 = plt.barh(
|
||||||
|
ind,
|
||||||
|
values2,
|
||||||
|
width,
|
||||||
|
left=sumzip(values1),
|
||||||
|
color=self.color[1],
|
||||||
|
label=self.label[1])
|
||||||
|
|
||||||
extra_space = 0.15
|
extra_space = 0.15
|
||||||
ax.set_yticks(ind + width - extra_space)
|
ax.set_yticks(ind + width - extra_space)
|
||||||
@@ -326,7 +377,12 @@ class lf_horizontal_stacked_graph():
|
|||||||
ax.spines['top'].set_visible(False)
|
ax.spines['top'].set_visible(False)
|
||||||
ax.legend(loc='upper right')
|
ax.legend(loc='upper right')
|
||||||
if self.disable_xaxis:
|
if self.disable_xaxis:
|
||||||
plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) # disable x-axis
|
plt.tick_params(
|
||||||
|
axis='x',
|
||||||
|
which='both',
|
||||||
|
bottom=False,
|
||||||
|
top=False,
|
||||||
|
labelbottom=False) # disable x-axis
|
||||||
plt.savefig("%s.png" % self.graph_image_name, dpi=96)
|
plt.savefig("%s.png" % self.graph_image_name, dpi=96)
|
||||||
plt.close()
|
plt.close()
|
||||||
print("{}.png".format(self.graph_image_name))
|
print("{}.png".format(self.graph_image_name))
|
||||||
@@ -390,12 +446,22 @@ class lf_line_graph():
|
|||||||
fig = plt.subplots(figsize=self.figsize)
|
fig = plt.subplots(figsize=self.figsize)
|
||||||
i = 0
|
i = 0
|
||||||
for data in self.data_set:
|
for data in self.data_set:
|
||||||
plt.plot(self.xaxis_categories, data, color=self.color[i], label=self.label[i], marker = self.marker)
|
plt.plot(
|
||||||
|
self.xaxis_categories,
|
||||||
|
data,
|
||||||
|
color=self.color[i],
|
||||||
|
label=self.label[i],
|
||||||
|
marker=self.marker)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
plt.xlabel(self.xaxis_name, fontweight='bold', fontsize=15)
|
plt.xlabel(self.xaxis_name, fontweight='bold', fontsize=15)
|
||||||
plt.ylabel(self.yaxis_name, fontweight='bold', fontsize=15)
|
plt.ylabel(self.yaxis_name, fontweight='bold', fontsize=15)
|
||||||
plt.legend(handles=self.legend_handles, loc=self.legend_loc, bbox_to_anchor=self.legend_box, ncol=self.legend_ncol, fontsize=self.legend_fontsize)
|
plt.legend(
|
||||||
|
handles=self.legend_handles,
|
||||||
|
loc=self.legend_loc,
|
||||||
|
bbox_to_anchor=self.legend_box,
|
||||||
|
ncol=self.legend_ncol,
|
||||||
|
fontsize=self.legend_fontsize)
|
||||||
plt.suptitle(self.grp_title, fontsize=self.title_size)
|
plt.suptitle(self.grp_title, fontsize=self.title_size)
|
||||||
fig = plt.gcf()
|
fig = plt.gcf()
|
||||||
plt.savefig("%s.png" % self.graph_image_name, dpi=96)
|
plt.savefig("%s.png" % self.graph_image_name, dpi=96)
|
||||||
@@ -412,6 +478,7 @@ class lf_line_graph():
|
|||||||
print("{}.csv".format(self.graph_image_name))
|
print("{}.csv".format(self.graph_image_name))
|
||||||
return "%s.png" % self.graph_image_name
|
return "%s.png" % self.graph_image_name
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# arguments
|
# arguments
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
@@ -440,7 +507,12 @@ COPYWRITE
|
|||||||
INCLUDE_IN_README
|
INCLUDE_IN_README
|
||||||
---------------------
|
---------------------
|
||||||
''')
|
''')
|
||||||
parser.add_argument('--mgr','--lfmgr', dest='lfmgr', help='sample argument: where LANforge GUI is running', default='localhost')
|
parser.add_argument(
|
||||||
|
'--mgr',
|
||||||
|
'--lfmgr',
|
||||||
|
dest='lfmgr',
|
||||||
|
help='sample argument: where LANforge GUI is running',
|
||||||
|
default='localhost')
|
||||||
# the args parser is not really used , this is so the report is not generated when testing
|
# the args parser is not really used , this is so the report is not generated when testing
|
||||||
# the imports with --help
|
# the imports with --help
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@@ -464,7 +536,8 @@ INCLUDE_IN_README
|
|||||||
# write logic to generate pdf here
|
# write logic to generate pdf here
|
||||||
# wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
|
# wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
|
||||||
# sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb
|
# sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb
|
||||||
options = {"enable-local-file-access": None} # prevent eerror Blocked access to file
|
# prevent eerror Blocked access to file
|
||||||
|
options = {"enable-local-file-access": None}
|
||||||
pdfkit.from_file(output_html_1, output_pdf_1, options=options)
|
pdfkit.from_file(output_html_1, output_pdf_1, options=options)
|
||||||
|
|
||||||
# test build_bar_graph setting values
|
# test build_bar_graph setting values
|
||||||
@@ -497,10 +570,11 @@ INCLUDE_IN_README
|
|||||||
# write logic to generate pdf here
|
# write logic to generate pdf here
|
||||||
# wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
|
# wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
|
||||||
# sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb
|
# sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb
|
||||||
options = {"enable-local-file-access": None} # prevent eerror Blocked access to file
|
# prevent eerror Blocked access to file
|
||||||
|
options = {"enable-local-file-access": None}
|
||||||
pdfkit.from_file(output_html_2, output_pdf_2, options=options)
|
pdfkit.from_file(output_html_2, output_pdf_2, options=options)
|
||||||
|
|
||||||
|
|
||||||
# Unit Test
|
# Unit Test
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ lf_stacked_graph = lf_graph.lf_stacked_graph
|
|||||||
lf_horizontal_stacked_graph = lf_graph.lf_horizontal_stacked_graph
|
lf_horizontal_stacked_graph = lf_graph.lf_horizontal_stacked_graph
|
||||||
|
|
||||||
# Unit Test
|
# Unit Test
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Testing: generate data frame
|
# Testing: generate data frame
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
@@ -65,7 +67,12 @@ COPYWRITE
|
|||||||
INCLUDE_IN_README
|
INCLUDE_IN_README
|
||||||
''')
|
''')
|
||||||
|
|
||||||
parser.add_argument('--mgr','--lfmgr', dest='lfmgr', help='sample argument: where LANforge GUI is running', default='localhost')
|
parser.add_argument(
|
||||||
|
'--mgr',
|
||||||
|
'--lfmgr',
|
||||||
|
dest='lfmgr',
|
||||||
|
help='sample argument: where LANforge GUI is running',
|
||||||
|
default='localhost')
|
||||||
# the args parser is not really used , this is so the report is not generated when testing
|
# the args parser is not really used , this is so the report is not generated when testing
|
||||||
# the imports with --help
|
# the imports with --help
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@@ -178,7 +185,8 @@ INCLUDE_IN_README
|
|||||||
report.move_graph_image()
|
report.move_graph_image()
|
||||||
|
|
||||||
report.build_graph()
|
report.build_graph()
|
||||||
# this will generate graph which is independent,we can customize the value with different colors
|
# this will generate graph which is independent,we can customize the value
|
||||||
|
# with different colors
|
||||||
graph2 = lf_scatter_graph(_x_data_set=set1, _y_data_set=[45, 67, 45, 34], _values=[0, 0, 0, 1],
|
graph2 = lf_scatter_graph(_x_data_set=set1, _y_data_set=[45, 67, 45, 34], _values=[0, 0, 0, 1],
|
||||||
_xaxis_name="x-axis",
|
_xaxis_name="x-axis",
|
||||||
_yaxis_name="y-axis",
|
_yaxis_name="y-axis",
|
||||||
@@ -194,7 +202,8 @@ INCLUDE_IN_README
|
|||||||
report.move_graph_image()
|
report.move_graph_image()
|
||||||
|
|
||||||
report.build_graph()
|
report.build_graph()
|
||||||
dataset = [["1", "2", "3", "4"], [12, 45, 67, 34], [23, 67, 23, 12], [25, 45, 34, 23]]
|
dataset = [["1", "2", "3", "4"], [12, 45, 67, 34],
|
||||||
|
[23, 67, 23, 12], [25, 45, 34, 23]]
|
||||||
graph = lf_stacked_graph(_data_set=dataset,
|
graph = lf_stacked_graph(_data_set=dataset,
|
||||||
_xaxis_name="Stations",
|
_xaxis_name="Stations",
|
||||||
_yaxis_name="Login PASS/FAIL",
|
_yaxis_name="Login PASS/FAIL",
|
||||||
|
|||||||
Reference in New Issue
Block a user