<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def api_tracks(self, icao24: str) -> Flight: """Returns a Flight corresponding to a given aircraft. Official documentation Retrieve the trajectory for a certain aircraft at a given time. The trajectory is a list of waypoints containing position, barometric altitude, true track and an on-ground flag. In contrast to state vectors, trajectories do not contain all information we have about the flight, but rather show the aircraft’s general movement pattern. For this reason, waypoints are selected among available state vectors given the following set of rules: - The first point is set immediately after the the aircraft’s expected departure, or after the network received the first poisition when the aircraft entered its reception range. - The last point is set right before the aircraft’s expected arrival, or the aircraft left the networks reception range. - There is a waypoint at least every 15 minutes when the aircraft is in-flight. - A waypoint is added if the aircraft changes its track more than 2.5°. - A waypoint is added if the aircraft changes altitude by more than 100m (~330ft). - A waypoint is added if the on-ground state changes. Tracks are strongly related to flights. Internally, we compute flights and tracks within the same processing step. As such, it may be benificial to retrieve a list of flights with the API methods from above, and use these results with the given time stamps to retrieve detailed track information. """

        c = requests.get(
            f"https://opensky-network.org/api/tracks/?icao24={icao24}"
        )
        if c.status_code != 200:
            raise ValueError(c.content.decode())
        json = c.json()

        df = pd.DataFrame.from_records(
            json["path"],
            columns=[
                "timestamp",
                "latitude",
                "longitude",
                "altitude",
                "track",
                "onground",
            ],
        ).assign(icao24=json["icao24"], callsign=json["callsign"])
        return Flight(self._format_dataframe(df, nautical_units=True))