hockey-blast-common-lib 0.1.7__py3-none-any.whl → 0.1.9__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.
@@ -0,0 +1,165 @@
1
+ import sys, os
2
+
3
+ # Add the package directory to the Python path
4
+ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
5
+
6
+ from datetime import datetime, timedelta
7
+ import sqlalchemy
8
+ from options import not_human_names
9
+ from hockey_blast_common_lib.models import Game, GameRoster
10
+ from stats_models import OrgStatsGoalie, DivisionStatsGoalie, OrgStatsWeeklyGoalie, OrgStatsDailyGoalie, DivisionStatsWeeklyGoalie, DivisionStatsDailyGoalie
11
+ from db_connection import create_session
12
+ from sqlalchemy.sql import func, case
13
+ from options import parse_args, MIN_GAMES_FOR_ORG_STATS, MIN_GAMES_FOR_DIVISION_STATS
14
+ from utils import get_org_id_from_alias, get_human_ids_by_names, get_division_ids_for_last_season_in_all_leagues, get_all_division_ids_for_org
15
+
16
+ def aggregate_goalie_stats(session, aggregation_type, aggregation_id, names_to_filter_out, aggregation_window=None):
17
+ human_ids_to_filter = get_human_ids_by_names(session, names_to_filter_out)
18
+
19
+ if aggregation_type == 'org':
20
+ if aggregation_window == 'Daily':
21
+ StatsModel = OrgStatsDailyGoalie
22
+ elif aggregation_window == 'Weekly':
23
+ StatsModel = OrgStatsWeeklyGoalie
24
+ else:
25
+ StatsModel = OrgStatsGoalie
26
+ min_games = MIN_GAMES_FOR_ORG_STATS
27
+ filter_condition = Game.org_id == aggregation_id
28
+ elif aggregation_type == 'division':
29
+ if aggregation_window == 'Daily':
30
+ StatsModel = DivisionStatsDailyGoalie
31
+ elif aggregation_window == 'Weekly':
32
+ StatsModel = DivisionStatsWeeklyGoalie
33
+ else:
34
+ StatsModel = DivisionStatsGoalie
35
+ min_games = MIN_GAMES_FOR_DIVISION_STATS
36
+ filter_condition = Game.division_id == aggregation_id
37
+ else:
38
+ raise ValueError("Invalid aggregation type")
39
+
40
+ # Apply aggregation window filter
41
+ if aggregation_window:
42
+ last_game_datetime = session.query(func.max(func.concat(Game.date, ' ', Game.time))).filter(filter_condition, Game.status.like('Final%')).scalar()
43
+ if last_game_datetime:
44
+ last_game_datetime = datetime.strptime(last_game_datetime, '%Y-%m-%d %H:%M:%S')
45
+ if aggregation_window == 'Daily':
46
+ start_datetime = last_game_datetime - timedelta(days=1)
47
+ elif aggregation_window == 'Weekly':
48
+ start_datetime = last_game_datetime - timedelta(weeks=1)
49
+ else:
50
+ start_datetime = None
51
+ if start_datetime:
52
+ game_window_filter = func.cast(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP).between(start_datetime, last_game_datetime)
53
+ filter_condition = filter_condition & game_window_filter
54
+
55
+ # Delete existing items from the stats table
56
+ session.query(StatsModel).filter(StatsModel.aggregation_id == aggregation_id).delete()
57
+ session.commit()
58
+
59
+ # Aggregate games played, goals allowed, and shots faced for each goalie
60
+ goalie_stats = session.query(
61
+ GameRoster.human_id,
62
+ func.count(Game.id).label('games_played'),
63
+ func.sum(case((GameRoster.team_id == Game.home_team_id, Game.visitor_final_score), else_=Game.home_final_score)).label('goals_allowed'),
64
+ func.sum(case((GameRoster.team_id == Game.home_team_id, Game.visitor_period_1_shots + Game.visitor_period_2_shots + Game.visitor_period_3_shots + Game.visitor_ot_shots + Game.visitor_so_shots), else_=Game.home_period_1_shots + Game.home_period_2_shots + Game.home_period_3_shots + Game.home_ot_shots + Game.home_so_shots)).label('shots_faced'),
65
+ func.array_agg(Game.id).label('game_ids')
66
+ ).join(Game, GameRoster.game_id == Game.id).filter(filter_condition, GameRoster.role == 'G').group_by(GameRoster.human_id).all()
67
+
68
+ # Combine the results
69
+ stats_dict = {}
70
+ for stat in goalie_stats:
71
+ if stat.human_id in human_ids_to_filter:
72
+ continue
73
+ key = (aggregation_id, stat.human_id)
74
+ stats_dict[key] = {
75
+ 'games_played': stat.games_played,
76
+ 'goals_allowed': stat.goals_allowed if stat.goals_allowed is not None else 0,
77
+ 'shots_faced': stat.shots_faced if stat.shots_faced is not None else 0,
78
+ 'goals_allowed_per_game': 0.0,
79
+ 'save_percentage': 0.0,
80
+ 'game_ids': stat.game_ids,
81
+ 'first_game_id': None,
82
+ 'last_game_id': None
83
+ }
84
+
85
+ # Calculate per game stats
86
+ for key, stat in stats_dict.items():
87
+ if stat['games_played'] > 0:
88
+ stat['goals_allowed_per_game'] = stat['goals_allowed'] / stat['games_played']
89
+ stat['save_percentage'] = (stat['shots_faced'] - stat['goals_allowed']) / stat['shots_faced'] if stat['shots_faced'] > 0 else 0.0
90
+
91
+ # Ensure all keys have valid human_id values
92
+ stats_dict = {key: value for key, value in stats_dict.items() if key[1] is not None}
93
+
94
+ # Populate first_game_id and last_game_id
95
+ for key, stat in stats_dict.items():
96
+ all_game_ids = stat['game_ids']
97
+ if all_game_ids:
98
+ first_game = session.query(Game).filter(Game.id.in_(all_game_ids)).order_by(Game.date, Game.time).first()
99
+ last_game = session.query(Game).filter(Game.id.in_(all_game_ids)).order_by(Game.date.desc(), Game.time.desc()).first()
100
+ stat['first_game_id'] = first_game.id if first_game else None
101
+ stat['last_game_id'] = last_game.id if last_game else None
102
+
103
+ # Calculate total_in_rank
104
+ total_in_rank = len(stats_dict)
105
+
106
+ # Assign ranks
107
+ def assign_ranks(stats_dict, field):
108
+ sorted_stats = sorted(stats_dict.items(), key=lambda x: x[1][field], reverse=True)
109
+ for rank, (key, stat) in enumerate(sorted_stats, start=1):
110
+ stats_dict[key][f'{field}_rank'] = rank
111
+
112
+ assign_ranks(stats_dict, 'games_played')
113
+ assign_ranks(stats_dict, 'goals_allowed')
114
+ assign_ranks(stats_dict, 'goals_allowed_per_game')
115
+ assign_ranks(stats_dict, 'shots_faced')
116
+ assign_ranks(stats_dict, 'save_percentage')
117
+
118
+ # Insert aggregated stats into the appropriate table with progress output
119
+ total_items = len(stats_dict)
120
+ batch_size = 1000
121
+ for i, (key, stat) in enumerate(stats_dict.items(), 1):
122
+ aggregation_id, human_id = key
123
+ if stat['games_played'] < min_games:
124
+ continue
125
+ goalie_stat = StatsModel(
126
+ aggregation_id=aggregation_id,
127
+ human_id=human_id,
128
+ games_played=stat['games_played'],
129
+ goals_allowed=stat['goals_allowed'],
130
+ goals_allowed_per_game=stat['goals_allowed_per_game'],
131
+ shots_faced=stat['shots_faced'],
132
+ save_percentage=stat['save_percentage'],
133
+ games_played_rank=stat['games_played_rank'],
134
+ goals_allowed_rank=stat['goals_allowed_rank'],
135
+ goals_allowed_per_game_rank=stat['goals_allowed_per_game_rank'],
136
+ shots_faced_rank=stat['shots_faced_rank'],
137
+ save_percentage_rank=stat['save_percentage_rank'],
138
+ total_in_rank=total_in_rank,
139
+ first_game_id=stat['first_game_id'],
140
+ last_game_id=stat['last_game_id']
141
+ )
142
+ session.add(goalie_stat)
143
+ # Commit in batches
144
+ if i % batch_size == 0:
145
+ session.commit()
146
+ print(f"\r{i}/{total_items} ({(i/total_items)*100:.2f}%)", end="")
147
+ session.commit()
148
+ print(f"\r{total_items}/{total_items} (100.00%)")
149
+ print("\nDone.")
150
+
151
+ # Example usage
152
+ if __name__ == "__main__":
153
+ args = parse_args()
154
+ org_alias = args.org
155
+ session = create_session("boss")
156
+ org_id = get_org_id_from_alias(session, org_alias)
157
+ division_ids = get_division_ids_for_last_season_in_all_leagues(session, org_id)
158
+ print(f"Aggregating goalie stats for {len(division_ids)} divisions in {org_alias}...")
159
+ for division_id in division_ids:
160
+ aggregate_goalie_stats(session, aggregation_type='division', aggregation_id=division_id, names_to_filter_out=not_human_names)
161
+ aggregate_goalie_stats(session, aggregation_type='division', aggregation_id=division_id, names_to_filter_out=not_human_names, aggregation_window='Daily')
162
+ aggregate_goalie_stats(session, aggregation_type='division', aggregation_id=division_id, names_to_filter_out=not_human_names, aggregation_window='Weekly')
163
+ aggregate_goalie_stats(session, aggregation_type='org', aggregation_id=org_id, names_to_filter_out=not_human_names)
164
+ aggregate_goalie_stats(session, aggregation_type='org', aggregation_id=org_id, names_to_filter_out=not_human_names, aggregation_window='Daily')
165
+ aggregate_goalie_stats(session, aggregation_type='org', aggregation_id=org_id, names_to_filter_out=not_human_names, aggregation_window='Weekly')
@@ -0,0 +1,296 @@
1
+ import sys, os
2
+
3
+ # Add the package directory to the Python path
4
+ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
5
+
6
+
7
+ from datetime import datetime, timedelta
8
+ import sqlalchemy
9
+ from hockey_blast_common_lib.models import Game, GameRoster
10
+ from stats_models import OrgStatsHuman, DivisionStatsHuman, OrgStatsDailyHuman, OrgStatsWeeklyHuman, DivisionStatsDailyHuman, DivisionStatsWeeklyHuman
11
+ from db_connection import create_session
12
+ from sqlalchemy.sql import func, case
13
+ from options import parse_args, MIN_GAMES_FOR_ORG_STATS, MIN_GAMES_FOR_DIVISION_STATS, not_human_names
14
+ from utils import get_org_id_from_alias, get_human_ids_by_names, get_division_ids_for_last_season_in_all_leagues
15
+ from db_utils import get_fake_human_for_stats
16
+
17
+ def aggregate_human_stats(session, aggregation_type, aggregation_id, names_to_filter_out, human_id_filter=None, aggregation_window=None):
18
+ human_ids_to_filter = get_human_ids_by_names(session, names_to_filter_out)
19
+
20
+ if aggregation_type == 'org':
21
+ if aggregation_window == 'Daily':
22
+ StatsModel = OrgStatsDailyHuman
23
+ elif aggregation_window == 'Weekly':
24
+ StatsModel = OrgStatsWeeklyHuman
25
+ else:
26
+ StatsModel = OrgStatsHuman
27
+ min_games = MIN_GAMES_FOR_ORG_STATS
28
+ filter_condition = Game.org_id == aggregation_id
29
+ elif aggregation_type == 'division':
30
+ if aggregation_window == 'Daily':
31
+ StatsModel = DivisionStatsDailyHuman
32
+ elif aggregation_window == 'Weekly':
33
+ StatsModel = DivisionStatsWeeklyHuman
34
+ else:
35
+ StatsModel = DivisionStatsHuman
36
+ min_games = MIN_GAMES_FOR_DIVISION_STATS
37
+ filter_condition = Game.division_id == aggregation_id
38
+ else:
39
+ raise ValueError("Invalid aggregation type")
40
+
41
+ # Delete existing items from the stats table
42
+ session.query(StatsModel).filter(StatsModel.aggregation_id == aggregation_id).delete()
43
+ session.commit()
44
+
45
+ # Filter for specific human_id if provided
46
+ human_filter = []
47
+ if human_id_filter:
48
+ human_filter = [GameRoster.human_id == human_id_filter]
49
+
50
+ # Filter games by status
51
+ game_status_filter = Game.status.like('Final%')
52
+
53
+ # Apply aggregation window filter
54
+ if aggregation_window:
55
+ last_game_datetime = session.query(func.max(func.concat(Game.date, ' ', Game.time))).filter(filter_condition, game_status_filter).scalar()
56
+ if last_game_datetime:
57
+ last_game_datetime = datetime.strptime(last_game_datetime, '%Y-%m-%d %H:%M:%S')
58
+ if aggregation_window == 'Daily':
59
+ start_datetime = last_game_datetime - timedelta(days=1)
60
+ elif aggregation_window == 'Weekly':
61
+ start_datetime = last_game_datetime - timedelta(weeks=1)
62
+ else:
63
+ start_datetime = None
64
+ if start_datetime:
65
+ game_window_filter = func.cast(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP).between(start_datetime, last_game_datetime)
66
+ filter_condition = filter_condition & game_window_filter
67
+
68
+ # Aggregate games played for each human in each role
69
+ human_stats = session.query(
70
+ GameRoster.human_id,
71
+ func.count(func.distinct(case((GameRoster.role != 'G', Game.id), else_=None))).label('games_skater'),
72
+ func.count(func.distinct(case((GameRoster.role == 'G', Game.id), else_=None))).label('games_goalie'),
73
+ func.array_agg(func.distinct(Game.id)).label('game_ids')
74
+ ).join(Game, GameRoster.game_id == Game.id).filter(filter_condition, game_status_filter, *human_filter).group_by(GameRoster.human_id).all()
75
+
76
+ # Aggregate referee and scorekeeper games from Game table
77
+ referee_stats = session.query(
78
+ Game.referee_1_id.label('human_id'),
79
+ func.count(func.distinct(Game.id)).label('games_referee'),
80
+ func.array_agg(func.distinct(Game.id)).label('referee_game_ids')
81
+ ).filter(filter_condition, game_status_filter, *human_filter).group_by(Game.referee_1_id).all()
82
+
83
+ referee_stats_2 = session.query(
84
+ Game.referee_2_id.label('human_id'),
85
+ func.count(func.distinct(Game.id)).label('games_referee'),
86
+ func.array_agg(func.distinct(Game.id)).label('referee_game_ids')
87
+ ).filter(filter_condition, game_status_filter, *human_filter).group_by(Game.referee_2_id).all()
88
+
89
+ scorekeeper_stats = session.query(
90
+ Game.scorekeeper_id.label('human_id'),
91
+ func.count(func.distinct(Game.id)).label('games_scorekeeper'),
92
+ func.array_agg(func.distinct(Game.id)).label('scorekeeper_game_ids')
93
+ ).filter(filter_condition, game_status_filter, *human_filter).group_by(Game.scorekeeper_id).all()
94
+
95
+ # Combine the results
96
+ stats_dict = {}
97
+ for stat in human_stats:
98
+ if stat.human_id in human_ids_to_filter:
99
+ continue
100
+ key = (aggregation_id, stat.human_id)
101
+ stats_dict[key] = {
102
+ 'games_total': stat.games_skater + stat.games_goalie,
103
+ 'games_skater': stat.games_skater,
104
+ 'games_goalie': stat.games_goalie,
105
+ 'games_referee': 0,
106
+ 'games_scorekeeper': 0,
107
+ 'game_ids': stat.game_ids,
108
+ 'referee_game_ids': [],
109
+ 'scorekeeper_game_ids': []
110
+ }
111
+
112
+ for stat in referee_stats:
113
+ if stat.human_id in human_ids_to_filter:
114
+ continue
115
+ key = (aggregation_id, stat.human_id)
116
+ if key not in stats_dict:
117
+ stats_dict[key] = {
118
+ 'games_total': stat.games_referee,
119
+ 'games_skater': 0,
120
+ 'games_goalie': 0,
121
+ 'games_referee': stat.games_referee,
122
+ 'games_scorekeeper': 0,
123
+ 'game_ids': [],
124
+ 'referee_game_ids': stat.referee_game_ids,
125
+ 'scorekeeper_game_ids': []
126
+ }
127
+ else:
128
+ stats_dict[key]['games_referee'] += stat.games_referee
129
+ stats_dict[key]['games_total'] += stat.games_referee
130
+ stats_dict[key]['referee_game_ids'] += stat.referee_game_ids
131
+
132
+ for stat in referee_stats_2:
133
+ if stat.human_id in human_ids_to_filter:
134
+ continue
135
+ key = (aggregation_id, stat.human_id)
136
+ if key not in stats_dict:
137
+ stats_dict[key] = {
138
+ 'games_total': stat.games_referee,
139
+ 'games_skater': 0,
140
+ 'games_goalie': 0,
141
+ 'games_referee': stat.games_referee,
142
+ 'games_scorekeeper': 0,
143
+ 'game_ids': [],
144
+ 'referee_game_ids': stat.referee_game_ids,
145
+ 'scorekeeper_game_ids': []
146
+ }
147
+ else:
148
+ stats_dict[key]['games_referee'] += stat.games_referee
149
+ stats_dict[key]['games_total'] += stat.games_referee
150
+ stats_dict[key]['referee_game_ids'] += stat.referee_game_ids
151
+
152
+ for stat in scorekeeper_stats:
153
+ if stat.human_id in human_ids_to_filter:
154
+ continue
155
+ key = (aggregation_id, stat.human_id)
156
+ if key not in stats_dict:
157
+ stats_dict[key] = {
158
+ 'games_total': stat.games_scorekeeper,
159
+ 'games_skater': 0,
160
+ 'games_goalie': 0,
161
+ 'games_referee': 0,
162
+ 'games_scorekeeper': stat.games_scorekeeper,
163
+ 'game_ids': [],
164
+ 'referee_game_ids': [],
165
+ 'scorekeeper_game_ids': stat.scorekeeper_game_ids
166
+ }
167
+ else:
168
+ stats_dict[key]['games_scorekeeper'] += stat.games_scorekeeper
169
+ stats_dict[key]['games_total'] += stat.games_scorekeeper
170
+ stats_dict[key]['scorekeeper_game_ids'] += stat.scorekeeper_game_ids
171
+
172
+ # Ensure all keys have valid human_id values
173
+ stats_dict = {key: value for key, value in stats_dict.items() if key[1] is not None}
174
+
175
+ # Calculate total_in_rank
176
+ total_in_rank = len(stats_dict)
177
+
178
+ # Assign ranks
179
+ def assign_ranks(stats_dict, field):
180
+ sorted_stats = sorted(stats_dict.items(), key=lambda x: x[1][field], reverse=True)
181
+ for rank, (key, stat) in enumerate(sorted_stats, start=1):
182
+ stats_dict[key][f'{field}_rank'] = rank
183
+
184
+ assign_ranks(stats_dict, 'games_total')
185
+ assign_ranks(stats_dict, 'games_skater')
186
+ assign_ranks(stats_dict, 'games_goalie')
187
+ assign_ranks(stats_dict, 'games_referee')
188
+ assign_ranks(stats_dict, 'games_scorekeeper')
189
+
190
+ # Populate first_game_id and last_game_id
191
+ for key, stat in stats_dict.items():
192
+ all_game_ids = stat['game_ids'] + stat['referee_game_ids'] + stat['scorekeeper_game_ids']
193
+ if all_game_ids:
194
+ first_game = session.query(Game).filter(Game.id.in_(all_game_ids)).order_by(Game.date, Game.time).first()
195
+ last_game = session.query(Game).filter(Game.id.in_(all_game_ids)).order_by(Game.date.desc(), Game.time.desc()).first()
196
+ stat['first_game_id'] = first_game.id if first_game else None
197
+ stat['last_game_id'] = last_game.id if last_game else None
198
+
199
+ # Insert aggregated stats into the appropriate table with progress output
200
+ total_items = len(stats_dict)
201
+ batch_size = 1000
202
+ for i, (key, stat) in enumerate(stats_dict.items(), 1):
203
+ aggregation_id, human_id = key
204
+ if human_id_filter and human_id != human_id_filter:
205
+ continue
206
+ if stat['games_total'] < min_games:
207
+ continue
208
+
209
+ human_stat = StatsModel(
210
+ aggregation_id=aggregation_id,
211
+ human_id=human_id,
212
+ games_total=stat['games_total'],
213
+ games_total_rank=stat['games_total_rank'],
214
+ games_skater=stat['games_skater'],
215
+ games_skater_rank=stat['games_skater_rank'],
216
+ games_goalie=stat['games_goalie'],
217
+ games_goalie_rank=stat['games_goalie_rank'],
218
+ games_referee=stat['games_referee'],
219
+ games_referee_rank=stat['games_referee_rank'],
220
+ games_scorekeeper=stat['games_scorekeeper'],
221
+ games_scorekeeper_rank=stat['games_scorekeeper_rank'],
222
+ total_in_rank=total_in_rank,
223
+ first_game_id=stat['first_game_id'],
224
+ last_game_id=stat['last_game_id']
225
+ )
226
+ session.add(human_stat)
227
+ # Commit in batches
228
+ if i % batch_size == 0:
229
+ session.commit()
230
+ print(f"\r{i}/{total_items} ({(i/total_items)*100:.2f}%)", end="")
231
+ session.commit()
232
+
233
+ # Fetch fake human ID for overall stats
234
+ fake_human_id = get_fake_human_for_stats(session)
235
+
236
+ # Calculate overall stats
237
+ overall_stats = {
238
+ 'games_total': sum(stat['games_total'] for stat in stats_dict.values()),
239
+ 'games_skater': sum(stat['games_skater'] for stat in stats_dict.values()),
240
+ 'games_goalie': sum(stat['games_goalie'] for stat in stats_dict.values()),
241
+ 'games_referee': sum(stat['games_referee'] for stat in stats_dict.values()),
242
+ 'games_scorekeeper': sum(stat['games_scorekeeper'] for stat in stats_dict.values()),
243
+ 'total_in_rank': total_in_rank,
244
+ 'first_game_id': None,
245
+ 'last_game_id': None
246
+ }
247
+
248
+ # Populate first_game_id and last_game_id for overall stats
249
+ all_game_ids = [game_id for stat in stats_dict.values() for game_id in stat['game_ids'] + stat['referee_game_ids'] + stat['scorekeeper_game_ids']]
250
+ if all_game_ids:
251
+ first_game = session.query(Game).filter(Game.id.in_(all_game_ids)).order_by(Game.date, Game.time).first()
252
+ last_game = session.query(Game).filter(Game.id.in_(all_game_ids)).order_by(Game.date.desc(), Game.time.desc()).first()
253
+ overall_stats['first_game_id'] = first_game.id if first_game else None
254
+ overall_stats['last_game_id'] = last_game.id if last_game else None
255
+
256
+ # Insert overall stats for the fake human
257
+ overall_human_stat = StatsModel(
258
+ aggregation_id=aggregation_id,
259
+ human_id=fake_human_id,
260
+ games_total=overall_stats['games_total'],
261
+ games_total_rank=0, # Overall stats do not need a rank
262
+ games_skater=overall_stats['games_skater'],
263
+ games_skater_rank=0, # Overall stats do not need a rank
264
+ games_goalie=overall_stats['games_goalie'],
265
+ games_goalie_rank=0, # Overall stats do not need a rank
266
+ games_referee=overall_stats['games_referee'],
267
+ games_referee_rank=0, # Overall stats do not need a rank
268
+ games_scorekeeper=overall_stats['games_scorekeeper'],
269
+ games_scorekeeper_rank=0, # Overall stats do not need a rank
270
+ total_in_rank=overall_stats['total_in_rank'],
271
+ first_game_id=overall_stats['first_game_id'],
272
+ last_game_id=overall_stats['last_game_id']
273
+ )
274
+ session.add(overall_human_stat)
275
+ session.commit()
276
+
277
+ print(f"\r{total_items}/{total_items} (100.00%)")
278
+ print("\nDone.")
279
+
280
+ # Example usage
281
+ if __name__ == "__main__":
282
+ args = parse_args()
283
+ org_alias=args.org
284
+ session = create_session("boss")
285
+ org_id = get_org_id_from_alias(session, org_alias)
286
+
287
+ division_ids = get_division_ids_for_last_season_in_all_leagues(session, org_id)
288
+ print(f"Aggregating human stats for {len(division_ids)} divisions in {org_alias}...")
289
+ for division_id in division_ids:
290
+ aggregate_human_stats(session, aggregation_type='division', aggregation_id=division_id, names_to_filter_out=not_human_names, human_id_filter=None)
291
+ aggregate_human_stats(session, aggregation_type='division', aggregation_id=division_id, names_to_filter_out=not_human_names, human_id_filter=None, aggregation_window='Daily')
292
+ aggregate_human_stats(session, aggregation_type='division', aggregation_id=division_id, names_to_filter_out=not_human_names, human_id_filter=None, aggregation_window='Weekly')
293
+
294
+ aggregate_human_stats(session, aggregation_type='org', aggregation_id=org_id, names_to_filter_out=not_human_names, human_id_filter=None)
295
+ aggregate_human_stats(session, aggregation_type='org', aggregation_id=org_id, names_to_filter_out=not_human_names, human_id_filter=None, aggregation_window='Daily')
296
+ aggregate_human_stats(session, aggregation_type='org', aggregation_id=org_id, names_to_filter_out=not_human_names, human_id_filter=None, aggregation_window='Weekly')