diff --git a/src/boat.py b/src/boat.py index 63e7921..df421e7 100644 --- a/src/boat.py +++ b/src/boat.py @@ -1,6 +1,6 @@ #coding:utf-8 import statistics -import custom_exception +from custom_exception.nothing_to_compare_error import * class Boat: def __init__(self, boat_id: str, name: str, sismer_id: str, url: str, avatar:str , temperatures: list, positions: list): @@ -13,15 +13,21 @@ class Boat: self.positions = positions def __str__(self): return f"{self.name}" + def __eq__(self, other): + if other is None: + return False + if not isinstance(other, self.__class__): + return False + return self.boat_id == other.boat_id def get_temp_mean(self): return statistics.mean(self.temperatures) def get_northiest_coords(self): if len(self.positions) == 0: - raise custom_exception.NothingToComapreError(f"{self.name} must have coords to compare") + raise NothingToCompareError(f"{self.name} must have coords to compare") best = self.positions[0] for position in self.positions: - if position.is_northiest_than(best): + if position.is_norther_than(best): best = position return best diff --git a/src/fleet.py b/src/fleet.py index de639f3..a66d80c 100644 --- a/src/fleet.py +++ b/src/fleet.py @@ -6,7 +6,7 @@ from position import Position from custom_exception.nothing_to_compare_error import NothingToCompareError class Fleet: - def __init__(self, year: int, loader: BoatsLoader): + def __init__(self, year: int, loader :BoatsLoader): self.boats = loader.load_boats(year) @@ -25,8 +25,16 @@ class Fleet: return best_boat, best_element_to_compare def get_northiest(self): - return self.compare_boats(Boat.get_northiest_coords, Position.is_northiest_than) + try: + return self.compare_boats(Boat.get_northiest_coords, Position.is_norther_than) + except TypeError as e: + print(e) + return; def get_highiest_heat_mean(self): - return self.compare_boats(Boat.get_temp_mean, float.__ge__) + try: + return self.compare_boats(Boat.get_temp_mean, float.__ge__) + except TypeError as e: + print(e) + return; diff --git a/src/position.py b/src/position.py index df4a9b3..50abbb6 100644 --- a/src/position.py +++ b/src/position.py @@ -7,7 +7,14 @@ class Position: def __str__(self): return f"[{self.latitude}; {self.longitude}]" - def is_northiest_than(self, position): + def is_norther_than(self, position): if position == None: return True return self.latitude >= position.latitude + def __eq__(self, other): + if other is None: + return False + if not isinstance(other, self.__class__): + return False + return self.longitude == other.longitude and self.latitude == other.latitude +