Search in sources :

Example 11 with Fix

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

the class VesselsInGbrMain method main.

public static void main(String[] args) throws IOException {
    long t = System.currentTimeMillis();
    File out = new File("target/mmsi.txt");
    out.delete();
    try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out)))) {
        Pattern pattern = Pattern.compile(".*\\.track");
        List<File> list = new ArrayList<File>();
        list.addAll(Files.find(new File("/media/an/binary-fixes-5-minute/2014"), pattern));
        list.addAll(Files.find(new File("/media/an/binary-fixes-5-minute/2015"), pattern));
        list.addAll(Files.find(new File("/media/an/binary-fixes-5-minute/2016"), pattern));
        AtomicInteger count = new AtomicInteger();
        // 
        Observable.from(list).groupBy(f -> count.getAndIncrement() % // 
        Runtime.getRuntime().availableProcessors()).flatMap(// 
        files -> vesselsInGbr(files, Schedulers.computation())).distinct(// 
        fix -> fix.mmsi() + fix.aisClass().name()).sorted(// 
        (a, b) -> Integer.compare(a.mmsi(), b.mmsi())).filter(// 
        fix -> MmsiValidator2.INSTANCE.isValid((long) fix.mmsi())).doOnNext(// 
        fix -> write(writer, fix)).toBlocking().subscribe();
    }
    System.out.println((System.currentTimeMillis() - t) + "ms");
}
Also used : BufferedWriter(java.io.BufferedWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Scheduler(rx.Scheduler) Files(au.gov.amsa.util.Files) File(java.io.File) ArrayList(java.util.ArrayList) Observable(rx.Observable) List(java.util.List) GroupedObservable(rx.observables.GroupedObservable) BinaryFixes(au.gov.amsa.risky.format.BinaryFixes) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Fix(au.gov.amsa.risky.format.Fix) Schedulers(rx.schedulers.Schedulers) OutputStreamWriter(java.io.OutputStreamWriter) MmsiValidator2(au.gov.amsa.util.identity.MmsiValidator2) Pattern(java.util.regex.Pattern) Pattern(java.util.regex.Pattern) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 12 with Fix

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

the class DriftDetectorTest method testRule2TwoDriftersBigTimeGap.

@Test
public void testRule2TwoDriftersBigTimeGap() {
    long t = 0;
    // drifter
    Fix f1 = createFix(90, DRIFT_SPEED_KNOTS, t);
    // drifter
    Fix f2 = createFix(91, DRIFT_SPEED_KNOTS, t += TimeUnit.DAYS.toMillis(1));
    List<DriftCandidate> list = getCandidates(Observable.just(f1, f2));
    assertTrue(list.isEmpty());
}
Also used : Fix(au.gov.amsa.risky.format.Fix) Test(org.junit.Test)

Example 13 with Fix

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

the class DriftDetectorTest method testTwoDriftersButDifferentMmsi.

@Test
public void testTwoDriftersButDifferentMmsi() {
    long t = 0;
    // drifter
    Fix f1 = createFix(12344, 90, DRIFT_SPEED_KNOTS, t);
    // drifter
    Fix f2 = createFix(12345, 91, DRIFT_SPEED_KNOTS, t += 1);
    List<DriftCandidate> list = getCandidates(Observable.just(f1, f2));
    assertTrue(list.isEmpty());
}
Also used : Fix(au.gov.amsa.risky.format.Fix) Test(org.junit.Test)

Example 14 with Fix

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

the class DriftDetectorTest method createFix.

private static Fix createFix(int mmsi, float courseHeadingDiff, float speedKnots, long time) {
    Fix f = Mockito.mock(Fix.class);
    Mockito.when(f.courseOverGroundDegrees()).thenReturn(Optional.of(10.0f));
    Mockito.when(f.headingDegrees()).thenReturn(Optional.of(10.0f + courseHeadingDiff));
    Mockito.when(f.speedOverGroundKnots()).thenReturn(Optional.of(speedKnots));
    Mockito.when(f.navigationalStatus()).thenReturn(Optional.<NavigationalStatus>empty());
    Mockito.when(f.mmsi()).thenReturn(mmsi);
    Mockito.when(f.fix()).thenReturn(f);
    Mockito.when(f.time()).thenReturn(time);
    return f;
}
Also used : Fix(au.gov.amsa.risky.format.Fix)

Example 15 with Fix

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

the class DriftDetectorTest method testNotDriftedBecauseCogHeadingDiffTooLow.

@Test
public void testNotDriftedBecauseCogHeadingDiffTooLow() {
    Fix fix = Mockito.mock(Fix.class);
    Mockito.when(fix.courseOverGroundDegrees()).thenReturn(Optional.of(10.0f));
    Mockito.when(fix.headingDegrees()).thenReturn(Optional.of(11.0f));
    Mockito.when(fix.speedOverGroundKnots()).thenReturn(Optional.of(DRIFT_SPEED_KNOTS));
    Mockito.when(fix.navigationalStatus()).thenReturn(Optional.<NavigationalStatus>empty());
    assertFalse(DriftDetector.isCandidate(Options.instance()).call(fix));
}
Also used : Fix(au.gov.amsa.risky.format.Fix) Test(org.junit.Test)

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