-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpricing_engine.py
More file actions
42 lines (32 loc) · 1.04 KB
/
Copy pathpricing_engine.py
File metadata and controls
42 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Pricing Engine - YOUR Patent Algorithms
"""
DELTA_MAX = 0.3
def greedy_surge(predicted_demand, drivers_available, is_high_demand_zone=False):
"""YOUR GREEDY ALGORITHM FROM PATENT"""
if predicted_demand == 0:
return 1.0
ratio = drivers_available / predicted_demand
if ratio < 0.5:
surge = 2.5
elif ratio < 0.7:
surge = 2.0
elif ratio < 1.0:
surge = 1.5
elif ratio < 1.3:
surge = 1.2
else:
surge = 1.0
if is_high_demand_zone:
surge = min(surge * 1.4, 2.5)
return round(surge, 2)
def stabilize_surge(previous_surge, current_surge):
"""YOUR STABILIZATION FROM PATENT"""
if previous_surge is None:
return current_surge
# S_t = min(max(S_raw, S_(t-1) - Δ_max), S_(t-1) + Δ_max)
stabilized = min(max(current_surge, previous_surge - DELTA_MAX), previous_surge + DELTA_MAX)
return round(stabilized, 2)
def calculate_fare(base_fare, surge):
"""Final fare calculation"""
return round(base_fare * surge, 2)