from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import config_collat import id_gen import random import ast debug = True author = "CSN/IFREE REU 2019 oTree Team" doc = """ Full Collateral Game """ class Constants(BaseConstants): """ Description: Inherits oTree Class BaseConstants. Defines constants for the experiment these will remain unchanged Input: uuid - (ID generating package) config_collat - (Dictionary of treatment parameters) Output: None """ name_in_url = 'Collateral_Game' # name in webbrowser list_of_treatments = config_collat.parameters.keys() randomized_treatment = list(list_of_treatments)[0] quiz_answers = [True, 'The lender offers a repayment rate, the borrower offers collateral, the lender' ' offers a loan, the borrower accepts the loan agreement', '1-5', '3', 'The lender', 'The lender can obtain some value from the collateral up to the value minus the collateral fee'] treatment = randomized_treatment#randomized_treatment dic_of_treatment_parameters = config_collat.parameters[treatment] timer = int(dic_of_treatment_parameters['game_timeout']) confirmation_timeout = int(dic_of_treatment_parameters['confirmation_timeout']) matching_timeout = int(dic_of_treatment_parameters['matching_timeout']) # rate_of_return = float(dic_of_treatment_parameters['rate_of_return']) contract_enforcement = eval(dic_of_treatment_parameters['contract_enforcement']) players_per_group = int(dic_of_treatment_parameters["players_per_group"]) num_rounds = int(dic_of_treatment_parameters["num_rounds"]) initial_points = c(dic_of_treatment_parameters["initial_points"]) recovery_fee = c(dic_of_treatment_parameters["recovery_fee"]) productivity = int(dic_of_treatment_parameters["productivity"]) instructions_payoff = c(10) information_score_sheet = 'Collateral_Game/Information_Score_Sheet.html' class Subsession(BaseSubsession): """ Description: Inherits oTree Class BaseSubsession. Defines subsession for the experiment. Input: None Output: None """ class Group(BaseGroup): """ Description: Inherits BaseGroup oTree class. Assigns group characteristics. Input: None Output: None """ # this is here so we can grab its field name game_timeout = models.IntegerField(initial=0) game_timeout_borrower = models.IntegerField(initial=0) game_timeout_lender = models.IntegerField(initial=0) treatment = models.CharField(initial=Constants.treatment) treatment_recovery_fee = models.CurrencyField(initial= Constants.recovery_fee) treatment_contract_enforcement = models.BooleanField(initial= Constants.contract_enforcement) rate_of_return = models.FloatField(max=Constants.productivity, min=0, verbose_name='Enter a rate of return') project_multiplier = models.IntegerField(initial=Constants.productivity) starting_points = models.CurrencyField(initial=Constants.initial_points) collateral_after_fee = models.CurrencyField() collateral = models.CurrencyField(verbose_name='Enter a collateral offer:', min=0, max=Constants.initial_points ) loan = models.CurrencyField(verbose_name='Enter a loan offer:', min=0, max=Constants.initial_points ) repayment = models.CurrencyField(verbose_name='Enter the amount you wish to repay:', min=0) actual_return = models.FloatField() accept_loan = models.CharField( verbose_name='Do you accept the loan agreement?', choices=['Yes', 'No'], widget=widgets.RadioSelect) satisfied = models.CharField( verbose_name='Are you satisfied with the repayment?', choices=['Yes', 'No'], widget=widgets.RadioSelect) recovered_collateral = models.CurrencyField(verbose_name='Enter the amount of collateral you want to recover:',min=0) returned_collateral = models.CurrencyField() requested_repayment = models.CurrencyField() expected_borrower_profit = models.CurrencyField() lender_money = models.CurrencyField(initial=Constants.initial_points ) borrower_money = models.CurrencyField(initial=Constants.initial_points ) lender_dollar_value = models.CharField(initial='$1.00') borrower_dollar_value = models.CharField(initial='$1.00') project_return = models.CurrencyField() group_id = models.CharField(initial=id_gen.id_gen()) current_page_index = models.IntegerField(initial=1) def repayment_max(self): """ Description: Sets a maximum value for the field repayment Input: Loan - (Global, Stored in models.py, Group, Currency) Productivity - (Global, models.py, Constants, Integer) Output: Max Return - (Loan * Productivity) """ max_return = int(self.loan) * Constants.productivity return max_return def recovered_collateral_max(self): """ Description: Sets a maximum value for the field recovered_collateral Input: Value of Collateral - (Global, Stored in models.py, Group, Currency) Output: Max Seized Collateral - (Value of Collateral) """ return self.collateral_after_fee class Player(BasePlayer): """ Description: Inherits oTree class BasePlayer. Defines player characteristics. Input: None Output: None """ money = models.CurrencyField(initial=Constants.initial_points) using_mobile = models.BooleanField(initial=False) def role(self): """ Description: Inherits oTree class BasePlayer. Defines player characteristics. Input: Player - (Player Location) Output: Player Role """ if self.participant.vars['role'] == 'lender': return 'lender' if self.participant.vars['role'] == 'borrower': return 'borrower'