Cleans table generation and transposes output

This commit is contained in:
LSaldyt
2018-01-12 14:30:35 -07:00
parent 0a0369f5e1
commit 6215ccb08a

View File

@ -24,22 +24,27 @@ def main(args):
tableItems = key_sorted_items(crossTable) tableItems = key_sorted_items(crossTable)
assert len(tableItems) > 0, 'Empty table' assert len(tableItems) > 0, 'Empty table'
with open('output/cross_compare.csv', 'w') as outfile: headKey, headSubDict = tableItems[0]
headKey, headSubDict = tableItems[0] # Create table and add headers
cells = ['problems x variants'] table = [['problems x variants']]
for subkey, subsubdict in key_sorted_items(headSubDict): for subkey, subsubdict in key_sorted_items(headSubDict):
for subsubkey, result in key_sorted_items(subsubdict): for subsubkey, result in key_sorted_items(subsubdict):
cells.append('{} x {} for {} x {}'.format(*subkey, *subsubkey)) table[-1].append('{} x {} for {} x {}'.format(*subkey, *subsubkey))
outfile.write(','.join(cells) + '\n')
for key, subdict in tableItems: # Add test results to table
cells = [] for key, subdict in tableItems:
problem = '{}:{}::{}:_'.format(*key) table.append([])
cells.append(problem) problem = '{}:{}::{}:_'.format(*key)
for subkey, subsubdict in key_sorted_items(subdict): table[-1].append(problem)
for subsubkey, result in key_sorted_items(subsubdict): for subkey, subsubdict in key_sorted_items(subdict):
cells.append(str(result)) for subsubkey, result in key_sorted_items(subsubdict):
outfile.write(','.join(cells) + '\n') table[-1].append(str(result))
# A simple transpose
table = list(map(list, zip(*table)))
with open('output/cross_compare.csv', 'w') as outfile:
outfile.write('\n'.join(','.join(row) for row in table) + '\n')
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':