from datetime import date from typing import Optional def get_track_in_playlist_trend( current_position: int, previous_position: Optional[int], current_highest_position: int = None, none_as=None ) -> Optional[int]: """Calculate track is trend in playlist. Args: current_position (int): Current track position in playlist. current_highest_position (int): The highest position for the specific isrc of the specific playlist. previous_position (int or None): Previous track position in playlist. none_as (Any): value to mark None trend as, None - by default. Returns: Int or None """ if ( current_highest_position is not None and current_position != current_highest_position or previous_position is None ): return none_as return current_position - previous_position def is_track_in_playlist_new_entry( earliest_added_date: date, current_date: date = None, current_position: int = None, current_highest_position: int = None, ) -> bool: """Calculate if track is new in playlist. Args: current_position (int): Current track position in playlist. current_date (date): Date considered as current, "today" by default. current_highest_position (int): The highest position for the specific isrc of the specific playlist. earliest_added_date (date): Earliest date of track in playlist. Returns: Boolean """ current_date = current_date or date.today() return ( current_highest_position is None or current_position is None or current_position == current_highest_position ) and current_date == earliest_added_date