mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-03 20:27:54 +00:00
added 'if debug' logic, df to excel now working, better print statements
Signed-off-by: Dipti <dipti.dhond@candelatech.com>
This commit is contained in:
@@ -16,6 +16,7 @@ from LANforge import LFRequest
|
|||||||
import LANforge.LFRequest
|
import LANforge.LFRequest
|
||||||
import csv
|
import csv
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
#import xlsxwriter
|
||||||
|
|
||||||
class LFCliBase:
|
class LFCliBase:
|
||||||
|
|
||||||
@@ -624,27 +625,29 @@ class LFCliBase:
|
|||||||
#================ Pandas Dataframe Functions ======================================
|
#================ Pandas Dataframe Functions ======================================
|
||||||
|
|
||||||
#takes any dataframe and returns the specified file extension of it
|
#takes any dataframe and returns the specified file extension of it
|
||||||
def df_to_file(self, dataframe=None, output_f=None):
|
def df_to_file(self, output_f=None,dataframe=None, save_path=None):
|
||||||
df = dataframe
|
df = dataframe
|
||||||
if output_f == 'hdf':
|
#pd.set_option("display.max_rows", None, "display.max_columns", None)
|
||||||
return df.to_hdf(output_f, 'table', append=True)
|
#print(df)
|
||||||
if output_f == 'parquet':
|
if output_f.lower() == 'hdf':
|
||||||
return df.to_parquet(output_f, engine='pyarrow')
|
df.to_hdf(save_path, 'table', append=True)
|
||||||
if output_f == 'png':
|
if output_f.lower() == 'parquet':
|
||||||
|
df.to_parquet(save_path, engine='pyarrow')
|
||||||
|
if output_f.lower() == 'png':
|
||||||
fig = df.plot().get_figure()
|
fig = df.plot().get_figure()
|
||||||
return fig.savefig(output_f)
|
fig.savefig(save_path)
|
||||||
if output_f.lower() in ['excel', 'xlsx']:
|
if output_f.lower() == 'xlsx':
|
||||||
return df.to_excel(output_f, index=False)
|
df.to_excel(save_path)
|
||||||
if output_f == 'df':
|
if output_f.lower() == 'df':
|
||||||
return df
|
df
|
||||||
if output_f == 'json':
|
if output_f.lower() == 'json':
|
||||||
return df.to_json(output_f)
|
df.to_json(save_path)
|
||||||
if output_f == 'stata':
|
if output_f.lower() == 'stata':
|
||||||
return df.to_stata(output_f)
|
df.to_stata(save_path)
|
||||||
if output_f == 'pickle':
|
if output_f.lower() == 'pickle':
|
||||||
return df.to_pickle(output_f)
|
df.to_pickle(save_path)
|
||||||
if output_f == 'html':
|
if output_f.lower() == 'html':
|
||||||
return df.to_html(output_f)
|
df.to_html(save_path)
|
||||||
|
|
||||||
#takes any format of a file and returns a dataframe of it
|
#takes any format of a file and returns a dataframe of it
|
||||||
def file_to_df(self,file_name):
|
def file_to_df(self,file_name):
|
||||||
|
|||||||
@@ -545,7 +545,8 @@ class Realm(LFCliBase):
|
|||||||
|
|
||||||
return matched_map
|
return matched_map
|
||||||
|
|
||||||
def name_to_eid(self, eid):
|
def name_to_eid(self, eid,debug=False):
|
||||||
|
if debug:
|
||||||
self.logg(level="debug", mesg="name_to_eid: "+str(eid))
|
self.logg(level="debug", mesg="name_to_eid: "+str(eid))
|
||||||
if (type(eid) is list) or (type(eid) is tuple):
|
if (type(eid) is list) or (type(eid) is tuple):
|
||||||
return eid
|
return eid
|
||||||
@@ -1206,6 +1207,7 @@ class L3CXProfile(LFCliBase):
|
|||||||
#default save to csv first
|
#default save to csv first
|
||||||
if report_file.split('.')[-1] != 'csv':
|
if report_file.split('.')[-1] != 'csv':
|
||||||
report_file = report_file.replace(str(output_format),'csv',1)
|
report_file = report_file.replace(str(output_format),'csv',1)
|
||||||
|
print("Saving rolling data into..." + str(report_file))
|
||||||
|
|
||||||
#retrieve compared report if specified - turn into dataframe === under construction ===
|
#retrieve compared report if specified - turn into dataframe === under construction ===
|
||||||
if compared_report is not None:
|
if compared_report is not None:
|
||||||
@@ -1330,10 +1332,7 @@ class L3CXProfile(LFCliBase):
|
|||||||
|
|
||||||
#df to final report file output if necessary
|
#df to final report file output if necessary
|
||||||
if output_format.lower() != 'csv':
|
if output_format.lower() != 'csv':
|
||||||
dataframe_output = pd.read_csv(report_file)
|
self.df_to_file(dataframe=pd.read_csv(report_file), output_f=output_format, save_path=report_file.replace('csv',output_format,1))
|
||||||
final_file = self.df_to_file(dataframe=dataframe_output, output_f=output_format)
|
|
||||||
#save final file output
|
|
||||||
#print(report_file)
|
|
||||||
|
|
||||||
|
|
||||||
def refresh_cx(self):
|
def refresh_cx(self):
|
||||||
@@ -1408,7 +1407,7 @@ class L3CXProfile(LFCliBase):
|
|||||||
side_b_resource = side_b_info[1]
|
side_b_resource = side_b_info[1]
|
||||||
|
|
||||||
for port_name in side_a:
|
for port_name in side_a:
|
||||||
side_a_info = self.local_realm.name_to_eid(port_name)
|
side_a_info = self.local_realm.name_to_eid(port_name,debug=debug_)
|
||||||
side_a_shelf = side_a_info[0]
|
side_a_shelf = side_a_info[0]
|
||||||
side_a_resource = side_a_info[1]
|
side_a_resource = side_a_info[1]
|
||||||
if port_name.find('.') < 0:
|
if port_name.find('.') < 0:
|
||||||
@@ -1491,14 +1490,14 @@ class L3CXProfile(LFCliBase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
elif type(side_b) == list and type(side_a) != list:
|
elif type(side_b) == list and type(side_a) != list:
|
||||||
side_a_info = self.local_realm.name_to_eid(side_a)
|
side_a_info = self.local_realm.name_to_eid(side_a,debug=debug_)
|
||||||
side_a_shelf = side_a_info[0]
|
side_a_shelf = side_a_info[0]
|
||||||
side_a_resource = side_a_info[1]
|
side_a_resource = side_a_info[1]
|
||||||
# side_a_name = side_a_info[2]
|
# side_a_name = side_a_info[2]
|
||||||
|
|
||||||
for port_name in side_b:
|
for port_name in side_b:
|
||||||
print(side_b)
|
print(side_b)
|
||||||
side_b_info = self.local_realm.name_to_eid(port_name)
|
side_b_info = self.local_realm.name_to_eid(port_name,debug=debug_)
|
||||||
side_b_shelf = side_b_info[0]
|
side_b_shelf = side_b_info[0]
|
||||||
side_b_resource = side_b_info[1]
|
side_b_resource = side_b_info[1]
|
||||||
side_b_name = side_b_info[2]
|
side_b_name = side_b_info[2]
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
# in new folder based in current file's directory
|
# in new folder based in current file's directory
|
||||||
|
|
||||||
if args.report_file is None:
|
if args.report_file is None:
|
||||||
new_file_path = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")).replace(':',
|
new_file_path = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-h-%M-m-%S-s")).replace(':',
|
||||||
'-') + '-test_ipv4_variable_time' # create path name
|
'-') + '-test_ipv4_variable_time' # create path name
|
||||||
try:
|
try:
|
||||||
path = os.path.join('/home/lanforge/report-data/', new_file_path)
|
path = os.path.join('/home/lanforge/report-data/', new_file_path)
|
||||||
@@ -296,7 +296,7 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
report_f = str(path) + '/data.' + args.output_format
|
report_f = str(path) + '/data.' + args.output_format
|
||||||
output = args.output_format
|
output = args.output_format
|
||||||
else:
|
else:
|
||||||
print('Defaulting to csv data file output type, naming it data.csv.')
|
print('Not supporting this report format or cannot find report format provided. Defaulting to csv data file output type, naming it data.csv.')
|
||||||
report_f = str(path) + '/data.csv'
|
report_f = str(path) + '/data.csv'
|
||||||
output = 'csv'
|
output = 'csv'
|
||||||
|
|
||||||
@@ -306,7 +306,7 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
output = str(args.report_file).split('.')[-1]
|
output = str(args.report_file).split('.')[-1]
|
||||||
else:
|
else:
|
||||||
output = args.output_format
|
output = args.output_format
|
||||||
print("Saving report data in ... " + report_f)
|
print("Saving final report data in ... " + report_f)
|
||||||
|
|
||||||
# Retrieve last data file
|
# Retrieve last data file
|
||||||
compared_rept = None
|
compared_rept = None
|
||||||
|
|||||||
Reference in New Issue
Block a user