Ejemplo n.º 1
0
    def init_aws(self, opt, task_directory_path=None):
        print(
            "\nYou are going to allow workers from Amazon Mechanical Turk to be an agent in ParlAI.\nDuring this process, Internet connection is required, and you should turn off your computer's auto-sleep feature.\n"
        )
        key_input = input("Please press Enter to continue... ")
        print("")

        setup_aws_credentials()

        payment_opt = {
            'type': 'reward',
            'num_hits': opt['num_hits'],
            'num_assignments': opt['num_assignments'],
            'reward': opt['reward']  # in dollars
        }
        total_cost = calculate_mturk_cost(payment_opt=payment_opt)
        if not check_mturk_balance(balance_needed=total_cost,
                                   is_sandbox=opt['is_sandbox']):
            return

        print('Setting up MTurk backend...')
        create_hit_config(task_description=opt['task_description'],
                          num_hits=opt['num_hits'],
                          num_assignments=opt['num_assignments'],
                          is_sandbox=opt['is_sandbox'])
        if not self.task_files_to_copy:
            self.task_files_to_copy = []
        if not task_directory_path:
            task_directory_path = os.path.join(opt['parlai_home'], 'parlai',
                                               'mturk', 'tasks', opt['task'])
        for mturk_agent_id in self.mturk_agent_ids:
            self.task_files_to_copy.append(
                os.path.join(task_directory_path, 'html',
                             mturk_agent_id + '_cover_page.html'))
            self.task_files_to_copy.append(
                os.path.join(task_directory_path, 'html',
                             mturk_agent_id + '_index.html'))
        html_api_endpoint_url, json_api_endpoint_url = setup_aws(
            task_files_to_copy=self.task_files_to_copy)
        self.html_api_endpoint_url = html_api_endpoint_url
        self.json_api_endpoint_url = json_api_endpoint_url
        if debug:
            print(self.json_api_endpoint_url)
        print("MTurk setup done.\n")

        # Create an engine connected to the in-memory database
        engine = create_engine('sqlite://',
                               connect_args={'check_same_thread': False},
                               poolclass=StaticPool)

        # Create all tables in the engine
        Base.metadata.create_all(engine)
        Base.metadata.bind = engine

        session_maker = sessionmaker(bind=engine)

        self.db_session = scoped_session(session_maker)
Ejemplo n.º 2
0
    def init_aws(self, opt, task_directory_path=None):
        self.run_id = str(int(time.time()))

        print("\nYou are going to allow workers from Amazon Mechanical Turk to be an agent in ParlAI.\nDuring this process, Internet connection is required, and you should turn off your computer's auto-sleep feature.\n")
        key_input = input("Please press Enter to continue... ")
        print("")

        setup_aws_credentials()

        payment_opt = {
            'type': 'reward',
            'num_hits': opt['num_hits'],
            'num_assignments': opt['num_assignments'],
            'reward': opt['reward']  # in dollars
        }
        total_cost = calculate_mturk_cost(payment_opt=payment_opt)
        if not check_mturk_balance(balance_needed=total_cost, is_sandbox=opt['is_sandbox']):
            return

        print('Setting up MTurk backend...')
        create_hit_config(task_description=opt['task_description'], num_hits=opt['num_hits'], num_assignments=opt['num_assignments'], is_sandbox=opt['is_sandbox'])
        if not self.task_files_to_copy:
            self.task_files_to_copy = []
        if not task_directory_path:
            task_directory_path = os.path.join(opt['parlai_home'], 'parlai', 'mturk', 'tasks', opt['task'])
        for mturk_agent_id in self.mturk_agent_ids:
            self.task_files_to_copy.append(os.path.join(task_directory_path, 'html', mturk_agent_id+'_cover_page.html'))
            self.task_files_to_copy.append(os.path.join(task_directory_path, 'html', mturk_agent_id+'_index.html'))
        html_api_endpoint_url, json_api_endpoint_url = setup_aws(task_files_to_copy = self.task_files_to_copy)
        self.html_api_endpoint_url = html_api_endpoint_url
        self.json_api_endpoint_url = json_api_endpoint_url
        if debug:
            print(self.json_api_endpoint_url)
        print("MTurk setup done.\n")

        self.task_group_id = str(opt['task']) + '_' + str(self.run_id)

        # Create an engine connected to the in-memory database
        engine = create_engine('sqlite://',
                                connect_args={'check_same_thread':False},
                                poolclass=StaticPool)
         
        # Create all tables in the engine
        Base.metadata.create_all(engine)
        Base.metadata.bind = engine

        session_maker = sessionmaker(bind=engine)

        self.db_session = scoped_session(session_maker)

        self.db_thread_stop_event = threading.Event()
        self.db_thread = threading.Thread(target=self._sync_with_remote_db, args=())
        self.db_thread.daemon = True
        self.db_thread.start()
Ejemplo n.º 3
0
    def pay_bonus(self, worker_id, bonus_amount, assignment_id, reason, unique_request_token):
        total_cost = calculate_mturk_cost(payment_opt={'type': 'bonus', 'amount': bonus_amount})
        if not check_mturk_balance(balance_needed=total_cost, is_sandbox=self.is_sandbox):
            print("Cannot pay bonus. Reason: Insufficient fund in your MTurk account.")
            return False

        client = get_mturk_client(self.is_sandbox)
        client.send_bonus(
            WorkerId=worker_id,
            BonusAmount=str(bonus_amount),
            AssignmentId=assignment_id,
            Reason=reason,
            UniqueRequestToken=unique_request_token # Could be useful in the future, for handling network errors
        )

        return True