from otree.api import * import time import random import json c = Currency doc = """ Your app description """ #global variable FIRST_ROUND_STAGE=5 answear_dict = {} history = {} guess_quality_dict = {} item_price_list = [700, 500, 500, 150, 150, 300, 200, 300, 400, 200, 300, 300, 250, 500, 125, 400, 100, 200 , 600, 300] item_condition = [0.8, 1, 1, 0.8, 0.9, 0.8, 0.80, 0.8, 0.8, 0.9, 0.8, 0.9, 0.9, 1 , 1, 0.9, 0.9, 0.9, 0.8, 0.9 ] item_description = ['GOOD COSMETIC CONDIis_acceptTION, SEE PICTURES FOR DETAILS', 'New: A brand-new, unused, unopened, undamaged item in its original packaging (where packaging is applicable)', 'BRAND NEW IN HAND FACTORY SEALED READY TO SHIP', 'Casio G-Shock GA-2100-1A GA2100-1A Brand New Unworn', 'They are refurbished, in excellent condition and will work as normal. new in dox and ship sealed with all proper packaging.', 'nintendo switch console Ring fit bundle new. Condition is "New". Dispatched with Royal Mail recorded delivery. Unwanted prize ', 'Used Nintendo Switch Lite - Blue Console + Box. Condition is "Used". Shipped with USPS Priority', 'Vendo AJ1 Retro High OG Court Purple', 'Fair : Used with ovious scratches stains and wrinkles. e00280', 'For Sale: Nike Air Jordan 1 Retro High OG Court Purple Size 10.5 W / 9 M W/Receipt. Condition is New with box Shipped with UPS! ', 'Condition like new, with box. They were rarely worn. Dry cleaning done. There are different sizes', 'Card is in fantastic shape,', 'Card is in fantastic shape, sharp corners and edges, nice auto, bought with the intention of grading but never got around to it', 'Charizard HOLO Rare Pokemon Card Game Base Set 4/102. Condition is good. Shipped with USPS First Class.', 'All have been played with but still in great condition (although not complete), lots of figurines', 'Willie Mays signed baseball PSA authenticated Since this is a Leonard Coleman Natl league president ball, it was signed between 1994 and 1999.', 'MEGA SET Radiotehnika S-90 Amplifier Pre-Amplifier Turntable Record Loudspeakers', 'Used in very good to Excellent Cosmetic condition, perfect working Vintage Lenco Turntable with heavy duty Rosewood plinth and original tonearm There is no top lid.' ] def make_q(label): return models.IntegerField(label=label, choices=[1, 2, 3, 4, 5], widget=widgets.RadioSelect) class Constants(BaseConstants): name_in_url = 'ebay' players_per_group = 10 num_rounds = 1 valuation_max = cu(500) consent_form = 'ebay/consent_form.html' instruction_template = 'ebay/instruction_template.html' personality_template = 'ebay/personality_template.html' payment_template = 'ebay/payment_template.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): start_timestamp = models.IntegerField() class Player(BasePlayer): #id = models.IntegerField() is_buyer = models.BooleanField() current_offer = models.IntegerField() current_quality = models.FloatField() overall_round = models.IntegerField(initial=4) current_round = models.IntegerField(initial=0) overall_stage = models.IntegerField(initial=3) # decide how many people to trade in a round current_stage = models.IntegerField(initial=0) current_item = models.IntegerField(initial=0) left_chance = models.IntegerField(initial=3) earning_this_round = models.FloatField(initial=0.0) earning_last_item = models.FloatField(initial=0.0) earning_last_round = models.FloatField(initial=0.0) overall_earning = models.FloatField(initial=0.0) timeout_second = models.IntegerField(initial=100000) finished = models.BooleanField(initial=False) #history = [[] for x in range(overall_stage)] consent = models.BooleanField( choices=[ [True, 'Yes, I consent'], [False, 'No, I do not consent'], ] ) name_info = models.StringField(label="Name:") major_info = models.StringField(label="Major:") gender_info = models.StringField(label="Gender:") payment_choice_info = models.StringField(label="What payment method do you accept? Venmo or quickpay?") account_info = models.StringField(label="Account infomation") q1 = make_q('Am the life of the party.') q2 = make_q('Feel little concern for others.') q3 = make_q('Am always prepared. ') q4 = make_q(' Get stressed out easily. ') q5 = make_q('Have a rich vocabulary.') q6 = make_q('Do not talk a lot. ') q7 = make_q('Am interested in people. ') q8 = make_q('Leave my belongings around.') q9 = make_q('Am relaxed most of the time. ') q10 = make_q(' Have difficulty understanding abstract ideas.') q11 = make_q('Feel comfortable around people.') q12 = make_q('Insult people. ') q13 = make_q('Pay attention to details.') q14 = make_q('Worry about things. ') q15 = make_q('Have a vivid imagination.') q16 = make_q('Keep in the background. ') q17 = make_q('Sympathize with others feelings. ') q18 = make_q('Make a mess of things. ') q19 = make_q('Seldom feel blue. ') q20 = make_q('Am not interested in abstract ideas. ') q21 = make_q('Start conversations. ') q22 = make_q('Am not interested in other peoples problems.') q23 = make_q('Get chores done right away. ') q24 = make_q('Am easily disturbed. ') q25 = make_q('Have excellent ideas. ') q26 = make_q('Have little to say. ') q27 = make_q('Have a soft heart. ') q28 = make_q('Often forget to put things back in their proper place. ') q29 = make_q('Get upset easily. ') q30 = make_q('Do not have a good imagination. ') q31 = make_q('Talk to a lot of different people at parties. ') q32 = make_q('Am not really interested in others. ') q33 = make_q('Like order. ') q34 = make_q('Change my mood a lot.') q35 = make_q('Am quick to understand things. ') q36 = make_q('Do not like to draw attention to myself.') q37 = make_q('Take time out for others. ') q38 = make_q('Shirk my duties. ') q39 = make_q('Have frequent mood swings. ') q40 = make_q('Use difficult words. ') q41 = make_q('Don not mind being the center of attention.') q42 = make_q('Feel others emotions.') q43 = make_q('Follow a schedule.') q44 = make_q('Get irritated easily.') q45 = make_q('Spend time reflecting on things.') q46 = make_q('Am quiet around strangers. ') q47 = make_q('Make people feel at ease.') q48 = make_q('Am exacting in my work. ') q49 = make_q(' Often feel blue. ') q50 = make_q('Am full of ideas. ') def offer_error_message(player, value): if value == False: print(f'player:{player.id} do not consent.') return 'Can not go futher if you do not consent.' else: print(f'player:{player.id} consent.') class Transaction(ExtraModel): group = models.Link(Group) buyer = models.Link(Player) seller = models.Link(Player) price = models.CurrencyField() seconds = models.IntegerField(doc="Timestamp (seconds since beginneng of trading)") def find_match(buyers, sellers): for buyer in buyers: for seller in sellers: if seller.id_in_group == buyer.id_in_group-1: return [buyer, seller] def creating_session(subsession: Subsession): players = subsession.get_players() for p in players: # for more buyers, change the 2 to 3 p.is_buyer = p.id_in_group % 2 > 0 p.current_offer = item_price_list[0] p.current_quality = item_condition[0] ''' if p.is_buyer: p.current_offer = 0 else: p.current_offer = Constants.valuation_max + 1 ''' def find_match_buyer(buyers, sellers): buyer_match = {} for buyer_index in range(len(buyers)): buyer = buyers[buyer_index] if buyer.current_round == 0 or buyer.current_round == 2: buyer_match[buyers[buyer_index].id_in_group] = sellers[(buyer.current_stage+buyer_index)%len(buyers)].id_in_group elif buyer.current_round == 1 or buyer.current_round == 3: buyer_match[buyers[buyer_index].id_in_group] = sellers[((buyer.current_stage)//3+buyer_index)%(len(buyers))].id_in_group else: buyer_match[buyers[buyer_index].id_in_group] = sellers[buyer_index].id_in_group return buyer_match def find_match_seller(buyers, sellers): buyer_match = {} for buyer_index in range(len(buyers)): buyer = buyers[buyer_index] if buyer.current_round == 0 or buyer.current_round == 2: buyer_match[buyers[buyer_index].id_in_group] = sellers[(buyer.current_stage+buyer_index)%len(buyers)].id_in_group elif buyer.current_round == 1 or buyer.current_round == 3: buyer_match[buyers[buyer_index].id_in_group] = sellers[((buyer.current_stage)//3+buyer_index)%(len(buyers))].id_in_group else: buyer_match[buyers[buyer_index].id_in_group] = sellers[buyer_index].id_in_group return buyer_match def next_round(players, buyer, seller): global item_price_list buyer.overall_earning += buyer.earning_this_round seller.overall_earning += seller.earning_this_round buyer.earning_last_round = buyer.earning_this_round seller.earning_last_round = seller.earning_this_round buyer.earning_this_round = 0 seller.earning_this_round = 0 buyer.finished = True seller.finished = True if buyer.current_round == 0 or buyer.current_round ==2: if buyer.current_stage < FIRST_ROUND_STAGE -1: buyer.current_stage += 1 seller.current_stage += 1 if (buyer.current_round == 1 or buyer.current_round == 3) and buyer.current_stage != FIRST_ROUND_STAGE -1: buyer.finished = False seller.finished = False elif buyer.current_stage == FIRST_ROUND_STAGE -1: buyer.current_stage = 0 seller.current_stage = 0 buyer.current_round += 1 seller.current_round += 1 else: if buyer.current_stage < buyer.overall_stage*3 -1: buyer.current_stage += 1 seller.current_stage += 1 #if (buyer.current_round == 1 or buyer.current_round == 3) and buyer.current_stage%3 != 2 : # buyer.finished = False # seller.finished = False elif buyer.current_stage == buyer.overall_stage*3 -1: buyer.current_stage = 0 seller.current_stage = 0 buyer.current_round += 1 seller.current_round += 1 buyer.left_chance = 3 seller.left_chance = 3 buyer.current_item += 1 seller.current_item += 1 buyer.current_offer = item_price_list[buyer.current_item] seller.current_offer = item_price_list[seller.current_item] buyer.current_quality = item_condition[buyer.current_item] seller.current_quality = item_condition[seller.current_item] def find_corresponding_seller(player, buyers, sellers): buyer = player buyers_match = find_match_buyer(buyers, sellers) seller_id = buyers_match[player.id_in_group] for _seller in sellers: if _seller.id_in_group == seller_id: seller = _seller return seller def find_corresponding_buyer(player, buyers, sellers): sellers_match = find_match_seller(sellers, buyers) seller = player buyer_id = sellers_match[player.id_in_group] for _buyer in buyers: if _buyer.id_in_group == buyer_id: buyer = _buyer return buyer def live_method(player: Player, data): global history global guess_quality_dict if player.id_in_group not in history: history[player.id_in_group] = [] group = player.group players = group.get_players() buyers = [p for p in players if p.is_buyer] sellers = [p for p in players if not p.is_buyer] news = None accept_offer = -10000 reject_offer = -20000 buyers_match = find_match_buyer(buyers, sellers) sellers_match = find_match_seller(sellers, buyers) if player.is_buyer: buyer = player seller_id = buyers_match[player.id_in_group] for _seller in sellers: if _seller.id_in_group == seller_id: seller = _seller else: seller = player buyer_id = sellers_match[player.id_in_group] for _buyer in buyers: if _buyer.id_in_group == buyer_id: buyer = _buyer if seller.id_in_group not in history: history[seller.id_in_group] = [] if buyer.id_in_group not in history: history[buyer.id_in_group] = [] if data: try: offer = int(data['offer']) except Exception: print('invalid message received:', data) #return offer = -1 try: guess_quality = float(data['guess_quality']) except Exception: guess_quality = -1.0 if player.id_in_group not in guess_quality_dict: guess_quality_dict[player.id_in_group] = [] guess_quality_dict[player.id_in_group].append([f"round:{player.current_round}", f"stage:{player.current_stage}", f"left chances:{player.left_chance}",f"guess_quality:{guess_quality}"]) else: guess_quality_dict[player.id_in_group].append([f"round:{player.current_round}", f"stage:{player.current_stage}", f"left chances:{player.left_chance}",f"guess_quality:{guess_quality}"]) if offer == accept_offer: if player.is_buyer: news = dict(buyer=buyer.id_in_group, seller=seller.id_in_group, price=seller.current_offer, from_buyer=player.is_buyer, is_rejct=False, is_accept=True) round_start_stage = [0, 5, 14, 19, 28] seller.earning_this_round += float(seller.current_offer - 0.75*item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage]) # calculate earning seller.earning_last_item = float(seller.current_offer - 0.75*item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage]) buyer.earning_this_round += float(item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage] - seller.current_offer) buyer.earning_last_item = float(item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage] - seller.current_offer) history[buyer.id_in_group].append([f"round:{buyer.current_round}", f"stage:{buyer.current_stage}", f"left chances:{buyer.left_chance}", "Accept", seller.current_offer, buyer.id_in_group, seller.id_in_group]) history[seller.id_in_group].append([f"round:{buyer.current_round}", f"stage:{seller.current_stage}", f"left chances:{seller.left_chance}", "Accept", seller.current_offer, buyer.id_in_group, seller.id_in_group]) #print(f"seller id before next round:{seller.id_in_group}\n") next_round(players, buyer, seller) _seller = find_corresponding_seller(buyer, buyers, sellers) if _seller.id_in_group == seller.id_in_group: seller.finished = False buyer.finished = False else: if _seller.finished == True: _seller.finished = False buyer.finished = False _buyer = find_corresponding_buyer(seller, buyers, sellers) if _buyer.id_in_group == buyer.id_in_group: seller.finished = False buyer.finished = False else: if _buyer.finished == True: _buyer.finished = False seller.finished = False else: news = dict(buyer=buyer.id_in_group, seller=seller.id_in_group, price=buyer.current_offer, from_buyer=player.is_buyer, is_rejct=False, is_accept=True) round_start_stage = [0, 5, 14, 19, 28] seller.earning_this_round += float(buyer.current_offer - 0.75*item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage]) # calculate earning seller.earning_last_item = float(buyer.current_offer - 0.75*item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage]) buyer.earning_this_round += float(item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage] - buyer.current_offer ) buyer.earning_last_item = float(item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage] - buyer.current_offer ) history[buyer.id_in_group].append([f"round:{buyer.current_round}", f"stage:{buyer.current_stage}", f"left chance:{buyer.left_chance}", "Accept", buyer.current_offer, buyer.id_in_group, seller.id_in_group]) history[seller.id_in_group].append([f"round:{buyer.current_round}", f"stage:{seller.current_stage}", f"left chance:{buyer.left_chance}", "Accept", buyer.current_offer, buyer.id_in_group, seller.id_in_group]) next_round(players, buyer, seller) _seller = find_corresponding_seller(buyer, buyers, sellers) if _seller.id_in_group == seller.id_in_group: seller.finished = False buyer.finished = False else: if _seller.finished == True: _seller.finished = False buyer.finished = False _buyer = find_corresponding_buyer(seller, buyers, sellers) if _buyer.id_in_group == buyer.id_in_group: seller.finished = False buyer.finished = False else: if _buyer.finished == True: _buyer.finished = False seller.finished = False elif offer == reject_offer: if player.is_buyer: news = dict(buyer=buyer.id_in_group, seller=seller.id_in_group, price=seller.current_offer, from_buyer=player.is_buyer, is_rejct=True, is_accept=False) seller.earning_this_round += 0.0 #float(seller.current_offer - 0.75*item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage]) # calculate earning seller.earning_last_item = 0.0 #float(seller.current_offer - 0.75*item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage]) buyer.earning_this_round += 0.0 #float(item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage] - seller.current_offer) buyer.earning_last_item = 0.0#float(item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage] - seller.current_offer) history[buyer.id_in_group].append([f"round:{buyer.current_round}", f"stage:{buyer.current_stage}", f"left chance:{buyer.left_chance}", "Reject", seller.current_offer, buyer.id_in_group, seller.id_in_group]) history[seller.id_in_group].append([f"round:{seller.current_round}", f"stage:{seller.current_stage}", f"left chance:{seller.left_chance}", "Reject", seller.current_offer, buyer.id_in_group, seller.id_in_group]) next_round(players, buyer, seller) _seller = find_corresponding_seller(buyer, buyers, sellers) if _seller.id_in_group == seller.id_in_group: seller.finished = False buyer.finished = False else: if _seller.finished == True: _seller.finished = False buyer.finished = False _buyer = find_corresponding_buyer(seller, buyers, sellers) if _buyer.id_in_group == buyer.id_in_group: seller.finished = False buyer.finished = False else: if _buyer.finished == True: _buyer.finished = False seller.finished = False else: news = dict(buyer=buyer.id_in_group, seller=seller.id_in_group, price=buyer.current_offer, from_buyer=player.is_buyer, is_rejct=True, is_accept=False) seller.earning_this_round += 0.0 #float(seller.current_offer - 0.75*item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage]) # calculate earning seller.earning_last_item = 0.0 #float(seller.current_offer - 0.75*item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage]) buyer.earning_this_round += 0.0 #float(item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage] - seller.current_offer) buyer.earning_last_item = 0.0#float(item_price_list[round_start_stage[seller.current_round]+seller.current_stage] * item_condition[round_start_stage[seller.current_round]+seller.current_stage] - seller.current_offer) history[buyer.id_in_group].append([f"round:{buyer.current_round}", f"stage:{buyer.current_stage}", f"left chance:{buyer.left_chance}", "Reject", buyer.current_offer, buyer.id_in_group, seller.id_in_group]) history[seller.id_in_group].append([f"round:{seller.current_round}", f"stage:{seller.current_stage}", f"left chance:{seller.left_chance}", "Reject", buyer.current_offer, buyer.id_in_group, seller.id_in_group]) next_round(players, buyer, seller) _seller = find_corresponding_seller(buyer, buyers, sellers) if _seller.id_in_group == seller.id_in_group: seller.finished = False buyer.finished = False else: if _seller.finished == True: _seller.finished = False buyer.finished = False _buyer = find_corresponding_buyer(seller, buyers, sellers) if _buyer.id_in_group == buyer.id_in_group: seller.finished = False buyer.finished = False else: if _buyer.finished == True: _buyer.finished = False seller.finished = False else: if player.left_chance > 0: player.left_chance -= 1 if player.is_buyer: player.current_offer = offer news = dict(buyer=buyer.id_in_group, seller=seller.id_in_group, price=buyer.current_offer, from_buyer=player.is_buyer, is_rejct=False, is_accept=False) history[buyer.id_in_group].append([f"round:{buyer.current_round}", f"stage:{buyer.current_stage}", f"left chance:{buyer.left_chance}", "Counter", offer, buyer.id_in_group, seller.id_in_group]) history[seller.id_in_group].append([f"round:{seller.current_round}", f"stage:{seller.current_stage}", f"left chance:{seller.left_chance}", "Counter", offer, buyer.id_in_group, seller.id_in_group]) else: player.current_offer = offer news = dict(buyer=buyer.id_in_group, seller=seller.id_in_group, price=seller.current_offer, from_buyer=player.is_buyer, is_rejct=False, is_accept=False) history[seller.id_in_group].append([f"round:{seller.current_round}", f"stage:{seller.current_stage}", f"left chance:{seller.left_chance}", "Counter", offer, buyer.id_in_group, seller.id_in_group]) history[buyer.id_in_group].append([f"round:{buyer.current_round}", f"stage:{buyer.current_stage}", f"left chance:{buyer.left_chance}", "Counter", offer, buyer.id_in_group, seller.id_in_group]) #player.current_offer = offer #bids = sorted([p.current_offer for p in buyers if p.current_offer > 0], reverse=True) #asks = sorted([p.current_offer for p in sellers if p.current_offer <= Constants.valuation_max]) #highcharts_series = [[tx.seconds, tx.price] for tx in Transaction.filter(group=group)] round_start_stage = [0, 5, 14, 19, 28] return { p.id_in_group: dict( finished=p.finished, round_info=dict(round=p.current_round, stage=p.current_stage, chance=p.left_chance), display=dict( value=item_price_list[round_start_stage[p.current_round]+p.current_stage], condition=item_condition[round_start_stage[p.current_round]+p.current_stage], description=item_description[round_start_stage[p.current_round]+p.current_stage], earning=p.earning_last_item), history=history[p.id_in_group] if p.id_in_group in history else [], current_price=p.current_offer, news=news ) for p in players } round_start_stage = [0, 5, 14, 19, 29] class Trading1(Page): live_method = live_method @staticmethod def js_vars(player: Player): return dict(id_in_group=player.id_in_group, is_buyer=player.is_buyer) #@staticmethod #def get_timeout_seconds(player: Player): # import time # group = player.group # return 10 * 60 + group.start_timestamp - time.time() @staticmethod def vars_for_template(player): return dict( image_path='{}_1.jpg'.format(round_start_stage[player.current_round] + player.current_stage + 1) ) class Trading2(Page): live_method = live_method @staticmethod def js_vars(player: Player): return dict(id_in_group=player.id_in_group, is_buyer=player.is_buyer) #@staticmethod #def get_timeout_seconds(player: Player): # import time # group = player.group # return 10 * 60 + group.start_timestamp - time.time() @staticmethod def vars_for_template(player): return dict( image_path='{}_1.jpg'.format(round_start_stage[player.current_round] + player.current_stage + 1) ) class Trading3(Page): live_method = live_method @staticmethod def js_vars(player: Player): return dict(id_in_group=player.id_in_group, is_buyer=player.is_buyer) #@staticmethod #def get_timeout_seconds(player: Player): # import time # group = player.group # return 10 * 60 + group.start_timestamp - time.time() @staticmethod def vars_for_template(player): return dict( image_path='{}_1.jpg'.format(round_start_stage[player.current_round] + player.current_stage + 1) ) class Trading4(Page): live_method = live_method @staticmethod def js_vars(player: Player): return dict(id_in_group=player.id_in_group, is_buyer=player.is_buyer) #@staticmethod #def get_timeout_seconds(player: Player): # import time # group = player.group # return 10 * 60 + group.start_timestamp - time.time() @staticmethod def vars_for_template(player): return dict( image_path='{}_1.jpg'.format(round_start_stage[player.current_round] + player.current_stage + 1) ) # PAGES class Form(Page): pass #timeout_seconds = 100 class Consent(Page): pass #timeout_seconds = 100 class Instructions(Page): pass #timeout_seconds = 120 class AfterInstructions(Page): pass class AfterTrading1(Page): pass class AfterTrading2(Page): pass class AfterTrading3(Page): pass class MyPage(Page): pass class TradingWaitPage(WaitPage): pass class ResultsWaitPage(WaitPage): pass class ShowEarningPage(Page): pass class Results(Page): pass class Personality(Page): form_model = 'player' form_fields = ['q1', 'q2', 'q3', 'q4', 'q5', 'q6', 'q7', 'q8', 'q9', 'q10', 'q11', 'q12', 'q13', 'q14', 'q15', 'q16', 'q17', 'q18', 'q19', 'q20', 'q21', 'q22', 'q23', 'q24', 'q25', 'q26', 'q27', 'q28', 'q29', 'q30', 'q31', 'q32', 'q33', 'q34', 'q35', 'q36', 'q37', 'q38', 'q39', 'q40', 'q41', 'q42', 'q43', 'q44', 'q45', 'q46', 'q47', 'q48', 'q49', 'q50'] @staticmethod def before_next_page(player: Player, timeout_happened): global answear_dict answear_dict[player.id_in_group] = { "q1": player.q1, "q2": player.q2, "q3": player.q3, "q4": player.q4, "q5": player.q5, "q6": player.q6, "q7": player.q7, "q8": player.q8, "q9": player.q9, "q10": player.q10, "q11": player.q11, "q12": player.q12, "q13": player.q13, "q14": player.q14, "q15": player.q15, "q16": player.q16, "q17": player.q17, "q18": player.q18, "q19": player.q19, "q20": player.q20, "q21": player.q21, "q22": player.q22, "q23": player.q23, "q24": player.q24, "q25": player.q25, "q26": player.q26, "q27": player.q27, "q28": player.q28, "q29": player.q29, "q30": player.q30, "q31": player.q31, "q32": player.q32, "q33": player.q33, "q34": player.q34, "q35": player.q35, "q36": player.q36, "q37": player.q37, "q38": player.q38, "q39": player.q39, "q40": player.q40, "q41": player.q41, "q42": player.q42, "q43": player.q43, "q44": player.q44, "q45": player.q45, "q46": player.q46, "q47": player.q47, "q48": player.q48, "q49": player.q49, "q50": player.q50 } class Payment(Page): form_model = 'player' form_fields = ['name_info', 'major_info', 'gender_info', 'payment_choice_info', 'account_info'] @staticmethod def before_next_page(player, timeout_happened): global answear_dict global guess_quality record = dict() fp = open(f"player:{player.id} + {time.ctime()}.json", 'w') record['name'] = player.name_info record['major'] = player.major_info record['gender'] = player.gender_info record['payment_choice'] = player.payment_choice_info record['account'] = player.account_info record['answear_dict'] = answear_dict[player.id_in_group] if player.id_in_group in answear_dict else None record['history'] = history[player.id_in_group] if player.id_in_group in history else None record['guess_quality'] = guess_quality_dict[player.id_in_group] if player.id_in_group in guess_quality_dict else None record['is_buyer'] = player.is_buyer record['overall_earning'] = player.overall_earning record["question_answer"] = [player.q1,player.q2,player.q3,player.q4,player.q5,player.q6,player.q7,player.q8,player.q9,player.q10,player.q11,player.q12,player.q13,player.q14,player.q15,player.q16,player.q17,player.q18,player.q19,player.q20,player.q21,player.q22,player.q23,player.q24,player.q25,player.q26,player.q27,player.q28,player.q29,player.q30,player.q31,player.q32,player.q33,player.q34,player.q35,player.q36,player.q37,player.q38,player.q39,player.q40,player.q41,player.q42,player.q43,player.q44,player.q45,player.q46,player.q47,player.q48,player.q49,player.q50] json.dump(record, fp) # PAGES class WaitToStart(WaitPage): @staticmethod def after_all_players_arrive(group: Group): group.start_timestamp = int(time.time()) #page_sequence = [WaitToStart, Consent, Instructions, TradingWaitPage, Trading, MyPage, ResultsWaitPage, Results, Personality, Payment] page_sequence = [WaitToStart, Consent, Instructions, AfterInstructions, TradingWaitPage, Trading1, ShowEarningPage, AfterTrading1, ResultsWaitPage, Trading2, ShowEarningPage, AfterTrading2, ResultsWaitPage, Trading3, ShowEarningPage, AfterTrading3, ResultsWaitPage, Trading4, ShowEarningPage, ResultsWaitPage, Results, Personality, Payment]