File size: 1,656 Bytes
35527e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
 * Training Stress Score (TSS) Calculator
 * 
 * TSS is a concept developed by Andrew Coggan to quantify the physiological
 * load and fatigue of a given training session, taking into account both
 * its duration and intensity.
 * 
 * Formula for running:
 * TSS = (t × NP × IF) / (FTP × 3600) × 100
 * 
 * Where:
 * - t: Duration of activity in seconds
 * - NP (Normalized Power®): Power you could have maintained if effort was perfectly regular
 * - IF (Intensity Factor): NP / FTP
 * - FTP (Functional Threshold Power): Maximum power you can maintain for about 1 hour
 * - 3600: Conversion of one hour to seconds
 * 
 * In practice:
 * - TSS = 100: represents 1 hour at threshold intensity (FTP)
 * - TSS < 100: easy or moderate training
 * - TSS > 100: very long or very intense training
 */

export interface TSSInputs {
    durationSeconds: number;
    normalizedPower?: number; // NP in watts
    ftp?: number; // Functional Threshold Power in watts
}

/**
 * Calculate Training Stress Score (TSS)
 * 
 * @param inputs - Duration, Normalized Power, and FTP
 * @returns TSS value or undefined if required data is missing
 */
export function calculateTSS(inputs: TSSInputs): number | undefined {
    const { durationSeconds, normalizedPower, ftp } = inputs;

    // Need all three values to calculate TSS
    if (!normalizedPower || !ftp || ftp === 0) {
        return undefined;
    }

    // IF (Intensity Factor) = NP / FTP
    const intensityFactor = normalizedPower / ftp;

    // TSS = (t × NP × IF) / (FTP × 3600) × 100
    const tss = (durationSeconds * normalizedPower * intensityFactor) / (ftp * 3600) * 100;

    return tss;
}