diff options
| author | LV-426 <lv-426@taproot.org.il> | 2015-05-17 17:57:00 +0300 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2015-05-17 18:07:51 +0300 |
| commit | 7e13f1fc247e8157abedbdf3f20e95012dee7a05 (patch) | |
| tree | 163d0157c06aa673ade9c7601d2498356f3532d8 /src/server-tests | |
| parent | be61af9c3f8bca1428dad7eaba1ad6c8da58e666 (diff) | |
refactoring DBO_RDG__skill_graph out of Test_Domain_CRI
Diffstat (limited to 'src/server-tests')
| -rw-r--r-- | src/server-tests/test_util__rzdoc.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/server-tests/test_util__rzdoc.py b/src/server-tests/test_util__rzdoc.py new file mode 100644 index 00000000..ffcc2423 --- /dev/null +++ b/src/server-tests/test_util__rzdoc.py @@ -0,0 +1,65 @@ +from db_op import DBO_cypher_query +import neo4j_util + + +class DBO_RDG__skill_graph(DBO_cypher_query): + + def __init__(self, rzdoc, + lim_n=50, + lim_r=10000, + prob_link_create=0.03, + name_set=['Bruce Lee', 'Kesuke Miyagi'], + skill_set=['Kung Foo', 'Karate'], + skill_level_set=['Novice', 'Intermediate', 'Expert'] + ): + """ + Random data generator: + - Name x Skill[proficiency: {Novice|Intermediate|Expert}] + """ + super(DBO_RDG__skill_graph, self).__init__() + + rzdoc_label = neo4j_util.rzdoc__ns_label(rzdoc) + min_id = 10000 # separate group ids with numerical perfix + + # create persons + q_arr = ['with {name_set} as n_attr_set', # TODO clean: foreach triggers SyntaxException: otherwise + 'foreach (idx in range(0,%d)' % (lim_n - 1), + '|', + 'create (n:%s:%s' % (rzdoc_label, 'Person'), + '{id: \'test-id_\' + toString(%d + idx),' % (min_id), + 'name: n_attr_set[idx %% %d]}' % (len(name_set)), + '))', + ] + q_param = {'name_set': name_set} + self.add_statement(q_arr, q_param) + min_id *= 2 + + # create skills + q_arr = ['with {skill_set} as skill_set', # TODO clean: foreach triggers SyntaxException: otherwise + 'foreach (idx in range(0,%d)' % (len(skill_set) - 1), + '|', + 'create (n:%s:%s' % (rzdoc_label, 'Skill'), + '{id: \'test-id_\' + toString(idx + %d),' % (min_id), + 'name: skill_set[idx]}', + '))', + ] + q_param = {'skill_set': skill_set} + self.add_statement(q_arr, q_param) + min_id *= 2 + + # create links + for skill_level in skill_level_set: + q_arr = ['match (n:%s),(m:%s)' % ('Person', 'Skill'), + 'with n, m, rand() as rand', + 'order by rand', + 'limit %d' % (lim_r - 1), + 'where rand() < %.2f' % (prob_link_create), + 'create (n)-[r:%s' % (skill_level), + '{id: \'test-id_\' + toString(%d + toInt(%d * rand())),' % (min_id, lim_r * 100000), # aim for low id collision probability, + 'proficiency: \'%s\'}' % (skill_level), + ']->(m)', + 'return collect(r.id)', + ] + + self.add_statement(q_arr, q_param) + |
