feat(health): 优化HRV数据质量分析与获取逻辑

- 新增HRV质量评分算法,综合评估数值有效性、数据源可靠性与元数据完整性
- 实现最佳质量HRV值自动选取,优先手动测量并过滤异常值
- 扩展TS类型定义,支持完整HRV数据结构及质量分析接口
- 移除StressMeter中未使用的时间格式化函数与注释代码
- 默认采样数提升至50条,增强质量分析准确性
This commit is contained in:
richarjiang
2025-09-24 18:29:58 +08:00
parent 6303795870
commit 83e534c4a7
3 changed files with 374 additions and 41 deletions

View File

@@ -1,5 +1,4 @@
import { fetchHRVForDate } from '@/utils/health';
import dayjs from 'dayjs';
import { Image } from 'expo-image';
import { LinearGradient } from 'expo-linear-gradient';
import React, { useEffect, useState } from 'react';
@@ -11,26 +10,6 @@ interface StressMeterProps {
}
export function StressMeter({ curDate }: StressMeterProps) {
// 格式化更新时间显示
const formatUpdateTime = (date: Date): string => {
const now = dayjs();
const updateTime = dayjs(date);
const diffMinutes = now.diff(updateTime, 'minute');
const diffHours = now.diff(updateTime, 'hour');
const diffDays = now.diff(updateTime, 'day');
if (diffMinutes < 1) {
return '刚刚更新';
} else if (diffMinutes < 60) {
return `${diffMinutes}分钟前更新`;
} else if (diffHours < 24) {
return `${diffHours}小时前更新`;
} else if (diffDays < 7) {
return `${diffDays}天前更新`;
} else {
return updateTime.format('MM-DD HH:mm');
}
};
// 将HRV值转换为压力指数0-100
// HRV值范围30-110ms映射到压力指数100-0
@@ -58,7 +37,7 @@ export function StressMeter({ curDate }: StressMeterProps) {
const data = await fetchHRVForDate(curDate)
if (data) {
setHrvValue(data)
setHrvValue(Math.round(data.value))
}
} catch (error) {
@@ -138,7 +117,7 @@ export function StressMeter({ curDate }: StressMeterProps) {
visible={showStressModal}
onClose={() => setShowStressModal(false)}
hrvValue={hrvValue}
// updateTime={updateTime || new Date()}
updateTime={new Date()}
/>
</>
);