""" from otree.api import Currency as c from datetime import datetime, timedelta from ._builtin import Page from .models import Constants class Results_New(Page): form_model = 'player' form_fields = ['paypal'] def vars_for_template(self): pvars = self.participant.vars payoff_time_date = pvars.get('payoff_time_date', 0) payoff_risk = pvars.get('payoff_risk', 0) payoff_ambig = pvars.get('payoff_ambig', 0) payoff_time = pvars.get('payoff_time', 0) if payoff_time_date == 0: payment_today = c(payoff_risk + payoff_ambig) payment_tomorrow = c(payoff_time) payment_4w = c(0) else: payment_today = c(payoff_risk + payoff_ambig) payment_tomorrow = c(0) payment_4w = c(payoff_time) orig_payment = payment_today + payment_tomorrow + payment_4w if orig_payment < c(10): total_payment = c(10) payment_today = c(10 - payment_tomorrow - payment_4w) else: total_payment = orig_payment if payoff_time_date == 1: d = datetime.now() + timedelta(days=28) delayed_pay_date = d.strftime('%b-%d-%Y') else: delayed_pay_date = None compl_link = ( 'https://insead.sona-systems.com/webstudy_credit.aspx?experiment_id=630' '&credit_token=0197e24034a04164a3530be9a34dde1c&survey_code=' + str(self.participant.label) ) return { 'payment_risk': c(payoff_risk), 'payment_time': c(payoff_time), 'payment_ambig': c(payoff_ambig), 'orig_payment': orig_payment, 'total_payment': total_payment, 'payment_today': payment_today, 'payment_tomorrow': payment_tomorrow, 'payment_4w': payment_4w, 'delayed_date': delayed_pay_date, 'compl_link': compl_link, 'id': self.participant.label, } def before_next_page(self): self.player.set_payment_vars() class Debrief(Page): def vars_for_template(self): compl_link = ( 'https://insead.sona-systems.com/webstudy_credit.aspx?experiment_id=630' '&credit_token=0197e24034a04164a3530be9a34dde1c&survey_code=' + str(self.participant.label) ) return { 'compl_link': compl_link, 'id': self.participant.label, } page_sequence = [Results_New, Debrief] """ from otree.api import Currency as c from datetime import datetime, timedelta from ._builtin import Page from .models import Constants class Results_New(Page): form_model = 'player' form_fields = ['paypal'] def vars_for_template(self): pv = self.participant.vars participation_fee = c(pv.get('participation_fee', 5)) bonus_eligible = pv.get('bonus_eligible', False) bonus_part = pv.get('bonus_part', None) payoff_risk = c(pv.get('payoff_risk', 0)) payoff_time = c(pv.get('payoff_time', 0)) payoff_ambig = c(pv.get('payoff_ambig', 0)) time_selected_task = pv.get('time_selected_task', None) time_selected_choice = pv.get('time_selected_choice', None) # bonus allocation bonus_today = c(0) bonus_tomorrow = c(0) bonus_4w = c(0) bonus_8w = c(0) selected_bonus_amount = c(0) selected_bonus_part_label = None if bonus_eligible: if bonus_part == 1: selected_bonus_amount = payoff_risk selected_bonus_part_label = 'Part 1 (Risk)' bonus_today = payoff_risk elif bonus_part == 2: selected_bonus_amount = payoff_time selected_bonus_part_label = 'Part 2 (Time)' if time_selected_choice == 'early': bonus_tomorrow = payoff_time elif time_selected_task in ('lot_4w', 'ce_4w'): bonus_4w = payoff_time elif time_selected_task in ('lot_8w', 'ce_8w'): bonus_8w = payoff_time elif bonus_part == 3: selected_bonus_amount = payoff_ambig selected_bonus_part_label = 'Part 3 (Ambiguity)' bonus_today = payoff_ambig payment_today = participation_fee + bonus_today payment_tomorrow = bonus_tomorrow payment_4w = bonus_4w payment_8w = bonus_8w total_payment = payment_today + payment_tomorrow + payment_4w + payment_8w d4 = datetime.now() + timedelta(days=28) d8 = datetime.now() + timedelta(days=56) delayed_date_4w = d4.strftime('%b-%d-%Y') delayed_date_8w = d8.strftime('%b-%d-%Y') compl_link = ( 'https://insead.sona-systems.com/webstudy_credit.aspx?experiment_id=630' '&credit_token=0197e24034a04164a3530be9a34dde1c&survey_code=' + str(self.participant.label) ) # ---- extra display logic for bonus section ---- bonus_payment_timing = None bonus_amount_known = False bonus_amount_display = c(0) if bonus_eligible: if bonus_part == 1: bonus_payment_timing = 'today' bonus_amount_known = True bonus_amount_display = payoff_risk elif bonus_part == 3: bonus_payment_timing = 'today' bonus_amount_known = True bonus_amount_display = payoff_ambig elif bonus_part == 2: if time_selected_choice == 'early': bonus_payment_timing = 'tomorrow' elif time_selected_task in ('lot_4w', 'ce_4w'): bonus_payment_timing = '4 weeks' elif time_selected_task in ('lot_8w', 'ce_8w'): bonus_payment_timing = '8 weeks' if time_selected_task in ('ce_4w', 'ce_8w'): bonus_amount_known = True bonus_amount_display = payoff_time elif time_selected_task in ('lot_4w', 'lot_8w'): bonus_amount_known = False return { 'id': self.participant.label, 'compl_link': compl_link, 'participation_fee': participation_fee, 'bonus_eligible': bonus_eligible, 'bonus_part': bonus_part, 'selected_bonus_part_label': selected_bonus_part_label, 'selected_bonus_amount': selected_bonus_amount, 'payment_risk': payoff_risk, 'payment_time': payoff_time, 'payment_ambig': payoff_ambig, 'time_selected_task': time_selected_task, 'time_selected_choice': time_selected_choice, 'payment_today': payment_today, 'payment_tomorrow': payment_tomorrow, 'payment_4w': payment_4w, 'payment_8w': payment_8w, 'total_payment': total_payment, 'delayed_date_4w': delayed_date_4w, 'delayed_date_8w': delayed_date_8w, 'bonus_payment_timing': bonus_payment_timing, 'bonus_amount_known': bonus_amount_known, 'bonus_amount_display': bonus_amount_display, } def before_next_page(self): self.player.set_payment_vars() class Debrief(Page): def vars_for_template(self): compl_link = ( 'https://insead.sona-systems.com/webstudy_credit.aspx?experiment_id=630' '&credit_token=0197e24034a04164a3530be9a34dde1c&survey_code=' + str(self.participant.label) ) return { 'compl_link': compl_link, 'id': self.participant.label, } page_sequence = [Results_New, Debrief]