Update: 2026-07-09 01:01:15
This commit is contained in:
@@ -129,6 +129,46 @@ export async function saveFormulas(
|
||||
await pool.execute(sql, flatParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* لقطة insert-only من معاملات كل معادلة — لا تُستبدل أبداً، بعكس
|
||||
* competitor_secret_formulas (UPSERT). هاي المصدر اللي يقارن عليه
|
||||
* محرك الثبات (cron_pricing_stability_engine.php) "المعامل اليوم
|
||||
* مقابل المعامل قبل أسبوع" لتمييز التغيير الحقيقي عن البرومو المؤقت.
|
||||
*/
|
||||
export async function saveFormulaHistory(
|
||||
pool: mysql.Pool,
|
||||
formulas: Array<{
|
||||
competitorName: string;
|
||||
countryCode: string;
|
||||
tier: string;
|
||||
baseFare: number;
|
||||
kmRate: number;
|
||||
minRate: number;
|
||||
minFare: number;
|
||||
rSquared: number;
|
||||
sampleCount: number;
|
||||
}>
|
||||
): Promise<void> {
|
||||
if (formulas.length === 0) return;
|
||||
|
||||
const values = formulas.map(() => `(?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())`).join(',');
|
||||
const flatParams: (string | number)[] = [];
|
||||
|
||||
for (const f of formulas) {
|
||||
flatParams.push(
|
||||
f.competitorName, f.countryCode, f.tier,
|
||||
f.baseFare, f.kmRate, f.minRate, f.minFare,
|
||||
f.rSquared, f.sampleCount
|
||||
);
|
||||
}
|
||||
|
||||
const sql = `INSERT INTO competitor_formula_history
|
||||
(competitor_name, country_code, tier, base_fare, price_per_km, price_per_min, min_fare, r_squared, sample_size, snapshotted_at)
|
||||
VALUES ${values}`;
|
||||
|
||||
await pool.execute(sql, flatParams);
|
||||
}
|
||||
|
||||
export async function saveSurgeInsights(
|
||||
pool: mysql.Pool,
|
||||
insights: Array<{
|
||||
|
||||
Reference in New Issue
Block a user