Skip to content

Commit d2ea6f5

Browse files
authored
Merge pull request #67 from stanmart/real_effort_task
Real effort task
2 parents 23bb445 + 3a9a218 commit d2ea6f5

19 files changed

+1127
-16
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repos:
44
rev: v0.2.1
55
hooks:
66
- id: ruff
7-
args: [ --fix ]
7+
args: [ --fix, --select, I ]
88
- id: ruff-format
99

1010
- repo: https://github.com/codespell-project/codespell

introduction/Payment.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h4> Payment at the end of the experiment </h4>
1313
<hr>
1414

1515
<p> If you have any questions, please raise your hand now and an experimenter will come to you. </p>
16-
<p> Otherwise, please proceed to the <b> trial round</b>. </p>
16+
<p> Otherwise, please proceed to the <b> task </b>. </p>
1717

1818
{{ next_button }}
1919

introduction/Proposal.html

+10-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@
1414
<h4> Group budgets </h4>
1515

1616
<p>
17-
You and the two other players will each be randomly assigned a player role ({{P1}}, {{P2}}, {{P3}}).
18-
<b> The player roles will be reassigned each round. </b>
17+
The assignment of player roles works as follows: After these instructions, you will work on a task (moving sliders).
18+
In each round, you and the respective two other players will each be randomly assigned a player role ({{P1}}, {{P2}}, {{P3}}).
19+
20+
{{ if not last_player_is_dummy }}
21+
<b> The better you performed on the task, the higher the probability that you will be assigned player role {{P1}}.</b>
22+
{{ else }}
23+
<b> The better you performed on the task, the higher the probability that you will be assigned player role {{P1}} or {{P2}}. </b>
24+
{{ endif}}
25+
26+
<b> The player roles will be reassigned each round. </b>
1927
</p>
2028
{{ if not last_player_is_dummy }}
2129
<p>

introduction/tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from otree.api import Bot, Submission
2+
23
from . import Coalitions, Instructions, Payment, Proposal, Welcome
34

45

live_bargaining/__init__.py

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pickle
22
import time
33
from datetime import datetime
4+
from random import choices
45

56
from otree.api import (
67
BaseConstants,
@@ -272,12 +273,38 @@ def create_acceptance_data(group: Group):
272273
}
273274

274275

276+
class WaitForRoles(WaitPage):
277+
@staticmethod
278+
def after_all_players_arrive(group: Group):
279+
last_player_is_dummy = (
280+
len(group.session.config["prod_fct"]) == C.PLAYERS_PER_GROUP - 1
281+
)
282+
scores = {
283+
player.id_in_group: player.participant.task_score
284+
for player in group.get_players()
285+
}
286+
sorted_ids = [id for id, _ in sorted(scores.items(), key=lambda x: x[1])]
287+
288+
# assign player roles
289+
if (
290+
last_player_is_dummy
291+
): # the lower the score, the higher the probability of being the dummy player
292+
dummy_id = choices(sorted_ids, weights=[5, 3, 2])
293+
new_group_ids = [id for id in scores.keys() if id != dummy_id[0]] + dummy_id
294+
else: # the higher the score, the higher the probability of being the big player
295+
p1_id = choices(sorted_ids, weights=[2, 3, 5])
296+
new_group_ids = p1_id + [id for id in scores.keys() if id != p1_id[0]]
297+
new_group = [group.get_player_by_id(id) for id in new_group_ids]
298+
group.set_players(new_group) # type: ignore
299+
300+
275301
class Info(Page):
276302
@staticmethod
277303
def vars_for_template(player: Player):
278304
return dict(
279305
actual_round_number=player.subsession.round_number - 1,
280306
player_name=player.session.config["player_names"][f"P{player.id_in_group}"],
307+
player_score=player.participant.task_score,
281308
)
282309

283310

@@ -514,6 +541,7 @@ def custom_export(players):
514541

515542

516543
page_sequence = [
544+
WaitForRoles,
517545
Info,
518546
WaitForBargaining,
519547
Bargain,

live_bargaining/tests.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from otree.api import Currency as c, expect, Bot, Submission
2-
from . import Info, Bargain, BargainingResults
1+
from otree.api import Bot, Submission, expect
2+
from otree.api import Currency as c
3+
4+
from . import Bargain, BargainingResults, Info
35

46

57
def create_offers(method, Y):

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ otree~=5.10.3
22
psycopg2~=2.9.9
33
requests~=2.31.0
44
country_list~=1.1.0
5+
Pillow~=8.0

settings.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
dict(
1616
name="treatment_y_10",
1717
display_name="Treatment: Y=10",
18-
app_sequence=["introduction", "live_bargaining", "survey"],
18+
app_sequence=["introduction", "sliders", "live_bargaining", "survey"],
1919
num_demo_participants=3,
2020
seconds_per_round=5 * 60,
2121
prod_fct={
@@ -33,7 +33,7 @@
3333
dict(
3434
name="treatment_y_30",
3535
display_name="Treatment: Y=30",
36-
app_sequence=["introduction", "live_bargaining", "survey"],
36+
app_sequence=["introduction", "sliders", "live_bargaining", "survey"],
3737
num_demo_participants=3,
3838
seconds_per_round=5 * 60,
3939
prod_fct={
@@ -51,7 +51,7 @@
5151
dict(
5252
name="treatment_y_90",
5353
display_name="Treatment: Y=90",
54-
app_sequence=["introduction", "live_bargaining", "survey"],
54+
app_sequence=["introduction", "sliders", "live_bargaining", "survey"],
5555
num_demo_participants=3,
5656
seconds_per_round=5 * 60,
5757
prod_fct={
@@ -69,7 +69,7 @@
6969
dict(
7070
name="treatment_dummy_player",
7171
display_name="Treatment: Dummy Player",
72-
app_sequence=["introduction", "live_bargaining", "survey"],
72+
app_sequence=["introduction", "sliders", "live_bargaining", "survey"],
7373
num_demo_participants=3,
7474
seconds_per_round=5 * 60,
7575
prod_fct={
@@ -95,11 +95,9 @@
9595
real_world_currency_per_point=1.00, participation_fee=10.00, doc=""
9696
)
9797

98-
PARTICIPANT_FIELDS = [
99-
"final_payoff",
100-
"payoff_list",
101-
]
102-
SESSION_FIELDS = []
98+
PARTICIPANT_FIELDS = ["final_payoff", "payoff_list", "task_score"]
99+
100+
SESSION_FIELDS = ["params"]
103101

104102
# ISO-639 code
105103
# for example: de, fr, ja, ko, zh-hans

sliders/Game.html

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{% block styles %}
2+
<link href="{% static 'sliders.css' %}" rel="stylesheet"/>
3+
{% endblock %}
4+
5+
{{ block title }}
6+
Task
7+
{{ endblock }}
8+
9+
{{ block content }}
10+
11+
<p> Move the slider into the position indicated by the red dot.
12+
Once the slider is in the correct position, it will turn green.
13+
{{ if not last_player_is_dummy }}
14+
Recall: The more sliders you put in the correct position, the higher the probability that you will be assigned player role {{P1}}.
15+
{{ else }}
16+
Recall: The more sliders you put in the correct position, the higher the probability that you will be assigned player role {{P1}} or {{P2}}.
17+
{{ endif }}
18+
You have 4 minutes in total.
19+
</p>
20+
21+
22+
<div class="d-flex flex-column align-items-center">
23+
24+
<canvas id="canvas" class="m-2"></canvas>
25+
26+
</div>
27+
28+
{{ endblock }}
29+
30+
{{ block scripts }}
31+
<script src="{{ static 'sliders.js' }}"></script>
32+
33+
{{ endblock }}

sliders/Results.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{ block title }}
2+
Results
3+
{{ endblock }}
4+
5+
{{ block content }}
6+
7+
<p> Thank you for working on the task. Please now proceed to the <b> trial round</b>. </p>
8+
9+
{{ next_button }}
10+
11+
{{ endblock }}

0 commit comments

Comments
 (0)