Search in sources :

Example 1 with Fix

use of au.gov.amsa.risky.format.Fix in project risky by amsa-code.

the class VoyageDatasetProducerTest method createInEez.

private static Fix createInEez(long aTime) {
    Fix a = Mockito.mock(Fix.class);
    when(a.lat()).thenReturn(-35f);
    when(a.lon()).thenReturn(149f);
    when(a.time()).thenReturn(aTime);
    return a;
}
Also used : Fix(au.gov.amsa.risky.format.Fix)

Example 2 with Fix

use of au.gov.amsa.risky.format.Fix in project risky by amsa-code.

the class VoyageDatasetProducerTest method createInSydneyPort.

private static Fix createInSydneyPort(long aTime) {
    Fix a = Mockito.mock(Fix.class);
    when(a.lat()).thenReturn(-33.8523f);
    when(a.lon()).thenReturn(151.2108f);
    when(a.time()).thenReturn(aTime);
    return a;
}
Also used : Fix(au.gov.amsa.risky.format.Fix)

Example 3 with Fix

use of au.gov.amsa.risky.format.Fix in project risky by amsa-code.

the class VoyageDatasetProducerTest method createOutOfEez.

private static Fix createOutOfEez(long bTime) {
    Fix b = Mockito.mock(Fix.class);
    when(b.lat()).thenReturn(-35f);
    when(b.lon()).thenReturn(175f);
    when(b.time()).thenReturn(bTime);
    return b;
}
Also used : Fix(au.gov.amsa.risky.format.Fix)

Example 4 with Fix

use of au.gov.amsa.risky.format.Fix 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)

Example 5 with Fix

use of au.gov.amsa.risky.format.Fix in project risky by amsa-code.

the class DistanceTravelledInEezMain method main.

public static void main(String[] args) throws FileNotFoundException, IOException {
    System.out.println("running");
    File tracks = new File("/home/dxm/combinedSortedTracks");
    long t = System.currentTimeMillis();
    List<File> files = Arrays.asList(tracks.listFiles());
    files.sort((a, b) -> a.getName().compareTo(b.getName()));
    try (PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("target/output.csv")))) {
        out.println(Vessel.headings());
        // 
        Observable.from(// 
        files).filter(// 
        x -> x.getName().endsWith(".track.gz")).filter(// 
        x -> x.getName().startsWith("2017")).flatMap(file -> {
            log.info(file);
            // Note that the Shapefile objects are not thread-safe so we make new one for
            // each file to enable parallel processing
            // used for intersections with eez boundary
            Shapefile eezLine = Eez.loadEezLine();
            // used for contains tests
            Shapefile eezPolygon = Eez.loadEezPolygon();
            long startTime = Util.getStartTime(file);
            long endTime = startTime + TimeUnit.HOURS.toMillis(24);
            return // 
            BinaryFixes.from(file, true, // 
            BinaryFixesFormat.WITH_MMSI).subscribeOn(// 
            Schedulers.computation()).filter(// 
            f -> MmsiValidator2.INSTANCE.isValid(f.mmsi())).filter(// 
            f -> f.time() >= startTime && f.time() <= endTime).groupBy(// 
            fix -> fix.mmsi()).flatMap(o -> calculateDistance(file, eezLine, eezPolygon, o));
        }, // 
        Runtime.getRuntime().availableProcessors()).filter(// 
        x -> x.state.fix != null).toBlocking().forEach(x -> out.println(x.line()));
    }
    System.out.println((System.currentTimeMillis() - t) + "ms");
}
Also used : Arrays(java.util.Arrays) Downsample(au.gov.amsa.risky.format.Downsample) Date(java.util.Date) SegmentOptions(au.gov.amsa.geo.model.SegmentOptions) OperatorEffectiveSpeedChecker(au.gov.amsa.geo.distance.OperatorEffectiveSpeedChecker) SimpleDateFormat(java.text.SimpleDateFormat) ShapefileUtil(au.gov.amsa.geo.ShapefileUtil) BufferedOutputStream(java.io.BufferedOutputStream) TimedPosition(au.gov.amsa.geo.TimedPosition) Observable(rx.Observable) Logger(org.apache.log4j.Logger) BinaryFixes(au.gov.amsa.risky.format.BinaryFixes) Fix(au.gov.amsa.risky.format.Fix) Schedulers(rx.schedulers.Schedulers) Eez(au.gov.amsa.geo.Eez) ParseException(java.text.ParseException) PrintStream(java.io.PrintStream) TimeZone(java.util.TimeZone) DecimalFormat(java.text.DecimalFormat) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) BinaryFixesFormat(au.gov.amsa.risky.format.BinaryFixesFormat) TimeUnit(java.util.concurrent.TimeUnit) Position(com.github.davidmoten.grumpy.core.Position) List(java.util.List) GroupedObservable(rx.observables.GroupedObservable) Shapefile(au.gov.amsa.gt.Shapefile) MmsiValidator2(au.gov.amsa.util.identity.MmsiValidator2) PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) Shapefile(au.gov.amsa.gt.Shapefile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

Fix (au.gov.amsa.risky.format.Fix)48 Test (org.junit.Test)27 File (java.io.File)18 BinaryFixes (au.gov.amsa.risky.format.BinaryFixes)12 Observable (rx.Observable)12 IOException (java.io.IOException)11 List (java.util.List)10 FileOutputStream (java.io.FileOutputStream)9 Pattern (java.util.regex.Pattern)7 Schedulers (rx.schedulers.Schedulers)7 SegmentOptions (au.gov.amsa.geo.model.SegmentOptions)6 Shapefile (au.gov.amsa.gt.Shapefile)6 BinaryFixesFormat (au.gov.amsa.risky.format.BinaryFixesFormat)6 Files (au.gov.amsa.util.Files)6 InputStream (java.io.InputStream)6 TimeUnit (java.util.concurrent.TimeUnit)6 MmsiValidator2 (au.gov.amsa.util.identity.MmsiValidator2)5 BufferedOutputStream (java.io.BufferedOutputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 OutputStream (java.io.OutputStream)5