import fs from 'fs'; import path from 'path'; const statsFile = 'uploads/rpi-webcam-2/2025/12/20/stats.json'; if (fs.existsSync(statsFile)) { try { const raw = fs.readFileSync(statsFile, 'utf8'); const stats = JSON.parse(raw); console.log(`Original count: ${stats.length}`); const filtered = stats.filter(s => { // Keep if ocr_val is missing (null/undefined) or >= 99 // User said: "filter values below 99". // If ocr_val is null, it's not "below 99" technically, it's "no value". // But if we are charting, we usually want to keep valid data. // If ocr_val is strictly a number < 99, remove it. if (typeof s.ocr_val === 'number') { return s.ocr_val >= 99; } // Keep entries without ocr_val or null return true; }); console.log(`Filtered count: ${filtered.length}`); fs.writeFileSync(statsFile, JSON.stringify(filtered, null, 2)); console.log('Stats file filtered and saved.'); } catch (e) { console.error('Error processing stats:', e); } } else { console.error('File not found:', statsFile); }