Exemplo n.º 1
0
    def review_hits(self, print_assignment):
        """Interactively reject/approve all HITs associated with this task."""
        hits = list(self.get_reviewable_hits())
        worker_to_assignments = defaultdict(list)
        assignments_batch = parallel_call(self._mtc.get_assignments, [hit.HITId for hit in hits])
        for assignments in assignments_batch:
            for assignment in assignments:
                worker_to_assignments[assignment.WorkerId].append(assignment)

        def approve(assignment):
            self._mtc.approve_assignment(assignment.AssignmentId)
            try:
                self._mtc.dispose_hit(assignment.HITId)
            except MTurkRequestError:
                print('Failed to dispose HIT {}'.format(assignment.HITId))
                raise

        total_workers = len(worker_to_assignments)
        for i, (worker, assignments) in enumerate(worker_to_assignments.items()):
            print("Answers of worker {} ({} of {}, completed {} HITs):".format(worker, i+1, total_workers,
                                                                               len(assignments)))

            while True:
                assignment = random.choice(assignments)
                print_assignment(assignment)

                answer = self._prompt_yes_no_more()
                if answer == "y":
                    parallel_call(approve, assignments)
                    print("Approved all assignments for this worker")
                    break
                elif answer == "n":
                    print("Did not approve assignments for this worker")
                    break
            print("\n----- ----- ----- ----- ----- ----- ----- ----- ----- ----- \n")
Exemplo n.º 2
0
    def disable_hits(self):
        """Disable all HITs associated with this task.

        WARNING: approves all submitted assignments that have not already been approved or rejected.
        """
        hits = list(self.get_hits())
        hit_ids = [hit.HITId for hit in hits]
        parallel_call(self._mtc.disable_hit, hit_ids)
Exemplo n.º 3
0
    def expire_hits(self):
        """Expire all HITs associated with this task.

        The task will no longer appear in the marketplace.
        But the HITs and their assignments will still exist on MTurk, awaiting approval/rejection.
        """
        hits = list(self.get_hits())
        hit_ids = [hit.HITId for hit in hits]
        parallel_call(self._mtc.expire_hit, hit_ids)
Exemplo n.º 4
0
    def launch(self, example_uids):
        """Launch task.

        Args:
            example_uids (list[str]): list of example_uids to launch the task with

        """
        batches = list(chunks(example_uids, self._batch_size))

        total_hits = len(batches)
        assert isinstance(self._price_per_hit, float)
        total_cost = total_hits * self._price_per_hit

        print('Launching {} HITs (${}). Type Enter to continue.'.format(total_hits, total_cost))
        input()

        parallel_call(self.create_hit, batches)
Exemplo n.º 5
0
 def get_all_assignments(self, hits=[]):
     assignments = []
     assignments_batch = parallel_call(self._mtc.get_assignments,
                                       [hit.HITId for hit in hits])
     for assignments in assignments_batch:
         for assignment in assignments:
             assignments.append(assignments)
     return assignments