Skip to content

Commit

Permalink
Debugged granting qualifications during unit launch
Browse files Browse the repository at this point in the history
  • Loading branch information
meta-paul committed Jul 12, 2023
1 parent 88ac0e9 commit 3d13138
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
20 changes: 10 additions & 10 deletions examples/simple_static_task/static_test_prolific_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ def main(operator, cfg: DictConfig) -> None:

# Mephisto qualifications
shared_state.qualifications = [
make_qualification_dict('Best workers', QUAL_GREATER_EQUAL, 1),
make_qualification_dict('ok', QUAL_GREATER_EQUAL, 1),
]

# Prolific qualifications
shared_state.prolific_specific_qualifications = [
{
# Without `web.eligibility.models.` as API requires. We will add it in the code
'name': 'AgeRangeEligibilityRequirement',
# Prolific Eligibility Requirement attributes and its values
'min_age': 18,
'max_age': 100,
},
]
# shared_state.prolific_specific_qualifications = [
# {
# # Without `web.eligibility.models.` as API requires. We will add it in the code
# 'name': 'AgeRangeEligibilityRequirement',
# # Prolific Eligibility Requirement attributes and its values
# 'min_age': 20,
# 'max_age': 100,
# },
# ]

operator.launch_task_run(cfg.mephisto, shared_state)
operator.wait_for_runs_then_shutdown(skip_input=True, log_rate=30)
Expand Down
4 changes: 2 additions & 2 deletions mephisto/abstractions/providers/prolific/prolific_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def reject_work(self, reason) -> None:
)
except ProlificException:
logger.info(
"NOTE: ignore the above error - "
"Prolific API always returns error here, even when it works"
"IGNORE ABOVE ERROR - it's a bug of Prolific API. "
"It always returns error here, even when the request works."
)

logger.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def create_participant_proup_mapping(
else:
raise e

def create_quailfication_mapping(
def create_qualification_mapping(
self,
run_id: str,
prolific_participant_group_id: str,
Expand Down
16 changes: 7 additions & 9 deletions mephisto/abstractions/providers/prolific/prolific_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,16 @@ def _get_client(self, requester_name: str) -> ProlificClient:
"""Get a Prolific client"""
return self.datastore.get_client_for_requester(requester_name)

def _get_quailified_workers(self, qualifications: List[QualificationType]) -> List["Worker"]:
def _get_qualified_workers(self, qualifications: List[QualificationType]) -> List["Worker"]:
qualified_workers = []
prolific_workers: List[Worker] = self.db.find_workers(provider_type='prolific')
workers: List[Worker] = self.db.find_workers(provider_type='prolific')
blocked_workers = self.datastore.get_blocked_workers()
# `worker_name` is `worker_id` in provider-specific datastore
blocked_workers_names = [w['worker_id'] for w in blocked_workers]
available_workers = [w for w in workers if w.worker_name not in blocked_workers_names]

for worker in prolific_workers:
not_blocked = worker.worker_name not in blocked_workers_names
is_qualified = worker_is_qualified(worker, qualifications)

if not_blocked and is_qualified:
for worker in available_workers:
if worker_is_qualified(worker, qualifications):
qualified_workers.append(worker)

return qualified_workers
Expand Down Expand Up @@ -258,7 +256,7 @@ def setup_resources_for_task_run(
)

if qualifications:
qualified_workers = self._get_quailified_workers(qualifications)
qualified_workers = self._get_qualified_workers(qualifications)

if qualified_workers:
prolific_workers_ids = [w.worker_name for w in qualified_workers]
Expand All @@ -283,7 +281,7 @@ def setup_resources_for_task_run(
q.db_id for q in qualification_objs
if q.qualification_name in qualification_names
]
self.datastore.create_quailfication_mapping(
self.datastore.create_qualification_mapping(
run_id=task_run_id,
prolific_participant_group_id=prolific_participant_group.id,
qualifications=qualifications,
Expand Down
8 changes: 5 additions & 3 deletions mephisto/utils/qualifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def worker_is_qualified(worker: "Worker", qualifications: List[QualificationType
for qualification in qualifications:
qual_name = qualification["qualification_name"]
qual_objs = db.find_qualifications(qual_name)
if len(qual_objs) == 0:
if not qual_objs:
logger.warning(
f"Expected to create qualification for {qual_name}, but none found... skipping."
)
Expand All @@ -44,13 +44,15 @@ def worker_is_qualified(worker: "Worker", qualifications: List[QualificationType
)
comp = qualification["comparator"]
compare_value = qualification["value"]
if comp == QUAL_EXISTS and len(granted_quals) == 0:
if comp == QUAL_EXISTS and not granted_quals:
return False
elif comp == QUAL_NOT_EXIST and len(granted_quals) != 0:
elif comp == QUAL_NOT_EXIST and granted_quals:
return False
elif comp in [QUAL_EXISTS, QUAL_NOT_EXIST]:
continue
else:
if not granted_quals:
return False
granted_qual = granted_quals[0]
if not COMPARATOR_OPERATIONS[comp](granted_qual.value, compare_value):
return False
Expand Down

0 comments on commit 3d13138

Please sign in to comment.