How to use the dallinger.models.Participant function in dallinger

To help you get started, we’ve selected a few dallinger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_participant_json(self, db_session):
        participant = models.Participant(
            recruiter_id="hotair",
            worker_id=str(1),
            hit_id=str(1),
            assignment_id=str(1),
            mode="test",
        )
        participant.details = {"data": "something"}
        db_session.add(participant)
        db_session.commit()

        participant_json = participant.__json__()
        assert "details" in participant_json
        assert participant_json["details"].get("data") == "something"

        # make sure private data is not in there
        assert "unique_id" not in participant_json
github Dallinger / Dallinger / tests / test_recruiters.py View on Github external
def test_notify_recruited_when_group_name_specified(self):
        participant = mock.Mock(spec=Participant, worker_id='some worker id')
        recruiter = self.make_one(
            id="some experiment uid",
            group_name='some existing group_name'
        )
        recruiter.notify_recruited(participant)

        recruiter.mturkservice.increment_qualification_score.assert_has_calls([
            mock.call('some experiment uid', 'some worker id'),
            mock.call('some existing group_name', 'some worker id')
        ], any_order=True)
github Dallinger / Dallinger / tests / test_data.py View on Github external
def test_ingest_zip_recreates_participants(self, db_session, zip_path):
        dallinger.data.ingest_zip(zip_path)

        participants = dallinger.models.Participant.query.all()
        assert len(participants) == 4
        for p in participants:
            assert p.status == "approved"
github Dallinger / Dallinger / tests / test_experiment_server.py View on Github external
def standard_args(experiment):
    from dallinger.models import Participant
    from sqlalchemy.orm.scoping import scoped_session

    return {
        "participant": mock.Mock(spec_set=Participant, status="working"),
        "assignment_id": "some assignment id",
        "experiment": experiment,
        "session": mock.Mock(spec_set=scoped_session),
        "config": {},
        "now": end_time,
    }.copy()
github Dallinger / Dallinger / dallinger / experiment.py View on Github external
def log_summary(self):
        """Log a summary of all the participants' status codes."""
        participants = Participant.query\
            .with_entities(Participant.status).all()
        counts = Counter([p.status for p in participants])
        sorted_counts = sorted(counts.items(), key=itemgetter(0))
        self.log("Status summary: {}".format(str(sorted_counts)))
        return sorted_counts
github Dallinger / Dallinger / dallinger / experiment_server / experiment_server.py View on Github external
.filter_by(assignment_id=assignment_id)\
            .all()

        # if there are one or more participants select the most recent
        if participants:
            participant = max(participants,
                              key=attrgetter('creation_time'))

        # if there are none print an error
        else:
            exp.log("Warning: No participants associated with this "
                    "assignment_id. Notification will not be processed.", key)
            return None

    elif participant_id is not None:
        participant = models.Participant.query\
            .filter_by(id=participant_id).all()[0]
    else:
        raise ValueError(
            "Error: worker_function needs either an assignment_id or a "
            "participant_id, they cannot both be None")

    participant_id = participant.id

    if event_type == 'AssignmentAccepted':
        pass

    elif event_type == 'AssignmentAbandoned':
        if participant.status == "working":
            participant.end_time = datetime.now()
            participant.status = "abandoned"
            exp.assignment_abandoned(participant=participant)
github Dallinger / Dallinger / dallinger / recruiters.py View on Github external
def current_hit_id(self):
        any_participant_record = Participant.query.with_entities(
            Participant.hit_id).filter_by(recruiter_id=self.nickname).first()

        if any_participant_record is not None:
            return str(any_participant_record.hit_id)
github Dallinger / Dallinger / demos / dlgr / demos / rogers / experiment.py View on Github external
def submission_successful(self, participant):
        """Run when a participant submits successfully."""
        num_approved = len(Participant.query.filter_by(status="approved").all())
        current_generation = participant.nodes()[0].generation
        if (
            num_approved % self.generation_size == 0
            and (current_generation % 10 + 1) == 0
        ):
            for e in self.models.RogersEnvironment.query.all():
                e.step()
github Dallinger / Dallinger / dallinger / experiment.py View on Github external
def log_summary(self):
        """Log a summary of all the participants' status codes."""
        participants = Participant.query\
            .with_entities(Participant.status).all()
        counts = Counter([p.status for p in participants])
        sorted_counts = sorted(counts.items(), key=itemgetter(0))
        self.log("Status summary: {}".format(str(sorted_counts)))
        return sorted_counts