Compare commits

..

No commits in common. '8901a7d2e2f2b6a77e876bd46dfd0b4563a2c2ea' and 'b97109833516ea9f21259d46269edcc14acd9d1c' have entirely different histories.

1
.gitignore vendored

@ -1 +0,0 @@
playground.*

@ -5,70 +5,11 @@ 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
return re.sub(r'[\s|_]', '', data.lower())
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:
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
else: return 1
return 0
from bson import ObjectId
match (a, b):
case (dict(), dict()):
return itcmp([*a.keys(), *a.values()], [*b.keys(), *b.values()])
case (ObjectId(aa), ObjectId(bb)):
return cmp(aa, bb)
case (Iterable(), Iterable()):
return itcmp(a, b)
case _ if type(a) == type(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
try:
match data:
case str():
return postproc_str(data)
case dict():
return { postproc_iter(k):postproc_iter(v) for k, v in data.items() }
case Iterable(): # flatten, remove order and empty iterables
res = type(data)(
sorted(
[postproc_iter(d) for d in data
if not isinstance(d, Iterable) or d]
, key = cmp_to_key(comparator))
)
return res[0] if len(res) == 1 else res
case _: # primitives
return 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'(\$?[\d\w]+)\s*:', r'"\1" :', query)
query = re.sub(r'[\r|\n]|.\s*pretty\s*\(\s*\)', '', query).strip()
if query.endswith(';'): query = query[:-1]
return postproc_iter(list(eval(query))) if query else None
return list(eval(query))[0] if query else None
for d in datasets:
with open(fsroot + d + '.json', encoding = 'utf-8') as f:
@ -97,16 +38,13 @@ if submissions:
module = module_from_spec(spec)
spec.loader.exec_module(module)
q = getattr(module, f'query{i + 1}')()
ans = evaluate(q)
if ans == answers[i]:
if evaluate(q) == answers[i]:
grade += 1
feedback += 'Correct.\n'
else:
feedback += 'Wrong Answer.\n'
print('ans: ', ans, '\nsol: ', answers[i])
except Exception as e:
except Exception:
feedback += 'Runtime Error.\n'
print (e)
else:
feedback += 'No python file in submission.\n'

@ -30,7 +30,7 @@ sols = ['db.bills.find({sponsor_name:"Marco Rubio"}, {_id:0, title: 1, sponsor_n
foreignField: "sponsor_state",
as:"otherBills"} },
{ $unwind: "$otherBills" },
{ $project: {title: 1, sponsor_name: 1, sponsor_state: 1, otherbill_id: "$otherBills._id", otherbill_title: "$otherBills.title", otherbill_sponsor_name: "$otherBills.sponsor_name", otherbill_sponsor_state: "$otherBills.sponsor_state"}},
{ $project: {title: 1, sponsor_name: 1, sponsor_state: 1, otherbill_id: "$otherBills._id", otherbill_title: "$otherBills.title", otherbill_sponser_name: "$otherBills.sponsor_name", otherbill_sponsor_state: "$otherBills.sponsor_state"}},
{ $match: {$expr: {$lt: ["$_id", "$otherbill_id"]}}}
])''',
'''db.congress.aggregate([

@ -4,64 +4,9 @@ import neo4j, json
fsroot = '/autograder/source/'
datasets = ['Neo4J_dataset']
db = neo4j.GraphDatabase.driver('bolt://localhost:7687', auth = ('neo4j', '4Sfz541Lm')).session()
def postproc_str(data : str): # relaxed str matching
import re
return re.sub(r'[\s|_]', '', data.lower())
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:
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
else: return 1
return 0
match (a, b):
case (dict(), dict()):
return itcmp([*a.keys(), *a.values()], [*b.keys(), *b.values()])
case (Iterable(), Iterable()):
return itcmp(a, b)
case _ if type(a) == type(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
try:
match data:
case str():
return postproc_str(data)
case dict():
return { postproc_iter(k):postproc_iter(v) for k, v in data.items() }
case Iterable(): # flatten, remove order and empty iterables
res = type(data)(
sorted(
[postproc_iter(d) for d in data
if not isinstance(d, Iterable) or d]
, key = cmp_to_key(comparator))
)
return res[0] if len(res) == 1 else res
case _: # primitives
return data
except Exception as e: # fail proof
print(e)
return data
def evaluate(query : str):
query = query.strip()
return postproc_iter(db.run(query).data()) if query else None
return db.run(query).data() if query else None
while True:
try:
@ -98,19 +43,19 @@ if submissions:
spec.loader.exec_module(module)
q = getattr(module, f'query{i + 1}')()
def eq(a: list, b):
if a is None: return False
if type(b) is tuple:
return any(eq(a, bb) for bb in b)
else: return a == b
ans = evaluate(q)
if eq(ans, answers[i]):
if len(a) != len(b): return False
return all(aa == bb for aa, bb in zip(a, b))
if eq(evaluate(q), answers[i]):
grade += 1
feedback += 'Correct.\n'
else:
feedback += 'Wrong Answer.\n'
print('ans: ', ans, '\nsol: ', answers[i])
except Exception as e:
except Exception:
feedback += 'Runtime Error.\n'
print(e)
else:
feedback += 'No python file in submission.\n'

@ -7,4 +7,4 @@ sed -i '1s/^/server.default_listen_address=0.0.0.0\n/' /etc/neo4j/neo4j.conf
systemctl enable --now neo4j
neo4j-admin dbms set-initial-password 4Sfz541Lm --require-password-change=false
python3 -m pip install neo4j
python3 -m pip install neo4j

Loading…
Cancel
Save