Skip to content

Commit

Permalink
PERF: sortedset to list for feature and sample data (#53)
Browse files Browse the repository at this point in the history
* PERF: sortedset to list for feature and sample data

* STY and BIOM comma

* Missed one test

* STY: remove noqa

* The style gods were unhappy
  • Loading branch information
wasade authored and antgonza committed Feb 8, 2018
1 parent 649abbb commit 3200355
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
18 changes: 8 additions & 10 deletions redbiom/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ class ScriptManager:
local result = {}
local formedkey = context .. ':' .. 'feature' .. ':' .. key
local items = redis.call('ZRANGEBYSCORE',
local items = redis.call('LRANGE',
formedkey,
'-inf', 'inf',
'withscores')
'0', '-1')
-- adapted from https://gist.github.com/klovadis/5170446
local resultkey
Expand All @@ -39,10 +38,9 @@ class ScriptManager:
local result = {}
local formedkey = context .. ':' .. 'sample' .. ':' .. key
local items = redis.call('ZRANGEBYSCORE',
local items = redis.call('LRANGE',
formedkey,
'-inf', 'inf',
'withscores')
'0', '-1')
-- adapted from https://gist.github.com/klovadis/5170446
local resultkey
Expand Down Expand Up @@ -203,8 +201,8 @@ def load_sample_data(table, context, tag=None, redis_protocol=False):
---------------------
EVALSHA <get-index-sha1> 1 <context>:feature-index <feature_id>
EVALSHA <get-index-sha1> 1 <context>:sample-index <redbiom_id>
ZADD <context>:samples:<redbiom_id> <count> <feature_id> ...
ZADD <context>:features:<redbiom_id> <count> <redbiom_id> ...
LPUSH <context>:samples:<redbiom_id> <count> <feature_id> ...
LPUSH <context>:features:<redbiom_id> <count> <redbiom_id> ...
SADD <context>:samples-represented <redbiom_id> ... <redbiom_id>
SADD <context>:features-represented <feature_id> ... <feature_id>
Expand Down Expand Up @@ -243,7 +241,7 @@ def load_sample_data(table, context, tag=None, redis_protocol=False):
packed = '/'.join(["%d/%s" % (v, i)
for i, v in zip(remapped,
int_values.data)])
post(context, 'ZADD', 'sample:%s/%s' % (id_, packed))
post(context, 'LPUSH', 'sample:%s/%s' % (id_, packed))

payload = "samples-represented/%s" % '/'.join(samples)
post(context, 'SADD', payload)
Expand All @@ -256,7 +254,7 @@ def load_sample_data(table, context, tag=None, redis_protocol=False):
packed = '/'.join(["%d/%s" % (v, i)
for i, v in zip(remapped,
int_values.data)])
post(context, 'ZADD', 'feature:%s/%s' % (id_, packed))
post(context, 'LPUSH', 'feature:%s/%s' % (id_, packed))

payload = "features-represented/%s" % '/'.join(obs)
post(context, 'SADD', payload)
Expand Down
12 changes: 6 additions & 6 deletions redbiom/tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def test_feature_sample_associations(self):
inv_index = get('HGETALL', 'test:sample-index-inverted')
for values, id_, _ in table.iter(axis='observation'):
exp = set(sample_ids[values > 0])
obs = get('ZRANGEBYSCORE', 'test:feature:%s/%s/%s' %
(id_, '-inf', 'inf'))
obs = {inv_index[i] for i in obs}
obs = get('LRANGE', 'test:feature:%s/%s/%s' %
(id_, '0', '-1'))
obs = {inv_index[i] for i in obs[::2]}
self.assertEqual(obs, exp)

def test_sample_data(self):
Expand All @@ -64,9 +64,9 @@ def test_sample_data(self):
exp_ids = feature_ids[values > 0]
exp_dict = {i: v for i, v in zip(exp_ids, exp_data)}

obs = get('ZRANGEBYSCORE',
'test:sample:UNTAGGED_%s/%s/%s/%s' %
(id_, "-inf", "inf", "withscores"))
obs = get('LRANGE',
'test:sample:UNTAGGED_%s/%s/%s' %
(id_, "0", "-1"))
obs_dict = {inv_index[i]: float(v) for i, v in zip(obs[::2],
obs[1::2])}

Expand Down

0 comments on commit 3200355

Please sign in to comment.