| #!/usr/bin/env node |
| 'use strict'; |
| |
| |
| |
| |
| const fs = require('fs'); |
| const path = require('path'); |
| const DATA = path.join(__dirname, '..', 'data'); |
|
|
| const REQUIRED_TOP = ['id', 'type', 'payload', 'plb', 'meta']; |
| const VALID_TYPES = ['cheat_code','law','archetype','mistake','soul_code','chamber','council_member','council_trace','decision','reflection','doctrine_snippet','frequency_marker','daily_log','exit_calculation','frequency_band','dimension','multiversal_principle','quantum_decision','fractal_code','paradox']; |
| const VALID_HORIZONS = ['90d', '1yr', '5yr', 'multiple', 'real-time', 'generational', 'infinity']; |
|
|
| let errors = 0, warnings = 0, total = 0; |
|
|
| const files = fs.readdirSync(DATA).filter(f => f.endsWith('.jsonl')).sort(); |
| console.log('=== PLT Dataset Validation ===\n'); |
|
|
| for (const file of files) { |
| const rows = fs.readFileSync(path.join(DATA, file), 'utf8') |
| .split('\n').filter(Boolean); |
| let fileErrors = 0; |
|
|
| console.log(`\n${file} (${rows.length} rows)`); |
|
|
| rows.forEach((line, i) => { |
| total++; |
| let row; |
| try { row = JSON.parse(line); } catch { |
| errors++; fileErrors++; |
| console.log(` ✗ Row ${i+1}: invalid JSON`); |
| return; |
| } |
|
|
| |
| for (const k of REQUIRED_TOP) { |
| if (!(k in row)) { |
| errors++; fileErrors++; |
| console.log(` ✗ Row ${i+1} (${row.id || '?'}): missing field "${k}"`); |
| } |
| } |
|
|
| |
| if (!VALID_TYPES.includes(row.type)) { |
| warnings++; |
| console.log(` ⚠ Row ${i+1}: unknown type "${row.type}"`); |
| } |
|
|
| |
| const plb = row.plb || {}; |
| for (const k of ['profit', 'love', 'tax']) { |
| if (typeof plb[k] !== 'number' || plb[k] < -1 || plb[k] > 1) { |
| warnings++; |
| console.log(` ⚠ Row ${i+1}: plb.${k} out of range: ${plb[k]}`); |
| } |
| } |
| if (!VALID_HORIZONS.includes(plb.time_horizon)) { |
| warnings++; |
| console.log(` ⚠ Row ${i+1}: invalid time_horizon "${plb.time_horizon}"`); |
| } |
|
|
| |
| if (row.type === 'cheat_code' && !row.payload?.rcc_number) { |
| console.log(` ⚠ Row ${i+1}: cheat_code missing rcc_number`); |
| } |
| if (row.type === 'archetype' && !row.payload?.number) { |
| console.log(` ⚠ Row ${i+1}: archetype missing number`); |
| } |
|
|
| |
| if (!row.meta?.source_book) { |
| warnings++; |
| console.log(` ⚠ Row ${i+1}: meta.source_book missing`); |
| } |
| }); |
|
|
| console.log(` ${fileErrors} errors, ${rows.length - fileErrors} OK`); |
| } |
|
|
| console.log(`\n=== Summary ===`); |
| console.log(`Total rows: ${total}`); |
| console.log(`Errors: ${errors}`); |
| console.log(`Warnings: ${warnings}`); |
| console.log(errors === 0 ? '\n✓ All files valid.' : `\n✗ ${errors} errors found.`); |
| process.exit(errors > 0 ? 1 : 0); |
|
|