This commit is contained in:
Julien Froidefond
2025-08-20 15:43:24 +02:00
commit 09d2c5cbe1
100 changed files with 12494 additions and 0 deletions

76
lib/evaluation-utils.ts Normal file
View File

@@ -0,0 +1,76 @@
import {
SkillLevel,
SKILL_LEVEL_VALUES,
CategoryEvaluation,
RadarChartData,
UserEvaluation,
SkillCategory,
} from "./types";
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 saveUserEvaluation(evaluation: UserEvaluation): void {
try {
localStorage.setItem(
"peakSkills_userEvaluation",
JSON.stringify(evaluation)
);
} catch (error) {
console.error("Failed to save user evaluation:", error);
}
}
export function loadUserEvaluation(): UserEvaluation | null {
try {
const saved = localStorage.getItem("peakSkills_userEvaluation");
return saved ? JSON.parse(saved) : null;
} catch (error) {
console.error("Failed to load user evaluation:", error);
return null;
}
}
export function createEmptyEvaluation(
categories: SkillCategory[]
): CategoryEvaluation[] {
return categories.map((category) => ({
category: category.category,
skills: [],
selectedSkillIds: [],
}));
}