master
結愛すみか 8 months ago
parent 2d5db639fb
commit b343bb2468

1
.gitignore vendored

@ -1 +1,2 @@
playground.*
__pycache__

@ -1,26 +1,23 @@
# You can change these variables to use a different base image, but
# you must ensure that your base image inherits from one of ours.
# You can also override these at build time with --build-arg flags
ARG BASE_REPO=gradescope/autograder-base
ARG TAG=latest
FROM ${BASE_REPO}:${TAG}
ADD source /autograder/source
RUN python3 -m pip install pymongo
RUN cp /autograder/source/run_autograder /autograder/run_autograder
RUN curl -fsSL https://pgp.mongodb.com/server-7.0.asc | gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
RUN export OS_VER=`cat /etc/os-release | grep VERSION_CODENAME` && \
export OS_VER=${OS_VER#*=} && \
printf "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu "${OS_VER}"/mongodb-org/7.0 multiverse\n">/etc/apt/sources.list.d/mongodb.list
# Ensure that scripts are Unix-friendly and executable
RUN dos2unix /autograder/run_autograder /autograder/source/setup.sh
RUN chmod +x /autograder/run_autograder
RUN apt-get update
RUN mkdir -p /data/db
RUN apt install -y mongodb-org
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Do whatever setup was needed in setup.sh, including installing apt packages
# Cleans up the apt cache afterwards in the same step to keep the image small
RUN apt-get update && \
bash /autograder/source/setup.sh && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ADD source /autograder/source
# You can also use RUN commands in the Dockerfile to install things
# instead of using a bash script
RUN cp /autograder/source/run_autograder /autograder/run_autograder
# The base image defines the CMD and ENTRYPOINT, so don't redefine those
RUN dos2unix /autograder/run_autograder
RUN chmod +x /autograder/run_autograder

@ -1,159 +1,184 @@
import pymongo, json
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())
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:
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):
c = comparator(aa, bb)
if c != 0:
return c
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'//[^\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:
with open(fsroot + d + '.json', encoding = 'utf-8') as f:
db[d].insert_many(json.load(f))
from solution import sols
answers = [evaluate(s) for s in sols]
# grading
from os import listdir
from importlib.util import module_from_spec, spec_from_file_location
subroot = '/autograder/submission/'
feedback = ''
submissions = [subroot + f for f in listdir(subroot) if f.strip().lower().endswith('.py')]
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
else:
sol.remove(a)
except Exception as e:
print(e)
return False
else:
return False
return True
if submissions:
submission = submissions[0]
for i in range(n_queries):
feedback += f'Query {i + 1}: '
try:
spec = spec_from_file_location('curr', submission)
module = module_from_spec(spec)
spec.loader.exec_module(module)
q = getattr(module, f'query{i + 1}')()
ans = evaluate(q)
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:
feedback += 'Wrong Answer.\n'
print('ans: ', ans, '\nsol: ', answers[i])
except Exception as e:
feedback += 'Runtime Error.\n'
print (e)
else:
feedback += 'No python file in submission.\n'
# output
results = {
'output': feedback,
'score': grade * 100 / n_queries,
'max_score': 100,
}
with open('/autograder/results/results.json', 'w') as res:
json.dump(results, res)
import pymongo, json, re
from bson import json_util
print('ver: 1.5')
# dbprep
fsroot = '/autograder/source/'
datasets = ['movies', 'comments']
db = pymongo.MongoClient('mongodb://127.0.0.1')['test']
points = (4,4,5,5,8,8,8,8)
def postproc_str(data : str): # relaxed str matching
return re.sub(r'[\s|_|.]', '', data.lower())
def postproc_keys(data : str):
if type(data) is not str:
return postproc_iter(data)
_dict = {}
data = postproc_str(data)
for k, v in _dict.items():
data = re.sub(k, v, data)
return 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:
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):
c = comparator(aa, bb)
if c != 0:
return c
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, naive = False):
from collections.abc import Iterable
from functools import cmp_to_key
try:
match data:
case str():
return postproc_str(data)
case dict():
return {
(i if naive else postproc_keys(k)) : postproc_iter(v, naive)
for i, (k, v) in enumerate(data.items())
}
case Iterable(): # flatten, remove order and empty iterables
res = type(data)(
sorted(
[postproc_iter(d, naive) 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):
if type(query) is not str:
return tuple(evaluate(q) for q in query)
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()
if not query: return [None] * 2
query = re.sub(r'.\s*aggregate\s*\(\s*([^\[^\s][^\)]*)\)', r'.aggregate([\1])', query)
if query.endswith(';'): query = query[:-1]
true = True
data = list(eval(query))
return [postproc_iter(data, n) if query else None for n in (True, False)]
for d in datasets:
with open(fsroot + d + '.json', encoding = 'utf-8') as f:
# ds = re.sub(r'{\s*"\$oid"\s*:\s*("\w*")\s*}', r'ObjectId(\1)', f.read())
jsonds = '[' + f.read().strip().replace('\n', ',') + ']'
db[d].insert_many(json.loads(jsonds, object_hook=json_util.object_hook))
from solution import sols
answers = [evaluate(s) for s in sols]
# grading
from os import listdir
from importlib.util import module_from_spec, spec_from_file_location
subroot = '/autograder/submission/'
feedback = ''
submissions = [subroot + f for f in listdir(subroot) if f.strip().lower().endswith('.py')]
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
else:
sol.remove(a)
except Exception as e:
print(e)
return False
else:
return False
return True
wa = rte = False
if submissions:
submission = submissions[0]
for i in range(n_queries):
feedback += f'Query {i + 1}: '
try:
spec = spec_from_file_location('curr', submission)
module = module_from_spec(spec)
spec.loader.exec_module(module)
q = getattr(module, f'query{i + 1}')()
ans = evaluate(q)
def eq(i):
_cmp = lambda a, b: any(aa == bb for aa, bb in zip(a, b))
if type(answers[i]) is tuple:
return any(_cmp(ans, aa) for aa in answers[i])
else:
return _cmp(ans, answers[i])
if eq(i):
grade += points[i]
feedback += 'Correct.\n'
else:
feedback += 'Wrong Answer.\n'
wa = True
print('ans: ', ans, '\nsol: ', answers[i])
except Exception as e:
rte = True
feedback += 'Runtime Error.\n'
print (e)
else:
feedback += 'No python file in submission.\n'
max_score = sum(points)
if rte:
feedback += ('\nPlease check for syntax errors first if you encountered runtime errors.\n' +
'If you believe it\'s a mistake, contact the TA at sun1226@purdue.edu for assistance.')
# output
results = {
'output': feedback,
'score': grade,
'max_score': max_score,
}
with open('/autograder/results/results.json', 'w') as res:
json.dump(results, res)

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -8,13 +8,3 @@ cd -
python3 /autograder/source/autograder.py
# files_submitted=$(ls /autograder/submission)
# num_files_submitted=$(ls /autograder/submission/ | wc -l)
# cat > /autograder/results/results.json <<EOF
# {
# "output": "Good job, you passed! Submitted ${num_files_submitted} files: ${files_submitted}",
# "score": 10,
# "max_score": 10
# }
# EOF

@ -1,10 +0,0 @@
apt install -y curl python3 python3-pip
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
export OS_VER=`cat /etc/os-release | grep VERSION_CODENAME` &&\
export OS_VER=${OS_VER#*=} &&\
printf "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu "${OS_VER}"/mongodb-org/7.0 multiverse\n">/etc/apt/sources.list.d/mongodb.list
apt update
apt install -y mongodb-org
mkdir -p /data/db
cd /data
python3 -m pip install pymongo

@ -1,47 +1,77 @@
sols = ['db.bills.find({sponsor_name:"Marco Rubio"}, {_id:0, title: 1, sponsor_name:1, sponsor_state:1})',
'db.bills.find({cosponsors:{$gte:3, $lte:5}}, {_id:0, title:1, sponsor_name:1, cosponsors:1})',
'db.bills.find({$or:[{cosponsors:{$gte:3, $lte:5}}, {sponsor_name:"Marco Rubio"}]}, {_id:0, title:1, sponsor_name:1, cosponsors:1})',
'''db.congress.aggregate([
{ $match: {"state": "IN"} },
{ $group: {_id: "$role_type", count_of_this_role: {$sum:1} } },
{ $sort: {count_of_this_role: -1} },
{ $project: {_id: 1, count_of_this_role: 1} }
])''',
'''db.bills.aggregate([
{ $lookup: {
from: "congress",
localField: "sponsor_id",
foreignField: "person.bioguideid",
as:"congressMember"} },
{ $unwind: "$congressMember" },
{ $project: {_id: 0, title:1, sponsor_name: 1, "description": "$congressMember.description", "DOB": "$congressMember.person.birthday"} }
])''',
'''db.bills.aggregate([
{ $unwind: "$committee_codes" },
{ $project: {committee_codes: 1} },
{ $group: {_id: "$committee_codes", countOfCommittee: {$sum:1} } },
{ $sort: {countOfCommittee: -1} },
])''',
'''db.bills.aggregate([
{ $project: {_id: 1, title:1, sponsor_name: 1, sponsor_state:1}},
{ $lookup: {
from: "bills",
localField: "sponsor_state",
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"}},
{ $match: {$expr: {$lt: ["$_id", "$otherbill_id"]}}}
])''',
'''db.congress.aggregate([
{ $project: {_id: 1, firstname: "$person.firstname", lastname: "$person.lastname", state: 1}},
{ $lookup: {
from: "congress",
localField: "lastname",
foreignField: "person.lastname",
as:"otherPersons"} },
{ $unwind: "$otherPersons" },
{ $match: {$expr: {$lt: ["$_id", "$otherPersons._id"]}}},
{ $project: {_id:1, firstname: 1, lastname: 1, state:1, otherPerson_id: "$otherPersons._id", otherPerson_firstname: "$otherPersons.person.firstname", otherPerson_lastname: "$otherPersons.person.lastname", otherPerson_state: "$otherPersons.state"}},
{ $match: {$expr: {$eq: ["$state", "$otherPerson_state"]}}},
])''']
sols = ['db.movies.find({year: 1928}, {_id: 0, title: 1, plot: 1})',
"""db.movies.find({'awards.wins' :{$gt: 200}}, {_id: 0, title: 1, 'awards_wins': '$awards.wins'})""",
"""db.movies.find({'imdb.votes' :{$gt: 100}, 'imdb.rating':{$gt: 9.0}}, {_id: 0, title: 1, 'imdb.votes': 1, 'imdb.rating':1})""",
"""
db.movies.aggregate([{$unwind: '$directors'},
{$match: {year: {$gte: 1915, $lte: 1920}}},
{$group: {_id: '$directors', count_of_movies: {$sum: 1}}},
{ $sort: {count_of_movies: -1} }
])
""",
"""
db.comments.aggregate([
{ $lookup: {
from: "movies",
localField: "movie_id",
foreignField: "_id",
as:"MovieDetails"}},
{ $unwind: "$MovieDetails" },
{$project: {name:1, "Movie_imdb_rating": "$MovieDetails.imdb.rating"}},
{$group: {_id: '$name', count_of_comments: {$sum:1}, average_movie_ratings: {$avg: "$Movie_imdb_rating"}}},
{$match: {count_of_comments: {$gt: 250}}}
])
""",
("""
db.movies.aggregate([
{$unwind: "$cast"},
{$match: {year:1996}},
{$project: {cast: 1}},
{$group: {_id: "$cast", CountOfMovies: {$sum:1}}},
{$match: {CountOfMovies:{$gt: 3}}},
{ $sort: {CountOfMovies: -1} }
])
""",
"""
db.movies.aggregate([
{$unwind: "$cast"},
{$match: {year:1996}},
{$project: {cast: 1}},
{$group: {_id: "$cast", CountOfMovies: {$sum:1}}},
{$match: {CountOfMovies:{$gte: 3}}},
{ $sort: {CountOfMovies: -1} }
])
"""),
("""
db.comments.aggregate([
{ $lookup: {
from: "movies",
localField: "movie_id",
foreignField: "_id",
as:"MovieDetails"}},
{$unwind: '$MovieDetails'},{$unwind: '$MovieDetails.genres'},
{$group: {_id: {name: '$name', Genres: '$MovieDetails.genres'}, comment_count: {$sum: 1}}},
{$match:{"_id.Genres": "Crime", comment_count:{$gt: 35}}},
{$project: {_id:0, name : "$_id.name", comment_count: 1}}
])
""",
"""
db.comments.aggregate([
{ $lookup: {
from: "movies",
localField: "movie_id",
foreignField: "_id",
as:"MovieDetails"}},
{$unwind: '$MovieDetails'},{$unwind: '$MovieDetails.genres'},
{$group: {_id: {name: '$name', Genres: '$MovieDetails.genres'}, comment_count: {$sum: 1}}},
{$match:{"_id.Genres": "Crime", comment_count:{$gte: 35}}},
{$project: {_id:0, name : "$_id.name", comment_count: 1}}
])
"""),
"""
db.movies.aggregate([
{$unwind: '$cast'},
{$unwind: '$directors'},
{$match: {$expr: {$eq: ["$cast", "$directors"]}}},
{$project: {title:1, directors: 1}}
])
"""]

@ -1,26 +1,22 @@
# You can change these variables to use a different base image, but
# you must ensure that your base image inherits from one of ours.
# You can also override these at build time with --build-arg flags
ARG BASE_REPO=gradescope/autograder-base
ARG TAG=latest
FROM ${BASE_REPO}:${TAG}
ADD source /autograder/source
RUN cp /autograder/source/run_autograder /autograder/run_autograder
# Ensure that scripts are Unix-friendly and executable
RUN dos2unix /autograder/run_autograder /autograder/source/setup.sh
RUN chmod +x /autograder/run_autograder
RUN curl -fsSL https://debian.neo4j.com/neotechnology.gpg.key | gpg --dearmor -o /usr/share/keyrings/neo4j.gpg
RUN echo "deb [signed-by=/usr/share/keyrings/neo4j.gpg] https://debian.neo4j.com stable latest" > /etc/apt/sources.list.d/neo4j.list
# Do whatever setup was needed in setup.sh, including installing apt packages
# Cleans up the apt cache afterwards in the same step to keep the image small
RUN apt-get update && \
bash /autograder/source/setup.sh && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN python3 -m pip install neo4j
RUN apt-get update
RUN apt install -y neo4j
RUN sed -i '1s/^/server.default_listen_address=0.0.0.0\n/' /etc/neo4j/neo4j.conf
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# You can also use RUN commands in the Dockerfile to install things
# instead of using a bash script
RUN service neo4j start
RUN neo4j-admin dbms set-initial-password 4Sfz541Lm --require-password-change=false
ADD source /autograder/source
# The base image defines the CMD and ENTRYPOINT, so don't redefine those
RUN cp /autograder/source/run_autograder /autograder/run_autograder
RUN dos2unix /autograder/run_autograder
RUN chmod +x /autograder/run_autograder

@ -1 +1 @@
docker build -t sunyinqi0508/neo4j_autograder . && docker push sunyinqi0508/neo4j_autograder
docker build -t sunyinqi0508/neo4j_autograder . && docker push sunyinqi0508/neo4j_autograder

@ -1,47 +0,0 @@
CREATE
(gorman:Author {name:"Gorman, Michael"}),
(toner:Author {name:"Toner, Patrick"}),
(koslicki:Author {name:"Koslicki, Kathrin"}),
(fine:Author {name:"Fine, Kit"}),
(roger:Author {name:"Roger, Cat"}),
(beth:Author {name:"Beth, Dog"}),
(art1:Article {doi:"10.5840/ipq20064626", title:"Independence and Substance"}),
(art2:Article {doi:"10.1007/s11098-010-9521-4", title:"Independence Accounts of Substance and Substantial Parts"}),
(art3:Article {doi:"10.1007/s11098-011-9708-3", title:"On Substantial Independence: a Reply to Patrick Toner"}),
(art4:Article {doi:"10.1080/05568640609485174", title:"Substance and Identity-Dependence"}),
(art5:Article {doi:"10.2307/4545221", title:"Ontological Dependence"}),
(art6:Article {doi:"10.2307/4519752", title:"Yet Another Title"}),
(art7:Article {doi:"10.2308/4547590", title:"Seventh Title"}),
(chp1:Chapter {no:9, title:"Substance, Independence, and Unity"}),
(chp2:Chapter {no:10, title:"Chapter on Making Chapters"}),
(ipq:Journal {title:"International Philosophical Quarterly", ISSN:"0019-0365", onlineISSN:"2153-8077"}),
(ps:Journal {title:"Philosophical Studies", ISSN:"0031-8116", onlineISSN:"1573-0883"}),
(pp:Journal {title:"Philosophical Papers", ISSN:"0556-8641", onlineISSN:"1996-8523"}),
(pas:Journal {title:"Proceedings of the Aristotelian Society", ISSN:"0066-7374", onlineISSN:"1467-9264"}),
(hitm:Journal {title:"History in the making", ISSN:"0084-7649", onlineISSN:"1235-7549"}),
(ssj:Journal {title:"Something Something Journal", ISSN:"0420-6729", onlineISSN:"5964-3248"}),
(gorman)-[:WRITES]->(art1)-[:IN {pp:[147,159]} ]->(:Issue {volume:46, issue:2, year:2006, month:6})-[:OF]->(ipq),
(toner)-[:WRITES]->(art2)-[:IN {pp:[37,43]} ]->(:Issue {volume:155, issue:1, year:2011, month:8})-[:OF]->(ps),
(gorman)-[:WRITES]->(art3)-[:IN {pp:[239,297]} ]->(:Issue {volume:159, issue:2, year:2012, month:6})-[:OF]->(ps),
(gorman)-[:WRITES]->(art4)-[:IN {pp:[103,118]} ]->(:Issue {volume:35, issue:1, year:2006, month:3})-[:OF]->(pp),
(fine)-[:WRITES]->(art5)-[:IN {pp:[269,290]} ]->(:Issue {volume:95, year:1995})-[:OF]->(pas),
(roger)-[:WRITES]->(art6)-[:IN {pp:[206,300]} ]->(:Issue {volume:24, year:1996})-[:OF]->(hitm),
(beth)-[:WRITES]->(art7)-[:IN {pp:[0,5]} ]->(:Issue {volume:32, year:1903})-[:OF]->(ssj),
(koslicki)-[:WRITES]->(chp1)-[:IN {pp:[169,195]} ]->(book:Book {title:"Aristotle on Method and Metaphysics", `ISBN-10`:"0230360912", `ISBN-13`:"978-0230360914", year:2013, month:7})<-[:EDITS]-(feser:Author {name:"Feser, Edward"}),
(beth)-[:WRITES]->(chp2)-[:IN {pp:[104,109]} ]->(book2:Book {title:"Book Name is Two", `ISBN-10`:"023546382", `ISBN-13`:"978-0230346584", year:2003, month:9})<-[:EDITS]-(tim:Author {name:"Tim, Bob"}),
(book)<-[:PUBLISHED_BY]-(pub:Publisher {location:"London", name:"Palgrave Macmillan"}),
(book2)<-[:PUBLISHED_BY]-(pub2:Publisher {location:"Madagascar", name:"Alex Lion"}),
(art1)-[:CITES]->(art5),
(art2)-[:CITES]->(art1),
(art2)-[:CITES]->(art4),
(art3)-[:CITES]->(art2),
(art3)-[:CITES]->(art4),
(art5)-[:CITES]->(art6),
(art7)-[:CITES]->(art3),
(art6)-[:CITES]->(art1),
(chp1)-[:CITES]->(art1),
(chp1)-[:CITES]->(art2),
(chp2)-[:CITES]->(art3),
(chp1)-[:CITES]->(art6),
(chp2)-[:CITES]->(art7),
(chp1)-[:CITES]->(art3)

@ -1,126 +1,151 @@
import neo4j, json
print('ver: 1.3')
# dbprep
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:
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):
c = comparator(aa, bb)
if c != 0:
return c
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
while True:
try:
db.run('RETURN 0')
break
except:
continue
for d in datasets:
with open(fsroot + d + '.txt', encoding = 'utf-8') as f:
db.run(f.read())
from solution import sols
answers = [evaluate(s) if type(s) is str else tuple(evaluate(k) for k in s) for s in sols ]
# grading
from os import listdir
from importlib.util import module_from_spec, spec_from_file_location
subroot = '/autograder/submission/'
feedback = ''
submissions = [subroot + f for f in listdir(subroot) if f.strip().lower().endswith('.py')]
grade = 0
n_queries = len(sols)
if submissions:
submission = submissions[0]
for i in range(n_queries):
feedback += f'Query {i + 1}: '
try:
spec = spec_from_file_location('curr', submission)
module = module_from_spec(spec)
spec.loader.exec_module(module)
q = getattr(module, f'query{i + 1}')()
def eq(a: list, b):
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]):
grade += 1
feedback += 'Correct.\n'
else:
feedback += 'Wrong Answer.\n'
print('ans: ', ans, '\nsol: ', answers[i])
except Exception as e:
feedback += 'Runtime Error.\n'
print(e)
else:
feedback += 'No python file in submission.\n'
# output
results = {
'output': feedback,
'score': round(grade * 100 / n_queries, 1),
'max_score': 100,
}
with open('/autograder/results/results.json', 'w') as res:
json.dump(results, res)
import neo4j, json, re
print('ver: 1.33')
# dbprep
fsroot = '/autograder/source/'
datasets = ['databaseCreateQueries']
db = neo4j.GraphDatabase.driver('bolt://localhost:7687', auth = ('neo4j', '4Sfz541Lm')).session()
points = (5,)*10
def postproc_str(data : str): # relaxed str matching
return re.sub(r'[\s|_|.]', '', data.lower())
def postproc_keys(data : str):
if type(data) is not str:
return postproc_iter(data)
_dict = {r'count\(\*\)': 'cnt',
r'efamily': 'family',
r'sname': 'aname',
r'size\(continents\)': 'numberofcontinent'}
data = postproc_str(data)
for k, v in _dict.items():
data = re.sub(k, v, data)
return 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:
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):
c = comparator(aa, bb)
if c != 0:
return c
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, naive = False):
from collections.abc import Iterable
from functools import cmp_to_key
try:
match data:
case str():
return postproc_str(data)
case dict():
return {
(i if naive else postproc_keys(k)) : postproc_iter(v, naive)
for i, (k, v) in enumerate(data.items())
}
case Iterable(): # flatten, remove order and empty iterables
res = type(data)(
sorted(
[postproc_iter(d, naive) 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(), n)
if query else None for n in (False, True)]
while True:
try:
db.run('RETURN 0')
break
except:
continue
for d in datasets:
with open(fsroot + d + '.txt', encoding = 'utf-8') as f:
db.run(f.read())
from solution import sols
answers = [evaluate(s) if type(s) is str else tuple(evaluate(k) for k in s) for s in sols ]
# grading
from os import listdir
from importlib.util import module_from_spec, spec_from_file_location
subroot = '/autograder/submission/'
feedback = ''
submissions = [subroot + f for f in listdir(subroot) if f.strip().lower().endswith('.py')]
grade = 0
n_queries = len(sols)
wa = rte = False
if submissions:
submission = submissions[0]
for i in range(n_queries):
feedback += f'Query {i + 1}: '
try:
spec = spec_from_file_location('curr', submission)
module = module_from_spec(spec)
spec.loader.exec_module(module)
q = getattr(module, f'query{i + 1}')()
def eq(a: list, b):
if type(b) is tuple:
return any(eq(a, bb) for bb in b)
else:
return any(aa == bb for aa, bb in zip(a, b))
ans = evaluate(q)
if eq(ans, answers[i]):
grade += points[i]
feedback += 'Correct.\n'
else:
wa = True
feedback += 'Wrong Answer.\n'
print('ans: ', ans, '\nsol: ', answers[i])
except Exception as e:
rte = True
feedback += 'Runtime Error.\n'
print(e)
else:
feedback += 'No python file in submission.\n'
if rte:
feedback += ('\nPlease check for syntax errors if you encountered runtime errors.\n' +
'If you believe it\'s a mistake, contact the TA at sun1226@purdue.edu for assistance.')
# output
results = {
'output': feedback,
'score': grade,
'max_score': sum(points),
}
with open('/autograder/results/results.json', 'w') as res:
json.dump(results, res)

@ -0,0 +1,488 @@
CREATE (continent1:Continent{name:'North America'})
CREATE (continent2:Continent{name:'South America'})
CREATE (continent3:Continent{name:'Asia'})
CREATE (continent4:Continent{name:'Europe'})
CREATE (continent5:Continent{name:'Australia'})
CREATE (region1:Region{name:'N. Virginia', launched:2006})
CREATE (region2:Region{name:'Oregon', launched:2011})
CREATE (region3:Region{name:'N. California', launched:2009})
CREATE (region4:Region{name:'Ireland', launched:2007})
CREATE (region5:Region{name:'Singapore', launched:2010})
CREATE (region6:Region{name:'Tokyo', launched:2011})
CREATE (region7:Region{name:'Sydney', launched:2012})
CREATE (region8:Region{name:'Sao Paulo', launched:2011})
CREATE (region9:Region{name:'GovCloud', launched:2011})
CREATE (region10:Region{name:'Beijing', launched:2014})
CREATE (availabilityzone1:AvailabilityZone{name:'eu-west-1a'})
CREATE (availabilityzone2:AvailabilityZone{name:'eu-west-1b'})
CREATE (availabilityzone3:AvailabilityZone{name:'eu-west-1c'})
CREATE (availabilityzone4:AvailabilityZone{name:'us-east-1a'})
CREATE (availabilityzone5:AvailabilityZone{name:'us-east-1b'})
CREATE (availabilityzone6:AvailabilityZone{name:'us-east-1c'})
CREATE (availabilityzone7:AvailabilityZone{name:'us-east-1d'})
CREATE (availabilityzone8:AvailabilityZone{name:'us-west-2a'})
CREATE (availabilityzone9:AvailabilityZone{name:'us-west-2b'})
CREATE (availabilityzone10:AvailabilityZone{name:'us-west-2c'})
CREATE (availabilityzone11:AvailabilityZone{name:'us-west-1a'})
CREATE (availabilityzone12:AvailabilityZone{name:'us-west-1c'})
CREATE (availabilityzone13:AvailabilityZone{name:'ap-southeast-1a'})
CREATE (availabilityzone14:AvailabilityZone{name:'ap-southeast-1b'})
CREATE (availabilityzone15:AvailabilityZone{name:'ap-northeast-1a'})
CREATE (availabilityzone16:AvailabilityZone{name:'ap-northeast-1b'})
CREATE (availabilityzone17:AvailabilityZone{name:'ap-northeast-1c'})
CREATE (availabilityzone18:AvailabilityZone{name:'ap-southeast-2a'})
CREATE (availabilityzone19:AvailabilityZone{name:'ap-southeast-2b'})
CREATE (availabilityzone20:AvailabilityZone{name:'sa-east-1a'})
CREATE (availabilityzone21:AvailabilityZone{name:'sa-east-1b'})
CREATE (region1)-[:IS_LOCATED_IN]->(continent1)
CREATE (region2)-[:IS_LOCATED_IN]->(continent1)
CREATE (region3)-[:IS_LOCATED_IN]->(continent1)
CREATE (region4)-[:IS_LOCATED_IN]->(continent4)
CREATE (region5)-[:IS_LOCATED_IN]->(continent3)
CREATE (region6)-[:IS_LOCATED_IN]->(continent3)
CREATE (region7)-[:IS_LOCATED_IN]->(continent5)
CREATE (region8)-[:IS_LOCATED_IN]->(continent2)
CREATE (region9)-[:IS_LOCATED_IN]->(continent1)
CREATE (region10)-[:IS_LOCATED_IN]->(continent3)
CREATE (region4)-[:HAS_ISOLATED]->(availabilityzone1)
CREATE (region4)-[:HAS_ISOLATED]->(availabilityzone2)
CREATE (region4)-[:HAS_ISOLATED]->(availabilityzone3)
CREATE (region1)-[:HAS_ISOLATED]->(availabilityzone4)
CREATE (region1)-[:HAS_ISOLATED]->(availabilityzone5)
CREATE (region1)-[:HAS_ISOLATED]->(availabilityzone6)
CREATE (region1)-[:HAS_ISOLATED]->(availabilityzone7)
CREATE (region2)-[:HAS_ISOLATED]->(availabilityzone8)
CREATE (region2)-[:HAS_ISOLATED]->(availabilityzone9)
CREATE (region2)-[:HAS_ISOLATED]->(availabilityzone10)
CREATE (region3)-[:HAS_ISOLATED]->(availabilityzone11)
CREATE (region3)-[:HAS_ISOLATED]->(availabilityzone12)
CREATE (region5)-[:HAS_ISOLATED]->(availabilityzone13)
CREATE (region5)-[:HAS_ISOLATED]->(availabilityzone14)
CREATE (region6)-[:HAS_ISOLATED]->(availabilityzone15)
CREATE (region6)-[:HAS_ISOLATED]->(availabilityzone16)
CREATE (region6)-[:HAS_ISOLATED]->(availabilityzone17)
CREATE (region7)-[:HAS_ISOLATED]->(availabilityzone18)
CREATE (region7)-[:HAS_ISOLATED]->(availabilityzone19)
CREATE (region8)-[:HAS_ISOLATED]->(availabilityzone20)
CREATE (region8)-[:HAS_ISOLATED]->(availabilityzone21)
CREATE (service1:Service{name:'Amazon Elastic Compute Cloud'})
CREATE (service2:Service{name:'Amazon CloudWatch'})
CREATE (service3:Service{name:'Amazon Virtual Private Cloud'})
CREATE (service4:Service{name:'Amazon Simple Storage Service'})
CREATE (service5:Service{name:'Amazon Elastic Block Store'})
CREATE (service6:Service{name:'Auto Scaling'})
CREATE (service7:Service{name:'Amazon Simple Queue Service'})
CREATE (service8:Service{name:'Amazon Simple Notification Service'})
CREATE (service9:Service{name:'Elastic Load Balancing'})
CREATE (service10:Service{name:'AWS Support'})
CREATE (service11:Service{name:'Amazon DynamoDB'})
CREATE (service12:Service{name:'Amazon Relational Database Service'})
CREATE (service13:Service{name:'Amazon Simple Workflow Service'})
CREATE (service14:Service{name:'Amazon Elastic MapReduce'})
CREATE (service15:Service{name:'AWS Direct Connect'})
CREATE (service16:Service{name:'AWS CloudFormation'})
CREATE (service17:Service{name:'VM Import/Export'})
CREATE (service18:Service{name:'AWS Elastic Beanstalk'})
CREATE (service19:Service{name:'AWS Storage Gateway'})
CREATE (service20:Service{name:'Amazon SimpleDB'})
CREATE (service21:Service{name:'Amazon ElastiCache'})
CREATE (service22:Service{name:'Amazon Elastic Transcoder'})
CREATE (service23:Service{name:'Amazon Redshift'})
CREATE (service24:Service{name:'Amazon CloudSearch'})
CREATE (service25:Service{name:'AWS Import/Export'})
CREATE (service26:Service{name:'Amazon Glacier'})
CREATE (service27:Service{name:'High Performance Computing'})
CREATE (service28:Service{name:'AWS CloudHSM'})
CREATE (service29:Service{name:'AWS CloudTrail'})
CREATE (service30:Service{name:'Amazon Simple Email Service'})
CREATE (service31:Service{name:'AWS Data Pipeline'})
CREATE (service32:Service{name:'Amazon Kinesis'})
CREATE (region1)-[:OFFERS_SERVICE]->(service1)
CREATE (region1)-[:OFFERS_SERVICE]->(service2)
CREATE (region1)-[:OFFERS_SERVICE]->(service3)
CREATE (region1)-[:OFFERS_SERVICE]->(service4)
CREATE (region1)-[:OFFERS_SERVICE]->(service5)
CREATE (region1)-[:OFFERS_SERVICE]->(service6)
CREATE (region1)-[:OFFERS_SERVICE]->(service7)
CREATE (region1)-[:OFFERS_SERVICE]->(service8)
CREATE (region1)-[:OFFERS_SERVICE]->(service9)
CREATE (region1)-[:OFFERS_SERVICE]->(service10)
CREATE (region1)-[:OFFERS_SERVICE]->(service11)
CREATE (region1)-[:OFFERS_SERVICE]->(service12)
CREATE (region1)-[:OFFERS_SERVICE]->(service13)
CREATE (region1)-[:OFFERS_SERVICE]->(service14)
CREATE (region1)-[:OFFERS_SERVICE]->(service15)
CREATE (region1)-[:OFFERS_SERVICE]->(service16)
CREATE (region1)-[:OFFERS_SERVICE]->(service17)
CREATE (region1)-[:OFFERS_SERVICE]->(service18)
CREATE (region1)-[:OFFERS_SERVICE]->(service19)
CREATE (region1)-[:OFFERS_SERVICE]->(service20)
CREATE (region1)-[:OFFERS_SERVICE]->(service21)
CREATE (region1)-[:OFFERS_SERVICE]->(service22)
CREATE (region1)-[:OFFERS_SERVICE]->(service23)
CREATE (region1)-[:OFFERS_SERVICE]->(service24)
CREATE (region1)-[:OFFERS_SERVICE]->(service25)
CREATE (region1)-[:OFFERS_SERVICE]->(service26)
CREATE (region1)-[:OFFERS_SERVICE]->(service27)
CREATE (region1)-[:OFFERS_SERVICE]->(service28)
CREATE (region1)-[:OFFERS_SERVICE]->(service29)
CREATE (region1)-[:OFFERS_SERVICE]->(service30)
CREATE (region1)-[:OFFERS_SERVICE]->(service31)
CREATE (region1)-[:OFFERS_SERVICE]->(service32)
CREATE (region2)-[:OFFERS_SERVICE]->(service1)
CREATE (region2)-[:OFFERS_SERVICE]->(service2)
CREATE (region2)-[:OFFERS_SERVICE]->(service3)
CREATE (region2)-[:OFFERS_SERVICE]->(service4)
CREATE (region2)-[:OFFERS_SERVICE]->(service5)
CREATE (region2)-[:OFFERS_SERVICE]->(service6)
CREATE (region2)-[:OFFERS_SERVICE]->(service7)
CREATE (region2)-[:OFFERS_SERVICE]->(service8)
CREATE (region2)-[:OFFERS_SERVICE]->(service9)
CREATE (region2)-[:OFFERS_SERVICE]->(service10)
CREATE (region2)-[:OFFERS_SERVICE]->(service11)
CREATE (region2)-[:OFFERS_SERVICE]->(service12)
CREATE (region2)-[:OFFERS_SERVICE]->(service13)
CREATE (region2)-[:OFFERS_SERVICE]->(service14)
CREATE (region2)-[:OFFERS_SERVICE]->(service15)
CREATE (region2)-[:OFFERS_SERVICE]->(service16)
CREATE (region2)-[:OFFERS_SERVICE]->(service17)
CREATE (region2)-[:OFFERS_SERVICE]->(service18)
CREATE (region2)-[:OFFERS_SERVICE]->(service19)
CREATE (region2)-[:OFFERS_SERVICE]->(service20)
CREATE (region2)-[:OFFERS_SERVICE]->(service21)
CREATE (region2)-[:OFFERS_SERVICE]->(service22)
CREATE (region2)-[:OFFERS_SERVICE]->(service23)
CREATE (region2)-[:OFFERS_SERVICE]->(service24)
CREATE (region2)-[:OFFERS_SERVICE]->(service25)
CREATE (region2)-[:OFFERS_SERVICE]->(service26)
CREATE (region2)-[:OFFERS_SERVICE]->(service27)
CREATE (region2)-[:OFFERS_SERVICE]->(service28)
CREATE (region2)-[:OFFERS_SERVICE]->(service29)
CREATE (region3)-[:OFFERS_SERVICE]->(service1)
CREATE (region3)-[:OFFERS_SERVICE]->(service2)
CREATE (region3)-[:OFFERS_SERVICE]->(service3)
CREATE (region3)-[:OFFERS_SERVICE]->(service4)
CREATE (region3)-[:OFFERS_SERVICE]->(service5)
CREATE (region3)-[:OFFERS_SERVICE]->(service6)
CREATE (region3)-[:OFFERS_SERVICE]->(service7)
CREATE (region3)-[:OFFERS_SERVICE]->(service8)
CREATE (region3)-[:OFFERS_SERVICE]->(service9)
CREATE (region3)-[:OFFERS_SERVICE]->(service10)
CREATE (region3)-[:OFFERS_SERVICE]->(service11)
CREATE (region3)-[:OFFERS_SERVICE]->(service12)
CREATE (region3)-[:OFFERS_SERVICE]->(service13)
CREATE (region3)-[:OFFERS_SERVICE]->(service14)
CREATE (region3)-[:OFFERS_SERVICE]->(service15)
CREATE (region3)-[:OFFERS_SERVICE]->(service16)
CREATE (region3)-[:OFFERS_SERVICE]->(service17)
CREATE (region3)-[:OFFERS_SERVICE]->(service18)
CREATE (region3)-[:OFFERS_SERVICE]->(service19)
CREATE (region3)-[:OFFERS_SERVICE]->(service20)
CREATE (region3)-[:OFFERS_SERVICE]->(service21)
CREATE (region3)-[:OFFERS_SERVICE]->(service22)
CREATE (region3)-[:OFFERS_SERVICE]->(service24)
CREATE (region3)-[:OFFERS_SERVICE]->(service25)
CREATE (region3)-[:OFFERS_SERVICE]->(service26)
CREATE (region4)-[:OFFERS_SERVICE]->(service1)
CREATE (region4)-[:OFFERS_SERVICE]->(service2)
CREATE (region4)-[:OFFERS_SERVICE]->(service3)
CREATE (region4)-[:OFFERS_SERVICE]->(service4)
CREATE (region4)-[:OFFERS_SERVICE]->(service5)
CREATE (region4)-[:OFFERS_SERVICE]->(service6)
CREATE (region4)-[:OFFERS_SERVICE]->(service7)
CREATE (region4)-[:OFFERS_SERVICE]->(service8)
CREATE (region4)-[:OFFERS_SERVICE]->(service9)
CREATE (region4)-[:OFFERS_SERVICE]->(service10)
CREATE (region4)-[:OFFERS_SERVICE]->(service11)
CREATE (region4)-[:OFFERS_SERVICE]->(service12)
CREATE (region4)-[:OFFERS_SERVICE]->(service13)
CREATE (region4)-[:OFFERS_SERVICE]->(service14)
CREATE (region4)-[:OFFERS_SERVICE]->(service15)
CREATE (region4)-[:OFFERS_SERVICE]->(service16)
CREATE (region4)-[:OFFERS_SERVICE]->(service17)
CREATE (region4)-[:OFFERS_SERVICE]->(service18)
CREATE (region4)-[:OFFERS_SERVICE]->(service19)
CREATE (region4)-[:OFFERS_SERVICE]->(service20)
CREATE (region4)-[:OFFERS_SERVICE]->(service21)
CREATE (region4)-[:OFFERS_SERVICE]->(service22)
CREATE (region4)-[:OFFERS_SERVICE]->(service23)
CREATE (region4)-[:OFFERS_SERVICE]->(service24)
CREATE (region4)-[:OFFERS_SERVICE]->(service25)
CREATE (region4)-[:OFFERS_SERVICE]->(service26)
CREATE (region4)-[:OFFERS_SERVICE]->(service27)
CREATE (region4)-[:OFFERS_SERVICE]->(service28)
CREATE (region4)-[:OFFERS_SERVICE]->(service30)
CREATE (region5)-[:OFFERS_SERVICE]->(service1)
CREATE (region5)-[:OFFERS_SERVICE]->(service2)
CREATE (region5)-[:OFFERS_SERVICE]->(service3)
CREATE (region5)-[:OFFERS_SERVICE]->(service4)
CREATE (region5)-[:OFFERS_SERVICE]->(service5)
CREATE (region5)-[:OFFERS_SERVICE]->(service6)
CREATE (region5)-[:OFFERS_SERVICE]->(service7)
CREATE (region5)-[:OFFERS_SERVICE]->(service8)
CREATE (region5)-[:OFFERS_SERVICE]->(service9)
CREATE (region5)-[:OFFERS_SERVICE]->(service10)
CREATE (region5)-[:OFFERS_SERVICE]->(service11)
CREATE (region5)-[:OFFERS_SERVICE]->(service12)
CREATE (region5)-[:OFFERS_SERVICE]->(service13)
CREATE (region5)-[:OFFERS_SERVICE]->(service14)
CREATE (region5)-[:OFFERS_SERVICE]->(service15)
CREATE (region5)-[:OFFERS_SERVICE]->(service16)
CREATE (region5)-[:OFFERS_SERVICE]->(service17)
CREATE (region5)-[:OFFERS_SERVICE]->(service18)
CREATE (region5)-[:OFFERS_SERVICE]->(service19)
CREATE (region5)-[:OFFERS_SERVICE]->(service20)
CREATE (region5)-[:OFFERS_SERVICE]->(service21)
CREATE (region5)-[:OFFERS_SERVICE]->(service22)
CREATE (region5)-[:OFFERS_SERVICE]->(service23)
CREATE (region5)-[:OFFERS_SERVICE]->(service24)
CREATE (region5)-[:OFFERS_SERVICE]->(service25)
CREATE (region6)-[:OFFERS_SERVICE]->(service1)
CREATE (region6)-[:OFFERS_SERVICE]->(service2)
CREATE (region6)-[:OFFERS_SERVICE]->(service3)
CREATE (region6)-[:OFFERS_SERVICE]->(service4)
CREATE (region6)-[:OFFERS_SERVICE]->(service5)
CREATE (region6)-[:OFFERS_SERVICE]->(service6)
CREATE (region6)-[:OFFERS_SERVICE]->(service7)
CREATE (region6)-[:OFFERS_SERVICE]->(service8)
CREATE (region6)-[:OFFERS_SERVICE]->(service9)
CREATE (region6)-[:OFFERS_SERVICE]->(service10)
CREATE (region6)-[:OFFERS_SERVICE]->(service11)
CREATE (region6)-[:OFFERS_SERVICE]->(service12)
CREATE (region6)-[:OFFERS_SERVICE]->(service13)
CREATE (region6)-[:OFFERS_SERVICE]->(service14)
CREATE (region6)-[:OFFERS_SERVICE]->(service15)
CREATE (region6)-[:OFFERS_SERVICE]->(service16)
CREATE (region6)-[:OFFERS_SERVICE]->(service17)
CREATE (region6)-[:OFFERS_SERVICE]->(service18)
CREATE (region6)-[:OFFERS_SERVICE]->(service19)
CREATE (region6)-[:OFFERS_SERVICE]->(service20)
CREATE (region6)-[:OFFERS_SERVICE]->(service21)
CREATE (region6)-[:OFFERS_SERVICE]->(service22)
CREATE (region6)-[:OFFERS_SERVICE]->(service23)
CREATE (region6)-[:OFFERS_SERVICE]->(service26)
CREATE (region6)-[:OFFERS_SERVICE]->(service27)
CREATE (region7)-[:OFFERS_SERVICE]->(service1)
CREATE (region7)-[:OFFERS_SERVICE]->(service2)
CREATE (region7)-[:OFFERS_SERVICE]->(service3)
CREATE (region7)-[:OFFERS_SERVICE]->(service4)
CREATE (region7)-[:OFFERS_SERVICE]->(service5)
CREATE (region7)-[:OFFERS_SERVICE]->(service6)
CREATE (region7)-[:OFFERS_SERVICE]->(service7)
CREATE (region7)-[:OFFERS_SERVICE]->(service8)
CREATE (region7)-[:OFFERS_SERVICE]->(service9)
CREATE (region7)-[:OFFERS_SERVICE]->(service10)
CREATE (region7)-[:OFFERS_SERVICE]->(service11)
CREATE (region7)-[:OFFERS_SERVICE]->(service12)
CREATE (region7)-[:OFFERS_SERVICE]->(service13)
CREATE (region7)-[:OFFERS_SERVICE]->(service14)
CREATE (region7)-[:OFFERS_SERVICE]->(service15)
CREATE (region7)-[:OFFERS_SERVICE]->(service16)
CREATE (region7)-[:OFFERS_SERVICE]->(service17)
CREATE (region7)-[:OFFERS_SERVICE]->(service18)
CREATE (region7)-[:OFFERS_SERVICE]->(service19)
CREATE (region7)-[:OFFERS_SERVICE]->(service20)
CREATE (region7)-[:OFFERS_SERVICE]->(service21)
CREATE (region7)-[:OFFERS_SERVICE]->(service23)
CREATE (region7)-[:OFFERS_SERVICE]->(service26)
CREATE (region7)-[:OFFERS_SERVICE]->(service28)
CREATE (region8)-[:OFFERS_SERVICE]->(service1)
CREATE (region8)-[:OFFERS_SERVICE]->(service2)
CREATE (region8)-[:OFFERS_SERVICE]->(service3)
CREATE (region8)-[:OFFERS_SERVICE]->(service4)
CREATE (region8)-[:OFFERS_SERVICE]->(service5)
CREATE (region8)-[:OFFERS_SERVICE]->(service6)
CREATE (region8)-[:OFFERS_SERVICE]->(service7)
CREATE (region8)-[:OFFERS_SERVICE]->(service8)
CREATE (region8)-[:OFFERS_SERVICE]->(service9)
CREATE (region8)-[:OFFERS_SERVICE]->(service10)
CREATE (region8)-[:OFFERS_SERVICE]->(service11)
CREATE (region8)-[:OFFERS_SERVICE]->(service12)
CREATE (region8)-[:OFFERS_SERVICE]->(service13)
CREATE (region8)-[:OFFERS_SERVICE]->(service14)
CREATE (region8)-[:OFFERS_SERVICE]->(service15)
CREATE (region8)-[:OFFERS_SERVICE]->(service16)
CREATE (region8)-[:OFFERS_SERVICE]->(service18)
CREATE (region8)-[:OFFERS_SERVICE]->(service19)
CREATE (region8)-[:OFFERS_SERVICE]->(service20)
CREATE (region8)-[:OFFERS_SERVICE]->(service21)
CREATE (region9)-[:OFFERS_SERVICE]->(service1)
CREATE (region9)-[:OFFERS_SERVICE]->(service2)
CREATE (region9)-[:OFFERS_SERVICE]->(service3)
CREATE (region9)-[:OFFERS_SERVICE]->(service4)
CREATE (region9)-[:OFFERS_SERVICE]->(service5)
CREATE (region9)-[:OFFERS_SERVICE]->(service6)
CREATE (region9)-[:OFFERS_SERVICE]->(service7)
CREATE (region9)-[:OFFERS_SERVICE]->(service8)
CREATE (region9)-[:OFFERS_SERVICE]->(service9)
CREATE (region9)-[:OFFERS_SERVICE]->(service10)
CREATE (region9)-[:OFFERS_SERVICE]->(service11)
CREATE (region9)-[:OFFERS_SERVICE]->(service12)
CREATE (region9)-[:OFFERS_SERVICE]->(service13)
CREATE (region9)-[:OFFERS_SERVICE]->(service14)
CREATE (region9)-[:OFFERS_SERVICE]->(service15)
CREATE (region9)-[:OFFERS_SERVICE]->(service16)
CREATE (region9)-[:OFFERS_SERVICE]->(service27)
CREATE (region10)-[:OFFERS_SERVICE]->(service1)
CREATE (region10)-[:OFFERS_SERVICE]->(service2)
CREATE (region10)-[:OFFERS_SERVICE]->(service3)
CREATE (region10)-[:OFFERS_SERVICE]->(service4)
CREATE (region10)-[:OFFERS_SERVICE]->(service5)
CREATE (region10)-[:OFFERS_SERVICE]->(service6)
CREATE (region10)-[:OFFERS_SERVICE]->(service7)
CREATE (region10)-[:OFFERS_SERVICE]->(service8)
CREATE (region10)-[:OFFERS_SERVICE]->(service9)
CREATE (region10)-[:OFFERS_SERVICE]->(service10)
CREATE (region10)-[:OFFERS_SERVICE]->(service11)
CREATE (region10)-[:OFFERS_SERVICE]->(service12)
CREATE (region10)-[:OFFERS_SERVICE]->(service13)
CREATE (region10)-[:OFFERS_SERVICE]->(service14)
CREATE (region10)-[:OFFERS_SERVICE]->(service16)
CREATE (region10)-[:OFFERS_SERVICE]->(service17)
CREATE (region10)-[:OFFERS_SERVICE]->(service19)
CREATE (region10)-[:OFFERS_SERVICE]->(service21)
CREATE (region10)-[:OFFERS_SERVICE]->(service26)
CREATE (instance1:EC2InstanceType{name:'m1.small', family:'general purpose', memory:1.7 })-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance2:EC2InstanceType{name:'m1.medium', family:'general purpose', memory:3.75})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance3:EC2InstanceType{name:'m1.large', family:'general purpose', memory:7.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance4:EC2InstanceType{name:'m1.xlarge', family:'general purpose', memory:15})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance5:EC2InstanceType{name:'m3.xlarge', family:'general purpose', memory:15 })-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance6:EC2InstanceType{name:'m3.2xlarge', family:'general purpose', memory:30})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance7:EC2InstanceType{name:'c1.medium', family:'Compute optimized', memory:1.7})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance8:EC2InstanceType{name:'c1.xlarge', family:'Compute optimized', memory:7})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance9:EC2InstanceType{name:'c3.large', family:'Compute optimized', memory:3.75})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance10:EC2InstanceType{name:'c3.xlarge', family:'Compute optimized', memory:7.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance11:EC2InstanceType{name:'c3.2xlarge', family:'Compute optimized', memory:15})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance12:EC2InstanceType{name:'c3.4xlarge', family:'Compute optimized', memory:30})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance13:EC2InstanceType{name:'c3.8xlarge', family:'Compute optimized', memory:60})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance14:EC2InstanceType{name:'cc2.8xlarge', family:'Compute optimized', memory:60.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance15:EC2InstanceType{name:'m2.xlarge', family:'Memory optimized', memory:17.1})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance16:EC2InstanceType{name:'m2.2xlarge', family:'Memory optimized', memory:34.2})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance17:EC2InstanceType{name:'m2.4xlarge', family:'Memory optimized', memory:68.4})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance18:EC2InstanceType{name:'cr1.8xlarge', family:'Memory optimized', memory:244})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance19:EC2InstanceType{name:'hi1.4xlarge', family:'Storage optimized', memory:60.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance20:EC2InstanceType{name:'hs1.8xlarge', family:'Storage optimized', memory:117})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance21:EC2InstanceType{name:'i2.xlarge', family:'Storage optimized', memory:30.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance22:EC2InstanceType{name:'Â i2.2xlarge', family:'Storage optimized', memory:61})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance23:EC2InstanceType{name:'i2.4xlarge ', family:'Storage optimized', memory:122})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance24:EC2InstanceType{name:'i2.8xlarge', family:'Storage optimized', memory:244})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance25:EC2InstanceType{name:'t1.micro', family:'Micro instances', memory:.615})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance26:EC2InstanceType{name:'cg1.4xlarge', family:'GPU instances', memory:22.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance27:EC2InstanceType{name:'g2.2xlarge', family:'GPU instances', memory:15})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance27)-[:IS_EC2_INSTANCE_TYPE]->(service2)
CREATE (instance1)-[:IS_EC2_INSTANCE_TYPE]->(service3)
CREATE (instance22)-[:IS_EC2_INSTANCE_TYPE]->(service3)
CREATE (instance11)-[:IS_EC2_INSTANCE_TYPE]->(service3)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service4)
CREATE (instance3)-[:IS_EC2_INSTANCE_TYPE]->(service5)
CREATE (instance17)-[:IS_EC2_INSTANCE_TYPE]->(service5)
CREATE (instance22)-[:IS_EC2_INSTANCE_TYPE]->(service6)
CREATE (instance11)-[:IS_EC2_INSTANCE_TYPE]->(service7)
CREATE (instance1)-[:IS_EC2_INSTANCE_TYPE]->(service8)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service8)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service8)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service9)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service2)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service10)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service11)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service12)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service13)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service14)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service15)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service16)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service17)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service18)
CREATE (instance3)-[:IS_EC2_INSTANCE_TYPE]->(service19)
CREATE (instance3)-[:IS_EC2_INSTANCE_TYPE]->(service20)
CREATE (instance3)-[:IS_EC2_INSTANCE_TYPE]->(service21)
CREATE (instance4)-[:IS_EC2_INSTANCE_TYPE]->(service22)
CREATE (instance3)-[:IS_EC2_INSTANCE_TYPE]->(service23)
CREATE (instance26)-[:IS_EC2_INSTANCE_TYPE]->(service16)
CREATE (instance5)-[:IS_EC2_INSTANCE_TYPE]->(service17)
CREATE (instance5)-[:IS_EC2_INSTANCE_TYPE]->(service10)
CREATE (instance5)-[:IS_EC2_INSTANCE_TYPE]->(service11)
CREATE (instance5)-[:IS_EC2_INSTANCE_TYPE]->(service12)
CREATE (instance7)-[:IS_EC2_INSTANCE_TYPE]->(service13)
CREATE (instance17)-[:IS_EC2_INSTANCE_TYPE]->(service14)
CREATE (instance10)-[:IS_EC2_INSTANCE_TYPE]->(service15)
CREATE (instance10)-[:IS_EC2_INSTANCE_TYPE]->(service16)
CREATE (instance10)-[:IS_EC2_INSTANCE_TYPE]->(service17)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service17)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service10)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service11)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service12)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service13)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service14)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service15)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service16)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service17)
//instance 9
CREATE (price1:Price{name:'PriceBook', desc:'region 1 price book', cost_per_hour:0.150})
CREATE (price2:Price{name:'PriceBook', desc:'region 2 pricebook', cost_per_hour:0.150})
CREATE (price3:Price{name:'PriceBook', desc:'region 3 pricebook', cost_per_hour:0.171})
CREATE (region1)-[:CHARGES]->(price1)-[:FOR_INSTANCE]->(instance9)
CREATE (region2)-[:CHARGES]->(price2)-[:FOR_INSTANCE]->(instance9)
CREATE (region3)-[:CHARGES]->(price3)-[:FOR_INSTANCE]->(instance9)
//instance1
CREATE (price4:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.060})
CREATE (region1)-[:CHARGES]->(price4)-[:FOR_INSTANCE]->(instance1)
//instance 10
CREATE (price5:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.300})
CREATE (price6:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.300})
CREATE (price7:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.342})
CREATE (region1)-[:CHARGES]->(price5)-[:FOR_INSTANCE]->(instance10)
CREATE (region2)-[:CHARGES]->(price6)-[:FOR_INSTANCE]->(instance10)
CREATE (region3)-[:CHARGES]->(price7)-[:FOR_INSTANCE]->(instance10)
//instance 11
CREATE (price8:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.600})
CREATE (price9:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.600})
CREATE (price10:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.683})
CREATE (region9)-[:CHARGES]->(price8)-[:FOR_INSTANCE]->(instance11)
CREATE (region2)-[:CHARGES]->(price9)-[:FOR_INSTANCE]->(instance11)
CREATE (region3)-[:CHARGES]->(price10)-[:FOR_INSTANCE]->(instance11)
//instance 12
CREATE (price11:Price{name:'PriceBook', desc:'foo', cost_per_hour:1.200})
CREATE (price12:Price{name:'PriceBook', desc:'foo', cost_per_hour:1.200})
CREATE (price13:Price{name:'PriceBook', desc:'foo', cost_per_hour:1.366})
CREATE (region1)-[:CHARGES]->(price11)-[:FOR_INSTANCE]->(instance12)
CREATE (region2)-[:CHARGES]->(price12)-[:FOR_INSTANCE]->(instance12)
CREATE (region3)-[:CHARGES]->(price13)-[:FOR_INSTANCE]->(instance12)
//instance 13
CREATE (price14:Price{name:'PriceBook', desc:'foo', cost_per_hour:2.400})
CREATE (price15:Price{name:'PriceBook', desc:'foo', cost_per_hour:2.400})
CREATE (price16:Price{name:'PriceBook', desc:'foo', cost_per_hour:2.732})
CREATE (region1)-[:CHARGES]->(price14)-[:FOR_INSTANCE]->(instance13)
CREATE (region2)-[:CHARGES]->(price15)-[:FOR_INSTANCE]->(instance13)
CREATE (region3)-[:CHARGES]->(price16)-[:FOR_INSTANCE]->(instance13)

@ -6,13 +6,3 @@ service neo4j start
python3 /autograder/source/autograder.py
# files_submitted=$(ls /autograder/submission)
# num_files_submitted=$(ls /autograder/submission/ | wc -l)
# cat > /autograder/results/results.json <<EOF
# {
# "output": "Good job, you passed! Submitted ${num_files_submitted} files: ${files_submitted}",
# "score": 10,
# "max_score": 10
# }
# EOF

@ -1,10 +0,0 @@
apt install -y curl python3 python3-pip
curl -fsSL https://debian.neo4j.com/neotechnology.gpg.key | gpg --dearmor -o /usr/share/keyrings/neo4j.gpg
echo "deb [signed-by=/usr/share/keyrings/neo4j.gpg] https://debian.neo4j.com stable latest" > /etc/apt/sources.list.d/neo4j.list
apt update
apt install -y neo4j
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

@ -1,73 +1,57 @@
sols = [
'''
MATCH (author:Author)-[:WRITES]->(article:Article)
RETURN author.name, article.title
''',
('''
match (author:Author)-[:WRITES]->(paper_or_chapter)
return author.name, paper_or_chapter.title, labels(paper_or_chapter)
''',
'''
MATCH (author:Author)-[:WRITES]->(paper_or_chapter)
WITH author, paper_or_chapter, labels(paper_or_chapter) as publicationType
WHERE publicationType=["Article"] or publicationType=["Chapter"]
RETURN author.name, paper_or_chapter.title, publicationType
'''),
('''
match (author:Author)-[:WRITES|EDITS]->(publication)
return author.name, publication.title, labels(publication)
''',
'''
MATCH (author:Author)-[]->(publication)
WHERE publication:Article or publication:Chapter or publication:Book
RETURN author.name, publication.title, labels(publication)
'''),
('''
match (author:Author)-[:WRITES|EDITS]->(publication)
return author.name, count(publication) as publication_count
''',
'''
MATCH (author:Author)-[]->(publication)
WHERE publication:Article OR publication:Chapter or publication:Book
RETURN author.name, count(publication) as publication_count
'''),
('''
match(a:Article)-[in:IN]->(:Issue)
where (in.pp[1] - in.pp[0]) <= 10
return a.title, (in.pp[1] - in.pp[0] + 1) as NumberOfPages
''',
'''
MATCH (a:Article)-[e:IN]->(:Issue)
WITH a, e.pp[1]-e.pp[0]+1 as NumberOfPages
WHERE NumberOfPages <=10
RETURN a.title, NumberOfPages
'''),
'''
MATCH (p2:Article)<-[]-(a1:Author)-[]->(p1:Article),(p1)-[:CITES]->(p2)
RETURN a1.name, p1.title, p2.title
''',
'''
MATCH (publication)<-[:CITES]-()
WITH publication, count(*) as publication_count
WHERE (publication:Article or publication:Chapter) and publication_count >= 2
RETURN publication.title, publication_count
''',
('''
match (journal:Journal)<-[:OF]-(issue:Issue)<-[:IN]-(article:Article)<-[:CITES]-(someOtherPublication)
with journal, article, count(someOtherPublication) as citations_count
where citations_count > 1
match (article)<-[:WRITES]-(author:Author)
return journal.title, article.title, citations_count, author.name
''',
'''
MATCH (author:Author)-[:WRITES]->(article:Article)-[:IN]->()-[]->(journal:Journal), ()-[e:CITES]->(article:Article)
WITH journal, article, author, count(e) as citation_count
WHERE citation_count >= 2
RETURN journal.title, article.title, citation_count, author.name
'''),
'''
MATCH (a1:Article)-[:IN]->(i1:Issue)-[]->(:Journal)<-[]-(i2:Issue)<-[]-(a2:Article)
WHERE (a1)-[:CITES]->(a2)
RETURN a1.title, i1.issue, a2.title, i2.issue
'''
]
sols = [
'''
MATCH (region:Region)-[:IS_LOCATED_IN]-(continent:Continent)
RETURN region.name, continent.name
''',
'''
MATCH (region:Region)-[:HAS_ISOLATED]-(azone:AvailabilityZone)
RETURN region.name,azone.name
''',
'''
MATCH(e:EC2InstanceType)
return e.family, count(*)
''',
'''
MATCH(e:EC2InstanceType)--(p:Price)
with e, p.cost_per_hour/e.memory as price_per_GB
Order by price_per_GB
Return e.name, price_per_GB
Limit 1
''',
'''
match (service:Service)-[:OFFERS_SERVICE]-(region:Region)
with service, count(region) as number_of_region, collect(region.name) as region_name_collection
where number_of_region > 5
return service.name, number_of_region,region_name_collection
order by number_of_region desc, service.name asc
''',
'''
match (instance:EC2InstanceType)--(price:Price)--(region:Region {name: "N. Virginia"})
where price.cost_per_hour > 1
return instance.name, price.cost_per_hour, region.name
''',
'''
match(a:Service)--(:Region)--(c:Continent)
with a, count(distinct c) as number_of_continent
where number_of_continent = 5
return a.name, number_of_continent
''',
'''
match (r:Region)-[:OFFERS_SERVICE]->(s1:Service {name:'AWS Data Pipeline'}), (r)-[:OFFERS_SERVICE]->(s2:Service {name:'Amazon Kinesis'})
return r.name
''',
'''
match (r:Region)-[:OFFERS_SERVICE]->(s1:Service {name:'Amazon Simple Email Service'})
WHERE NOT (r)-[:OFFERS_SERVICE]->(:Service {name:'AWS Data Pipeline'})
return r.name
''',
'''
match(a:Service)<-[]-(e:EC2InstanceType {name: 'Â i2.2xlarge'})
where NOT (a)<-[]-(:EC2InstanceType {name: 'c3.2xlarge'})
return a.name, 'offered only on i2.2xlarge' as description
union
match(a:Service)<-[]-(e:EC2InstanceType {name: 'Â i2.2xlarge'})
where (a)<-[]-(:EC2InstanceType {name: 'c3.2xlarge'})
return a.name, 'offered on i2.2xlarge and c3.2xlarge' as description
'''
]

@ -0,0 +1,45 @@
instr = '''Instructions:
Please put the queries under the corresponding functions below.
Running this python file will check if the formatting is okay.
'''
def query1():
return """
"""
def query2():
return """
"""
def query3():
return """
"""
def query4():
return """
"""
def query5():
return """
"""
def query6():
return """
"""
def query7():
return """
"""
def query8():
return """
"""
if __name__ == "__main__":
try:
if all(type(eval(f'query{f}()'))==str for f in range(1,9)):
print('Your submission is valid.')
else:
raise TypeError('Invalid Return Types.')
except Exception as e:
print(f'Your submission is invalid.\n{instr}\n{e}')

@ -0,0 +1,53 @@
instr = '''Instructions:
Please put the queries under the corresponding functions below.
Running this python file will check if the formatting is okay.
'''
def query1():
return """
"""
def query2():
return """
"""
def query3():
return """
"""
def query4():
return """
"""
def query5():
return """
"""
def query6():
return """
"""
def query7():
return """
"""
def query8():
return """
"""
def query9():
return """
"""
def query10():
return """
"""
if __name__ == "__main__":
try:
if all(type(eval(f'query{f}()'))==str for f in range(1,11)):
print('Your submission is valid.')
else:
raise TypeError('Invalid Return Types.')
except Exception as e:
print(f'Your submission is invalid.\n{instr}\n{e}')
Loading…
Cancel
Save