Skip to content

Commit

Permalink
Fixes for aircraft classification and callsign naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ampledata committed May 27, 2021
1 parent fbfd2c0 commit aaf3c09
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 9 deletions.
20 changes: 15 additions & 5 deletions aircot/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ def set_friendly_mil(icao: int, attitude: str = "u", affil: str = "") -> tuple:
if icao_in_known_range(icao, "MIL"):
affil = "M"
attitude = "f"
return affil, attitude
return attitude, affil


def set_neutral_civ(icao: int, attitude: str = "u", affil: str = "") -> tuple:
"""Sets Affiliation and Attitude for known 'neutral' Civilian ICAOs."""
if icao_in_known_range(icao):
affil = "C"
attitude = "n"
return affil, attitude
return attitude, affil


def is_known_country_icao(icao: int, attitude: str = "u"):
Expand Down Expand Up @@ -238,16 +238,26 @@ def get_speed(gs: float = 0.0):
return str(speed)


def set_name_callsign(icao: str, reg, craft_type, flight, known_craft={}):
def set_name_callsign(icao: str, reg=None, craft_type=None, flight=None, known_craft={}):
"""
Sets the Name and Callsign of the CoT Event.
Populates the fields with ICAO, Reg, Craft Type and Flight data, if available.
"""
name: str = known_craft.get("CALLSIGN")
if name:
callsign = name
else:
name = f"ICAO-{icao}"
if flight:
if flight and reg and craft_type:
callsign = "-".join([flight.strip().upper(), reg, craft_type])
else:
elif reg and craft_type:
callsign = "-".join([reg, craft_type])
elif reg:
callsign = reg
elif flight:
callsign = flight.strip().upper()
else:
callsign = name
return name, callsign


Expand Down
78 changes: 74 additions & 4 deletions tests/test_aircot.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ def test_icao_in_range():

def test_set_neutral_civ():
icao = 0xC80000 # NZ-CIV Range
affil, attitude = aircot.functions.set_neutral_civ(icao)
attitude, affil = aircot.functions.set_neutral_civ(icao)
assert affil == "C"
assert attitude == "n"


def test_negative_set_neutral_civ():
icao = 0xC87F00 # NZ-MIL Range
affil, attitude = aircot.functions.set_neutral_civ(icao)
attitude, affil = aircot.functions.set_neutral_civ(icao)
assert "" == affil
assert "u" == attitude

Expand All @@ -97,14 +97,14 @@ def test_icao_in_range_mil():

def test_set_friendly_mil():
icao = 0xC87F00 # NZ-MIL Range
affil, attitude = aircot.functions.set_friendly_mil(icao)
attitude, affil = aircot.functions.set_friendly_mil(icao)
assert affil == "M"
assert attitude == "f"


def test_negative_set_friendly_mil():
icao = 0xC80000 # NZ-CIV Range
affil, attitude = aircot.functions.set_friendly_mil(icao)
attitude, affil = aircot.functions.set_friendly_mil(icao)
assert "" == affil
assert "u" == attitude

Expand Down Expand Up @@ -166,3 +166,73 @@ def test_negative_get_speed():
gs = ""
speed = aircot.functions.get_speed(gs)
assert speed == "9999999.0"


def test_negative_set_neutral_civ_lux():
icao = 0x4D0223 # from sn
affil, attitude = aircot.functions.set_neutral_civ(icao)
assert "u" == affil
assert "" == attitude


def test_adsb_to_cot_type_lux():
icao = 0x4D0223
category = "1"
flight = "SVW20E"
cot_type = aircot.adsb_to_cot_type(icao, category, flight)
assert "a-n-A-C-F" == cot_type


def test_set_name_callsign_icao():
#icao: str, reg, craft_type, flight, known_craft = {}
icao = "icao123"
reg = "reg123"
craft_type = "craft_type123"
flight = "flight123"
name, callsign = aircot.set_name_callsign(icao)
assert "ICAO-icao123" == name
assert "ICAO-icao123" == callsign


def test_set_name_callsign_icao_reg():
#icao: str, reg, craft_type, flight, known_craft = {}
icao = "icao123"
reg = "reg123"
craft_type = "craft_type123"
flight = "flight123"
name, callsign = aircot.set_name_callsign(icao, reg)
assert "ICAO-icao123" == name
assert "reg123" == callsign


def test_set_name_callsign_icao_reg_craft_type():
#icao: str, reg, craft_type, flight, known_craft = {}
icao = "icao123"
reg = "reg123"
craft_type = "craft_type123"
flight = "flight123"
name, callsign = aircot.set_name_callsign(icao, reg, craft_type)
assert "ICAO-icao123" == name
assert "reg123-craft_type123" == callsign


def test_set_name_callsign_icao_reg_craft_type_flight():
#icao: str, reg, craft_type, flight, known_craft = {}
icao = "icao123"
reg = "reg123"
craft_type = "craft_type123"
flight = "flight123"
name, callsign = aircot.set_name_callsign(icao, reg, craft_type, flight)
assert "ICAO-icao123" == name
assert "FLIGHT123-reg123-craft_type123" == callsign


def test_set_name_callsign_icao_flight():
#icao: str, reg, craft_type, flight, known_craft = {}
icao = "icao123"
reg = "reg123"
craft_type = "craft_type123"
flight = "flight123"
name, callsign = aircot.set_name_callsign(icao, flight=flight)
assert "ICAO-icao123" == name
assert "FLIGHT123" == callsign

0 comments on commit aaf3c09

Please sign in to comment.