Last active
April 24, 2016 13:11
-
-
Save RichardB01/6d57394b03ae30d93cea1a645a5f040f to your computer and use it in GitHub Desktop.
This was one of two scripts produced for a piece of coursework at the University of Hull for the 08227 ACW 2016. Placed in C:/timings directory. EXAMPLE USEAGE "python this_script.py smalldataset"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import sys | |
| import re | |
| import subprocess | |
| processedRows = 0 | |
| dataSetPartialName = sys.argv[1] ## only import data from files with s in the name. | |
| ## remove text and write to outfile | |
| for folder, subs, files in os.walk("C:/timings"): | |
| with open(os.path.join(folder, 'timing-data-' + dataSetPartialName + '.txt'), 'w') as dest: | |
| for filename in files: | |
| if filename == "08227.py" or not dataSetPartialName in filename or "timing" in filename: | |
| continue | |
| else: | |
| with open(os.path.join(folder, filename), 'r') as src: | |
| lineNumber = 1 | |
| for line in src: | |
| result = re.search(" - (.*) seconds", line) | |
| if result is not None: | |
| timing = result.group(1) | |
| processedRows = processedRows + 1 | |
| lineNumber = lineNumber + 1 | |
| if lineNumber <= 9: | |
| dest.write(timing + ",") | |
| else: | |
| dest.write(timing + "\n") | |
| print("Processed " + str(processedRows) + " rows.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment