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;
}
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;
}
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;
}
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);
}
}
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");
}
Aggregations