Teknisk referanse og formler

Komplett matematisk implementasjon

Implementeringsguide

Denne siden gir deg kopierbare formler og steg-for-steg utregningsmetoder for alle metrikker i Run Analytics. Bruk disse for egne implementasjoner, verifisering eller dypere forståelse.

⚠️ Implementeringsnotater

  • Alle tider bør konverteres til sekunder for beregninger
  • rTSS-beregningen bruker Intensitetsfaktor i annen (IF²)
  • Valider alltid inntastede verdier mot fornuftige grenser
  • Håndter grensetilfeller (divisjon på null, negative verdier)

Kjerne-ytelsesmetrikker

Critical Run Speed (CRS)

Formel:

CRS (m/s) = (D₂ - D₁) / (T₂ - T₁)
CRS Tempo (min/km) = 16.667 / CRS (m/s)

🧪 Interaktiv kalkulator - Test formelen

CRS Tempo (min/km):
4:17
Utregning:
CRS (m/s) = (3600 - 1200) / (900 - 270) = 3.81 m/s
Tempo (min/km) = 1000 / 3.81 = 262 sekunder = 4:22

JavaScript Implementasjon:

function calculateCRS(distance1, time1, distance2, time2) {
  // Convert times to seconds
  const t1 = typeof time1 === 'string' ? timeToSeconds(time1) : time1;
  const t2 = typeof time2 === 'string' ? timeToSeconds(time2) : time2;

  // Calculate CRS velocity in m/s
  const crs_ms = (distance2 - distance1) / (t2 - t1);

  // Calculate pace per km in seconds
  const pace_per_km = 1000 / crs_ms;

  // Convert to mm:ss format
  const minutes = Math.floor(pace_per_km / 60);
  const seconds = Math.round(pace_per_km % 60);

  return {
    velocity_ms: crs_ms,
    pace_seconds: pace_per_km,
    pace_formatted: `${minutes}:${seconds.toString().padStart(2, '0')}`
  };
}

Running Stress Score (rTSS)

Komplett formel:

rTSS = (IF²) × Varighet (timer) × 100
IF = NSS / Terskelhastighet
NSS = Total Distanse / Total Tid (m/min)

🧪 Interaktiv kalkulator - Test formelen

Beregnet rTSS:
31
Utregning:
NSS = 5000m / 400min = 200 m/min
FTP = 1000 / (255/60) = 235.3 m/min
IF = 200 / 235.3 = 0.850
rTSS = 0.850² × (25/60) × 100 = 31

JavaScript Implementasjon:

function calculateRTSS(distance, timeMinutes, ftpMetersPerMin) {
  // Calculate Normalized Run Speed
  const nss = distance / timeMinutes;

  // Calculate Intensity Factor
  const intensityFactor = nss / ftpMetersPerMin;

  // Calculate hours
  const hours = timeMinutes / 60;

  // Calculate rTSS using quadratic intensity factor
  const rtss = Math.pow(intensityFactor, 2) * hours * 100;

  return Math.round(rtss);
}

// Example usage:
const rtss = calculateRTSS(3000, 55, 64.5);
// Returns: 65

// Helper: Convert CRS Pace to Running Speed (m/min)
function crsPaceToSpeed(crsPacePerKmSeconds) {
  // Speed in m/min = 1000m / (pace in minutes)
  return 1000 / (crsPacePerKmSeconds / 60);
}

// Example: CRS of 4:15 (255 seconds)
const speed = crsPaceToSpeed(255); // Returns: 235.3 m/min

Biomekanisk Effektivitet: Vertikal Ratio

Formel:

Vertikal Ratio (%) = (Vertikal Oscillasjon ÷ Steglengde) × 100

🧪 Interaktiv kalkulator - Test formelen

Vertikal Ratio:
7.4%
Utregning:
Vertikal Ratio = (8.5 / 115) × 100 = 7.4%

JavaScript Implementasjon:

function calculateVerticalRatio(oscillationCm, strideLengthCm) {
  return (oscillationCm / strideLengthCm) * 100;
}

function calculateEfficiencyFactor(paceMetersPerMin, avgHeartRate) {
  return paceMetersPerMin / avgHeartRate;
}

Stegmekanikk

Stegfrekvens (SR)

Formel:

SR = 60 / Syklustid (sekunder)
SR = (Antall steg / Tid i sekunder) × 60

🧪 Interaktiv kalkulator - Test formelen

Kadens (SPM):
180
Utregning:
Kadens = (180 / 60) × 60 = 180 SPM

JavaScript Implementasjon:

function calculateCadence(stepCount, timeSeconds) {
  return (stepCount / timeSeconds) * 60;
}

// Example:
const spm = calculateCadence(180, 60);
// Returns: 180 SPM

Steglengde

Formel:

Steglengde = Distanse / (Antall steg / 2)
Steglengde = Hastighet / (Kadens / 120)

JavaScript Implementasjon:

function calculateStrideLength(distanceMeters, stepCount) {
  // Stride length is distance / number of stride pairs (left+right)
  return distanceMeters / (stepCount / 2);
}

// Example (1000m, 800 steps):
const strideLength = calculateStrideLength(1000, 800);
// Returns: 2.50 meters per stride

Hastighet fra SR og DPS

Formel:

Hastighet (m/s) = (SR / 60) × DPS

JavaScript Implementasjon:

function calculateVelocity(strideRate, dps) {
  return (strideRate / 60) * dps;
}

// Example:
const velocity = calculateVelocity(70, 1.6);
// Returns: 1.87 m/s

Stride Index (SI)

Formel:

SI = Hastighet (m/s) × DPS (m/stride)

JavaScript Implementasjon:

function calculateStrideIndex(velocity, dps) {
  return velocity * dps;
}

// Example:
const si = calculateStrideIndex(1.5, 1.7);
// Returns: 2.55

Performance Management Chart (PMC)

CTL, ATL, TSB Beregninger

Formler:

CTL i dag = CTL i går + (TSS i dag - CTL i går) × (1/42)
ATL i dag = ATL i går + (TSS i dag - ATL i går) × (1/7)
TSB = CTL i går - ATL i går

JavaScript Implementasjon:

function updateCTL(previousCTL, todayTSS) {
  return previousCTL + (todayTSS - previousCTL) * (1/42);
}

function updateATL(previousATL, todayTSS) {
  return previousATL + (todayTSS - previousATL) * (1/7);
}

function calculateTSB(yesterdayCTL, yesterdayATL) {
  return yesterdayCTL - yesterdayATL;
}

// Calculate PMC for series of workouts
function calculatePMC(workouts) {
  let ctl = 0, atl = 0;
  const results = [];

  workouts.forEach(workout => {
    ctl = updateCTL(ctl, workout.tss);
    atl = updateATL(atl, workout.tss);
    const tsb = calculateTSB(ctl, atl);

    results.push({
      date: workout.date,
      tss: workout.tss,
      ctl: Math.round(ctl * 10) / 10,
      atl: Math.round(atl * 10) / 10,
      tsb: Math.round(tsb * 10) / 10
    });
  });

  return results;
}

// Example usage:
const workouts = [
  { date: '2025-01-01', tss: 50 },
  { date: '2025-01-02', tss: 60 },
  { date: '2025-01-03', tss: 45 },
  // ... more workouts
];

const pmc = calculatePMC(workouts);
// Returns array with CTL, ATL, TSB for each day

Avanserte beregninger

CRS fra flere distanser (Regresjonsmetode)

JavaScript Implementasjon:

function calculateCRSRegression(distances, times) {
  // Linear regression: distance = a + b*time
  const n = distances.length;
  const sumX = times.reduce((a, b) => a + b, 0);
  const sumY = distances.reduce((a, b) => a + b, 0);
  const sumXY = times.reduce((sum, x, i) => sum + x * distances[i], 0);
  const sumXX = times.reduce((sum, x) => sum + x * x, 0);

  const slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
  const intercept = (sumY - slope * sumX) / n;

  return {
    crs: slope, // Critical running velocity (m/s)
    anaerobic_capacity: intercept // Anaerobic distance capacity (m)
  };
}

// Example with multiple test distances:
const distances = [100, 200, 400, 800];
const times = [65, 150, 340, 720]; // in seconds
const result = calculateCRSRegression(distances, times);
// Returns: { crs: 1.18, anaerobic_capacity: 15.3 }

Intensitetsfaktor fra fart

JavaScript Implementasjon:

function calculateIntensityFactor(actualPaceMinKm, thresholdPaceMinKm) {
  // Convert pace strings "mm:ss" to seconds if necessary
  const actualSecs = typeof actualPaceMinKm === 'string' ? timeToSeconds(actualPaceMinKm) : actualPaceMinKm;
  const thresholdSecs = typeof thresholdPaceMinKm === 'string' ? timeToSeconds(thresholdPaceMinKm) : thresholdPaceMinKm;

  // IF is Threshold Pace / Actual Pace (faster pace = smaller seconds value)
  return thresholdSecs / actualSecs;
}

// Example:
const if_value = calculateIntensityFactor("4:45", "4:15");
// Returns: 0.895 (running at 89.5% of threshold)

Analyse av fartskonsistens

JavaScript Implementasjon:

function analyzePaceConsistency(segments) {
  const paces = segments.map(kilometer => kilometer.distance / kilometer.time);
  const avgPace = paces.reduce((a, b) => a + b) / paces.length;

  const variance = paces.reduce((sum, pace) =>
    sum + Math.pow(pace - avgPace, 2), 0) / paces.length;
  const stdDev = Math.sqrt(variance);
  const coefficientOfVariation = (stdDev / avgPace) * 100;

  return {
    avgPace,
    stdDev,
    coefficientOfVariation,
    consistency: coefficientOfVariation < 5 ? "Excellent" :
                 coefficientOfVariation < 10 ? "Good" :
                 coefficientOfVariation < 15 ? "Moderate" : "Variable"
  };
}

// Example:
const segments = [
  { distance: 100, time: 70 },
  { distance: 100, time: 72 },
  { distance: 100, time: 71 },
  // ...
  // ...
];
const analysis = analyzePaceConsistency(segments);
// Returns: { avgPace: 1.41, stdDev: 0.02, coefficientOfVariation: 1.4, consistency: "Excellent" }

Tretthetsanalyse fra stegeffektivitet

JavaScript Implementasjon:

function detectFatigue(segments) {
  // Compare Vertical Ratio of first and last segments
  const firstSegment = segments[0];
  const lastSegment = segments[segments.length - 1];

  const ratioIncrease = lastSegment.verticalRatio - firstSegment.verticalRatio;

  return {
    startRatio: firstSegment.verticalRatio,
    endRatio: lastSegment.verticalRatio,
    increase: Math.round(ratioIncrease * 10) / 10,
    fatigueLevel: ratioIncrease < 0.2 ? "Minimal" :
                  ratioIncrease < 0.5 ? "Moderate" :
                  ratioIncrease < 1.0 ? "Significant" : "Severe"
  };
}

// Example:
const segments = [
  { verticalRatio: 7.2 }, { verticalRatio: 7.3 }, { verticalRatio: 8.1 }
];
const fatigue = detectFatigue(segments);
// Returns: { startRatio: 7.2, endRatio: 8.1, increase: 0.9, fatigueLevel: "Significant" }

Datavalidering

Kvalitetssjekk av treningsdata

JavaScript Implementasjon:

function validateWorkoutData(workout) {
  const issues = [];

  // Check for reasonable pace ranges (3:00-8:00 per km)
  const avgPaceSecs = workout.totalTime / (workout.totalDistance / 1000);
  if (avgPaceSecs < 180 || avgPaceSecs > 480) {
    issues.push(`Unusual average pace: ${Math.round(avgPaceSecs)}s per km`);
  }

  // Check for reasonable Vertical Ratio (4% - 15%)
  if (workout.avgVerticalRatio < 4 || workout.avgVerticalRatio > 15) {
    issues.push(`Unusual Vertical Ratio: ${workout.avgVerticalRatio}%`);
  }

  // Check for reasonable cadence (120-220 SPM)
  const avgCadence = calculateCadence(workout.totalSteps, workout.totalTime);
  if (avgCadence < 120 || avgCadence > 220) {
    issues.push(`Unusual cadence: ${Math.round(avgCadence)} SPM`);
  }

  // Check for missing segments (gaps in time)
  if (workout.segments && workout.segments.length > 1) {
    for (let i = 1; i < workout.segments.length; i++) {
      const gap = workout.segments[i].startTime -
                  (workout.segments[i-1].startTime + workout.segments[i-1].duration);
      if (gap > 300) { // 5 minute gap
        issues.push(`Large gap detected between segments ${i} and ${i+1}`);
      }
    }
  }

  return {
    isValid: issues.length === 0,
    issues
  };
}

// Example:
const workout = {
  totalDistance: 2000,
  totalTime: 1800, // 30 minutes
  totalStrides: 800,
  segments: [/* kilometer data */]
};
const validation = validateWorkoutData(workout);
// Returns: { isValid: true, issues: [] }

Hjelpefunksjoner

Tidskonvertering

JavaScript Implementasjon:

// Convert mm:ss to seconds
function timeToSeconds(timeString) {
  const parts = timeString.split(':');
  return parseInt(parts[0]) * 60 + parseInt(parts[1]);
}

// Convert seconds to mm:ss
function secondsToTime(seconds) {
  const minutes = Math.floor(seconds / 60);
  const secs = Math.round(seconds % 60);
  return `${minutes}:${secs.toString().padStart(2, '0')}`;
}