added imports to only when they are used (small imports), dataframe comparison underway

Signed-off-by: Dipti <dipti.dhond@candelatech.com>
This commit is contained in:
Dipti
2021-02-18 02:10:52 -08:00
parent ad834dd3b8
commit 84760e6959
3 changed files with 24 additions and 5 deletions

View File

@@ -16,9 +16,7 @@ from LANforge import LFRequest
import LANforge.LFRequest
import csv
import pandas as pd
import tables
import pyarrow as pa
#import xlsxwriter
class LFCliBase:
@@ -611,8 +609,10 @@ class LFCliBase:
#takes any dataframe and returns the specified file extension of it
def df_to_file(self, output_f=None,dataframe=None, save_path=None):
if output_f.lower() == 'hdf':
import tables
dataframe.to_hdf(save_path.replace('csv','h5',1), 'table', append=True)
if output_f.lower() == 'parquet':
import pyarrow as pa
dataframe.to_parquet(save_path.replace('csv','parquet',1), engine='pyarrow')
if output_f.lower() == 'png':
fig = dataframe.plot().get_figure()
@@ -635,6 +635,23 @@ class LFCliBase:
def compare_two_df(self,dataframe_one=None,dataframe_two=None):
pd.set_option("display.max_rows", None, "display.max_columns", None)
#get all of common columns besides Timestamp, Timestamp milliseconds
common_cols = set(dataframe_one.columns).intersection(set(dataframe_two.columns))
if common_cols is not None:
cols_to_remove=['Timestamp milliseconds epoch','Timestamp','LANforge GUI Build: 5.4.3']
#drop unwanted cols from df
dataframe_one = dataframe_one.drop(list(cols_to_remove), axis=1)
dataframe_two = dataframe_two.drop(list(cols_to_remove), axis=1)
#for time elapsed section and endpoint name combo
#
print(dataframe_one)
print(dataframe_two)
#take those columns and separate those columns from others in DF.
pass
#return compared_df

View File

@@ -1299,7 +1299,6 @@ class L3CXProfile(LFCliBase):
for key in port_mgr_values_dict.keys():
renamed_port_cols['port mgr - ' +key]=port_mgr_values_dict[key]
merge.update(renamed_port_cols)
print(header_row[3:-3])
for name in header_row[3:-3]:
temp_list.append(merge[name])
csvwriter.writerow(temp_list)
@@ -1323,6 +1322,7 @@ class L3CXProfile(LFCliBase):
#comparison to last report / report inputted
if compared_report is not None:
compared_df = self.compare_two_df(dataframe_one=self.file_to_df(report_file), dataframe_two=self.file_to_df(compared_report))
exit(1)
#append compared df to created one
if output_format.lower() != 'csv':
self.df_to_file(dataframe=pd.read_csv(report_file), output_f=output_format, save_path=report_file)

View File

@@ -314,8 +314,10 @@ python3 ./test_ipv4_variable_time.py
compared_report_format=args.compared_report.split('.')[-1]
#if compared_report_format not in ['csv', 'json', 'dta', 'pkl','html','xlsx','parquet','h5']:
if compared_report_format != 'csv':
ValueError("Cannot process this file type. Please select a different file and re-run script.")
print(ValueError("Cannot process this file type. Please select a different file and re-run script."))
exit(1)
else:
compared_rept=args.compared_report
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000,
radio=args.radio)