Search in sources :

Example 1 with FixImpl

use of au.gov.amsa.risky.format.FixImpl in project risky by amsa-code.

the class ParquetTest method testWriteOneFixToFile.

@Test
public void testWriteOneFixToFile() throws IOException {
    FixImpl f = new FixImpl(213456789, -10f, 135f, 1526002907873L, of(12), of((short) 1), of(NavigationalStatus.ENGAGED_IN_FISHING), of(7.5f), of(45f), of(46f), AisClass.B);
    File output = new File("target/test.parquet");
    output.delete();
    Iterable<Record> iterable = () -> Iterators.limit(Iterators.cycle(Parquet.toRecord(f)), 1000);
    Parquet.writeTo(iterable, new Path(output.getPath()));
    System.out.println(output.length());
}
Also used : Path(org.apache.hadoop.fs.Path) Record(org.apache.avro.generic.GenericData.Record) FixImpl(au.gov.amsa.risky.format.FixImpl) File(java.io.File) Test(org.junit.Test)

Example 2 with FixImpl

use of au.gov.amsa.risky.format.FixImpl in project risky by amsa-code.

the class VesselPositionsTest method testFixSpeedComesThroughCorrectly.

@Test
public void testFixSpeedComesThroughCorrectly() {
    FixImpl fix = new FixImpl(213456789, -10f, 135f, 12000, of(12), of((short) 1), of(NavigationalStatus.ENGAGED_IN_FISHING), of(7.5f), of(45f), of(46f), AisClass.B);
    assertEquals(7.5 * 1852.0 / 3600, VesselPositions.TO_VESSEL_POSITION.call(fix).speedMetresPerSecond().get(), PRECISION);
}
Also used : FixImpl(au.gov.amsa.risky.format.FixImpl) Test(org.junit.Test)

Example 3 with FixImpl

use of au.gov.amsa.risky.format.FixImpl in project risky by amsa-code.

the class DriftCandidates method toDriftCandidate.

private static DriftCandidate toDriftCandidate(String line) {
    String[] items = line.split(",");
    int i = 0;
    int mmsi = Integer.parseInt(items[i++]);
    float lat = Float.parseFloat(items[i++]);
    float lon = Float.parseFloat(items[i++]);
    long time = Long.parseLong(items[i++]);
    String cls = items[i++];
    float course = Float.parseFloat(items[i++]);
    float heading = Float.parseFloat(items[i++]);
    float speedKnots = Float.parseFloat(items[i++]);
    String status = items[i++];
    long driftingSince = Long.parseLong(items[i++]);
    final Optional<NavigationalStatus> navigationalStatus;
    if (status.trim().length() == 0)
        navigationalStatus = Optional.empty();
    else
        navigationalStatus = Optional.of(NavigationalStatus.valueOf(status));
    final AisClass aisClass;
    if (cls.trim().length() == 0)
        throw new RuntimeException("cls should not be empty");
    else if (AisClass.A.name().equals(cls))
        aisClass = AisClass.A;
    else
        aisClass = AisClass.B;
    FixImpl fix = new FixImpl(mmsi, lat, lon, time, Optional.<Integer>empty(), Optional.<Short>empty(), navigationalStatus, Optional.of(speedKnots), Optional.of(course), Optional.of(heading), aisClass);
    return new DriftCandidate(fix, driftingSince);
}
Also used : AisClass(au.gov.amsa.risky.format.AisClass) FixImpl(au.gov.amsa.risky.format.FixImpl) NavigationalStatus(au.gov.amsa.risky.format.NavigationalStatus)

Example 4 with FixImpl

use of au.gov.amsa.risky.format.FixImpl in project risky by amsa-code.

the class OperatorEffectiveSpeedCheckerTest method testSpiritOfTasmania.

@Test
public void testSpiritOfTasmania() throws ParseException {
    SegmentOptions options = SegmentOptions.builder().acceptAnyFixHours(12L).maxSpeedKnots(50).build();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    Fix a = new FixImpl(1, -39.572643f, 145.38763f, df.parse("2015-01-01T03:36:36").getTime(), AisClass.A);
    Fix b = new FixImpl(1, -40.095074f, 145.71864f, df.parse("2015-01-01T04:52:25").getTime(), AisClass.A);
    System.out.println(Position.create(a.lat(), a.lon()).getDistanceToKm(Position.create(b.lat(), b.lon())) / 1.852 / (75.81666666 / 60) + "knots");
    assertEquals(27.605441702145423, EffectiveSpeedChecker.effectiveSpeedKnots(a, b, options).get(), 0.00001);
}
Also used : Fix(au.gov.amsa.risky.format.Fix) SegmentOptions(au.gov.amsa.geo.model.SegmentOptions) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) FixImpl(au.gov.amsa.risky.format.FixImpl) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

FixImpl (au.gov.amsa.risky.format.FixImpl)4 Test (org.junit.Test)3 SegmentOptions (au.gov.amsa.geo.model.SegmentOptions)1 AisClass (au.gov.amsa.risky.format.AisClass)1 Fix (au.gov.amsa.risky.format.Fix)1 NavigationalStatus (au.gov.amsa.risky.format.NavigationalStatus)1 File (java.io.File)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Record (org.apache.avro.generic.GenericData.Record)1 Path (org.apache.hadoop.fs.Path)1