# -*- coding: utf-8 -*- from __future__ import division from . import models from ._builtin import Page, WaitPage from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from .models import Constants from otree.common import safe_json class Introduction(Page): def is_displayed(self): return self.subsession.round_number == 1 class Guess(Page): form_model = models.player form_fields = ['guess_value'] class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() body_text = "Waiting for the other participants." class Results(Page): def vars_for_template(self): other_guesses = [] winners_cnt = int(self.player.is_winner) for p in self.player.get_others_in_group(): other_guesses.append(p.guess_value) winners_cnt += int(p.is_winner) return { 'other_guesses': other_guesses, 'other_guesses_count': len(other_guesses), 'two_third_average': round(self.group.two_third_guesses, 4), 'average_guess': self.group.average_guess, 'winners_cnt': winners_cnt, } class FinalResults(Page): def is_displayed(self): return self.subsession.round_number == Constants.num_rounds def vars_for_template(self): two_thirds = [] to_return = {} categories = ['Round {}'.format(i) for i in range(1,11)] for round in self.group.in_all_rounds(): two_thirds.append(round.two_third_guesses) to_return['name'] = 'One half of the average plus 10' to_return['series'] = two_thirds to_return['categories'] = categories return to_return page_sequence = [Introduction, Guess, ResultsWaitPage, Results, FinalResults ]