from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import config_collat import random author = 'CSN/IFREE REU 2019 oTree Team' doc = """ Instructions for the Collateral Game """ class Constants(BaseConstants): instructions_payoff = c(10) name_in_url = 'Collateral_Instructions' #TODO: be less specific '''Determines which treatment to run''' treatment = 'treatment1' '''Refrences the dictonary of treatments to assign variables to this round''' # boolean has not been integrated yet contract_enforcement = config_collat.parameters[treatment]['contract_enforcement'] '''As of right now this will always be set to two. If for some reason this is changed it will *Break* the game.''' players_per_group = config_collat.parameters[treatment]["players_per_group"] '''As of right now this will always be set to one.''' num_rounds = config_collat.parameters[treatment]["num_rounds"] '''Returns an integer which is converted into an otree specific type currency.''' initial_points = c(config_collat.parameters[treatment]["initial_points "]) recovery_fee = c(config_collat.parameters[treatment]["recovery_fee"]) productivity = config_collat.parameters[treatment]["productivity"] class Subsession(BaseSubsession): def creating_session(self): '''Populates example variables with random values and takes constant variables into account to find example loan return amount and maximum salvage amount.''' players = self.get_players() for p in players: p.example_loan_amount = random.SystemRandom().randrange(1,11,2) p.example_return_amount = p.example_loan_amount * Constants.productivity p.example_collateral_amount = random.SystemRandom().randrange(1,11,2) p.example_salvage_max = p.example_collateral_amount - int(Constants.recovery_fee) class Group(BaseGroup): pass class Player(BasePlayer): '''Empty variables that will be defined in the creating_session method above. Elaborate''' example_loan_amount = models.IntegerField(initial=None) example_return_amount = models.IntegerField(initial=None) example_collateral_amount = models.IntegerField(initial=None) example_salvage_max = models.IntegerField(initial=None) def role(self): '''Assigns roles to players by id.''' if self.id_in_group == 1: return 'lender' if self.id_in_group == 2: return 'borrower'