← Return to the example · Supporting files

2020 02 Project task scheduling in Neo4j from Nicole White reviewed.cypher

CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
UNWIND [{_id:46, properties:{duration:10, earliest_finish:10, slack:0, name:"Identify waste", earliest_start:0, latest_start:0, latest_finish:10}}, {_id:47, properties:{duration:10, earliest_finish:50, slack:0, name:"Remove waste", earliest_start:40, latest_start:40, latest_finish:50}}, {_id:49, properties:{duration:20, earliest_finish:30, slack:0, name:"Prepare Waste extraction plan", latest_finish:30, earliest_start:10, latest_start:10}}, {_id:100, properties:{duration:0, earliest_finish:50, slack:0, name:"Finish", latest_start:50, earliest_start:50, latest_finish:50}}, {_id:102, properties:{duration:10, earliest_finish:40, slack:0, name:"Commission suppliers", earliest_start:30, latest_start:30, latest_finish:40}}, {_id:115, properties:{duration:0, earliest_finish:0, slack:0, name:"Start", latest_start:0, latest_finish:0, earliest_start:0}}] AS row
CREATE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row._id}) SET n += row.properties SET n:Task;
UNWIND [{_id:48, properties:{name:"Plan agreed"}}, {_id:103, properties:{name:"No waste left on site"}}, {_id:110, properties:{name:"Suppliers ready"}}, {_id:116, properties:{name:"Waste understood"}}] AS row
CREATE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row._id}) SET n += row.properties SET n:State;
UNWIND [{_id:111, properties:{role:"Engineer"}}, {_id:112, properties:{role:"Project_manager"}}, {_id:113, properties:{role:"Supplier"}}, {_id:114, properties:{role:"Operator"}}] AS row
CREATE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row._id}) SET n += row.properties SET n:Resource;
UNWIND [{start: {_id:112}, end: {_id:102}, properties:{}}, {start: {_id:113}, end: {_id:102}, properties:{}}, {start: {_id:111}, end: {_id:49}, properties:{}}, {start: {_id:113}, end: {_id:47}, properties:{}}, {start: {_id:114}, end: {_id:46}, properties:{}}] AS row
MATCH (start:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.start._id})
MATCH (end:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.end._id})
CREATE (start)-[r:allocated_to]->(end) SET r += row.properties;
UNWIND [{start: {_id:116}, end: {_id:49}, properties:{}}, {start: {_id:110}, end: {_id:47}, properties:{}}, {start: {_id:48}, end: {_id:102}, properties:{}}] AS row
MATCH (start:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.start._id})
MATCH (end:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.end._id})
CREATE (start)-[r:permits]->(end) SET r += row.properties;
UNWIND [{start: {_id:47}, end: {_id:103}, properties:{}}, {start: {_id:49}, end: {_id:48}, properties:{}}, {start: {_id:102}, end: {_id:110}, properties:{}}, {start: {_id:46}, end: {_id:116}, properties:{}}] AS row
MATCH (start:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.start._id})
MATCH (end:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.end._id})
CREATE (start)-[r:causes]->(end) SET r += row.properties;
UNWIND [{start: {_id:49}, end: {_id:102}, properties:{}}, {start: {_id:102}, end: {_id:47}, properties:{}}, {start: {_id:115}, end: {_id:46}, properties:{}}, {start: {_id:46}, end: {_id:49}, properties:{}}, {start: {_id:47}, end: {_id:100}, properties:{}}] AS row
MATCH (start:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.start._id})
MATCH (end:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.end._id})
CREATE (start)-[r:permits]->(end) SET r += row.properties;
MATCH (n:`UNIQUE IMPORT LABEL`)  WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;