Skip to content

Commit 5b6dcff

Browse files
quick bugfix to results file
1 parent b26e3c0 commit 5b6dcff

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

.DS_Store

0 Bytes
Binary file not shown.

lib/testing.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def tester(table, MAT, algorithm=['geormsd', 'wgt', '500'], number=None, testing=False):
1+
def tester(table, MAT, algorithm=['geormsd', 'wgt', '500'], number=None, testing=False, go=1):
22
from collections import Counter
33
from tinydb import TinyDB, Query
44
from pprint import pprint
@@ -83,7 +83,7 @@ def tester(table, MAT, algorithm=['geormsd', 'wgt', '500'], number=None, testing
8383
x['sims'] += float(value)
8484
errorcount += 1
8585
donecand.append(dict(x))
86-
if errorcount > 0:
86+
if errorcount > 0 and go == 0:
8787
print('Weight exception: \'{}\' not found ({}/{})'.format(key, errorcount, len(cand)), flush=True)
8888
cand = donecand[:]
8989

@@ -104,15 +104,13 @@ def tester(table, MAT, algorithm=['geormsd', 'wgt', '500'], number=None, testing
104104
lastthing = finlist
105105
else:
106106
dict1 = {x: [] for x in defs.ProgressScoreHeaders}
107-
dict2 = dict(dict1)
107+
dict2 = {x: [] for x in defs.ProgressScoreHeaders}
108108
for x in finlist[:number]:
109109
for ID in next(item for item in counterpack if item['Trust name'] == x[0])['IDs']:
110110
school = core.get(doc_id=ID)
111111
for y, z in school.items():
112112
if y in defs.ProgressScoreHeaders:
113113
dict1[y].append(float(z))
114-
else:
115-
pass
116114
for ID in tested['IDs']:
117115
school = core.get(doc_id=ID)
118116
for y, z in school.items():

main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def main():
7979
test = subparsers.add_parser('Test', help='''\
8080
Runs Testing Utililty''')
8181

82-
can.add_argument('--multi', '-m', type=int, default=10, metavar='x', help='''\
82+
can.add_argument('--multi', '-m', type=int, default=50, metavar='x', help='''\
8383
Displays x most similar MATs''')
8484
test.add_argument('--plural', '-p', type=int, default=20, metavar='x', help='''\
8585
Splits this many of the MATs into 2.''')
@@ -104,22 +104,28 @@ def doit(algorithm, tested, num, testing=False):
104104
if algorithm in (None, ['defaults', ], 'defaults'):
105105
algorithm = defs.algorithm
106106
if tested is not None:
107+
chain = itertools.chain.from_iterable
107108
importkeys = []
108109
for a, b in zip(algorithm[:-3:4], algorithm[1:-2:4]):
109110
importkeys += [a, b]
110111
table = importer(importkeys, testing=testing)[0]
111112
retresults = []
112113
with multiprocess.Pool(processes=defs.threadcount) as pool:
113114
partthing = partial(tester, table, algorithm=algorithm, number=num, testing=testing)
114-
for result in pool.imap_unordered(partthing, tested):
115+
if len(tested) > 1:
116+
first = [partthing(tested.pop() go=0), ]
117+
partthing = partial(tester, table, algorithm=algorithm, number=num, testing=testing, go=1)
118+
else:
119+
first = []
120+
121+
for result in chain(first, pool.imap_unordered(partthing, tested)):
115122
print('{} is most similar to {}\n'.format(result[2], ' then '.join(result[0])), flush=True)
116123
retresults.append((result[2], result[1]))
117124
if testing:
118125
return retresults
119126
else:
120127
with open('result.csv', 'w', encoding='utf-16') as resultsfile:
121128
print('Writing results to file...', flush=True)
122-
chain = itertools.chain.from_iterable
123129
fields = sorted(list(chain(['Average ' + x, 'Subject ' + x] for x in defs.ProgressScoreHeaders)))
124130
writer = csv.DictWriter(resultsfile, fieldnames=['MAT', ] + fields)
125131
writer.writeheader()

result.csv

134 KB
Binary file not shown.

0 commit comments

Comments
 (0)