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