I have the following question regarding participant variables. How would I have to change the below code in order to store the following variables (referenced in template) as participant variables so I can use them again at the very end of the experiment?
{{ chosen_probability }}
{{ chosen_return }}
{{ chosen_endowment }}
{{ chosen_investment }}
{{ payoff }}
In init.py:
class Constants(BaseConstants):
name_in_url = 'gneezy_potters'
# group size
players_per_group = None
# endowment amount for each different round
endowment = (20, 20, 20, 20)
# probability of success
probability = (1 / 2, 1 / 2, 1 / 2, 1 / 2)
# multiplier = return rate + 1
multiplier = (1.7, 1.35, 1.5, 1.35)
# multiplier2 = return rate2 + 1
multipliersecond = (0.7, 0.75, 0.75, 0.7)
# the number of total rounds
num_rounds = len(probability)
class Results(Page):
# skip results until last page
# ----------------------------------------------------------------------------------------------------------------
@staticmethod
def is_displayed(player: Player):
# if Constants.one_choice_per_page:
return player.subsession.round_number == Constants.num_rounds
# return True
@staticmethod
def vars_for_template(player: Player):
# round_num = self.subsession.round_number
rand_num = player.subsession.rand_round
# unzip <cem_choices> into list of lists
choices = player.participant.vars['environment'][rand_num - 1]
endowment = choices[1]
probability = round(choices[2], 2)
if player.winner == 1:
return_rate = round(choices[3], 2)
else:
return_rate = round(choices[4], 2)
return {
'round_to_pay': rand_num,
'chosen_endowment': endowment,
'chosen_investment': player.participant.vars['investment'][rand_num - 1],
'chosen_probability': probability,
'chosen_return': return_rate,
'payoff': player.participant.payoff,
}
In template:
{% extends "global/Page.html" %}
{% load staticfiles otree %}
{% block title %}
Resultat
{% endblock %}
{% block content %}
<p> Die Wahrscheinlichkeit einer positiven
Entwicklung der Anlage lag bei <b>{{ chosen_probability }}</b> und die Rendite war <b>{{ chosen_return }}</b>.
Ihr Ausstattung in der Runde war <b>{{ chosen_endowment }} und Sie investierten <b>{{ chosen_investment }}</b>
in die riskante Anlage. Somit liegt die Auszahlung dieser Runde bei <b>{{ payoff }}</b>.
</p>
{% next_button %}
{% endblock %}