import random
import numpy as np
import pandas as pd
from otree.api import *
doc = """
Pilot for Rules Project
"""
class C(BaseConstants):
NAME_IN_URL = 'intro'
PLAYERS_PER_GROUP = None
NUM_ROUNDS = 10
MIN_TIME = 15 # in minutes
MAX_TIME = 25 # in minutes
# REVIEW_INSTRUCTIONS = 'informational_cost/reviewInstructions.html'
DONATION = cu(1000)
ATTRIBUTES = ['category', 'location', 'name', 'expense_ratio', 'admin_expenses', 'fund_expenses', 'liabilities',
'efficiency', 'working_capital', 'expense_growth']
class Subsession(BaseSubsession):
pass
def creating_session(subsession: Subsession):
if subsession.round_number == 1:
for p in subsession.get_players():
p.participant.surprise_round = np.random.randint(1, high=C.NUM_ROUNDS)
df = pd.read_csv('rules/charities_database.csv', nrows=200, header=0,
names=C.ATTRIBUTES)
df = df.sample(frac=1).reset_index()
charities_dict = {}
for col in df.columns:
charities_dict[col] = df[col].values.tolist()
subsession.session.charities_dict = charities_dict
# for k in charities_dict.keys():
# print(k)
class Group(BaseGroup):
pass
class Player(BasePlayer):
message = models.LongStringField(blank=True, label='Type the message below.')
# FUNCTIONS
# PAGES
class Welcome(Page):
pass
class Consent(Page):
pass
class Instructions(Page):
pass
class IntroduceCharities(Page):
pass
class Message(Page):
form_model = 'player'
form_fields = ['message']
def is_displayed(player: Player):
return player.round_number == player.participant.surprise_round
class CharityPractice(Page):
@staticmethod
def vars_for_template(player: Player):
charities_dict = player.session.charities_dict
category = charities_dict['category']
location = charities_dict['location']
expense_ratio = charities_dict['expense_ratio']
admin_expenses = charities_dict['admin_expenses']
fund_expenses = charities_dict['fund_expenses']
liabilities = charities_dict['liabilities']
efficiency = charities_dict['efficiency']
working_capital = charities_dict['working_capital']
expense_growth = charities_dict['expense_growth']
i = player.round_number + 5*(player.round_number-1) if player.round_number > 1 else player.round_number
return_dict = {}
category1 = category[i]
category2 = category[i + 1]
category3 = category[i + 2]
category4 = category[i + 3]
category5 = category[i + 4]
category6 = category[i + 5]
location1 = location[i]
location2 = location[i + 1]
location3 = location[i + 2]
location4 = location[i + 3]
location5 = location[i + 4]
location6 = location[i + 5]
expense_ratio1 = expense_ratio[i]
expense_ratio2 = expense_ratio[i + 1]
expense_ratio3 = expense_ratio[i + 2]
expense_ratio4 = expense_ratio[i + 3]
expense_ratio5 = expense_ratio[i + 4]
expense_ratio6 = expense_ratio[i + 5]
admin_expenses1 = admin_expenses[i]
admin_expenses2 = admin_expenses[i + 1]
admin_expenses3 = admin_expenses[i + 2]
admin_expenses4 = admin_expenses[i + 3]
admin_expenses5 = admin_expenses[i + 4]
admin_expenses6 = admin_expenses[i + 5]
fund_expenses1 = fund_expenses[i]
fund_expenses2 = fund_expenses[i + 1]
fund_expenses3 = fund_expenses[i + 2]
fund_expenses4 = fund_expenses[i + 3]
fund_expenses5 = fund_expenses[i + 4]
fund_expenses6 = fund_expenses[i + 5]
liabilities1 = liabilities[i]
liabilities2 = liabilities[i + 1]
liabilities3 = liabilities[i + 2]
liabilities4 = liabilities[i + 3]
liabilities5 = liabilities[i + 4]
liabilities6 = liabilities[i + 5]
efficiency1 = efficiency[i]
efficiency2 = efficiency[i + 1]
efficiency3 = efficiency[i + 2]
efficiency4 = efficiency[i + 3]
efficiency5 = efficiency[i + 4]
efficiency6 = efficiency[i + 5]
working_capital1 = working_capital[i]
working_capital2 = working_capital[i + 1]
working_capital3 = working_capital[i + 2]
working_capital4 = working_capital[i + 3]
working_capital5 = working_capital[i + 4]
working_capital6 = working_capital[i + 5]
expense_growth1 = expense_growth[i]
expense_growth2 = expense_growth[i + 1]
expense_growth3 = expense_growth[i + 2]
expense_growth4 = expense_growth[i + 3]
expense_growth5 = expense_growth[i + 4]
expense_growth6 = expense_growth[i + 5]
return_dict.update(category1=category1, category2=category2, category3=category3, category4=category4,
category5=category5, category6=category6,
expense_ratio1=expense_ratio1, expense_ratio2=expense_ratio2, expense_ratio3=expense_ratio3,
expense_ratio4=expense_ratio4, expense_ratio5=expense_ratio5, expense_ratio6=expense_ratio6,
location1=location1, location2=location2, location3=location3, location4=location4,
location5=location5, location6=location6,
admin_expenses1=admin_expenses1, admin_expenses2=admin_expenses2,
admin_expenses3=admin_expenses3, admin_expenses4=admin_expenses4,
admin_expenses5=admin_expenses5, admin_expenses6=admin_expenses6,
fund_expenses1=fund_expenses1, fund_expenses2=fund_expenses2, fund_expenses3=fund_expenses3,
fund_expenses4=fund_expenses4,
fund_expenses5=fund_expenses5, fund_expenses6=fund_expenses6,
liabilities1=liabilities1, liabilities2=liabilities2, liabilities3=liabilities3,
liabilities4=liabilities4,
liabilities5=liabilities5, liabilities6=liabilities6,
efficiency1=efficiency1, efficiency2=efficiency2, efficiency3=efficiency3,
efficiency4=efficiency4,
efficiency5=efficiency5, efficiency6=efficiency6,
working_capital1=working_capital1, working_capital2=working_capital2,
working_capital3=working_capital3, working_capital4=working_capital4,
working_capital5=working_capital5, working_capital6=working_capital6,
expense_growth1=expense_growth1, expense_growth2=expense_growth2,
expense_growth3=expense_growth3, expense_growth4=expense_growth4,
expense_growth5=expense_growth5, expense_growth6=expense_growth6)
return return_dict
# class CQ(Page):
# pass
# form_model = 'player'
# form_fields = ['cq1', 'cq2', 'cq3']
# class Transition(Page):
# @staticmethod
# def is_displayed(player: Player):
# return player.round_number in [5, 10] if player.participant.det else player.round_number == 10
#
# @staticmethod
# def before_next_page(player: Player, timeout_happened):
# all_participant_choices = []
# if player.round_number == 10:
# for p in player.in_all_rounds():
# all_participant_choices.append(p.environment_choice)
# player.participant.environment_choice = all_participant_choices
# class Hypothetical(Page):
# form_model = 'player'
# form_fields = ['explain', 'advice']
#
# @staticmethod
# def vars_for_template(player):
# if player.participant.environment_choice[-1]:
# label = 'In part 1 of the last decision, you chose the ' + \
# C.LABEL_POOL[-1] + ' tasks. Why did you choose these tasks?'
# else:
# label = 'In part 1 of the last decision, you chose the ' + \
# C.LABEL_SEP[-1] + ' tasks. Why did you choose these tasks?'
# adv_label = 'If you could advise another participant on the last decision of whether the computer ' \
# 'faces ' + C.LABEL_POOL[-1] + ' or ' + C.LABEL_SEP[-1] + ' tasks, which would you advise them' \
# ' to choose?'
# return dict(
# explain_label=label,
# advice_label=adv_label
# )
#
# @staticmethod
# def error_message(player, values):
# if not player.session.config['development'] and (values['advice'] is None or values['explain'] is None):
# return 'Please, answer the questions.'
# @staticmethod
# def is_displayed(player: Player):
# return player.round_number == 10
page_sequence = [
# Welcome,
# Consent,
# Instructions,
CharityPractice,
Message,
# CQ,
# Transition,
# Hypothetical
]