hockey-blast-common-lib 0.1.63__py3-none-any.whl → 0.1.65__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.
Files changed (27) hide show
  1. hockey_blast_common_lib/aggregate_all_stats.py +7 -4
  2. hockey_blast_common_lib/aggregate_goalie_stats.py +301 -107
  3. hockey_blast_common_lib/aggregate_h2h_stats.py +64 -33
  4. hockey_blast_common_lib/aggregate_human_stats.py +565 -280
  5. hockey_blast_common_lib/aggregate_referee_stats.py +286 -135
  6. hockey_blast_common_lib/aggregate_s2s_stats.py +85 -25
  7. hockey_blast_common_lib/aggregate_scorekeeper_stats.py +228 -113
  8. hockey_blast_common_lib/aggregate_skater_stats.py +561 -238
  9. hockey_blast_common_lib/assign_skater_skill.py +21 -11
  10. hockey_blast_common_lib/db_connection.py +59 -8
  11. hockey_blast_common_lib/embedding_utils.py +309 -0
  12. hockey_blast_common_lib/h2h_models.py +150 -56
  13. hockey_blast_common_lib/hockey_blast_sample_backup.sql.gz +0 -0
  14. hockey_blast_common_lib/models.py +305 -150
  15. hockey_blast_common_lib/options.py +30 -15
  16. hockey_blast_common_lib/progress_utils.py +21 -13
  17. hockey_blast_common_lib/skills_in_divisions.py +170 -33
  18. hockey_blast_common_lib/skills_propagation.py +164 -70
  19. hockey_blast_common_lib/stats_models.py +489 -245
  20. hockey_blast_common_lib/stats_utils.py +6 -3
  21. hockey_blast_common_lib/utils.py +91 -25
  22. hockey_blast_common_lib/wsgi.py +7 -5
  23. {hockey_blast_common_lib-0.1.63.dist-info → hockey_blast_common_lib-0.1.65.dist-info}/METADATA +1 -1
  24. hockey_blast_common_lib-0.1.65.dist-info/RECORD +29 -0
  25. hockey_blast_common_lib-0.1.63.dist-info/RECORD +0 -28
  26. {hockey_blast_common_lib-0.1.63.dist-info → hockey_blast_common_lib-0.1.65.dist-info}/WHEEL +0 -0
  27. {hockey_blast_common_lib-0.1.63.dist-info → hockey_blast_common_lib-0.1.65.dist-info}/top_level.txt +0 -0
@@ -1,73 +1,122 @@
1
- import sys, os
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 hockey_blast_common_lib.models import Game, GameRoster, Organization, Division
10
- from hockey_blast_common_lib.stats_models import OrgStatsHuman, DivisionStatsHuman, OrgStatsDailyHuman, OrgStatsWeeklyHuman, DivisionStatsDailyHuman, DivisionStatsWeeklyHuman, LevelStatsHuman
11
+ from sqlalchemy.sql import func
12
+
11
13
  from hockey_blast_common_lib.db_connection import create_session
12
- from sqlalchemy.sql import func, case
13
- from hockey_blast_common_lib.options import parse_args, MIN_GAMES_FOR_ORG_STATS, MIN_GAMES_FOR_DIVISION_STATS, MIN_GAMES_FOR_LEVEL_STATS
14
- from hockey_blast_common_lib.utils import get_fake_human_for_stats, get_org_id_from_alias, get_non_human_ids, get_division_ids_for_last_season_in_all_leagues, get_all_division_ids_for_org
15
- from hockey_blast_common_lib.utils import assign_ranks
16
- from hockey_blast_common_lib.utils import get_start_datetime
17
- from hockey_blast_common_lib.stats_utils import ALL_ORGS_ID
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
- def aggregate_human_stats(session, aggregation_type, aggregation_id, human_id_filter=None, aggregation_window=None):
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 == 'org':
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 = session.query(Organization).filter(Organization.id == aggregation_id).first().organization_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(f"Aggregating human stats for {aggregation_name} with window {aggregation_window}...")
31
- if aggregation_window == 'Daily':
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 == 'Weekly':
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 == 'division':
39
- if aggregation_window == 'Daily':
71
+ elif aggregation_type == "division":
72
+ if aggregation_window == "Daily":
40
73
  StatsModel = DivisionStatsDailyHuman
41
- elif aggregation_window == 'Weekly':
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 == 'level':
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 = func.cast(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP) >= five_years_ago
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(StatsModel.aggregation_id == aggregation_id).delete()
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 = session.query(func.max(func.concat(Game.date, ' ', Game.time))).filter(filter_condition, (Game.status.like('Final%')) | (Game.status == 'NOEVENTS')).scalar()
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(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP).between(start_datetime, last_game_datetime_str)
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('Final%')) | (Game.status == 'NOEVENTS')
128
+ game_status_filter = (Game.status.like("Final%")) | (Game.status == "NOEVENTS")
80
129
 
81
130
  # Aggregate skater games played
82
- skater_stats = session.query(
83
- GameRoster.human_id,
84
- func.count(func.distinct(Game.id)).label('games_skater'),
85
- func.array_agg(func.distinct(Game.id)).label('skater_game_ids')
86
- ).join(Game, GameRoster.game_id == Game.id).join(Division, Game.division_id == Division.id).filter(filter_condition, game_status_filter, ~GameRoster.role.ilike('G'), *human_filter).group_by(GameRoster.human_id).all()
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 = session.query(
90
- GameRoster.human_id,
91
- func.count(func.distinct(Game.id)).label('games_goalie'),
92
- func.array_agg(func.distinct(Game.id)).label('goalie_game_ids')
93
- ).join(Game, GameRoster.game_id == Game.id).join(Division, Game.division_id == Division.id).filter(filter_condition, game_status_filter, GameRoster.role.ilike('G'), *human_filter).group_by(GameRoster.human_id).all()
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 = session.query(
97
- Game.referee_1_id.label('human_id'),
98
- func.count(func.distinct(Game.id)).label('games_referee'),
99
- func.array_agg(func.distinct(Game.id)).label('referee_game_ids')
100
- ).join(Division, Game.division_id == Division.id).filter(filter_condition, game_status_filter, *human_filter).group_by(Game.referee_1_id).all()
101
-
102
- referee_stats_2 = session.query(
103
- Game.referee_2_id.label('human_id'),
104
- func.count(func.distinct(Game.id)).label('games_referee'),
105
- func.array_agg(func.distinct(Game.id)).label('referee_game_ids')
106
- ).join(Division, Game.division_id == Division.id).filter(filter_condition, game_status_filter, *human_filter).group_by(Game.referee_2_id).all()
107
-
108
- scorekeeper_stats = session.query(
109
- Game.scorekeeper_id.label('human_id'),
110
- func.count(func.distinct(Game.id)).label('games_scorekeeper'),
111
- func.array_agg(func.distinct(Game.id)).label('scorekeeper_game_ids')
112
- ).join(Division, Game.division_id == Division.id).filter(filter_condition, game_status_filter, *human_filter).group_by(Game.scorekeeper_id).all()
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
- 'games_total': 0,
123
- 'games_skater': 0,
124
- 'games_goalie': 0,
125
- 'games_referee': 0,
126
- 'games_scorekeeper': 0,
127
- 'skater_game_ids': [],
128
- 'goalie_game_ids': [],
129
- 'referee_game_ids': [],
130
- 'scorekeeper_game_ids': [],
131
- 'first_game_id_skater': None,
132
- 'last_game_id_skater': None,
133
- 'first_game_id_goalie': None,
134
- 'last_game_id_goalie': None,
135
- 'first_game_id_referee': None,
136
- 'last_game_id_referee': None,
137
- 'first_game_id_scorekeeper': None,
138
- 'last_game_id_scorekeeper': None
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]['games_total'] += stat.games_skater
141
- stats_dict[key]['games_skater'] += stat.games_skater
142
- stats_dict[key]['skater_game_ids'].extend(stat.skater_game_ids)
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
- 'games_total': 0,
151
- 'games_skater': 0,
152
- 'games_goalie': 0,
153
- 'games_referee': 0,
154
- 'games_scorekeeper': 0,
155
- 'skater_game_ids': [],
156
- 'goalie_game_ids': [],
157
- 'referee_game_ids': [],
158
- 'scorekeeper_game_ids': [],
159
- 'first_game_id_skater': None,
160
- 'last_game_id_skater': None,
161
- 'first_game_id_goalie': None,
162
- 'last_game_id_goalie': None,
163
- 'first_game_id_referee': None,
164
- 'last_game_id_referee': None,
165
- 'first_game_id_scorekeeper': None,
166
- 'last_game_id_scorekeeper': None
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]['games_total'] += stat.games_goalie
169
- stats_dict[key]['games_goalie'] += stat.games_goalie
170
- stats_dict[key]['goalie_game_ids'].extend(stat.goalie_game_ids)
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
- 'games_total': 0,
179
- 'games_skater': 0,
180
- 'games_goalie': 0,
181
- 'games_referee': 0,
182
- 'games_scorekeeper': 0,
183
- 'skater_game_ids': [],
184
- 'goalie_game_ids': [],
185
- 'referee_game_ids': [],
186
- 'scorekeeper_game_ids': [],
187
- 'first_game_id_skater': None,
188
- 'last_game_id_skater': None,
189
- 'first_game_id_goalie': None,
190
- 'last_game_id_goalie': None,
191
- 'first_game_id_referee': None,
192
- 'last_game_id_referee': None,
193
- 'first_game_id_scorekeeper': None,
194
- 'last_game_id_scorekeeper': None
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]['games_total'] += stat.games_referee
197
- stats_dict[key]['games_referee'] += stat.games_referee
198
- stats_dict[key]['referee_game_ids'].extend(stat.referee_game_ids)
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
- 'games_total': 0,
207
- 'games_skater': 0,
208
- 'games_goalie': 0,
209
- 'games_referee': 0,
210
- 'games_scorekeeper': 0,
211
- 'skater_game_ids': [],
212
- 'goalie_game_ids': [],
213
- 'referee_game_ids': [],
214
- 'scorekeeper_game_ids': [],
215
- 'first_game_id_skater': None,
216
- 'last_game_id_skater': None,
217
- 'first_game_id_goalie': None,
218
- 'last_game_id_goalie': None,
219
- 'first_game_id_referee': None,
220
- 'last_game_id_referee': None,
221
- 'first_game_id_scorekeeper': None,
222
- 'last_game_id_scorekeeper': None
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]['games_total'] += stat.games_referee
225
- stats_dict[key]['games_referee'] += stat.games_referee
226
- stats_dict[key]['referee_game_ids'].extend(stat.referee_game_ids)
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
- 'games_total': 0,
235
- 'games_skater': 0,
236
- 'games_goalie': 0,
237
- 'games_referee': 0,
238
- 'games_scorekeeper': 0,
239
- 'skater_game_ids': [],
240
- 'goalie_game_ids': [],
241
- 'referee_game_ids': [],
242
- 'scorekeeper_game_ids': [],
243
- 'first_game_id_skater': None,
244
- 'last_game_id_skater': None,
245
- 'first_game_id_goalie': None,
246
- 'last_game_id_goalie': None,
247
- 'first_game_id_referee': None,
248
- 'last_game_id_referee': None,
249
- 'first_game_id_scorekeeper': None,
250
- 'last_game_id_scorekeeper': None
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]['games_total'] += stat.games_scorekeeper
253
- stats_dict[key]['games_scorekeeper'] += stat.games_scorekeeper
254
- stats_dict[key]['scorekeeper_game_ids'].extend(stat.scorekeeper_game_ids)
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([stat for stat in stats_dict.values() if stat['games_skater'] > 0])
264
- goalies_in_rank = len([stat for stat in stats_dict.values() if stat['games_goalie'] > 0])
265
- referees_in_rank = len([stat for stat in stats_dict.values() if stat['games_referee'] > 0])
266
- scorekeepers_in_rank = len([stat for stat in stats_dict.values() if stat['games_scorekeeper'] > 0])
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 = {key: value for key, value in stats_dict.items() if value['games_total'] >= min_games}
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, 'games_total')
273
- assign_ranks(stats_dict, 'games_skater')
274
- assign_ranks(stats_dict, 'games_goalie')
275
- assign_ranks(stats_dict, 'games_referee')
276
- assign_ranks(stats_dict, 'games_scorekeeper')
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 = stat['skater_game_ids'] + stat['goalie_game_ids'] + stat['referee_game_ids'] + stat['scorekeeper_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 = session.query(Game).filter(Game.id.in_(all_game_ids)).order_by(Game.date, Game.time).first()
283
- last_game = session.query(Game).filter(Game.id.in_(all_game_ids)).order_by(Game.date.desc(), Game.time.desc()).first()
284
- stat['first_game_id'] = first_game.id if first_game else None
285
- stat['last_game_id'] = last_game.id if last_game else None
286
-
287
- if stat['skater_game_ids']:
288
- first_game_skater = session.query(Game).filter(Game.id.in_(stat['skater_game_ids'])).order_by(Game.date, Game.time).first()
289
- last_game_skater = session.query(Game).filter(Game.id.in_(stat['skater_game_ids'])).order_by(Game.date.desc(), Game.time.desc()).first()
290
- stat['first_game_id_skater'] = first_game_skater.id if first_game_skater else None
291
- stat['last_game_id_skater'] = last_game_skater.id if last_game_skater else None
292
-
293
- if stat['goalie_game_ids']:
294
- first_game_goalie = session.query(Game).filter(Game.id.in_(stat['goalie_game_ids'])).order_by(Game.date, Game.time).first()
295
- last_game_goalie = session.query(Game).filter(Game.id.in_(stat['goalie_game_ids'])).order_by(Game.date.desc(), Game.time.desc()).first()
296
- stat['first_game_id_goalie'] = first_game_goalie.id if first_game_goalie else None
297
- stat['last_game_id_goalie'] = last_game_goalie.id if last_game_goalie else None
298
-
299
- if stat['referee_game_ids']:
300
- first_game_referee = session.query(Game).filter(Game.id.in_(stat['referee_game_ids'])).order_by(Game.date, Game.time).first()
301
- last_game_referee = session.query(Game).filter(Game.id.in_(stat['referee_game_ids'])).order_by(Game.date.desc(), Game.time.desc()).first()
302
- stat['first_game_id_referee'] = first_game_referee.id if first_game_referee else None
303
- stat['last_game_id_referee'] = last_game_referee.id if last_game_referee else None
304
-
305
- if stat['scorekeeper_game_ids']:
306
- first_game_scorekeeper = session.query(Game).filter(Game.id.in_(stat['scorekeeper_game_ids'])).order_by(Game.date, Game.time).first()
307
- last_game_scorekeeper = session.query(Game).filter(Game.id.in_(stat['scorekeeper_game_ids'])).order_by(Game.date.desc(), Game.time.desc()).first()
308
- stat['first_game_id_scorekeeper'] = first_game_scorekeeper.id if first_game_scorekeeper else None
309
- stat['last_game_id_scorekeeper'] = last_game_scorekeeper.id if last_game_scorekeeper else None
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['games_total'],
322
- games_total_rank=stat['games_total_rank'],
323
- games_skater=stat['games_skater'],
324
- games_skater_rank=stat['games_skater_rank'],
325
- games_goalie=stat['games_goalie'],
326
- games_goalie_rank=stat['games_goalie_rank'],
327
- games_referee=stat['games_referee'],
328
- games_referee_rank=stat['games_referee_rank'],
329
- games_scorekeeper=stat['games_scorekeeper'],
330
- games_scorekeeper_rank=stat['games_scorekeeper_rank'],
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['first_game_id'],
337
- last_game_id=stat['last_game_id'],
338
- first_game_id_skater=stat['first_game_id_skater'],
339
- last_game_id_skater=stat['last_game_id_skater'],
340
- first_game_id_goalie=stat['first_game_id_goalie'],
341
- last_game_id_goalie=stat['last_game_id_goalie'],
342
- first_game_id_referee=stat['first_game_id_referee'],
343
- last_game_id_referee=stat['last_game_id_referee'],
344
- first_game_id_scorekeeper=stat['first_game_id_scorekeeper'],
345
- last_game_id_scorekeeper=stat['last_game_id_scorekeeper']
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
- 'games_total': sum(stat['games_total'] for stat in stats_dict.values()),
359
- 'games_skater': sum(stat['games_skater'] for stat in stats_dict.values()),
360
- 'games_goalie': sum(stat['games_goalie'] for stat in stats_dict.values()),
361
- 'games_referee': sum(stat['games_referee'] for stat in stats_dict.values()),
362
- 'games_scorekeeper': sum(stat['games_scorekeeper'] for stat in stats_dict.values()),
363
- 'total_in_rank': total_in_rank,
364
- 'skaters_in_rank': skaters_in_rank,
365
- 'goalies_in_rank': goalies_in_rank,
366
- 'referees_in_rank': referees_in_rank,
367
- 'scorekeepers_in_rank': scorekeepers_in_rank,
368
- 'first_game_id': None,
369
- 'last_game_id': None,
370
- 'first_game_id_skater': None,
371
- 'last_game_id_skater': None,
372
- 'first_game_id_goalie': None,
373
- 'last_game_id_goalie': None,
374
- 'first_game_id_referee': None,
375
- 'last_game_id_referee': None,
376
- 'first_game_id_scorekeeper': None,
377
- 'last_game_id_scorekeeper': None
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 = [game_id for stat in stats_dict.values() for game_id in stat['skater_game_ids'] + stat['goalie_game_ids'] + stat['referee_game_ids'] + stat['scorekeeper_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 = session.query(Game).filter(Game.id.in_(all_game_ids)).order_by(Game.date, Game.time).first()
384
- last_game = session.query(Game).filter(Game.id.in_(all_game_ids)).order_by(Game.date.desc(), Game.time.desc()).first()
385
- overall_stats['first_game_id'] = first_game.id if first_game else None
386
- overall_stats['last_game_id'] = last_game.id if last_game else None
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['games_total'],
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['games_skater'],
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['games_goalie'],
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['games_referee'],
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['games_scorekeeper'],
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['total_in_rank'],
403
- skaters_in_rank=overall_stats['skaters_in_rank'],
404
- goalies_in_rank=overall_stats['goalies_in_rank'],
405
- referees_in_rank=overall_stats['referees_in_rank'],
406
- scorekeepers_in_rank=overall_stats['scorekeepers_in_rank'],
407
- first_game_id=overall_stats['first_game_id'],
408
- last_game_id=overall_stats['last_game_id'],
409
- first_game_id_skater=overall_stats['first_game_id_skater'],
410
- last_game_id_skater=overall_stats['last_game_id_skater'],
411
- first_game_id_goalie=overall_stats['first_game_id_goalie'],
412
- last_game_id_goalie=overall_stats['last_game_id_goalie'],
413
- first_game_id_referee=overall_stats['first_game_id_referee'],
414
- last_game_id_referee=overall_stats['last_game_id_referee'],
415
- first_game_id_scorekeeper=overall_stats['first_game_id_scorekeeper'],
416
- last_game_id_scorekeeper=overall_stats['last_game_id_scorekeeper']
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 = session.query(Organization.organization_name).filter(Organization.id == org_id).scalar() or f"org_id {org_id}"
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(len(division_ids), f"Processing {len(division_ids)} divisions for {org_name}")
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(session, aggregation_type='division', aggregation_id=division_id, human_id_filter=human_id_to_debug)
438
- aggregate_human_stats(session, aggregation_type='division', aggregation_id=division_id, human_id_filter=human_id_to_debug, aggregation_window='Weekly')
439
- aggregate_human_stats(session, aggregation_type='division', aggregation_id=division_id, human_id_filter=human_id_to_debug, aggregation_window='Daily')
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(session, aggregation_type='division', aggregation_id=division_id, human_id_filter=human_id_to_debug)
445
- aggregate_human_stats(session, aggregation_type='division', aggregation_id=division_id, human_id_filter=human_id_to_debug, aggregation_window='Weekly')
446
- aggregate_human_stats(session, aggregation_type='division', aggregation_id=division_id, human_id_filter=human_id_to_debug, aggregation_window='Daily')
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(3, f"Processing org-level stats for {org_name}")
451
- aggregate_human_stats(session, aggregation_type='org', aggregation_id=org_id, human_id_filter=human_id_to_debug)
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(session, aggregation_type='org', aggregation_id=org_id, human_id_filter=human_id_to_debug, aggregation_window='Weekly')
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(session, aggregation_type='org', aggregation_id=org_id, human_id_filter=human_id_to_debug, aggregation_window='Daily')
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(session, aggregation_type='org', aggregation_id=org_id, human_id_filter=human_id_to_debug)
459
- aggregate_human_stats(session, aggregation_type='org', aggregation_id=org_id, human_id_filter=human_id_to_debug, aggregation_window='Weekly')
460
- aggregate_human_stats(session, aggregation_type='org', aggregation_id=org_id, human_id_filter=human_id_to_debug, aggregation_window='Daily')
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(len(level_ids), f"Processing {len(level_ids)} skill levels")
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(session, aggregation_type='level', aggregation_id=level_id, human_id_filter=human_id_to_debug)
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(session, aggregation_type='level', aggregation_id=level_id, human_id_filter=human_id_to_debug)
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()