Update: 2026-07-06 19:17:19
This commit is contained in:
@@ -164,6 +164,43 @@ export async function saveSurgeInsights(
|
||||
await pool.execute(sql, flatParams);
|
||||
}
|
||||
|
||||
export async function saveSurgeZones(
|
||||
pool: mysql.Pool,
|
||||
zones: Array<{
|
||||
competitorName: string;
|
||||
countryCode: string;
|
||||
zoneKey: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
avgPpk: number;
|
||||
sampleCount: number;
|
||||
surgeMultiplier: number;
|
||||
}>
|
||||
): Promise<void> {
|
||||
if (zones.length === 0) return;
|
||||
|
||||
const values = zones.map(() => `(?, ?, ?, ?, ?, ?, ?, ?, NOW())`).join(',');
|
||||
const flatParams: (string | number)[] = [];
|
||||
|
||||
for (const z of zones) {
|
||||
flatParams.push(
|
||||
z.competitorName, z.countryCode, z.zoneKey,
|
||||
z.latitude, z.longitude, z.avgPpk, z.sampleCount, z.surgeMultiplier
|
||||
);
|
||||
}
|
||||
|
||||
const sql = `INSERT INTO competitor_surge_zones
|
||||
(competitor_name, country_code, zone_key, latitude, longitude, avg_ppk, sample_count, surge_multiplier, detected_at)
|
||||
VALUES ${values}
|
||||
ON DUPLICATE KEY UPDATE
|
||||
avg_ppk = VALUES(avg_ppk),
|
||||
sample_count = VALUES(sample_count),
|
||||
surge_multiplier = VALUES(surge_multiplier),
|
||||
detected_at = NOW()`;
|
||||
|
||||
await pool.execute(sql, flatParams);
|
||||
}
|
||||
|
||||
export async function closeConnections(): Promise<void> {
|
||||
if (mysqlPool) {
|
||||
await mysqlPool.end();
|
||||
|
||||
Reference in New Issue
Block a user