-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
102 lines (77 loc) · 2.83 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from otree.api import (
models,
widgets,
BaseConstants,
BaseSubsession,
BaseGroup,
BasePlayer,
Currency as c,
currency_range,
)
import random
author = 'Your name here'
doc = """
Your app description
"""
class Constants(BaseConstants):
name_in_url = 'Second_Price_Auction_Bots'
players_per_group = None
num_rounds = 5
endowment = c(100)
value = c(150)
error = c(50)
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
bot1 = models.CurrencyField()
#bot2 = models.CurrencyField()
# bot1 = models.CurrencyField(initial=c(random.uniform(Constants.value - Constants.error, Constants.value + Constants.error)))
# bot2 = models.CurrencyField(initial=c(random.uniform(Constants.value - Constants.error, Constants.value + Constants.error)))
#bot1 = random.uniform(Constants.value - Constants.error, Constants.value + Constants.error)
#bot2 = random.uniform(Constants.value - Constants.error, Constants.value + Constants.error)
bid = models.CurrencyField(
label="What is your bid?",
min=0)
highest_bid = models.CurrencyField()
second_highest_bid = models.CurrencyField()
def highest(self):
print(min([self.bid, self.bot1]))
print(sorted([self.bid, self.bot1])[1])
players = self.get_players()
#print(self.get_players())
#print(self.bid, Constants.bot1, Constants.bot2)
self.highest_bid = min([self.bid, self.bot1])
self.second_highest_bid = sorted([self.bid, self.bot1])[1]
#return self.highest_bid
#return self.second_highest_bid
#player_with_highest_bid = [self.bid==self.highest_bid]
#winner = random.choice(player_with_highest_bid)
#winner.is_winner = True
#if self.bid==self.highest_bid:
# self.group.player.is_winner=True
for p in players:
p.set_payoff()
#self.group.player.set_payoff()
class Player(BasePlayer):
is_winner = models.BooleanField(
initial = False
)
valuation = models.CurrencyField()
profit = models.CurrencyField(initial=c(0))
def random_valuation(self):
import random
minimum = Constants.value - Constants.error
maximum = Constants.value + Constants.error
estimate = random.uniform(minimum, maximum)
return estimate
def set_payoff(self):
if self.group.bid==self.group.highest_bid:
self.is_winner=True
if self.is_winner:
self.payoff = self.group.second_highest_bid - self.valuation
else:
self.payoff = c(0)
if self.round_number==1:
self.profit = self.payoff
else:
self.profit = self.in_round(self.round_number - 1).profit + self.payoff