Skip to content

Commit 369f140

Browse files
committed
fixes for classification
1 parent 010939c commit 369f140

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

aircot/functions.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ def lookup_country(icao: int) -> str:
3333
# FlightID AND/OR ICAO HEX address.
3434
def dolphin(flight: str = None, affil: str = None) -> str:
3535
"""
36-
Classify an aircraft as USCG Dolphin, or not.
37-
What, are you afraid of water?
38-
"""
39-
# MH-65D Dolphins out of Air Station SF use older ADS-B, but luckily have
40-
# a similar "flight" name.
41-
# For example:
42-
# * C6540 / AE2682 https://globe.adsbexchange.com/?icao=ae2682
43-
# * C6604 / AE26BB https://globe.adsbexchange.com/?icao=ae26bb
36+
Classify an aircraft as USCG Dolphin.
37+
38+
MH-65D Dolphins out of Air Station SF use older ADS-B, but luckily have a similar "flight" name.
4439
40+
For example:
41+
* C6540 / AE2682 https://globe.adsbexchange.com/?icao=ae2682
42+
* C6604 / AE26BB https://globe.adsbexchange.com/?icao=ae26bb
43+
"""
4544
if flight and len(flight) >= 3 and flight[:2] in ["C6", b"C6"]:
4645
if affil and affil in ["M", b"M"]:
4746
return True
@@ -55,7 +54,7 @@ def adsb_to_cot_type(icao: typing.Union[str, int], category: typing.Union[str, N
5554
ADS-B DO-260B or GDL90 Emitter Category & Flight ID.
5655
"""
5756
affil = "C" # Affiliation, default = Civilian
58-
attitude = "u" # Attitude
57+
attitude = "u" # Attitude, default = unknown
5958

6059
# TODO: If the adsbx has a leading underscore and registry "_N1234A" then that means they are calculating the
6160
# registration with no Flight ID field transmited
@@ -161,30 +160,30 @@ def get_icao_range(range_type: str = "CIV") -> list:
161160
return list(filter(lambda x: f"-{range_type}" in x, aircot.DEFAULT_HEX_RANGES))
162161

163162

164-
def icao_in_range(icao_int, range_type: str = "CIV") -> bool:
163+
def icao_in_known_range(icao_int, range_type: str = "CIV") -> bool:
165164
"""Determines if the given ICAO is within a known 'friendly' ICAO Range."""
166165
for idx in get_icao_range(range_type):
167166
if aircot.DEFAULT_HEX_RANGES[idx]["start"] <= icao_int <= aircot.DEFAULT_HEX_RANGES[idx]["end"]:
168167
return True
169168

170169

171-
def set_friendly_mil(icao_int: int, affil: str = "", attitude: str = ".") -> tuple:
170+
def set_friendly_mil(icao: int, attitude: str = "u", affil: str = "") -> tuple:
172171
"""Sets Affiliation and Attitude for 'friendly' Military ICAOs."""
173-
if icao_in_range(icao_int, "MIL"):
174-
attitude = "f"
172+
if icao_in_known_range(icao, "MIL"):
175173
affil = "M"
174+
attitude = "f"
176175
return affil, attitude
177176

178177

179-
def set_neutral_civ(icao: int, affil: str = "", attitude: str = ".") -> tuple:
178+
def set_neutral_civ(icao: int, attitude: str = "u", affil: str = "") -> tuple:
180179
"""Sets Affiliation and Attitude for known 'neutral' Civilian ICAOs."""
181-
if icao_in_range(icao):
182-
attitude = "n"
180+
if icao_in_known_range(icao):
183181
affil = "C"
182+
attitude = "n"
184183
return affil, attitude
185184

186185

187-
def is_known_country_icao(icao: int, attitude: str = "."):
186+
def is_known_country_icao(icao: int, attitude: str = "u"):
188187
if lookup_country(icao):
189188
attitude = "n"
190189
return attitude
@@ -201,7 +200,7 @@ def is_civ(icao: int) -> str:
201200
return True
202201

203202

204-
def is_tw(icao: int, attitude: str = ".") -> str:
203+
def is_tw(icao: int, attitude: str = "u") -> str:
205204
tw_start = 0x899000
206205
tw_end = 0x8993FF
207206
if tw_start <= icao <= tw_end:
@@ -280,7 +279,6 @@ def icao_int_to_hex(addr) -> str:
280279

281280

282281

283-
284282
def read_known_craft(csv_file: str) -> list:
285283
"""Reads the FILTER_CSV file into a `list`"""
286284
all_rows = []

tests/test_aircot.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,27 @@ def test_negative_get_icao_range():
7171

7272
def test_icao_in_range():
7373
icao = 0xC80000 # NZ-CIV Range
74-
in_range = aircot.functions.icao_in_range(icao)
74+
in_range = aircot.functions.icao_in_known_range(icao)
7575
assert in_range == True
7676

7777

78+
def test_set_neutral_civ():
79+
icao = 0xC80000 # NZ-CIV Range
80+
affil, attitude = aircot.functions.set_neutral_civ(icao)
81+
assert affil == "C"
82+
assert attitude == "n"
83+
84+
85+
def test_negative_set_neutral_civ():
86+
icao = 0xC87F00 # NZ-MIL Range
87+
affil, attitude = aircot.functions.set_neutral_civ(icao)
88+
assert "" == affil
89+
assert "u" == attitude
90+
91+
7892
def test_icao_in_range_mil():
7993
icao = 0xC87F00 # NZ-MIL Range
80-
in_range = aircot.functions.icao_in_range(icao, "MIL")
94+
in_range = aircot.functions.icao_in_known_range(icao, "MIL")
8195
assert in_range == True
8296

8397

@@ -91,8 +105,8 @@ def test_set_friendly_mil():
91105
def test_negative_set_friendly_mil():
92106
icao = 0xC80000 # NZ-CIV Range
93107
affil, attitude = aircot.functions.set_friendly_mil(icao)
94-
assert affil == ""
95-
assert attitude == "."
108+
assert "" == affil
109+
assert "u" == attitude
96110

97111

98112
def test_cot_type_from_category_A5():

0 commit comments

Comments
 (0)