|
|
|
@ -1,14 +1,15 @@
|
|
|
|
|
import pymongo, json
|
|
|
|
|
|
|
|
|
|
print('ver: 1.1')
|
|
|
|
|
print('ver: 1.5')
|
|
|
|
|
# dbprep
|
|
|
|
|
fsroot = '/autograder/source/'
|
|
|
|
|
datasets = ['congress', 'bills']
|
|
|
|
|
db = pymongo.MongoClient('mongodb://127.0.0.1')['test']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def postproc_str(data : str): # relaxed str matching
|
|
|
|
|
import re
|
|
|
|
|
data = re.sub(r'[\s|_]', '', data.lower())
|
|
|
|
|
data = re.sub(r'[\s|_|.]', '', data.lower())
|
|
|
|
|
return re.sub(r'sponser', 'sponsor', data)
|
|
|
|
|
|
|
|
|
|
def comparator(a, b):
|
|
|
|
@ -40,7 +41,7 @@ def comparator(a, b):
|
|
|
|
|
return cmp(f'{a}', f'{b}')
|
|
|
|
|
case _:
|
|
|
|
|
return cmp(hash(type(a)), hash(type(b)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def postproc_iter(data):
|
|
|
|
|
from collections.abc import Iterable
|
|
|
|
|
from functools import cmp_to_key
|
|
|
|
@ -63,13 +64,17 @@ def postproc_iter(data):
|
|
|
|
|
except Exception as e: # fail proof
|
|
|
|
|
print(e)
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def evaluate(query : str):
|
|
|
|
|
import re
|
|
|
|
|
query = re.sub(r'(\$?[\d\w_]+)\s*:', r'"\1" :', query)
|
|
|
|
|
query = re.sub(r'[\r|\n]|.\s*pretty\s*\(\s*\)', '', query).strip()
|
|
|
|
|
query = re.sub(r'//[^\n]*', '', query)
|
|
|
|
|
query = re.sub(r'(\$?[\d\w_]+)[\s\r\n]*:', r'"\1" :', query)
|
|
|
|
|
query = re.sub(r'[\r\n]|.\s*pretty\s*\(\s*\)|.\s*sort\s*\([^\)]*\)', '', query).strip()
|
|
|
|
|
query = re.sub(r'.\s*aggregate\s*\(\s*([^\[^\s][^\)]*)\)', r'.aggregate([\1])', query)
|
|
|
|
|
|
|
|
|
|
if query.endswith(';'): query = query[:-1]
|
|
|
|
|
true = True
|
|
|
|
|
return postproc_iter(list(eval(query))) if query else None
|
|
|
|
|
|
|
|
|
|
for d in datasets:
|
|
|
|
@ -106,6 +111,8 @@ def grade78(ans, i):
|
|
|
|
|
a[ak] = t
|
|
|
|
|
if a not in sol:
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
sol.remove(a)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
return False
|
|
|
|
|