feat: 完善中文心理测评平台
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
interface WHO5CalculatorProps {
|
||||
answers: { [key: number]: string };
|
||||
}
|
||||
|
||||
export const calculateWHO5Results = ({ answers }: WHO5CalculatorProps) => {
|
||||
const itemScores = Array.from({ length: 5 }, (_, index) => {
|
||||
const questionId = index + 1;
|
||||
return Number.parseInt(answers[questionId] ?? "0", 10);
|
||||
});
|
||||
|
||||
const rawScore = itemScores.reduce((sum, score) => sum + score, 0);
|
||||
const percentageScore = rawScore * 4;
|
||||
const hasVeryLowItem = itemScores.some((score) => score <= 1);
|
||||
|
||||
let level: "high" | "moderate" | "low" | "very_low" = "high";
|
||||
if (rawScore <= 7) {
|
||||
level = "very_low";
|
||||
} else if (rawScore <= 12) {
|
||||
level = "low";
|
||||
} else if (rawScore <= 17) {
|
||||
level = "moderate";
|
||||
}
|
||||
|
||||
return {
|
||||
rawScore,
|
||||
percentageScore,
|
||||
itemScores,
|
||||
hasVeryLowItem,
|
||||
level,
|
||||
needsAttention: rawScore <= 12 || hasVeryLowItem,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user