Search in sources :

Example 1 with EezWaypoint

use of au.gov.amsa.geo.VoyageDatasetProducer.EezWaypoint in project risky by amsa-code.

the class VoyageDatasetProducerTest method test.

@Test
public void test() throws IOException {
    long aTime = 1498199825552L;
    long bTime = aTime + TimeUnit.DAYS.toMillis(2);
    long cTime = bTime + TimeUnit.DAYS.toMillis(4);
    Shapefile eezLine = Eez.loadEezLine();
    Shapefile eezPolygon = Eez.loadEezPolygon();
    assertTrue(eezPolygon.contains(-35, 149));
    assertTrue(!eezPolygon.contains(-35, 175));
    Fix a = createOutOfEez(aTime);
    Fix b = createInEez(bTime);
    PublishSubject<Fix> fixes = PublishSubject.create();
    Collection<Port> ports = VoyageDatasetProducer.loadPorts();
    Collection<EezWaypoint> eezWaypoints = Collections.singleton(new EezWaypoint(EEZ_WAYPOINT_NAME, -35, 151.0, Optional.empty()));
    AssertableSubscriber<TimedLeg> ts = VoyageDatasetProducer.toLegs(eezLine, eezPolygon, ports, eezWaypoints, // 
    fixes).test();
    fixes.onNext(a);
    fixes.onNext(b);
    ts.assertNoValues();
    // in sydney port
    Fix c = createInSydneyPort(cTime);
    fixes.onNext(c);
    // 
    ts.assertNoTerminalEvent().assertValueCount(1);
    {
        TimedLeg leg = ts.getOnNextEvents().get(0);
        System.out.println(leg);
        assertTrue(leg.a.waypoint instanceof EezWaypoint);
        assertTrue(leg.b.waypoint instanceof Port);
        assertEquals(EEZ_WAYPOINT_NAME, leg.a.waypoint.name());
        assertEquals("Sydney", leg.b.waypoint.name());
        assertEquals(cTime, leg.b.time);
        assertTrue(leg.a.time > a.time());
        assertTrue(leg.a.time < b.time());
        assertTrue(leg.a.time < leg.b.time);
    }
    // another sydney report, the next leg should start with this timestamp
    long dTime = cTime + TimeUnit.DAYS.toMillis(1);
    Fix d = createInSydneyPort(dTime);
    fixes.onNext(d);
    // 
    ts.assertNoTerminalEvent().assertValueCount(1);
    // out of sydney
    long eTime = dTime + TimeUnit.DAYS.toMillis(1);
    Fix e = createInEez(eTime);
    fixes.onNext(e);
    // 
    ts.assertNoTerminalEvent().assertValueCount(1);
    // out of eez
    long fTime = eTime + TimeUnit.DAYS.toMillis(1);
    Fix f = createOutOfEez(fTime);
    fixes.onNext(f);
    // 
    ts.assertNoTerminalEvent().assertValueCount(2);
    {
        TimedLeg leg = ts.getOnNextEvents().get(1);
        System.out.println(leg);
        assertTrue(leg.a.waypoint instanceof Port);
        assertEquals("Sydney", leg.a.waypoint.name());
        assertTrue(leg.b.waypoint instanceof EezWaypoint);
        assertEquals(EEZ_WAYPOINT_NAME, leg.b.waypoint.name());
        assertEquals(dTime, leg.a.time);
    }
}
Also used : Fix(au.gov.amsa.risky.format.Fix) Port(au.gov.amsa.geo.VoyageDatasetProducer.Port) TimedLeg(au.gov.amsa.geo.VoyageDatasetProducer.TimedLeg) Shapefile(au.gov.amsa.gt.Shapefile) EezWaypoint(au.gov.amsa.geo.VoyageDatasetProducer.EezWaypoint) Test(org.junit.Test)

Aggregations

EezWaypoint (au.gov.amsa.geo.VoyageDatasetProducer.EezWaypoint)1 Port (au.gov.amsa.geo.VoyageDatasetProducer.Port)1 TimedLeg (au.gov.amsa.geo.VoyageDatasetProducer.TimedLeg)1 Shapefile (au.gov.amsa.gt.Shapefile)1 Fix (au.gov.amsa.risky.format.Fix)1 Test (org.junit.Test)1