I've a graph network of 5 nodes (train stations) as in the image below. Every station has a Code, Name, Division and State and then there are relationships with details of Journey_Date, Distance_KM, Time_Taken in hours.
Presently the relationship I could build is at trip level (row level in csv/excel) details. The cypher code for that is:
Step 1)
LOAD CSV WITH HEADERS FROM "file:///five_stations.csv" AS row WITH row MERGE (:Station {name:row.Origin, code:row.Origin_Code, division:row.Origin_Division, state:row.Origin_State, zone:row.Origin_Zone}) MERGE (:Station {name:row.Destination, code:row.Destination_Code, division:row.Destination_Division, state:row.Destination_State, zone:row.Destination_Zone});
Step 2)
LOAD CSV WITH HEADERS FROM "file:///five_stations.csv" AS row WITH row MATCH (origin:Station {code:row.Origin_Code}), (destination:Station {code:row.Destination_Code}) CREATE (origin)-[:Time_Taken {timeTaken:row.Time, jrnyDate:row.Journey_Date, distance:row.Distance_KM}]->(destination);
I want to find:
- All combination of 2 hops between Main Station back to Main Station
- Show only combination of 2 hops which fall within a certain time limit (eg: show all round trips where the journey took less than n hours [addition of each hop's time taken])
- Show only combination of 2 hops which fall within a certain kilometre limit (eg: show all round trips where the journey took less than x kms [addition of each hop's distance])
- Start date of journey from Main Station of any particular train should be End date of any previous journey [Journey_Date is in 9/27/2019 format]
- The above 2 hop is on the same 5 station, but it can be n number of hops when we scale up to more.
Note: I'm new to Cypher and Neo4j, asked a question on the same, if you too are learning, you can go through the QA here.