Skip to content

Commit

Permalink
chore: updates docs for updated API of FilterChain
Browse files Browse the repository at this point in the history
  • Loading branch information
M0r13n committed Jun 25, 2024
1 parent fa8bb66 commit 998b78d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Example Usage

.. code-block:: python
from pyais import decode
from pyais import decode, TCPConnection
# ... (importing necessary classes)
# Define and initialize filters
Expand All @@ -82,8 +82,8 @@ Example Usage
])
# Decode AIS data and filter
data = [decode(b"!AIVDM..."), ...]
filtered_data = list(chain.filter(data))
stream = TCPConnection(...)
filtered_data = chain.filter(stream)
for msg in filtered_data:
print(msg.lat, msg.lon)
Expand Down
18 changes: 18 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pathlib
import unittest
from pyais.filter import AttributeFilter, DistanceFilter, FilterChain, GridFilter, MessageTypeFilter, NoneFilter, haversine
from pyais.stream import FileReaderStream


class MockAISMessage:
Expand Down Expand Up @@ -204,6 +206,22 @@ def test_complex_filter_chain(self):
self.assertEqual(filtered_data[0].lon, -73.965)
self.assertEqual(filtered_data[0].msg_type, 1)

def test_filter_chain_with_file_stream(self):
# Setup: Define the filters and chain
chain = FilterChain([AttributeFilter(lambda x: x.mmsi == 445451000)])

# Setup: Define sample file
file = pathlib.Path(__file__).parent.joinpath('messages.ais')

with FileReaderStream(file) as ais_stream:
total = len(list(ais_stream))

with FileReaderStream(file) as ais_stream:
filtered = list(chain.filter(ais_stream))

self.assertEqual(len(filtered), 2)
self.assertEqual(total, 6)


class TestAttributeFilter(unittest.TestCase):
def test_attribute_filtering(self):
Expand Down

0 comments on commit 998b78d

Please sign in to comment.