Files
peakskills/lib/evaluation-utils.ts
2025-08-24 22:03:15 +02:00

57 lines
1.4 KiB
TypeScript

import {
SkillLevel,
SKILL_LEVEL_VALUES,
CategoryEvaluation,
RadarChartData,
UserEvaluation,
SkillCategory,
} from "./types";
import { evaluationClient } from "../clients";
export function calculateCategoryScore(
categoryEvaluation: CategoryEvaluation
): number {
if (categoryEvaluation.skills.length === 0) return 0;
const evaluatedSkills = categoryEvaluation.skills.filter(
(skill) => skill.level !== null
);
if (evaluatedSkills.length === 0) return 0;
const totalScore = evaluatedSkills.reduce((sum, skill) => {
return sum + SKILL_LEVEL_VALUES[skill.level!];
}, 0);
return totalScore / evaluatedSkills.length;
}
export function generateRadarData(
evaluations: CategoryEvaluation[],
categories: SkillCategory[]
): RadarChartData[] {
const maxScore = 3; // Expert level
return categories.map((category) => {
const evaluation = evaluations.find(
(e) => e.category === category.category
);
const score = evaluation ? calculateCategoryScore(evaluation) : 0;
return {
category: category.category,
score: Math.round(score * 10) / 10, // Round to 1 decimal
maxScore,
};
});
}
export function createEmptyEvaluation(
categories: SkillCategory[]
): CategoryEvaluation[] {
return categories.map((category) => ({
category: category.category,
skills: [],
selectedSkillIds: [],
}));
}