Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.63 KB | None | 0 0
  1. import os
  2. import csv
  3.  
  4. path = os.listdir("C:\\Users\\elias\\Documents")
  5. CompletePath = "C:\\Users\\elias\\Documents\\Complete"
  6. #Combine logfiles
  7. for file in path:
  8.     output_line = ""
  9.     first_bench = file.partition("-")[0]
  10.     if file.startswith("4"):
  11.         with open(file, 'r') as input_file, open(os.path.join(CompletePath, 'ALL.txt'), 'a') as output_file:
  12.             lines = input_file.read().splitlines()
  13.  
  14.             if first_bench in lines[0]:
  15.                 for line in lines:
  16.                     output_line += line
  17.                     output_line += " "
  18.             else:
  19.                 #swap lines
  20.                 lines[0], lines[1] = lines[1], lines[0]
  21.                 for line in lines:
  22.                     output_line += line
  23.                     output_line += " "
  24.  
  25.             #Columns in right order
  26.             output_line = output_line.split(" ")
  27.             output_line[1], output_line[2] = output_line[2], output_line[1]
  28.             output_line = " ".join(output_line)
  29.  
  30.             output_file.write(output_line)
  31.             output_file.write("\n")
  32.  
  33. #Create seperate files for each program
  34. if __name__ == '__main__':
  35.     benchmark_list = ['400.perlbench.sh', '401.bzip2.sh', '403.gcc.sh', '429.mcf.sh', '445.gobmk.sh', '456.hmmer.sh', '458.sjeng.sh', '462.libquantum.sh', '464.h264ref.sh', '471.omnetpp.sh', '473.astar.sh', '483.xalancbmk.sh']
  36.     for benchmark in benchmark_list:
  37.         with open(os.path.join(CompletePath, 'ALL.txt'), 'r') as input_file, open(os.path.join(CompletePath,'{}.txt'.format(benchmark)), 'w') as output_file:
  38.             lines = input_file.read().splitlines()
  39.             output_data = []
  40.  
  41.             for line in lines:
  42.                 columns = line.split(' ')
  43.                 if benchmark in line:
  44.                     if benchmark in columns[0]:
  45.                         output_data.append(" ".join(columns))
  46.            
  47.                     else:
  48.                         columns[0], columns[1] = columns[1], columns[0]
  49.                         columns[2], columns[3] = columns[3], columns[2]
  50.                         output_data.append(" ".join(columns))
  51.             output_data = sorted(output_data, key=lambda x: float(x.split(" ")[2]), reverse=True)
  52.             for line in output_data:
  53.                 output_file.write(line)
  54.                 output_file.write("\n")
  55. #Convert all files to .csv
  56. os.chdir(CompletePath)
  57. for filename in os.listdir(CompletePath):
  58.     txt_file = filename
  59.     csv_file = filename.replace('.txt', '.csv')
  60.  
  61.     in_txt = csv.reader(open(txt_file, 'r'), delimiter = ' ')
  62.     out_csv = csv.writer(open(csv_file, 'w'))
  63.  
  64.     out_csv.writerows(in_txt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement