[AMT] Creating white list of workers on Mechanical Turk

0

Hello, I am trying to create qualification to allow only users from specific white list to access the HIT. However, it works only for 1 user ID but does not work for array of users. I am using Python and boto3 API to deploy HITs. Also I am providing my tests in sandbox. My code:

TaskAttributes = {
        'MaxAssignments': 1,
        'LifetimeInSeconds': 7 * 24 * 60 * 60,
        'AssignmentDurationInSeconds': 60 * 15,
        'Reward': '0.75',
        'Title': 'my title',
        'Keywords': 'some keywords',
        'Description': 'some description.',
        'QualificationRequirements': [{
            'QualificationTypeId': whitelist_qualification_id,
            'Comparator': 'EqualTo',
            'IntegerValues': [1],
            'RequiredToPreview': True,
        }, {
            'QualificationTypeId': blacklist_qualification_id,
            'Comparator': 'DoesNotExist',
            'RequiredToPreview': True,
        }],
    }
...

def manage_qualification_lists(client, whitelist_file, blacklist_file):
   # Read workers from the whitelist
    with open(whitelist_file, 'r') as f:
        reader = csv.reader(f)
        whitelist = [worker_id.strip() for sublist in reader for worker_id in sublist]
    # Read workers from the blacklist
    with open(blacklist_file, 'r') as f:
        reader = csv.reader(f)
        blacklist = [worker_id.strip() for sublist in reader for worker_id in sublist]

    # Create a unique name for the whitelist qualification
    whitelist_qualification_name = 'WhitelistQualification_{}'.format(int(time.time()))
    # Create the whitelist qualification
    response = client.create_qualification_type(Name=whitelist_qualification_name,
                                                Description='This is a qualification for whitelisted workers',
                                                QualificationTypeStatus='Active',
                                                AutoGranted=False)
    whitelist_qualification_id = response['QualificationType']['QualificationTypeId']

    # Assign the whitelist qualification to each worker in the whitelist
    for worker_id in whitelist:
        print("White list: ", whitelist)
        print(f"Worker ID type: {type(worker_id)}, Value: {worker_id}")
        client.associate_qualification_with_worker(QualificationTypeId=whitelist_qualification_id,
                                                   WorkerId=worker_id,
                                                   IntegerValue=1,
                                                   SendNotification=False)

    # Create a unique name for the blacklist qualification
    blacklist_qualification_name = 'BlacklistQualification_{}'.format(int(time.time()))
    # Create the blacklist qualification
    response = client.create_qualification_type(Name=blacklist_qualification_name,
                                                Description='This is a qualification for blacklisted workers',
                                                QualificationTypeStatus='Active',
                                                AutoGranted=False)
    blacklist_qualification_id = response['QualificationType']['QualificationTypeId']

    # Assign the blacklist qualification to each worker in the blacklist
    for worker_id in blacklist:
        client.associate_qualification_with_worker(QualificationTypeId=blacklist_qualification_id,
                                                   WorkerId=worker_id,
                                                   IntegerValue=1,
                                                   SendNotification=False)

    return whitelist_qualification_id, blacklist_qualification_id

whitelist_file is a csv containing list of worker IDs

This code returns following traceback: Launching HITs, existing logfile will be overwritten White list: ['A21GE3SZCDZ8ZE', 'A1B8BFBK7T6YWJ', 'AFRKVRPZ2RHY8', 'A9MGD6PRW1N7K', 'AZU9D7YLCTAYV', 'A1Y35C8EJW168W', 'ARZ49D9ZQE6NM', 'A1PVUDM918PGMT', 'A2DLLQ60Y35X2U', 'A28PKKMBXHJCN3', 'AKQAI78JTXXC9', 'A3NFGEUZAH9V5G', 'A1OYUKUH3SWNOG', 'A1B5DQL8UVSLBW', 'A3NFGEUZAH9V5G', 'A329OLXWLB6WT9', 'A1N8TKTLXV92QR', 'A28PKKMBXHJCN3'] Worker ID type: <class 'str'>, Value: A21GE3SZCDZ8ZE White list: ['A21GE3SZCDZ8ZE', 'A1B8BFBK7T6YWJ', 'AFRKVRPZ2RHY8', 'A9MGD6PRW1N7K', 'AZU9D7YLCTAYV', 'A1Y35C8EJW168W', 'ARZ49D9ZQE6NM', 'A1PVUDM918PGMT', 'A2DLLQ60Y35X2U', 'A28PKKMBXHJCN3', 'AKQAI78JTXXC9', 'A3NFGEUZAH9V5G', 'A1OYUKUH3SWNOG', 'A1B5DQL8UVSLBW', 'A3NFGEUZAH9V5G', 'A329OLXWLB6WT9', 'A1N8TKTLXV92QR', 'A28PKKMBXHJCN3'] Worker ID type: <class 'str'>, Value: A1B8BFBK7T6YWJ Traceback (most recent call last): File "/home/ubuntu/mturk/1c_deploy_hit_wb_lists_test.py", line 178, in <module> deployHITs(client, preview_url, args.start_index, args.end_index, args.logdir) File "/home/ubuntu/mturk/1c_deploy_hit_wb_lists_test.py", line 30, in deployHITs whitelist_qualification_id, blacklist_qualification_id = manage_qualification_lists( File "/home/ubuntu/mturk/1c_deploy_hit_wb_lists_test.py", line 138, in manage_qualification_lists client.associate_qualification_with_worker(QualificationTypeId=whitelist_qualification_id, File "/home/ubuntu/stool/lib/python3.10/site-packages/botocore/client.py", line 530, in _api_call return self._make_api_call(operation_name, kwargs) File "/home/ubuntu/stool/lib/python3.10/site-packages/botocore/client.py", line 960, in _make_api_call raise error_class(parsed_response, operation_name) botocore.exceptions.ClientError: An error occurred (ParameterValidationError) when calling the AssociateQualificationWithWorker operation: The value "A1B8BFBK7T6YWJ" is not valid for the parameter WorkerId. (1691603149014 s)

Is there a way to create qualification with list of worker IDs that are allowed or forbidden to work with HIT?

Sergii
gefragt vor 9 Monaten83 Aufrufe
Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen