I have a problem with calculating SUM amongst nodes in the subgraph. If I have a binary tree then I need to sum a certain property namely "weight" on nodes. for example, I should SUM all weight on the right side of specific nodes. Next Problem is, that 10 levels (depth) after that node in this path formula will be changed. So I need to return all SUM weight at every level. For instance, is my aim output:
levels|sum of weights__
1 | 16
2 | 7
..... and so on
I don’t know if a way to do that using cypher. Cypher really works on paths, not subtrees.
Your problem is easily solved by writing your own procedure. The procedure would take a node as an input, which would represent the point in your tree that you want to begin the calculation. You would then use the neo4j API to traverse the graph recursively to calculate your metric at each node. You would roll up the level and calculated metric at each level. The end result would be a list of pairs, level and value.
I have performed similar calculations in my application. Let me know if you want help getting started if you decide to pursue this approach.