from otree.api import * import csv import random as r doc = """ Résultats et gains """ class C(BaseConstants): NAME_IN_URL = 'triCV_resultats' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): gain_partie1 = models.CurrencyField() gain_partie2 = models.CurrencyField() class Transition(Page): timeout_seconds = 1 class Resultats(Page): @staticmethod def vars_for_template(player: Player): # payoff partie 1 payoff1 = player.participant.vars['gain_final1'] + cu(150) source_gain1 = player.participant.vars['essai_gagnant1'] source_choix_gain1 = player.participant.vars['choix_gagnant1'] nb_bonnes_estimations1 = player.participant.vars['nb_bonnes_estimations1'] nb_bons_choix1 = player.participant.vars['nb_bons_choix1'] nb_estimations1 = 4 * player.participant.vars['nb_rounds1'] nb_choix1 = player.participant.vars['nb_rounds1'] if player.participant.vars['estimation_gagnante1'] == 1: estimation_gagnante1 = 'première' elif player.participant.vars['estimation_gagnante1'] == 2: estimation_gagnante1 = 'deuxième' elif player.participant.vars['estimation_gagnante1'] == 3: estimation_gagnante1 = 'troisième' elif player.participant.vars['estimation_gagnante1'] == 4: estimation_gagnante1 = 'quatrième' # payoff partie2 payoff2 = player.participant.vars['gain_final2'] + cu(150) source_gain2 = player.participant.vars['essai_gagnant2'] source_choix_gain2 = player.participant.vars['choix_gagnant2'] nb_bonnes_estimations2 = player.participant.vars['nb_bonnes_estimations2'] nb_bons_choix2 = player.participant.vars['nb_bons_choix2'] nb_estimations2 = 4 * player.participant.vars['nb_rounds2'] nb_choix2 = player.participant.vars['nb_rounds2'] if player.participant.vars['estimation_gagnante2'] == 1: estimation_gagnante2 = 'première' elif player.participant.vars['estimation_gagnante2'] == 2: estimation_gagnante2 = 'deuxième' elif player.participant.vars['estimation_gagnante2'] == 3: estimation_gagnante2 = 'troisième' elif player.participant.vars['estimation_gagnante2'] == 4: estimation_gagnante2 = 'quatrième' # payoff total player.payoff = player.participant.vars['gain_final2'] + player.participant.vars['gain_final1'] score_final = payoff1 + payoff2 gain_final = player.participant.payoff_plus_participation_fee() nb_bonnes_estimations = nb_bonnes_estimations1 + nb_bonnes_estimations2 nb_bons_choix = nb_bons_choix1 + nb_bons_choix2 nb_estimations = nb_estimations1 + nb_estimations2 nb_choix = nb_choix1 + nb_choix2 # Enregistrement des résultats player.gain_partie1 = player.participant.vars['gain_final1'] player.gain_partie2 = player.participant.vars['gain_final2'] return dict( nb_bonnes_estimations=nb_bonnes_estimations, nb_bons_choix=nb_bons_choix, nb_estimations=nb_estimations, nb_choix=nb_choix, score_final=score_final, gain_final=gain_final, nb_bonnes_estimations1=nb_bonnes_estimations1, nb_bons_choix1=nb_bons_choix1, nb_estimations1=nb_estimations1, nb_choix1=nb_choix1, source_gain1=source_gain1, payoff1=payoff1, estimation_gagnante1=estimation_gagnante1, source_choix_gain1=source_choix_gain1, nb_bonnes_estimations2=nb_bonnes_estimations2, nb_bons_choix2=nb_bons_choix2, nb_estimations2=nb_estimations2, nb_choix2=nb_choix2, source_gain2=source_gain2, payoff2=payoff2, estimation_gagnante2=estimation_gagnante2, source_choix_gain2=source_choix_gain2 ) page_sequence = [ Transition, Resultats ]