File size: 2,960 Bytes
6bda4a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node

import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
import chalk from 'chalk';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Chemins
const RESULTS_DIR = path.join(__dirname, 'results');
const PUBLIC_DEBUG_DIR = path.join(__dirname, '..', '..', '..', '..', 'public', 'debug-umap');

/**
 * Copie les résultats UMAP dans le dossier public pour l'accès web
 */
async function copyResultsToPublic() {
  try {
    console.log(chalk.blue.bold('📁 Copie des résultats UMAP vers public/debug-umap\n'));
    
    // Créer le dossier de destination
    await fs.mkdir(PUBLIC_DEBUG_DIR, { recursive: true });
    
    // Lister tous les fichiers de résultats
    const files = await fs.readdir(RESULTS_DIR);
    const resultFiles = files.filter(file => file.endsWith('.json'));
    
    if (resultFiles.length === 0) {
      console.log(chalk.yellow('⚠️  Aucun résultat trouvé. Exécutez d\'abord: npm run batch-test'));
      return;
    }
    
    console.log(chalk.blue(`📋 ${resultFiles.length} fichiers à copier...`));
    
    // Copier chaque fichier
    for (const file of resultFiles) {
      const sourcePath = path.join(RESULTS_DIR, file);
      const destPath = path.join(PUBLIC_DEBUG_DIR, file);
      
      await fs.copyFile(sourcePath, destPath);
      console.log(chalk.green(`✅ ${file}`));
    }
    
    // Créer un fichier index avec la liste des configurations
    const configs = [];
    for (const file of resultFiles) {
      const content = await fs.readFile(path.join(RESULTS_DIR, file), 'utf8');
      const data = JSON.parse(content);
      configs.push({
        filename: file,
        testName: data.metadata.test_name,
        config: data.metadata.config,
        stats: data.metadata.stats,
        timestamp: data.metadata.generated_at
      });
    }
    
    // Trier par nom de test puis par timestamp
    configs.sort((a, b) => {
      if (a.testName !== b.testName) {
        return a.testName.localeCompare(b.testName);
      }
      return new Date(b.timestamp) - new Date(a.timestamp);
    });
    
    const indexContent = {
      generated_at: new Date().toISOString(),
      total_configs: configs.length,
      configs: configs
    };
    
    await fs.writeFile(
      path.join(PUBLIC_DEBUG_DIR, 'index.json'),
      JSON.stringify(indexContent, null, 2)
    );
    
    console.log(chalk.green(`\n✅ ${resultFiles.length} résultats copiés vers public/debug-umap/`));
    console.log(chalk.blue(`📊 Index créé: public/debug-umap/index.json`));
    console.log(chalk.gray(`\n💡 Accessible via: http://localhost:3000/debug-umap`));
    
  } catch (error) {
    console.error(chalk.red('💥 Erreur lors de la copie:'), error.message);
    process.exit(1);
  }
}

// Exécuter si appelé directement
if (import.meta.url === `file://${process.argv[1]}`) {
  copyResultsToPublic();
}