fixed path saving. added script and LANforge information to csv file. copied df to other file output conversions

This commit is contained in:
Dipti
2021-02-08 22:51:05 -08:00
parent f95974b1e7
commit dda9b45740
3 changed files with 39 additions and 35 deletions

View File

@@ -617,10 +617,10 @@ class LFCliBase:
return df.to_excel(output_file_type, index=False)
if output_file_type == 'df':
return df
supported_formats = ['csv', 'json', 'stata', 'pickle','html']
for format in supported_formats:
if output_file_type.lower() == format:
return exec('df.to_' + x + '("'+file_name'")')
#supported_formats = ['csv', 'json', 'stata', 'pickle','html']
#for format in supported_formats:
# if output_file_type.lower() == format:
# return exec('df.to_' + x + '("'+file_name'")')
#takes any format of a file and returns a dataframe of it
def file_to_df(file_type, file_name):
@@ -629,19 +629,4 @@ class LFCliBase:
def append_df_to_file(dataframe, file_name):
pass
#dataframe conversion
# df = pd.DataFrame(full_test_data_list)
# df=df[["Timestamp","Timestamp milliseconds", *header_row[:-2]]]
#compare previous data to current data
#systeminfo = self.json_get('/')
# df['LFGUI Release'] = systeminfo['VersionInfo']['BuildVersion']
# df['Script Name'] = script_name
# df['Arguments'] = arguments
# for x in ['LFGUI Release', 'Script Name', 'Arguments']:
# df[x][1:] = ''
#
# ~class

View File

@@ -1190,7 +1190,9 @@ class L3CXProfile(LFCliBase):
raise ValueError('Filename %s does not match output format %s' % (report_file, output_format))
else:
output_format = report_file.split('.')[-1]
#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:
supported_formats = ['csv', 'json', 'stata', 'pickle','html']
for format in supported_formats:
@@ -1217,6 +1219,12 @@ class L3CXProfile(LFCliBase):
#instantiate csv file here, add specified column headers
csvfile=open(str(report_file),'w')
csvwriter = csv.writer(csvfile,delimiter=",")
#write system info to csv
systeminfo = self.json_get('/')
csvwriter.writerow(systeminfo['VersionInfo']['BuildVersion'])
csvwriter.writerow(script_name)
#csvwriter.writerow(arguments)
csvwriter.writerow(header_row)
# for x in range(0,int(round(iterations,0))):
@@ -1258,8 +1266,12 @@ class L3CXProfile(LFCliBase):
old_cx_rx_values = new_cx_rx_values
time.sleep(monitor_interval)
csvfile.close()
#here, do column manipulations
#here,
dataframe_output = self.file_to_df()
#here, do csv to df
#here, do df to final report file output
def refresh_cx(self):

View File

@@ -267,25 +267,32 @@ python3 ./test_ipv4_variable_time.py
num_sta = int(args.num_stations)
#Create directory
if args.report_file is None:
try:
homedir = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M")).replace(':','-')+'test_ipv4_variable_time'
path = os.path.join('/home/lanforge/report-data/',homedir)
os.mkdir(path)
except:
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print('Saving file to local directory')
else:
pass
#if file path with output file extension is not given...
# check if home/lanforge/report-data exists. if not, save
# in new folder based in current file's directory
if args.report_file is None:
new_file_path = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M")).replace(':','-')+'test_ipv4_variable_time' #create path name
try:
path = os.path.join('/home/lanforge/report-data/',new_file_path)
os.mkdir(path)
except:
curr_dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
path = os.path.join(curr_dir_path, new_file_path)
os.mkdir(path)
print('Saving file to ' + path)
if args.output_format in ['csv','json','html','hdf','stata','pickle','pdf','png','df','parquet','xlsx']:
report_f='/home/lanforge/report-data/'+homedir+'/data.' + args.output_format
report_f= str(path) + '/data.' + args.output_format
print(report_f)
output=args.output_format
else:
print('Defaulting data file output type to Excel')
report_f='/home/lanforge/report-data/'+homedir+'/data.xlsx'
output='xlsx'
print('Defaulting to csv data file output type, naming it data.csv.')
report_f= str(path)+'/data.csv'
print(report_f)
output='csv'
else:
report_f=args.report_file
if args.output_format is None: