-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Otree project with demo games && Add application mini_ultimatum
- Loading branch information
0 parents
commit 71a9c57
Showing
78 changed files
with
2,402 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
venv | ||
staticfiles | ||
./db.sqlite3 | ||
.idea | ||
*~ | ||
*.sqlite3 | ||
_static_root | ||
_bots*s | ||
__temp* | ||
__pycache__/ | ||
*.py[cod] | ||
.DS_Store | ||
merge.ps1 | ||
*.otreezip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright (c) 2014 Daniel Li Chen, Martin Walter Schonger, Christopher Wickens. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
|
||
The Licensee undertakes to mention the name oTree, the names of the licensors | ||
(Daniel L. Chen, Martin Schonger and Christopher Wickens) and to cite the | ||
following article in all publications in which results of experiments conducted | ||
with the Software are published: Chen, Daniel L., Martin Schonger, and Chris Wickens. | ||
2016. "oTree - An open-source platform for laboratory, online, and field experiments." | ||
Journal of Behavioral and Experimental Finance, vol 9: 88-97. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
web: otree prodserver1of2 | ||
worker: otree prodserver2of2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Alice | ||
Bob | ||
Charlie |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{ extends "otree/Page.html" }} | ||
{{ load otree }} | ||
|
||
{{ block global_styles }} | ||
{{ endblock }} | ||
{{ block global_scripts }} | ||
{{ endblock }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{ block title }}Introduction{{ endblock }} | ||
{{ block content }} | ||
{{ include_sibling 'instructions.html' }} | ||
{{ next_button }} | ||
{{ endblock }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{ block title }}Request{{ endblock }} | ||
{{ block content }} | ||
|
||
<p>How much will you demand for yourself?</p> | ||
|
||
{{ formfields }} | ||
|
||
<p>{{ next_button }}</p> | ||
|
||
{{ include_sibling 'instructions.html' }} | ||
|
||
{{ endblock }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{{ block title }}Results{{ endblock }} | ||
{{ block content }} | ||
<table class=table style="width: auto"> | ||
<tr> | ||
<th>You demanded</th> | ||
<td>{{ player.request }}</td> | ||
</tr> | ||
<tr> | ||
<th>The other participant demanded</th> | ||
<td>{{ other_player_request }}</td> | ||
</tr> | ||
<tr> | ||
<th>Sum of your demands</th> | ||
<td>{{ group.total_requests }}</td> | ||
</tr> | ||
<tr> | ||
<th>Thus you earn</th> | ||
<td>{{ player.payoff }}</td> | ||
</tr> | ||
</table> | ||
|
||
<p>{{ next_button }}</p> | ||
|
||
{{ include_sibling 'instructions.html' }} | ||
|
||
{{ endblock }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from otree.api import * | ||
|
||
|
||
|
||
|
||
doc = """ | ||
This bargaining game involves 2 players. Each demands for a portion of some | ||
available amount. If the sum of demands is no larger than the available | ||
amount, both players get demanded portions. Otherwise, both get nothing. | ||
""" | ||
|
||
|
||
class C(BaseConstants): | ||
NAME_IN_URL = 'bargaining' | ||
PLAYERS_PER_GROUP = 2 | ||
NUM_ROUNDS = 1 | ||
AMOUNT_SHARED = cu(100) | ||
|
||
|
||
class Subsession(BaseSubsession): | ||
pass | ||
|
||
|
||
class Group(BaseGroup): | ||
total_requests = models.CurrencyField() | ||
|
||
|
||
class Player(BasePlayer): | ||
request = models.CurrencyField( | ||
doc=""" | ||
Amount requested by this player. | ||
""", | ||
min=0, | ||
max=C.AMOUNT_SHARED, | ||
label="Please enter an amount from 0 to 100", | ||
) | ||
|
||
|
||
# FUNCTIONS | ||
def set_payoffs(group: Group): | ||
players = group.get_players() | ||
group.total_requests = sum([p.request for p in players]) | ||
if group.total_requests <= C.AMOUNT_SHARED: | ||
for p in players: | ||
p.payoff = p.request | ||
else: | ||
for p in players: | ||
p.payoff = cu(0) | ||
|
||
|
||
def other_player(player: Player): | ||
return player.get_others_in_group()[0] | ||
|
||
|
||
# PAGES | ||
class Introduction(Page): | ||
pass | ||
|
||
|
||
class Request(Page): | ||
form_model = 'player' | ||
form_fields = ['request'] | ||
|
||
|
||
class ResultsWaitPage(WaitPage): | ||
after_all_players_arrive = set_payoffs | ||
|
||
|
||
class Results(Page): | ||
@staticmethod | ||
def vars_for_template(player: Player): | ||
return dict(other_player_request=other_player(player).request) | ||
|
||
|
||
page_sequence = [Introduction, Request, ResultsWaitPage, Results] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
<div class="card bg-light m-3"> | ||
|
||
<div class="card-body"> | ||
<h3> | ||
Instructions | ||
</h3> | ||
|
||
<p> | ||
You have been randomly and anonymously paired with another participant. | ||
There is {{ C.AMOUNT_SHARED }} for you to divide. | ||
Both of you have to simultaneously and independently demand a portion | ||
of the {{ C.AMOUNT_SHARED }} for yourselves. If the sum of your | ||
demands is smaller or equal to {{ C.AMOUNT_SHARED }}, both of | ||
you get what you demanded. If the sum of your demands is larger | ||
than {{ C.AMOUNT_SHARED }}, | ||
both of you get nothing. | ||
</p> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ block title }}Set Your Price{{ endblock }} | ||
{{ block content }} | ||
|
||
{{ formfields }} | ||
|
||
|
||
<p>{{ next_button }}</p> | ||
|
||
{{ include_sibling 'instructions.html' }} | ||
|
||
{{ endblock }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{ block title }}Introduction{{ endblock }} | ||
{{ block content }} | ||
{{ include_sibling 'instructions.html' }} | ||
{{ next_button }} | ||
{{ endblock }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{{ block title }}Results{{ endblock }} | ||
{{ block content }} | ||
<table class="table"> | ||
<tr> | ||
<th>Your price</th> | ||
<td>{{ player.price }}</td> | ||
</tr> | ||
<tr> | ||
<th>Lowest price</th> | ||
<td>{{ group.winning_price }}</td> | ||
</tr> | ||
<tr> | ||
<th>Was your product sold?</th> | ||
<td>{{ if player.is_winner }} Yes {{ else }} No {{ endif }}</td> | ||
</tr> | ||
<tr> | ||
<th>Your payoff</th> | ||
<td>{{ player.payoff }}</td> | ||
</tr> | ||
</table> | ||
|
||
{{ next_button }} | ||
|
||
{{ include_sibling 'instructions.html' }} | ||
|
||
{{ endblock }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from otree.api import * | ||
|
||
|
||
|
||
doc = """ | ||
2 firms complete in a market by setting prices for homogenous goods. | ||
See "Kruse, J. B., Rassenti, S., Reynolds, S. S., & Smith, V. L. (1994). | ||
Bertrand-Edgeworth competition in experimental markets. | ||
Econometrica: Journal of the Econometric Society, 343-371." | ||
""" | ||
|
||
|
||
class C(BaseConstants): | ||
PLAYERS_PER_GROUP = 2 | ||
NAME_IN_URL = 'bertrand' | ||
NUM_ROUNDS = 1 | ||
MAXIMUM_PRICE = cu(100) | ||
|
||
|
||
class Subsession(BaseSubsession): | ||
pass | ||
|
||
|
||
class Group(BaseGroup): | ||
winning_price = models.CurrencyField() | ||
|
||
|
||
class Player(BasePlayer): | ||
price = models.CurrencyField( | ||
min=0, | ||
max=C.MAXIMUM_PRICE, | ||
doc="""Price player offers to sell product for""", | ||
label="Please enter an amount from 0 to 100 as your price", | ||
) | ||
is_winner = models.BooleanField() | ||
|
||
|
||
# FUNCTIONS | ||
def set_payoffs(group: Group): | ||
import random | ||
|
||
players = group.get_players() | ||
group.winning_price = min([p.price for p in players]) | ||
winners = [p for p in players if p.price == group.winning_price] | ||
winner = random.choice(winners) | ||
for p in players: | ||
if p == winner: | ||
p.is_winner = True | ||
p.payoff = p.price | ||
else: | ||
p.is_winner = False | ||
p.payoff = cu(0) | ||
|
||
|
||
# PAGES | ||
class Introduction(Page): | ||
pass | ||
|
||
|
||
class Decide(Page): | ||
form_model = 'player' | ||
form_fields = ['price'] | ||
|
||
|
||
class ResultsWaitPage(WaitPage): | ||
after_all_players_arrive = set_payoffs | ||
|
||
|
||
class Results(Page): | ||
pass | ||
|
||
|
||
page_sequence = [Introduction, Decide, ResultsWaitPage, Results] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
<div class="instructions well well-lg" style=""> | ||
|
||
<h3> | ||
Instructions | ||
</h3> | ||
<p> | ||
You have been randomly and anonymously paired with another participant. | ||
Each of you will represent a firm. Each firm manufactures one unit of | ||
the same product at no cost. | ||
</p> | ||
<p> | ||
Each of you privately sets your price, anything from 0 to {{ C.MAXIMUM_PRICE }}. | ||
The buyer in the market will always buy one unit of the product at the | ||
lower price. In case of a tie, the buyer will buy from one of you at | ||
random. Your profit is your price if your product is sold and zero | ||
otherwise. | ||
</p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{{ block title }}Bid{{ endblock }} | ||
{{ block content }} | ||
|
||
<p> | ||
The value of the item is estimated to be {{ player.item_value_estimate }}. | ||
This estimate may deviate from the actual value by at most {{ C.BID_NOISE }}. | ||
</p> | ||
|
||
<p> | ||
Please make your bid now. The amount can be between {{ C.BID_MIN }} and {{ C.BID_MAX }}, inclusive. | ||
</p> | ||
|
||
{{ formfields }} | ||
|
||
{{ next_button }} | ||
|
||
{{ include_sibling 'instructions.html' }} | ||
|
||
{{ endblock }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{ block title }}Introduction{{ endblock }} | ||
{{ block content }} | ||
|
||
{{ include_sibling 'instructions.html' }} | ||
|
||
{{ next_button }} | ||
|
||
{{ endblock }} |
Oops, something went wrong.