Exemplo n.º 1
0
    def update(self, mturk_assignment=None, hit=None):
        """Update self with Mechanical Turk API data

        If mturk_assignment is given to this function, it should be
        a Boto assignment object that represents a Mechanical Turk
        Assignment instance.  Otherwise, Amazon Mechanical Turk is
        contacted.

        This instance's attributes are updated.
        """
        self.hit.generate_connection()
        assignment = None

        if mturk_assignment is None:
            hit = self.hit.connection.get_hit(self.hit.mturk_id)[0]
            for a in self.hit.connection.get_assignments(hit.HITId):
                # While we have the query, we may as well update
                if a.AssignmentId == self.mturk_id:
                    # That's this record. Hold onto so we can update below
                    assignment = a
                else:
                    other_assignment = Assignment.objects.get(
                            mturk_id=a.AssignmentId)
                    other_assignment.update(a)
        else:
            assert isinstance(mturk_assignment,
                              boto.mturk.connection.Assignment)
            assignment = mturk_assignment

        if assignment != None:
            self.status = self.reverse_status_lookup[assignment.AssignmentStatus]
            self.worker_id = get_worker(assignment.WorkerId)
            self.submit_time = amazon_string_to_datetime(assignment.SubmitTime)
            self.accept_time = amazon_string_to_datetime(assignment.AcceptTime)
            self.auto_approval_time = amazon_string_to_datetime(assignment.AutoApprovalTime)
            self.submit_time = amazon_string_to_datetime(assignment.SubmitTime)

            # Different response groups for query
            if hasattr(assignment, 'RejectionTime'):
                self.rejection_time = amazon_string_to_datetime(assignment.RejectionTime)
            if hasattr(assignment, 'ApprovalTime'):
                self.approval_time = amazon_string_to_datetime(assignment.ApprovalTime)

            # Update any Key-Value Pairs that were associated with this
            # assignment
            for result_set in assignment.answers:
                for question in result_set:
                    for key, value in question.fields:
                        kv = KeyValue.objects.get_or_create(key=key,assignment=self)[0]
                        if kv.value != value:
                            kv.value = value
                            kv.save()
        self.save()
Exemplo n.º 2
0
    def update(self, mturk_assignment=None, hit=None):
        """Update self with Mechanical Turk API data

        If mturk_assignment is given to this function, it should be
        a Boto assignment object that represents a Mechanical Turk
        Assignment instance.  Otherwise, Amazon Mechanical Turk is
        contacted.

        This instance's attributes are updated.
        """
        self.hit.generate_connection()
        assignment = None

        if mturk_assignment is None:
            hit = self.hit.connection.get_hit(self.hit.mturk_id)[0]
            for a in self.hit.connection.get_assignments(hit.HITId):
                # While we have the query, we may as well update
                if a.AssignmentId == self.mturk_id:
                    # That's this record. Hold onto so we can update below
                    assignment = a
                else:
                    other_assignments = Assignment.objects.filter(
                        mturk_id=a.AssignmentId)
                    # Amazon can reuse Assignment ids, so there is an
                    # occasional duplicate
                    for other_assignment in other_assignments:
                        if other_assignment.worker_id == a.WorkerId:
                            other_assignment.update(a)
        else:
            assert isinstance(mturk_assignment,
                              boto.mturk.connection.Assignment)
            assignment = mturk_assignment

        if assignment is not None:
            self.status = self.reverse_status_lookup[
                assignment.AssignmentStatus]
            self.worker_id = get_worker(assignment.WorkerId)
            self.submit_time = amazon_string_to_datetime(assignment.SubmitTime)
            self.accept_time = amazon_string_to_datetime(assignment.AcceptTime)
            self.auto_approval_time = amazon_string_to_datetime(
                assignment.AutoApprovalTime)
            self.submit_time = amazon_string_to_datetime(assignment.SubmitTime)

            # Different response groups for query
            if hasattr(assignment, 'RejectionTime'):
                self.rejection_time = amazon_string_to_datetime(
                    assignment.RejectionTime)
            if hasattr(assignment, 'ApprovalTime'):
                self.approval_time = amazon_string_to_datetime(
                    assignment.ApprovalTime)

        self.save()
Exemplo n.º 3
0
    def update(self, mturk_hit=None, do_update_assignments=False):
        """Update self with Mechanical Turk API data

        If mturk_hit is given to this function, it should be a Boto
        hit object that represents a Mechanical Turk HIT instance.
        Otherwise, Amazon Mechanical Turk is contacted to get additional
        information.

        This instance's attributes are updated.
        """
        self.generate_connection()
        if mturk_hit is None or not hasattr(mturk_hit, "HITStatus"):
            hit = self.connection.get_hit(self.mturk_id)[0]
        else:
            assert isinstance(mturk_hit, boto.mturk.connection.HIT)
            hit = mturk_hit

        self.status = HIT.reverse_status_lookup[hit.HITStatus]
        self.reward = hit.Amount
        self.assignment_duration_in_seconds = hit.AssignmentDurationInSeconds
        self.auto_approval_delay_in_seconds = hit.AutoApprovalDelayInSeconds
        self.max_assignments = hit.MaxAssignments
        self.creation_time = amazon_string_to_datetime(hit.CreationTime)
        self.description = hit.Description
        self.title = hit.Title
        self.hit_type_id = hit.HITTypeId
        self.keywords = hit.Keywords
        if hasattr(self, 'NumberOfAssignmentsCompleted'):
            self.number_of_assignments_completed = hit.NumberOfAssignmentsCompleted
        if hasattr(self, 'NumberOfAssignmentsAvailable'):
            self.number_of_assignments_available = hit.NumberOfAssignmentsAvailable
        if hasattr(self, 'NumberOfAssignmentsPending'):
            self.number_of_assignments_pending = hit.NumberOfAssignmentsPending
        #'CurrencyCode', 'Reward', 'Expiration', 'expired']

        self.save()

        if do_update_assignments:
            self.update_assignments()
Exemplo n.º 4
0
    def update(self, mturk_hit=None, do_update_assignments=False):
        """Update self with Mechanical Turk API data

        If mturk_hit is given to this function, it should be a Boto
        hit object that represents a Mechanical Turk HIT instance.
        Otherwise, Amazon Mechanical Turk is contacted to get additional
        information.

        This instance's attributes are updated.
        """
        self.generate_connection()
        if mturk_hit is None or not hasattr(mturk_hit, "HITStatus"):
            hit = self.connection.get_hit(self.mturk_id)[0]
        else:
            assert isinstance(mturk_hit, boto.mturk.connection.HIT)
            hit = mturk_hit

        self.status = HIT.reverse_status_lookup[hit.HITStatus]
        self.reward = hit.Amount
        self.assignment_duration_in_seconds = hit.AssignmentDurationInSeconds
        self.auto_approval_delay_in_seconds = hit.AutoApprovalDelayInSeconds
        self.max_assignments = hit.MaxAssignments
        self.creation_time = amazon_string_to_datetime(hit.CreationTime)
        self.description = hit.Description
        self.title = hit.Title
        self.hit_type_id = hit.HITTypeId
        self.keywords = hit.Keywords
        if hasattr(self, 'NumberOfAssignmentsCompleted'):
            self.number_of_assignments_completed = hit.NumberOfAssignmentsCompleted
        if hasattr(self, 'NumberOfAssignmentsAvailable'):
            self.number_of_assignments_available = hit.NumberOfAssignmentsAvailable
        if hasattr(self, 'NumberOfAssignmentsPending'):
            self.number_of_assignments_pending = hit.NumberOfAssignmentsPending
        # 'CurrencyCode', 'Reward', 'Expiration', 'expired']

        self.save()

        if do_update_assignments:
            self.update_assignments()
Exemplo n.º 5
0
    def update(self, mturk_assignment=None, hit=None):
        """Update self with Mechanical Turk API data

        If mturk_assignment is given to this function, it should be
        a Boto assignment object that represents a Mechanical Turk
        Assignment instance.  Otherwise, Amazon Mechanical Turk is
        contacted.

        This instance's attributes are updated.
        """
        self.hit.generate_connection()
        assignment = None

        if mturk_assignment is None:
            hit = self.hit.connection.get_hit(self.hit.mturk_id)[0]
            for a in self.hit.connection.get_assignments(hit.HITId):
                # While we have the query, we may as well update
                if a.AssignmentId == self.mturk_id:
                    # That's this record. Hold onto so we can update below
                    assignment = a
                else:
                    other_assignments = Assignment.objects.filter(mturk_id=a.AssignmentId)
                    # Amazon can reuse Assignment ids, so there is an occasional duplicate
                    for other_assignment in other_assignments:
                        if other_assignment.worker_id == a.WorkerId:
                            other_assignment.update(a)
        else:
            assert isinstance(mturk_assignment,boto.mturk.connection.Assignment)
            assignment = mturk_assignment

        if assignment != None:
            self.status = self.reverse_status_lookup[assignment.AssignmentStatus]
            self.worker_id = get_worker(assignment.WorkerId)
            self.submit_time = amazon_string_to_datetime(assignment.SubmitTime)
            self.accept_time = amazon_string_to_datetime(assignment.AcceptTime)
            self.auto_approval_time = amazon_string_to_datetime(assignment.AutoApprovalTime)
            self.submit_time = amazon_string_to_datetime(assignment.SubmitTime)

            # Different response groups for query
            if hasattr(assignment, 'RejectionTime'):
                self.rejection_time = amazon_string_to_datetime(assignment.RejectionTime)
            if hasattr(assignment, 'ApprovalTime'):
                self.approval_time = amazon_string_to_datetime(assignment.ApprovalTime)

        self.save()