Skip to content

Commit

Permalink
quick bugfix to results file
Browse files Browse the repository at this point in the history
  • Loading branch information
willwill2will54 committed Jul 11, 2018
1 parent b26e3c0 commit 5b6dcff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 3 additions & 5 deletions lib/testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def tester(table, MAT, algorithm=['geormsd', 'wgt', '500'], number=None, testing=False):
def tester(table, MAT, algorithm=['geormsd', 'wgt', '500'], number=None, testing=False, go=1):
from collections import Counter
from tinydb import TinyDB, Query
from pprint import pprint
Expand Down Expand Up @@ -83,7 +83,7 @@ def tester(table, MAT, algorithm=['geormsd', 'wgt', '500'], number=None, testing
x['sims'] += float(value)
errorcount += 1
donecand.append(dict(x))
if errorcount > 0:
if errorcount > 0 and go == 0:
print('Weight exception: \'{}\' not found ({}/{})'.format(key, errorcount, len(cand)), flush=True)
cand = donecand[:]

Expand All @@ -104,15 +104,13 @@ def tester(table, MAT, algorithm=['geormsd', 'wgt', '500'], number=None, testing
lastthing = finlist
else:
dict1 = {x: [] for x in defs.ProgressScoreHeaders}
dict2 = dict(dict1)
dict2 = {x: [] for x in defs.ProgressScoreHeaders}
for x in finlist[:number]:
for ID in next(item for item in counterpack if item['Trust name'] == x[0])['IDs']:
school = core.get(doc_id=ID)
for y, z in school.items():
if y in defs.ProgressScoreHeaders:
dict1[y].append(float(z))
else:
pass
for ID in tested['IDs']:
school = core.get(doc_id=ID)
for y, z in school.items():
Expand Down
12 changes: 9 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def main():
test = subparsers.add_parser('Test', help='''\
Runs Testing Utililty''')

can.add_argument('--multi', '-m', type=int, default=10, metavar='x', help='''\
can.add_argument('--multi', '-m', type=int, default=50, metavar='x', help='''\
Displays x most similar MATs''')
test.add_argument('--plural', '-p', type=int, default=20, metavar='x', help='''\
Splits this many of the MATs into 2.''')
Expand All @@ -104,22 +104,28 @@ def doit(algorithm, tested, num, testing=False):
if algorithm in (None, ['defaults', ], 'defaults'):
algorithm = defs.algorithm
if tested is not None:
chain = itertools.chain.from_iterable
importkeys = []
for a, b in zip(algorithm[:-3:4], algorithm[1:-2:4]):
importkeys += [a, b]
table = importer(importkeys, testing=testing)[0]
retresults = []
with multiprocess.Pool(processes=defs.threadcount) as pool:
partthing = partial(tester, table, algorithm=algorithm, number=num, testing=testing)
for result in pool.imap_unordered(partthing, tested):
if len(tested) > 1:
first = [partthing(tested.pop() go=0), ]
partthing = partial(tester, table, algorithm=algorithm, number=num, testing=testing, go=1)
else:
first = []

for result in chain(first, pool.imap_unordered(partthing, tested)):
print('{} is most similar to {}\n'.format(result[2], ' then '.join(result[0])), flush=True)
retresults.append((result[2], result[1]))
if testing:
return retresults
else:
with open('result.csv', 'w', encoding='utf-16') as resultsfile:
print('Writing results to file...', flush=True)
chain = itertools.chain.from_iterable
fields = sorted(list(chain(['Average ' + x, 'Subject ' + x] for x in defs.ProgressScoreHeaders)))
writer = csv.DictWriter(resultsfile, fieldnames=['MAT', ] + fields)
writer.writeheader()
Expand Down
Binary file modified result.csv
Binary file not shown.

0 comments on commit 5b6dcff

Please sign in to comment.