age-grade-tables
Version:
Age grading tables for races like Ironman in compact array format
107 lines • 4.07 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAgeGradeTable = getAgeGradeTable;
const _2025_ironman_1 = require("./tables/2025_ironman");
const _2025_ironman703_1 = require("./tables/2025_ironman703");
// Main exports for the age-grade-tables package
__exportStar(require("./types"), exports);
__exportStar(require("./helpers"), exports);
/**
* Get age grade table by name and format
*
* Retrieves age grading tables for triathlon events from memory. Age grading tables
* provide performance factors for different age groups and genders, allowing comparison
* of performance across different demographics.
*
* @param name - The table name to retrieve. Currently supports:
* - '2025_ironman': Full Ironman distance (2.4mi swim, 112mi bike, 26.2mi run)
* - '2025_ironman703': Ironman 70.3 distance (1.2mi swim, 56mi bike, 13.1mi run)
* @param format - The output format for the table data:
* - 'array': Returns compact array format `[gender, start_age, end_age, factor]`
* - 'json': Returns object format `{gender, start, end, factor}`
* @returns The age grade table in the specified format
*
* @throws {Error} When an unknown table name is provided
* @throws {Error} When an unknown format is specified
*
* @example
* ```typescript
* // Get Ironman table in array format (default)
* const ironmanArray = getAgeGradeTable('2025_ironman');
* // Returns: [["M", 0, 19, 1.000], ["M", 20, 24, 0.995], ...]
*
* // Get Ironman 70.3 table in JSON format
* const ironman703Json = getAgeGradeTable('2025_ironman703', 'json');
* // Returns: [{ gender: "M", start: 0, end: 19, factor: 1.000 }, ...]
*
* // Find age grade factor for a 35-year-old male in Ironman
* const ironmanTable = getAgeGradeTable('2025_ironman', 'array') as AgeGradeCompactEntry[];
* const male35Entry = ironmanTable.find(entry =>
* entry[0] === 'M' && entry[1] <= 35 && entry[2] >= 35
* );
* const factor = male35Entry?.[3]; // 0.980
* ```
*
* @example
* ```typescript
* // Calculate age-graded performance
* const table = getAgeGradeTable('2025_ironman', 'json') as AgeGradeObjectEntry[];
* const age = 35;
* const gender = 'M';
* const finishTime = 9 * 3600 + 30 * 60; // 9:30:00 in seconds
*
* const entry = table.find(e =>
* e.gender === gender && e.start <= age && e.end >= age
* );
*
* if (entry) {
* const ageGradedTime = finishTime / entry.factor;
* console.log(`Age-graded time: ${ageGradedTime} seconds`);
* }
* ```
*/
function getAgeGradeTable(name, format = 'array') {
let table;
// Get the appropriate table from memory
switch (name) {
case '2025_ironman':
table = _2025_ironman_1.ageGradeTable_2025_ironman;
break;
case '2025_ironman703':
table = _2025_ironman703_1.ageGradeTable_2025_ironman703;
break;
default:
throw new Error(`Unknown table name: ${name}`);
}
// Return in requested format
if (format === 'array') {
return table;
}
else if (format === 'json') {
// Convert compact array format to object format
return table.map(([gender, start, end, factor]) => ({
gender,
start,
end,
factor
}));
}
else {
throw new Error(`Unknown format: ${format}`);
}
}
//# sourceMappingURL=index.js.map