use of au.gov.amsa.risky.format.BinaryFixes in project risky by amsa-code.
the class VoyageDatasetProducer method produce.
public static void produce(File output, File fixesOutput, List<File> list) throws Exception {
// reset output directories
output.delete();
FileUtils.deleteDirectory(fixesOutput);
int numFiles = list.size();
System.out.println(numFiles + "binary fix files");
AtomicInteger fileNumber = new AtomicInteger(0);
Collection<Port> ports = loadPorts();
Collection<EezWaypoint> eezWaypoints = readEezWaypoints();
Shapefile eezLine = Eez.loadEezLine();
Shapefile eezPolygon = Eez.loadEezPolygon();
System.out.println("loaded eez shapefiles");
long t = System.currentTimeMillis();
AtomicLong failedCheck = new AtomicLong();
AtomicLong fixCount = new AtomicLong();
Map<Integer, Integer> mmsisWithFailedChecks = new TreeMap<>();
Persister persister = new Persister(fixesOutput);
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output)))) {
// Note that in the observable below we don't employ parallel techniques
// this is because the runtime is acceptable
//
Observable.from(list).groupBy(//
f -> mmsiFromFilename(f)).flatMap(files -> {
String mmsi = files.getKey();
if (!isShipMmsi(mmsi)) {
return Observable.empty();
} else {
return //
files.compose(//
o -> logPercentCompleted(numFiles, t, o, fileNumber)).concatMap(//
BinaryFixes::from).lift(new OperatorEffectiveSpeedChecker(SegmentOptions.builder().acceptAnyFixHours(24L).maxSpeedKnots(50).build())).doOnNext(//
check -> updatedCounts(failedCheck, fixCount, mmsisWithFailedChecks, check)).filter(//
check -> check.isOk()).map(//
check -> check.fix()).doOnNext(fix -> persister.persist(fix)).compose(//
o -> toLegs(eezLine, eezPolygon, ports, eezWaypoints, o)).filter(x -> includeLeg(x));
}
}).sorted(//
(a, b) -> compareByMmsiThenLegStartTime(a, b)).doOnNext(//
x -> write(writer, x)).doOnTerminate(//
Checked.a0(() -> persister.close())).toBlocking().subscribe();
System.out.println((System.currentTimeMillis() - t) + "ms");
System.out.println("total fixes=" + fixCount.get());
System.out.println("num fixes rejected due failed effective speed check=" + failedCheck.get());
System.out.println("num mmsis with failed effective speed checks=" + mmsisWithFailedChecks.size());
try (PrintStream p = new PrintStream("target/info.txt")) {
p.println("total fixes=" + fixCount.get());
p.println("num fixes rejected due failed effective speed check=" + failedCheck.get());
p.println("num mmsis with failed effective speed checks=" + mmsisWithFailedChecks.size());
}
try (PrintStream p = new PrintStream("target/failures.txt")) {
p.println("failures mmsi <TAB> number of rejected fixes");
for (Integer mmsi : mmsisWithFailedChecks.keySet()) {
p.println(mmsi + "\t" + mmsisWithFailedChecks.get(mmsi));
}
}
}
}
use of au.gov.amsa.risky.format.BinaryFixes in project risky by amsa-code.
the class SingleThreadedPerfMain method main.
public static void main(String[] args) throws FileNotFoundException, IOException {
long t = System.currentTimeMillis();
File out = new File("target/positions.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));
//
Observable.from(list).concatMap(//
BinaryFixes::from).count().doOnNext(//
System.out::println).toBlocking().subscribe();
}
System.out.println((System.currentTimeMillis() - t) + "ms");
}
use of au.gov.amsa.risky.format.BinaryFixes in project risky by amsa-code.
the class PositionsInGbrMain method main.
public static void main(String[] args) throws FileNotFoundException, IOException {
long t = System.currentTimeMillis();
File out = new File("target/positions.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();
int numFiles = list.size();
AtomicInteger fileNumber = new AtomicInteger(0);
//
Observable.from(list).groupBy(f -> count.getAndIncrement() % //
Runtime.getRuntime().availableProcessors()).flatMap(files -> //
files.doOnNext(file -> {
int n = fileNumber.incrementAndGet();
if (n % 1000 == 0)
System.out.println("complete: " + new DecimalFormat("0.0").format(n / (double) numFiles * 100) + "%");
}).concatMap(//
BinaryFixes::from).filter(//
x -> inGbr(x)).onBackpressureBuffer().subscribeOn(//
Schedulers.computation())).count().doOnNext(//
System.out::println).toBlocking().subscribe();
}
System.out.println((System.currentTimeMillis() - t) + "ms");
}
Aggregations