def create_qualification_typeID_boto2(client):

    logfile = open(
        get_log_directory('Qualification_boto2') + get_timestamp() + '.txt',
        'w')
    response = client.create_qualification_type(
        name=get_timestamp(),
        description=
        "Only workers affected by our system could work on this task.",
        status="Active",
        auto_granted=True,
        auto_granted_value=1)

    logfile.write(
        "Your Qualification is created. Your Qualification Type ID is:\n")
    logfile.write(response[0].QualificationTypeId)

    # client.assign_qualification(response[0].QualificationTypeId, 'A2MGXHBK15GC8Y', value=1, send_notification=True)
    # client.assign_qualification(response[0].QualificationTypeId, 'A2BA16GUOB0DT5', value=1, send_notification=True)
    # client.assign_qualification(response[0].QualificationTypeId, 'A3D1A336ZEGP79', value=1, send_notification=True)

    return response[0].QualificationTypeId


# if __name__ == '__main__':
#     client = get_client('sandbox')
#     create_qualification_typeID(client)
def store_assignement_info_on_submission(client):

    mongo_client = MongoClient('localhost', 8081)
    db = mongo_client.meteor
    collection = db[FEEDBACK_COLLECTION]
    while (True):

        time.sleep(10)
        with open(
                get_log_directory('CompHIT_submission') + '/records.txt',
                'a') as logfile:

            assignment_info = get_workerid_assignmentid(client)

            for worker_id in assignment_info:
                result = is_worker_info_available(worker_id, collection)
                if not result:
                    assignment_id = assignment_info[worker_id]['assignmentID']
                    feedback = assignment_info[worker_id]['feedback']
                    document = {
                        'workerID': worker_id,
                        'assignment_id': assignment_id,
                        'feedback': feedback
                    }
                    collection.insert_one(document)
                    logfile.write("Worker %s has been checked at %s.\n" %
                                  (worker_id, get_timestamp()))
def main(environment):

    client = get_client(environment)

    qualification_type_id = create_qualification_typeID(client)

    # worker_id_list = get_worker_id()
    # worker_id_list = ['A2MGXHBK15GC8Y']
    # worker_id_list = ['A2MGXHBK15GC8Y', 'A3VOSKJ5LS9WB', 'A389861VXHBHWU']

    # create a HIT for A3O4TI9D8EPCL7, A1TGV7LT6LTIQU who made mistakes in compensation HIT
    worker_id_list = ['A3O4TI9D8EPCL7', 'A1TGV7LT6LTIQU']
    print(len(worker_id_list))

    logfile = open(
        get_log_directory('CompensationHIT') + get_timestamp() + '.txt', 'w')
    CompHITlog = open(
        get_log_directory('CompensationHIT') + '/records2.txt', 'w')
    response = create_hit(qualification_type_id, environment,
                          len(worker_id_list))

    HIT_URL = get_URL_parameters(environment) + response['HIT']['HITGroupId']
    HIT_ID = response['HIT']['HITId']
    print(HIT_URL + "\n")
    print("HITID = " + HIT_ID)
    logfile.write(HIT_URL + "\n")
    logfile.write("HITID = " + HIT_ID)
    CompHITlog.write(HIT_ID)

    for worker_id in worker_id_list:
        assign(client, worker_id, qualification_type_id)
        send_worker_message(client, worker_id, HIT_URL)
예제 #4
0
def pay_worker_bonus(client, worker_id, total_money, logfile):

    workerid_assignmentid_dict = get_workerid_assignmentid(client)

    assignment_id = workerid_assignmentid_dict[worker_id]['assignmentID']
    feedback = workerid_assignmentid_dict[worker_id]['feedback']

    # https://boto3.readthedocs.io/en/latest/reference/services/mturk.html#MTurk.Client.send_bonus
    client.send_bonus(WorkerId=worker_id, AssignmentId=assignment_id, BonusAmount=total_money, Reason=MESSAGE)

    store_feedback_in_db(worker_id, assignment_id, feedback, total_money, get_timestamp())
    logfile.write('Paid worker %s for AssignmentId %s: $%s at %s\n' % (worker_id, assignment_id, total_money, get_timestamp()))
예제 #5
0
def delete_all_hits(client):
    logfile = open(
        get_log_directory('DeletionLog') + get_timestamp() + '.txt', 'w')
    logfile.write("HITs deleted in this batch:\n")
    response = client.get_all_hits()
    hit_id_list = list()
    for hit in response:
        hit_id_list.append(hit.HITId)

    for hit_id in tqdm(hit_id_list):
        delete_hit(client, hit_id)
        logfile.write(hit_id + "\n")
예제 #6
0
    def save_model(self, model):
        #Create directory to store results
        time = get_timestamp()
        self._result_dir = f"results/training_run_{time}"
        [os.mkdir(x) for x in [f"{self._result_dir}/{subdir}" for subdir in ["", "model", "plots"]]]

        #Save in TF savedModel format
        model.save(f'{self._result_dir}/model')

        #Freeze model as protobuf (.pb), launches another clean process to take care of it. See model_freeze.py for
        #more explanation. If sys.prefix points to wrong python executable, this will probably fail in an odd manner.
        python_exec = f'{sys.prefix}/bin/python'
        os.system(f'{python_exec} model_freeze.py {self._result_dir}')
def create_qualification_typeID(client):

    logfile = open(
        get_log_directory('Qualification') + get_timestamp() + '.txt', 'w')
    response = client.create_qualification_type(
        Name=get_timestamp(),
        Description=
        "Only workers affected by our system could work on this task.",
        QualificationTypeStatus="Active",
        AutoGranted=True,
        AutoGrantedValue=1)

    logfile.write(
        "Your Qualification is created. Your Qualification Type ID is:\n")
    logfile.write(response['QualificationType']['QualificationTypeId'])

    # assign(client, 'A2MGXHBK15GC8Y', response['QualificationType']['QualificationTypeId'])
    # assign(client, 'A3VOSKJ5LS9WB', response['QualificationType']['QualificationTypeId'])
    # assign(client, 'A2BA16GUOB0DT5', response['QualificationType']['QualificationTypeId'])
    # assign(client, 'A3D1A336ZEGP79', response['QualificationType']['QualificationTypeId'])

    return response['QualificationType']['QualificationTypeId']
예제 #8
0
def process_inspire():
    """Returns a quote of correct sentiment and store analyses info in db."""

    #getting twitter_handle & user_id from session
    twitter_handle = session["twitter_handle"]
    user_id = session["user_id"]

    # get timestamp for storing to db when user clicks button
    timestamp = get_timestamp()

    quote_to_send = {}
    # calling get_quote function from twitter_analysis, passing in the twitter_handle
    # saving it to the quote_to_send dictionary as a value with the key "quote"
    quote_info = get_quote(twitter_handle, user_id)

    if len(quote_info) > 1:
        #adding the actual quote itself to a dictionary to send via JSON
        quote_to_send["quote"] = quote_info[0]

        # getting quote_id, sentiment to add to db
        quote_id = quote_info[1]
        sentiment = quote_info[2]

        #Part 2: send data to store in analyses in db
        # Store: user_id(y), timestamp(y), tweet_sent_id(y), quote_id(y)

        # adding analysis instance to the database
        analysis = Analyses(user_id=user_id,
                            timestamp=timestamp,
                            tweet_sent_id=sentiment,
                            quote_id=quote_id)
        db.session.add(analysis)
        db.session.commit()

    else:
        quote_to_send["quote"] = quote_info[0]

    return jsonify(quote_to_send)
예제 #9
0
    number_of_tweets = 0
    if data_type is None:
        create_document(hit_id)
    if data_type == "crowdflower":
        number_of_tweets = create_crowdflower_document(hit_id, start_position,
                                                       tweet_count)

    logfile.write("Your HIT ID is: {}\n\n".format(hit_id))

    return hit_type_id, number_of_tweets


if __name__ == '__main__':
    argument_length = len(sys.argv)

    logfile = open(get_log_directory('HITs') + get_timestamp() + '.txt', 'w')

    hit_type_id = ""
    if argument_length < 4:
        print("4 arguments required ....\n"
              "example: python script.py sandbox crowdflower 5 10")
        sys.exit(0)

    environment = sys.argv[1]
    client = get_client(environment)
    if sys.argv[2] == 'unlabeled':
        hit_type_id = create_hit(client, logfile, sys.argv[2])

    if sys.argv[2] == 'crowdflower':

        # qualification_type_id = create_qualification_typeID_boto2(client)