Last active
December 24, 2023 16:28
-
-
Save wesslen/4b343f7be94cfbbae98318016c9a7c3c to your computer and use it in GitHub Desktop.
Python function to map random user ID's (e.g., crowdsource platform) to a unique Prodigy session name
This file contains 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 random | |
import string | |
def generate_random_userids(num_ids): | |
passwords = [] | |
for _ in range(num_ids): | |
password = ''.join(random.choices(string.ascii_letters + string.digits, k=12)) | |
passwords.append(password) | |
return passwords | |
def assign_session_id(new_user_id, session_ids): | |
# assumes session_ids are in order, hence next would be 1 more than length | |
next_session_number = len(session_ids) + 1 | |
next_session_id = "user" + str(next_session_number) | |
return {new_user_id: next_session_id} | |
## Test example | |
# new_user_id = "gxG1SyMBJb6I" | |
# assigned_sessions = [ | |
# {"aASB1k10tYmA": "user1"}, | |
# {"6rSei5t0sb8f": "user2"}, | |
# {"GiFTnff72opR": "user3"}, | |
# {"gzFuSyEuIJwh": "user4"} | |
# ] | |
# result = assign_session_id(new_user_id, assigned_sessions) | |
# print(result) | |
# {"gxG1SyMBJb6I": "user5"} | |
# General example | |
user_ids = generate_random_userids(10) | |
assigned_sessions = [] | |
for new_user_id in user_ids: | |
result = assign_session_id(new_user_id, assigned_sessions) | |
assigned_sessions.append(result) | |
for key,val in result.items(): | |
print(f"For user {key}, send them to https://my-prodigy-url.com?session={val}".format(key,val)) | |
# For user aASB1k10tYmA, send them to https://my-prodigy-url.com?session=user1 | |
# For user 6rSei5t0sb8f, send them to https://my-prodigy-url.com?session=user2 | |
# For user GiFTnff72opR, send them to https://my-prodigy-url.com?session=user3 | |
# For user gzFuSyEuIJwh, send them to https://my-prodigy-url.com?session=user4 | |
# For user gxG1SyMBJb6I, send them to https://my-prodigy-url.com?session=user5 | |
# For user wHV0a8xbqskh, send them to https://my-prodigy-url.com?session=user6 | |
# For user TgNjgNBr0wxt, send them to https://my-prodigy-url.com?session=user7 | |
# For user EL7nHI9nMY5b, send them to https://my-prodigy-url.com?session=user8 | |
# For user mrCMIbRqwGTJ, send them to https://my-prodigy-url.com?session=user9 | |
# For user AvZqcq7WsOaH, send them to https://my-prodigy-url.com?session=user10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LLM alternative recommendation: