def _get_berthed_ships(self, date: datetime) -> pd.DataFrame: """ Queries the LogKeeper instance to obtain a list of the ships berthed to the port at the given date. """ start_of_today = date.replace(hour=0, minute=0, second=0, microsecond=0) ships_at_port = self.log_keeper.read_ships_at_port( start_of_today + relativedelta(days=1), start_of_today ) return ships_at_port[ ships_at_port.apply( lambda ship: get_ship_status(ship, date) == ShipStatus.BERTHED, axis=1 ) ].reset_index(drop=True)
def determine_entry_status(entry: pd.Series) -> str: """ Takes the raw data from a ship entry and presents a human readable status. Uses the arrival, berthing, and sailing dates to determine the status of the ship. """ # Use the current date to compare the with the others # Store it so that it's consistent over the runtime of the function now = datetime.now() status = get_ship_status(entry, now) berco = get_ship_berth_number(entry) if berco is None: berco_desc = 'T.B.D.' else: berco_desc = '#' + str(berco) if status == ShipStatus.TO_ARRIVE: is_prediction = entry['TA_is_predicted'] status_desc = f'Arrives {make_delta_human_readable(now, entry["TA"])}' elif status == ShipStatus.ARRIVED: is_prediction = entry['TA_is_predicted'] status_desc = f'Arrived, berths at {berco_desc} {make_delta_human_readable(now, entry["TB"])}' elif status == ShipStatus.BERTHED: is_prediction = entry['TB_is_predicted'] status_desc = f'Berthed at {berco_desc}, sails {make_delta_human_readable(now, entry["TS"])}' elif status == ShipStatus.SAILED: is_prediction = entry['TS_is_predicted'] status_desc = f'Sailed {make_delta_human_readable(now, entry["TS"])}' else: is_prediction = False status_desc = 'Unknown' if is_prediction: return '[PREDICTION] ' + status_desc return status_desc
def test_berthed_ship(ship_entry: pd.Series) -> None: assert get_ship_status( ship_entry, datetime(2010, 1, 1, 13, 0, 0) ) == ShipStatus.BERTHED
def test_sailed_ship(ship_entry: pd.Series) -> None: assert get_ship_status( ship_entry, datetime(2010, 1, 2, 12, 0, 0) ) == ShipStatus.SAILED
def test_arrived_ship(ship_entry: pd.Series) -> None: assert get_ship_status( ship_entry, datetime(2010, 1, 1, 11, 0, 0) ) == ShipStatus.ARRIVED