#1 by js8773420
Hi everyone, I have inherited this code and am tring to use it for my own Honours experiment but I need to save the variables used in this End_Of_Game page at the participant level so that I can save them across apps because my experiment will be using multiple. I specificially just need to save "actual_payout" or "wealth", which are both only defined in the vars_for_template function for this page. Does anyone know how to do this? Alternatively if anyone also knows how I can transform the wealth variable into the payoff, that would work too. I am a bit desperate as I have tried quite a bit to solve this with no success so I would really appreciate any advice you guys can give me even if you don't know the full answer. The code used is below: class End_Of_Game(Page): def is_displayed(player): return player.round_number == C.NUM_ROUNDS def vars_for_template(player: Player): max_t = C.NUM_ROUNDS # get the affectation of the player: actifs = (player.actifs).split(",") idxs_prix = [] for i in range(1, (max_t + 1) + C.history): idxs_prix.append(i) prices_to_show = get_prices(player) # in order to compute the positions in the portfolio: qtes_pfeuille = [] cumulA = sum([p.quantityA * p.decisionA for p in player.in_all_rounds()]) cumulB = sum([p.quantityB * p.decisionB for p in player.in_all_rounds()]) cumulC = sum([p.quantityC * p.decisionC for p in player.in_all_rounds()]) cumulD = sum([p.quantityD * p.decisionD for p in player.in_all_rounds()]) cumulE = sum([p.quantityE * p.decisionE for p in player.in_all_rounds()]) cumulF = sum([p.quantityF * p.decisionF for p in player.in_all_rounds()]) qtes_pfeuille = [cumulA, cumulB, cumulC, cumulD, cumulE, cumulF] cours_actuels = [] valeurs = [] for (idx, a) in enumerate(actifs): cours_actuels.append(C.prices[int(a)][max_t + C.history]) valeurs.append(cours_actuels[idx] * qtes_pfeuille[idx]) sum_valeurs = sum([v for v in valeurs]) player.cash_money = available_cash(player, prices_to_show) cash = '%4d' % player.cash_money wealth = sum_valeurs + player.cash_money performance_payout = (sum_valeurs + player.cash_money)/2500 actual_payout = (sum_valeurs + player.cash_money)/2500 + 2 final_reward = C.rewarding_rate * wealth wealth = '%4d' % round(wealth, 0) player.reward = final_reward final_reward = round(final_reward + 0.499, 0) nu = time.localtime() chaine = player.actifs player.code_fin = ( chaine[0:1] + chaine[2:3] + '-' + str(nu.tm_min).zfill(2) + '-' + chaine[4:5] + chaine[6:7] ) player.code_fin += '-' + str(nu.tm_sec).zfill(2) + '-' + chaine[8:9] + chaine[10:11] return { 'actifs': actifs, 'prices_to_show': prices_to_show, 'qtes_pfeuille': qtes_pfeuille, 'cours_actuels': cours_actuels, 'valeurs': valeurs, 'sum_valeurs': sum_valeurs, 'idxs_prix': idxs_prix, 'val_ptf': sum_valeurs, 'cash': cash, 'wealth': wealth, 'final_reward': final_reward, 'performance_payout': performance_payout, 'actual_payout': actual_payout, }
#2 by PhilP
Just like player.reward is saved in the vars_for_template, you can also do the same for player.participant.reward, provided that you have set 'reward' in your participant fields. I.e. put player.participant.reward = player.reward in your vars_for_template just after you set player.reward = final_reward. If you want to specifically save the wealth variable you can just create a new variable in the player class, add it to participant fields and do the same thing, i.e. player.participant.X = wealth