Skip to content

Instantly share code, notes, and snippets.

@5aurabh
Created November 1, 2025 07:10
Show Gist options
  • Select an option

  • Save 5aurabh/f0b945d5c3bab61ed2ec447f8ec9c2a0 to your computer and use it in GitHub Desktop.

Select an option

Save 5aurabh/f0b945d5c3bab61ed2ec447f8ec9c2a0 to your computer and use it in GitHub Desktop.
face_scan_score_calculation
const calculateWellnessIndex = (results: VitalResults): number => {
let wellnessIndex = 0;
const ranges: HealthRanges = {
'Pulse Rate': { low: 60, normal: [60, 100], high: 100, monitor: 120 },
'Blood Oxygen': { low: 95, normal: [95, 100], high: 100, monitor: 100 },
'Blood Pressure': {
systolic: { low: 90, normal: [90, 120], high: 120, monitor: 140 },
diastolic: { low: 60, normal: [60, 80], high: 80, monitor: 90 }
},
'Respiration Rate': { low: 12, normal: [12, 20], high: 20, monitor: 24 },
'SDNN': { low: 50, normal: [50, 100], high: 100, monitor: 30 },
'RMSSD': { low: 20, normal: [20, 89], high: 107, monitor: 16 },
'Mean RRI': { low: 650, normal: [650, 1200], high: 1200, monitor: 600 },
'LF/HF Ratio': { low: 1, normal: [1, 2], high: 2, monitor: 3 },
'PNS Index': { low: -2, normal: [-2, 2], high: 2, monitor: 2 },
'SNS Index': { low: -5, normal: [-5, 5], high: 5, monitor: 5 },
'Stress Level': { low: 1, normal: [1, 3], high: 4, monitor: 5 },
'Stress Index': { low: 0, normal: [0, 150], high: 150, monitor: 200 },
'Wellness Index': { low: 0, normal: [70, 100], high: 100, monitor: 100 }
};
const checkRange = (value: number, range: RangeConfig) => {
return value >= range.normal[0] && value <= range.normal[1];
};
// Basic Vitals (Total: 40 points)
if (checkRange(Number(results.pulseRate), ranges['Pulse Rate'])) wellnessIndex += 5;
if (checkRange(Number(results.spo2), ranges['Blood Oxygen'])) wellnessIndex += 10;
// Commenting out blood pressure check for App Store submission
if (checkRange(Number(results.bloodPressure.systolic), ranges['Blood Pressure'].systolic) &&
checkRange(Number(results.bloodPressure.diastolic), ranges['Blood Pressure'].diastolic)) wellnessIndex += 15;
if (checkRange(Number(results.respirationRate), ranges['Respiration Rate'])) wellnessIndex += 10;
// Commenting out HRV Metrics for App Store submission
// HRV Metrics (Total: 25 points)
if (checkRange(Number(results.sdnn), ranges['SDNN'])) wellnessIndex += 10;
if (checkRange(Number(results.rmssd), ranges['RMSSD'])) wellnessIndex += 10;
if (checkRange(Number(results.meanRRI), ranges['Mean RRI'])) wellnessIndex += 5;
// ANS Metrics (Total: 30 points)
if (checkRange(Number(results.lfhf), ranges['LF/HF Ratio'])) wellnessIndex += 10;
if (checkRange(Number(results.pnsIndex), ranges['PNS Index'])) wellnessIndex += 10;
if (checkRange(Number(results.snsIndex), ranges['SNS Index'])) wellnessIndex += 10;
// Stress Level (5 points)
if (checkRange(Number(results.stressLevel), ranges['Stress Level'])) wellnessIndex += 5;
// Sum all possible points from each metric
// Pulse Rate: 5, Blood Oxygen: 10, Blood Pressure: 15, Respiration Rate: 10
// SDNN: 10, RMSSD: 10, Mean RRI: 5, LF/HF Ratio: 10, PNS Index: 10, SNS Index: 10, Stress Level: 5
const maxPointsPossible = 100;
// Scale back to 0-100 range
wellnessIndex = (wellnessIndex / maxPointsPossible) * 100;
// Ensure the score never exceeds 100
return Math.min(100, Math.round(wellnessIndex));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment