Skip to content

Commit

Permalink
Heading and speed added to wecdis positions
Browse files Browse the repository at this point in the history
  • Loading branch information
mew-nsc committed Dec 13, 2021
1 parent fc190d5 commit f0e1cd3
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 7 deletions.
22 changes: 15 additions & 7 deletions importers/wecdis_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def __init__(self):
)
self.current_line_no = None
self.platform_name = None
self.platform_speed = None
self.platform_heading = None
self.platform_speed = {}
self.platform_heading = {}
self.timestamp = None
self.elevation = None
self.set_highlighting_level(HighlightLevel.NONE)
Expand Down Expand Up @@ -129,7 +129,9 @@ def handle_speed(self, tokens, line_number):
speed_token.text, units, line_number, self.errors, self.error_type
)
if speed_valid:
self.platform_speed = speed
key = "1" if tokens[1].text == MsgType.SPEED else tokens[1].text[-1]
print(f"Speed index == {key}")
self.platform_speed[key] = speed
speed_token.record(self.name, "Speed", self.platform_speed)

def handle_heading(self, tokens, line_number):
Expand All @@ -144,7 +146,9 @@ def handle_heading(self, tokens, line_number):
heading_token.text, line_number, self.errors, self.error_type
)
if heading_valid:
self.platform_heading = heading
key = "1" if tokens[1].text == MsgType.HEADING else tokens[1].text[-1]
print(f"Heading index == {key}")
self.platform_heading[key] = heading
heading_token.record(self.name, "Heading", self.platform_heading)

def handle_timestamp(self, dza_tokens, line_number):
Expand Down Expand Up @@ -280,12 +284,16 @@ def handle_position(self, data_store, line_number, tokens, datafile, change_id):
if speed_valid:
state.speed = speed
speed_token.record(self.name, "speed", speed)
elif tokens[1].text == "POS":
elif tokens[1].text.startswith("POS"):
key = "1" if tokens[1].text == MsgType.POSITION else tokens[1].text[-1]
print(f"Position index == {key}")
print(f"speed: {self.platform_speed}")
print(f"hdg: {self.platform_heading}")
# Speed / heading for POS is taken from the VEL/HDG lines
if self.platform_speed:
state.speed = self.platform_speed
state.speed = self.platform_speed[key]
if self.platform_heading:
state.heading = self.platform_heading
state.heading = self.platform_heading[key]
if self.elevation:
state.elevation = self.elevation

Expand Down
22 changes: 22 additions & 0 deletions tests/sample_data/wecdis_files/multiple_pos_hdg_vel_sources.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$POSL,DZA,20211101,010230.123,012345678*21
$POSL,SOUND,ON*10
$POSL,CHART,LOAD,A:/File/Path,1234,SOURCE,1,01 Nov 2021, 2 Nov 2021*A01
$POSL,VER,Some text,License,2020 Jun 08, S123*0D
$POSL,VNM,NONSUCH*5C
$POSL,PDS,11.1,M*00
$POSL,POS,GPS,1234.1678,N,01234.1678,W,10.01,,Some text,N,,,,,*45
$POSL,HDG,200.0,a,b,c,d*CA
$POSL,DZA,20211101,010233.010,012345678*18
$POSL,POS,GPS,1234.1678,N,01234.1678,W,10.01,,Some text,N,,,,,*45
$POSL,DZA,20211101,010305.010,012345678*18
$POSL,HDG1,201.0,a,b,c,d*CA
$POSL,HDG2,199.43,a,b,c,d*CA
$POSL,POS1,GPS,1235.0678,N,01236.1678,W,10.01,,Some text,N,,,,,*45
$POSL,POS2,GPS2,1235.0678,N,01236.1678,W,10.01,,Some text,N,,,,,*45
$POSL,PDS,19.7,M*00
$POSL,HDG,201.2,a,b,c,d*CA
$POSL,VEL,SPL,a,b,c,3.08,a,b,c,d*11
$POSL,VEL2,SPL,a,b,c,6.60,a,b,c,d*12
$POSL,DZA,20211212,010335.010,012345678*18
$POSL,POS1,GPS,1235.9978,N,01237.1678,W,10.01,,Some text,N,,,,,*45
$POSL,POS2,GPS2,1235.9978,N,01237.1678,W,10.01,,Some text,N,,,,,*45
88 changes: 88 additions & 0 deletions tests/test_load_wecdis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
INVALID_LON_DATA_PATH = os.path.join(FILE_PATH, "sample_data/wecdis_files/invalid_lon.log")
DEPTH_DATA_PATH = os.path.join(FILE_PATH, "sample_data/wecdis_files/depth.log")
# INVALID_TTM_PATH = os.path.join(FILE_PATH, "sample_data/wecdis_files/ttm_invalid.log")
DATA_MULTI_POS_HDG_VEL_SOURCES_PATH = os.path.join(
FILE_PATH, "sample_data/wecdis_files/multiple_pos_hdg_vel_sources.log"
)


class TestWecdisImporter(unittest.TestCase):
Expand Down Expand Up @@ -499,6 +502,91 @@ def test_wecdis_multi_timestep_sample(self):
# assert round(stored_contacts[4].range.to(ureg.kilometer).magnitude, 2) == 12.79
# assert stored_contacts[4].track_number == "TTM_18_b"

def test_wecdis_multi_pos_sources_sample(self):
processor = FileProcessor(archive=False)
processor.register_importer(WecdisImporter())

# check states empty
with self.store.session_scope():
# there must be no states at the beginning
states = self.store.session.query(self.store.db_classes.State).all()
self.assertEqual(len(states), 0)
# there must be no contacts at the beginning
contacts = self.store.session.query(self.store.db_classes.Contact).all()
self.assertEqual(len(contacts), 0)

# there must be no platforms at the beginning
platforms = self.store.session.query(self.store.db_classes.Platform).all()
self.assertEqual(len(platforms), 0)

# there must be no datafiles at the beginning
datafiles = self.store.session.query(self.store.db_classes.Datafile).all()
self.assertEqual(len(datafiles), 0)

# parse the folder
processor.process(DATA_MULTI_POS_HDG_VEL_SOURCES_PATH, self.store, False)

# check data got created
with self.store.session_scope():
# there must be states after the import
states = self.store.session.query(self.store.db_classes.State).all()
self.assertEqual(len(states), 6)

# there must be no contacts after the import
contacts = self.store.session.query(self.store.db_classes.Contact).all()
self.assertEqual(len(contacts), 0)

# there must be platforms after the import
platforms = self.store.session.query(self.store.db_classes.Platform).all()
self.assertEqual(len(platforms), 1)

# there must be datafile afterwards
datafiles = self.store.session.query(self.store.db_classes.Datafile).all()
self.assertEqual(len(datafiles), 1)

stored_states = (
self.store.session.query(self.store.db_classes.State)
.order_by(self.store.db_classes.State.time)
.all()
)
ureg = UnitRegistry()

assert stored_states[0].time == datetime(2021, 11, 1, 1, 2, 30, 123000)
assert stored_states[0].sensor.name == "GPS"
assert stored_states[0].sensor.sensor_type.name == "Location-Satellite"
assert stored_states[0].speed is None
assert stored_states[0].heading is None

assert stored_states[1].time == datetime(2021, 11, 1, 1, 2, 33, 10000)
assert stored_states[1].sensor.name == "GPS"
assert stored_states[1].sensor.sensor_type.name == "Location-Satellite"
assert stored_states[1].speed is None
assert stored_states[1].heading.to(ureg.degree).magnitude == 200

assert stored_states[2].time == datetime(2021, 11, 1, 1, 3, 5, 10000)
assert stored_states[2].sensor.name == "GPS"
assert stored_states[2].sensor.sensor_type.name == "Location-Satellite"
assert stored_states[2].speed is None
assert round(stored_states[2].heading.to(ureg.degree).magnitude, 3) == 201.0

assert stored_states[3].time == datetime(2021, 11, 1, 1, 3, 5, 10000)
assert stored_states[3].sensor.name == "GPS2"
assert stored_states[3].sensor.sensor_type.name == "Location-Satellite"
assert stored_states[3].speed is None
assert round(stored_states[3].heading.to(ureg.degree).magnitude, 3) == 199.43

assert stored_states[4].time == datetime(2021, 12, 12, 1, 3, 35, 10000)
assert stored_states[4].sensor.name == "GPS"
assert stored_states[4].sensor.sensor_type.name == "Location-Satellite"
assert round(stored_states[4].speed.to(ureg.knot).magnitude, 2) == 3.08
assert round(stored_states[4].heading.to(ureg.degree).magnitude, 3) == 201.2

assert stored_states[5].time == datetime(2021, 12, 12, 1, 3, 35, 10000)
assert stored_states[5].sensor.name == "GPS2"
assert stored_states[5].sensor.sensor_type.name == "Location-Satellite"
assert round(stored_states[5].speed.to(ureg.knot).magnitude, 3) == 6.6
assert round(stored_states[5].heading.to(ureg.degree).magnitude, 3) == 199.43

def test_invalid_lat(self):
processor = FileProcessor(archive=False)
processor.register_importer(WecdisImporter())
Expand Down

0 comments on commit f0e1cd3

Please sign in to comment.