use of au.gov.amsa.ais.rx.Streams.TimestampedAndLine in project risky by amsa-code.
the class ShipTypeBreakdownMain method main.
public static void main(String[] args) throws FileNotFoundException, IOException {
// load a shapefile
final GeometryFactory gf = new GeometryFactory();
File file = new File("/home/dxm/temp/srr.shp");
Map<String, Serializable> map = new HashMap<>();
map.put("url", file.toURI().toURL());
DataStore datastore = DataStoreFinder.getDataStore(map);
String typeName = datastore.getTypeNames()[0];
System.out.println(typeName);
SimpleFeatureSource source = datastore.getFeatureSource(typeName);
final SimpleFeatureCollection features = source.getFeatures();
final List<PreparedGeometry> geometries = new ArrayList<>();
SimpleFeatureIterator it = features.features();
while (it.hasNext()) {
SimpleFeature feature = it.next();
Geometry g = (Geometry) feature.getDefaultGeometry();
geometries.add(PreparedGeometryFactory.prepare(g));
}
// System.exit(0);
String filename = "/media/analysis/nmea/2014/NMEA_ITU_20140815.gz";
final Set<Long> mmsi = new HashSet<Long>();
final Set<Long> mmsiA = new HashSet<Long>();
final Set<Long> mmsiB = new HashSet<Long>();
Streams.extract(Streams.nmeaFromGzip(filename)).flatMap(aisPositionsOnly).lift(Logging.<TimestampedAndLine<AisPosition>>logger().showCount().every(100000).log()).doOnNext(m -> {
AisPosition p = m.getMessage().get().message();
if (p.getLatitude() != null && p.getLongitude() != null && contains(gf, geometries, p.getLatitude(), p.getLongitude())) {
long mmsiNo = m.getMessage().get().message().getMmsi();
mmsi.add(mmsiNo);
if (m.getMessage().get().message() instanceof AisPositionA)
mmsiA.add(mmsiNo);
else
mmsiB.add(mmsiNo);
}
}).subscribe();
final Map<ShipTypeClass, Set<Integer>> countsByShipType = new ConcurrentHashMap<>();
Streams.extract(Streams.nmeaFromGzip(filename)).flatMap(aisShipStaticOnly).doOnNext(m -> {
AisShipStatic s = m.getMessage().get().message();
if (mmsi.contains(Long.valueOf(s.getMmsi()))) {
boolean isClassA = s instanceof AisShipStaticA;
ShipTypeClass shipTypeClass = new ShipTypeClass(isClassA, s.getShipType());
if (countsByShipType.get(shipTypeClass) == null)
countsByShipType.put(shipTypeClass, new HashSet<Integer>());
else
countsByShipType.get(shipTypeClass).add(s.getMmsi());
}
}).subscribe();
System.out.println(countsByShipType);
Set<String> set = new TreeSet<String>();
int sizeA = 0;
int sizeB = 0;
for (Entry<ShipTypeClass, Set<Integer>> s : countsByShipType.entrySet()) {
set.add(ShipTypeDecoder.getShipType(s.getKey().shipType) + "\t" + (s.getKey().isClassA ? "A" : "B") + "\t" + s.getValue().size());
if (s.getKey().isClassA)
sizeA += s.getValue().size();
else
sizeB += s.getValue().size();
}
set.stream().forEach(System.out::println);
System.out.println("Unknown\tA\t" + (mmsiA.size() - sizeA));
System.out.println("Unknown\tB\t" + (mmsiB.size() - sizeB));
log.info("finished");
}
use of au.gov.amsa.ais.rx.Streams.TimestampedAndLine in project risky by amsa-code.
the class StreamsTest method stringRepresentationOfTimestampedAndLineContainsMessageInCaseOfSuccess.
@Test
public void stringRepresentationOfTimestampedAndLineContainsMessageInCaseOfSuccess() {
final Timestamped<AisMessage> aisMessage = new Timestamped<>(new AisMessageOther(4242, "source", 0), 0);
final TimestampedAndLine<AisMessage> message = new TimestampedAndLine<>(Optional.of(aisMessage), "test", null);
final String representation = message.toString();
assertNotNull(representation);
assertTrue("String representation should contain message ID, but got: " + representation, representation.contains("4242"));
}
Aggregations