argparser: add argparser and nice print
This commit is contained in:
21
graph.py
21
graph.py
@@ -3,6 +3,7 @@ Module, which creates a graph
|
||||
"""
|
||||
|
||||
from classes import DataSet, LocationType, TransportMethod, TransportKind
|
||||
from args import Settings
|
||||
|
||||
|
||||
def calc_co2(distance: float, kind: TransportKind) -> float:
|
||||
@@ -68,14 +69,15 @@ def calc_time(
|
||||
return waittime + (distance / TransportMethod.AIRPLANE.value.speed)
|
||||
|
||||
|
||||
def create_graph(dataset: DataSet) -> dict:
|
||||
def create_graph(dataset: DataSet, settings: Settings) -> dict:
|
||||
"""
|
||||
Creates the initial graph, with all edges
|
||||
"""
|
||||
locations = dataset.locations
|
||||
graph: dict = {}
|
||||
|
||||
print("Creating graph...")
|
||||
if settings.debug:
|
||||
print("Creating graph...")
|
||||
|
||||
# add nodes with no edges
|
||||
for start in locations:
|
||||
@@ -87,7 +89,8 @@ def create_graph(dataset: DataSet) -> dict:
|
||||
# skip, if we wouldnt go anywhere
|
||||
if start == dest:
|
||||
continue
|
||||
print(f"Searching for nodes from {start} to {dest}...")
|
||||
if settings.debug:
|
||||
print(f"Searching for nodes from {start} to {dest}...")
|
||||
distance = locations[start].distance(locations[dest])
|
||||
|
||||
# Individualtransport
|
||||
@@ -100,7 +103,8 @@ def create_graph(dataset: DataSet) -> dict:
|
||||
"co2": co2,
|
||||
"time": time}}
|
||||
graph[start].append(new_connection)
|
||||
print(f"Added new INDIVIDUAL connection from {start} to {dest}")
|
||||
if settings.debug:
|
||||
print(f"Added new INDIVIDUAL connection from {start} to {dest}")
|
||||
|
||||
# Train
|
||||
is_haltestelle = locations[start].type == LocationType.HALTESTELLE
|
||||
@@ -121,10 +125,12 @@ def create_graph(dataset: DataSet) -> dict:
|
||||
"co2": co2,
|
||||
"time": time}}
|
||||
graph[start].append(new_connection)
|
||||
print(f"Added new TRAIN connection from {start} to {dest}")
|
||||
if settings.debug:
|
||||
print(f"Added new TRAIN connection from {start} to {dest}")
|
||||
|
||||
# Flying
|
||||
print("Adding flights...")
|
||||
if settings.debug:
|
||||
print("Adding flights...")
|
||||
flights = dataset.flights
|
||||
for flight in flights:
|
||||
start = flight
|
||||
@@ -138,6 +144,7 @@ def create_graph(dataset: DataSet) -> dict:
|
||||
"co2": co2,
|
||||
"time": time}}
|
||||
graph[start].append(new_connection)
|
||||
print(f"Added new FLYING connection from {start} to {dest}")
|
||||
if settings.debug:
|
||||
print(f"Added new FLYING connection from {start} to {dest}")
|
||||
|
||||
return graph
|
||||
|
||||
Reference in New Issue
Block a user