# -*- coding: utf-8 -*- from __future__ import division from . import models from ._builtin import Page, WaitPage from otree.common import Currency as c, currency_range from .models import Constants from django.utils import timezone import time # from datetime import datetime # import pytz # $ pip install pytz # from django.utils.timezone import activate # # activate(settings.TIME_ZONE) # This restricts players to those matching the conditions. # It sets the variable 'eligible' to False if the conditions are not met, # so that on the ThankYou page, people are thanked and excluded. # The multiple if conditions have to be put in parantheses in order to write them over several lines # The 'not in' is a useful way of specifying several exclusion categories def preselection(player): if (player.income not in ("40,000-60,000$/year","60,000-100,000$/year","over 100,000$/year") and player.race not in("White", "Another race, ethnicity, or origin")): return True else: return False # and (player.race not in ("White") and player.gender=="Male")) # exclude white males !! mind the parantheses !! # Previously was: # def preselection(player): # if player.poverty!=None: # return player.poverty # to disable non-poor being excluded set True # else: # return True class BasePage(Page): def is_displayed(self): return preselection(self.player) and self.extra_display_condition() def extra_display_condition(self): return True # For the selection mechanism to work, the first three pages # (Welcome, Preselection and ThankYou) need to be basedon 'Page' rather #than 'BasePage' to disable the show-only-if-preselection is true mechanism of BasePage # passes the variable 'eligible' to all players def vars_for_all_templates(self): return {'eligible': preselection(self.player)} class Textprime(BasePage): form_model = models.Player def get_form_fields(self): if self.player.treatment: return "treatprimetext", else: return "controlprimetext", class PreselectionQuestionnaire(Page): def before_next_page(self): self.player.questionnaire_start_time= timezone.now() form_model=models.Player def get_form_fields(self): return ["age", "gender", "education", "occupation", "hhsize", "income", "savings", "poverty", "satisfied", "race", "children", "state", ] class Hunting(BasePage): form_model=models.Player #show page only when eligible, only when there is a bit of time left (if we dont do this, # the person might refresh, and might get another 30secs) #otherwise people are moved on (that's the default behaviour of the is_displayed internal # function without the additional condition added by Philipp) def extra_display_condition(self): self.player.hunting_start_time = timezone.now() return self.player.hunting_time_left() def vars_for_template(self): # self.player.hunting_start_time = timezone.now() self.player.hunting_refreshed=0 if self.player.hunting_refreshed is None else self.player.hunting_refreshed+1 # vars necessary only for displaying on the page - just shortening the variable to more easily refer to them later return { 'stag_stag': Constants.stag_stag_amount, 'stag_hare': Constants.stag_hare_amount, 'hare_stag': Constants.hare_stag_amount, 'hare_hare': Constants.hare_hare_amount, "time_left": self.player.hunting_time_left(), # will be used in Java timer } def before_next_page(self): #the time has come :) to get the player some profit based on his decision in hunting page self.player.payoff=(Constants.stag_stag_amount+Constants.postgame_earnings) if self.player.decision=="Stag" else (Constants.hare_stag_amount+Constants.postgame_earnings) # decision gets automatically registered def get_form_fields(self): return ["decision", "hunting_thinkingtime", "over_ontimeout" ] class Welcome(Page): def vars_for_template(self): return {'nq': 11, 'lb': c(Constants.postgame_earnings+Constants.stag_hare_amount), 'ub': c(Constants.postgame_earnings+Constants.stag_stag_amount), 'min': "5-15", # "time_limit": int(Constants.round_1_seconds / 60), # the lower bound and higher bound amounts should be replaced with variables recording people's # earnings, once we have sorted out the payoffs } class ThankYou(Page): def before_next_page(self): self.player.priming_start_time= timezone.now() def vars_for_template(self): return {'lb': c(Constants.postgame_earnings+Constants.stag_hare_amount), 'ub': c(Constants.postgame_earnings+Constants.stag_stag_amount), } class Priming(BasePage): def extra_display_condition(self): return self.player.priming_time_left() def vars_for_template(self): time_left=self.player.priming_time_left() timeleftstr =time.strftime("%M:%S", time.gmtime(time_left)) print('TIME LEFT SUKA'+timeleftstr) if self.player.treatment: tr_text=["$3,500","$325","$3,900"] #before ["$3,500","$325","$3,900"] else: tr_text=["$150","$15","$180"] return {'tr_text': tr_text, "time_left": self.player.priming_time_left(), #'waiting_time': , # timeleftstr was behaving strangely for periods <60 secs, used to be time.strftime("%M:%S", time.gmtime(Constants.priming_time)) } class Instructions1(BasePage): pass class Instructions2(BasePage): pass class Waiting1(BasePage): template_name = 'stag_hunt/WaitingPage.html' timeout_seconds = Constants.waiting_partner_time text="Please wait until the other MTurker has joined the hunting task…." def vars_for_template(self): return {'text': self.text} class PartnerJoined(BasePage): def before_next_page(self): pass class QuestionnaireAnnouncement(BasePage): def vars_for_template(self): return {'nq_postgame': 12, #'postgame_earnings':c(2), 'stag':True if self.player.decision=="Stag" else False} class PostQuestionnaire1(BasePage): form_model = models.Player def get_form_fields(self): return ["think_stag", "stress_sum", "remember_sum", "touch", "loan", "friends", ] def vars_for_template(self): return {'nq_remaining':5,} class PostQuestionnaire2(BasePage): form_model = models.Player def get_form_fields(self): return [ "payrate", "lastpay", "traveltime", # newly inserted traveltime "risks", "paid_tomorrow", ] class FinalPage(BasePage): def before_next_page(self): self.player.last_page_time= timezone.now() form_model = models.Player def get_form_fields(self): return [ "while_waiting", "understand", # "letknow", # combined with with 'understand' question ] def vars_for_template(self): return {'total_payoffs': c(self.session.config['participation_fee']+self.player.payoff) } page_sequence = [#Welcome, PreselectionQuestionnaire, ThankYou, Priming, # Textprime, Instructions1, Instructions2, Waiting1, PartnerJoined, Hunting, QuestionnaireAnnouncement, PostQuestionnaire1, PostQuestionnaire2, FinalPage, ]