-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgas_stops.py
73 lines (67 loc) · 2.53 KB
/
gas_stops.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from extract_function import *
from map_extract import get_route
from carmpg_request import *
from find_gas_station import *
stops = []
meters = 1609.34
route = get_route()
mpg = get_mpg()
tot_range = 13.2 * meters * mpg
current_tank = 0
cost = 0
current_price = find_price("Charlotte")
#Going through and figuring out what distance to stop at
def returnCost():
global current_tank
global stops
global meters
global route
global tot_range
global current_tank
global cost
global current_price
for x in range(0,len(route['distanceSteps'])):
current_tank += route['distanceSteps'][x]['value']
if current_tank >= tot_range:
find_coord(x)
add_costs()
return round(cost, 2)
def returnStops():
return stops
#adding up the tank costs
def add_costs():
global current_tank
global cost
global meters
global current_price
cost += ((current_tank / meters) / mpg) * current_price
def find_coord(y):
global current_tank
global tot_range
global meters
global current_price
global cost
global mpg
global addy
temp_lat = 0
temp_lng = 0
temp_miles = current_tank - tot_range
if temp_miles < tot_range:
temp_rate = (current_tank - tot_range) / route['distanceSteps'][y]['value']
cost += ((tot_range / meters) / get_mpg()) * current_price
temp_lat = (route['startLocationSteps'][y]['lat'] - route['endLocationSteps'][y]['lat']) * temp_rate
temp_lng = (route['startLocationSteps'][y]['lng'] - route['endLocationSteps'][y]['lng']) * temp_rate
addy = find_addy(str(route['startLocationSteps'][y]['lat'] + temp_lat), str(route['startLocationSteps'][y]['lng'] + temp_lng))
stops.append(addy)
current_price = find_price(sparse_addy(addy))
current_tank = temp_miles
#edge case instead distanceSteps happens to need more than 1 stop on a single direction step
else:
temp_rate = (current_tank - tot_range) / route['distanceSteps'][y]['value']
cost += ((tot_range / meters) / get_mpg()) * current_price
temp_lat = (route['startLocationSteps'][y]['lat'] - route['endLocationSteps'][y]['lat']) * temp_rate
temp_lng = (route['startLocationSteps'][y]['lng'] - route['endLocationSteps'][y]['lng']) * temp_rate
addy = find_addy(str(route['startLocationSteps'][y]['lat'] + temp_lat), str(route['startLocationSteps'][y]['lng'] + temp_lng))
stops.append(addy)
current_price = find_price(sparse_addy(addy))
current_tank = temp_miles