Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real effort task #67

Merged
merged 15 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
rev: v0.2.1
hooks:
- id: ruff
args: [ --fix ]
args: [ --fix, --select, I ]
- id: ruff-format

- repo: https://github.com/codespell-project/codespell
Expand Down
2 changes: 1 addition & 1 deletion introduction/Payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h4> Payment at the end of the experiment </h4>
<hr>

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

{{ next_button }}

Expand Down
12 changes: 10 additions & 2 deletions introduction/Proposal.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@
<h4> Group budgets </h4>

<p>
You and the two other players will each be randomly assigned a player role ({{P1}}, {{P2}}, {{P3}}).
<b> The player roles will be reassigned each round. </b>
The assignment of player roles works as follows: After these instructions, you will work on a task (moving sliders).
In each round, you and the respective two other players will each be randomly assigned a player role ({{P1}}, {{P2}}, {{P3}}).

{{ if not last_player_is_dummy }}
<b> The better you performed on the task, the higher the probability that you will be assigned player role {{P1}}.</b>
{{ else }}
<b> The better you performed on the task, the higher the probability that you will be assigned player role {{P1}} or {{P2}}. </b>
{{ endif}}

<b> The player roles will be reassigned each round. </b>
</p>
{{ if not last_player_is_dummy }}
<p>
Expand Down
1 change: 1 addition & 0 deletions introduction/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from otree.api import Bot, Submission

from . import Coalitions, Instructions, Payment, Proposal, Welcome


Expand Down
28 changes: 28 additions & 0 deletions live_bargaining/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pickle
import time
from datetime import datetime
from random import choices

from otree.api import (
BaseConstants,
Expand Down Expand Up @@ -272,12 +273,38 @@ def create_acceptance_data(group: Group):
}


class WaitForRoles(WaitPage):
@staticmethod
def after_all_players_arrive(group: Group):
last_player_is_dummy = (
len(group.session.config["prod_fct"]) == C.PLAYERS_PER_GROUP - 1
)
scores = {
player.id_in_group: player.participant.task_score
for player in group.get_players()
}
sorted_ids = [id for id, _ in sorted(scores.items(), key=lambda x: x[1])]

# assign player roles
if (
last_player_is_dummy
): # the lower the score, the higher the probability of being the dummy player
dummy_id = choices(sorted_ids, weights=[5, 3, 2])
new_group_ids = [id for id in scores.keys() if id != dummy_id[0]] + dummy_id
else: # the higher the score, the higher the probability of being the big player
p1_id = choices(sorted_ids, weights=[2, 3, 5])
new_group_ids = p1_id + [id for id in scores.keys() if id != p1_id[0]]
new_group = [group.get_player_by_id(id) for id in new_group_ids]
group.set_players(new_group) # type: ignore


class Info(Page):
@staticmethod
def vars_for_template(player: Player):
return dict(
actual_round_number=player.subsession.round_number - 1,
player_name=player.session.config["player_names"][f"P{player.id_in_group}"],
player_score=player.participant.task_score,
)


Expand Down Expand Up @@ -514,6 +541,7 @@ def custom_export(players):


page_sequence = [
WaitForRoles,
Info,
WaitForBargaining,
Bargain,
Expand Down
6 changes: 4 additions & 2 deletions live_bargaining/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from otree.api import Currency as c, expect, Bot, Submission
from . import Info, Bargain, BargainingResults
from otree.api import Bot, Submission, expect
from otree.api import Currency as c

from . import Bargain, BargainingResults, Info


def create_offers(method, Y):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ otree~=5.10.3
psycopg2~=2.9.9
requests~=2.31.0
country_list~=1.1.0
Pillow~=8.0
16 changes: 7 additions & 9 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
dict(
name="treatment_y_10",
display_name="Treatment: Y=10",
app_sequence=["introduction", "live_bargaining", "survey"],
app_sequence=["introduction", "sliders", "live_bargaining", "survey"],
num_demo_participants=3,
seconds_per_round=5 * 60,
prod_fct={
Expand All @@ -33,7 +33,7 @@
dict(
name="treatment_y_30",
display_name="Treatment: Y=30",
app_sequence=["introduction", "live_bargaining", "survey"],
app_sequence=["introduction", "sliders", "live_bargaining", "survey"],
num_demo_participants=3,
seconds_per_round=5 * 60,
prod_fct={
Expand All @@ -51,7 +51,7 @@
dict(
name="treatment_y_90",
display_name="Treatment: Y=90",
app_sequence=["introduction", "live_bargaining", "survey"],
app_sequence=["introduction", "sliders", "live_bargaining", "survey"],
num_demo_participants=3,
seconds_per_round=5 * 60,
prod_fct={
Expand All @@ -69,7 +69,7 @@
dict(
name="treatment_dummy_player",
display_name="Treatment: Dummy Player",
app_sequence=["introduction", "live_bargaining", "survey"],
app_sequence=["introduction", "sliders", "live_bargaining", "survey"],
num_demo_participants=3,
seconds_per_round=5 * 60,
prod_fct={
Expand All @@ -95,11 +95,9 @@
real_world_currency_per_point=1.00, participation_fee=10.00, doc=""
)

PARTICIPANT_FIELDS = [
"final_payoff",
"payoff_list",
]
SESSION_FIELDS = []
PARTICIPANT_FIELDS = ["final_payoff", "payoff_list", "task_score"]

SESSION_FIELDS = ["params"]

# ISO-639 code
# for example: de, fr, ja, ko, zh-hans
Expand Down
33 changes: 33 additions & 0 deletions sliders/Game.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% block styles %}
<link href="{% static 'sliders.css' %}" rel="stylesheet"/>
{% endblock %}

{{ block title }}
Task
{{ endblock }}

{{ block content }}

<p> Move the slider into the position indicated by the red dot.
Once the slider is in the correct position, it will turn green.
{{ if not last_player_is_dummy }}
Recall: The more sliders you put in the correct position, the higher the probability that you will be assigned player role {{P1}}.
{{ else }}
Recall: The more sliders you put in the correct position, the higher the probability that you will be assigned player role {{P1}} or {{P2}}.
{{ endif }}
You have 4 minutes in total.
</p>


<div class="d-flex flex-column align-items-center">

<canvas id="canvas" class="m-2"></canvas>

</div>

{{ endblock }}

{{ block scripts }}
<script src="{{ static 'sliders.js' }}"></script>

{{ endblock }}
11 changes: 11 additions & 0 deletions sliders/Results.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ block title }}
Results
{{ endblock }}

{{ block content }}

<p> Thank you for working on the task. Please now proceed to the <b> trial round</b>. </p>

{{ next_button }}

{{ endblock }}
Loading
Loading