Skip to content

Coursegraph Queries

Tony Kim edited this page Aug 31, 2018 · 21 revisions

For information on how to write queries in Cypher (Neo4j's query language), reference the following:

For EdX's sample queries, look here.

What follows is a list of queries that can be run on our courses in addition to EdX's list.

Naming nodes to their actual display names instead of initial setting of "None"

MATCH (n)
SET n.name = n.display_name
RETURN n

Due dates

These queries are primitive and will need more refinement.

Check for valid due dates

MATCH (c:course) -[:PARENT_OF*]-> (n:sequential)
WHERE 
	n.due > c.start
	AND n.due <= c.end
RETURN n.display_name as valid_due_dates

Check for invalid due dates

MATCH (c:course) -[:PARENT_OF*]-> (n:sequential)
WHERE 
	n.due <= c.start
	AND n.due > c.end
RETURN n.display_name as invalid_due_dates

Advanced modules

Give names of courses using advanced modules and their list of advanced modules

MATCH (n) 
WHERE EXISTS(n.advanced_modules) 
RETURN n.course_key as course_name, n.advanced_modules as modules

How often an advanced module is used in a course (openassessment in this example)

MATCH 
	(c:course) -[:PARENT_OF*]-> (o:openassessment)
RETURN
	count(o)

Block types

Give types and frequencies of each block type in all courses combined

MATCH
    (c:course) -[:PARENT_OF*]-> (n:item)
RETURN
    distinct(n.block_type) as blockType,
    count(n.block_type) as number
order by
    number DESC

** To localize query to one course in particular, add a WHERE c.course_key = "INSERT COURSE KEY HERE" before RETURN.

Old ImageModal blocks

Find all courses with one or more instances of the old ImageModal

MATCH
	(c:course)-[:PARENT_OF*]->(h:item)
WHERE
	h.data CONTAINS 'modal-content'
RETURN
	distinct(h.course_key)

Find all instances of the old ImageModal

MATCH
	(c:course)-[:PARENT_OF*]->(h:item)
WHERE
	h.data CONTAINS 'modal-content'
RETURN
	h.course_key,
	h.data,
	"https://studio.stage.lagunita.stanford.edu/container/" + h.location as link

Search the most recently edited blocks

In a specified course (in this case, the Demo Course)

MATCH 
	(c:course) -[:PARENT_OF*]-> (n:item)
WHERE
	c.course_key = "course-v1:edX+DemoX+Demo_Course"
	AND n.edited_on >= '2018-08-01' // or any recent date
RETURN
	n.block_type as block_type,
	n.display_name as display_name,
	n.location as location
LIMIT 25

in general, without any course specification

MATCH 
	(c:course) -[:PARENT_OF*]-> (n:item)
WHERE
	n.edited_on >= '2018-08-01' // or any recent date
RETURN
	n.block_type as block_type,
	n.display_name as display_name,
	n.course_key as course_key,
	n.location as location
LIMIT 25

Sibling blocks

Return all sibling blocks in a course

MATCH 
	sibs = (c:course)-[:PARENT_OF*]->()-[r:PRECEDES]->()
WHERE
	c.course_key = "course-v1:edX+DemoX+Demo_Course"
RETURN
	count(sibs)

Return chapters with multiple subsections

MATCH
	sibs = (c:course)-[:PARENT_OF]->(n:item)-[:PARENT_OF]->()-[:PRECEDES]->()
WHERE
	c.course_key = "course-v1:edX+DemoX+Demo_Course"
RETURN
	(n)-[:PARENT_OF]->()

Similar query but return the entire graph structure starting from the course block

MATCH
	sibs = (c:course)-[:PARENT_OF]->(n:item)-[:PARENT_OF]->()-[:PRECEDES]->()
WHERE
	c.course_key = "course-v1:edX+DemoX+Demo_Course"
RETURN
	sibs

For more experimental queries, click here.

Clone this wiki locally