Skip to content

Add a new function for flight time calculation.  #1

@onesch

Description

@onesch

We need to add a new function to the Flight class that calculates the flight time based on the distance and average cruising speed of the aircraft. This will enhance the existing functionality by providing users with an estimate of how long their flight will take.

Steps:

  1. Update the Flight class in flight.py to include a new method calculate_flight_time.
  2. Use the average cruising speed of the aircraft (e.g., 840 km/h for Boeing 737-800) to calculate the flight time.
  3. Include this new calculation in the print_flight_params and _to_dict methods to display and save the flight time.

Example Implementation:

class Flight:
    # ... existing code ...

    def calculate_flight_time(self) -> float:
        average_speed_kmph = self.aircraft_data["Speed"]["Cruise"]
        if average_speed_kmph <= 0:
            raise ValueError("Invalid aircraft speed data.")
        
        flight_time_hours = self.distance_km / average_speed_kmph
        return flight_time_hours

    def print_flight_params(self) -> None:
        flight_time = self.calculate_flight_time()
        print(
            # ... existing code ...
            f"\nFlight Time: {flight_time:.2f} hours\n"
        )

    def _to_dict(self) -> dict[str, Any]:
        flight_dict = {
            # ... existing code ...
            "parameters": {
                # ... existing code ...
                "flight_time_hours": self.calculate_flight_time()
            }
        }
        return flight_dict

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions