Files
peakskills/lib/evaluation-utils.ts
Julien Froidefond 1a0877f51d refactor: update data fetching in management pages and improve type imports
- Simplified data extraction from AdminService in SkillsPage, TeamsPage, and UsersPage.
- Updated import paths for Team type in user-related components for consistency.
- Added id and name properties to SkillCategory interface for better data structure.
- Enhanced logging in useSkillsManagement for debugging skill creation process.
2025-08-24 22:25:12 +02:00

54 lines
1.3 KiB
TypeScript

import {
SKILL_LEVEL_VALUES,
CategoryEvaluation,
RadarChartData,
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 createEmptyEvaluation(
categories: SkillCategory[]
): CategoryEvaluation[] {
return categories.map((category) => ({
category: category.category,
skills: [],
selectedSkillIds: [],
}));
}