-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.py
31 lines (23 loc) · 1.15 KB
/
validate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
import csv
import collections
class ResultConsistencyCheck(object):
def __init__(self):
with open('results.csv') as results_csv:
self.results = list(csv.DictReader(results_csv))
def scores_should_add_up(self):
for row in self.results:
derived_total = sum([int(value) for column, value in row.iteritems() if "score_" in column])
actual_total = int(row['total'])
assert derived_total == actual_total, "[FAIL] Inconsistent total score in row: %s" % row
print("[PASS] All dances have consistent totals")
def series_week_running_order_should_be_unique(self):
unique_ids = ["%s-%s-%s" % (row['series'], row['week'], row['running_order']) for row in self.results]
counts = [item for item, count in collections.Counter(unique_ids).items() if count > 1]
assert not counts, "[FAIL] Non-unique identifiers: %s" % counts
print("[PASS] All dances have unique identifiers")
def run(self):
self.scores_should_add_up()
self.series_week_running_order_should_be_unique()
if __name__ == "__main__":
ResultConsistencyCheck().run()