Files
ihk-dijkstra/classes.py
2022-07-27 17:58:29 +02:00

127 lines
2.9 KiB
Python

"""
All types used in the project
"""
from enum import Enum
import math
class ParsingMode(Enum):
"""
Used for parsing
"""
LOCATIONS = 1
FLIGHTSCHEDULE = 2
FINDCONNECTION = 3
class LocationType(Enum):
"""
Differenciate between types of location
"""
LOCATION = 1
HALTESTELLE = 2
FLUGHAFEN = 3
class TransportData():
def __init__(self, co2: float, speed: float):
self.co2 = co2
self.speed = speed
def __str__(self):
return f"{{co2: {self.co2}, speed: {self.speed}}}"
def __repr__(self):
return self.__str__()
class TransportMethod(Enum):
"""
More precise methods of transportation.
They are subgroups of TransportKind.
"""
WALK = TransportData(0, 4)
CITY = TransportData(0.189, 30)
AUTOBAHN = TransportData(0.189, 100)
OEPNV = TransportData(0.055, 30)
ICE = TransportData(0.055, 100)
AIRPLANE = TransportData(0.2113, 900)
class TransportKind(Enum):
"""
General transportation kind.
Value: distance_penalty
"""
INDIVIDUAL = 0.2
TRAIN = 0.1
FLYING = 0.02
class Coordinate:
def __init__(self, lat: float, long: float):
self.lat = lat
self.long = long
def __str__(self):
return f"Lat: {self.lat}, Long: {self.long}"
def __repr__(self):
return self.__str__()
class Location:
def __init__(
self,
coord: Coordinate,
continent: int,
name: str,
type: LocationType):
self.coord = coord
self.continent = continent
self.name = name
self.type = type
def __str__(self):
return f"{{Location: {self.coord}, continent: {self.continent}, \
name: {self.name}, type: {self.type}}}"
def __repr__(self):
return self.__str__()
def distance(self, loc2) -> float:
"""
Calculate the distance im km between two locations with the help of the
Seitenkosinussatz
"""
rErde = 6378.388
lat1 = math.radians(float(self.coord.lat))
long1 = math.radians(float(self.coord.long))
lat2 = math.radians(float(loc2.coord.lat))
long2 = math.radians(float(loc2.coord.long))
inner = math.sin(lat1) * math.sin(lat2) + \
math.cos(lat1) * math.cos(lat2) * math.cos(long2 - long1)
return rErde * math.acos(inner)
def is_same_continent(self, loc2) -> bool:
return self.continent == loc2.continent
class DataSet:
"""
Represent the parsed data
"""
def __init__(self, locations: dict, flights: dict, connection: tuple):
self.locations = locations
self.flights = flights
self.connection = connection
def __str__(self):
return f"locations: {self.locations}, flights: {self.flights}, \
connection: {self.connection}"
def __repr__(self):
return self.__str__()