to_16_point optimization

This commit is contained in:
ManchurianMan 2023-10-04 15:18:49 -04:00
parent 86179768ff
commit 7bbc13fc54

View file

@ -127,40 +127,37 @@ def to_description(symbol_code):
def to_16_point(degrees): def to_16_point(degrees):
# 360 degrees / 16 = 22.5 degrees of arc or 11.25 degrees around the point """
if degrees > (360 - 11.25) or degrees <= 11.25: Convert degrees to a 16-point compass direction.
return 'N'
if degrees > 11.25 and degrees <= (11.25 + 22.5): Parameters:
return 'NNE' degrees (float): The degrees to be converted.
if degrees > (11.25 + (22.5 * 1)) and degrees <= (11.25 + (22.5 * 2)):
return 'NE' Returns:
if degrees > (11.25 + (22.5 * 2)) and degrees <= (11.25 + (22.5 * 3)): str: The corresponding compass direction.
return 'ENE' """
if degrees > (11.25 + (22.5 * 3)) and degrees <= (11.25 + (22.5 * 4)): directions = [
return 'E' (11.25, 'N'),
if degrees > (11.25 + (22.5 * 4)) and degrees <= (11.25 + (22.5 * 5)): (33.75, 'NNE'),
return 'ESE' (56.25, 'NE'),
if degrees > (11.25 + (22.5 * 5)) and degrees <= (11.25 + (22.5 * 6)): (78.75, 'ENE'),
return 'SE' (101.25, 'E'),
if degrees > (11.25 + (22.5 * 6)) and degrees <= (11.25 + (22.5 * 7)): (123.75, 'ESE'),
return 'SSE' (146.25, 'SE'),
if degrees > (11.25 + (22.5 * 7)) and degrees <= (11.25 + (22.5 * 8)): (168.75, 'SSE'),
return 'S' (191.25, 'S'),
if degrees > (11.25 + (22.5 * 8)) and degrees <= (11.25 + (22.5 * 9)): (213.75, 'SSW'),
return 'SSW' (236.25, 'SW'),
if degrees > (11.25 + (22.5 * 9)) and degrees <= (11.25 + (22.5 * 10)): (258.75, 'WSW'),
return 'SW' (281.25, 'W'),
if degrees > (11.25 + (22.5 * 10)) and degrees <= (11.25 + (22.5 * 11)): (303.75, 'WNW'),
return 'WSW' (326.25, 'NW'),
if degrees > (11.25 + (22.5 * 11)) and degrees <= (11.25 + (22.5 * 12)): (348.75, 'NNW'),
return 'W' (360, 'N')
if degrees > (11.25 + (22.5 * 12)) and degrees <= (11.25 + (22.5 * 13)): ]
return 'WNW' for max_degree, direction in directions:
if degrees > (11.25 + (22.5 * 13)) and degrees <= (11.25 + (22.5 * 14)): if degrees <= max_degree:
return 'NW' return direction
if degrees > (11.25 + (22.5 * 14)) and degrees <= (11.25 + (22.5 * 15)):
return 'NNW'
def meters_to_miles(meters): def meters_to_miles(meters):
return round(meters * 0.00062137, 2) return round(meters * 0.00062137, 2)