From 7c22f6e83b030a168f93e84f3999ecfb037ac0fc Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 20 Nov 2020 02:19:38 -0800 Subject: [PATCH] Change mach function to take altitude in meters. All of the callers are passing altitude in meters because that's what pydcs uses. This still returns knots which makes it extra weird, but that's what almost all of the callers expect. It's probably a good idea to introduce some explicit types for the various distance and speed units to avoid these sorts of mistakes. --- gen/flights/traveltime.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gen/flights/traveltime.py b/gen/flights/traveltime.py index 742dfce3..7cc45069 100644 --- a/gen/flights/traveltime.py +++ b/gen/flights/traveltime.py @@ -45,20 +45,21 @@ class GroundSpeed: return int(cls.from_mach(mach, altitude)) # knots @staticmethod - def from_mach(mach: float, altitude: int) -> float: + def from_mach(mach: float, altitude_m: int) -> float: """Returns the ground speed in knots for the given mach and altitude. Args: mach: The mach number to convert to ground speed. - altitude: The altitude in feet. + altitude_m: The altitude in meters. Returns: The ground speed corresponding to the given altitude and mach number in knots. """ # https://www.grc.nasa.gov/WWW/K-12/airplane/atmos.html - if altitude <= 36152: - temperature_f = 59 - 0.00356 * altitude + altitude_ft = altitude_m * 3.28084 + if altitude_ft <= 36152: + temperature_f = 59 - 0.00356 * altitude_ft else: # There's another formula for altitudes over 82k feet, but we better # not be planning waypoints that high...