Update: 2026-07-06 02:31:40
This commit is contained in:
@@ -196,14 +196,14 @@ function calculateDynamicPrice($country, $minFare, $distance, $duration, $kazanR
|
||||
$isEgypt = ($kazanRow['country'] === 'Egypt' || $kazanRow['country'] === 'EG');
|
||||
|
||||
if ($isJordan) {
|
||||
$longSpeedPerKm = 0.30; // Reasonable long distance speed price for Jordan
|
||||
$longTripPerMin = 0.06; // Reasonable long distance minute price for Jordan
|
||||
$longSpeedPerKm = 0.17; // Long trips should be cheaper per km!
|
||||
$longTripPerMin = 0.02; // Highway time is usually discounted
|
||||
} else if ($isEgypt) {
|
||||
$longSpeedPerKm = 18.0; // Reasonable long distance speed price for Egypt
|
||||
$longTripPerMin = 0.80; // 80 Piasters for long distance minute price for Egypt
|
||||
$longSpeedPerKm = 10.0; // Cheaper for long distance
|
||||
$longTripPerMin = 0.40;
|
||||
} else {
|
||||
$longSpeedPerKm = 26.0; // Syrian Pound
|
||||
$longTripPerMin = 6.0; // Syrian Pound
|
||||
$longSpeedPerKm = 18.0;
|
||||
$longTripPerMin = 3.0;
|
||||
}
|
||||
|
||||
$mediumDistThresholdKm = 25.0;
|
||||
@@ -246,20 +246,14 @@ function calculateDynamicPrice($country, $minFare, $distance, $duration, $kazanR
|
||||
$isLongSpeed = $billableDistance > $longSpeedThresholdKm;
|
||||
|
||||
$perKmSpeedBaseFromServer = getPerKmRate($carType, $kazanRow);
|
||||
$perKmSpeed = $isLongSpeed ? $longSpeedPerKm : $perKmSpeedBaseFromServer;
|
||||
|
||||
$reductionPct40 = 0.0;
|
||||
if ($perKmSpeedBaseFromServer > 0) {
|
||||
$r = 1.0 - ($longSpeedPerKm / $perKmSpeedBaseFromServer);
|
||||
$reductionPct40 = max(0.0, min($maxReductionCap, $r));
|
||||
}
|
||||
$reductionPct100 = max(0.0, min($maxReductionCap, $reductionPct40 + $extraReduction100));
|
||||
|
||||
$distanceReduction = 0.0;
|
||||
if ($billableDistance > 100.0) {
|
||||
$distanceReduction = $reductionPct100;
|
||||
} else if ($billableDistance > 40.0) {
|
||||
$distanceReduction = $reductionPct40;
|
||||
$perKmSpeed = $perKmSpeedBaseFromServer;
|
||||
|
||||
if ($billableDistance > $longSpeedThresholdKm) { // > 40km
|
||||
$perKmSpeed = $longSpeedPerKm;
|
||||
} else if ($billableDistance > $mediumDistThresholdKm) { // 25km to 40km
|
||||
// Interpolate smoothly between base rate and long distance rate
|
||||
$progress = ($billableDistance - $mediumDistThresholdKm) / ($longSpeedThresholdKm - $mediumDistThresholdKm);
|
||||
$perKmSpeed = $perKmSpeedBaseFromServer - ($progress * ($perKmSpeedBaseFromServer - $longSpeedPerKm));
|
||||
}
|
||||
|
||||
date_default_timezone_set('Asia/Damascus');
|
||||
@@ -379,7 +373,12 @@ function calculateDynamicPrice($country, $minFare, $distance, $duration, $kazanR
|
||||
$compDist = (float)$row['distance_km'];
|
||||
$compPrice = (float)$row['total_price'];
|
||||
if ($compDist > 0) {
|
||||
$normalizedPrices[] = ($compPrice / $compDist) * $distance;
|
||||
// Only trust competitor trips that are somewhat close in distance scale (within 35%)
|
||||
// Otherwise, extrapolating a 3km traffic-heavy trip to 40km highway trip creates nonsense pricing
|
||||
$ratio = $distance / $compDist;
|
||||
if ($ratio >= 0.65 && $ratio <= 1.35) {
|
||||
$normalizedPrices[] = ($compPrice / $compDist) * $distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($normalizedPrices)) {
|
||||
|
||||
Reference in New Issue
Block a user