-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbambu_data_normalizer.mjs
More file actions
87 lines (72 loc) · 2.54 KB
/
bambu_data_normalizer.mjs
File metadata and controls
87 lines (72 loc) · 2.54 KB
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
#!/usr/bin/env node
// bambu_data_normalizer.mjs
//
// Normalizes Bambu Lab data by linking machine profiles with printer definitions
import fs from 'fs';
import path from 'path';
// Get paths from command line arguments
const args = process.argv.slice(2);
if (args.length < 3) {
console.error('Usage: bambu_data_normalizer.mjs <BBL_MACHINE_DIR> <PRINTERS_DIR> <OUTPUT_DIR>');
process.exit(1);
}
const BBL_MACHINE_DIR = args[0];
const PRINTERS_DIR = args[1];
const OUTPUT_DIR = args[2];
// Validate input directories exist
if (!fs.existsSync(BBL_MACHINE_DIR)) {
console.error(`Error: BBL machine directory not found: ${BBL_MACHINE_DIR}`);
process.exit(1);
}
if (!fs.existsSync(PRINTERS_DIR)) {
console.error(`Error: Printers directory not found: ${PRINTERS_DIR}`);
process.exit(1);
}
// Create normalized directory
if (!fs.existsSync(OUTPUT_DIR)) {
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
}
// Read all machine profiles
const machineFiles = fs.readdirSync(BBL_MACHINE_DIR).filter(f => f.endsWith('.json'));
let processedCount = 0;
let errorCount = 0;
for (const machineFile of machineFiles) {
try {
const machinePath = path.join(BBL_MACHINE_DIR, machineFile);
const machine = JSON.parse(fs.readFileSync(machinePath, 'utf8'));
if (machine.model_id) {
// Try to find corresponding printer definition
const printerPath = path.join(PRINTERS_DIR, machine.model_id + '.json');
if (fs.existsSync(printerPath)) {
const printer = JSON.parse(fs.readFileSync(printerPath, 'utf8'));
// Create normalized entry combining both
const normalized = {
...machine,
printer_config: printer,
source_files: {
machine: machineFile,
printer: machine.model_id + '.json'
}
};
// Write normalized file
const outputPath = path.join(OUTPUT_DIR, machineFile);
fs.writeFileSync(outputPath, JSON.stringify(normalized, null, 2));
console.log(`Normalized: ${machine.name || 'Unknown'} (${machine.model_id})`);
processedCount++;
} else {
console.warn(`Warning: No printer definition found for ${machine.model_id}`);
}
} else {
console.warn(`Warning: No model_id found in ${machineFile}`);
}
} catch (err) {
console.error(`Error processing ${machineFile}:`, err.message);
errorCount++;
}
}
console.log(`\nBambu Lab data normalization complete`);
console.log(`Processed: ${processedCount} machines`);
if (errorCount > 0) {
console.log(`Errors: ${errorCount}`);
process.exit(1);
}