|
|
@ -1,5 +1,6 @@
|
|
|
|
import pymongo, json
|
|
|
|
import pymongo, json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print('ver: 1.1')
|
|
|
|
# dbprep
|
|
|
|
# dbprep
|
|
|
|
fsroot = '/autograder/source/'
|
|
|
|
fsroot = '/autograder/source/'
|
|
|
|
datasets = ['congress', 'bills']
|
|
|
|
datasets = ['congress', 'bills']
|
|
|
@ -7,22 +8,23 @@ db = pymongo.MongoClient('mongodb://127.0.0.1')['test']
|
|
|
|
|
|
|
|
|
|
|
|
def postproc_str(data : str): # relaxed str matching
|
|
|
|
def postproc_str(data : str): # relaxed str matching
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
return re.sub(r'[\s|_]', '', data.lower())
|
|
|
|
data = re.sub(r'[\s|_]', '', data.lower())
|
|
|
|
|
|
|
|
return re.sub(r'sponser', 'sponsor', data)
|
|
|
|
|
|
|
|
|
|
|
|
def comparator(a, b):
|
|
|
|
def comparator(a, b):
|
|
|
|
cmp = lambda x, y: 1 if x < y else -1 if x > y else 0
|
|
|
|
cmp = lambda x, y: 1 if x < y else -1 if x > y else 0
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
return cmp(a, b)
|
|
|
|
return cmp(a, b)
|
|
|
|
except Exception as e:
|
|
|
|
except Exception:
|
|
|
|
from collections.abc import Iterable
|
|
|
|
from collections.abc import Iterable
|
|
|
|
def itcmp(a: Iterable, b: Iterable):
|
|
|
|
def itcmp(a: Iterable, b: Iterable):
|
|
|
|
if len(a) < len(b):
|
|
|
|
if len(a) < len(b):
|
|
|
|
return -1
|
|
|
|
return -1
|
|
|
|
elif len(a) == len(b):
|
|
|
|
elif len(a) == len(b):
|
|
|
|
for aa, bb in zip(a, b):
|
|
|
|
for aa, bb in zip(a, b):
|
|
|
|
cmp = comparator(aa, bb)
|
|
|
|
c = comparator(aa, bb)
|
|
|
|
if cmp != 0:
|
|
|
|
if c != 0:
|
|
|
|
return cmp
|
|
|
|
return c
|
|
|
|
else: return 1
|
|
|
|
else: return 1
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
|
from bson import ObjectId
|
|
|
|
from bson import ObjectId
|
|
|
@ -87,6 +89,30 @@ submissions = [subroot + f for f in listdir(subroot) if f.strip().lower().endswi
|
|
|
|
grade = 0
|
|
|
|
grade = 0
|
|
|
|
n_queries = len(sols)
|
|
|
|
n_queries = len(sols)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def grade78(ans, i):
|
|
|
|
|
|
|
|
sol = answers[i]
|
|
|
|
|
|
|
|
others = ('otherbill', 'otherperson')[i - 6]
|
|
|
|
|
|
|
|
if type(ans) != list or len(ans) != len(sol):
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
for a in ans:
|
|
|
|
|
|
|
|
if a not in sol:
|
|
|
|
|
|
|
|
if type(a) is dict:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
for ak in a.keys():
|
|
|
|
|
|
|
|
if ak.startswith(others):
|
|
|
|
|
|
|
|
key_others = ak[len(others):]
|
|
|
|
|
|
|
|
t = a[key_others]
|
|
|
|
|
|
|
|
a[key_others] = a[ak]
|
|
|
|
|
|
|
|
a[ak] = t
|
|
|
|
|
|
|
|
if a not in sol:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
if submissions:
|
|
|
|
if submissions:
|
|
|
|
submission = submissions[0]
|
|
|
|
submission = submissions[0]
|
|
|
|
|
|
|
|
|
|
|
@ -98,7 +124,12 @@ if submissions:
|
|
|
|
spec.loader.exec_module(module)
|
|
|
|
spec.loader.exec_module(module)
|
|
|
|
q = getattr(module, f'query{i + 1}')()
|
|
|
|
q = getattr(module, f'query{i + 1}')()
|
|
|
|
ans = evaluate(q)
|
|
|
|
ans = evaluate(q)
|
|
|
|
if ans == answers[i]:
|
|
|
|
def eq(i):
|
|
|
|
|
|
|
|
if i in (6, 7):
|
|
|
|
|
|
|
|
return grade78(ans, i)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return ans == answers[i]
|
|
|
|
|
|
|
|
if eq(i):
|
|
|
|
grade += 1
|
|
|
|
grade += 1
|
|
|
|
feedback += 'Correct.\n'
|
|
|
|
feedback += 'Correct.\n'
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|