master
bill 6 months ago
parent 8901a7d2e2
commit 1af680b561

@ -1,5 +1,6 @@
import pymongo, json
print('ver: 1.1')
# dbprep
fsroot = '/autograder/source/'
datasets = ['congress', 'bills']
@ -7,22 +8,23 @@ db = pymongo.MongoClient('mongodb://127.0.0.1')['test']
def postproc_str(data : str): # relaxed str matching
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):
cmp = lambda x, y: 1 if x < y else -1 if x > y else 0
try:
return cmp(a, b)
except Exception as e:
except Exception:
from collections.abc import Iterable
def itcmp(a: Iterable, b: Iterable):
if len(a) < len(b):
return -1
elif len(a) == len(b):
for aa, bb in zip(a, b):
cmp = comparator(aa, bb)
if cmp != 0:
return cmp
c = comparator(aa, bb)
if c != 0:
return c
else: return 1
return 0
from bson import ObjectId
@ -87,6 +89,30 @@ submissions = [subroot + f for f in listdir(subroot) if f.strip().lower().endswi
grade = 0
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:
submission = submissions[0]
@ -98,7 +124,12 @@ if submissions:
spec.loader.exec_module(module)
q = getattr(module, f'query{i + 1}')()
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
feedback += 'Correct.\n'
else:

@ -13,16 +13,16 @@ def comparator(a, b):
cmp = lambda x, y: 1 if x < y else -1 if x > y else 0
try:
return cmp(a, b)
except Exception as e:
except Exception:
from collections.abc import Iterable
def itcmp(a: Iterable, b: Iterable):
if len(a) < len(b):
return -1
elif len(a) == len(b):
for aa, bb in zip(a, b):
cmp = comparator(aa, bb)
if cmp != 0:
return cmp
c = comparator(aa, bb)
if c != 0:
return c
else: return 1
return 0

Loading…
Cancel
Save