示例#1
0
    def get_context_data(self, **kwargs):

        session = self.session
        if session.mturk_HITId:
            with MTurkConnection(
                self.request, session.mturk_sandbox
            ) as mturk_connection:
                workers_with_submit = [
                    completed_assignment.WorkerId
                    for completed_assignment in
                    mturk_connection.get_assignments(session.mturk_HITId)
                ]
                participants = session.participant_set.filter(
                    mturk_worker_id__in=workers_with_submit
                )
        else:
            participants = session.get_participants()
        total_payments = 0.0
        mean_payment = 0.0
        if participants:
            total_payments = sum(
                part.money_to_pay() or c(0) for part in participants
            )
            mean_payment = total_payments / len(participants)

        context = super(SessionPayments, self).get_context_data(**kwargs)
        context.update({
            'participants': participants,
            'total_payments': total_payments,
            'mean_payment': mean_payment,
            'participation_fee': session.config['participation_fee'],
        })

        return context
示例#2
0
    def get_context_data(self, **kwargs):

        session = self.session
        if session.mturk_HITId:
            with MTurkConnection(self.request,
                                 session.mturk_sandbox) as mturk_connection:
                workers_with_submit = [
                    completed_assignment.WorkerId for completed_assignment in
                    mturk_connection.get_assignments(session.mturk_HITId)
                ]
                participants = session.participant_set.filter(
                    mturk_worker_id__in=workers_with_submit)
        else:
            participants = session.get_participants()
        total_payments = 0.0
        mean_payment = 0.0
        if participants:
            total_payments = sum(part.money_to_pay() or c(0)
                                 for part in participants)
            mean_payment = total_payments / len(participants)
        # dictionary for json response
        # will be used only if json request  is done
        self.context_json = {
            'participants':
            getSerializableObjectWithAttributes(
                participants,
                True,
                props=[
                    'payoff_in_real_world_currency', 'money_to_pay',
                    'money_to_pay_display', 'payoff_in_real_world_currency'
                ]),
            'total_payments':
            total_payments,
            'mean_payment':
            mean_payment,
            'participation_fee':
            session.participation_fee,
        }

        context = super(SessionPayments, self).get_context_data(**kwargs)
        context.update({
            'participants':
            participants,
            'total_payments':
            total_payments,
            'mean_payment':
            mean_payment,
            'participation_fee':
            session.config['participation_fee'],
        })

        return context
示例#3
0
 def _response_when_ready(self):
     session = Session.objects.get(_pre_create_id=self._pre_create_id)
     if self.request.session.get('for_mturk', False):
         session.mturk_num_participants = (
             len(session.get_participants()) /
             settings.MTURK_NUM_PARTICIPANTS_MULT)
     session.save()
     if session.is_for_mturk():
         session_home_url = reverse('session_create_hit',
                                    args=(session.pk, ))
     else:
         session_home_url = reverse('session_start_links',
                                    args=(session.pk, ))
     return HttpResponseRedirect(session_home_url)
示例#4
0
 def _response_when_ready(self):
     session = Session.objects.get(_pre_create_id=self._pre_create_id)
     if self.request.session.get('for_mturk', False):
         session.mturk_num_participants = (
             len(session.get_participants()) /
             settings.MTURK_NUM_PARTICIPANTS_MULT
         )
     session.save()
     if session.is_for_mturk():
         session_home_url = reverse(
             'session_create_hit', args=(session.pk,)
         )
     else:
         session_home_url = reverse(
             'session_start_links', args=(session.pk,)
         )
     return HttpResponseRedirect(session_home_url)
示例#5
0
    def get_context_data(self, **kwargs):

        session = self.session
        if session.mturk_HITId:
            with MTurkConnection(
                self.request, session.mturk_sandbox
            ) as mturk_connection:
                workers_with_submit = [
                    completed_assignment.WorkerId
                    for completed_assignment in
                    mturk_connection.get_assignments(session.mturk_HITId)
                ]
                participants = session.participant_set.filter(
                    mturk_worker_id__in=workers_with_submit
                )
        else:
            participants = session.get_participants()
        total_payments = 0.0
        mean_payment = 0.0
        if participants:
            total_payments = sum(
                part.money_to_pay() or c(0) for part in participants
            )
            mean_payment = total_payments / len(participants)
        # dictionary for json response
        # will be used only if json request  is done
        self.context_json = {
            'participants': getSerializableObjectWithAttributes(participants, True, props=['payoff_in_real_world_currency','money_to_pay','money_to_pay_display','payoff_in_real_world_currency']),
            'total_payments': total_payments,
            'mean_payment': mean_payment,
            'participation_fee': session.participation_fee,
        }

        context = super(SessionPayments, self).get_context_data(**kwargs)
        context.update({
            'participants': participants,
            'total_payments': total_payments,
            'mean_payment': mean_payment,
            'participation_fee': session.config['participation_fee'],
        })

        return context
示例#6
0
    def get_context_data(self, **kwargs):
        session = self.session
        participants = session.get_participants()
        total_payments = 0.0
        mean_payment = 0.0
        if participants:
            total_payments = sum(
                part.money_to_pay() or c(0) for part in participants
            )
            mean_payment = total_payments / len(participants)

        context = super(SessionPayments, self).get_context_data(**kwargs)
        context.update({
            'participants': participants,
            'total_payments': total_payments,
            'mean_payment': mean_payment,
            'participation_fee': session.config['participation_fee'],
        })

        return context
示例#7
0
    def get_context_data(self, **kwargs):
        session = self.session

        participant_urls = [
            self.request.build_absolute_uri(participant._start_url())
            for participant in session.get_participants()
        ]

        anonymous_url = self.request.build_absolute_uri(
            reverse('join_session_anonymously',
                    args=(session._anonymous_code, )))

        context = super(SessionStartLinks, self).get_context_data(**kwargs)

        context.update({
            'participant_urls': participant_urls,
            'anonymous_url': anonymous_url,
            'num_participants': len(participant_urls),
            'fullscreen_mode_on': len(participant_urls) <= 3
        })
        return context
示例#8
0
    def get_context_data(self, **kwargs):
        session = self.session
        participants = session.get_participants()
        total_payments = 0.0
        mean_payment = 0.0
        if participants:
            total_payments = sum(part.money_to_pay() or c(0)
                                 for part in participants)
            mean_payment = total_payments / len(participants)

        context = super(SessionPayments, self).get_context_data(**kwargs)
        context.update({
            'participants':
            participants,
            'total_payments':
            total_payments,
            'mean_payment':
            mean_payment,
            'participation_fee':
            session.config['participation_fee'],
        })

        return context
示例#9
0
    def get_context_data(self, **kwargs):
        session = self.session

        participant_urls = [
            self.request.build_absolute_uri(participant._start_url())
            for participant in session.get_participants()
        ]

        anonymous_url = self.request.build_absolute_uri(
            reverse(
                'join_session_anonymously',
                args=(session._anonymous_code,)
            )
        )

        context = super(SessionStartLinks, self).get_context_data(**kwargs)

        context.update({
            'participant_urls': participant_urls,
            'anonymous_url': anonymous_url,
            'num_participants': len(participant_urls),
            'fullscreen_mode_on': len(participant_urls) <= 3
        })
        return context
示例#10
0
    def get_context_data(self, **kwargs):

        session = self.session
        if session.mturk_HITId:
            with MTurkConnection(self.request,
                                 session.mturk_sandbox) as mturk_connection:
                workers_with_submit = [
                    completed_assignment.WorkerId
                    for completed_assignment in mturk_connection.
                    get_assignments(session.mturk_HITId,
                                    page_size=session.mturk_num_participants)
                ]
                participants = session.participant_set.filter(
                    mturk_worker_id__in=workers_with_submit)
        else:
            participants = session.get_participants()
        total_payments = 0.0
        mean_payment = 0.0
        if participants:
            total_payments = sum(part.money_to_pay() or c(0)
                                 for part in participants)
            mean_payment = total_payments / len(participants)

        context = super(SessionPayments, self).get_context_data(**kwargs)
        context.update({
            'participants':
            participants,
            'total_payments':
            total_payments,
            'mean_payment':
            mean_payment,
            'participation_fee':
            session.config['participation_fee'],
        })

        return context
示例#11
0
    def get_context_data(self, **kwargs):
        session = self.session

        participants = session.get_participants()
        participant_labels = [p._id_in_session_display() for p in participants]
        column_name_tuples = []
        rows = []

        for subsession in session.get_subsessions():
            app_label = subsession._meta.app_config.name

            column_names, subsession_rows = get_display_table_rows(
                subsession._meta.app_config.name,
                for_export=False,
                subsession_pk=subsession.pk
            )

            if not rows:
                rows = subsession_rows
            else:
                for i in range(len(rows)):
                    rows[i].extend(subsession_rows[i])

            round_number = subsession.round_number
            if round_number > 1:
                subsession_column_name = '{} [Round {}]'.format(
                    app_label, round_number
                )
            else:
                subsession_column_name = app_label

            for model_column_name, field_column_name in column_names:
                column_name_tuples.append(
                    (subsession_column_name,
                     model_column_name,
                     field_column_name)
                )

        subsession_headers = [
            (pretty_name(key), len(list(group)))
            for key, group in
            itertools.groupby(column_name_tuples, key=lambda x: x[0])
        ]

        model_headers = [
            (pretty_name(key[1]), len(list(group)))
            for key, group in
            itertools.groupby(column_name_tuples, key=lambda x: (x[0], x[1]))
        ]

        field_headers = [
            pretty_name(key[2]) for key, group in
            itertools.groupby(column_name_tuples, key=lambda x: x)
        ]

        # dictionary for json response
        # will be used only if json request  is done
        self.context_json = []
        for i, row in enumerate(rows):
            d_row = OrderedDict()
            d_row['participant_label'] = participant_labels[i]
            for t, v in zip(column_name_tuples, row):
                d_row['.'.join(t)] = v
            self.context_json.append(d_row)

        context = super(SessionResults, self).get_context_data(**kwargs)
        context.update({
            'subsession_headers': subsession_headers,
            'model_headers': model_headers,
            'field_headers': field_headers,
            'rows': rows})
        return context
示例#12
0
    def get_context_data(self, **kwargs):
        session = self.session

        participants = session.get_participants()
        participant_labels = [p._id_in_session_display() for p in participants]
        column_name_tuples = []
        rows = []

        for subsession in session.get_subsessions():
            app_label = subsession._meta.app_config.name

            column_names, subsession_rows = get_display_table_rows(
                subsession._meta.app_config.name,
                for_export=False,
                subsession_pk=subsession.pk)

            if not rows:
                rows = subsession_rows
            else:
                for i in range(len(rows)):
                    rows[i].extend(subsession_rows[i])

            round_number = subsession.round_number
            if round_number > 1:
                subsession_column_name = '{} [Round {}]'.format(
                    app_label, round_number)
            else:
                subsession_column_name = app_label

            for model_column_name, field_column_name in column_names:
                column_name_tuples.append(
                    (subsession_column_name, model_column_name,
                     field_column_name))

        subsession_headers = [(pretty_name(key), len(list(group)))
                              for key, group in itertools.groupby(
                                  column_name_tuples, key=lambda x: x[0])]

        model_headers = [(pretty_name(key[1]), len(list(group)))
                         for key, group in itertools.groupby(
                             column_name_tuples, key=lambda x: (x[0], x[1]))]

        field_headers = [
            pretty_name(key[2])
            for key, group in itertools.groupby(column_name_tuples,
                                                key=lambda x: x)
        ]

        # dictionary for json response
        # will be used only if json request  is done
        self.context_json = []
        for i, row in enumerate(rows):
            d_row = OrderedDict()
            d_row['participant_label'] = participant_labels[i]
            for t, v in zip(column_name_tuples, row):
                d_row['.'.join(t)] = v
            self.context_json.append(d_row)

        context = super(SessionResults, self).get_context_data(**kwargs)
        context.update({
            'subsession_headers': subsession_headers,
            'model_headers': model_headers,
            'field_headers': field_headers,
            'rows': rows
        })
        return context