From dda9b4574025ab7dcaf143f050215a05a7af6e01 Mon Sep 17 00:00:00 2001 From: Dipti Date: Mon, 8 Feb 2021 22:51:05 -0800 Subject: [PATCH] fixed path saving. added script and LANforge information to csv file. copied df to other file output conversions --- py-json/LANforge/lfcli_base.py | 23 +++--------------- py-json/realm.py | 16 ++++++++++-- py-scripts/test_ipv4_variable_time.py | 35 ++++++++++++++++----------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/py-json/LANforge/lfcli_base.py b/py-json/LANforge/lfcli_base.py index 34c5eb15..87b2943b 100644 --- a/py-json/LANforge/lfcli_base.py +++ b/py-json/LANforge/lfcli_base.py @@ -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 diff --git a/py-json/realm.py b/py-json/realm.py index 7a99778a..6fedd106 100755 --- a/py-json/realm.py +++ b/py-json/realm.py @@ -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): diff --git a/py-scripts/test_ipv4_variable_time.py b/py-scripts/test_ipv4_variable_time.py index 3d11c12d..97416738 100755 --- a/py-scripts/test_ipv4_variable_time.py +++ b/py-scripts/test_ipv4_variable_time.py @@ -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: