from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import base64 class welcome(Page): def is_displayed(self): return self.player.round_number == 1 form_model = 'player' form_fields = ['consent'] def before_next_page(self): self.player.device_type = user_agent = self.request.META['HTTP_USER_AGENT'] self.player.is_mobile = False for substring in ['Mobi', 'Android', 'iPad']: if substring in user_agent: self.player.is_mobile = True class no_consent(Page): def is_displayed(self): return self.player.consent == False class RealTask(Page): def is_displayed(self): return self.player.round_number == 1 class quiz(Page): def is_displayed(self): return self.subsession.round_number == 1 form_model = 'player' form_fields = ['quiz_1', 'quiz_2', 'quiz_3', 'quiz_4', 'quiz_5'] def error_message(self, values): print('values is', values) if values["quiz_1"] != "10 rondes" or values["quiz_2"] != "5 eurocent" or values["quiz_3"] != \ "32 punten" or values["quiz_4"] != \ "6 punten" or values["quiz_5"] != \ "60 seconden": return 'U heeft minstens 1 fout antwoord gegeven. Lees de onderstaande instructies nog een keer goed door, en corrigeer de vragen die u fout heeft. Mocht u er niet uitkomen, lees dan de instructies hierboven nog een keer goed door.' class Treatment(Page): def is_displayed(self): return self.player.treatment > 1 #class Choice(Page): # form_model = 'player' # form_fields = ['choose_to_work'] class SliderTask(Page): pass timeout_seconds = 60 form_model = 'player' form_fields = ['task_stopped','s1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's10', 's11', 's12', 's13', 's14', 's15', 's16', 's17', 's18', 's19', 's20', 's21', 's22', 's23', 's24', 's25', 's26', 's27', 's28', 's29', 's30', 's31', 's32'] class RealTask2(Page): pass timeout_seconds = 60 def before_next_page(self): self.player.set_payoffs() self.player.saldo = self.participant.payoff class Slider_Result(Page): pass timeout_seconds = 60 def vars_for_template(self): absolute_payoff = abs(self.participant.payoff) absolute_payoff_round = abs(self.player.payoff) if self.participant.payoff < 0: verdiendofverloren = "verloren" if self.participant.payoff >= 0: verdiendofverloren = "verdiend" if self.player.payoff < 0: verdiendofverloren_round = "verloren" if self.player.payoff >= 0: verdiendofverloren_round = "verdiend" return {'absolute_payoff': absolute_payoff, 'verdiendofverloren': verdiendofverloren, 'absolute_payoff_round': absolute_payoff_round, 'verdiendofverloren_round': verdiendofverloren_round} class motives(Page): form_model = 'player' form_fields = ['motive_1', 'motive_2', 'motive_3', 'motive_4', 'motive_5', 'motive_6', 'motive_7', 'motive_8','motive_9','motive_10'] def is_displayed(self): return self.player.round_number == Constants.num_rounds class MTS7(Page): form_model = 'player' form_fields = ['MTS7_1', 'MTS7_2','MTS7_3', 'MTS7_4', 'MTS7_5', 'MTS7_6', 'MTS7_7'] def is_displayed(self): return self.player.round_number == Constants.num_rounds def before_next_page(self): if self.participant.payoff <= c(0): self.participant.payoff = c(0) if self.participant.payoff > c(0): self.participant.payoff = self.participant.payoff bonus = self.participant.payoff_plus_participation_fee() bonus = str(bonus) reversed_cipher = '' i = len(bonus) - 1 while i >= 0: reversed_cipher = reversed_cipher + bonus[i] i = i - 1 self.player.reversed_cipher = reversed_cipher print(reversed_cipher) def cipher_encrypt(reversed_cipher, key): encrypted = "" for c in reversed_cipher: if c.isupper(): #check if it's an uppercase character c_index = ord(c) - ord('A') # shift the current character by key positions c_shifted = (c_index + key) % 26 + ord('A') c_new = chr(c_shifted) encrypted += c_new elif c.islower(): #check if its a lowercase character # subtract the unicode of 'a' to get index in [0-25) range c_index = ord(c) - ord('a') c_shifted = (c_index + key) % 26 + ord('a') c_new = chr(c_shifted) encrypted += c_new elif c.isdigit(): # if it's a number,shift its actual value c_new = (int(c) + key) % 10 encrypted += str(c_new) else: # if its neither alphabetical nor a number, just leave it like that encrypted += c return encrypted ciphertext = cipher_encrypt(reversed_cipher, 4) print(ciphertext) encodedBytes = base64.b64encode(ciphertext.encode("utf-8")) p = str(encodedBytes) print(p) self.player.encrypted_payoff = p class WA(Page): form_model = 'player' form_fields = ['WA_1', 'WA_2', 'WA_3', 'WA_4', 'WA_5', 'WA_6', 'WA_7', 'WA_8', 'WA_9', 'WA_10', 'WA_11', 'WA_12'] def is_displayed(self): return self.player.round_number == Constants.num_rounds class DemographicsNL(Page): def is_displayed(self): return self.player.round_number == Constants.num_rounds form_model = 'player' form_fields = ['age', 'gender', 'education', 'worksituation', 'profession', 'income'] #class Siblings(Page): # def is_displayed(self): # return self.player.siblings == True # form_model = models.Player # form_fields = ['brothers', # 'sisters', # 'position'] class openvraag(Page): def is_displayed(self): return self.player.round_number == Constants.num_rounds form_model = 'player' form_fields = ['openvraag'] class lastpage(Page): def is_displayed(self): return self.player.round_number == Constants.num_rounds def vars_for_template(self): bonus = self.player.encrypted_payoff link = "https://leidenuniv.eu.qualtrics.com/jfe/form/SV_4ITPgQlTn342W8d?b=" + str(bonus) return{'link': link, 'payoff_player': self.participant.payoff_plus_participation_fee() } class redirect(Page): def is_displayed(self): return self.player.round_number == Constants.num_rounds def vars_for_template(self): bonus = self.player.encrypted_payoff participantcode = self.participant.code link = "https://leidenuniv.eu.qualtrics.com/jfe/form/SV_4ITPgQlTn342W8d?b=" + str(bonus[2:-1]) + "&pc=" + str(participantcode) return{'link': link} page_sequence = [welcome, no_consent, RealTask, quiz, Treatment, SliderTask, RealTask2, Slider_Result, motives, MTS7, WA, DemographicsNL, openvraag, lastpage, redirect]