hockey-blast-common-lib 0.1.63__py3-none-any.whl → 0.1.64__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hockey_blast_common_lib/aggregate_all_stats.py +7 -4
- hockey_blast_common_lib/aggregate_goalie_stats.py +301 -107
- hockey_blast_common_lib/aggregate_h2h_stats.py +64 -33
- hockey_blast_common_lib/aggregate_human_stats.py +565 -280
- hockey_blast_common_lib/aggregate_referee_stats.py +286 -135
- hockey_blast_common_lib/aggregate_s2s_stats.py +85 -25
- hockey_blast_common_lib/aggregate_scorekeeper_stats.py +228 -113
- hockey_blast_common_lib/aggregate_skater_stats.py +561 -238
- hockey_blast_common_lib/assign_skater_skill.py +21 -11
- hockey_blast_common_lib/db_connection.py +59 -8
- hockey_blast_common_lib/embedding_utils.py +309 -0
- hockey_blast_common_lib/h2h_models.py +150 -56
- hockey_blast_common_lib/models.py +305 -150
- hockey_blast_common_lib/options.py +30 -15
- hockey_blast_common_lib/progress_utils.py +21 -13
- hockey_blast_common_lib/skills_in_divisions.py +170 -33
- hockey_blast_common_lib/skills_propagation.py +164 -70
- hockey_blast_common_lib/stats_models.py +489 -245
- hockey_blast_common_lib/stats_utils.py +6 -3
- hockey_blast_common_lib/utils.py +89 -25
- hockey_blast_common_lib/wsgi.py +7 -5
- {hockey_blast_common_lib-0.1.63.dist-info → hockey_blast_common_lib-0.1.64.dist-info}/METADATA +1 -1
- hockey_blast_common_lib-0.1.64.dist-info/RECORD +29 -0
- hockey_blast_common_lib-0.1.63.dist-info/RECORD +0 -28
- {hockey_blast_common_lib-0.1.63.dist-info → hockey_blast_common_lib-0.1.64.dist-info}/WHEEL +0 -0
- {hockey_blast_common_lib-0.1.63.dist-info → hockey_blast_common_lib-0.1.64.dist-info}/top_level.txt +0 -0
|
@@ -1,73 +1,122 @@
|
|
|
1
|
-
import
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
2
3
|
|
|
3
4
|
# Add the package directory to the Python path
|
|
4
5
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
from datetime import datetime, timedelta
|
|
9
|
+
|
|
8
10
|
import sqlalchemy
|
|
9
|
-
from
|
|
10
|
-
|
|
11
|
+
from sqlalchemy.sql import func
|
|
12
|
+
|
|
11
13
|
from hockey_blast_common_lib.db_connection import create_session
|
|
12
|
-
from
|
|
13
|
-
from hockey_blast_common_lib.options import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
from hockey_blast_common_lib.models import Division, Game, GameRoster, Organization
|
|
15
|
+
from hockey_blast_common_lib.options import (
|
|
16
|
+
MIN_GAMES_FOR_DIVISION_STATS,
|
|
17
|
+
MIN_GAMES_FOR_LEVEL_STATS,
|
|
18
|
+
MIN_GAMES_FOR_ORG_STATS,
|
|
19
|
+
)
|
|
18
20
|
from hockey_blast_common_lib.progress_utils import create_progress_tracker
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
from hockey_blast_common_lib.stats_models import (
|
|
22
|
+
DivisionStatsDailyHuman,
|
|
23
|
+
DivisionStatsHuman,
|
|
24
|
+
DivisionStatsWeeklyHuman,
|
|
25
|
+
LevelStatsHuman,
|
|
26
|
+
OrgStatsDailyHuman,
|
|
27
|
+
OrgStatsHuman,
|
|
28
|
+
OrgStatsWeeklyHuman,
|
|
29
|
+
)
|
|
30
|
+
from hockey_blast_common_lib.stats_utils import ALL_ORGS_ID
|
|
31
|
+
from hockey_blast_common_lib.utils import (
|
|
32
|
+
assign_ranks,
|
|
33
|
+
get_all_division_ids_for_org,
|
|
34
|
+
get_fake_human_for_stats,
|
|
35
|
+
get_non_human_ids,
|
|
36
|
+
get_start_datetime,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def aggregate_human_stats(
|
|
41
|
+
session,
|
|
42
|
+
aggregation_type,
|
|
43
|
+
aggregation_id,
|
|
44
|
+
human_id_filter=None,
|
|
45
|
+
aggregation_window=None,
|
|
46
|
+
):
|
|
21
47
|
human_ids_to_filter = get_non_human_ids(session)
|
|
22
48
|
|
|
23
|
-
if aggregation_type ==
|
|
49
|
+
if aggregation_type == "org":
|
|
24
50
|
if aggregation_id == ALL_ORGS_ID:
|
|
25
51
|
aggregation_name = "All Orgs"
|
|
26
52
|
filter_condition = sqlalchemy.true() # No filter for organization
|
|
27
53
|
else:
|
|
28
|
-
aggregation_name =
|
|
54
|
+
aggregation_name = (
|
|
55
|
+
session.query(Organization)
|
|
56
|
+
.filter(Organization.id == aggregation_id)
|
|
57
|
+
.first()
|
|
58
|
+
.organization_name
|
|
59
|
+
)
|
|
29
60
|
filter_condition = Game.org_id == aggregation_id
|
|
30
|
-
print(
|
|
31
|
-
|
|
61
|
+
print(
|
|
62
|
+
f"Aggregating human stats for {aggregation_name} with window {aggregation_window}..."
|
|
63
|
+
)
|
|
64
|
+
if aggregation_window == "Daily":
|
|
32
65
|
StatsModel = OrgStatsDailyHuman
|
|
33
|
-
elif aggregation_window ==
|
|
66
|
+
elif aggregation_window == "Weekly":
|
|
34
67
|
StatsModel = OrgStatsWeeklyHuman
|
|
35
68
|
else:
|
|
36
69
|
StatsModel = OrgStatsHuman
|
|
37
70
|
min_games = MIN_GAMES_FOR_ORG_STATS
|
|
38
|
-
elif aggregation_type ==
|
|
39
|
-
if aggregation_window ==
|
|
71
|
+
elif aggregation_type == "division":
|
|
72
|
+
if aggregation_window == "Daily":
|
|
40
73
|
StatsModel = DivisionStatsDailyHuman
|
|
41
|
-
elif aggregation_window ==
|
|
74
|
+
elif aggregation_window == "Weekly":
|
|
42
75
|
StatsModel = DivisionStatsWeeklyHuman
|
|
43
76
|
else:
|
|
44
77
|
StatsModel = DivisionStatsHuman
|
|
45
78
|
min_games = MIN_GAMES_FOR_DIVISION_STATS
|
|
46
79
|
filter_condition = Game.division_id == aggregation_id
|
|
47
|
-
elif aggregation_type ==
|
|
80
|
+
elif aggregation_type == "level":
|
|
48
81
|
StatsModel = LevelStatsHuman
|
|
49
82
|
min_games = MIN_GAMES_FOR_LEVEL_STATS
|
|
50
83
|
filter_condition = Division.level_id == aggregation_id
|
|
51
84
|
# Add filter to only include games for the last 5 years
|
|
52
|
-
five_years_ago = datetime.now() - timedelta(days=5*365)
|
|
53
|
-
level_window_filter =
|
|
85
|
+
five_years_ago = datetime.now() - timedelta(days=5 * 365)
|
|
86
|
+
level_window_filter = (
|
|
87
|
+
func.cast(
|
|
88
|
+
func.concat(Game.date, " ", Game.time), sqlalchemy.types.TIMESTAMP
|
|
89
|
+
)
|
|
90
|
+
>= five_years_ago
|
|
91
|
+
)
|
|
54
92
|
filter_condition = filter_condition & level_window_filter
|
|
55
93
|
else:
|
|
56
94
|
raise ValueError("Invalid aggregation type")
|
|
57
95
|
|
|
58
96
|
# Delete existing items from the stats table
|
|
59
|
-
session.query(StatsModel).filter(
|
|
97
|
+
session.query(StatsModel).filter(
|
|
98
|
+
StatsModel.aggregation_id == aggregation_id
|
|
99
|
+
).delete()
|
|
60
100
|
session.commit()
|
|
61
101
|
|
|
62
102
|
# Apply aggregation window filter
|
|
63
103
|
if aggregation_window:
|
|
64
|
-
last_game_datetime_str =
|
|
104
|
+
last_game_datetime_str = (
|
|
105
|
+
session.query(func.max(func.concat(Game.date, " ", Game.time)))
|
|
106
|
+
.filter(
|
|
107
|
+
filter_condition,
|
|
108
|
+
(Game.status.like("Final%")) | (Game.status == "NOEVENTS"),
|
|
109
|
+
)
|
|
110
|
+
.scalar()
|
|
111
|
+
)
|
|
65
112
|
start_datetime = get_start_datetime(last_game_datetime_str, aggregation_window)
|
|
66
113
|
if start_datetime:
|
|
67
|
-
game_window_filter = func.cast(
|
|
114
|
+
game_window_filter = func.cast(
|
|
115
|
+
func.concat(Game.date, " ", Game.time), sqlalchemy.types.TIMESTAMP
|
|
116
|
+
).between(start_datetime, last_game_datetime_str)
|
|
68
117
|
filter_condition = filter_condition & game_window_filter
|
|
69
118
|
else:
|
|
70
|
-
#print(f"Warning: No valid start datetime for aggregation window '{aggregation_window}' for {aggregation_name}. No games will be included.")
|
|
119
|
+
# print(f"Warning: No valid start datetime for aggregation window '{aggregation_window}' for {aggregation_name}. No games will be included.")
|
|
71
120
|
return
|
|
72
121
|
|
|
73
122
|
# Filter for specific human_id if provided
|
|
@@ -76,40 +125,82 @@ def aggregate_human_stats(session, aggregation_type, aggregation_id, human_id_fi
|
|
|
76
125
|
human_filter = [GameRoster.human_id == human_id_filter]
|
|
77
126
|
|
|
78
127
|
# Filter games by status - include both Final and NOEVENTS games
|
|
79
|
-
game_status_filter = (Game.status.like(
|
|
128
|
+
game_status_filter = (Game.status.like("Final%")) | (Game.status == "NOEVENTS")
|
|
80
129
|
|
|
81
130
|
# Aggregate skater games played
|
|
82
|
-
skater_stats =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
131
|
+
skater_stats = (
|
|
132
|
+
session.query(
|
|
133
|
+
GameRoster.human_id,
|
|
134
|
+
func.count(func.distinct(Game.id)).label("games_skater"),
|
|
135
|
+
func.array_agg(func.distinct(Game.id)).label("skater_game_ids"),
|
|
136
|
+
)
|
|
137
|
+
.join(Game, GameRoster.game_id == Game.id)
|
|
138
|
+
.join(Division, Game.division_id == Division.id)
|
|
139
|
+
.filter(
|
|
140
|
+
filter_condition,
|
|
141
|
+
game_status_filter,
|
|
142
|
+
~GameRoster.role.ilike("G"),
|
|
143
|
+
*human_filter,
|
|
144
|
+
)
|
|
145
|
+
.group_by(GameRoster.human_id)
|
|
146
|
+
.all()
|
|
147
|
+
)
|
|
87
148
|
|
|
88
149
|
# Aggregate goalie games played
|
|
89
|
-
goalie_stats =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
150
|
+
goalie_stats = (
|
|
151
|
+
session.query(
|
|
152
|
+
GameRoster.human_id,
|
|
153
|
+
func.count(func.distinct(Game.id)).label("games_goalie"),
|
|
154
|
+
func.array_agg(func.distinct(Game.id)).label("goalie_game_ids"),
|
|
155
|
+
)
|
|
156
|
+
.join(Game, GameRoster.game_id == Game.id)
|
|
157
|
+
.join(Division, Game.division_id == Division.id)
|
|
158
|
+
.filter(
|
|
159
|
+
filter_condition,
|
|
160
|
+
game_status_filter,
|
|
161
|
+
GameRoster.role.ilike("G"),
|
|
162
|
+
*human_filter,
|
|
163
|
+
)
|
|
164
|
+
.group_by(GameRoster.human_id)
|
|
165
|
+
.all()
|
|
166
|
+
)
|
|
94
167
|
|
|
95
168
|
# Aggregate referee and scorekeeper games from Game table
|
|
96
|
-
referee_stats =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
169
|
+
referee_stats = (
|
|
170
|
+
session.query(
|
|
171
|
+
Game.referee_1_id.label("human_id"),
|
|
172
|
+
func.count(func.distinct(Game.id)).label("games_referee"),
|
|
173
|
+
func.array_agg(func.distinct(Game.id)).label("referee_game_ids"),
|
|
174
|
+
)
|
|
175
|
+
.join(Division, Game.division_id == Division.id)
|
|
176
|
+
.filter(filter_condition, game_status_filter, *human_filter)
|
|
177
|
+
.group_by(Game.referee_1_id)
|
|
178
|
+
.all()
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
referee_stats_2 = (
|
|
182
|
+
session.query(
|
|
183
|
+
Game.referee_2_id.label("human_id"),
|
|
184
|
+
func.count(func.distinct(Game.id)).label("games_referee"),
|
|
185
|
+
func.array_agg(func.distinct(Game.id)).label("referee_game_ids"),
|
|
186
|
+
)
|
|
187
|
+
.join(Division, Game.division_id == Division.id)
|
|
188
|
+
.filter(filter_condition, game_status_filter, *human_filter)
|
|
189
|
+
.group_by(Game.referee_2_id)
|
|
190
|
+
.all()
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
scorekeeper_stats = (
|
|
194
|
+
session.query(
|
|
195
|
+
Game.scorekeeper_id.label("human_id"),
|
|
196
|
+
func.count(func.distinct(Game.id)).label("games_scorekeeper"),
|
|
197
|
+
func.array_agg(func.distinct(Game.id)).label("scorekeeper_game_ids"),
|
|
198
|
+
)
|
|
199
|
+
.join(Division, Game.division_id == Division.id)
|
|
200
|
+
.filter(filter_condition, game_status_filter, *human_filter)
|
|
201
|
+
.group_by(Game.scorekeeper_id)
|
|
202
|
+
.all()
|
|
203
|
+
)
|
|
113
204
|
|
|
114
205
|
# Combine the results
|
|
115
206
|
stats_dict = {}
|
|
@@ -119,27 +210,27 @@ def aggregate_human_stats(session, aggregation_type, aggregation_id, human_id_fi
|
|
|
119
210
|
key = (aggregation_id, stat.human_id)
|
|
120
211
|
if key not in stats_dict:
|
|
121
212
|
stats_dict[key] = {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
213
|
+
"games_total": 0,
|
|
214
|
+
"games_skater": 0,
|
|
215
|
+
"games_goalie": 0,
|
|
216
|
+
"games_referee": 0,
|
|
217
|
+
"games_scorekeeper": 0,
|
|
218
|
+
"skater_game_ids": [],
|
|
219
|
+
"goalie_game_ids": [],
|
|
220
|
+
"referee_game_ids": [],
|
|
221
|
+
"scorekeeper_game_ids": [],
|
|
222
|
+
"first_game_id_skater": None,
|
|
223
|
+
"last_game_id_skater": None,
|
|
224
|
+
"first_game_id_goalie": None,
|
|
225
|
+
"last_game_id_goalie": None,
|
|
226
|
+
"first_game_id_referee": None,
|
|
227
|
+
"last_game_id_referee": None,
|
|
228
|
+
"first_game_id_scorekeeper": None,
|
|
229
|
+
"last_game_id_scorekeeper": None,
|
|
139
230
|
}
|
|
140
|
-
stats_dict[key][
|
|
141
|
-
stats_dict[key][
|
|
142
|
-
stats_dict[key][
|
|
231
|
+
stats_dict[key]["games_total"] += stat.games_skater
|
|
232
|
+
stats_dict[key]["games_skater"] += stat.games_skater
|
|
233
|
+
stats_dict[key]["skater_game_ids"].extend(stat.skater_game_ids)
|
|
143
234
|
|
|
144
235
|
for stat in goalie_stats:
|
|
145
236
|
if stat.human_id in human_ids_to_filter:
|
|
@@ -147,27 +238,27 @@ def aggregate_human_stats(session, aggregation_type, aggregation_id, human_id_fi
|
|
|
147
238
|
key = (aggregation_id, stat.human_id)
|
|
148
239
|
if key not in stats_dict:
|
|
149
240
|
stats_dict[key] = {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
241
|
+
"games_total": 0,
|
|
242
|
+
"games_skater": 0,
|
|
243
|
+
"games_goalie": 0,
|
|
244
|
+
"games_referee": 0,
|
|
245
|
+
"games_scorekeeper": 0,
|
|
246
|
+
"skater_game_ids": [],
|
|
247
|
+
"goalie_game_ids": [],
|
|
248
|
+
"referee_game_ids": [],
|
|
249
|
+
"scorekeeper_game_ids": [],
|
|
250
|
+
"first_game_id_skater": None,
|
|
251
|
+
"last_game_id_skater": None,
|
|
252
|
+
"first_game_id_goalie": None,
|
|
253
|
+
"last_game_id_goalie": None,
|
|
254
|
+
"first_game_id_referee": None,
|
|
255
|
+
"last_game_id_referee": None,
|
|
256
|
+
"first_game_id_scorekeeper": None,
|
|
257
|
+
"last_game_id_scorekeeper": None,
|
|
167
258
|
}
|
|
168
|
-
stats_dict[key][
|
|
169
|
-
stats_dict[key][
|
|
170
|
-
stats_dict[key][
|
|
259
|
+
stats_dict[key]["games_total"] += stat.games_goalie
|
|
260
|
+
stats_dict[key]["games_goalie"] += stat.games_goalie
|
|
261
|
+
stats_dict[key]["goalie_game_ids"].extend(stat.goalie_game_ids)
|
|
171
262
|
|
|
172
263
|
for stat in referee_stats:
|
|
173
264
|
if stat.human_id in human_ids_to_filter:
|
|
@@ -175,27 +266,27 @@ def aggregate_human_stats(session, aggregation_type, aggregation_id, human_id_fi
|
|
|
175
266
|
key = (aggregation_id, stat.human_id)
|
|
176
267
|
if key not in stats_dict:
|
|
177
268
|
stats_dict[key] = {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
269
|
+
"games_total": 0,
|
|
270
|
+
"games_skater": 0,
|
|
271
|
+
"games_goalie": 0,
|
|
272
|
+
"games_referee": 0,
|
|
273
|
+
"games_scorekeeper": 0,
|
|
274
|
+
"skater_game_ids": [],
|
|
275
|
+
"goalie_game_ids": [],
|
|
276
|
+
"referee_game_ids": [],
|
|
277
|
+
"scorekeeper_game_ids": [],
|
|
278
|
+
"first_game_id_skater": None,
|
|
279
|
+
"last_game_id_skater": None,
|
|
280
|
+
"first_game_id_goalie": None,
|
|
281
|
+
"last_game_id_goalie": None,
|
|
282
|
+
"first_game_id_referee": None,
|
|
283
|
+
"last_game_id_referee": None,
|
|
284
|
+
"first_game_id_scorekeeper": None,
|
|
285
|
+
"last_game_id_scorekeeper": None,
|
|
195
286
|
}
|
|
196
|
-
stats_dict[key][
|
|
197
|
-
stats_dict[key][
|
|
198
|
-
stats_dict[key][
|
|
287
|
+
stats_dict[key]["games_total"] += stat.games_referee
|
|
288
|
+
stats_dict[key]["games_referee"] += stat.games_referee
|
|
289
|
+
stats_dict[key]["referee_game_ids"].extend(stat.referee_game_ids)
|
|
199
290
|
|
|
200
291
|
for stat in referee_stats_2:
|
|
201
292
|
if stat.human_id in human_ids_to_filter:
|
|
@@ -203,27 +294,27 @@ def aggregate_human_stats(session, aggregation_type, aggregation_id, human_id_fi
|
|
|
203
294
|
key = (aggregation_id, stat.human_id)
|
|
204
295
|
if key not in stats_dict:
|
|
205
296
|
stats_dict[key] = {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
297
|
+
"games_total": 0,
|
|
298
|
+
"games_skater": 0,
|
|
299
|
+
"games_goalie": 0,
|
|
300
|
+
"games_referee": 0,
|
|
301
|
+
"games_scorekeeper": 0,
|
|
302
|
+
"skater_game_ids": [],
|
|
303
|
+
"goalie_game_ids": [],
|
|
304
|
+
"referee_game_ids": [],
|
|
305
|
+
"scorekeeper_game_ids": [],
|
|
306
|
+
"first_game_id_skater": None,
|
|
307
|
+
"last_game_id_skater": None,
|
|
308
|
+
"first_game_id_goalie": None,
|
|
309
|
+
"last_game_id_goalie": None,
|
|
310
|
+
"first_game_id_referee": None,
|
|
311
|
+
"last_game_id_referee": None,
|
|
312
|
+
"first_game_id_scorekeeper": None,
|
|
313
|
+
"last_game_id_scorekeeper": None,
|
|
223
314
|
}
|
|
224
|
-
stats_dict[key][
|
|
225
|
-
stats_dict[key][
|
|
226
|
-
stats_dict[key][
|
|
315
|
+
stats_dict[key]["games_total"] += stat.games_referee
|
|
316
|
+
stats_dict[key]["games_referee"] += stat.games_referee
|
|
317
|
+
stats_dict[key]["referee_game_ids"].extend(stat.referee_game_ids)
|
|
227
318
|
|
|
228
319
|
for stat in scorekeeper_stats:
|
|
229
320
|
if stat.human_id in human_ids_to_filter:
|
|
@@ -231,27 +322,27 @@ def aggregate_human_stats(session, aggregation_type, aggregation_id, human_id_fi
|
|
|
231
322
|
key = (aggregation_id, stat.human_id)
|
|
232
323
|
if key not in stats_dict:
|
|
233
324
|
stats_dict[key] = {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
325
|
+
"games_total": 0,
|
|
326
|
+
"games_skater": 0,
|
|
327
|
+
"games_goalie": 0,
|
|
328
|
+
"games_referee": 0,
|
|
329
|
+
"games_scorekeeper": 0,
|
|
330
|
+
"skater_game_ids": [],
|
|
331
|
+
"goalie_game_ids": [],
|
|
332
|
+
"referee_game_ids": [],
|
|
333
|
+
"scorekeeper_game_ids": [],
|
|
334
|
+
"first_game_id_skater": None,
|
|
335
|
+
"last_game_id_skater": None,
|
|
336
|
+
"first_game_id_goalie": None,
|
|
337
|
+
"last_game_id_goalie": None,
|
|
338
|
+
"first_game_id_referee": None,
|
|
339
|
+
"last_game_id_referee": None,
|
|
340
|
+
"first_game_id_scorekeeper": None,
|
|
341
|
+
"last_game_id_scorekeeper": None,
|
|
251
342
|
}
|
|
252
|
-
stats_dict[key][
|
|
253
|
-
stats_dict[key][
|
|
254
|
-
stats_dict[key][
|
|
343
|
+
stats_dict[key]["games_total"] += stat.games_scorekeeper
|
|
344
|
+
stats_dict[key]["games_scorekeeper"] += stat.games_scorekeeper
|
|
345
|
+
stats_dict[key]["scorekeeper_game_ids"].extend(stat.scorekeeper_game_ids)
|
|
255
346
|
|
|
256
347
|
# Ensure all keys have valid human_id values
|
|
257
348
|
stats_dict = {key: value for key, value in stats_dict.items() if key[1] is not None}
|
|
@@ -260,53 +351,136 @@ def aggregate_human_stats(session, aggregation_type, aggregation_id, human_id_fi
|
|
|
260
351
|
total_in_rank = len(stats_dict)
|
|
261
352
|
|
|
262
353
|
# Calculate number of items in rank per role
|
|
263
|
-
skaters_in_rank = len(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
354
|
+
skaters_in_rank = len(
|
|
355
|
+
[stat for stat in stats_dict.values() if stat["games_skater"] > 0]
|
|
356
|
+
)
|
|
357
|
+
goalies_in_rank = len(
|
|
358
|
+
[stat for stat in stats_dict.values() if stat["games_goalie"] > 0]
|
|
359
|
+
)
|
|
360
|
+
referees_in_rank = len(
|
|
361
|
+
[stat for stat in stats_dict.values() if stat["games_referee"] > 0]
|
|
362
|
+
)
|
|
363
|
+
scorekeepers_in_rank = len(
|
|
364
|
+
[stat for stat in stats_dict.values() if stat["games_scorekeeper"] > 0]
|
|
365
|
+
)
|
|
267
366
|
|
|
268
367
|
# Filter out humans with less than min_games
|
|
269
|
-
stats_dict = {
|
|
368
|
+
stats_dict = {
|
|
369
|
+
key: value
|
|
370
|
+
for key, value in stats_dict.items()
|
|
371
|
+
if value["games_total"] >= min_games
|
|
372
|
+
}
|
|
270
373
|
|
|
271
374
|
# Assign ranks
|
|
272
|
-
assign_ranks(stats_dict,
|
|
273
|
-
assign_ranks(stats_dict,
|
|
274
|
-
assign_ranks(stats_dict,
|
|
275
|
-
assign_ranks(stats_dict,
|
|
276
|
-
assign_ranks(stats_dict,
|
|
375
|
+
assign_ranks(stats_dict, "games_total")
|
|
376
|
+
assign_ranks(stats_dict, "games_skater")
|
|
377
|
+
assign_ranks(stats_dict, "games_goalie")
|
|
378
|
+
assign_ranks(stats_dict, "games_referee")
|
|
379
|
+
assign_ranks(stats_dict, "games_scorekeeper")
|
|
277
380
|
|
|
278
381
|
# Populate first_game_id and last_game_id for each role
|
|
279
382
|
for key, stat in stats_dict.items():
|
|
280
|
-
all_game_ids =
|
|
383
|
+
all_game_ids = (
|
|
384
|
+
stat["skater_game_ids"]
|
|
385
|
+
+ stat["goalie_game_ids"]
|
|
386
|
+
+ stat["referee_game_ids"]
|
|
387
|
+
+ stat["scorekeeper_game_ids"]
|
|
388
|
+
)
|
|
281
389
|
if all_game_ids:
|
|
282
|
-
first_game =
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
390
|
+
first_game = (
|
|
391
|
+
session.query(Game)
|
|
392
|
+
.filter(Game.id.in_(all_game_ids))
|
|
393
|
+
.order_by(Game.date, Game.time)
|
|
394
|
+
.first()
|
|
395
|
+
)
|
|
396
|
+
last_game = (
|
|
397
|
+
session.query(Game)
|
|
398
|
+
.filter(Game.id.in_(all_game_ids))
|
|
399
|
+
.order_by(Game.date.desc(), Game.time.desc())
|
|
400
|
+
.first()
|
|
401
|
+
)
|
|
402
|
+
stat["first_game_id"] = first_game.id if first_game else None
|
|
403
|
+
stat["last_game_id"] = last_game.id if last_game else None
|
|
404
|
+
|
|
405
|
+
if stat["skater_game_ids"]:
|
|
406
|
+
first_game_skater = (
|
|
407
|
+
session.query(Game)
|
|
408
|
+
.filter(Game.id.in_(stat["skater_game_ids"]))
|
|
409
|
+
.order_by(Game.date, Game.time)
|
|
410
|
+
.first()
|
|
411
|
+
)
|
|
412
|
+
last_game_skater = (
|
|
413
|
+
session.query(Game)
|
|
414
|
+
.filter(Game.id.in_(stat["skater_game_ids"]))
|
|
415
|
+
.order_by(Game.date.desc(), Game.time.desc())
|
|
416
|
+
.first()
|
|
417
|
+
)
|
|
418
|
+
stat["first_game_id_skater"] = (
|
|
419
|
+
first_game_skater.id if first_game_skater else None
|
|
420
|
+
)
|
|
421
|
+
stat["last_game_id_skater"] = (
|
|
422
|
+
last_game_skater.id if last_game_skater else None
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
if stat["goalie_game_ids"]:
|
|
426
|
+
first_game_goalie = (
|
|
427
|
+
session.query(Game)
|
|
428
|
+
.filter(Game.id.in_(stat["goalie_game_ids"]))
|
|
429
|
+
.order_by(Game.date, Game.time)
|
|
430
|
+
.first()
|
|
431
|
+
)
|
|
432
|
+
last_game_goalie = (
|
|
433
|
+
session.query(Game)
|
|
434
|
+
.filter(Game.id.in_(stat["goalie_game_ids"]))
|
|
435
|
+
.order_by(Game.date.desc(), Game.time.desc())
|
|
436
|
+
.first()
|
|
437
|
+
)
|
|
438
|
+
stat["first_game_id_goalie"] = (
|
|
439
|
+
first_game_goalie.id if first_game_goalie else None
|
|
440
|
+
)
|
|
441
|
+
stat["last_game_id_goalie"] = (
|
|
442
|
+
last_game_goalie.id if last_game_goalie else None
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
if stat["referee_game_ids"]:
|
|
446
|
+
first_game_referee = (
|
|
447
|
+
session.query(Game)
|
|
448
|
+
.filter(Game.id.in_(stat["referee_game_ids"]))
|
|
449
|
+
.order_by(Game.date, Game.time)
|
|
450
|
+
.first()
|
|
451
|
+
)
|
|
452
|
+
last_game_referee = (
|
|
453
|
+
session.query(Game)
|
|
454
|
+
.filter(Game.id.in_(stat["referee_game_ids"]))
|
|
455
|
+
.order_by(Game.date.desc(), Game.time.desc())
|
|
456
|
+
.first()
|
|
457
|
+
)
|
|
458
|
+
stat["first_game_id_referee"] = (
|
|
459
|
+
first_game_referee.id if first_game_referee else None
|
|
460
|
+
)
|
|
461
|
+
stat["last_game_id_referee"] = (
|
|
462
|
+
last_game_referee.id if last_game_referee else None
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
if stat["scorekeeper_game_ids"]:
|
|
466
|
+
first_game_scorekeeper = (
|
|
467
|
+
session.query(Game)
|
|
468
|
+
.filter(Game.id.in_(stat["scorekeeper_game_ids"]))
|
|
469
|
+
.order_by(Game.date, Game.time)
|
|
470
|
+
.first()
|
|
471
|
+
)
|
|
472
|
+
last_game_scorekeeper = (
|
|
473
|
+
session.query(Game)
|
|
474
|
+
.filter(Game.id.in_(stat["scorekeeper_game_ids"]))
|
|
475
|
+
.order_by(Game.date.desc(), Game.time.desc())
|
|
476
|
+
.first()
|
|
477
|
+
)
|
|
478
|
+
stat["first_game_id_scorekeeper"] = (
|
|
479
|
+
first_game_scorekeeper.id if first_game_scorekeeper else None
|
|
480
|
+
)
|
|
481
|
+
stat["last_game_id_scorekeeper"] = (
|
|
482
|
+
last_game_scorekeeper.id if last_game_scorekeeper else None
|
|
483
|
+
)
|
|
310
484
|
|
|
311
485
|
# Insert aggregated stats into the appropriate table with progress output
|
|
312
486
|
batch_size = 1000
|
|
@@ -318,31 +492,31 @@ def aggregate_human_stats(session, aggregation_type, aggregation_id, human_id_fi
|
|
|
318
492
|
human_stat = StatsModel(
|
|
319
493
|
aggregation_id=aggregation_id,
|
|
320
494
|
human_id=human_id,
|
|
321
|
-
games_total=stat[
|
|
322
|
-
games_total_rank=stat[
|
|
323
|
-
games_skater=stat[
|
|
324
|
-
games_skater_rank=stat[
|
|
325
|
-
games_goalie=stat[
|
|
326
|
-
games_goalie_rank=stat[
|
|
327
|
-
games_referee=stat[
|
|
328
|
-
games_referee_rank=stat[
|
|
329
|
-
games_scorekeeper=stat[
|
|
330
|
-
games_scorekeeper_rank=stat[
|
|
495
|
+
games_total=stat["games_total"],
|
|
496
|
+
games_total_rank=stat["games_total_rank"],
|
|
497
|
+
games_skater=stat["games_skater"],
|
|
498
|
+
games_skater_rank=stat["games_skater_rank"],
|
|
499
|
+
games_goalie=stat["games_goalie"],
|
|
500
|
+
games_goalie_rank=stat["games_goalie_rank"],
|
|
501
|
+
games_referee=stat["games_referee"],
|
|
502
|
+
games_referee_rank=stat["games_referee_rank"],
|
|
503
|
+
games_scorekeeper=stat["games_scorekeeper"],
|
|
504
|
+
games_scorekeeper_rank=stat["games_scorekeeper_rank"],
|
|
331
505
|
total_in_rank=total_in_rank,
|
|
332
506
|
skaters_in_rank=skaters_in_rank,
|
|
333
507
|
goalies_in_rank=goalies_in_rank,
|
|
334
508
|
referees_in_rank=referees_in_rank,
|
|
335
509
|
scorekeepers_in_rank=scorekeepers_in_rank,
|
|
336
|
-
first_game_id=stat[
|
|
337
|
-
last_game_id=stat[
|
|
338
|
-
first_game_id_skater=stat[
|
|
339
|
-
last_game_id_skater=stat[
|
|
340
|
-
first_game_id_goalie=stat[
|
|
341
|
-
last_game_id_goalie=stat[
|
|
342
|
-
first_game_id_referee=stat[
|
|
343
|
-
last_game_id_referee=stat[
|
|
344
|
-
first_game_id_scorekeeper=stat[
|
|
345
|
-
last_game_id_scorekeeper=stat[
|
|
510
|
+
first_game_id=stat["first_game_id"],
|
|
511
|
+
last_game_id=stat["last_game_id"],
|
|
512
|
+
first_game_id_skater=stat["first_game_id_skater"],
|
|
513
|
+
last_game_id_skater=stat["last_game_id_skater"],
|
|
514
|
+
first_game_id_goalie=stat["first_game_id_goalie"],
|
|
515
|
+
last_game_id_goalie=stat["last_game_id_goalie"],
|
|
516
|
+
first_game_id_referee=stat["first_game_id_referee"],
|
|
517
|
+
last_game_id_referee=stat["last_game_id_referee"],
|
|
518
|
+
first_game_id_scorekeeper=stat["first_game_id_scorekeeper"],
|
|
519
|
+
last_game_id_scorekeeper=stat["last_game_id_scorekeeper"],
|
|
346
520
|
)
|
|
347
521
|
session.add(human_stat)
|
|
348
522
|
# Commit in batches
|
|
@@ -355,69 +529,89 @@ def aggregate_human_stats(session, aggregation_type, aggregation_id, human_id_fi
|
|
|
355
529
|
|
|
356
530
|
# Calculate overall stats
|
|
357
531
|
overall_stats = {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
532
|
+
"games_total": sum(stat["games_total"] for stat in stats_dict.values()),
|
|
533
|
+
"games_skater": sum(stat["games_skater"] for stat in stats_dict.values()),
|
|
534
|
+
"games_goalie": sum(stat["games_goalie"] for stat in stats_dict.values()),
|
|
535
|
+
"games_referee": sum(stat["games_referee"] for stat in stats_dict.values()),
|
|
536
|
+
"games_scorekeeper": sum(
|
|
537
|
+
stat["games_scorekeeper"] for stat in stats_dict.values()
|
|
538
|
+
),
|
|
539
|
+
"total_in_rank": total_in_rank,
|
|
540
|
+
"skaters_in_rank": skaters_in_rank,
|
|
541
|
+
"goalies_in_rank": goalies_in_rank,
|
|
542
|
+
"referees_in_rank": referees_in_rank,
|
|
543
|
+
"scorekeepers_in_rank": scorekeepers_in_rank,
|
|
544
|
+
"first_game_id": None,
|
|
545
|
+
"last_game_id": None,
|
|
546
|
+
"first_game_id_skater": None,
|
|
547
|
+
"last_game_id_skater": None,
|
|
548
|
+
"first_game_id_goalie": None,
|
|
549
|
+
"last_game_id_goalie": None,
|
|
550
|
+
"first_game_id_referee": None,
|
|
551
|
+
"last_game_id_referee": None,
|
|
552
|
+
"first_game_id_scorekeeper": None,
|
|
553
|
+
"last_game_id_scorekeeper": None,
|
|
378
554
|
}
|
|
379
555
|
|
|
380
556
|
# Populate first_game_id and last_game_id for overall stats
|
|
381
|
-
all_game_ids = [
|
|
557
|
+
all_game_ids = [
|
|
558
|
+
game_id
|
|
559
|
+
for stat in stats_dict.values()
|
|
560
|
+
for game_id in stat["skater_game_ids"]
|
|
561
|
+
+ stat["goalie_game_ids"]
|
|
562
|
+
+ stat["referee_game_ids"]
|
|
563
|
+
+ stat["scorekeeper_game_ids"]
|
|
564
|
+
]
|
|
382
565
|
if all_game_ids:
|
|
383
|
-
first_game =
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
566
|
+
first_game = (
|
|
567
|
+
session.query(Game)
|
|
568
|
+
.filter(Game.id.in_(all_game_ids))
|
|
569
|
+
.order_by(Game.date, Game.time)
|
|
570
|
+
.first()
|
|
571
|
+
)
|
|
572
|
+
last_game = (
|
|
573
|
+
session.query(Game)
|
|
574
|
+
.filter(Game.id.in_(all_game_ids))
|
|
575
|
+
.order_by(Game.date.desc(), Game.time.desc())
|
|
576
|
+
.first()
|
|
577
|
+
)
|
|
578
|
+
overall_stats["first_game_id"] = first_game.id if first_game else None
|
|
579
|
+
overall_stats["last_game_id"] = last_game.id if last_game else None
|
|
387
580
|
|
|
388
581
|
# Insert overall stats for the fake human
|
|
389
582
|
overall_human_stat = StatsModel(
|
|
390
583
|
aggregation_id=aggregation_id,
|
|
391
584
|
human_id=fake_human_id,
|
|
392
|
-
games_total=overall_stats[
|
|
585
|
+
games_total=overall_stats["games_total"],
|
|
393
586
|
games_total_rank=0, # Overall stats do not need a rank
|
|
394
|
-
games_skater=overall_stats[
|
|
587
|
+
games_skater=overall_stats["games_skater"],
|
|
395
588
|
games_skater_rank=0, # Overall stats do not need a rank
|
|
396
|
-
games_goalie=overall_stats[
|
|
589
|
+
games_goalie=overall_stats["games_goalie"],
|
|
397
590
|
games_goalie_rank=0, # Overall stats do not need a rank
|
|
398
|
-
games_referee=overall_stats[
|
|
591
|
+
games_referee=overall_stats["games_referee"],
|
|
399
592
|
games_referee_rank=0, # Overall stats do not need a rank
|
|
400
|
-
games_scorekeeper=overall_stats[
|
|
593
|
+
games_scorekeeper=overall_stats["games_scorekeeper"],
|
|
401
594
|
games_scorekeeper_rank=0, # Overall stats do not need a rank
|
|
402
|
-
total_in_rank=overall_stats[
|
|
403
|
-
skaters_in_rank=overall_stats[
|
|
404
|
-
goalies_in_rank=overall_stats[
|
|
405
|
-
referees_in_rank=overall_stats[
|
|
406
|
-
scorekeepers_in_rank=overall_stats[
|
|
407
|
-
first_game_id=overall_stats[
|
|
408
|
-
last_game_id=overall_stats[
|
|
409
|
-
first_game_id_skater=overall_stats[
|
|
410
|
-
last_game_id_skater=overall_stats[
|
|
411
|
-
first_game_id_goalie=overall_stats[
|
|
412
|
-
last_game_id_goalie=overall_stats[
|
|
413
|
-
first_game_id_referee=overall_stats[
|
|
414
|
-
last_game_id_referee=overall_stats[
|
|
415
|
-
first_game_id_scorekeeper=overall_stats[
|
|
416
|
-
last_game_id_scorekeeper=overall_stats[
|
|
595
|
+
total_in_rank=overall_stats["total_in_rank"],
|
|
596
|
+
skaters_in_rank=overall_stats["skaters_in_rank"],
|
|
597
|
+
goalies_in_rank=overall_stats["goalies_in_rank"],
|
|
598
|
+
referees_in_rank=overall_stats["referees_in_rank"],
|
|
599
|
+
scorekeepers_in_rank=overall_stats["scorekeepers_in_rank"],
|
|
600
|
+
first_game_id=overall_stats["first_game_id"],
|
|
601
|
+
last_game_id=overall_stats["last_game_id"],
|
|
602
|
+
first_game_id_skater=overall_stats["first_game_id_skater"],
|
|
603
|
+
last_game_id_skater=overall_stats["last_game_id_skater"],
|
|
604
|
+
first_game_id_goalie=overall_stats["first_game_id_goalie"],
|
|
605
|
+
last_game_id_goalie=overall_stats["last_game_id_goalie"],
|
|
606
|
+
first_game_id_referee=overall_stats["first_game_id_referee"],
|
|
607
|
+
last_game_id_referee=overall_stats["last_game_id_referee"],
|
|
608
|
+
first_game_id_scorekeeper=overall_stats["first_game_id_scorekeeper"],
|
|
609
|
+
last_game_id_scorekeeper=overall_stats["last_game_id_scorekeeper"],
|
|
417
610
|
)
|
|
418
611
|
session.add(overall_human_stat)
|
|
419
612
|
session.commit()
|
|
420
613
|
|
|
614
|
+
|
|
421
615
|
def run_aggregate_human_stats():
|
|
422
616
|
session = create_session("boss")
|
|
423
617
|
human_id_to_debug = None
|
|
@@ -428,51 +622,142 @@ def run_aggregate_human_stats():
|
|
|
428
622
|
|
|
429
623
|
for org_id in org_ids:
|
|
430
624
|
division_ids = get_all_division_ids_for_org(session, org_id)
|
|
431
|
-
org_name =
|
|
432
|
-
|
|
625
|
+
org_name = (
|
|
626
|
+
session.query(Organization.organization_name)
|
|
627
|
+
.filter(Organization.id == org_id)
|
|
628
|
+
.scalar()
|
|
629
|
+
or f"org_id {org_id}"
|
|
630
|
+
)
|
|
631
|
+
|
|
433
632
|
if human_id_to_debug is None and division_ids:
|
|
434
633
|
# Process divisions with progress tracking
|
|
435
|
-
progress = create_progress_tracker(
|
|
634
|
+
progress = create_progress_tracker(
|
|
635
|
+
len(division_ids),
|
|
636
|
+
f"Processing {len(division_ids)} divisions for {org_name}",
|
|
637
|
+
)
|
|
436
638
|
for i, division_id in enumerate(division_ids):
|
|
437
|
-
aggregate_human_stats(
|
|
438
|
-
|
|
439
|
-
|
|
639
|
+
aggregate_human_stats(
|
|
640
|
+
session,
|
|
641
|
+
aggregation_type="division",
|
|
642
|
+
aggregation_id=division_id,
|
|
643
|
+
human_id_filter=human_id_to_debug,
|
|
644
|
+
)
|
|
645
|
+
aggregate_human_stats(
|
|
646
|
+
session,
|
|
647
|
+
aggregation_type="division",
|
|
648
|
+
aggregation_id=division_id,
|
|
649
|
+
human_id_filter=human_id_to_debug,
|
|
650
|
+
aggregation_window="Weekly",
|
|
651
|
+
)
|
|
652
|
+
aggregate_human_stats(
|
|
653
|
+
session,
|
|
654
|
+
aggregation_type="division",
|
|
655
|
+
aggregation_id=division_id,
|
|
656
|
+
human_id_filter=human_id_to_debug,
|
|
657
|
+
aggregation_window="Daily",
|
|
658
|
+
)
|
|
440
659
|
progress.update(i + 1)
|
|
441
660
|
else:
|
|
442
661
|
# Debug mode or no divisions - process without progress tracking
|
|
443
662
|
for division_id in division_ids:
|
|
444
|
-
aggregate_human_stats(
|
|
445
|
-
|
|
446
|
-
|
|
663
|
+
aggregate_human_stats(
|
|
664
|
+
session,
|
|
665
|
+
aggregation_type="division",
|
|
666
|
+
aggregation_id=division_id,
|
|
667
|
+
human_id_filter=human_id_to_debug,
|
|
668
|
+
)
|
|
669
|
+
aggregate_human_stats(
|
|
670
|
+
session,
|
|
671
|
+
aggregation_type="division",
|
|
672
|
+
aggregation_id=division_id,
|
|
673
|
+
human_id_filter=human_id_to_debug,
|
|
674
|
+
aggregation_window="Weekly",
|
|
675
|
+
)
|
|
676
|
+
aggregate_human_stats(
|
|
677
|
+
session,
|
|
678
|
+
aggregation_type="division",
|
|
679
|
+
aggregation_id=division_id,
|
|
680
|
+
human_id_filter=human_id_to_debug,
|
|
681
|
+
aggregation_window="Daily",
|
|
682
|
+
)
|
|
447
683
|
|
|
448
684
|
# Process org-level stats with progress tracking
|
|
449
685
|
if human_id_to_debug is None:
|
|
450
|
-
org_progress = create_progress_tracker(
|
|
451
|
-
|
|
686
|
+
org_progress = create_progress_tracker(
|
|
687
|
+
3, f"Processing org-level stats for {org_name}"
|
|
688
|
+
)
|
|
689
|
+
aggregate_human_stats(
|
|
690
|
+
session,
|
|
691
|
+
aggregation_type="org",
|
|
692
|
+
aggregation_id=org_id,
|
|
693
|
+
human_id_filter=human_id_to_debug,
|
|
694
|
+
)
|
|
452
695
|
org_progress.update(1)
|
|
453
|
-
aggregate_human_stats(
|
|
696
|
+
aggregate_human_stats(
|
|
697
|
+
session,
|
|
698
|
+
aggregation_type="org",
|
|
699
|
+
aggregation_id=org_id,
|
|
700
|
+
human_id_filter=human_id_to_debug,
|
|
701
|
+
aggregation_window="Weekly",
|
|
702
|
+
)
|
|
454
703
|
org_progress.update(2)
|
|
455
|
-
aggregate_human_stats(
|
|
704
|
+
aggregate_human_stats(
|
|
705
|
+
session,
|
|
706
|
+
aggregation_type="org",
|
|
707
|
+
aggregation_id=org_id,
|
|
708
|
+
human_id_filter=human_id_to_debug,
|
|
709
|
+
aggregation_window="Daily",
|
|
710
|
+
)
|
|
456
711
|
org_progress.update(3)
|
|
457
712
|
else:
|
|
458
|
-
aggregate_human_stats(
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
713
|
+
aggregate_human_stats(
|
|
714
|
+
session,
|
|
715
|
+
aggregation_type="org",
|
|
716
|
+
aggregation_id=org_id,
|
|
717
|
+
human_id_filter=human_id_to_debug,
|
|
718
|
+
)
|
|
719
|
+
aggregate_human_stats(
|
|
720
|
+
session,
|
|
721
|
+
aggregation_type="org",
|
|
722
|
+
aggregation_id=org_id,
|
|
723
|
+
human_id_filter=human_id_to_debug,
|
|
724
|
+
aggregation_window="Weekly",
|
|
725
|
+
)
|
|
726
|
+
aggregate_human_stats(
|
|
727
|
+
session,
|
|
728
|
+
aggregation_type="org",
|
|
729
|
+
aggregation_id=org_id,
|
|
730
|
+
human_id_filter=human_id_to_debug,
|
|
731
|
+
aggregation_window="Daily",
|
|
732
|
+
)
|
|
733
|
+
|
|
462
734
|
# Aggregate by level
|
|
463
735
|
level_ids = session.query(Division.level_id).distinct().all()
|
|
464
736
|
level_ids = [level_id[0] for level_id in level_ids if level_id[0] is not None]
|
|
465
|
-
|
|
737
|
+
|
|
466
738
|
if human_id_to_debug is None and level_ids:
|
|
467
739
|
# Process levels with progress tracking
|
|
468
|
-
level_progress = create_progress_tracker(
|
|
740
|
+
level_progress = create_progress_tracker(
|
|
741
|
+
len(level_ids), f"Processing {len(level_ids)} skill levels"
|
|
742
|
+
)
|
|
469
743
|
for i, level_id in enumerate(level_ids):
|
|
470
|
-
aggregate_human_stats(
|
|
744
|
+
aggregate_human_stats(
|
|
745
|
+
session,
|
|
746
|
+
aggregation_type="level",
|
|
747
|
+
aggregation_id=level_id,
|
|
748
|
+
human_id_filter=human_id_to_debug,
|
|
749
|
+
)
|
|
471
750
|
level_progress.update(i + 1)
|
|
472
751
|
else:
|
|
473
752
|
# Debug mode or no levels - process without progress tracking
|
|
474
753
|
for level_id in level_ids:
|
|
475
|
-
aggregate_human_stats(
|
|
754
|
+
aggregate_human_stats(
|
|
755
|
+
session,
|
|
756
|
+
aggregation_type="level",
|
|
757
|
+
aggregation_id=level_id,
|
|
758
|
+
human_id_filter=human_id_to_debug,
|
|
759
|
+
)
|
|
760
|
+
|
|
476
761
|
|
|
477
762
|
if __name__ == "__main__":
|
|
478
|
-
run_aggregate_human_stats()
|
|
763
|
+
run_aggregate_human_stats()
|