Skip to content

Commit

Permalink
fix checking whether client id is in experiment (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
eu9ene authored Dec 9, 2020
1 parent c688525 commit f5693b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion taar/recommenders/randomizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def in_experiment(client_id, xp_prob=0.5):
"""
hex_client = "".join([c for c in client_id.lower() if c in "abcdef0123456789"])
int_client = int(hex_client, 16)
return int((int_client % 100) <= (xp_prob * 100))
return int((int_client % 100) < (xp_prob * 100))


def reorder_guids(guid_weight_tuples, size=None):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_randomizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ def test_experimental_branch_guid():

total = sum([in_experiment(id, cutoff - 0.1) for i in range(100)])
assert total == 0


def test_in_experiment_zero_prob():
"""
Test the edge case when some client IDs go to experiment even with 0 probability.
"""
assert not in_experiment('0ace1ca2a3519332ab93e76a049fe74091fa8fc9063399caa8545dd23f93de5c', xp_prob=0.0)

0 comments on commit f5693b7

Please sign in to comment.