code styling: add comments and fix pep8

This commit is contained in:
Marco Thomas
2022-07-27 17:58:29 +02:00
parent 68885ff560
commit 8a0a59c222
4 changed files with 49 additions and 12 deletions

View File

@@ -41,19 +41,23 @@ def calc_time(
return distance / TransportMethod.WALK.value.speed
elif distance <= 10 + 1:
speed = 1 / TransportMethod.WALK.value.speed
return speed + ((distance - 1) / TransportMethod.CITY.value.speed)
new_dist = (distance - 1)
speed += (new_dist / TransportMethod.CITY.value.speed)
return speed
elif distance < 2000 + 10 + 1:
speed = 1 / TransportMethod.WALK.value.speed
speed += 10 / TransportMethod.CITY.value.speed
return speed + ((distance - 1 - 10) / TransportMethod.AUTOBAHN.value.speed)
new_dist = (distance - 1 - 10)
speed += (new_dist / TransportMethod.AUTOBAHN.value.speed)
return speed
case TransportKind.TRAIN:
if distance <= 25:
return distance / TransportMethod.OEPNV.value.speed
else:
return (distance / TransportMethod.ICE.value.speed)
case TransportKind.FLYING:
assert(flights != None)
assert(frm != None)
assert(flights)
assert(frm)
stops = flights[frm]["stops"]
domestic = flights[frm]["domestic"]
if domestic:
@@ -100,9 +104,10 @@ def create_graph(dataset: DataSet) -> dict:
# Train
is_haltestelle = locations[start].type == LocationType.HALTESTELLE
is_airport = locations[start].type == LocationType.FLUGHAFEN
is_same_continent = locations[start].is_same_continent(locations[dest])
# trains only drive from haltestelle and same continent
if is_haltestelle and is_same_continent:
if (is_haltestelle or is_airport) and is_same_continent:
dest_type = locations[dest].type
# there are only trains between haltestellen or airports
is_dest_haltestelle = dest_type == LocationType.HALTESTELLE