summaryrefslogtreecommitdiff
path: root/iss/utils.py
blob: 656d4e3f270c185727e16b8ea4e9e9c78e15489d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def chunks(l, n):
    for i in range(0, len(l), n):
        yield l[i : i + n]


def seconds_to_minutes(secs):
    return f"{secs // 60}:{secs % 60:02}"


def normalize_lat_lng(lat, lng):
    if lat[0] not in "NS" or lng[0] not in "EW":
        raise Exception("Lat/lng must be formatted as N12.345 and E67.890")
    nlat = float(lat[1:]) * (-1 if lat[0] == "S" else 1)
    nlng = float(lng[1:]) * (-1 if lng[0] == "W" else 1)
    return nlat, nlng


def deg_to_cardinal(deg):
    cardinals = [
        "N",
        "NNE",
        "NE",
        "ENE",
        "E",
        "ESE",
        "SE",
        "SSE",
        "S",
        "SSW",
        "SW",
        "WSW",
        "W",
        "WNW",
        "NW",
        "NNW",
    ]
    return cardinals[round((deg % 360) / 22.5) % 16]