Last active
August 29, 2015 13:56
-
-
Save dideler/9164196 to your computer and use it in GitHub Desktop.
Trying a feature on a percentage of users.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Modified version of the snippet that appears in: | |
| # http://blog.disqus.com/post/789540337/partial-deployment-with-feature-switches | |
| def get_for_user(self, user): | |
| """Returns true if experimental feature should be enabled for users. | |
| percent_range determines the set of users that get access. | |
| E.g. (35, 45) does NOT mean 35-45% of users get access! | |
| It means that 10% of users get access, but only users with an ID ending in 35 to 44. | |
| """ | |
| if 'users' in self.value: | |
| percent_range = (0, 10) # 10% of users. | |
| return percent_range[0] <= user.id % 100 < percent_range[1] | |
| return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment