272 lines
6.7 KiB
TypeScript
272 lines
6.7 KiB
TypeScript
#!/usr/bin/env tsx
|
|
import { getPool, closePool } from "../services/database";
|
|
import { SkillLevel } from "../lib/types";
|
|
import * as fs from "fs";
|
|
import * as path from "path";
|
|
|
|
// Données de test
|
|
const TEST_DIRECTION = "TestData";
|
|
|
|
const TEST_TEAMS = [
|
|
{ id: "test-frontend", name: "Test Frontend Team" },
|
|
{ id: "test-backend", name: "Test Backend Team" },
|
|
{ id: "test-fullstack", name: "Test Full Stack Team" },
|
|
{ id: "test-mobile", name: "Test Mobile Team" },
|
|
{ id: "test-devops", name: "Test DevOps Team" },
|
|
];
|
|
|
|
const FIRST_NAMES = [
|
|
"Alice",
|
|
"Bob",
|
|
"Claire",
|
|
"David",
|
|
"Emma",
|
|
"François",
|
|
"Julie",
|
|
"Marc",
|
|
"Sophie",
|
|
"Thomas",
|
|
"Amélie",
|
|
"Nicolas",
|
|
"Camille",
|
|
"Pierre",
|
|
"Léa",
|
|
"Julien",
|
|
"Marie",
|
|
"Antoine",
|
|
"Sarah",
|
|
"Maxime",
|
|
];
|
|
|
|
const LAST_NAMES = [
|
|
"Martin",
|
|
"Bernard",
|
|
"Dubois",
|
|
"Thomas",
|
|
"Robert",
|
|
"Petit",
|
|
"Durand",
|
|
"Leroy",
|
|
"Moreau",
|
|
"Simon",
|
|
"Laurent",
|
|
"Lefebvre",
|
|
"Michel",
|
|
"Garcia",
|
|
"David",
|
|
"Bertrand",
|
|
"Roux",
|
|
"Vincent",
|
|
"Fournier",
|
|
"Morel",
|
|
];
|
|
|
|
const SKILL_LEVELS: SkillLevel[] = [
|
|
"never",
|
|
"not-autonomous",
|
|
"autonomous",
|
|
"expert",
|
|
];
|
|
|
|
interface SkillData {
|
|
id: string;
|
|
name: string;
|
|
description: string;
|
|
icon?: string;
|
|
category: string;
|
|
}
|
|
|
|
async function loadAllSkills(): Promise<SkillData[]> {
|
|
const skillsDir = path.join(__dirname, "../data/skills");
|
|
const files = fs
|
|
.readdirSync(skillsDir)
|
|
.filter((file) => file.endsWith(".json"));
|
|
|
|
const allSkills: SkillData[] = [];
|
|
|
|
for (const file of files) {
|
|
const filePath = path.join(skillsDir, file);
|
|
const content = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
|
|
content.skills.forEach((skill: any) => {
|
|
allSkills.push({
|
|
...skill,
|
|
category: content.category,
|
|
});
|
|
});
|
|
}
|
|
|
|
return allSkills;
|
|
}
|
|
|
|
function getRandomElement<T>(array: T[]): T {
|
|
return array[Math.floor(Math.random() * array.length)];
|
|
}
|
|
|
|
function getRandomElements<T>(array: T[], count: number): T[] {
|
|
const shuffled = [...array].sort(() => 0.5 - Math.random());
|
|
return shuffled.slice(0, count);
|
|
}
|
|
|
|
function generateRandomLevel(): SkillLevel {
|
|
const weights = [0.3, 0.4, 0.25, 0.05]; // never, not-autonomous, autonomous, expert
|
|
const random = Math.random();
|
|
let cumulative = 0;
|
|
|
|
for (let i = 0; i < weights.length; i++) {
|
|
cumulative += weights[i];
|
|
if (random <= cumulative) {
|
|
return SKILL_LEVELS[i];
|
|
}
|
|
}
|
|
|
|
return "never";
|
|
}
|
|
|
|
async function insertTestTeams() {
|
|
const pool = getPool();
|
|
|
|
console.log("🏢 Création des teams de test...");
|
|
|
|
for (const team of TEST_TEAMS) {
|
|
await pool.query(
|
|
"INSERT INTO teams (id, name, direction) VALUES ($1, $2, $3) ON CONFLICT (id) DO NOTHING",
|
|
[team.id, team.name, TEST_DIRECTION]
|
|
);
|
|
console.log(` ✅ Team créée: ${team.name}`);
|
|
}
|
|
}
|
|
|
|
async function insertTestUsers() {
|
|
const pool = getPool();
|
|
|
|
console.log("👥 Création des utilisateurs de test...");
|
|
|
|
const users = [];
|
|
|
|
// Créer 3-5 utilisateurs par team
|
|
for (const team of TEST_TEAMS) {
|
|
const userCount = 3 + Math.floor(Math.random() * 3); // 3 à 5 utilisateurs
|
|
|
|
for (let i = 0; i < userCount; i++) {
|
|
const firstName = getRandomElement(FIRST_NAMES);
|
|
const lastName = getRandomElement(LAST_NAMES);
|
|
|
|
try {
|
|
const result = await pool.query(
|
|
`INSERT INTO users (first_name, last_name, team_id)
|
|
VALUES ($1, $2, $3)
|
|
ON CONFLICT (first_name, last_name, team_id) DO NOTHING
|
|
RETURNING uuid_id`,
|
|
[firstName, lastName, team.id]
|
|
);
|
|
|
|
if (result.rows.length > 0) {
|
|
users.push({
|
|
uuid: result.rows[0].uuid_id,
|
|
firstName,
|
|
lastName,
|
|
teamId: team.id,
|
|
});
|
|
console.log(
|
|
` ✅ Utilisateur créé: ${firstName} ${lastName} (${team.name})`
|
|
);
|
|
}
|
|
} catch (error) {
|
|
// Ignore les conflits de nom
|
|
console.log(
|
|
` ⚠️ Utilisateur ${firstName} ${lastName} existe déjà dans ${team.name}`
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
return users;
|
|
}
|
|
|
|
async function insertTestEvaluations(users: any[], skills: SkillData[]) {
|
|
const pool = getPool();
|
|
|
|
console.log("📊 Création des évaluations de test...");
|
|
|
|
for (const user of users) {
|
|
console.log(` 📝 Évaluation pour ${user.firstName} ${user.lastName}...`);
|
|
|
|
// Créer une évaluation pour cet utilisateur
|
|
const evaluationResult = await pool.query(
|
|
`INSERT INTO user_evaluations (user_uuid)
|
|
VALUES ($1)
|
|
ON CONFLICT (user_uuid) DO UPDATE SET last_updated = CURRENT_TIMESTAMP
|
|
RETURNING id`,
|
|
[user.uuid]
|
|
);
|
|
|
|
const evaluationId = evaluationResult.rows[0].id;
|
|
|
|
// Sélectionner aléatoirement 15-30 skills à évaluer
|
|
const skillsToEvaluate = getRandomElements(
|
|
skills,
|
|
15 + Math.floor(Math.random() * 16)
|
|
);
|
|
|
|
for (const skill of skillsToEvaluate) {
|
|
const level = generateRandomLevel();
|
|
const canMentor = level === "expert" ? Math.random() > 0.5 : false;
|
|
const wantsToLearn =
|
|
level === "never" || level === "not-autonomous"
|
|
? Math.random() > 0.3
|
|
: false;
|
|
|
|
await pool.query(
|
|
`INSERT INTO skill_evaluations (user_evaluation_id, skill_id, level, can_mentor, wants_to_learn, is_selected)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
ON CONFLICT (user_evaluation_id, skill_id) DO UPDATE SET
|
|
level = $3, can_mentor = $4, wants_to_learn = $5, updated_at = CURRENT_TIMESTAMP`,
|
|
[evaluationId, skill.id, level, canMentor, wantsToLearn, true]
|
|
);
|
|
}
|
|
|
|
console.log(` ✅ ${skillsToEvaluate.length} skills évaluées`);
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
try {
|
|
console.log("🚀 Génération des données de test...\n");
|
|
|
|
// Charger tous les skills
|
|
console.log("📚 Chargement des skills...");
|
|
const skills = await loadAllSkills();
|
|
console.log(` ✅ ${skills.length} skills chargées\n`);
|
|
|
|
// Créer les teams
|
|
await insertTestTeams();
|
|
console.log("");
|
|
|
|
// Créer les utilisateurs
|
|
const users = await insertTestUsers();
|
|
console.log(` 📊 Total: ${users.length} utilisateurs créés\n`);
|
|
|
|
// Créer les évaluations
|
|
await insertTestEvaluations(users, skills);
|
|
console.log("");
|
|
|
|
console.log("✨ Données de test générées avec succès !");
|
|
console.log(`📈 Résumé :`);
|
|
console.log(` - Direction: ${TEST_DIRECTION}`);
|
|
console.log(` - Teams: ${TEST_TEAMS.length}`);
|
|
console.log(` - Utilisateurs: ${users.length}`);
|
|
console.log(` - Skills disponibles: ${skills.length}`);
|
|
} catch (error) {
|
|
console.error("❌ Erreur lors de la génération des données:", error);
|
|
process.exit(1);
|
|
} finally {
|
|
await closePool();
|
|
}
|
|
}
|
|
|
|
// Exécuter le script
|
|
if (require.main === module) {
|
|
main();
|
|
}
|