Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more general function with better name #893

Merged
merged 12 commits into from
Sep 2, 2022
24 changes: 12 additions & 12 deletions .github/workflows/cypress-end-to-end-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ jobs:
uses: actions/setup-python@v2

- name: 🪨 Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 16.16.0

- name: 🤖 Install Mephisto
run: pip install -e .
Expand Down Expand Up @@ -116,9 +116,9 @@ jobs:
uses: actions/setup-python@v2

- name: 🪨 Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 16.16.0

- name: 🤖 Install Mephisto
run: pip install -e .
Expand Down Expand Up @@ -161,9 +161,9 @@ jobs:
uses: actions/setup-python@v2

- name: 🪨 Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 16.16.0

- name: 🤖 Install Mephisto
run: pip install -e .
Expand Down Expand Up @@ -205,9 +205,9 @@ jobs:
uses: actions/setup-python@v2

- name: 🪨 Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 16.16.0

- name: 🤖 Install Mephisto
run: |
Expand Down Expand Up @@ -251,9 +251,9 @@ jobs:
uses: actions/setup-python@v2

- name: 🪨 Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 16.16.0

- name: 🤖 Install Mephisto
run: pip install -e .
Expand Down Expand Up @@ -295,9 +295,9 @@ jobs:
uses: actions/setup-python@v2

- name: 🪨 Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 16.16.0

- name: 🤖 Install Mephisto
run: |
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ We actively welcome your pull requests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
* This can be done by running `pre-commit install`. This will check the if your code is formatted correctly on each commit.
* This can be done by running `pip install pre-commit; pre-commit install`. This will check the if your code is formatted correctly on each commit.
* Make sure that pre-commit is installed by following the steps in [this website](https://pre-commit.com/).
6. If you haven't already, complete the Contributor License Agreement ("CLA").

Expand Down Expand Up @@ -80,4 +80,4 @@ By contributing to Mephisto, you agree that your contributions will be licensed
under the LICENSE file in the root directory of this source tree.

## Dependencies
To add a python dependency you need to add the dependency as well as its version number to the pyproject.toml file.
To add a python dependency you need to add the dependency as well as its version number to the pyproject.toml file.
2 changes: 1 addition & 1 deletion mephisto/abstractions/databases/local_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def _get_connection(self) -> Connection:
curr_thread = threading.get_ident()
if curr_thread not in self.conn or self.conn[curr_thread] is None:
try:
conn = sqlite3.connect(self.db_path)
conn = sqlite3.connect(self.db_path, check_same_thread=False)
conn.row_factory = StringIDRow
self.conn[curr_thread] = conn
except sqlite3.Error as e:
Expand Down
2 changes: 1 addition & 1 deletion mephisto/abstractions/providers/mock/mock_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _get_connection(self) -> sqlite3.Connection:
"""
curr_thread = threading.get_ident()
if curr_thread not in self.conn or self.conn[curr_thread] is None:
conn = sqlite3.connect(self.db_path)
conn = sqlite3.connect(self.db_path, check_same_thread=False)
conn.row_factory = sqlite3.Row
self.conn[curr_thread] = conn
return self.conn[curr_thread]
Expand Down
2 changes: 1 addition & 1 deletion mephisto/abstractions/providers/mturk/mturk_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _get_connection(self) -> sqlite3.Connection:
"""
curr_thread = threading.get_ident()
if curr_thread not in self.conn or self.conn[curr_thread] is None:
conn = sqlite3.connect(self.db_path)
conn = sqlite3.connect(self.db_path, check_same_thread=False)
conn.row_factory = sqlite3.Row
self.conn[curr_thread] = conn
return self.conn[curr_thread]
Expand Down
46 changes: 32 additions & 14 deletions mephisto/abstractions/providers/mturk/utils/script_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@
from mephisto.data_model.requester import Requester
from mephisto.data_model.unit import Unit
from tqdm import tqdm # type: ignore
from mephisto.utils.logger_core import get_logger

logging = get_logger(name=__name__)

if TYPE_CHECKING:
from mephisto.abstractions.database import MephistoDB


def direct_soft_block_mturk_workers(
def direct_assign_qual_mturk_workers(
db: "MephistoDB",
worker_list: List[str],
soft_block_qual_name: str,
qual_name: str,
requester_name: Optional[str] = None,
):
"""
Directly assign the soft blocking MTurk qualification that Mephisto
associates with soft_block_qual_name to all of the MTurk worker ids
in worker_list. If requester_name is not provided, it will use the
most recently registered mturk requester in the database.
Directly assign MTurk qualification that Mephisto associates with qual_name
to all of the MTurk worker ids in worker_list. If requester_name is not provided,
it will use the most recently registered mturk requester in the database.
"""
reqs = db.find_requesters(requester_name=requester_name, provider_type="mturk")
requester = reqs[-1]
Expand All @@ -35,33 +37,49 @@ def direct_soft_block_mturk_workers(
requester, MTurkRequester
), "Can only direct soft block mturk workers from mturk requester"

mturk_qual_details = requester.datastore.get_qualification_mapping(
soft_block_qual_name
)
mturk_qual_details = requester.datastore.get_qualification_mapping(qual_name)
if mturk_qual_details is not None:
# Overrule the requester, as this qualification already exists
requester = Requester.get(db, mturk_qual_details["requester_id"])
qualification_id = mturk_qual_details["mturk_qualification_id"]
else:
qualification_id = requester._create_new_mturk_qualification(
soft_block_qual_name
)
qualification_id = requester._create_new_mturk_qualification(qual_name)

assert isinstance(
requester, MTurkRequester
), "Can only direct soft block mturk workers from mturk requester"
), "Can only direct assign qualification (soft block) mturk workers from mturk requester"
mturk_client = requester._get_client(requester._requester_name)
for worker_id in tqdm(worker_list):
try:
give_worker_qualification(
mturk_client, worker_id, qualification_id, value=1
)
except Exception as e:
print(
logging.exception(
f'Failed to give worker with ID: "{worker_id}" qualification with error: {e}. Skipping.'
)


def direct_soft_block_mturk_workers(
db: "MephistoDB",
worker_list: List[str],
soft_block_qual_name: str,
requester_name: Optional[str] = None,
):
"""
Directly assign the soft blocking MTurk qualification that Mephisto
associates with soft_block_qual_name to all of the MTurk worker ids
in worker_list. If requester_name is not provided, it will use the
most recently registered mturk requester in the database.
"""
direct_assign_qual_mturk_workers(
db=db,
worker_list=worker_list,
qual_name=soft_block_qual_name,
requester_name=requester_name,
)


def get_mturk_ids_from_unit_id(db, unit_id: str) -> Dict[str, Optional[str]]:
"""
Find the relevant mturk ids from the given mephisto unit id
Expand Down