# -*- coding: utf-8 -*- from __future__ import division from . import models from ._builtin import Page, WaitPage from otree.common import 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), 'winners_cnt': winners_cnt, } class FinalResults(Page): def is_displayed(self): return self.subsession.round_number == Constants.num_rounds def vars_for_template(self): for player in self.player.in_all_rounds(): data = {'old_player': player} # # Filling the data for graph # # transaction price for each round (None if no transaction happened) two_thirds = [] data['series'] = list() #data['series2'] = list() for round in self.group.in_all_rounds(): two_thirds.append(round.two_third_guesses) data['series'].append({'name': 'Two thirds of the average', 'data': two_thirds}) data['series'] = safe_json(data['series']) #data['series2'] = safe_json(data['series2']) return data page_sequence = [Introduction, Guess, ResultsWaitPage, Results, FinalResults]