Neo4j Corona Tracing
Installing Neo4j Desktop
Download the latest version of the Neo4j Desktop AppImage and make it executable:
chmod a+x neo4j-desktop-offline-1.2.9-x86_64.AppImage
Then run it from your Terminal ./neo4j-desktop-offline-1.2.9-x86_64.AppImage
.
Creating your Database
- Click on New Project, create the database and click on Manage to set it up.
-
Click on Open Folder, enter the import directory.
-
Copy your Corona Tracing Data as
.csv
file into the directory.
Alternative: If you are running Neo4j inside a Docker Container copy this file to /opt/neo4j/import
and use the web client to run the import.
- Now start the database and open the Neo4j Explorer.
Importing Data
Run the following Cypher query to add your data to your database:
LOAD CSV WITH HEADERS FROM 'file:///coronaTracing.csv' AS line
WITH line
MERGE (Infected:Person{name:line.Infected, Addr:line.InfectedAddress})
MERGE (Contact:Person{name:line.Contact, Addr:line.ContactAddress})
MERGE (Infected)-[info:Info{
`Contact Info`:line.ContactInfo,
`Relationship`:line.`Relationship`,
Location: CASE WHEN line.Geography IS NOT NULL THEN line.Geography ELSE '' END
}]->(Contact)
Working with your Data
- How many potential infections (query for relationship
Info
= event with the potential of an infection) ?
MATCH (person:Person)-[rel:Info]->(:Person)
RETURN COUNT (rel)
- How many persons have been traced from
Cordon M
?
MATCH (person:Person)
WHERE person.Addr = 'CordonM'
RETURN person
- How many infected persons has
Person A
been in contact with ?
MATCH (carrier)-[r:Info]->(person:Person{name:'PersonA'})
RETURN carrier, person, r
- How many were potentially infected by
Person J
?
MATCH (carrier:Person{name:'PersonJ'})-[r:Info]->(person:Person)
RETURN COUNT (person) AS Infected
4.1. Omit potential double-count:
MATCH (carrier:Person{name:'PersonJ'})-[r:Info]->(person:Person)
RETURN COUNT (DISTINCT person) AS Infected
- Select all and order by number of potential infection event - find Super Spreader:
MATCH (carrier:Person)-[rel:Info]->(person:Person)
RETURN carrier, COUNT(carrier) AS Infected
ORDER BY Infected DESC
LIMIT 10
Switch results from Graph
to Table
to see the persons who are most likely to be super spreader
- Select list of persons with highest number of potential infections:
MATCH (n)-[r:Info]->(m)
WITH n, COUNT((n)-[]->()) as num
ORDER BY num DESC
LIMIT 10
MATCH (n)-[i]->(b)
RETURN n,i,b
- Show the person that exposed the most:
MATCH (carrier:Person)-[rel:Info]->(person:Person)
RETURN person, COUNT(*) AS Infections
ORDER BY Infections DESC
LIMIT 1
- What carriers had contact with the person who was exposed the most ?
MATCH (carrier:Person)-[rel:Info]->(person:Person)
WITH person, COUNT(*) AS Infections
ORDER BY Infections DESC
LIMIT 1
MATCH (person:Person)<-[r]-(p)
RETURN person, r, p
- Who in
Cordon A
did not infect anyone ?
MATCH (a)
WHERE NOT(a:Person)-[:Info]->()
AND a.Addr = 'CordonA'
RETURN a
- Select carrier that infected the most of their own cordon:
MATCH (carrier:Person)-[r]->(person:Person)
WHERE carrier.Addr = person.Addr
WITH carrier, COUNT(*) AS Infections
ORDER BY Infections DESC
LIMIT 2
MATCH (p:Person)<-[r]-(carrier)
RETURN p,r,carrier
- Show the path of the infection between
Person K
andPerson L
MATCH path=(p1:Person{name:'PersonK'})-[*]->(p2:Person{name:'PersonL'})
RETURN path