Commit 9da0236e authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers 🐦

add collate script to make it esay for me to find

parent b62b9e12
Pipeline #2358 failed with stages
in 42 seconds
#! /usr/bin/env python3
import pathlib
import csv
FIELD_NAMES = ['gameId', 'agentUnderTest', 'agentPaired', 'gameType', 'p1', 'p2', 'p3', 'p4', 'p5', 'seed', 'players', 'information', 'lives', 'moves', 'score', 'disqal', 'model']
EXPECTED_ROWS = 12
EXPECTED_FILES = 200 #200
def main(results_dir, outfile="results.csv"):
data_dir = pathlib.Path(results_dir) / "results"
print(data_dir)
had_errors = False
files_seen = 0
lines = []
for filename in data_dir.glob("*.o*"):
file_lines = []
with open(filename, 'r') as f:
csv_reader = csv.DictReader(f, fieldnames=FIELD_NAMES)
for row in csv_reader:
# Sanity Check 1 - is None a key in the dictionary?
if None in row:
print("Too many columns, CSV reader dumped extra data for: {}".format(row))
had_errors = True
# Sanity Check 1a - Are there missing values?
for field in FIELD_NAMES:
if row[field] == None:
print("Field {} was empty for row".format(field))
had_errors = True
file_lines.append(row)
# Sanity Check 2 - Are there the correct number of lines?
if len(file_lines) != EXPECTED_ROWS:
print("Error processing {}, expected: {} rows, got {}".format(filename, EXPECTED_ROWS, len(file_lines)))
#had_errors = True
files_seen += 1
lines += file_lines
# Sanity check 3 - Did we see all the expected files
if files_seen != EXPECTED_FILES:
print("uncorrect number of files seen: expected {}, got {}".format(EXPECTED_FILES, files_seen))
#had_errors = True
# if we had errors processing the file, abort
if had_errors:
print("There were failures, aborting")
return
# Now we're ok with the structure, we should save our CSV data
with open(outfile, 'w', newline='') as f:
csv_writer = csv.DictWriter(f, fieldnames=FIELD_NAMES)
csv_writer.writeheader()
for line in lines:
csv_writer.writerow(line)
if __name__ == '__main__':
main('track-16/', outfile="track16.csv")
main('track-17/', outfile="track17.csv")
main('track-18/', outfile="track18.csv")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment