Video views never charge past the budget; audit reads scheduled and uncharged campaigns correctly
chargeVideoView charged a full view even when the budget had less left (#39: 602 of 600). It now charges only what is left, and nothing once the budget is gone; the viewer is still credited and the view still counted, so views keep matching the watch log. Audit: featured bookings are judged from their start time, not creation (#275 was flagged hours before its scheduled start); clicks-over-views only flags campaigns that charged the buyer (#146, a placeholder video paused by the source sweep, never spent a credit). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ function refunded() { const out = {}; try { for (const f of fs.readdirSync(R.dat
|
||||
async function run() {
|
||||
const out = { checkedAt: Date.now(), checks: [] };
|
||||
if (!db.enabled()) { out.checks.push({ name: 'Counters', ok: true, detail: 'JSON mode: not checked', issues: [] }); return out; }
|
||||
const camps = await db.q("SELECT id, name, type, status, imps, clicks, spent, accrued, budget, created, house FROM campaigns WHERE house=0 OR house IS NULL");
|
||||
const camps = await db.q("SELECT id, name, type, status, imps, clicks, spent, accrued, budget, created, starts, house FROM campaigns WHERE house=0 OR house IS NULL");
|
||||
const back = refunded(); for (const c of camps) if (back[c.id]) c.spent = Math.max(0, Number(c.spent) - back[c.id]); // already made right
|
||||
const logStart = (await db.q('SELECT MIN(day) d FROM camp_hours'))[0].d; const logStartMs = logStart ? Date.parse(logStart + 'T00:00:00Z') : 0;
|
||||
const byType = t => camps.filter(c => c.type === t);
|
||||
@@ -42,13 +42,18 @@ async function run() {
|
||||
// 4. featured: a live booking older than two hours must have views
|
||||
{
|
||||
const issues = []; const now = Date.now();
|
||||
for (const c of byType('featured').filter(c => c.status === 'active' && now - Number(c.created) > 2 * 3600e3)) if (!Number(c.imps)) issues.push('#' + c.id + ' ' + c.name.slice(0, 30) + ': live with 0 views');
|
||||
// counted from when the booking STARTS: a paid booking scheduled for later has no views yet by design
|
||||
// (#275 was flagged on 2026-09-27 hours before its 7 PM start)
|
||||
for (const c of byType('featured').filter(c => c.status === 'active' && now - Math.max(Number(c.created), Number(c.starts) || 0) > 2 * 3600e3)) if (!Number(c.imps)) issues.push('#' + c.id + ' ' + c.name.slice(0, 30) + ': live with 0 views');
|
||||
add('featured: live bookings have views', issues, byType('featured').filter(c => c.status === 'active').length + ' live bookings');
|
||||
}
|
||||
// 5. clicks can only exceed views where a click precedes the counted view (visits, login)
|
||||
{
|
||||
const issues = [];
|
||||
for (const c of camps.filter(c => !['visits', 'login'].includes(c.type) && Number(c.clicks) > Number(c.imps) + 5)) issues.push('#' + c.id + ' ' + c.name.slice(0, 30) + ' (' + c.type + '): ' + c.clicks + ' clicks vs ' + c.imps + ' views');
|
||||
// only where the buyer was charged: this check protects buyers, and a campaign that never spent a credit
|
||||
// cannot have overcharged anyone (#146: a placeholder video that never played, paused by the source
|
||||
// sweep, clicks on its button while the player failed, 0 credits spent)
|
||||
for (const c of camps.filter(c => !['visits', 'login'].includes(c.type) && Number(c.spent) + Number(c.accrued || 0) > 0 && Number(c.clicks) > Number(c.imps) + 5)) issues.push('#' + c.id + ' ' + c.name.slice(0, 30) + ' (' + c.type + '): ' + c.clicks + ' clicks vs ' + c.imps + ' views');
|
||||
add('clicks vs views', issues, 'campaigns with more clicks than views, where that cannot happen');
|
||||
}
|
||||
// 6. budgets: spent can never pass budget
|
||||
|
||||
Reference in New Issue
Block a user