fix: 修复压力数据
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
import { fetchHRVForDate } from '@/utils/health';
|
||||
import dayjs from 'dayjs';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import React, { useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
||||
import { StressAnalysisModal } from './StressAnalysisModal';
|
||||
|
||||
interface StressMeterProps {
|
||||
value: number | null;
|
||||
updateTime?: Date;
|
||||
style?: any;
|
||||
hrvValue: number | null;
|
||||
curDate: Date
|
||||
}
|
||||
|
||||
export function StressMeter({ value, updateTime, style, hrvValue }: StressMeterProps) {
|
||||
export function StressMeter({ curDate }: StressMeterProps) {
|
||||
// 格式化更新时间显示
|
||||
const formatUpdateTime = (date: Date): string => {
|
||||
const now = dayjs();
|
||||
@@ -41,12 +39,31 @@ export function StressMeter({ value, updateTime, style, hrvValue }: StressMeterP
|
||||
|
||||
// HRV 范围: 30-110ms,对应压力指数: 100-0
|
||||
// 线性映射: stressIndex = 100 - ((hrv - 30) / (110 - 30)) * 100
|
||||
const normalizedHrv = Math.max(30, Math.min(110, hrv));
|
||||
const stressIndex = 100 - ((normalizedHrv - 30) / (110 - 30)) * 100;
|
||||
const normalizedHrv = Math.max(30, Math.min(130, hrv));
|
||||
const stressIndex = 100 - ((normalizedHrv - 30) / (130 - 30)) * 100;
|
||||
|
||||
return Math.round(stressIndex);
|
||||
};
|
||||
|
||||
const [hrvValue, setHrvValue] = useState(0)
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
getHrvData()
|
||||
}, [curDate])
|
||||
|
||||
const getHrvData = async () => {
|
||||
try {
|
||||
const data = await fetchHRVForDate(curDate)
|
||||
|
||||
if (data) {
|
||||
setHrvValue(data)
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 使用传入的 hrvValue 进行转换
|
||||
const stressIndex = convertHrvToStressIndex(hrvValue);
|
||||
|
||||
@@ -72,7 +89,7 @@ export function StressMeter({ value, updateTime, style, hrvValue }: StressMeterP
|
||||
return (
|
||||
<>
|
||||
<TouchableOpacity
|
||||
style={[styles.container, style]}
|
||||
style={[styles.container]}
|
||||
onPress={handlePress}
|
||||
activeOpacity={0.8}
|
||||
>
|
||||
@@ -81,15 +98,15 @@ export function StressMeter({ value, updateTime, style, hrvValue }: StressMeterP
|
||||
<View style={styles.leftSection}>
|
||||
<Text style={styles.title}>压力</Text>
|
||||
</View>
|
||||
{updateTime && (
|
||||
{/* {updateTime && (
|
||||
<Text style={styles.headerUpdateTime}>{formatUpdateTime(updateTime)}</Text>
|
||||
)}
|
||||
)} */}
|
||||
</View>
|
||||
|
||||
{/* 数值显示区域 */}
|
||||
<View style={styles.valueSection}>
|
||||
<Text style={styles.value}>{stressIndex === null ? '--' : stressIndex}</Text>
|
||||
<Text style={styles.unit}>%</Text>
|
||||
<Text style={styles.value}>{hrvValue || '--'}</Text>
|
||||
<Text>ms</Text>
|
||||
</View>
|
||||
|
||||
{/* 进度条区域 */}
|
||||
@@ -116,7 +133,7 @@ export function StressMeter({ value, updateTime, style, hrvValue }: StressMeterP
|
||||
visible={showStressModal}
|
||||
onClose={() => setShowStressModal(false)}
|
||||
hrvValue={hrvValue}
|
||||
updateTime={updateTime || new Date()}
|
||||
// updateTime={updateTime || new Date()}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user