diff options
| author | Alon Levy <alon@pobox.com> | 2014-12-16 17:14:32 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-12-16 17:14:32 +0200 |
| commit | c7d026b1d504323a8c61d51b726e5e8d2337fc4b (patch) | |
| tree | 75607d07c90beb8024e34afd2bab3503dcaccda4 /src-py_test/neo4j_test_util.py | |
| parent | dff765d765085fe2ee172abc606f4f8b25a39c27 (diff) | |
| parent | 38078c537f642806e4849dc99c07d679f816fe23 (diff) | |
Merging rhizi-server into rhizi, back to a single repo
Merge remote-tracking branch 'old-server/master' into wip/map-nodes-by-id_minimize-name-use
Diffstat (limited to 'src-py_test/neo4j_test_util.py')
| -rw-r--r-- | src-py_test/neo4j_test_util.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src-py_test/neo4j_test_util.py b/src-py_test/neo4j_test_util.py new file mode 100644 index 00000000..d5aa640a --- /dev/null +++ b/src-py_test/neo4j_test_util.py @@ -0,0 +1,54 @@ +import uuid +import string +from random import choice +import db_controller as dbc + +def rand_id(): + return str(uuid.uuid4()) + +def rand_label(length=8): + """ + return random label + """ + char_set = string.ascii_lowercase + string.ascii_uppercase + string.digits + return ''.join([choice(string.ascii_lowercase)] + [choice(char_set) for _ in range(length - 1)]) + +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) + |
