Jon Solow
commited on
Commit
·
83e66a7
1
Parent(s):
0c9041a
Fix parsing of roster queries
Browse files- src/data_storage.py +30 -7
- src/pages/11_Scoreboard.py +4 -1
src/data_storage.py
CHANGED
@@ -10,12 +10,26 @@ TOKENS_TABLE = "npcs_tokens"
|
|
10 |
|
11 |
|
12 |
def update_selection(user_id: str | int, position_id: str, player_id: str):
|
13 |
-
(
|
14 |
supabase_client.table(USER_ROSTERS_TABLE)
|
15 |
-
.
|
16 |
.match({"user_id": user_id, "position_id": position_id})
|
17 |
.execute()
|
|
|
18 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
|
21 |
def get_user_team(user_id):
|
@@ -86,13 +100,19 @@ def get_all_users(columns_included: list[str] = ["user_id", "name", "email"]):
|
|
86 |
return all_users
|
87 |
|
88 |
|
89 |
-
def get_all_rosters() -> list[
|
90 |
-
all_rosters = supabase_client.table(USER_ROSTERS_TABLE).select("
|
91 |
return all_rosters
|
92 |
|
93 |
|
94 |
-
def get_all_rosters_week(week: int) -> list[
|
95 |
-
week_rosters =
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
return week_rosters
|
97 |
|
98 |
|
@@ -101,6 +121,9 @@ def migrate_players_from_week(migrate_from_week: int):
|
|
101 |
Migrate players from the week = migrate_from_week to the week = migrate_from_week + 1
|
102 |
"""
|
103 |
rosters = get_all_rosters_week(migrate_from_week)
|
104 |
-
for
|
|
|
|
|
|
|
105 |
new_position_id = f"""{migrate_from_week + 1}-{position_id.split("-", 1)[1]}"""
|
106 |
update_selection(user_id, new_position_id, player_id)
|
|
|
10 |
|
11 |
|
12 |
def update_selection(user_id: str | int, position_id: str, player_id: str):
|
13 |
+
existing_record = (
|
14 |
supabase_client.table(USER_ROSTERS_TABLE)
|
15 |
+
.select("*")
|
16 |
.match({"user_id": user_id, "position_id": position_id})
|
17 |
.execute()
|
18 |
+
.data
|
19 |
)
|
20 |
+
if existing_record:
|
21 |
+
(
|
22 |
+
supabase_client.table(USER_ROSTERS_TABLE)
|
23 |
+
.update({"user_id": user_id, "position_id": position_id, "player_id": player_id})
|
24 |
+
.match({"user_id": user_id, "position_id": position_id})
|
25 |
+
.execute()
|
26 |
+
)
|
27 |
+
else:
|
28 |
+
(
|
29 |
+
supabase_client.table(USER_ROSTERS_TABLE)
|
30 |
+
.insert({"user_id": user_id, "position_id": position_id, "player_id": player_id})
|
31 |
+
.execute()
|
32 |
+
)
|
33 |
|
34 |
|
35 |
def get_user_team(user_id):
|
|
|
100 |
return all_users
|
101 |
|
102 |
|
103 |
+
def get_all_rosters() -> list[dict[str, int | str]]:
|
104 |
+
all_rosters = supabase_client.table(USER_ROSTERS_TABLE).select("user_id", "position_id", "player_id").execute().data
|
105 |
return all_rosters
|
106 |
|
107 |
|
108 |
+
def get_all_rosters_week(week: int) -> list[dict[str, int | str]]:
|
109 |
+
week_rosters = (
|
110 |
+
supabase_client.table(USER_ROSTERS_TABLE)
|
111 |
+
.select("user_id", "position_id", "player_id")
|
112 |
+
.like("position_id", f"{week}%")
|
113 |
+
.execute()
|
114 |
+
.data
|
115 |
+
)
|
116 |
return week_rosters
|
117 |
|
118 |
|
|
|
121 |
Migrate players from the week = migrate_from_week to the week = migrate_from_week + 1
|
122 |
"""
|
123 |
rosters = get_all_rosters_week(migrate_from_week)
|
124 |
+
for roster_slot_map in rosters:
|
125 |
+
position_id = str(roster_slot_map["position_id"])
|
126 |
+
player_id = str(roster_slot_map["player_id"])
|
127 |
+
user_id = int(roster_slot_map["user_id"])
|
128 |
new_position_id = f"""{migrate_from_week + 1}-{position_id.split("-", 1)[1]}"""
|
129 |
update_selection(user_id, new_position_id, player_id)
|
src/pages/11_Scoreboard.py
CHANGED
@@ -32,7 +32,10 @@ def get_users_df():
|
|
32 |
def load_masked_rosters() -> dict[int, dict[str, PlayerOption]]:
|
33 |
options_map = get_map_week_player_id_option()
|
34 |
roster_user_position_map: dict[int, dict[str, PlayerOption]] = {}
|
35 |
-
for
|
|
|
|
|
|
|
36 |
if user_id not in roster_user_position_map:
|
37 |
roster_user_position_map[user_id] = {}
|
38 |
week = int(position_id[0])
|
|
|
32 |
def load_masked_rosters() -> dict[int, dict[str, PlayerOption]]:
|
33 |
options_map = get_map_week_player_id_option()
|
34 |
roster_user_position_map: dict[int, dict[str, PlayerOption]] = {}
|
35 |
+
for roster_slot_map in get_all_rosters():
|
36 |
+
position_id = str(roster_slot_map["position_id"])
|
37 |
+
player_id = str(roster_slot_map["player_id"])
|
38 |
+
user_id = int(roster_slot_map["user_id"])
|
39 |
if user_id not in roster_user_position_map:
|
40 |
roster_user_position_map[user_id] = {}
|
41 |
week = int(position_id[0])
|