use of au.gov.amsa.util.identity.MmsiValidator2 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");
}
use of au.gov.amsa.util.identity.MmsiValidator2 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");
}
use of au.gov.amsa.util.identity.MmsiValidator2 in project risky by amsa-code.
the class VesselsInCoverageMain 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 -> toFixes(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");
}
use of au.gov.amsa.util.identity.MmsiValidator2 in project risky by amsa-code.
the class DistanceTravelledMain method run.
private static void run(String directory, Options options, boolean gui, String dataSetName) {
InputStream is;
try {
is = new GZIPInputStream(new FileInputStream("/media/an/ship-data/ais/ship-data-2014-v2.txt.gz"));
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<Integer, Info> shipInfo = ShipStaticData.getMapFromReader(new InputStreamReader(is, StandardCharsets.UTF_8));
List<Setting> settings = new ArrayList<>();
settings.add(Setting.create(30, 30, "fishing"));
settings.add(Setting.create(52, 52, "tug"));
settings.add(Setting.create(60, 69, "passenger"));
settings.add(Setting.create(70, 79, "cargo"));
settings.add(Setting.create(80, 89, "tanker"));
settings.add(Setting.create(90, 99, "other"));
settings.add(Setting.create(-1, -1, "class_b"));
settings.add(Setting.create(0, 100, "all"));
for (Setting setting : settings) {
// filter out undesired mmsi numbers and ship types
Func1<Info, Boolean> shipSelector = info -> info != null && ((info.cls == AisClass.B && setting.lowerBound == -1) || (info.cls == AisClass.A && (info.shipType.isPresent() && info.shipType.get() >= setting.lowerBound && info.shipType.get() <= setting.upperBound))) && MmsiValidator2.INSTANCE.isValid(info.mmsi);
calculateTrafficDensity(directory, options, gui, shipInfo, shipSelector, setting.name + "-" + dataSetName);
}
}
use of au.gov.amsa.util.identity.MmsiValidator2 in project risky by amsa-code.
the class AdHocMain method main.
public static void main(String[] args) throws IOException {
long start = ZonedDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse("2014-05-13T00:00:00Z")).toEpochSecond() * 1000;
long finish = ZonedDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse("2014-05-27T00:00:00Z")).toEpochSecond() * 1000;
Pattern pattern = Pattern.compile(".*\\.track");
PrintStream out = new PrintStream("target/output.txt");
out.println("mmsi\ttime\tlat\tlong\tcourse\tspeedKnots");
List<File> files = Files.find(new File("/media/an/binary-fixes-5-minute/2014"), pattern);
Observable.from(files).flatMap(file -> extract(file, start, finish).subscribeOn(Schedulers.computation())).filter(fix -> MmsiValidator2.INSTANCE.isValid(fix.mmsi())).map(f -> String.format("%s\t%s\t%s\t%s\t%s\t%s", f.mmsi(), formatDateTime(f.time()), f.lat(), f.lon(), get(f.courseOverGroundDegrees()), get(f.speedOverGroundKnots()))).doOnNext(out::println).lift(Logging.<String>logger().showCount().every(10000).log()).count().doOnTerminate(out::close).toBlocking().single();
}
Aggregations