from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'timepreferencesonline' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): qo1 = models.IntegerField() qo2 = models.IntegerField() qo3 = models.IntegerField() qo4 = models.IntegerField() qo5 = models.IntegerField() qo6 = models.IntegerField() qo7 = models.IntegerField() qo8 = models.IntegerField() qo9 = models.IntegerField() qo10 = models.IntegerField() qo11 = models.IntegerField() qo12 = models.IntegerField() qo13 = models.IntegerField() qo14 = models.IntegerField() qo15 = models.IntegerField() qo16 = models.IntegerField() qo17 = models.IntegerField() qo18 = models.IntegerField() qo19 = models.IntegerField() qo20 = models.IntegerField() qo21 = models.IntegerField() qo22 = models.IntegerField() qo23 = models.IntegerField() qo24 = models.IntegerField() def ShuffleQ(Player): from datetime import datetime, timedelta from random import shuffle now = datetime.now() week_later = now + timedelta(days=7) fourweekslater = now + timedelta(days=28) twoweeks = now + timedelta(days=14) fiveweeks = now + timedelta(days=35) threeweeks = now + timedelta(days=21) sixweeks = now + timedelta(days=42) this_week = now.strftime("%d. %m.") next_week = week_later.strftime("%d. %m.") four_weeks = fourweekslater.strftime("%d. %m.") two_weeks = twoweeks.strftime("%d. %m.") five_weeks = fiveweeks.strftime("%d. %m.") three_weeks = threeweeks.strftime("%d. %m.") six_weeks = sixweeks.strftime("%d. %m.") tabulka1o = [["qo1", "154", "138", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za týden " +next_week + " od 17 do 24 hod"], ["qo2", "154", "154", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za týden " + next_week + " od 17 do 24 hod"], ["qo3", "154", "157", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za týden " + next_week + " od 17 do 24 hod"], ["qo4", "154", "164", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za týden " + next_week + " od 17 do 24 hod"], ["qo5", "154", "169", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za týden " + next_week + " od 17 do 24 hod"], ["qo6", "154", "184", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za týden " + next_week + " od 17 do 24 hod"]] tabulka2o = [["qo7", "154", "101", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za čtyři týdny " + four_weeks + " od 17 do 24 hod"], ["qo8", "154", "154", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za čtyři týdny " + four_weeks + " od 17 do 24 hod"], ["qo9", "154", "167", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za čtyři týdny " + four_weeks + " od 17 do 24 hod"], ["qo10", "154", "202", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za čtyři týdny " + four_weeks + " od 17 do 24 hod"], ["qo11", "154", "225", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za čtyři týdny " + four_weeks + " od 17 do 24 hod"], ["qo12", "154", "319", "Možnost A: Dnes " + this_week + " večer od 17 do 24 hod", "Možnost B: Za čtyři týdny " + four_weeks + " od 17 do 24 hod"]] tabulka3o = [["qo13", "154", "138", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za dva týdny" + two_weeks + " večer od 17 do 24 hod"], ["qo14", "154", "154", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za dva týdny" + two_weeks + " večer od 17 do 24 hod"], ["qo15", "154", "157", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za dva týdny" + two_weeks + " večer od 17 do 24 hod"], ["qo16", "154", "164", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za dva týdny" + two_weeks + " večer od 17 do 24 hod"], ["qo17", "154", "169", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za dva týdny" + two_weeks + " večer od 17 do 24 hod"], ["qo18", "154", "184", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za dva týdny" + two_weeks + " večer od 17 do 24 hod"]] tabulka4o = [["qo19", "154", "101", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za pět týdnů" + five_weeks + " večer od 17 do 24 hod"], ["qo20", "154", "154", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za pět týdnů" + five_weeks + " večer od 17 do 24 hod"], ["qo21", "154", "167", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za pět týdnů" + five_weeks + " večer od 17 do 24 hod"], ["qo22", "154", "202", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za pět týdnů" + five_weeks + " večer od 17 do 24 hod"], ["qo23", "154", "225", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za pět týdnů" + five_weeks + " večer od 17 do 24 hod"], ["qo24", "154", "319", "Možnost A: Za týden " + next_week + "večer od 17 do 24 hod ", "Možnost B: Za pět týdnů" + five_weeks + " večer od 17 do 24 hod"]] shuffle(tabulka1o) shuffle(tabulka2o) shuffle(tabulka3o) shuffle(tabulka4o) FinalTabulka = [tabulka1o, tabulka2o, tabulka3o, tabulka4o] shuffle(FinalTabulka) Player.participant.vars["Final_tabulka"] = FinalTabulka def PayoffFunction(Player): if Player.participant.vars['typ_vyplaty'] == "online time preferences": k = Player.participant.vars.get("cislo_ukolu") q_name = "qo{}".format(k) print(q_name) Player.participant.vars["kolikukolu"] = getattr(Player, q_name) print(Player.participant.vars["kolikukolu"]) # PAGES class MyPage(Page): def vars_for_template(player: Player): return dict( tabulka1=player.participant.vars.get("Final_tabulka"), ) def live_method(player, data): if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo1": if data['t'] == 'choice1': player.qo1 = 154 if data['t'] == 'choice2': player.qo1 = 138 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo2": if data['t'] == 'choice1': player.qo2 = 154 if data['t'] == 'choice2': player.qo2 = 154 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo3": if data['t'] == 'choice1': player.qo3 = 154 if data['t'] == 'choice2': player.qo3 = 157 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo4": if data['t'] == 'choice1': player.qo4 = 154 if data['t'] == 'choice2': player.qo4 = 164 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo5": if data['t'] == 'choice1': player.qo5 = 154 if data['t'] == 'choice2': player.qo5 = 169 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo6": if data['t'] == 'choice1': player.qo6 = 154 if data['t'] == 'choice2': player.qo6 = 184 #Tabulka2 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo7": if data['t'] == 'choice1': player.qo7 = 154 if data['t'] == 'choice2': player.qo7 = 101 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo8": if data['t'] == 'choice1': player.qo8 = 154 if data['t'] == 'choice2': player.qo8 = 154 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo9": if data['t'] == 'choice1': player.qo9 = 154 if data['t'] == 'choice2': player.qo9 = 167 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo10": if data['t'] == 'choice1': player.qo10 = 154 if data['t'] == 'choice2': player.qo10 = 202 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo11": if data['t'] == 'choice1': player.qo11 = 154 if data['t'] == 'choice2': player.qo11 = 225 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo12": if data['t'] == 'choice1': player.qo12 = 154 if data['t'] == 'choice2': player.qo12 = 319 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo13": if data['t'] == 'choice1': player.qo13 = 154 if data['t'] == 'choice2': player.qo13 = 138 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo14": if data['t'] == 'choice1': player.qo14 = 154 if data['t'] == 'choice2': player.qo14 = 154 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo15": if data['t'] == 'choice1': player.qo15 = 154 if data['t'] == 'choice2': player.qo15 = 157 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo16": if data['t'] == 'choice1': player.qo16 = 154 if data['t'] == 'choice2': player.qo16 = 164 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo17": if data['t'] == 'choice1': player.qo17 = 154 if data['t'] == 'choice2': player.qo17 = 169 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo18": if data['t'] == 'choice1': player.qo18 = 154 if data['t'] == 'choice2': player.qo18 = 184 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo19": if data['t'] == 'choice1': player.qo19 = 154 if data['t'] == 'choice2': player.qo19 = 101 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo20": if data['t'] == 'choice1': player.qo20 = 154 if data['t'] == 'choice2': player.qo20 = 154 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo21": if data['t'] == 'choice1': player.qo21 = 154 if data['t'] == 'choice2': player.qo21 = 167 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo22": if data['t'] == 'choice1': player.qo22 = 154 if data['t'] == 'choice2': player.qo22 = 202 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo23": if data['t'] == 'choice1': player.qo23 = 154 if data['t'] == 'choice2': player.qo23 = 225 if player.participant.vars.get("Final_tabulka")[data['indexino2']][data['indexino']][0] == "qo24": if data['t'] == 'choice1': player.qo24 = 154 if data['t'] == 'choice2': player.qo24 = 319 def before_next_page(player: Player, timeout_happened): player.PayoffFunction() class ResultsWaitPage(WaitPage): pass class Results(Page): def before_next_page(player: Player, timeout_happened): player.ShuffleQ() class FP(Page): def is_displayed(player: Player): return player.participant.vars.get("tvuj_kod") != "UAJWNK70" class FP2(Page): pass page_sequence = [Results, MyPage, FP,FP2]