Skip to content

Commit

Permalink
Merge pull request #66 from stanmart/update_golfers
Browse files Browse the repository at this point in the history
Update group matrix creation
  • Loading branch information
stanmart authored Apr 30, 2024
2 parents 355b468 + b375395 commit 23bb445
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 128 deletions.
6 changes: 2 additions & 4 deletions live_bargaining/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@

def creating_session(subsession):
num_active_groups = len(subsession.get_groups())
if num_active_groups in [6, 7]:
if num_active_groups == 10:
subsession_index = subsession.round_number - 1
with open(
"preparation/group_matrices/group_matrices_"
+ str(num_active_groups)
+ "_groups.pkl",
"preparation/group_matrices/group_matrices.pkl",
"rb",
) as file:
group_matrices = pickle.load(file)
Expand Down
13 changes: 6 additions & 7 deletions preparation/group_matrices/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Create group matrices for reshuffling

Make sure that

- no players are in the same group more than once (as much as possible)
- everyone gets a chance at being the first player (as much as possible)
Make sure that
- players within the same matching group have as little overlap with other players across rounds as possible
- everyone gets a chance at being the first player (as much as possible)(in the current setting, everyone is the first player twice)

## How it works

- The initial group allocation is from [goodenoughgolfers.com/](https://goodenoughgolfers.com/). The output from the website is `golfer_solution.csv`
- The script `create_group_matrices.py` reshuffles the players within groups so that everyone gets a chance at being the first player. It's output is a list(rounds) of lists (groups) of integers (player ids): `group_matrices.pkl`
- The group matrices are considered to be fixed, and are therefore committed to the repo. This readme file and Python script is only here for documentation purposes.
- The initial group allocation for one sample matching group is from [goodenoughgolfers.com/](https://goodenoughgolfers.com/ with 2 groups, 3 people per group and 6 number of rounds). The output from the website is `golfer_solution.csv`
- The jupyter notebook `create_group_matrices.ipynb` creates the group matrices for all matching groups within a session. It also reshuffles the players within groups so that everyone gets an equal chance at being the first player. Its output is a list(rounds) of lists (groups) of integers(player ids): `group_matrices.pkl`
- The group matrices are considered to be fixed, and are therefore committed to the repo. This readme file and notebook are only here for documentation purposes.
236 changes: 236 additions & 0 deletions preparation/group_matrices/create_group_matrices.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [],
"source": [
"import pickle\n",
"import warnings\n",
"import copy\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [],
"source": [
"num_groups = 2 # number of groups per matching group\n",
"num_match_grp = 5\n",
"num_rounds = 6"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
"class Groups:\n",
" def __init__(self, num_players, num_groups):\n",
" self.was_first = [False] * num_players\n",
" self.num_groups = num_groups\n",
" self.results = []\n",
"\n",
" def add_round(self, allocation):\n",
" is_trial_round = len(self.results) == 0\n",
" self.results.append([[] for _ in range(self.num_groups)])\n",
" for player, group in enumerate(allocation):\n",
" group_id = int(group.lstrip(\"Group \")) - 1\n",
" if self.was_first[player]:\n",
" self.results[-1][group_id].append(player)\n",
" else:\n",
" self.results[-1][group_id].insert(0, player)\n",
" for group in range(len(self.results[-1])):\n",
" first_in_group = self.results[-1][group][0]\n",
" if self.was_first[self.results[-1][group][0]]:\n",
" warnings.warn(f\"Player {first_in_group} was first multiple times\")\n",
" self.was_first[first_in_group] = True if not is_trial_round else False\n",
"\n",
" def adjust_indices(self):\n",
" for round in range(len(self.results)):\n",
" for group in range(len(self.results[round])):\n",
" for player in range(len(self.results[round][group])):\n",
" self.results[round][group][player] = (\n",
" self.results[round][group][player] + 1\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/ml/b6fb3hq91m70wjn5hjgyky58kdcssc/T/ipykernel_89633/62703243.py:19: UserWarning: Player 3 was first multiple times\n",
" warnings.warn(f\"Player {first_in_group} was first multiple times\")\n",
"/var/folders/ml/b6fb3hq91m70wjn5hjgyky58kdcssc/T/ipykernel_89633/62703243.py:19: UserWarning: Player 1 was first multiple times\n",
" warnings.warn(f\"Player {first_in_group} was first multiple times\")\n",
"/var/folders/ml/b6fb3hq91m70wjn5hjgyky58kdcssc/T/ipykernel_89633/62703243.py:19: UserWarning: Player 0 was first multiple times\n",
" warnings.warn(f\"Player {first_in_group} was first multiple times\")\n",
"/var/folders/ml/b6fb3hq91m70wjn5hjgyky58kdcssc/T/ipykernel_89633/62703243.py:19: UserWarning: Player 2 was first multiple times\n",
" warnings.warn(f\"Player {first_in_group} was first multiple times\")\n"
]
}
],
"source": [
"golfers = pd.read_csv(\n",
" \"golfer_solution.csv\", index_col=0\n",
")\n",
"golfers.index = [int(name.lstrip(\"Player \")) - 1 for name in golfers.index]\n",
"golfers.columns = [int(name.lstrip(\"Round \")) - 1 for name in golfers.columns]\n",
"\n",
"groups = Groups(len(golfers), num_groups)\n",
"for round in golfers.columns:\n",
" groups.add_round(golfers.loc[:, round])\n",
"groups.adjust_indices()"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[[5, 3, 1], [6, 4, 2]],\n",
" [[6, 5, 1], [4, 3, 2]],\n",
" [[5, 3, 4], [2, 1, 6]],\n",
" [[4, 5, 6], [3, 1, 2]],\n",
" [[2, 3, 6], [1, 4, 5]],\n",
" [[1, 2, 4], [3, 5, 6]]]"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"groups.results"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[[5, 3, 1],\n",
" [6, 4, 2],\n",
" [11, 9, 7],\n",
" [12, 10, 8],\n",
" [17, 15, 13],\n",
" [18, 16, 14],\n",
" [23, 21, 19],\n",
" [24, 22, 20],\n",
" [29, 27, 25],\n",
" [30, 28, 26]],\n",
" [[6, 5, 1],\n",
" [4, 3, 2],\n",
" [12, 11, 7],\n",
" [10, 9, 8],\n",
" [18, 17, 13],\n",
" [16, 15, 14],\n",
" [24, 23, 19],\n",
" [22, 21, 20],\n",
" [30, 29, 25],\n",
" [28, 27, 26]],\n",
" [[5, 3, 4],\n",
" [2, 1, 6],\n",
" [11, 9, 10],\n",
" [8, 7, 12],\n",
" [17, 15, 16],\n",
" [14, 13, 18],\n",
" [23, 21, 22],\n",
" [20, 19, 24],\n",
" [29, 27, 28],\n",
" [26, 25, 30]],\n",
" [[4, 5, 6],\n",
" [3, 1, 2],\n",
" [10, 11, 12],\n",
" [9, 7, 8],\n",
" [16, 17, 18],\n",
" [15, 13, 14],\n",
" [22, 23, 24],\n",
" [21, 19, 20],\n",
" [28, 29, 30],\n",
" [27, 25, 26]],\n",
" [[2, 3, 6],\n",
" [1, 4, 5],\n",
" [8, 9, 12],\n",
" [7, 10, 11],\n",
" [14, 15, 18],\n",
" [13, 16, 17],\n",
" [20, 21, 24],\n",
" [19, 22, 23],\n",
" [26, 27, 30],\n",
" [25, 28, 29]],\n",
" [[1, 2, 4],\n",
" [3, 5, 6],\n",
" [7, 8, 10],\n",
" [9, 11, 12],\n",
" [13, 14, 16],\n",
" [15, 17, 18],\n",
" [19, 20, 22],\n",
" [21, 23, 24],\n",
" [25, 26, 28],\n",
" [27, 29, 30]]]"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"group_matrices = copy.deepcopy(groups.results)\n",
"for round_num in range(0, num_rounds): \n",
" for match_grp_num in range(1, num_match_grp):\n",
" for i in range(num_groups): \n",
" group_matrices[round_num].append([pl_num + 6 * match_grp_num for pl_num in groups.results[round_num][i]])\n",
"group_matrices"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [],
"source": [
"with open(\"group_matrices.pkl\", \"wb\") as f:\n",
" pickle.dump(group_matrices, f)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
50 changes: 0 additions & 50 deletions preparation/group_matrices/create_group_matrices.py

This file was deleted.

7 changes: 7 additions & 0 deletions preparation/group_matrices/golfer_solution.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
,Round 1,Round 2,Round 3,Round 4,Round 5,Round 6
Player 1,Group 1,Group 1,Group 2,Group 2,Group 2,Group 1
Player 2,Group 2,Group 2,Group 2,Group 2,Group 1,Group 1
Player 3,Group 1,Group 2,Group 1,Group 2,Group 1,Group 2
Player 4,Group 2,Group 2,Group 1,Group 1,Group 2,Group 1
Player 5,Group 1,Group 1,Group 1,Group 1,Group 2,Group 2
Player 6,Group 2,Group 1,Group 2,Group 1,Group 1,Group 2
31 changes: 0 additions & 31 deletions preparation/group_matrices/golfer_solution_6_groups.csv

This file was deleted.

Loading

0 comments on commit 23bb445

Please sign in to comment.