1 package au.gov.amsa.ihs.reader;
2
3 import java.io.File;
4
5 public class IhsReaderMain {
6
7 // private static final Logger log = Logger.getLogger(IhsReaderMain.class);
8
9 private static final String GROSS_TONNAGE = "GrossTonnage";
10
11 public static void main(String[] args) {
12 File file = new File("/media/an/ship-data/ihs/608750-2015-04-01.zip");
13 // IhsReader.fromZip(file).filter(map -> map.get(GROSS_TONNAGE) ==
14 // null).count()
15 // .doOnNext(System.out::println).subscribe();
16 IhsReader.fromZip(file) //
17 .groupBy(map -> {
18 String name = map.get("FlagName");
19 if (name == null)
20 name = "UNKNOWN";
21 return name;
22 }) //
23 .flatMap(g -> g //
24 .groupBy(map -> map.containsKey(GROSS_TONNAGE)) //
25 .flatMap(g2 -> g2.reduce(0L,
26 (total, map) -> map.get(GROSS_TONNAGE) != null
27 ? total + Long.parseLong(map.get(GROSS_TONNAGE)) : total)
28 .map(x -> g.getKey() + "\t" + x)))
29 .doOnNext(System.out::println) //
30 .subscribe();
31
32 IhsReader.fromZip(file) //
33 .groupBy(map -> {
34 String name = map.get("FlagName");
35 if (name == null)
36 name = "UNKNOWN";
37 return name;
38 }) //
39 .flatMap(
40 g -> g //
41 .groupBy(map -> map.containsKey(GROSS_TONNAGE)) //
42 .flatMap(g2 -> g2
43 .reduce(0L,
44 (total, map) -> map.get(GROSS_TONNAGE) != null
45 ? total + 1 : total)
46 .map(x -> g.getKey() + "\t" + x)))
47 .doOnNext(System.out::println) //
48 .subscribe();
49 // log.info(IhsReader.fromZip(file).count().toBlocking().single() +
50 // " ships");
51 // log.info(IhsReader.fromZip(file).filter(ship ->
52 // ship.getMmsi().isPresent()).count()
53 // .toBlocking().single()
54 // + " ships");
55 // Map<String, Ship> map = IhsReader.fromZipAsMapByMmsi(file).map(x ->
56 // IhsReader.toShip(x))
57 // .toBlocking().single();
58 // System.out.println(map.get("503595000"));
59 }
60 }