← back to Prestige Car Wash
scripts/best-times.js
27 lines
#!/usr/bin/env node
'use strict';
/**
* best-times.js — validate + (optionally) recompute the best-times recommendations.
*
* The demand/post-time windows in data/best-times.json are curated from car-wash
* seasonality + local SFV signal. This script validates the shape and prints a summary
* so the admin "Best Times" tabs always have well-formed data. Extend later to pull
* real IG/GBP insights once owner tokens exist.
*/
const fs = require('fs');
const path = require('path');
const FILE = path.join(__dirname, '..', 'data', 'best-times.json');
const bt = JSON.parse(fs.readFileSync(FILE, 'utf8'));
const days = bt.traffic?.by_day || [];
const peak = days.filter(d => d.demand >= 5).map(d => d.day);
const slow = days.filter(d => d.demand <= 2).map(d => d.day);
console.log('⏰ Best-times summary');
console.log(` peak demand days: ${peak.join(', ') || '—'}`);
console.log(` slow days (B2B/mobile fill): ${slow.join(', ') || '—'}`);
console.log(` post platforms configured: ${Object.keys(bt.post_times || {}).filter(k => k !== 'note').join(', ')}`);
console.log(` spend triggers: ${(bt.market_times?.triggers || []).length}`);
if (!days.length) { console.error(' ✖ traffic.by_day is empty'); process.exit(1); }
console.log(' ✔ best-times.json valid');