From 91e67321ce3e03f4f8452fccdf8f8244d4fb0b51 Mon Sep 17 00:00:00 2001 From: Mia Lu Date: Tue, 30 Apr 2024 10:14:04 +0200 Subject: [PATCH 1/2] Update group matrix creation with respect to the use of matching groups and only three players per group --- preparation/group_matrices/README.md | 13 +- .../create_group_matrices.ipynb | 236 ++++++++++++++++++ .../group_matrices/create_group_matrices.py | 50 ---- .../group_matrices/golfer_solution.csv | 7 + .../golfer_solution_6_groups.csv | 31 --- .../golfer_solution_7_groups.csv | 36 --- preparation/group_matrices/group_matrices.pkl | Bin 0 -> 640 bytes .../group_matrices_6_groups.pkl | Bin 544 -> 0 bytes .../group_matrices_7_groups.pkl | Bin 628 -> 0 bytes 9 files changed, 249 insertions(+), 124 deletions(-) create mode 100644 preparation/group_matrices/create_group_matrices.ipynb delete mode 100644 preparation/group_matrices/create_group_matrices.py create mode 100644 preparation/group_matrices/golfer_solution.csv delete mode 100644 preparation/group_matrices/golfer_solution_6_groups.csv delete mode 100644 preparation/group_matrices/golfer_solution_7_groups.csv create mode 100644 preparation/group_matrices/group_matrices.pkl delete mode 100644 preparation/group_matrices/group_matrices_6_groups.pkl delete mode 100644 preparation/group_matrices/group_matrices_7_groups.pkl diff --git a/preparation/group_matrices/README.md b/preparation/group_matrices/README.md index 3be50d4..414e8f5 100644 --- a/preparation/group_matrices/README.md +++ b/preparation/group_matrices/README.md @@ -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. diff --git a/preparation/group_matrices/create_group_matrices.ipynb b/preparation/group_matrices/create_group_matrices.ipynb new file mode 100644 index 0000000..345045a --- /dev/null +++ b/preparation/group_matrices/create_group_matrices.ipynb @@ -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 +} diff --git a/preparation/group_matrices/create_group_matrices.py b/preparation/group_matrices/create_group_matrices.py deleted file mode 100644 index 7a3fd39..0000000 --- a/preparation/group_matrices/create_group_matrices.py +++ /dev/null @@ -1,50 +0,0 @@ -import pickle -import warnings - -import pandas as pd - - -class Groups: - def __init__(self, num_players, num_groups): - self.was_first = [False] * num_players - self.num_groups = num_groups - self.results = [] - - def add_round(self, allocation): - is_trial_round = len(self.results) == 0 - self.results.append([[] for _ in range(self.num_groups)]) - for player, group in enumerate(allocation): - group_id = int(group.lstrip("Group ")) - 1 - if self.was_first[player]: - self.results[-1][group_id].append(player) - else: - self.results[-1][group_id].insert(0, player) - for group in range(len(self.results[-1])): - first_in_group = self.results[-1][group][0] - if self.was_first[self.results[-1][group][0]]: - warnings.warn(f"Player {first_in_group} was first multiple times") - self.was_first[first_in_group] = True if not is_trial_round else False - - def adjust_indices(self): - for round in range(len(self.results)): - for group in range(len(self.results[round])): - for player in range(len(self.results[round][group])): - self.results[round][group][player] = ( - self.results[round][group][player] + 1 - ) - - -for num_groups in [6, 7]: - golfers = pd.read_csv( - "golfer_solution_" + str(num_groups) + "_groups.csv", index_col=0 - ) - golfers.index = [int(name.lstrip("Player ")) - 1 for name in golfers.index] - golfers.columns = [int(name.lstrip("Round ")) - 1 for name in golfers.columns] - - groups = Groups(len(golfers), num_groups) - for round in golfers.columns: - groups.add_round(golfers.loc[:, round]) - groups.adjust_indices() - - with open("group_matrices_" + str(num_groups) + "_groups.pkl", "wb") as f: - pickle.dump(groups.results, f) diff --git a/preparation/group_matrices/golfer_solution.csv b/preparation/group_matrices/golfer_solution.csv new file mode 100644 index 0000000..604d633 --- /dev/null +++ b/preparation/group_matrices/golfer_solution.csv @@ -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 \ No newline at end of file diff --git a/preparation/group_matrices/golfer_solution_6_groups.csv b/preparation/group_matrices/golfer_solution_6_groups.csv deleted file mode 100644 index ffbf9c5..0000000 --- a/preparation/group_matrices/golfer_solution_6_groups.csv +++ /dev/null @@ -1,31 +0,0 @@ -,Round 1,Round 2,Round 3,Round 4,Round 5,Round 6 -Player 1,Group 3,Group 2,Group 6,Group 6,Group 1,Group 3 -Player 2,Group 3,Group 5,Group 2,Group 3,Group 4,Group 1 -Player 3,Group 6,Group 3,Group 2,Group 6,Group 3,Group 1 -Player 4,Group 4,Group 4,Group 6,Group 1,Group 4,Group 3 -Player 5,Group 2,Group 6,Group 6,Group 5,Group 2,Group 1 -Player 6,Group 4,Group 2,Group 2,Group 2,Group 2,Group 6 -Player 7,Group 1,Group 5,Group 4,Group 5,Group 3,Group 3 -Player 8,Group 1,Group 4,Group 3,Group 3,Group 6,Group 2 -Player 9,Group 3,Group 4,Group 5,Group 4,Group 2,Group 5 -Player 10,Group 1,Group 3,Group 1,Group 2,Group 4,Group 4 -Player 11,Group 4,Group 1,Group 3,Group 5,Group 5,Group 1 -Player 12,Group 5,Group 3,Group 3,Group 1,Group 2,Group 2 -Player 13,Group 1,Group 1,Group 5,Group 6,Group 4,Group 6 -Player 14,Group 6,Group 1,Group 6,Group 3,Group 2,Group 4 -Player 15,Group 4,Group 5,Group 1,Group 6,Group 6,Group 5 -Player 16,Group 4,Group 6,Group 4,Group 4,Group 1,Group 2 -Player 17,Group 3,Group 3,Group 4,Group 1,Group 6,Group 6 -Player 18,Group 6,Group 4,Group 1,Group 5,Group 1,Group 6 -Player 19,Group 2,Group 4,Group 4,Group 6,Group 5,Group 4 -Player 20,Group 3,Group 6,Group 3,Group 2,Group 3,Group 4 -Player 21,Group 2,Group 1,Group 2,Group 4,Group 6,Group 3 -Player 22,Group 5,Group 5,Group 6,Group 4,Group 3,Group 6 -Player 23,Group 6,Group 5,Group 5,Group 2,Group 5,Group 2 -Player 24,Group 5,Group 6,Group 1,Group 3,Group 5,Group 3 -Player 25,Group 5,Group 2,Group 5,Group 5,Group 6,Group 4 -Player 26,Group 2,Group 3,Group 5,Group 3,Group 1,Group 5 -Player 27,Group 6,Group 2,Group 3,Group 4,Group 4,Group 5 -Player 28,Group 5,Group 1,Group 4,Group 2,Group 1,Group 1 -Player 29,Group 1,Group 6,Group 2,Group 1,Group 5,Group 5 -Player 30,Group 2,Group 2,Group 1,Group 1,Group 3,Group 2 \ No newline at end of file diff --git a/preparation/group_matrices/golfer_solution_7_groups.csv b/preparation/group_matrices/golfer_solution_7_groups.csv deleted file mode 100644 index 840a4eb..0000000 --- a/preparation/group_matrices/golfer_solution_7_groups.csv +++ /dev/null @@ -1,36 +0,0 @@ -,Round 1,Round 2,Round 3,Round 4,Round 5,Round 6 -Player 1,Group 3,Group 4,Group 7,Group 2,Group 1,Group 7 -Player 2,Group 4,Group 6,Group 4,Group 6,Group 2,Group 1 -Player 3,Group 2,Group 6,Group 7,Group 7,Group 3,Group 4 -Player 4,Group 7,Group 2,Group 1,Group 7,Group 2,Group 7 -Player 5,Group 1,Group 2,Group 7,Group 6,Group 6,Group 3 -Player 6,Group 4,Group 7,Group 7,Group 5,Group 5,Group 4 -Player 7,Group 6,Group 4,Group 2,Group 1,Group 6,Group 3 -Player 8,Group 7,Group 4,Group 5,Group 6,Group 3,Group 6 -Player 9,Group 3,Group 5,Group 3,Group 1,Group 2,Group 4 -Player 10,Group 2,Group 5,Group 1,Group 2,Group 5,Group 5 -Player 11,Group 6,Group 1,Group 3,Group 6,Group 5,Group 7 -Player 12,Group 5,Group 1,Group 1,Group 1,Group 3,Group 1 -Player 13,Group 7,Group 1,Group 6,Group 2,Group 7,Group 4 -Player 14,Group 1,Group 1,Group 4,Group 7,Group 4,Group 5 -Player 15,Group 1,Group 7,Group 2,Group 4,Group 3,Group 7 -Player 16,Group 3,Group 3,Group 2,Group 6,Group 7,Group 5 -Player 17,Group 3,Group 7,Group 6,Group 3,Group 4,Group 3 -Player 18,Group 5,Group 3,Group 3,Group 2,Group 4,Group 6 -Player 19,Group 1,Group 4,Group 1,Group 5,Group 2,Group 2 -Player 20,Group 5,Group 2,Group 2,Group 3,Group 1,Group 4 -Player 21,Group 6,Group 6,Group 5,Group 5,Group 1,Group 5 -Player 22,Group 6,Group 2,Group 4,Group 2,Group 3,Group 2 -Player 23,Group 2,Group 3,Group 6,Group 5,Group 6,Group 1 -Player 24,Group 7,Group 3,Group 4,Group 4,Group 1,Group 3 -Player 25,Group 1,Group 6,Group 3,Group 3,Group 5,Group 2 -Player 26,Group 4,Group 5,Group 6,Group 7,Group 1,Group 6 -Player 27,Group 4,Group 2,Group 3,Group 4,Group 7,Group 5 -Player 28,Group 2,Group 7,Group 4,Group 1,Group 7,Group 6 -Player 29,Group 4,Group 3,Group 5,Group 1,Group 4,Group 7 -Player 30,Group 3,Group 6,Group 1,Group 4,Group 6,Group 6 -Player 31,Group 5,Group 4,Group 6,Group 4,Group 5,Group 1 -Player 32,Group 6,Group 5,Group 7,Group 3,Group 7,Group 1 -Player 33,Group 7,Group 5,Group 2,Group 5,Group 4,Group 2 -Player 34,Group 5,Group 7,Group 5,Group 7,Group 6,Group 2 -Player 35,Group 2,Group 1,Group 5,Group 3,Group 2,Group 3 \ No newline at end of file diff --git a/preparation/group_matrices/group_matrices.pkl b/preparation/group_matrices/group_matrices.pkl new file mode 100644 index 0000000000000000000000000000000000000000..0937d7b1322c47911bd21433751072edf5336e65 GIT binary patch literal 640 zcmYk3OLBt%3_}ZnK=_4UfF!^=t6oHB=#nFJ-$S(bt&lym3=835{N~AD(a&f2rsw1P zWiMi!5N!Ow84*II92X=?1u~>c4X!AaTGXhNM%>UTO&HKCEqLOtv|`3%+oNrdofDC0 zoC3LXG7^o`qH#`5qH!jS&KXEF&Wgo3Gl_qk-6s-1M1Zr>?vp8{NKh#4KDAPX60Oqi zGbr`wFe&Xmv(f{1tcOp;=4?CrbDxYpww?XCPfZ`&&i>qIppR{5f9^BWXBCJ2{qqUw zW1N8ZiS(iym2ex_qXmel>iDzk~l~zptMU_t&9! zJ(McBc%W0O26c)o^=g#KmuIO~rChN>OS=}$8dX@@G^tgo;JV{Y+ToP2b2~q^F&{rk zE8K$Cz|J~uW*9i`1hY~i-_8y?de!*+b7!V2?w)o&zzi@vEN#pdIHr~w?j`K9TUv0* zuv{&TxJ3%_x#R6ykQ&~G2cf~^NCKkS<220t;>rW+1~k+o5HM_cO>@0Y0zvf4|eV7 UafTVBm9OErF}@9c<8@u1f9RTlD*ylh diff --git a/preparation/group_matrices/group_matrices_7_groups.pkl b/preparation/group_matrices/group_matrices_7_groups.pkl deleted file mode 100644 index 8c94671fc9ee869a78e3df90571c8b27d249a1a8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 628 zcmX|;OLl@#5JaOOUlkC60D^#%jIxnhLxv2pi!379Z?643c$gI3RNZQS{J-!0oBh6i zKis2Mr81p$Sb3p`ZfcasGc~GEu2?%$gL-uev^TZruB$FOnwnIrQmW9@taqIh$zPw+ z`JQ=mRBH2{?W+#VpRV&;3kcD@;3dUUOAcA-ZBzw=FD z31D#aAqfoxi*25`NDuk6rR;HO_$Mcum)xY){MtUyvVg#41|-Hbz1n6%W)7dbX2cCT QeBIrB?dX Date: Tue, 30 Apr 2024 11:10:20 +0200 Subject: [PATCH 2/2] Use new group matrices in __init__.py --- live_bargaining/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/live_bargaining/__init__.py b/live_bargaining/__init__.py index b22e70b..ee6160c 100644 --- a/live_bargaining/__init__.py +++ b/live_bargaining/__init__.py @@ -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)