mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-03 20:27:54 +00:00
added total_seconds function to calculate total seconds since epoch, test_time_elapsed column to help with dataframe comparison
Signed-off-by: Dipti <dipti.dhond@candelatech.com>
This commit is contained in:
@@ -580,6 +580,10 @@ class LFCliBase:
|
|||||||
def get_milliseconds(self,
|
def get_milliseconds(self,
|
||||||
timestamp):
|
timestamp):
|
||||||
return (timestamp - datetime.datetime(1970,1,1)).total_seconds()*1000
|
return (timestamp - datetime.datetime(1970,1,1)).total_seconds()*1000
|
||||||
|
def get_seconds(self,
|
||||||
|
timestamp):
|
||||||
|
return (timestamp - datetime.datetime(1970,1,1)).total_seconds()
|
||||||
|
|
||||||
|
|
||||||
def replace_special_char(self,
|
def replace_special_char(self,
|
||||||
str):
|
str):
|
||||||
@@ -626,15 +630,11 @@ class LFCliBase:
|
|||||||
|
|
||||||
#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):
|
||||||
|
if file_name.split('.')[-1] == 'csv':
|
||||||
return pd.read_csv(file_name)
|
return pd.read_csv(file_name)
|
||||||
#get difference of all common columns in 2 dataframes. store in
|
|
||||||
|
|
||||||
def compare_two_df(self,dataframe_one=None,dataframe_two=None):
|
def compare_two_df(self,dataframe_one=None,dataframe_two=None):
|
||||||
#get the columns to be compared
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pass
|
pass
|
||||||
#return compared_df
|
#return compared_df
|
||||||
|
|
||||||
|
|||||||
@@ -1209,20 +1209,13 @@ class L3CXProfile(LFCliBase):
|
|||||||
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))
|
print("Saving rolling data into..." + str(report_file))
|
||||||
|
|
||||||
#retrieve compared report if specified - turn into dataframe === under construction ===
|
|
||||||
if compared_report is not None:
|
|
||||||
supported_formats = ['csv', 'json', 'stata', 'pickle','html']
|
|
||||||
for format in supported_formats:
|
|
||||||
if compared_report.lower() == format:
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
#================== Step 1, set column names and header row
|
#================== Step 1, set column names and header row
|
||||||
layer3_cols=[self.replace_special_char(x) for x in layer3_cols]
|
layer3_cols=[self.replace_special_char(x) for x in layer3_cols]
|
||||||
layer3_fields = ",".join(layer3_cols)
|
layer3_fields = ",".join(layer3_cols)
|
||||||
header_row=layer3_cols
|
default_cols=['Timestamp','Timestamp milliseconds epoch','Duration elapsed']
|
||||||
header_row.insert(0,'Timestamp milliseconds')
|
default_cols.extend(layer3_cols)
|
||||||
header_row.insert(0,'Timestamp')
|
header_row=default_cols
|
||||||
|
|
||||||
|
|
||||||
#csvwriter.writerow([systeminfo['VersionInfo']['BuildVersion'], script_name, str(arguments)])
|
#csvwriter.writerow([systeminfo['VersionInfo']['BuildVersion'], script_name, str(arguments)])
|
||||||
|
|
||||||
@@ -1260,7 +1253,13 @@ class L3CXProfile(LFCliBase):
|
|||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
# for x in range(0,int(round(iterations,0))):
|
# for x in range(0,int(round(iterations,0))):
|
||||||
|
initial_starttime= datetime.datetime.now()
|
||||||
while datetime.datetime.now() < end_time:
|
while datetime.datetime.now() < end_time:
|
||||||
|
t = datetime.datetime.now()
|
||||||
|
timestamp= t.strftime("%m/%d/%Y %I:%M:%S")
|
||||||
|
t_to_millisec_epoch= int(self.get_milliseconds(t))
|
||||||
|
time_elapsed=int(self.get_seconds(t))-int(self.get_seconds(initial_starttime))
|
||||||
|
|
||||||
layer_3_response = self.json_get("/endp/%s?fields=%s" % (created_cx, layer3_fields))
|
layer_3_response = self.json_get("/endp/%s?fields=%s" % (created_cx, layer3_fields))
|
||||||
if port_mgr_cols is not None:
|
if port_mgr_cols is not None:
|
||||||
port_mgr_response=self.json_get("/port/1/1/%s?fields=%s" % (sta_list, port_mgr_fields))
|
port_mgr_response=self.json_get("/port/1/1/%s?fields=%s" % (sta_list, port_mgr_fields))
|
||||||
@@ -1278,10 +1277,6 @@ class L3CXProfile(LFCliBase):
|
|||||||
print("Json port_mgr_response from LANforge... " + str(port_mgr_response))
|
print("Json port_mgr_response from LANforge... " + str(port_mgr_response))
|
||||||
|
|
||||||
|
|
||||||
t = datetime.datetime.now()
|
|
||||||
|
|
||||||
timestamp= t.strftime("%m/%d/%Y %I:%M:%S")
|
|
||||||
t_to_millisec_epoch= int(self.get_milliseconds(t))
|
|
||||||
|
|
||||||
temp_list=[]
|
temp_list=[]
|
||||||
for endpoint in layer_3_response["endpoint"]:
|
for endpoint in layer_3_response["endpoint"]:
|
||||||
@@ -1289,7 +1284,7 @@ class L3CXProfile(LFCliBase):
|
|||||||
print("Current endpoint values list... ")
|
print("Current endpoint values list... ")
|
||||||
print(list(endpoint.values())[0])
|
print(list(endpoint.values())[0])
|
||||||
temp_endp_values=list(endpoint.values())[0] #dict
|
temp_endp_values=list(endpoint.values())[0] #dict
|
||||||
temp_list.extend([timestamp,t_to_millisec_epoch])
|
temp_list.extend([timestamp,t_to_millisec_epoch,time_elapsed])
|
||||||
current_sta = temp_endp_values['name']
|
current_sta = temp_endp_values['name']
|
||||||
merge={}
|
merge={}
|
||||||
if port_mgr_cols is not None:
|
if port_mgr_cols is not None:
|
||||||
@@ -1304,7 +1299,8 @@ class L3CXProfile(LFCliBase):
|
|||||||
for key in port_mgr_values_dict.keys():
|
for key in port_mgr_values_dict.keys():
|
||||||
renamed_port_cols['port mgr - ' +key]=port_mgr_values_dict[key]
|
renamed_port_cols['port mgr - ' +key]=port_mgr_values_dict[key]
|
||||||
merge.update(renamed_port_cols)
|
merge.update(renamed_port_cols)
|
||||||
for name in header_row[2:-3]:
|
print(header_row[3:-3])
|
||||||
|
for name in header_row[3:-3]:
|
||||||
temp_list.append(merge[name])
|
temp_list.append(merge[name])
|
||||||
csvwriter.writerow(temp_list)
|
csvwriter.writerow(temp_list)
|
||||||
temp_list.clear()
|
temp_list.clear()
|
||||||
@@ -1326,9 +1322,11 @@ class L3CXProfile(LFCliBase):
|
|||||||
|
|
||||||
#comparison to last report / report inputted
|
#comparison to last report / report inputted
|
||||||
if compared_report is not None:
|
if compared_report is not None:
|
||||||
compared_report_completed=self.compare_two_df(pd.read_csv(report_file), pd.read_csv(compared_report))
|
compared_df = self.compare_two_df(dataframe_one=self.file_to_df(report_file), dataframe_two=self.file_to_df(compared_report))
|
||||||
|
#append compared df to created one
|
||||||
#df to final report file output if necessary
|
if output_format.lower() != 'csv':
|
||||||
|
self.df_to_file(dataframe=pd.read_csv(report_file), output_f=output_format, save_path=report_file)
|
||||||
|
else:
|
||||||
if output_format.lower() != 'csv':
|
if output_format.lower() != 'csv':
|
||||||
self.df_to_file(dataframe=pd.read_csv(report_file), output_f=output_format, save_path=report_file)
|
self.df_to_file(dataframe=pd.read_csv(report_file), output_f=output_format, save_path=report_file)
|
||||||
|
|
||||||
|
|||||||
@@ -311,13 +311,11 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
# Retrieve last data file
|
# Retrieve last data file
|
||||||
compared_rept = None
|
compared_rept = None
|
||||||
if args.compared_report:
|
if args.compared_report:
|
||||||
# check if last report format is same as current rpt format
|
compared_report_format=args.compared_report.split('.')[-1]
|
||||||
last_report_format = args.compared_report.split('.')[-1]
|
#if compared_report_format not in ['csv', 'json', 'dta', 'pkl','html','xlsx','parquet','h5']:
|
||||||
if output == last_report_format:
|
if compared_report_format != 'csv':
|
||||||
compared_rept = args.compared_report
|
ValueError("Cannot process this file type. Please select a different file and re-run script.")
|
||||||
else:
|
exit(1)
|
||||||
ValueError(
|
|
||||||
"Compared report format is not the same as the new report format. Please make sure they are of the same file type.")
|
|
||||||
|
|
||||||
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000,
|
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000,
|
||||||
radio=args.radio)
|
radio=args.radio)
|
||||||
@@ -362,6 +360,7 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
# send col names here to file to reformat
|
# send col names here to file to reformat
|
||||||
else:
|
else:
|
||||||
port_mgr_cols = args.port_mgr_cols
|
port_mgr_cols = args.port_mgr_cols
|
||||||
|
# send col names here to file to reformat
|
||||||
if args.debug:
|
if args.debug:
|
||||||
print("Layer 3 Endp column names are...")
|
print("Layer 3 Endp column names are...")
|
||||||
print(layer3_cols)
|
print(layer3_cols)
|
||||||
|
|||||||
Reference in New Issue
Block a user