graph: Fix co2 and time calculation
This commit is contained in:
19
graph.py
19
graph.py
@@ -37,7 +37,6 @@ def calc_time(
|
||||
"""
|
||||
match kind:
|
||||
case TransportKind.INDIVIDUAL:
|
||||
distance += distance * TransportKind.INDIVIDUAL.value
|
||||
if distance <= 1:
|
||||
return distance / TransportMethod.WALK.value.speed
|
||||
elif distance <= 10 + 1:
|
||||
@@ -45,10 +44,9 @@ def calc_time(
|
||||
return speed + ((distance - 1) / TransportMethod.CITY.value.speed)
|
||||
elif distance < 2000 + 10 + 1:
|
||||
speed = 1 / TransportMethod.WALK.value.speed
|
||||
speed += 10 / TransportMethod.WALK.value.speed
|
||||
speed += 10 / TransportMethod.CITY.value.speed
|
||||
return speed + ((distance - 1 - 10) / TransportMethod.AUTOBAHN.value.speed)
|
||||
case TransportKind.TRAIN:
|
||||
distance += distance * TransportKind.TRAIN.value
|
||||
if distance <= 25:
|
||||
return distance / TransportMethod.OEPNV.value.speed
|
||||
else:
|
||||
@@ -58,7 +56,6 @@ def calc_time(
|
||||
case TransportKind.FLYING:
|
||||
assert(flights != None)
|
||||
assert(frm != None)
|
||||
distance += distance * TransportKind.FLYING.value
|
||||
stops = flights[frm]["stops"]
|
||||
domestic = flights[frm]["domestic"]
|
||||
if domestic:
|
||||
@@ -91,8 +88,9 @@ def create_graph(dataset: DataSet) -> dict:
|
||||
|
||||
# Individualtransport
|
||||
if distance <= 2000 + 10 + 1:
|
||||
time = calc_time(distance, TransportKind.INDIVIDUAL)
|
||||
co2 = calc_co2(distance, TransportKind.INDIVIDUAL)
|
||||
dist = distance + distance * TransportKind.INDIVIDUAL.value
|
||||
time = calc_time(dist, TransportKind.INDIVIDUAL)
|
||||
co2 = calc_co2(dist, TransportKind.INDIVIDUAL)
|
||||
new_connection: dict = {dest:
|
||||
{"kind": TransportKind.INDIVIDUAL,
|
||||
"co2": co2,
|
||||
@@ -105,8 +103,9 @@ def create_graph(dataset: DataSet) -> dict:
|
||||
dest_type = locations[dest].type
|
||||
# there are only trains between haltestellen or airports
|
||||
if dest_type == LocationType.HALTESTELLE or dest_type == LocationType.FLUGHAFEN:
|
||||
time = calc_time(distance, TransportKind.TRAIN)
|
||||
co2 = calc_co2(distance, TransportKind.TRAIN)
|
||||
dist = distance + distance * TransportKind.TRAIN.value
|
||||
time = calc_time(dist, TransportKind.TRAIN)
|
||||
co2 = calc_co2(dist, TransportKind.TRAIN)
|
||||
new_connection: dict = {dest:
|
||||
{"kind": TransportKind.TRAIN,
|
||||
"co2": co2,
|
||||
@@ -121,8 +120,8 @@ def create_graph(dataset: DataSet) -> dict:
|
||||
start = flight
|
||||
dest = flights[flight]["to"]
|
||||
distance = locations[start].distance(locations[dest])
|
||||
time = calc_time(distance, TransportKind.FLYING, flights, start)
|
||||
co2 = calc_co2(distance, TransportKind.FLYING)
|
||||
time = calc_time(distance * TransportKind.FLYING.value, TransportKind.FLYING, flights, start)
|
||||
co2 = calc_co2(distance * TransportKind.FLYING.value, TransportKind.FLYING)
|
||||
new_connection: dict = {dest:
|
||||
{"kind": TransportKind.TRAIN,
|
||||
"co2": co2,
|
||||
|
||||
Reference in New Issue
Block a user