Example #1
0
def test_prepare_trackpoints_too_far_away_fails() -> None:
    """Two records too far away is bad."""
    trackpoints = [
        (dt.datetime(2020, 5, 1, 0, 0, 0, 0, dt.timezone.utc), 49.00, 8.40),
        (dt.datetime(2020, 5, 1, 1, 0, 0, 0, dt.timezone.utc), 49.00, -8.40),
    ]
    with pytest.raises(processor.RegionTooLargeError):
        processor.prepare_trackpoints(trackpoints)
Example #2
0
 def _ensure_graph(self) -> None:
     """Rebuild graph if needed."""
     if self.graph is None:
         dfr_trackpoints = prepare_trackpoints(self.trackpoints)
         dfr_waypoints = prepare_waypoints(self.waypoints)
         if set(dfr_trackpoints["utm_zone"]) != set(
                 dfr_waypoints["utm_zone"]):
             raise RegionTooLargeError(
                 f"Trackpoints ({dfr_trackpoints['utm_zone']!r}) and "
                 f"waypoints ({dfr_waypoints['utm_zone']!r}) "
                 f"in different UTM_zones.")
         dfr_encounters = find_encounters(dfr_trackpoints, dfr_waypoints)
         self.graph = build_graph(dfr_encounters, dfr_waypoints)
Example #3
0
def test_prepare_trackpoints_one_row_ok() -> None:
    """One record returns good data."""
    trackpoints = [(dt.datetime(2020, 5, 1,
                                tzinfo=dt.timezone.utc), 49.00, 8.40)]
    result = processor.prepare_trackpoints(trackpoints)
    expected = pd.DataFrame({
        "utm_x": [456114],
        "utm_y": [5427629],
        "utm_zone": [32],
        "utm_ch": ["U"],
        "segment": [0],
        "offset": [0],
    })
    pd.testing.assert_frame_equal(result, expected)
Example #4
0
def test_prepare_trackpoints_two_segments_ok() -> None:
    """Two records in two segments is ok."""
    trackpoints = [
        (dt.datetime(2020, 5, 1, 0, 0, 0, 0, dt.timezone.utc), 49.00, 8.40),
        (dt.datetime(2020, 5, 1, 1, 0, 0, 0, dt.timezone.utc), 50.00, 8.40),
    ]
    result = processor.prepare_trackpoints(trackpoints)
    expected = pd.DataFrame({
        "utm_x": [456114, 456999],
        "utm_y": [5427629, 5538803],
        "utm_zone": 32,
        "utm_ch": "U",
        "segment": [0, 1],
        "offset": [0, 0],
    })
    pd.testing.assert_frame_equal(result, expected)
Example #5
0
def test_prepare_trackpoints_one_segment_ok() -> None:
    """Two records in same segment is ok."""
    trackpoints = [
        (dt.datetime(2020, 5, 1, 0, 0, 0, 0, dt.timezone.utc), 49.00, 8.40),
        (dt.datetime(2020, 5, 1, 0, 0, 2, 0, dt.timezone.utc), 49.01, 8.41),
    ]
    result = processor.prepare_trackpoints(trackpoints)
    expected = pd.DataFrame({
        "utm_x": [456114, 456854],
        "utm_y": [5427629, 5428735],
        "utm_zone": 32,
        "utm_ch": "U",
        "segment": [0, 0],
        "offset": [0, 2],
    })
    pd.testing.assert_frame_equal(result, expected)
Example #6
0
def test_prepare_trackpoints_empty_raises() -> None:
    """Empty list returns an empty DataFrame."""
    with pytest.raises(processor.EmptyDataError):
        processor.prepare_trackpoints([])