Update: 2026-07-06 19:17:19
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
* Cron integration: see crontab examples in package.json scripts
|
||||
*/
|
||||
|
||||
import { getMySQL, fetchSamples, saveFormulas, saveSurgeInsights, closeConnections } from './db/connection';
|
||||
import { getMySQL, fetchSamples, saveFormulas, saveSurgeInsights, saveSurgeZones, closeConnections } from './db/connection';
|
||||
import { runAnalysis } from './analysis/engine';
|
||||
import { Pool, RowDataPacket } from 'mysql2/promise';
|
||||
|
||||
@@ -255,6 +255,31 @@ async function processCompetitor(
|
||||
await saveSurgeInsights(pool, surgeInsights);
|
||||
console.log(` ✅ Saved surge insight: avg ${avgMultiplier.toFixed(3)}x, hours ${peakStart}:00-${peakEnd}:00`);
|
||||
}
|
||||
|
||||
// --- Save surge zones ---
|
||||
if (opts.mode !== 'report' && report.zones.length > 0) {
|
||||
// Find the standard tier formula to use as a baseline for calculating surge multipliers
|
||||
const standardTier = formulas.find(f => f.tier === 'standard') || formulas[0];
|
||||
const baselinePpk = standardTier ? standardTier.kmRate : 0.350;
|
||||
|
||||
const surgeZones = report.zones
|
||||
.filter(z => z.avgPpk > baselinePpk * 1.1) // Only keep zones with > 10% surge
|
||||
.map(z => ({
|
||||
competitorName: comp.competitor_name,
|
||||
countryCode: comp.country_code,
|
||||
zoneKey: z.zoneKey,
|
||||
latitude: z.centerLat,
|
||||
longitude: z.centerLng,
|
||||
avgPpk: z.avgPpk,
|
||||
sampleCount: z.samples.length,
|
||||
surgeMultiplier: parseFloat((z.avgPpk / baselinePpk).toFixed(3)),
|
||||
}));
|
||||
|
||||
if (surgeZones.length > 0) {
|
||||
await saveSurgeZones(pool, surgeZones);
|
||||
console.log(` ✅ Saved ${surgeZones.length} surge zones for heatmap`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchCompetitors(
|
||||
|
||||
Reference in New Issue
Block a user