From 332718d2fa2fd06fe5adca0627daea7c6815468c Mon Sep 17 00:00:00 2001 From: Etesam Ansari Date: Mon, 8 Aug 2022 15:26:32 -0400 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20Added=20ability=20to=20clear=20?= =?UTF-8?q?onboarding=20for=20a=20worker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assets/tips.csv | 0 .../blueprints/mixins/onboarding_required.py | 6 +++++ .../local_db/clear_worker_onboarding.py | 24 +++++++++++++++++++ 3 files changed, 30 insertions(+) delete mode 100644 examples/static_react_task_with_tips/assets/tips.csv create mode 100644 mephisto/scripts/local_db/clear_worker_onboarding.py diff --git a/examples/static_react_task_with_tips/assets/tips.csv b/examples/static_react_task_with_tips/assets/tips.csv deleted file mode 100644 index e69de29bb..000000000 diff --git a/mephisto/abstractions/blueprints/mixins/onboarding_required.py b/mephisto/abstractions/blueprints/mixins/onboarding_required.py index caacf575b..7c9555d2b 100644 --- a/mephisto/abstractions/blueprints/mixins/onboarding_required.py +++ b/mephisto/abstractions/blueprints/mixins/onboarding_required.py @@ -147,6 +147,12 @@ def init_onboarding_config( db, self.onboarding_failed_name ) + @classmethod + def clear_onboarding(self, worker: "Worker", qualification_name: str): + worker.revoke_qualification(qualification_name) + if qualification_name is not None: + worker.revoke_crowd_qualification(self.get_failed_qual(qualification_name)) + def get_onboarding_data(self, worker_id: str) -> Dict[str, Any]: """ If the onboarding task on the frontend requires any specialized data, the blueprint diff --git a/mephisto/scripts/local_db/clear_worker_onboarding.py b/mephisto/scripts/local_db/clear_worker_onboarding.py new file mode 100644 index 000000000..d3dfcf8ec --- /dev/null +++ b/mephisto/scripts/local_db/clear_worker_onboarding.py @@ -0,0 +1,24 @@ +from mephisto.abstractions.blueprints.mixins.onboarding_required import ( + OnboardingRequired, +) +from mephisto.abstractions.databases.local_database import LocalMephistoDB +from mephisto.data_model.worker import Worker +from rich import print +from rich.prompt import Prompt, IntPrompt + + +def main(): + worker_id = str(IntPrompt.ask("What is the worker's id:", default=1)) + qualification_name = Prompt.ask( + "What is the qualification name:", default="test-react-static-qualification" + ) + db = LocalMephistoDB() + desired_worker = Worker.get(db, worker_id) + OnboardingRequired.clear_onboarding( + worker=desired_worker, qualification_name=qualification_name + ) + print("\n[green]Cleared that onboarding[/green]\n") + + +if __name__ == "__main__": + main() From 3410de255b9929b77363d157173405129dfb9438 Mon Sep 17 00:00:00 2001 From: Etesam Ansari Date: Mon, 8 Aug 2022 15:34:38 -0400 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=94=A8=20Added=20clear=5Fworker=5Fonb?= =?UTF-8?q?oarding.py=20to=20scripts=20cli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mephisto/client/cli.py | 3 +++ mephisto/scripts/local_db/clear_worker_onboarding.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mephisto/client/cli.py b/mephisto/client/cli.py index 8fac20342..5ddfdb75b 100644 --- a/mephisto/client/cli.py +++ b/mephisto/client/cli.py @@ -18,6 +18,7 @@ import mephisto.scripts.local_db.remove_accepted_tip as remove_accepted_tip_local_db import mephisto.scripts.local_db.review_feedback_for_task as review_feedback_local_db import mephisto.scripts.local_db.load_data_to_mephisto_db as load_data_local_db +import mephisto.scripts.local_db.clear_worker_onboarding as clear_worker_onboarding_local_db import mephisto.scripts.heroku.initialize_heroku as initialize_heroku import mephisto.scripts.metrics.view_metrics as view_metrics import mephisto.scripts.metrics.shutdown_metrics as shutdown_metrics @@ -289,6 +290,7 @@ def print_non_markdown_list(items: List[str]): "remove_tip", "review_feedback", "load_data", + "clear_worker_onboarding", ] HEROKU_VALID_SCRIPTS_NAMES = ["initialize"] METRICS_VALID_SCRIPTS_NAMES = ["view", "shutdown"] @@ -307,6 +309,7 @@ def print_non_markdown_list(items: List[str]): LOCAL_DB_VALID_SCRIPTS_NAMES[1]: remove_accepted_tip_local_db.main, LOCAL_DB_VALID_SCRIPTS_NAMES[2]: review_feedback_local_db.main, LOCAL_DB_VALID_SCRIPTS_NAMES[3]: load_data_local_db.main, + LOCAL_DB_VALID_SCRIPTS_NAMES[4]: clear_worker_onboarding_local_db.main, }, }, "heroku": { diff --git a/mephisto/scripts/local_db/clear_worker_onboarding.py b/mephisto/scripts/local_db/clear_worker_onboarding.py index d3dfcf8ec..65a008227 100644 --- a/mephisto/scripts/local_db/clear_worker_onboarding.py +++ b/mephisto/scripts/local_db/clear_worker_onboarding.py @@ -8,16 +8,18 @@ def main(): + db = LocalMephistoDB() worker_id = str(IntPrompt.ask("What is the worker's id:", default=1)) + desired_worker = Worker.get(db, worker_id) + qualification_name = Prompt.ask( "What is the qualification name:", default="test-react-static-qualification" ) - db = LocalMephistoDB() - desired_worker = Worker.get(db, worker_id) + OnboardingRequired.clear_onboarding( worker=desired_worker, qualification_name=qualification_name ) - print("\n[green]Cleared that onboarding[/green]\n") + print("\n[green]Cleared that onboarding qualification[/green]\n") if __name__ == "__main__": From abda24cc115c0f45f978593ddb607e9bc3be6a28 Mon Sep 17 00:00:00 2001 From: Etesam Ansari Date: Mon, 8 Aug 2022 16:03:53 -0400 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=85=20Added=20.gitkeep=20in=20assets?= =?UTF-8?q?=20folder=20to=20allow=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ℹ️ This file allows for git to allow you to commit an empty folder. This assets folder is important for the tips cypress tests. --- examples/parlai_chat_task_demo/assets/.gitkeep | 0 examples/remote_procedure/mnist/assets/.gitkeep | 0 examples/remote_procedure/template/assets/.gitkeep | 0 examples/remote_procedure/toxicity_detection/assets/.gitkeep | 0 examples/static_react_task/assets/.gitkeep | 0 examples/static_react_task_with_tips/assets/.gitkeep | 0 6 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/parlai_chat_task_demo/assets/.gitkeep create mode 100644 examples/remote_procedure/mnist/assets/.gitkeep create mode 100644 examples/remote_procedure/template/assets/.gitkeep create mode 100644 examples/remote_procedure/toxicity_detection/assets/.gitkeep create mode 100644 examples/static_react_task/assets/.gitkeep create mode 100644 examples/static_react_task_with_tips/assets/.gitkeep diff --git a/examples/parlai_chat_task_demo/assets/.gitkeep b/examples/parlai_chat_task_demo/assets/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/examples/remote_procedure/mnist/assets/.gitkeep b/examples/remote_procedure/mnist/assets/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/examples/remote_procedure/template/assets/.gitkeep b/examples/remote_procedure/template/assets/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/examples/remote_procedure/toxicity_detection/assets/.gitkeep b/examples/remote_procedure/toxicity_detection/assets/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/examples/static_react_task/assets/.gitkeep b/examples/static_react_task/assets/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/examples/static_react_task_with_tips/assets/.gitkeep b/examples/static_react_task_with_tips/assets/.gitkeep new file mode 100644 index 000000000..e69de29bb From 3af2e4093c2a161fafee9b133551b68f66b60703 Mon Sep 17 00:00:00 2001 From: Etesam Ansari Date: Tue, 9 Aug 2022 17:32:05 -0400 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9C=A8=20Workers=20now=20searched=20by?= =?UTF-8?q?=20name=20in=20clear=5Fonboarding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../local_db/clear_worker_onboarding.py | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/mephisto/scripts/local_db/clear_worker_onboarding.py b/mephisto/scripts/local_db/clear_worker_onboarding.py index 65a008227..b617164e6 100644 --- a/mephisto/scripts/local_db/clear_worker_onboarding.py +++ b/mephisto/scripts/local_db/clear_worker_onboarding.py @@ -4,14 +4,56 @@ from mephisto.abstractions.databases.local_database import LocalMephistoDB from mephisto.data_model.worker import Worker from rich import print -from rich.prompt import Prompt, IntPrompt +from rich.prompt import Prompt + +""" +In this script we are asking for a worker_id, but we are actually using it as a worker_name. +In the database a worker_id is a number like 1 or 2, while a worker_name is like "x_sandbox". +However, when looking at an url like: http://localhost:3000/?worker_id=x&assignment_id=45 +the worker_id is "x". + +As the user is more likely to think of the worker_id as "x" instead of 1, we +are calling the worker_name, the worker_id. + +In the url example above, this script would first check if there are any workers with the name x. +If there is one, then that worker's onboarding qualification will be revoked. If there are +more than one worker with that name the script aborts. + +If there are no workers with that name, it then tries the name "x_sandbox". The _sandbox +affix is commonly attached to worker names in the backend, so that is why "x_sandbox" +is also tried. +""" def main(): db = LocalMephistoDB() - worker_id = str(IntPrompt.ask("What is the worker's id:", default=1)) - desired_worker = Worker.get(db, worker_id) + worker_id = str(Prompt.ask("What is the worker's id:", default="x")) + + desired_worker = db.find_workers(worker_name=worker_id) + + if len(desired_worker) == 0: + worker_id_with_sandbox = worker_id + "_sandbox" + sandbox_workers = db.find_workers(worker_name=worker_id_with_sandbox) + + if len(sandbox_workers) == 0: + print("\n[red]There are no workers with that name[/red]\n") + quit() + + elif len(sandbox_workers) > 1: + print("\n[red] There is more that one worker with that name[/red]\n") + quit() + + clear_onboarding(sandbox_workers[0]) + quit() + + elif len(desired_worker > 1): + print("\n[red]There is more than one worker with that name[/red]\n") + quit() + + clear_onboarding(desired_worker[0]) + +def clear_onboarding(desired_worker: Worker): qualification_name = Prompt.ask( "What is the qualification name:", default="test-react-static-qualification" )