Last active
November 14, 2018 00:08
-
-
Save claudijd/15ccfe5f72841ff4bc2143728ae2ffd6 to your computer and use it in GitHub Desktop.
A demo of pickle usage vs. random usage respective to existing and proposed
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
| import pickle | |
| import os.path | |
| import random | |
| # Old pickle queue logic (summarized) | |
| pickle_cache_file = "pickle.queue" | |
| reset_list_count = 0 | |
| assignment_rounds = 50 | |
| assignee_list_rotation_events = 0 | |
| assignment_counts_pickle = { | |
| "user1@mozilla.com": 0, | |
| "user2@mozilla.com": 0, | |
| "user3@mozilla.com": 0 | |
| } | |
| # If a queue is not initialized, create one | |
| if not os.path.isfile(pickle_cache_file): | |
| assign_hash = ['user1@mozilla.com', | |
| 'user2@mozilla.com', 'user3@mozilla.com'] | |
| assign_list = assign_hash[:] | |
| with open(pickle_cache_file, 'wb') as f: | |
| pickle.dump((assign_list, assign_hash), f) | |
| # Emulate a specific round | |
| for iteration in range(1, assignment_rounds): | |
| # Incremeent reset list counter | |
| reset_list_count += 1 | |
| with open(pickle_cache_file, 'rb') as f: | |
| assign_list, assign_hash = pickle.load(f) | |
| # Emulate a list reset at arbitrary times, to simulate an assignee edit | |
| if reset_list_count % random.randint(1, 28) == 0: | |
| assignee_list_rotation_events += 1 | |
| assign_hash = ['user1@mozilla.com', | |
| 'user2@mozilla.com', 'user3@mozilla.com'] | |
| assign_list = assign_hash[:] | |
| assignee = assign_list.pop() | |
| assign_list.insert(0, assignee) | |
| # Add a count to whomever was assigned | |
| assignment_counts_pickle[assignee] += 1 | |
| with open(pickle_cache_file, 'wb') as f: | |
| pickle.dump((assign_list, assign_hash), f) | |
| print("Pickle Strategy... (with {} rotation edits)".format( | |
| str(assignee_list_rotation_events))) | |
| print(assignment_counts_pickle) | |
| # New random.choice logic (summarized) | |
| assign_hash = ['user1@mozilla.com', | |
| 'user2@mozilla.com', 'user3@mozilla.com'] | |
| assignment_counts_random = { | |
| "user1@mozilla.com": 0, | |
| "user2@mozilla.com": 0, | |
| "user3@mozilla.com": 0 | |
| } | |
| for iteration in range(1, assignment_rounds): | |
| assignee = random.choice(assign_hash) | |
| assignment_counts_random[assignee] += 1 | |
| print("Random Strategy...") | |
| print(assignment_counts_random) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
with rotation logic: