@nukleus-sports/core 0.2.1 → 0.4.0
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.
- package/dist/index.cjs +1380 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +528 -1
- package/dist/index.d.ts +528 -1
- package/dist/index.js +1319 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -98,13 +98,1286 @@ function abbreviatePersonName(name) {
|
|
|
98
98
|
const last = parts[1] ?? "";
|
|
99
99
|
return `${initial}. ${last}`;
|
|
100
100
|
}
|
|
101
|
+
|
|
102
|
+
// src/teamSeasonRecord.ts
|
|
103
|
+
var HOCKEY_LEAGUE_ID = 14;
|
|
104
|
+
var STATUS_FINAL = "3";
|
|
105
|
+
function computeSeasonSummary(games, espnId, leagueId) {
|
|
106
|
+
const totalGames = games.length;
|
|
107
|
+
const isHockey = leagueId === HOCKEY_LEAGUE_ID;
|
|
108
|
+
let wins = 0;
|
|
109
|
+
let losses = 0;
|
|
110
|
+
let otLosses = 0;
|
|
111
|
+
let ties = 0;
|
|
112
|
+
let completedGames = 0;
|
|
113
|
+
for (const game of games) {
|
|
114
|
+
const competition = game.game_details?.competitions?.[0];
|
|
115
|
+
const status = competition?.status?.type?.id;
|
|
116
|
+
const competitors = competition?.competitors;
|
|
117
|
+
if (status !== STATUS_FINAL || !competitors || competitors.length !== 2) continue;
|
|
118
|
+
const [c0, c1] = competitors;
|
|
119
|
+
const myCompetitor = c0.id === espnId ? c0 : c1.id === espnId ? c1 : null;
|
|
120
|
+
if (!myCompetitor) continue;
|
|
121
|
+
completedGames++;
|
|
122
|
+
if (c0.score.value === c1.score.value) {
|
|
123
|
+
ties++;
|
|
124
|
+
} else if (myCompetitor.winner === true) {
|
|
125
|
+
wins++;
|
|
126
|
+
} else if (isHockey && (competition?.status?.period ?? 0) > 3) {
|
|
127
|
+
otLosses++;
|
|
128
|
+
} else {
|
|
129
|
+
losses++;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const record = isHockey ? `${wins}-${losses}-${otLosses}` : ties > 0 ? `${wins}-${losses}-${ties}` : `${wins}-${losses}`;
|
|
133
|
+
return { record, gamesPlayed: completedGames, totalGames };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/teamRosterColumns.ts
|
|
137
|
+
var NFL_NBA_WNBA_LEAGUE_IDS = [1, 4, 5];
|
|
138
|
+
var MLB_NHL_LEAGUE_IDS = [7, 14];
|
|
139
|
+
var NCAAF_LEAGUE_IDS = [2, 13];
|
|
140
|
+
var NCAAM_LEAGUE_ID = 6;
|
|
141
|
+
var MLS_LEAGUE_ID = 10;
|
|
142
|
+
var MLB_LEAGUE_ID = 7;
|
|
143
|
+
var BASE_COLUMNS = [
|
|
144
|
+
{ key: "first_name", label: "Name" },
|
|
145
|
+
{ key: "number", label: "No." },
|
|
146
|
+
{ key: "position", label: "Position" },
|
|
147
|
+
{ key: "height", label: "Height" },
|
|
148
|
+
{ key: "weight", label: "Weight" },
|
|
149
|
+
{ key: "age", label: "Age" }
|
|
150
|
+
];
|
|
151
|
+
function getRosterColumns(leagueId) {
|
|
152
|
+
if (NFL_NBA_WNBA_LEAGUE_IDS.includes(leagueId)) {
|
|
153
|
+
return [
|
|
154
|
+
...BASE_COLUMNS,
|
|
155
|
+
{ key: "experience", label: "Exp." },
|
|
156
|
+
{ key: "college", label: "College" }
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
if (MLB_NHL_LEAGUE_IDS.includes(leagueId)) {
|
|
160
|
+
return [
|
|
161
|
+
...BASE_COLUMNS,
|
|
162
|
+
{ key: "experience", label: "Exp" },
|
|
163
|
+
{ key: "birthplace", label: "Birthplace" }
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
if (NCAAF_LEAGUE_IDS.includes(leagueId)) {
|
|
167
|
+
return [
|
|
168
|
+
...BASE_COLUMNS,
|
|
169
|
+
{ key: "experience", label: "Class" },
|
|
170
|
+
{ key: "hometown", label: "Hometown" }
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
if (leagueId === NCAAM_LEAGUE_ID) {
|
|
174
|
+
return [
|
|
175
|
+
...BASE_COLUMNS,
|
|
176
|
+
{ key: "experience", label: "Class" },
|
|
177
|
+
{ key: "birthplace", label: "Birthplace" }
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
if (leagueId === MLS_LEAGUE_ID) {
|
|
181
|
+
return [...BASE_COLUMNS, { key: "birthplace", label: "Birthplace" }];
|
|
182
|
+
}
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
function calculateAge(birthDateString) {
|
|
186
|
+
const birthDate = new Date(birthDateString);
|
|
187
|
+
const today = /* @__PURE__ */ new Date();
|
|
188
|
+
let age = today.getFullYear() - birthDate.getFullYear();
|
|
189
|
+
const monthDiff = today.getMonth() - birthDate.getMonth();
|
|
190
|
+
if (monthDiff < 0 || monthDiff === 0 && today.getDate() < birthDate.getDate()) {
|
|
191
|
+
age--;
|
|
192
|
+
}
|
|
193
|
+
return age;
|
|
194
|
+
}
|
|
195
|
+
function formatBirthplace(specificData, leagueId) {
|
|
196
|
+
if (!specificData) return "--";
|
|
197
|
+
if (leagueId === MLS_LEAGUE_ID) {
|
|
198
|
+
const country2 = specificData.birth_country;
|
|
199
|
+
return country2 ? String(country2).trim() : "--";
|
|
200
|
+
}
|
|
201
|
+
const city = typeof specificData.birth_city === "string" ? specificData.birth_city.trim() : "";
|
|
202
|
+
const state = typeof specificData.birth_state === "string" ? specificData.birth_state.trim() : "";
|
|
203
|
+
const country = typeof specificData.birth_country === "string" ? specificData.birth_country.trim() : "";
|
|
204
|
+
const hasCity = city.length > 0;
|
|
205
|
+
const hasState = state.length > 0;
|
|
206
|
+
const hasCountry = country.length > 0;
|
|
207
|
+
const isUsa = country === "USA" || country === "United States";
|
|
208
|
+
if (!hasCity && !hasState) {
|
|
209
|
+
if (hasCountry && leagueId === MLB_LEAGUE_ID && isUsa) return "--";
|
|
210
|
+
return hasCountry ? country : "--";
|
|
211
|
+
}
|
|
212
|
+
let result = "";
|
|
213
|
+
if (hasCity && hasState) result = `${city}, ${state}`;
|
|
214
|
+
else if (hasCity) result = city;
|
|
215
|
+
else if (hasState) result = state;
|
|
216
|
+
if (hasCountry) {
|
|
217
|
+
const excludeCountry = leagueId === MLB_LEAGUE_ID ? isUsa : country === "USA";
|
|
218
|
+
if (!excludeCountry) {
|
|
219
|
+
if (hasState) result += ` ${country}`;
|
|
220
|
+
else if (hasCity) result += `, ${country}`;
|
|
221
|
+
else result += ` ${country}`;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return result || "--";
|
|
225
|
+
}
|
|
226
|
+
function formatHometown(specificData) {
|
|
227
|
+
if (!specificData) return "--";
|
|
228
|
+
const city = specificData.birth_city || "";
|
|
229
|
+
const state = specificData.birth_state || "";
|
|
230
|
+
if (city && state) return `${city}, ${state}`;
|
|
231
|
+
if (city) return city;
|
|
232
|
+
if (state) return state;
|
|
233
|
+
return "--";
|
|
234
|
+
}
|
|
235
|
+
function getRosterCellValue(player, columnKey, leagueId) {
|
|
236
|
+
switch (columnKey) {
|
|
237
|
+
case "first_name":
|
|
238
|
+
return player.first_name ? [player.first_name, player.last_name].filter(Boolean).join(" ") : "-";
|
|
239
|
+
case "number":
|
|
240
|
+
return player.number !== null && player.number !== void 0 && player.number !== "" ? String(player.number) : "-";
|
|
241
|
+
case "position":
|
|
242
|
+
return player.position || "-";
|
|
243
|
+
case "height":
|
|
244
|
+
return player.specific_data?.height ? String(player.specific_data.height) : "-";
|
|
245
|
+
case "weight":
|
|
246
|
+
return player.specific_data?.weight ? `${player.specific_data.weight} lbs` : "-";
|
|
247
|
+
case "age":
|
|
248
|
+
return player.specific_data?.birth_date ? String(calculateAge(player.specific_data.birth_date)) : "-";
|
|
249
|
+
case "experience":
|
|
250
|
+
return player.experience === "0" ? "R" : player.experience || "-";
|
|
251
|
+
case "college":
|
|
252
|
+
return player.specific_data?.college_name || "-";
|
|
253
|
+
case "birthplace":
|
|
254
|
+
return formatBirthplace(player.specific_data ?? null, leagueId);
|
|
255
|
+
case "hometown":
|
|
256
|
+
return formatHometown(player.specific_data ?? null);
|
|
257
|
+
default:
|
|
258
|
+
return "-";
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// src/jsonValue.ts
|
|
263
|
+
function isJsonRecord(value) {
|
|
264
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
265
|
+
}
|
|
266
|
+
function toJsonRecord(value) {
|
|
267
|
+
return isJsonRecord(value) ? value : {};
|
|
268
|
+
}
|
|
269
|
+
function toTrimmedText(value) {
|
|
270
|
+
if (typeof value !== "string") return null;
|
|
271
|
+
const trimmed = value.trim();
|
|
272
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// src/teamPlaceSummary.ts
|
|
276
|
+
var TEAM_PLACE_PARTS = ["name", "street", "city", "state", "zipcode"];
|
|
277
|
+
var EMPTY_TEAM_PLACE = { name: "", street: "", city: "", state: "", zipcode: "" };
|
|
278
|
+
var ARENA_LEAGUES = /* @__PURE__ */ new Set(["NBA", "WNBA", "NCAAM", "NHL"]);
|
|
279
|
+
function isCollegeLeague(abbreviation) {
|
|
280
|
+
return abbreviation.startsWith("NCAA");
|
|
281
|
+
}
|
|
282
|
+
function getTeamVenueConfig(leagueAbbreviation) {
|
|
283
|
+
return leagueAbbreviation && ARENA_LEAGUES.has(leagueAbbreviation) ? { kind: "arena", label: "Arena" } : { kind: "stadium", label: "Stadium" };
|
|
284
|
+
}
|
|
285
|
+
function getTeamFacilityConfig(leagueAbbreviation) {
|
|
286
|
+
return leagueAbbreviation && isCollegeLeague(leagueAbbreviation) ? { kind: "coaches_facility", label: "Coaches Facility" } : { kind: "training_facility", label: "Training Facility" };
|
|
287
|
+
}
|
|
288
|
+
function teamPlaceKey(kind, part) {
|
|
289
|
+
return `${kind}_${part}`;
|
|
290
|
+
}
|
|
291
|
+
function parseTeamPlace(specificData, kind) {
|
|
292
|
+
const place = { ...EMPTY_TEAM_PLACE };
|
|
293
|
+
for (const part of TEAM_PLACE_PARTS) {
|
|
294
|
+
const value = specificData[teamPlaceKey(kind, part)];
|
|
295
|
+
place[part] = typeof value === "string" ? value : "";
|
|
296
|
+
}
|
|
297
|
+
return place;
|
|
298
|
+
}
|
|
299
|
+
function formatTeamPlaceAddress(place) {
|
|
300
|
+
return [place.street, place.city, place.state, place.zipcode].map((part) => part.trim()).filter(Boolean).join(", ");
|
|
301
|
+
}
|
|
302
|
+
function summarize(label, place) {
|
|
303
|
+
const name = place.name.trim();
|
|
304
|
+
return { label, name: name || null, address: name ? formatTeamPlaceAddress(place) : "" };
|
|
305
|
+
}
|
|
306
|
+
function getTeamPlaceSummaries(specificData, leagueAbbreviation) {
|
|
307
|
+
const data = toJsonRecord(specificData);
|
|
308
|
+
const venue = getTeamVenueConfig(leagueAbbreviation);
|
|
309
|
+
const facility = getTeamFacilityConfig(leagueAbbreviation);
|
|
310
|
+
return {
|
|
311
|
+
venue: summarize(venue.label, parseTeamPlace(data, venue.kind)),
|
|
312
|
+
facility: summarize(facility.label, parseTeamPlace(data, facility.kind))
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function formatTeamName(team, nickname) {
|
|
316
|
+
return [team, nickname].map((part) => part?.trim()).filter(Boolean).join(" ");
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/teamStaffSort.ts
|
|
320
|
+
var EMPTY_VALUES = /* @__PURE__ */ new Set(["", "-"]);
|
|
321
|
+
function compareValues(left, right, desc) {
|
|
322
|
+
const leftMissing = typeof left === "string" && EMPTY_VALUES.has(left);
|
|
323
|
+
const rightMissing = typeof right === "string" && EMPTY_VALUES.has(right);
|
|
324
|
+
if (leftMissing && rightMissing) return 0;
|
|
325
|
+
if (leftMissing) return 1;
|
|
326
|
+
if (rightMissing) return -1;
|
|
327
|
+
const direction = desc ? -1 : 1;
|
|
328
|
+
if (typeof left === "number" && typeof right === "number") {
|
|
329
|
+
return (left - right) * direction;
|
|
330
|
+
}
|
|
331
|
+
return String(left).localeCompare(String(right), void 0, { numeric: true, sensitivity: "base" }) * direction;
|
|
332
|
+
}
|
|
333
|
+
function sortTeamStaff(staff, sorting) {
|
|
334
|
+
const activeSort = sorting[0];
|
|
335
|
+
if (!activeSort) return staff;
|
|
336
|
+
return [...staff].sort((left, right) => {
|
|
337
|
+
const value = (member) => {
|
|
338
|
+
switch (activeSort.id) {
|
|
339
|
+
case "name":
|
|
340
|
+
return `${member.first_name} ${member.last_name}`.trim();
|
|
341
|
+
case "position":
|
|
342
|
+
return member.position ?? "-";
|
|
343
|
+
default:
|
|
344
|
+
return member.display_order;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
return compareValues(value(left), value(right), activeSort.desc);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// src/teamSeasonStats.ts
|
|
352
|
+
var FOOTBALL_TEAM_STAT_IDS = {
|
|
353
|
+
PASSING_YARDS: 255,
|
|
354
|
+
RUSHING_YARDS: 261,
|
|
355
|
+
POINTS_FOR: 271,
|
|
356
|
+
POINTS_AGAINST: 272
|
|
357
|
+
};
|
|
358
|
+
var BASKETBALL_TEAM_STAT_IDS = {
|
|
359
|
+
POINTS_FOR: 300,
|
|
360
|
+
REBOUNDS: 279,
|
|
361
|
+
ASSISTS: 285,
|
|
362
|
+
POINTS_AGAINST: 301
|
|
363
|
+
};
|
|
364
|
+
var BASEBALL_TEAM_STAT_IDS = {
|
|
365
|
+
HITS: 303,
|
|
366
|
+
AT_BATS: 308,
|
|
367
|
+
HOMERUNS: 309,
|
|
368
|
+
STRIKEOUTS: 315,
|
|
369
|
+
EARNED_RUNS: 317,
|
|
370
|
+
INNINGS_PITCHED: 325
|
|
371
|
+
};
|
|
372
|
+
var HOCKEY_TEAM_STAT_IDS = {
|
|
373
|
+
GOALS_FOR: 346,
|
|
374
|
+
GOALS_AGAINST: 347,
|
|
375
|
+
SHOTS: 332,
|
|
376
|
+
POWER_PLAY_GOALS: 334,
|
|
377
|
+
POWER_PLAY_ATTEMPTS: 336
|
|
378
|
+
};
|
|
379
|
+
var TEAM_RANKING_CONFIG_IDS = {
|
|
380
|
+
1: {
|
|
381
|
+
1: [100, 101, 102, 103],
|
|
382
|
+
// NFL
|
|
383
|
+
2: [104, 105, 106, 107],
|
|
384
|
+
// NCAAF (FBS)
|
|
385
|
+
13: [108, 109, 110, 111]
|
|
386
|
+
// NCAAF (FCS)
|
|
387
|
+
},
|
|
388
|
+
2: {
|
|
389
|
+
4: [112, 113, 114, 115],
|
|
390
|
+
// NBA
|
|
391
|
+
5: [116, 117, 118, 119],
|
|
392
|
+
// WNBA
|
|
393
|
+
6: [120, 121, 122, 123]
|
|
394
|
+
// NCAAM
|
|
395
|
+
},
|
|
396
|
+
3: { 7: [124, 125, 126, 127] },
|
|
397
|
+
// MLB
|
|
398
|
+
5: { 14: [128, 129, 130, 131] }
|
|
399
|
+
// NHL
|
|
400
|
+
};
|
|
401
|
+
function getTeamRankingConfigIds(sportId, leagueId) {
|
|
402
|
+
if (!sportId || !leagueId) return null;
|
|
403
|
+
const ids = TEAM_RANKING_CONFIG_IDS[sportId]?.[leagueId];
|
|
404
|
+
return ids ? [...ids] : null;
|
|
405
|
+
}
|
|
406
|
+
var SUPPORTED_TEAM_STATS_SPORT_IDS = [1, 2, 3, 5];
|
|
407
|
+
function isSupportedTeamStatsSport(sportId) {
|
|
408
|
+
return SUPPORTED_TEAM_STATS_SPORT_IDS.includes(sportId);
|
|
409
|
+
}
|
|
410
|
+
function getTeamStatColumns(sportId) {
|
|
411
|
+
if (sportId === 1) {
|
|
412
|
+
return [
|
|
413
|
+
{ label: "Passing Yards" },
|
|
414
|
+
{ label: "Rushing Yards" },
|
|
415
|
+
{ label: "Points For" },
|
|
416
|
+
{ label: "Points Against" }
|
|
417
|
+
];
|
|
418
|
+
}
|
|
419
|
+
if (sportId === 2) {
|
|
420
|
+
return [
|
|
421
|
+
{ label: "Points For" },
|
|
422
|
+
{ label: "Points Against" },
|
|
423
|
+
{ label: "Rebounds" },
|
|
424
|
+
{ label: "Assists" }
|
|
425
|
+
];
|
|
426
|
+
}
|
|
427
|
+
if (sportId === 3) {
|
|
428
|
+
return [
|
|
429
|
+
{ label: "Batting Average" },
|
|
430
|
+
{ label: "Homeruns" },
|
|
431
|
+
{ label: "ERA" },
|
|
432
|
+
{ label: "Strikeouts" }
|
|
433
|
+
];
|
|
434
|
+
}
|
|
435
|
+
if (sportId === 5) {
|
|
436
|
+
return [
|
|
437
|
+
{ label: "Goals For" },
|
|
438
|
+
{ label: "Goals Against" },
|
|
439
|
+
{ label: "Shots" },
|
|
440
|
+
{ label: "Power Play %" }
|
|
441
|
+
];
|
|
442
|
+
}
|
|
443
|
+
return [];
|
|
444
|
+
}
|
|
445
|
+
function sumStatsByIds(statsData, idMap) {
|
|
446
|
+
const totals = {};
|
|
447
|
+
const idToKey = {};
|
|
448
|
+
for (const [key, id] of Object.entries(idMap)) {
|
|
449
|
+
idToKey[id] = key;
|
|
450
|
+
totals[key] = 0;
|
|
451
|
+
}
|
|
452
|
+
for (const record of statsData) {
|
|
453
|
+
const stats = record.stat_details?.stats ?? [];
|
|
454
|
+
for (const s of stats) {
|
|
455
|
+
const key = idToKey[s.stat_id];
|
|
456
|
+
if (key) totals[key] += parseFloat(String(s.stat_value ?? 0));
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return totals;
|
|
460
|
+
}
|
|
461
|
+
function parseInningsPitched(value) {
|
|
462
|
+
const numValue = typeof value === "string" ? parseFloat(value) : value;
|
|
463
|
+
if (isNaN(numValue)) return { wholeInnings: 0, thirds: 0 };
|
|
464
|
+
const wholeInnings = Math.floor(numValue);
|
|
465
|
+
const decimalPart = Math.round((numValue - wholeInnings) * 10);
|
|
466
|
+
return { wholeInnings, thirds: decimalPart };
|
|
467
|
+
}
|
|
468
|
+
function computeFootball(statsData) {
|
|
469
|
+
const totals = sumStatsByIds(statsData, FOOTBALL_TEAM_STAT_IDS);
|
|
470
|
+
const g = statsData.length;
|
|
471
|
+
const avg = (key) => g > 0 ? (totals[key] / g).toFixed(1) : "0.0";
|
|
472
|
+
return {
|
|
473
|
+
values: [avg("PASSING_YARDS"), avg("RUSHING_YARDS"), avg("POINTS_FOR"), avg("POINTS_AGAINST")]
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function computeBasketball(statsData) {
|
|
477
|
+
const totals = sumStatsByIds(statsData, BASKETBALL_TEAM_STAT_IDS);
|
|
478
|
+
const g = statsData.length;
|
|
479
|
+
const avg = (key) => g > 0 ? (totals[key] / g).toFixed(1) : "0.0";
|
|
480
|
+
return { values: [avg("POINTS_FOR"), avg("POINTS_AGAINST"), avg("REBOUNDS"), avg("ASSISTS")] };
|
|
481
|
+
}
|
|
482
|
+
function computeBaseball(statsData) {
|
|
483
|
+
let totalHits = 0;
|
|
484
|
+
let totalAtBats = 0;
|
|
485
|
+
let totalHomeruns = 0;
|
|
486
|
+
let totalStrikeouts = 0;
|
|
487
|
+
let totalEarnedRuns = 0;
|
|
488
|
+
let totalWholeInnings = 0;
|
|
489
|
+
let totalThirds = 0;
|
|
490
|
+
for (const record of statsData) {
|
|
491
|
+
const stats = record.stat_details?.stats ?? [];
|
|
492
|
+
for (const s of stats) {
|
|
493
|
+
const numValue = parseFloat(String(s.stat_value ?? 0));
|
|
494
|
+
if (s.stat_id === BASEBALL_TEAM_STAT_IDS.HITS) totalHits += numValue;
|
|
495
|
+
if (s.stat_id === BASEBALL_TEAM_STAT_IDS.AT_BATS) totalAtBats += numValue;
|
|
496
|
+
if (s.stat_id === BASEBALL_TEAM_STAT_IDS.HOMERUNS) totalHomeruns += numValue;
|
|
497
|
+
if (s.stat_id === BASEBALL_TEAM_STAT_IDS.STRIKEOUTS) totalStrikeouts += numValue;
|
|
498
|
+
if (s.stat_id === BASEBALL_TEAM_STAT_IDS.EARNED_RUNS) totalEarnedRuns += numValue;
|
|
499
|
+
if (s.stat_id === BASEBALL_TEAM_STAT_IDS.INNINGS_PITCHED) {
|
|
500
|
+
const { wholeInnings, thirds } = parseInningsPitched(s.stat_value ?? 0);
|
|
501
|
+
totalWholeInnings += wholeInnings;
|
|
502
|
+
totalThirds += thirds;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
const battingAverage = totalAtBats > 0 ? totalHits / totalAtBats : 0;
|
|
507
|
+
const additionalWholeInnings = Math.floor(totalThirds / 3);
|
|
508
|
+
const remainderThirds = totalThirds % 3;
|
|
509
|
+
const totalInningsPitched = totalWholeInnings + additionalWholeInnings + remainderThirds / 3;
|
|
510
|
+
const era = totalInningsPitched > 0 ? totalEarnedRuns * 9 / totalInningsPitched : 0;
|
|
511
|
+
return {
|
|
512
|
+
values: [
|
|
513
|
+
battingAverage.toFixed(3),
|
|
514
|
+
totalHomeruns.toString(),
|
|
515
|
+
era.toFixed(2),
|
|
516
|
+
totalStrikeouts.toString()
|
|
517
|
+
]
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
function computeHockey(statsData) {
|
|
521
|
+
const totals = sumStatsByIds(statsData, HOCKEY_TEAM_STAT_IDS);
|
|
522
|
+
const g = statsData.length;
|
|
523
|
+
const avg = (key) => g > 0 ? (totals[key] / g).toFixed(1) : "0.0";
|
|
524
|
+
const ppPct = totals["POWER_PLAY_ATTEMPTS"] > 0 ? (totals["POWER_PLAY_GOALS"] / totals["POWER_PLAY_ATTEMPTS"] * 100).toFixed(1) : "0.0";
|
|
525
|
+
return { values: [avg("GOALS_FOR"), avg("GOALS_AGAINST"), avg("SHOTS"), ppPct] };
|
|
526
|
+
}
|
|
527
|
+
function computeTeamSeasonStats(statsData, sportId) {
|
|
528
|
+
if (!statsData || statsData.length === 0) return null;
|
|
529
|
+
if (sportId === 1) return computeFootball(statsData);
|
|
530
|
+
if (sportId === 2) return computeBasketball(statsData);
|
|
531
|
+
if (sportId === 3) return computeBaseball(statsData);
|
|
532
|
+
if (sportId === 5) return computeHockey(statsData);
|
|
533
|
+
return null;
|
|
534
|
+
}
|
|
535
|
+
function summaryTotal(totals, statId) {
|
|
536
|
+
const entry = totals[String(statId)];
|
|
537
|
+
if (!entry) return 0;
|
|
538
|
+
const raw = entry.sum ?? entry.value ?? entry.avg ?? entry.num;
|
|
539
|
+
const parsed = typeof raw === "number" ? raw : parseFloat(String(raw ?? ""));
|
|
540
|
+
return Number.isNaN(parsed) ? 0 : parsed;
|
|
541
|
+
}
|
|
542
|
+
function computeTeamSeasonStatsFromSummary(summary, sportId) {
|
|
543
|
+
if (!summary || !summary.stat_totals) return null;
|
|
544
|
+
const totals = summary.stat_totals;
|
|
545
|
+
const g = summary.games_played || 0;
|
|
546
|
+
const avgOf = (statId) => g > 0 ? (summaryTotal(totals, statId) / g).toFixed(1) : "0.0";
|
|
547
|
+
if (sportId === 1) {
|
|
548
|
+
return {
|
|
549
|
+
values: [
|
|
550
|
+
avgOf(FOOTBALL_TEAM_STAT_IDS.PASSING_YARDS),
|
|
551
|
+
avgOf(FOOTBALL_TEAM_STAT_IDS.RUSHING_YARDS),
|
|
552
|
+
avgOf(FOOTBALL_TEAM_STAT_IDS.POINTS_FOR),
|
|
553
|
+
avgOf(FOOTBALL_TEAM_STAT_IDS.POINTS_AGAINST)
|
|
554
|
+
]
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
if (sportId === 2) {
|
|
558
|
+
return {
|
|
559
|
+
values: [
|
|
560
|
+
avgOf(BASKETBALL_TEAM_STAT_IDS.POINTS_FOR),
|
|
561
|
+
avgOf(BASKETBALL_TEAM_STAT_IDS.POINTS_AGAINST),
|
|
562
|
+
avgOf(BASKETBALL_TEAM_STAT_IDS.REBOUNDS),
|
|
563
|
+
avgOf(BASKETBALL_TEAM_STAT_IDS.ASSISTS)
|
|
564
|
+
]
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
if (sportId === 3) {
|
|
568
|
+
const hits = summaryTotal(totals, BASEBALL_TEAM_STAT_IDS.HITS);
|
|
569
|
+
const atBats = summaryTotal(totals, BASEBALL_TEAM_STAT_IDS.AT_BATS);
|
|
570
|
+
const earnedRuns = summaryTotal(totals, BASEBALL_TEAM_STAT_IDS.EARNED_RUNS);
|
|
571
|
+
const innings = summaryTotal(totals, BASEBALL_TEAM_STAT_IDS.INNINGS_PITCHED);
|
|
572
|
+
const battingAverage = atBats > 0 ? hits / atBats : 0;
|
|
573
|
+
const era = innings > 0 ? earnedRuns * 9 / innings : 0;
|
|
574
|
+
return {
|
|
575
|
+
values: [
|
|
576
|
+
battingAverage.toFixed(3),
|
|
577
|
+
summaryTotal(totals, BASEBALL_TEAM_STAT_IDS.HOMERUNS).toString(),
|
|
578
|
+
era.toFixed(2),
|
|
579
|
+
summaryTotal(totals, BASEBALL_TEAM_STAT_IDS.STRIKEOUTS).toString()
|
|
580
|
+
]
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
if (sportId === 5) {
|
|
584
|
+
const ppGoals = summaryTotal(totals, HOCKEY_TEAM_STAT_IDS.POWER_PLAY_GOALS);
|
|
585
|
+
const ppAttempts = summaryTotal(totals, HOCKEY_TEAM_STAT_IDS.POWER_PLAY_ATTEMPTS);
|
|
586
|
+
return {
|
|
587
|
+
values: [
|
|
588
|
+
avgOf(HOCKEY_TEAM_STAT_IDS.GOALS_FOR),
|
|
589
|
+
avgOf(HOCKEY_TEAM_STAT_IDS.GOALS_AGAINST),
|
|
590
|
+
avgOf(HOCKEY_TEAM_STAT_IDS.SHOTS),
|
|
591
|
+
ppAttempts > 0 ? (ppGoals / ppAttempts * 100).toFixed(1) : "0.0"
|
|
592
|
+
]
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// src/teamStatsTable.ts
|
|
599
|
+
var HIDDEN_TEAM_STAT_TYPES_CONFIG = {
|
|
600
|
+
// Football (sport_id = 1)
|
|
601
|
+
1: [250, 253, 254, 263, 264, 271, 272, 268, 257, 267],
|
|
602
|
+
// Basketball (sport_id = 2)
|
|
603
|
+
2: [293, 295, 297, 300, 281, 283],
|
|
604
|
+
// Baseball (sport_id = 3)
|
|
605
|
+
3: [307, 311, 312, 319, 320, 321],
|
|
606
|
+
// Hockey (sport_id = 5)
|
|
607
|
+
5: [338, 340, 346]
|
|
608
|
+
};
|
|
609
|
+
var TEAM_STAT_DISPLAY_ORDER_CONFIG = {
|
|
610
|
+
// Football (sport_id = 1)
|
|
611
|
+
1: {
|
|
612
|
+
offense: [251, 255, 261, 244, 246, 248, 266, 268, 257, 259, 265, 270],
|
|
613
|
+
defense: [252, 256, 262, 245, 247, 249, 267, 269, 258, 260]
|
|
614
|
+
},
|
|
615
|
+
// Hockey (sport_id = 5)
|
|
616
|
+
5: {
|
|
617
|
+
offense: [332, 334, 336, 328, 326, 330, 342, 344]
|
|
618
|
+
},
|
|
619
|
+
// Baseball (sport_id = 3)
|
|
620
|
+
3: {
|
|
621
|
+
batting: [303, 308, 304, 309, 306, 302, 310, 305, 313],
|
|
622
|
+
pitching: [325, 323, 316, 324, 317, 322, 318, 315, 314]
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
var SPORTS_WITHOUT_STAT_CATEGORIES = [2, 5];
|
|
626
|
+
function getVisibleTeamStatTypes(statTypes, sportId) {
|
|
627
|
+
const hidden = new Set(HIDDEN_TEAM_STAT_TYPES_CONFIG[sportId] ?? []);
|
|
628
|
+
return statTypes.filter((statType) => statType.sport_id === sportId && !hidden.has(statType.id));
|
|
629
|
+
}
|
|
630
|
+
function getOrderedTeamStatTypesForCategory(statTypes, sportId, category) {
|
|
631
|
+
const filtered = statTypes.filter((statType) => statType.type_source_name === category);
|
|
632
|
+
const order = TEAM_STAT_DISPLAY_ORDER_CONFIG[sportId]?.[category];
|
|
633
|
+
if (!order) return filtered;
|
|
634
|
+
return [...filtered].sort((a, b) => {
|
|
635
|
+
const indexA = order.indexOf(a.id);
|
|
636
|
+
const indexB = order.indexOf(b.id);
|
|
637
|
+
if (indexA !== -1 && indexB !== -1) return indexA - indexB;
|
|
638
|
+
if (indexA !== -1) return -1;
|
|
639
|
+
if (indexB !== -1) return 1;
|
|
640
|
+
return a.id - b.id;
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
function showsTeamStatCategoryPicker(sportId) {
|
|
644
|
+
return !SPORTS_WITHOUT_STAT_CATEGORIES.includes(sportId);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// src/teamSeasonSelector.ts
|
|
648
|
+
function getPreferredSeasonType(types) {
|
|
649
|
+
if (types.length === 0) return null;
|
|
650
|
+
if (types.includes(2)) return 2;
|
|
651
|
+
return Math.max(...types);
|
|
652
|
+
}
|
|
653
|
+
function getSeasonYearOptions(seasons) {
|
|
654
|
+
const years = [...new Set(seasons.map((s) => s.season_year))].sort((a, b) => b - a);
|
|
655
|
+
return years.map((year) => ({
|
|
656
|
+
value: year,
|
|
657
|
+
label: seasons.find((s) => s.season_year === year)?.year_display ?? String(year)
|
|
658
|
+
}));
|
|
659
|
+
}
|
|
660
|
+
function getSeasonTypeOptions(seasons, selectedYear) {
|
|
661
|
+
if (selectedYear === null) return [];
|
|
662
|
+
return seasons.filter((s) => s.season_year === selectedYear).sort((a, b) => b.season_type - a.season_type).map((s) => ({ value: s.season_type, label: s.type_name }));
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// src/recentGamesSelection.ts
|
|
666
|
+
function selectRecentGames(upcomingGames, pastGames) {
|
|
667
|
+
let selectedPastGames;
|
|
668
|
+
let selectedUpcomingGames;
|
|
669
|
+
if (upcomingGames.length >= 3 && pastGames.length >= 3) {
|
|
670
|
+
selectedPastGames = pastGames.slice(0, 3);
|
|
671
|
+
selectedUpcomingGames = upcomingGames.slice(0, 3);
|
|
672
|
+
} else if (upcomingGames.length < 3) {
|
|
673
|
+
selectedUpcomingGames = upcomingGames;
|
|
674
|
+
selectedPastGames = pastGames.slice(0, Math.min(6 - upcomingGames.length, pastGames.length));
|
|
675
|
+
} else {
|
|
676
|
+
selectedPastGames = pastGames;
|
|
677
|
+
selectedUpcomingGames = upcomingGames.slice(
|
|
678
|
+
0,
|
|
679
|
+
Math.min(6 - pastGames.length, upcomingGames.length)
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
return [...[...selectedPastGames].reverse(), ...selectedUpcomingGames];
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// src/statRanking.ts
|
|
686
|
+
function toOrdinal(rank) {
|
|
687
|
+
const mod10 = rank % 10;
|
|
688
|
+
const mod100 = rank % 100;
|
|
689
|
+
if (mod10 === 1 && mod100 !== 11) return `${rank}st`;
|
|
690
|
+
if (mod10 === 2 && mod100 !== 12) return `${rank}nd`;
|
|
691
|
+
if (mod10 === 3 && mod100 !== 13) return `${rank}rd`;
|
|
692
|
+
return `${rank}th`;
|
|
693
|
+
}
|
|
694
|
+
function formatOrdinal(rank, tied) {
|
|
695
|
+
return tied ? `T-${toOrdinal(rank)}` : toOrdinal(rank);
|
|
696
|
+
}
|
|
697
|
+
function formatStatRank(rankings, statTypeId) {
|
|
698
|
+
const ranking = rankings.find((r) => r.stat_type_id === statTypeId);
|
|
699
|
+
return ranking ? formatOrdinal(ranking.rank, ranking.tied) : null;
|
|
700
|
+
}
|
|
701
|
+
function formatStatRankByConfig(rankings, configId) {
|
|
702
|
+
const ranking = rankings.find((r) => r.config_id === configId);
|
|
703
|
+
return ranking ? formatOrdinal(ranking.rank, ranking.tied) : null;
|
|
704
|
+
}
|
|
705
|
+
function formatStatNumber(value, decimals, isPercent, locale) {
|
|
706
|
+
const places = isPercent ? 1 : decimals !== null && decimals >= 0 ? decimals : value % 1 === 0 ? 0 : 1;
|
|
707
|
+
return value.toLocaleString(locale, {
|
|
708
|
+
minimumFractionDigits: places,
|
|
709
|
+
maximumFractionDigits: places
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
function topPercentileLabel(rank, total) {
|
|
713
|
+
if (!rank || !total || rank < 1 || total < 1) return null;
|
|
714
|
+
const percentile = rank / total * 100;
|
|
715
|
+
if (percentile <= 10) return "Top 10%";
|
|
716
|
+
if (percentile <= 20) return "Top 20%";
|
|
717
|
+
return null;
|
|
718
|
+
}
|
|
719
|
+
function getStatRankingFootnotes(config) {
|
|
720
|
+
const footnotes = [];
|
|
721
|
+
if (config?.position_filter && config.position_filter.length > 0) {
|
|
722
|
+
footnotes.push(`Filtered by position: ${config.position_filter.join(", ")}`);
|
|
723
|
+
}
|
|
724
|
+
if (config?.minimum_games && config.minimum_games > 0) {
|
|
725
|
+
footnotes.push(`Min. ${config.minimum_games}% of team games played`);
|
|
726
|
+
}
|
|
727
|
+
return footnotes;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// src/teamFacts.ts
|
|
731
|
+
var EMPTY_TEAM_FACTS = {
|
|
732
|
+
championships_won: null,
|
|
733
|
+
championship_years: [],
|
|
734
|
+
other_national_titles: null,
|
|
735
|
+
other_title_years: [],
|
|
736
|
+
championship_appearances: null,
|
|
737
|
+
appearance_years: [],
|
|
738
|
+
conference_titles: null,
|
|
739
|
+
conference_title_years: [],
|
|
740
|
+
total_conference_titles: null,
|
|
741
|
+
conference_history: [],
|
|
742
|
+
division_titles: null,
|
|
743
|
+
fan_nicknames: [],
|
|
744
|
+
traditions: [],
|
|
745
|
+
primary_rival_team_id: null,
|
|
746
|
+
owner: null,
|
|
747
|
+
stadium_capacity: null,
|
|
748
|
+
year_established: null,
|
|
749
|
+
first_season: null,
|
|
750
|
+
summary: null
|
|
751
|
+
};
|
|
752
|
+
function toInt(value) {
|
|
753
|
+
if (typeof value === "number") return Number.isSafeInteger(value) ? value : null;
|
|
754
|
+
if (typeof value === "string" && /^\d+$/.test(value.trim())) {
|
|
755
|
+
const parsed = Number(value.trim());
|
|
756
|
+
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
757
|
+
}
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
function toIntList(value) {
|
|
761
|
+
if (!Array.isArray(value)) return [];
|
|
762
|
+
return value.map(toInt).filter((n) => n !== null);
|
|
763
|
+
}
|
|
764
|
+
function toTextList(value) {
|
|
765
|
+
if (!Array.isArray(value)) return [];
|
|
766
|
+
return value.map(toTrimmedText).filter((s) => s !== null);
|
|
767
|
+
}
|
|
768
|
+
function hasTeamFacts(raw) {
|
|
769
|
+
return isJsonRecord(raw);
|
|
770
|
+
}
|
|
771
|
+
function parseTeamFacts(raw) {
|
|
772
|
+
if (!isJsonRecord(raw)) return { ...EMPTY_TEAM_FACTS };
|
|
773
|
+
return {
|
|
774
|
+
championships_won: toInt(raw.championships_won),
|
|
775
|
+
championship_years: toIntList(raw.championship_years),
|
|
776
|
+
other_national_titles: toInt(raw.other_national_titles),
|
|
777
|
+
other_title_years: toTextList(raw.other_title_years),
|
|
778
|
+
championship_appearances: toInt(raw.championship_appearances),
|
|
779
|
+
appearance_years: toIntList(raw.appearance_years),
|
|
780
|
+
conference_titles: toInt(raw.conference_titles),
|
|
781
|
+
conference_title_years: toIntList(raw.conference_title_years),
|
|
782
|
+
total_conference_titles: toInt(raw.total_conference_titles),
|
|
783
|
+
conference_history: toTextList(raw.conference_history),
|
|
784
|
+
division_titles: toInt(raw.division_titles),
|
|
785
|
+
fan_nicknames: toTextList(raw.fan_nicknames),
|
|
786
|
+
traditions: toTextList(raw.traditions),
|
|
787
|
+
primary_rival_team_id: toInt(raw.primary_rival_team_id),
|
|
788
|
+
owner: toTrimmedText(raw.owner),
|
|
789
|
+
stadium_capacity: toInt(raw.stadium_capacity),
|
|
790
|
+
year_established: toInt(raw.year_established),
|
|
791
|
+
first_season: toInt(raw.first_season),
|
|
792
|
+
summary: toTrimmedText(raw.summary)
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
var FACILITY_NAME_KEYS = {
|
|
796
|
+
stadium: "stadium_name",
|
|
797
|
+
arena: "arena_name"
|
|
798
|
+
};
|
|
799
|
+
function httpsUrl(value) {
|
|
800
|
+
const raw = toTrimmedText(value);
|
|
801
|
+
if (!raw) return null;
|
|
802
|
+
try {
|
|
803
|
+
return new URL(raw).protocol === "https:" ? raw : null;
|
|
804
|
+
} catch {
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
function num(value) {
|
|
809
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
810
|
+
}
|
|
811
|
+
function parseTeamFacilityImage(specificData, kind) {
|
|
812
|
+
if (!isJsonRecord(specificData)) return null;
|
|
813
|
+
const images = specificData.facility_images;
|
|
814
|
+
if (!isJsonRecord(images)) return null;
|
|
815
|
+
const entry = images[kind];
|
|
816
|
+
if (!isJsonRecord(entry)) return null;
|
|
817
|
+
const path = toTrimmedText(entry.path);
|
|
818
|
+
if (!path || !path.startsWith("facilities/")) return null;
|
|
819
|
+
return {
|
|
820
|
+
path,
|
|
821
|
+
title: toTrimmedText(entry.title),
|
|
822
|
+
sourceUrl: httpsUrl(entry.source_url),
|
|
823
|
+
artist: toTrimmedText(entry.artist),
|
|
824
|
+
license: toTrimmedText(entry.license),
|
|
825
|
+
licenseUrl: httpsUrl(entry.license_url),
|
|
826
|
+
width: num(entry.width),
|
|
827
|
+
height: num(entry.height),
|
|
828
|
+
updatedAt: toTrimmedText(entry.updated_at)
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
function parseTeamVenue(specificData, kind) {
|
|
832
|
+
const record = isJsonRecord(specificData) ? specificData : {};
|
|
833
|
+
return {
|
|
834
|
+
name: toTrimmedText(record[FACILITY_NAME_KEYS[kind]]),
|
|
835
|
+
image: parseTeamFacilityImage(specificData, kind)
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
function facilityImageCredit(image) {
|
|
839
|
+
const parts = [image.artist, image.license].filter((p) => Boolean(p));
|
|
840
|
+
return parts.length ? parts.join(" \xB7 ") : null;
|
|
841
|
+
}
|
|
842
|
+
var EMPTY_FACT_VALUE = "\u2014";
|
|
843
|
+
function formatTeamFactNumber(kind, value) {
|
|
844
|
+
if (value === null) return EMPTY_FACT_VALUE;
|
|
845
|
+
if (kind === "number") return value.toLocaleString("en-US");
|
|
846
|
+
return String(value);
|
|
847
|
+
}
|
|
848
|
+
var ROMAN_NUMERALS = [
|
|
849
|
+
[1e3, "M"],
|
|
850
|
+
[900, "CM"],
|
|
851
|
+
[500, "D"],
|
|
852
|
+
[400, "CD"],
|
|
853
|
+
[100, "C"],
|
|
854
|
+
[90, "XC"],
|
|
855
|
+
[50, "L"],
|
|
856
|
+
[40, "XL"],
|
|
857
|
+
[10, "X"],
|
|
858
|
+
[9, "IX"],
|
|
859
|
+
[5, "V"],
|
|
860
|
+
[4, "IV"],
|
|
861
|
+
[1, "I"]
|
|
862
|
+
];
|
|
863
|
+
var MAX_ROMAN_NUMERAL = 3999;
|
|
864
|
+
function toRomanNumeral(value) {
|
|
865
|
+
if (!Number.isInteger(value) || value < 1 || value > MAX_ROMAN_NUMERAL) return String(value);
|
|
866
|
+
let rest = value;
|
|
867
|
+
let out = "";
|
|
868
|
+
for (const [n, numeral] of ROMAN_NUMERALS) {
|
|
869
|
+
while (rest >= n) {
|
|
870
|
+
out += numeral;
|
|
871
|
+
rest -= n;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
return out;
|
|
875
|
+
}
|
|
876
|
+
var FIRST_SUPER_BOWL_SEASON = 1966;
|
|
877
|
+
function formatSuperBowlYear(year) {
|
|
878
|
+
const number = year - FIRST_SUPER_BOWL_SEASON + 1;
|
|
879
|
+
if (year < FIRST_SUPER_BOWL_SEASON || number > MAX_ROMAN_NUMERAL) return String(year);
|
|
880
|
+
return `${toRomanNumeral(number)} \xB7 ${year}`;
|
|
881
|
+
}
|
|
882
|
+
function formatYearPills(years, formatYear) {
|
|
883
|
+
if (!formatYear) return years;
|
|
884
|
+
return years.map((year) => typeof year === "number" ? formatYear(year) : year);
|
|
885
|
+
}
|
|
886
|
+
var TEAM_FACT_KINDS = {
|
|
887
|
+
championships_won: "count",
|
|
888
|
+
championship_years: "years",
|
|
889
|
+
other_national_titles: "count",
|
|
890
|
+
other_title_years: "labeled_years",
|
|
891
|
+
championship_appearances: "count",
|
|
892
|
+
appearance_years: "years",
|
|
893
|
+
conference_titles: "count",
|
|
894
|
+
conference_title_years: "years",
|
|
895
|
+
total_conference_titles: "count",
|
|
896
|
+
conference_history: "list",
|
|
897
|
+
division_titles: "count",
|
|
898
|
+
fan_nicknames: "list",
|
|
899
|
+
traditions: "list",
|
|
900
|
+
primary_rival_team_id: "rival",
|
|
901
|
+
owner: "text",
|
|
902
|
+
stadium_capacity: "number",
|
|
903
|
+
year_established: "year",
|
|
904
|
+
first_season: "year",
|
|
905
|
+
summary: "longtext"
|
|
906
|
+
};
|
|
907
|
+
var TEAM_FACT_YEAR_PAIRS = {
|
|
908
|
+
championships_won: "championship_years",
|
|
909
|
+
other_national_titles: "other_title_years",
|
|
910
|
+
championship_appearances: "appearance_years",
|
|
911
|
+
conference_titles: "conference_title_years"
|
|
912
|
+
};
|
|
913
|
+
var PAIRED_YEAR_KEYS = new Set(Object.values(TEAM_FACT_YEAR_PAIRS));
|
|
914
|
+
function teamFactsDisplayFields(section) {
|
|
915
|
+
return section.fields.filter((key) => !PAIRED_YEAR_KEYS.has(key));
|
|
916
|
+
}
|
|
917
|
+
var DEFAULT_LABELS = {
|
|
918
|
+
championships_won: "Championships Won",
|
|
919
|
+
championship_years: "Championship Years",
|
|
920
|
+
other_national_titles: "Other National Titles",
|
|
921
|
+
other_title_years: "Other National Title Years",
|
|
922
|
+
championship_appearances: "Championship Appearances",
|
|
923
|
+
appearance_years: "Championship Appearance Years",
|
|
924
|
+
conference_titles: "Conference Titles",
|
|
925
|
+
conference_title_years: "Conference Title Years",
|
|
926
|
+
total_conference_titles: "Total Conference Titles",
|
|
927
|
+
conference_history: "Conference History",
|
|
928
|
+
division_titles: "Division Titles",
|
|
929
|
+
fan_nicknames: "Fan Nicknames",
|
|
930
|
+
traditions: "Traditions",
|
|
931
|
+
primary_rival_team_id: "Primary Rival",
|
|
932
|
+
owner: "Team Owner",
|
|
933
|
+
stadium_capacity: "Stadium Capacity",
|
|
934
|
+
year_established: "Year Established",
|
|
935
|
+
first_season: "First Season",
|
|
936
|
+
summary: "Team Summary"
|
|
937
|
+
};
|
|
938
|
+
var DEFAULT_SECTIONS = [
|
|
939
|
+
{
|
|
940
|
+
title: "Trophy Case",
|
|
941
|
+
layout: "grid",
|
|
942
|
+
fields: [
|
|
943
|
+
"championships_won",
|
|
944
|
+
"championship_years",
|
|
945
|
+
"championship_appearances",
|
|
946
|
+
"appearance_years",
|
|
947
|
+
"conference_titles",
|
|
948
|
+
"division_titles"
|
|
949
|
+
]
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
title: "Tradition",
|
|
953
|
+
layout: "column",
|
|
954
|
+
fields: ["fan_nicknames", "primary_rival_team_id", "summary"]
|
|
955
|
+
},
|
|
956
|
+
{
|
|
957
|
+
title: "Franchise Profile",
|
|
958
|
+
layout: "row",
|
|
959
|
+
showsVenuePhoto: true,
|
|
960
|
+
fields: ["owner", "year_established", "stadium_capacity"]
|
|
961
|
+
}
|
|
962
|
+
];
|
|
963
|
+
var LEAGUE_HIDDEN_FIELDS = {
|
|
964
|
+
NFL: ["conference_titles"],
|
|
965
|
+
MLB: ["conference_titles"],
|
|
966
|
+
NHL: ["conference_titles"],
|
|
967
|
+
WNBA: ["division_titles"]
|
|
968
|
+
};
|
|
969
|
+
var COLLEGE_FOOTBALL_SECTIONS = [
|
|
970
|
+
{
|
|
971
|
+
title: "Trophy Case",
|
|
972
|
+
layout: "grid",
|
|
973
|
+
fields: [
|
|
974
|
+
"championships_won",
|
|
975
|
+
"championship_years",
|
|
976
|
+
"other_national_titles",
|
|
977
|
+
"other_title_years",
|
|
978
|
+
"championship_appearances",
|
|
979
|
+
"appearance_years",
|
|
980
|
+
"conference_titles",
|
|
981
|
+
"total_conference_titles",
|
|
982
|
+
"conference_history"
|
|
983
|
+
]
|
|
984
|
+
},
|
|
985
|
+
{
|
|
986
|
+
title: "Tradition",
|
|
987
|
+
layout: "column",
|
|
988
|
+
fields: ["fan_nicknames", "traditions", "primary_rival_team_id", "summary"]
|
|
989
|
+
},
|
|
990
|
+
{
|
|
991
|
+
title: "School Profile",
|
|
992
|
+
layout: "row",
|
|
993
|
+
showsVenuePhoto: true,
|
|
994
|
+
fields: ["year_established", "first_season", "stadium_capacity"]
|
|
995
|
+
}
|
|
996
|
+
];
|
|
997
|
+
var FCS_SECTIONS = [
|
|
998
|
+
{
|
|
999
|
+
title: "Trophy Case",
|
|
1000
|
+
layout: "grid",
|
|
1001
|
+
fields: [
|
|
1002
|
+
"championships_won",
|
|
1003
|
+
"championship_years",
|
|
1004
|
+
"other_national_titles",
|
|
1005
|
+
"other_title_years",
|
|
1006
|
+
"conference_titles",
|
|
1007
|
+
"conference_title_years"
|
|
1008
|
+
]
|
|
1009
|
+
},
|
|
1010
|
+
{
|
|
1011
|
+
title: "Tradition",
|
|
1012
|
+
layout: "column",
|
|
1013
|
+
fields: ["fan_nicknames", "primary_rival_team_id", "summary"]
|
|
1014
|
+
},
|
|
1015
|
+
{
|
|
1016
|
+
title: "School Profile",
|
|
1017
|
+
layout: "row",
|
|
1018
|
+
showsVenuePhoto: true,
|
|
1019
|
+
fields: ["first_season", "stadium_capacity"]
|
|
1020
|
+
}
|
|
1021
|
+
];
|
|
1022
|
+
var COLLEGE_BASKETBALL_SECTIONS = [
|
|
1023
|
+
{
|
|
1024
|
+
title: "Trophy Case",
|
|
1025
|
+
layout: "grid",
|
|
1026
|
+
fields: [
|
|
1027
|
+
"championships_won",
|
|
1028
|
+
"championship_years",
|
|
1029
|
+
"championship_appearances",
|
|
1030
|
+
"appearance_years",
|
|
1031
|
+
"conference_titles",
|
|
1032
|
+
"total_conference_titles",
|
|
1033
|
+
"conference_history"
|
|
1034
|
+
]
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
title: "Tradition",
|
|
1038
|
+
layout: "column",
|
|
1039
|
+
fields: ["fan_nicknames", "traditions", "primary_rival_team_id", "summary"]
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
title: "School Profile",
|
|
1043
|
+
layout: "row",
|
|
1044
|
+
showsVenuePhoto: true,
|
|
1045
|
+
fields: ["year_established", "first_season", "stadium_capacity"]
|
|
1046
|
+
}
|
|
1047
|
+
];
|
|
1048
|
+
var LEAGUE_SECTIONS = {
|
|
1049
|
+
"NCAAF (FBS)": COLLEGE_FOOTBALL_SECTIONS,
|
|
1050
|
+
"NCAAF (FCS)": FCS_SECTIONS,
|
|
1051
|
+
NCAAM: COLLEGE_BASKETBALL_SECTIONS
|
|
1052
|
+
};
|
|
1053
|
+
var LEAGUE_RIVAL_PARTNERS = {
|
|
1054
|
+
"NCAAF (FBS)": "NCAAF (FCS)",
|
|
1055
|
+
"NCAAF (FCS)": "NCAAF (FBS)"
|
|
1056
|
+
};
|
|
1057
|
+
function sectionsWithout(hidden) {
|
|
1058
|
+
if (!hidden || hidden.length === 0) return DEFAULT_SECTIONS;
|
|
1059
|
+
const hiddenFields = new Set(hidden);
|
|
1060
|
+
return DEFAULT_SECTIONS.map((section) => ({
|
|
1061
|
+
...section,
|
|
1062
|
+
fields: section.fields.filter((field) => !hiddenFields.has(field))
|
|
1063
|
+
}));
|
|
1064
|
+
}
|
|
1065
|
+
var LEAGUE_YEAR_FORMATTERS = {
|
|
1066
|
+
NFL: formatSuperBowlYear
|
|
1067
|
+
};
|
|
1068
|
+
var LEAGUE_LABEL_OVERRIDES = {
|
|
1069
|
+
NFL: {
|
|
1070
|
+
championships_won: "Super Bowls Won",
|
|
1071
|
+
championship_years: "Super Bowl Win Years",
|
|
1072
|
+
championship_appearances: "Super Bowl Appearances",
|
|
1073
|
+
appearance_years: "Super Bowl Appearance Years",
|
|
1074
|
+
conference_titles: "Conference Championships",
|
|
1075
|
+
division_titles: "Division Championships",
|
|
1076
|
+
fan_nicknames: "Fan Nickname(s)",
|
|
1077
|
+
summary: "Short Team Summary"
|
|
1078
|
+
},
|
|
1079
|
+
NBA: {
|
|
1080
|
+
championships_won: "NBA Championships",
|
|
1081
|
+
championship_years: "NBA Championship Years",
|
|
1082
|
+
championship_appearances: "NBA Finals Appearances",
|
|
1083
|
+
appearance_years: "NBA Finals Appearance Years",
|
|
1084
|
+
fan_nicknames: "Fan Nickname(s)",
|
|
1085
|
+
stadium_capacity: "Arena Capacity",
|
|
1086
|
+
summary: "Short Team Summary"
|
|
1087
|
+
},
|
|
1088
|
+
NHL: {
|
|
1089
|
+
championships_won: "Stanley Cup Wins",
|
|
1090
|
+
championship_years: "Stanley Cup Winning Years",
|
|
1091
|
+
championship_appearances: "Stanley Cup Finals Appearances",
|
|
1092
|
+
appearance_years: "Stanley Cup Finals Years",
|
|
1093
|
+
conference_titles: "Conference Championships",
|
|
1094
|
+
fan_nicknames: "Fan Nickname(s)",
|
|
1095
|
+
stadium_capacity: "Arena Capacity",
|
|
1096
|
+
summary: "Short Team Summary"
|
|
1097
|
+
},
|
|
1098
|
+
MLB: {
|
|
1099
|
+
championships_won: "World Series Wins",
|
|
1100
|
+
championship_years: "World Series Winning Years",
|
|
1101
|
+
championship_appearances: "Pennants Won",
|
|
1102
|
+
appearance_years: "Pennant Years",
|
|
1103
|
+
conference_titles: "League Championships",
|
|
1104
|
+
fan_nicknames: "Fan Nickname(s)",
|
|
1105
|
+
summary: "Short Team Summary"
|
|
1106
|
+
},
|
|
1107
|
+
WNBA: {
|
|
1108
|
+
championships_won: "WNBA Championships",
|
|
1109
|
+
championship_years: "WNBA Championship Years",
|
|
1110
|
+
championship_appearances: "WNBA Finals Appearances",
|
|
1111
|
+
appearance_years: "WNBA Finals Appearance Years",
|
|
1112
|
+
fan_nicknames: "Fan Nickname(s)",
|
|
1113
|
+
stadium_capacity: "Arena Capacity",
|
|
1114
|
+
summary: "Short Team Summary"
|
|
1115
|
+
},
|
|
1116
|
+
"NCAAF (FBS)": {
|
|
1117
|
+
championships_won: "FBS Championships",
|
|
1118
|
+
championship_years: "FBS Championship Years",
|
|
1119
|
+
other_national_titles: "Other National Titles",
|
|
1120
|
+
other_title_years: "Other National Title Years",
|
|
1121
|
+
championship_appearances: "CFP Appearances",
|
|
1122
|
+
appearance_years: "CFP Appearance Years",
|
|
1123
|
+
conference_titles: "Current Conference Titles",
|
|
1124
|
+
total_conference_titles: "Total Conference Titles",
|
|
1125
|
+
conference_history: "Conference History",
|
|
1126
|
+
fan_nicknames: "Fan Nickname(s)",
|
|
1127
|
+
traditions: "Traditions",
|
|
1128
|
+
year_established: "University Founded",
|
|
1129
|
+
first_season: "First Season",
|
|
1130
|
+
summary: "Short Team Summary"
|
|
1131
|
+
},
|
|
1132
|
+
"NCAAF (FCS)": {
|
|
1133
|
+
championships_won: "National Championships",
|
|
1134
|
+
championship_years: "National Championship Years",
|
|
1135
|
+
other_national_titles: "Other National Titles",
|
|
1136
|
+
other_title_years: "Other National Title Years",
|
|
1137
|
+
conference_titles: "Conference Championships",
|
|
1138
|
+
conference_title_years: "Conference Championship Years",
|
|
1139
|
+
fan_nicknames: "Fan Nickname(s)",
|
|
1140
|
+
first_season: "First Season",
|
|
1141
|
+
summary: "Short Team Summary"
|
|
1142
|
+
},
|
|
1143
|
+
NCAAM: {
|
|
1144
|
+
championships_won: "National Championships",
|
|
1145
|
+
championship_years: "National Championship Years",
|
|
1146
|
+
championship_appearances: "Final Four Appearances",
|
|
1147
|
+
appearance_years: "Final Four Years",
|
|
1148
|
+
conference_titles: "Current Conference Titles",
|
|
1149
|
+
total_conference_titles: "Total Conference Titles",
|
|
1150
|
+
conference_history: "Conference History",
|
|
1151
|
+
fan_nicknames: "Fan Nickname(s)",
|
|
1152
|
+
traditions: "Traditions",
|
|
1153
|
+
stadium_capacity: "Arena Capacity",
|
|
1154
|
+
year_established: "University Founded",
|
|
1155
|
+
first_season: "First Season",
|
|
1156
|
+
summary: "Short Program History"
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
1159
|
+
var CONFIGURED_TEAM_FACTS_LEAGUES = Object.keys(LEAGUE_LABEL_OVERRIDES);
|
|
1160
|
+
function buildTeamFactsConfig(leagueAbbreviation) {
|
|
1161
|
+
const overrides = leagueAbbreviation ? LEAGUE_LABEL_OVERRIDES[leagueAbbreviation] : void 0;
|
|
1162
|
+
const venue = getTeamVenueConfig(leagueAbbreviation);
|
|
1163
|
+
const facility = getTeamFacilityConfig(leagueAbbreviation);
|
|
1164
|
+
const rivalPartnerLeague = leagueAbbreviation ? LEAGUE_RIVAL_PARTNERS[leagueAbbreviation] : void 0;
|
|
1165
|
+
const isDefaultVenue = venue.kind === DEFAULT_TEAM_FACTS_CONFIG.venue.kind;
|
|
1166
|
+
const isDefaultFacility = facility.kind === DEFAULT_TEAM_FACTS_CONFIG.facility.kind;
|
|
1167
|
+
if (!overrides && isDefaultVenue && isDefaultFacility && !rivalPartnerLeague) {
|
|
1168
|
+
return DEFAULT_TEAM_FACTS_CONFIG;
|
|
1169
|
+
}
|
|
1170
|
+
return {
|
|
1171
|
+
labels: { ...DEFAULT_LABELS, ...overrides },
|
|
1172
|
+
venue,
|
|
1173
|
+
facility,
|
|
1174
|
+
sections: (leagueAbbreviation ? LEAGUE_SECTIONS[leagueAbbreviation] : void 0) ?? sectionsWithout(leagueAbbreviation ? LEAGUE_HIDDEN_FIELDS[leagueAbbreviation] : void 0),
|
|
1175
|
+
formatChampionshipYear: leagueAbbreviation ? LEAGUE_YEAR_FORMATTERS[leagueAbbreviation] : void 0,
|
|
1176
|
+
rivalPartnerLeague
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
var DEFAULT_TEAM_FACTS_CONFIG = {
|
|
1180
|
+
labels: DEFAULT_LABELS,
|
|
1181
|
+
venue: getTeamVenueConfig(null),
|
|
1182
|
+
facility: getTeamFacilityConfig(null),
|
|
1183
|
+
sections: DEFAULT_SECTIONS
|
|
1184
|
+
};
|
|
1185
|
+
var CONFIG_CACHE = /* @__PURE__ */ new Map();
|
|
1186
|
+
function getTeamFactsConfig(leagueAbbreviation) {
|
|
1187
|
+
const cacheKey = leagueAbbreviation ?? "";
|
|
1188
|
+
const cached = CONFIG_CACHE.get(cacheKey);
|
|
1189
|
+
if (cached) return cached;
|
|
1190
|
+
const config = buildTeamFactsConfig(leagueAbbreviation);
|
|
1191
|
+
CONFIG_CACHE.set(cacheKey, config);
|
|
1192
|
+
return config;
|
|
1193
|
+
}
|
|
1194
|
+
function toTeamFactsView(team) {
|
|
1195
|
+
const data = isJsonRecord(team.specific_data) ? team.specific_data : {};
|
|
1196
|
+
const rawFacts = data.facts;
|
|
1197
|
+
const config = getTeamFactsConfig(team.league?.abbreviation);
|
|
1198
|
+
return {
|
|
1199
|
+
teamId: team.id,
|
|
1200
|
+
hasFacts: hasTeamFacts(rawFacts),
|
|
1201
|
+
facts: parseTeamFacts(rawFacts),
|
|
1202
|
+
config,
|
|
1203
|
+
venue: parseTeamVenue(team.specific_data, config.venue.kind)
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
function toRivalState(rivalId, rivalTeam, isError) {
|
|
1207
|
+
if (!rivalId) return { status: "none" };
|
|
1208
|
+
if (rivalTeam) {
|
|
1209
|
+
return {
|
|
1210
|
+
status: "ready",
|
|
1211
|
+
rival: {
|
|
1212
|
+
id: rivalId,
|
|
1213
|
+
name: formatTeamName(rivalTeam.team, rivalTeam.nickname),
|
|
1214
|
+
teamLogoUrl: rivalTeam.team_logo_url
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
return isError || rivalTeam === null ? { status: "error" } : { status: "loading" };
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
// src/recentGames.ts
|
|
1222
|
+
var COMPLETED_STATUS_ID = "3";
|
|
1223
|
+
function startOfLocalDay(now = /* @__PURE__ */ new Date()) {
|
|
1224
|
+
const day = new Date(now);
|
|
1225
|
+
day.setHours(0, 0, 0, 0);
|
|
1226
|
+
return day.getTime();
|
|
1227
|
+
}
|
|
1228
|
+
function firstCompetition(game) {
|
|
1229
|
+
return game.game_details?.competitions?.[0];
|
|
1230
|
+
}
|
|
1231
|
+
function isGameCompleted(game) {
|
|
1232
|
+
return firstCompetition(game)?.status?.type?.id === COMPLETED_STATUS_ID;
|
|
1233
|
+
}
|
|
1234
|
+
function isGameBeforeDay(game, dayStart) {
|
|
1235
|
+
return new Date(game.game_date).getTime() < dayStart;
|
|
1236
|
+
}
|
|
1237
|
+
function isTrueUpcomingGame(game, todayStart) {
|
|
1238
|
+
return !isGameCompleted(game) && !isGameBeforeDay(game, todayStart);
|
|
1239
|
+
}
|
|
1240
|
+
var NO_RESULT = { outcome: "none", detail: "" };
|
|
1241
|
+
function getRecentGameResult(game, teamEspnId) {
|
|
1242
|
+
const competition = firstCompetition(game);
|
|
1243
|
+
const competitors = competition?.competitors;
|
|
1244
|
+
if (competition?.status?.type?.id !== COMPLETED_STATUS_ID || !competitors || competitors.length !== 2 || !teamEspnId) {
|
|
1245
|
+
return NO_RESULT;
|
|
1246
|
+
}
|
|
1247
|
+
const [first, second] = competitors;
|
|
1248
|
+
if (!first || !second) return NO_RESULT;
|
|
1249
|
+
const extra = competition.status?.type?.altDetail;
|
|
1250
|
+
const withExtra = (score) => extra ? `${score} ${extra}` : score;
|
|
1251
|
+
const scoreFor = (own2, other2) => `${own2.score?.displayValue || "0"}-${other2.score?.displayValue || "0"}`;
|
|
1252
|
+
const teamId = String(teamEspnId);
|
|
1253
|
+
const own = first.id === teamId ? first : second.id === teamId ? second : null;
|
|
1254
|
+
if (!own) return NO_RESULT;
|
|
1255
|
+
const other = own === first ? second : first;
|
|
1256
|
+
if (first.score?.value === second.score?.value) {
|
|
1257
|
+
return { outcome: "tie", detail: withExtra(scoreFor(own, other)) };
|
|
1258
|
+
}
|
|
1259
|
+
return {
|
|
1260
|
+
outcome: own.winner === true ? "win" : "loss",
|
|
1261
|
+
detail: withExtra(scoreFor(own, other))
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
function collectRecentGameTeamIds(games) {
|
|
1265
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1266
|
+
for (const game of games) {
|
|
1267
|
+
if (game.home_team_id) ids.add(game.home_team_id);
|
|
1268
|
+
if (game.away_team_id) ids.add(game.away_team_id);
|
|
1269
|
+
}
|
|
1270
|
+
return [...ids].sort((a, b) => a - b);
|
|
1271
|
+
}
|
|
1272
|
+
function collectRecentGameEspnIds(games) {
|
|
1273
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1274
|
+
for (const game of games) {
|
|
1275
|
+
if (game.home_team_id && game.away_team_id) continue;
|
|
1276
|
+
const competitors = firstCompetition(game)?.competitors;
|
|
1277
|
+
if (!Array.isArray(competitors)) continue;
|
|
1278
|
+
for (const competitor of competitors) {
|
|
1279
|
+
const parsed = Number(competitor?.id);
|
|
1280
|
+
if (Number.isFinite(parsed)) ids.add(parsed);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
return [...ids].sort((a, b) => a - b);
|
|
1284
|
+
}
|
|
1285
|
+
var TBD_OPPONENT = { name: "TBD", logo: null };
|
|
1286
|
+
function teamName(row) {
|
|
1287
|
+
return formatTeamName(row.team, row.nickname) || "Unknown";
|
|
1288
|
+
}
|
|
1289
|
+
function logoOf(row, fallbackUrl) {
|
|
1290
|
+
if (row.team_logo_url) return { url: row.team_logo_url, stored: true };
|
|
1291
|
+
return fallbackUrl ? { url: fallbackUrl, stored: false } : null;
|
|
1292
|
+
}
|
|
1293
|
+
function isOpponentCompetitor(competitor, teamEspnId, isHome) {
|
|
1294
|
+
if (!competitor) return false;
|
|
1295
|
+
if (teamEspnId) return competitor.id !== String(teamEspnId);
|
|
1296
|
+
return competitor.homeAway === (isHome ? "away" : "home");
|
|
1297
|
+
}
|
|
1298
|
+
function resolveRecentGameOpponent({
|
|
1299
|
+
game,
|
|
1300
|
+
opponentTeamId,
|
|
1301
|
+
isHome,
|
|
1302
|
+
teamEspnId,
|
|
1303
|
+
teamsById,
|
|
1304
|
+
teamsByEspnId
|
|
1305
|
+
}) {
|
|
1306
|
+
const known = opponentTeamId ? teamsById.get(opponentTeamId) : void 0;
|
|
1307
|
+
if (known) return { name: teamName(known), logo: logoOf(known) };
|
|
1308
|
+
const competitors = firstCompetition(game)?.competitors;
|
|
1309
|
+
if (!competitors) return TBD_OPPONENT;
|
|
1310
|
+
const opponent = competitors.find((c) => isOpponentCompetitor(c, teamEspnId, isHome));
|
|
1311
|
+
if (!opponent) return TBD_OPPONENT;
|
|
1312
|
+
const stored = opponent.id ? teamsByEspnId.get(String(opponent.id)) : void 0;
|
|
1313
|
+
if (stored) return { name: teamName(stored), logo: logoOf(stored, opponent.team?.logo) };
|
|
1314
|
+
const payload = opponent.team;
|
|
1315
|
+
if (!payload) return TBD_OPPONENT;
|
|
1316
|
+
return {
|
|
1317
|
+
name: payload.displayName || payload.shortDisplayName || payload.name || "Unknown",
|
|
1318
|
+
logo: payload.logo ? { url: payload.logo, stored: false } : null
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
function buildRecentGameRows({
|
|
1322
|
+
games,
|
|
1323
|
+
teamId,
|
|
1324
|
+
teamEspnId,
|
|
1325
|
+
teams,
|
|
1326
|
+
espnTeams,
|
|
1327
|
+
todayStart
|
|
1328
|
+
}) {
|
|
1329
|
+
const teamsById = new Map(teams.map((team) => [team.id, team]));
|
|
1330
|
+
const teamsByEspnId = /* @__PURE__ */ new Map();
|
|
1331
|
+
for (const team of espnTeams) {
|
|
1332
|
+
if (team.espn_id !== null && team.espn_id !== void 0) {
|
|
1333
|
+
teamsByEspnId.set(String(team.espn_id), team);
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
return games.map((game, index) => {
|
|
1337
|
+
const isHome = teamId !== null && game.home_team_id === teamId;
|
|
1338
|
+
const completed = isGameCompleted(game);
|
|
1339
|
+
const past = isGameBeforeDay(game, todayStart);
|
|
1340
|
+
const previous = games[index - 1];
|
|
1341
|
+
return {
|
|
1342
|
+
id: game.id,
|
|
1343
|
+
gameDate: game.game_date,
|
|
1344
|
+
isHome,
|
|
1345
|
+
opponent: resolveRecentGameOpponent({
|
|
1346
|
+
game,
|
|
1347
|
+
opponentTeamId: isHome ? game.away_team_id : game.home_team_id,
|
|
1348
|
+
isHome,
|
|
1349
|
+
teamEspnId,
|
|
1350
|
+
teamsById,
|
|
1351
|
+
teamsByEspnId
|
|
1352
|
+
}),
|
|
1353
|
+
result: completed || past ? getRecentGameResult(game, teamEspnId) : null,
|
|
1354
|
+
time: !completed && !past ? game.game_details?.time ?? null : null,
|
|
1355
|
+
isFirstUpcoming: isTrueUpcomingGame(game, todayStart) && (!previous || !isTrueUpcomingGame(previous, todayStart))
|
|
1356
|
+
};
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
101
1359
|
export {
|
|
1360
|
+
BASEBALL_TEAM_STAT_IDS,
|
|
1361
|
+
BASKETBALL_TEAM_STAT_IDS,
|
|
1362
|
+
CONFIGURED_TEAM_FACTS_LEAGUES,
|
|
1363
|
+
EMPTY_FACT_VALUE,
|
|
1364
|
+
FOOTBALL_TEAM_STAT_IDS,
|
|
1365
|
+
HOCKEY_TEAM_STAT_IDS,
|
|
1366
|
+
TEAM_FACT_KINDS,
|
|
1367
|
+
TEAM_FACT_YEAR_PAIRS,
|
|
102
1368
|
abbreviatePersonName,
|
|
1369
|
+
buildRecentGameRows,
|
|
103
1370
|
canEditMarketingDeals,
|
|
104
1371
|
canEditProject,
|
|
105
1372
|
canEditTaskStatus,
|
|
106
1373
|
canManageMembers,
|
|
107
1374
|
canViewMarketingDeals,
|
|
1375
|
+
collectRecentGameEspnIds,
|
|
1376
|
+
collectRecentGameTeamIds,
|
|
1377
|
+
computeSeasonSummary,
|
|
1378
|
+
computeTeamSeasonStats,
|
|
1379
|
+
computeTeamSeasonStatsFromSummary,
|
|
1380
|
+
facilityImageCredit,
|
|
108
1381
|
fmt,
|
|
109
1382
|
fmtCurrency,
|
|
110
1383
|
fmtDate,
|
|
@@ -112,8 +1385,53 @@ export {
|
|
|
112
1385
|
fmtUSDCompact,
|
|
113
1386
|
fmtUSDWhole,
|
|
114
1387
|
formatDealDate,
|
|
1388
|
+
formatStatNumber,
|
|
1389
|
+
formatStatRank,
|
|
1390
|
+
formatStatRankByConfig,
|
|
1391
|
+
formatSuperBowlYear,
|
|
1392
|
+
formatTeamFactNumber,
|
|
1393
|
+
formatTeamName,
|
|
1394
|
+
formatTeamPlaceAddress,
|
|
1395
|
+
formatYearPills,
|
|
115
1396
|
getDealStatus,
|
|
116
1397
|
getEffectiveMemberRole,
|
|
117
|
-
|
|
1398
|
+
getOrderedTeamStatTypesForCategory,
|
|
1399
|
+
getPreferredSeasonType,
|
|
1400
|
+
getRecentGameResult,
|
|
1401
|
+
getRosterCellValue,
|
|
1402
|
+
getRosterColumns,
|
|
1403
|
+
getSeasonTypeOptions,
|
|
1404
|
+
getSeasonYearOptions,
|
|
1405
|
+
getStatRankingFootnotes,
|
|
1406
|
+
getTeamFacilityConfig,
|
|
1407
|
+
getTeamFactsConfig,
|
|
1408
|
+
getTeamPlaceSummaries,
|
|
1409
|
+
getTeamRankingConfigIds,
|
|
1410
|
+
getTeamStatColumns,
|
|
1411
|
+
getTeamVenueConfig,
|
|
1412
|
+
getVisibleTeamStatTypes,
|
|
1413
|
+
hasTeamFacts,
|
|
1414
|
+
isGameBeforeDay,
|
|
1415
|
+
isGameCompleted,
|
|
1416
|
+
isJsonRecord,
|
|
1417
|
+
isProjectCancelled,
|
|
1418
|
+
isSupportedTeamStatsSport,
|
|
1419
|
+
isTrueUpcomingGame,
|
|
1420
|
+
parseTeamFacts,
|
|
1421
|
+
parseTeamPlace,
|
|
1422
|
+
parseTeamVenue,
|
|
1423
|
+
resolveRecentGameOpponent,
|
|
1424
|
+
selectRecentGames,
|
|
1425
|
+
showsTeamStatCategoryPicker,
|
|
1426
|
+
sortTeamStaff,
|
|
1427
|
+
startOfLocalDay,
|
|
1428
|
+
teamFactsDisplayFields,
|
|
1429
|
+
toJsonRecord,
|
|
1430
|
+
toOrdinal,
|
|
1431
|
+
toRivalState,
|
|
1432
|
+
toRomanNumeral,
|
|
1433
|
+
toTeamFactsView,
|
|
1434
|
+
toTrimmedText,
|
|
1435
|
+
topPercentileLabel
|
|
118
1436
|
};
|
|
119
1437
|
//# sourceMappingURL=index.js.map
|