@@ -453,3 +453,101 @@ function getBiadjacencyMatrix(dfg::CloudGraphsDFG; solvable::Int=0)::NamedTuple{
453
453
454
454
return (B= adjMat, varLabels= varLabels, facLabels= factLabels)
455
455
end
456
+
457
+ # ## PPEs with DB calls
458
+
459
+ function listPPE (dfg:: CloudGraphsDFG , variablekey:: Symbol ; currentTransaction:: Union{Nothing, Neo4j.Transaction} = nothing ):: Vector{Symbol}
460
+ query = " match (ppe:PPE:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$variablekey ) return ppe.solverKey"
461
+ @debug " [CGDFG] PPE read query:\r\n $query "
462
+ result = nothing
463
+ if currentTransaction != nothing
464
+ result = currentTransaction (query; submit= true )
465
+ else
466
+ tx = transaction (dfg. neo4jInstance. connection)
467
+ tx (query)
468
+ result = commit (tx)
469
+ end
470
+ length (result. errors) > 0 && error (string (result. errors))
471
+ vals = map (d -> d[" row" ][1 ], result. results[1 ][" data" ])
472
+ return Symbol .(vals)
473
+ end
474
+
475
+ function getPPE (dfg:: CloudGraphsDFG , variablekey:: Symbol , ppekey:: Symbol = :default ; currentTransaction:: Union{Nothing, Neo4j.Transaction} = nothing ):: AbstractPointParametricEst
476
+ query = " match (ppe:PPE:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$variablekey :$(ppekey) ) return properties(ppe)"
477
+ @debug " [CGDFG] PPE read query:\r\n $query "
478
+ result = nothing
479
+ if currentTransaction != nothing
480
+ result = currentTransaction (query; submit= true )
481
+ else
482
+ tx = transaction (dfg. neo4jInstance. connection)
483
+ tx (query)
484
+ result = commit (tx)
485
+ end
486
+ length (result. errors) > 0 && error (string (result. errors))
487
+ length (result. results[1 ][" data" ]) != 1 && error (" Cannot find PPE '$ppekey ' for variable '$variablekey '" )
488
+ length (result. results[1 ][" data" ][1 ][" row" ]) != 1 && error (" Cannot find PPE '$ppekey ' for variable '$variablekey '" )
489
+ return unpackPPE (dfg, result. results[1 ][" data" ][1 ][" row" ][1 ])
490
+ end
491
+
492
+ function addPPE! (dfg:: CloudGraphsDFG , variablekey:: Symbol , ppe:: P , ppekey:: Symbol = :default ; currentTransaction:: Union{Nothing, Neo4j.Transaction} = nothing ):: AbstractPointParametricEst where P <: AbstractPointParametricEst
493
+ if ppekey in listPPE (dfg, variablekey, ppekey, currentTransaction= currentTransaction)
494
+ error (" PPE '$(ppekey) ' already exists" )
495
+ end
496
+ return updatePPE! (dfg, variablekey, ppe, ppekey, currentTransaction= currentTransaction)
497
+ end
498
+
499
+ function updatePPE! (dfg:: CloudGraphsDFG , variablekey:: Symbol , ppe:: P , ppekey:: Symbol = :default ; currentTransaction:: Union{Nothing, Neo4j.Transaction} = nothing ):: P where P <: AbstractPointParametricEst
500
+ packed = packPPE (dfg, ppe)
501
+ query = """
502
+ MATCH (var:VARIABLE:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$variablekey )
503
+ MERGE (ppe:PPE:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$variablekey :$(ppe. solverKey) )
504
+ SET ppe = $(_dictToNeo4jProps (packed))
505
+ CREATE UNIQUE (var)-[:PPE]->(ppe)
506
+ RETURN properties(ppe)"""
507
+ @debug " [CGDFG] PPE update query:\r\n $query "
508
+ result = nothing
509
+ if currentTransaction != nothing
510
+ result = currentTransaction (query; submit= true ) # TODO : Maybe we should submit (; submit = true) for the results to fail early?
511
+ else
512
+ tx = transaction (dfg. neo4jInstance. connection)
513
+ tx (query)
514
+ result = commit (tx)
515
+ end
516
+ length (result. errors) > 0 && error (string (result. errors))
517
+ length (result. results[1 ][" data" ]) != 1 && error (" Cannot find PPE '$(ppe. solverKey) ' for variable '$variablekey '" )
518
+ length (result. results[1 ][" data" ][1 ][" row" ]) != 1 && error (" Cannot find PPE '$(ppe. solverKey) ' for variable '$variablekey '" )
519
+ return unpackPPE (dfg, result. results[1 ][" data" ][1 ][" row" ][1 ])
520
+ end
521
+
522
+ function updatePPE! (dfg:: CloudGraphsDFG , sourceVariables:: Vector{<:DFGVariable} , ppekey:: Symbol = :default ; currentTransaction:: Union{Nothing, Neo4j.Transaction} = nothing )
523
+ tx = currentTransaction == nothing ? transaction (dfg. neo4jInstance. connection) : currentTransaction
524
+ for var in sourceVariables
525
+ updatePPE! (dfg, var. label, getPPE (dfg, var, ppekey), ppekey, currentTransaction= tx)
526
+ end
527
+ if currentTransaction == nothing
528
+ result = commit (tx)
529
+ end
530
+ return nothing
531
+ end
532
+
533
+ function deletePPE! (dfg:: CloudGraphsDFG , variablekey:: Symbol , ppekey:: Symbol = :default ; currentTransaction:: Union{Nothing, Neo4j.Transaction} = nothing ):: AbstractPointParametricEst
534
+ query = """
535
+ match (ppe:PPE:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$variablekey :$(ppekey) )
536
+ with ppe, properties(ppe) as props
537
+ detach delete ppe
538
+ return props
539
+ """
540
+ @debug " [CGDFG] PPE delete query:\r\n $query "
541
+ result = nothing
542
+ if currentTransaction != nothing
543
+ result = currentTransaction (query; submit= true ) # TODO : Maybe we should submit (; submit = true) for the results to fail early?
544
+ else
545
+ tx = transaction (dfg. neo4jInstance. connection)
546
+ tx (query)
547
+ result = commit (tx)
548
+ end
549
+ length (result. errors) > 0 && error (string (result. errors))
550
+ length (result. results[1 ][" data" ]) != 1 && error (" Cannot find PPE '$ppekey ' for variable '$variablekey '" )
551
+ length (result. results[1 ][" data" ][1 ][" row" ]) != 1 && error (" Cannot find PPE '$ppekey ' for variable '$variablekey '" )
552
+ return unpackPPE (dfg, @show result. results[1 ][" data" ][1 ][" row" ][1 ])
553
+ end
0 commit comments