from django.conf import settings from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Preview(Page): def before_next_page(self): self.player.participant.vars['negotiation'] = 0 def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return dict( score=self.player.participant.vars['initial_score'], tokens=self.player.participant.payoff, ) pass class Negotiation(Page): live_method = 'live_negotiate' def get_timeout_seconds(self): # 10 seconds to allow the user to read information # 5 seconds of forgiveness before the page is submitted return self.session.config['NEGOTIATION_TIME'] + 15 def vars_for_template(self): employee_offer = self.group.employeeOffer employer_offer = self.group.employerOffer opRole = "x" opStanding = 0 oppic = ' ' pic = '' opinitscore = 0 opscore = 0 opearn = 0 opneg = 0 # Find opponent information for p in self.group.get_players(): if not p.id_in_group == self.player.id_in_group: if p.participant.vars['gender'] == "Male/Man": oppic = 'male.jpg' else: oppic = 'female.jpg' opRole = p.participant.vars['Role'] opStanding = p.participant.vars['standing'] opinitscore = p.participant.vars['initial_score'] opscore = p.participant.vars['score'] opearn = p.participant.vars['prev_earnings'] opneg = int(p.participant.vars['negotiation'] * 100) # determine your image paths if self.player.participant.vars['gender'] == "Male/Man": pic = 'male.jpg' else: pic = 'female.jpg' neg = int(self.player.participant.vars['negotiation'] * 100) return dict( ee_offer=employee_offer, er_offer=employer_offer, op_image_path=oppic, your_image_path=pic, oprole=opRole, opstand=opStanding, opinitscore=opinitscore, opscore=opscore, opearn=opearn, opneg=opneg, neg=neg, ) def before_next_page(self): if self.timeout_happened: # This means there was no agreement! self.player.expired = True # if fallback is turned on, set the data here. if self.subsession.fallback: partnerAmount = 0 role = self.player.role() if role == 'Employee': self.player.participant.vars['negotiation'] = 0.4 else: self.player.participant.vars['negotiation'] = 0 partnerAmount = 0.4 for p in self.group.get_players(): if p.id_in_group != self.player.id_in_group: p.participant.vars['negotiation'] = partnerAmount pass class BasicWait(WaitPage): pass class FinalWait(WaitPage): pass class WorkWait(WaitPage): wait_for_all_groups = True after_all_players_arrive = 'set_scores' pass class PartnerWait(Page): live_method = 'live_partner_wait' pass class Results(Page): def vars_for_template(self): score = self.player.score standing = self.player.participant.vars['standing'] earn = self.player.participant.vars['prev_earnings'] neg = int(self.player.participant.vars['negotiation'] * 100) tokens = self.player.participant.payoff opscore = 0 opearn = 0 opneg = 0 oprole = "x" avgE = 0 for p in self.subsession.get_players(): avgE = avgE + p.participant.vars['prev_earnings'] avgE = avgE / self.session.num_participants avgEarn = int(avgE) # Find opponent information for p in self.group.get_players(): if not p.id_in_group == self.player.id_in_group: oprole = p.participant.vars['Role'] opscore = p.participant.vars['score'] opearn = p.participant.vars['prev_earnings'] opneg = int(p.participant.vars['negotiation'] * 100) return dict( avgE=avgEarn, score=score, standing=standing, earn=earn, tokens=tokens, oprole=oprole, opscore=opscore, opearn=opearn, opneg=opneg, neg=neg, ) pass class WorkSession(Page): live_method = 'live_work' def get_timeout_seconds(self): # 5 seconds of forgiveness time return self.session.config['MAIN_WORK_TIME'] + 5 def vars_for_template(self): return dict( neg=int(self.player.participant.vars['negotiation'] * 100)) pass page_sequence = [Preview, BasicWait, Negotiation, PartnerWait, WorkSession, WorkWait, Results, FinalWait]