from otree.api import * import os import json from os import environ from config.treatment import Treatment import pandas as pd from otree.api import BaseConstants, BaseGroup, BasePlayer, BaseSubsession from django import template from django.shortcuts import render doc = """ Your app description """ class Constants(BaseConstants): name_in_url = "cost_experiment" players_per_group = None num_rounds = 1 task_type = environ.get("TASK_TYPE", "estimation") # anagram: [answers] with open("data/anagram_answers.json") as f: data = json.loads(f.read()) class Subsession(BaseSubsession): treatment = models.StringField() # Hiring instructions 2/4 # Estimation Payment unit config_estimation_payment_unit_1 = models.FloatField() config_estimation_payment_unit_2 = models.FloatField() # Estimation Deduction unit config_estimation_deduction_unit = models.FloatField() # number of total candidates from part 1 config_num_total_candidates = models.IntegerField(initial=0) # number of candidates from part 1 for player to choose config_num_candidates = models.IntegerField() # prerandomised candidates all_candidates = models.StringField(max_length=1000000) class Group(BaseGroup): pass class Player(BasePlayer): score = models.IntegerField(initial=0) question1_answer = models.BooleanField( label='1. Each Candidate has a reservation wage, what is that for?', choices=((False, 'A. The exact wage must offer to the candidate, no matter whether tou want to hire or not'), (False, "B. The exact wage you must offer to the candidate you want to hire."), (True,"C. The minimum wage you need to offer to successfully hire the candidate you want to hire "), (False, "D. The maximum wage you need to offer to successfully hire the candidate you want to hire"))) question2_answer = models.BooleanField( label='2. Each reservation wage is equally likely to be any number from _ to _. Please select one of the options to fill in the blank.', choices=((False, 'A. 1, 20'), (True, "B. 5, 25"), (False,"C. 7, 28"), (False, "D. 10, 30")) ) question3_answer = models.BooleanField( label='3. If you decide to hire candidate 1 and candidate 2, which following pairs of wages you can offer respectively?', choices=((False, 'A. 17, 18'), (True, "B. 20, 20"), (False,"C. 1, 2"), (False, "D. 4, 4"), (False, "E. A, B")) ) is_wrong=models.BooleanField() no_answer = models.BooleanField(initial=False) error_message = models.StringField(label="test error 1", initial="true") # PAGES class FirstRoundPage(Page): def is_displayed(self): return self.round_number == 1 class PracticeTaskInstructions1(FirstRoundPage): pass class PracticeTaskInstructions2(FirstRoundPage): pass class Video(FirstRoundPage): def get_next_button_timeout(self): """Used in the javascript.""" if os.getenv("OTREE_PRODUCTION", 0) == "1": timeout_seconds = self.session.config["video_btn_time_timeout"] else: timeout_seconds = 1 return timeout_seconds def vars_for_template(self): video_url = ( self.session.config["s3_bucket"] + self.session.config["video_prefix"] + self.session.config["task_type_prefix"] + self.session.config["treatment"] + ".mp4" ) return { "video_url": video_url, "btn_timeout_seconds": self.get_next_button_timeout(), } class TestingQuestion1(FirstRoundPage): form_model = 'player' form_fields = ["question1_answer"] @staticmethod def error_message(player,values): print('values is', values) if values["question1_answer"] != True: return 'Each candidate has a reservation wage. This determines the minimum wages you need to offer to successfully hire the candidate. ' else: pass class TestingQuestion2(FirstRoundPage): form_model = 'player' form_fields = ["question2_answer"] def error_message(player,values): print('values is', values) if values["question2_answer"] != True: return 'Each candidate has a reservation wage, which is a random number from 5 to 25 points.' else: pass class TestingQuestionCompetition(FirstRoundPage): form_model = 'player' form_fields = ["competition5_answer","competition6_answer"] def is_displayed(self): return self.competition_answer def error_message(player, values): hints= { "non_competition5_answer": """Your total payment will consist of 15 initial points and the additional points you earn from the manager task.""", "non_competition6_answer": """You will receive 1 point for each score of the Employment Performance of your successfully hired candidate, minus the wage you decided to offer as additional points. Your total payment will consist of 15 initial points and the additional points you earn from the manager task.""" } error_messages = dict() for key, item in values.items(): if item != True: if key == "non_competition5_answer": error_messages["non_competition5_answer"] = hints[key] else: error_messages["non_competition6_answer"] = hints[key] return error_messages class PracticeTask(FirstRoundPage): def vars_for_template(self): ret = {"not_show_score": False} return ret class Survey(Page): pass class Payment(Page): pass page_sequence = [ PracticeTaskInstructions1 ,PracticeTaskInstructions2 ,PracticeTask # ,Video , TestingQuestion1 , TestingQuestion2 ]