心率检测评估报告
下面这个文件为中英词典的单词库
JavaScript:
// 存储最近20个非0心率
let heartRateData = [];
const MAX_POINTS = 20;
// 更新心率数据(在 export 里调用)
function addHeartRate(value) {
if (value <= 0) return; // 忽略0
heartRateData.push(value);
if (heartRateData.length > MAX_POINTS) {
heartRateData.shift(); // 只保留最近20个
}
this.report = generateConclusion();
this.metrics= calculateMetrics()
}
// 计算指标
function calculateMetrics() {
if (heartRateData.length === 0) {
return { count: 0, average: 0, min: 0, max: 0 };
}
const count = heartRateData.length;
const sum = heartRateData.reduce((acc, val) => acc + val, 0);
const average = sum / count;
const min = Math.min(...heartRateData);
const max = Math.max(...heartRateData);
return { count, average, min, max };
}
// 生成结论
function generateConclusion() {
const { average, min, max } = calculateMetrics();
let resultWord = '';
// 平均值结论
if (average < 60) {
resultWord += '您的平均心率较低,这可能表明您有良好的心血管健康或经常锻炼。\n';
} else if (average <= 100) {
resultWord += '您的平均心率在正常范围内。\n';
} else {
resultWord += '您的平均心率偏高,建议关注心血管健康。\n';
}
// 波动性
const range = max - min;
if (range > 30) {
resultWord += '心率波动较大,建议在相同条件下测量以获得更一致的数据。\n';
} else if (range > 15) {
resultWord += '心率数据有一定波动,属正常现象。\n';
} else {
resultWord += '心率数据稳定,身体状况较为稳定。\n';
}
// 异常值
const outlierThreshold = 1.5;
const q1 = calculateQuartile(0.25);
const q3 = calculateQuartile(0.75);
const iqr = q3 - q1;
const lowerBound = q1 - outlierThreshold * iqr;
const upperBound = q3 + outlierThreshold * iqr;
const outliers = heartRateData.filter(v => v < lowerBound || v > upperBound);
if (outliers.length > 0) {
resultWord += `检测到 ${outliers.length} 个异常值: ${outliers.join(', ')} bpm。\n`;
}
// 一般建议
resultWord += `一般建议:
在相同条件下测量(如晨起静息时)以获得可比数据
持续观察趋势比单个数值更重要
若心率长期异常并伴随不适,请及时就医
规律运动有助于心血管健康
`;
return resultWord;
}
// 计算四分位数
function calculateQuartile(percentile) {
const sortedData = [...heartRateData].sort((a, b) => a - b);
const index = (sortedData.length - 1) * percentile;
const lowerIndex = Math.floor(index);
const fraction = index - lowerIndex;
if (lowerIndex === sortedData.length - 1) {
return sortedData[lowerIndex];
}
return sortedData[lowerIndex] + fraction * (sortedData[lowerIndex + 1] - sortedData[lowerIndex]);
}