Beispiel #1
0
    def __contains__(self, subject):
        """
        Tests if the subject is linked to the subject_set.

        - **subject** a single :py:class:`.Subject` instance, or a single
          subject ID.

        Returns a boolean indicating if the subject is linked to the
        subject_set.

        Examples::
            1234 in subject_set
            Subject(1234) in subject_set
        """
        if isinstance(subject, Subject):
            _subject_id = str(subject.id)
        else:
            _subject_id = str(subject)

        linked_subject_count = SetMemberSubject.where(
            subject_set_id=self.id,
            subject_id=_subject_id
        ).object_count

        return linked_subject_count == 1
    def __contains__(self, obj):
        if self._cls == Subject:
            if isinstance(obj, Subject):
                _subject_id = str(obj.id)
            else:
                _subject_id = str(obj)

            linked_subject_count = SetMemberSubject.where(
                subject_set_id=self._parent.id,
                subject_id=_subject_id).object_count

            return linked_subject_count == 1
        return super(SubjectSetLinkCollection, self).__contains__(obj)
    def subjects(self):
        """
        A generator which yields :py:class:`.Subject` objects which are in this
        subject set.

        Examples::

            for subject in subject_set.subjects:
                print(subject.id)

        """

        for sms in SetMemberSubject.where(subject_set_id=self.id):
            yield sms.links.subject
    def subjects(self):
        """
        A generator which yields :py:class:`.Subject` objects which are in this
        subject set.

        Examples::

            for subject in subject_set.subjects:
                print(subject.id)

        """

        for sms in SetMemberSubject.where(subject_set_id=self.id):
            yield sms.links.subject
    def __contains__(self, obj):
        if self._cls == Subject:
            if isinstance(obj, Subject):
                _subject_id = str(obj.id)
            else:
                _subject_id = str(obj)

            linked_subject_count = SetMemberSubject.where(
                subject_set_id=self._parent.id,
                subject_id=_subject_id
            ).object_count

            return linked_subject_count == 1
        return super(SubjectSetLinkCollection, self).__contains__(obj)
    def subject_workflow_statuses(self, subject_set_id):
        """
        A generator which yields :py:class:`.SubjectWorkflowStatus` objects for subjects in the
        subject set of the given workflow

        Examples::

            for status in workflow.subject_workflow_statuses(1234):
                print(status.retirement_reason)
        """
        subject_ids = []
        for sms in SetMemberSubject.where(subject_set_id=subject_set_id):
            subject_ids.append(sms.links.subject.id)

        subject_ids = ','.join(map(str, subject_ids))
        for status in SubjectWorkflowStatus.where(subject_ids=subject_ids,
                                                  workflow_id=self.id):
            yield status
 def subjects(self):
     for sms in SetMemberSubject.where(subject_set_id=self.id):
         yield sms.links.subject
 def subject_sets(self):
     return [
         sms.links.subject_set
         for sms in SetMemberSubject.where(subject_id=self.id)
     ]
        workflow=Workflow(assocAndIdWorkflow)
        ssets = workflow.links.subject_sets # not project!
        workflows = project.links.workflows

        workflowStatuses = SubjectWorkflowStatus.where(
            workflow_id=assocAndIdWorkflow, timeout=1000
        )
        subjectRetirementStats = {
            workflowStatus.raw["links"]["subject"]: workflowStatus.raw["retired_at"]
            for workflowStatus in workflowStatuses
        }

        idsForSSets = {
            sset: [
                subjectSetMember.raw["links"]["subject"]
                for subjectSetMember in SetMemberSubject.where(subject_set_id=sset.id)
            ]
            for sset in ssets
        }

        ssetRetirementStats = {
            sset.display_name: np.sum(
                [
                    subjectRetirementStats[subject] is not None
                    for subject in subjects
                    if subject in subjectRetirementStats
                ]
            )
            for sset, subjects in idsForSSets.items()
        }
    except panoptes_client.panoptes.PanoptesAPIException as e:
 def test_find_id(self):
     sms = SetMemberSubject.find(1000)
     self.assertEqual(sms.id, '1000')