summaryrefslogtreecommitdiff
path: root/src-py
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2014-10-28 00:33:33 +0200
committerLV-426 <lv-426@taproot.org.il>2014-10-28 00:33:33 +0200
commit0f36eab1af1978bb0b1bacc5edcf59df253e573e (patch)
tree96911535256c4a9b3e1b948a2b4ff181819bda8f /src-py
parent89915ecebb2c3f8994ce3b727050ce35714acd78 (diff)
initial random neo4j data generator - use to avoid loading DB dumps
Diffstat (limited to 'src-py')
-rw-r--r--src-py/neo4j_test_util.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/src-py/neo4j_test_util.py b/src-py/neo4j_test_util.py
index 8edac1b2..d5c30a7f 100644
--- a/src-py/neo4j_test_util.py
+++ b/src-py/neo4j_test_util.py
@@ -8,3 +8,37 @@ def flush_db(db_ctl):
complete DB flush: remove all nodes & links
"""
db_ctl.exec_cypher_query('match (n) optional match (n)-[r]-() delete n,r')
+
+
+def gen_rand_data(db_ctl, lim_n=128, lim_r=256, prob_link_create = 0.3):
+ """
+ generate random DB data
+
+ @return: tuple consisting of the random node,link labels generated
+ """
+ assert 2 <= lim_n
+
+ n_label = rand_label()
+ r_label = rand_label()
+ q_arr = ['with 0 as _', # TODO clean: foreach triggers SyntaxException: otherwise
+ 'foreach (rid in range(0,%d)' % (lim_n - 1),
+ '|',
+ 'create (:%s {id:rid, n_attr_0:toInt(%d * rand())}))' % (n_label, lim_n)
+ ]
+
+ q = ' '.join(q_arr)
+ op = dbc.DBO_cypher_query(q)
+ db_ctl.exec_op(op)
+
+ q_arr = ['match (s:%s),(d:%s)' % (n_label, n_label),
+ 'with s,d',
+ 'limit %d' % (lim_r - 1),
+ 'where rand() < %.2f' % (prob_link_create),
+ 'create (s)-[:%s {l_attr_0:toInt(%d * rand())}]->(d)' % (r_label,lim_r)]
+
+ q = ' '.join(q_arr)
+ op = dbc.DBO_cypher_query(q)
+ db_ctl.exec_op(op)
+
+ return (n_label, r_label)
+