Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Last active May 30, 2020 06:18
Show Gist options
  • Save vladbatushkov/de77813eb05f9ccecc9339733569d9ad to your computer and use it in GitHub Desktop.
Save vladbatushkov/de77813eb05f9ccecc9339733569d9ad to your computer and use it in GitHub Desktop.
Sub-graph for money graph, that connects Transactions via HOPs
// clean up HOPS
CALL apoc.periodic.iterate(
"MATCH (:Transaction)-[r:HOP]->(:Transaction) RETURN r",
"DETACH DELETE r",
{ batchSize: 10000, parallel: false });
// generate HOP relationships
CALL apoc.periodic.iterate(
"MATCH (t1:Transaction)<-[:IN]-(e)-[:OUT]->(t2:Transaction)
WHERE (e:Client OR e:Company)
AND t1.timestamp < t2.timestamp
AND t2.amount < t1.amount
AND (t1.amount - t2.amount) / t1.amount < 0.25
RETURN t1, t2",
"MERGE (t1)-[:HOP]->(t2)",
{ batchSize: 10000, parallel: false });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment