当前位置: 首页>>代码示例>>Java>>正文


Java AisReaders类代码示例

本文整理汇总了Java中dk.dma.ais.reader.AisReaders的典型用法代码示例。如果您正苦于以下问题:Java AisReaders类的具体用法?Java AisReaders怎么用?Java AisReaders使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AisReaders类属于dk.dma.ais.reader包,在下文中一共展示了AisReaders类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doesNotDetectStocMarciasDriftOnOct02_2014

import dk.dma.ais.reader.AisReaders; //导入依赖的package包/类
@Test
public void doesNotDetectStocMarciasDriftOnOct02_2014() {
    Tracker tracker = injector.getInstance(EventEmittingTracker.class);
    EventRepository eventRepository = injector.getInstance(EventRepository.class);

    InputStream testDataStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("ais/212123000_drift_1.ais");
    AisReader aisReader = AisReaders.createReaderFromInputStream(testDataStream);

    context.checking(new Expectations() {{
        never(eventRepository).findOngoingEventByVessel(212123000, DriftEvent.class);
        never(eventRepository).save(with(any(DriftEvent.class)));
    }});

    driftAnalysis.start();
    aisReader.registerPacketHandler(aisPacket -> {
        tracker.update(aisPacket);
    });
    aisReader.run();

    context.assertIsSatisfied();
}
 
开发者ID:dma-ais,项目名称:AisAbnormal,代码行数:22,代码来源:DriftAnalysisTest.java

示例2: detectsFriosDriftOnSep28_2014

import dk.dma.ais.reader.AisReaders; //导入依赖的package包/类
@Test
public void detectsFriosDriftOnSep28_2014() {
    Tracker tracker = injector.getInstance(EventEmittingTracker.class);
    EventRepository eventRepository = injector.getInstance(EventRepository.class);

    InputStream testDataStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("ais/538004030_drift_1.ais");
    AisReader aisReader = AisReaders.createReaderFromInputStream(testDataStream);

    final ArgumentCaptor<DriftEvent> eventCaptor = ArgumentCaptor.forClass(DriftEvent.class);
    context.checking(new Expectations() {{
        atLeast(1).of(eventRepository).findOngoingEventByVessel(538004030, DriftEvent.class);
        atLeast(1).of(eventRepository).save(with(eventCaptor.getMatcher()));
    }});

    driftAnalysis.start();
    aisReader.registerPacketHandler(aisPacket -> {
        tracker.update(aisPacket);
    });
    aisReader.run();

    context.assertIsSatisfied();
    assertTrue(eventCaptor.getCapturedObject().getDescription().startsWith("FRIO is drifting"));
    assertEquals(MILLIS_TO_LOCALDATETIME_UTC.apply(1411923004556L), eventCaptor.getCapturedObject().getStartTime());
}
 
开发者ID:dma-ais,项目名称:AisAbnormal,代码行数:25,代码来源:DriftAnalysisTest.java

示例3: canDetectLotusSuddenSpeedChangeOnOct05_2014

import dk.dma.ais.reader.AisReaders; //导入依赖的package包/类
@Test
public void canDetectLotusSuddenSpeedChangeOnOct05_2014() {
    Tracker tracker = injector.getInstance(EventEmittingTracker.class);
    EventRepository eventRepository = injector.getInstance(EventRepository.class);

    InputStream testDataStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("ais/219165000_ssc_1.ais");
    AisReader aisReader = AisReaders.createReaderFromInputStream(testDataStream);

    final ArgumentCaptor<SuddenSpeedChangeEvent> eventCaptor = ArgumentCaptor.forClass(SuddenSpeedChangeEvent.class);
    context.checking(new Expectations() {{
        atLeast(1).of(eventRepository).findOngoingEventByVessel(219165000, SuddenSpeedChangeEvent.class);
        atLeast(1).of(eventRepository).save(with(eventCaptor.getMatcher()));
    }});

    analysis.start();
    aisReader.registerPacketHandler(aisPacket -> {
        tracker.update(aisPacket);
    });
    aisReader.run();

    context.assertIsSatisfied();
    assertTrue(eventCaptor.getCapturedObject().getDescription().startsWith("Sudden speed change of LOTUS"));
    assertEquals(LocalDateTime.ofInstant(Instant.ofEpochMilli(1412525411424L), ZoneOffset.UTC), eventCaptor.getCapturedObject().getStartTime());
}
 
开发者ID:dma-ais,项目名称:AisAbnormal,代码行数:25,代码来源:SuddenSpeedChangeAnalysisTest.java

示例4: createKml

import dk.dma.ais.reader.AisReaders; //导入依赖的package包/类
/**
 * Produce KML output for POSTed AIS data in NMEA format.
 *
 * Use 'curl -X POST -T <ais-data-file> http://127.0.0.1:8090/store/history/kml' to test
 * Or with expression filter:
 * 'curl -X POST -T <ais-data-file> http://127.0.0.1:8090/store/history/kml?filter="m.mmsi=247469000" > test.kmz'
 */
@POST
@Path("/history/kml")
@Produces(MEDIA_TYPE_KMZ)
public Response createKml(@QueryParam("filter") String filterExpression, InputStream inputStream) {
    LOG.debug("Filter expression: " + filterExpression);
    Predicate<AisPacket> filter = isBlank(filterExpression) ? p->true : AisPacketFilters.parseExpressionFilter(filterExpression);

    ArrayList<AisPacket> packets = new ArrayList<>();

    AisReader reader = AisReaders.createReaderFromInputStream(inputStream);
    reader.registerPacketHandler(
        aisPacket -> { if (filter.test(aisPacket)) packets.add(aisPacket); }
    );

    reader.start();
    try {
        reader.join();
    } catch (InterruptedException e) {
        LOG.error(e.getMessage(), e);
        return Response.serverError().build();
    }

    StreamingOutput output = StreamingUtil.createZippedStreamingOutput(packets, AisPacketOutputSinks.newKmlSink(), "history.kml");

    return Response
        .ok()
        .entity(output)
        .type(MEDIA_TYPE_KMZ).build();
}
 
开发者ID:dma-ais,项目名称:AisView,代码行数:37,代码来源:AisStoreResource.java

示例5: provideAisReader

import dk.dma.ais.reader.AisReaders; //导入依赖的package包/类
@Provides
@Singleton
AisReader provideAisReader() {
    AisReader aisReader = null;
    try {
        aisReader = AisReaders.createDirectoryReader(inputDirectory, inputFilenamePattern, inputRecursive);
        LOG.info("Created AisReader.");
    } catch (Exception e) {
        LOG.error("Failed to create AisReader object", e);
    }
    return aisReader;
}
 
开发者ID:dma-ais,项目名称:AisAbnormal,代码行数:13,代码来源:AbnormalStatBuilderAppModule.java

示例6: provideAisReader

import dk.dma.ais.reader.AisReaders; //导入依赖的package包/类
@Provides
AisReader provideAisReader() {
    AisReader aisReader = null;
    try {
        aisReader = AisReaders.createDirectoryReader(inputDirectory, inputFilenamePattern, inputRecursive);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return aisReader;
}
 
开发者ID:dma-ais,项目名称:AisAbnormal,代码行数:11,代码来源:AbnormalStatBuilderAppTestModule.java

示例7: runDaemon

import dk.dma.ais.reader.AisReaders; //导入依赖的package包/类
@Override
protected void runDaemon(Injector injector) throws Exception {
    // Tracking of live data
    final TargetTracker targetTracker = new TargetTracker();
    
    // A cache manager where caches can be held and retrieved
    final CacheManager cacheManager = new CacheManager();

    // Setup the readers
    AisReaderGroup g = AisReaders.createGroup("AisView",
            sources == null ? Collections.<String> emptyList() : sources);
    AisReaders.manageGroup(g);

    // A job manager that takes care of tracking ongoing jobs
    final JobManager jobManager = new JobManager();

    // Setup the backup process
    // Files.createDirectories(backup);
    backup.mkdirs();
    if(!backup.isDirectory()) {
        throw new IOException("Unable to create directories for " + backup);
    }

    start(new TargetTrackerFileBackupService(targetTracker, backup.toPath()));

    // start tracking
    targetTracker.subscribeToPacketStream(g.stream());
    
    //target tracking cleanup service
    start(new AbstractScheduledService() {
        
        @Override
        protected Scheduler scheduler() {
            return Scheduler.newFixedDelaySchedule(1, 10, TimeUnit.MINUTES);
        }
        
        @Override
        protected void runOneIteration() throws Exception {
            final Date satellite = new Date(new Date().getTime()-(1000*60*60*48));
            final Date live = new Date(new Date().getTime()-(1000*60*60*12));
            
            targetTracker.removeAll((t, u) -> {
                switch(t.getSourceType()) {
                case SATELLITE:
                    return !u.hasPositionInfo() || new Date(u.getPositionTimestamp()).before(satellite);
                default:
                    return !u.hasPositionInfo() || new Date(u.getPositionTimestamp()).before(live);
                }
            });
        }
    });
    
    //target cleanup missing static data
    start(new AbstractScheduledService() {
        @Override
        protected Scheduler scheduler() {
            return Scheduler.newFixedDelaySchedule(1, 24, TimeUnit.HOURS);
        }
        
        @Override
        protected void runOneIteration() throws Exception {
            targetTracker.removeAll(u -> !u.hasStaticInfo());
        }
    });
    
    start(g.asService());

    // Start Ais Store Connection
    final CassandraConnection con = connect();

    WebServer ws = new WebServer(port);
    ws.getContext().setAttribute(
            AbstractResource.CONFIG,
            AbstractResource.create(g, con, targetTracker, cacheManager, jobManager));

    ws.start();
    LOG.info("AisView started");
    ws.join();
}
 
开发者ID:dma-ais,项目名称:AisView,代码行数:80,代码来源:AisViewDaemon.java

示例8: countCellsFromFeed

import dk.dma.ais.reader.AisReaders; //导入依赖的package包/类
@Test
public void countCellsFromFeed() throws IOException, InterruptedException {        
    final Set<Integer> mmsis = new HashSet<>();
    final Set<Cell> cells = new HashSet<>();
    final Grid grid = Grid.createSize(200);
    final AtomicReference<Long> mCount = new AtomicReference<>(0L);
    long start = System.currentTimeMillis();
    final DownSampleFilter df = new DownSampleFilter(0);
    
    //AisReader reader = AisReaders.createReaderFromFile("/tmp/ais_dk_76h.txt.gz");
    AisReader reader = AisReaders.createReaderFromFile("src/test/resources/ais-sample.txt.gz");
    reader.registerPacketHandler(new Consumer<AisPacket>() {
        @Override
        public void accept(AisPacket p) {
            if (df.rejectedByFilter(p)) {
                return;
            }
            AisMessage m = p.tryGetAisMessage();
            if (m == null) {
                return;
            }
            mCount.set(mCount.get() + 1);                
            // Only look at class a position reports
            if (!(m instanceof AisPositionMessage)) {
                return;
            }                
            mmsis.add(m.getUserId());                
            AisPositionMessage posM = (AisPositionMessage)m;
            Position pos = posM.getValidPosition();
            if (pos == null) {
                return;
            }
            cells.add(grid.getCell(pos));
        }            
    });
    
    reader.start();
    reader.join();
    
    long elapsed = (System.currentTimeMillis() - start) / 1000;
    double rate = (double)mCount.get() / (double)elapsed;
    System.out.println(String.format("%-30s %9d", "Elapsed s", elapsed));
    System.out.println(String.format("%-30s %9.0f msg/sec", "Message rate", rate));
    System.out.println(String.format("%-30s %9d", "Unique mmsi", mmsis.size()));
    System.out.println(String.format("%-30s %9d", "Unique cells", cells.size()));
}
 
开发者ID:dma-ais,项目名称:AisAbnormal,代码行数:47,代码来源:GridTest.java


注:本文中的dk.dma.ais.reader.AisReaders类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。