Skip to content

flight_collection module

Collection of Data to Science flights associated with a project.

Source code in d2spy/models/flight_collection.py
class FlightCollection:
    """Collection of Data to Science flights associated with a project."""

    def __init__(self, collection: List[Flight] = []):
        self.collection = collection

    def __getitem__(self, index: int) -> Flight:
        return self.collection[int(index)]

    def __len__(self) -> int:
        return len(self.collection)

    def __repr__(self) -> str:
        return f"FlightCollection({self.collection})"

    def filter_by_date(self, start_date: date, end_date: date) -> "FlightCollection":
        """Returns list of flights with at least one flight within the date range.

        Args:
            start_date (date): Starting date for the flight acquisition date range.
            end_date (date): Ending date for the flight acquisition date range.

        Returns:
            List[Flight]: List of flights with a flight within the date range.
        """
        filtered_collection = [
            flight
            for flight in self.collection
            if convert_from_str_to_date(flight.acquisition_date) >= start_date
            and convert_from_str_to_date(flight.acquisition_date) <= end_date
        ]
        return FlightCollection(collection=filtered_collection)

filter_by_date(start_date, end_date)

Returns list of flights with at least one flight within the date range.

Parameters:

Name Type Description Default
start_date date

Starting date for the flight acquisition date range.

required
end_date date

Ending date for the flight acquisition date range.

required

Returns:

Type Description
FlightCollection

List[Flight]: List of flights with a flight within the date range.

Source code in d2spy/models/flight_collection.py
def filter_by_date(self, start_date: date, end_date: date) -> "FlightCollection":
    """Returns list of flights with at least one flight within the date range.

    Args:
        start_date (date): Starting date for the flight acquisition date range.
        end_date (date): Ending date for the flight acquisition date range.

    Returns:
        List[Flight]: List of flights with a flight within the date range.
    """
    filtered_collection = [
        flight
        for flight in self.collection
        if convert_from_str_to_date(flight.acquisition_date) >= start_date
        and convert_from_str_to_date(flight.acquisition_date) <= end_date
    ]
    return FlightCollection(collection=filtered_collection)