cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Model path based on dates

Hi,
I have data structured as in the photo. I wonder how to model this so that I can see the progression of files being worked on by certain users:

file1 was worked on by user1 then user2 then user3
file2 was worked on by user1 then user3 then user2

2X_d_d507bdf8add0ef32c0d8350f7310aa498db50707.png

many thanks in advance

3 REPLIES 3

nghia71
Node Clone

IMHO, I think one of the ways is to have the changes arranged in a "linked list":

(f:File)-[:CHANGE]->(c1:Change)-[:NEXT]->(c2:Change)->...-[:CHANGE]->(cn:Change)

Each Change node can contain what are worth to be stored.

Each user is linked to such change that he/she made:

(u1:User)-[:MADE_CHANGE {type: 'Create']->(c1: Change)
(u2:User)-[:MADE_CHANGE {type: 'Edit']->(c1: Change)
...

Of course this approach would make User node to be Supernode if there are large number of users and their edits.

My two cents.

Using LOAD CSV, and temporal data types, there are many options. Personally, I would lean toward the following pattern:

See Also: date, datetime, and durations

(:User)<-[:EDITED_BY]-(:File)

user-edits.csv

It's best to adjust the date-format to follow the built-in standard: YYYY-MM-DD (can include time: YYYY-MM-DDTHH:MM:SS ex: 2020-10-06T18:52). However, you can also use apoc.date.parse, to handle almost any format.

user, file, date_opened
user1, file1, 2020-07-15
user1, file1, 2020-07-16
user1, file2, 2020-07-16
user2, file1, 2020-07-17
user2, file2, 2020-07-20
user3, file1, 2020-07-18
user3, file2, 2020-07-18

Load the CSV

Put the csv in the $NEO4J/imports directory, or on a publicly accessible url.

LOAD CSV WITH HEADERS FROM 'user-edits.csv' AS line
WITH line,
   date(line.date_opened) as editDate
MERGE (user :User {name: line.user})
MERGE (file :File {name: line.file})
MERGE (user)<-[edit:EDITED_BY {date: editDate}]-(file)

2X_9_979e8bcb1bccd7377e40ffb0426adb64842f991b.png

Get your results

Since all you asked for was the order users worked on a certain file, I'll collect them into a list for each file:

MATCH (f:File)-[e:EDITED_BY]->(u:User)
WITH f, u ORDER BY e.date ASC
RETURN f.name, collect(u.name) as users

2X_c_c49d97d7f9361c86ba626fb63d6e88a2466fe20e.png

Thanks! This is a very neat and straightforward solution!