commented out broken code, added code so output_format and report_file exten. is passed in, exten is changed to csv to create file, then csv is changed to correct output format

This commit is contained in:
Dipti
2021-02-09 18:32:54 -08:00
parent a3e1f572c6
commit c3c0924cda
3 changed files with 13 additions and 15 deletions

View File

@@ -633,9 +633,9 @@ class LFCliBase:
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'")')
#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):

View File

@@ -1186,11 +1186,13 @@ class L3CXProfile(LFCliBase):
raise ValueError("L3CXProfile::monitor wants a list of column names to monitor")
if output_format is not None:
if output_format.lower() != report_file.split('.')[-1]:
if output_format.lower() != 'csv':
raise ValueError('Filename %s does not match output format %s' % (report_file, output_format))
raise ValueError('Filename %s has an extension that does not match output format %s .' % (report_file, output_format))
else:
output_format = report_file.split('.')[-1]
#default save to csv first
if report_file.split('.')[-1] != 'csv':
report_file = report_file.replace(str(output_format),'csv',1)
#retrieve compared report if specified - turn into dataframe === under construction ===
if compared_report is not None:
@@ -1268,10 +1270,10 @@ class L3CXProfile(LFCliBase):
csvfile.close()
#here, do column manipulations
#here, do df to final report file output
if output_format.lower() != 'csv':
dataframe_output = self.file_to_df()
dataframe_output = self.file_to_df(report_file, output_format)

View File

@@ -268,21 +268,17 @@ python3 ./test_ipv4_variable_time.py
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)
os.mkdir(path)
if args.output_format in ['csv','json','html','hdf','stata','pickle','pdf','png','df','parquet','xlsx']:
#always save to csv first
report_f= str(path) + '/data.csv'
#report_f= str(path) + '/data.' + args.output_format
print(report_f)
report_f= str(path) + '/data.' + args.output_format
output=args.output_format
else:
print('Defaulting to csv data file output type, naming it data.csv.')
report_f= str(path)+'/data.csv'
print(report_f)
output='csv'
if self.debug:
print("Saving report data in ... " + report_f)
else:
report_f=args.report_file
if args.output_format is None: