Search in sources :

Example 11 with Timer

use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.

the class PredefinedColorMap method minMax3.

/**
 * @return double[] {min, max, novalue}
 */
protected double[] minMax3(GridCoverage2D grid, IProgressMonitor monitor) {
    @SuppressWarnings("hiding") double // see OmsRasterReader
    novalue = -9999.0;
    double min = Double.POSITIVE_INFINITY;
    double max = Double.NEGATIVE_INFINITY;
    RenderedImage renderedImage = grid.getRenderedImage();
    monitor.beginTask("calculating min/max", renderedImage.getHeight());
    RectIter iter = RectIterFactory.create(renderedImage, null);
    Timer timer = new Timer();
    int sampleCount = 0;
    do {
        do {
            double value = iter.getSampleDouble();
            if (value == novalue) {
                continue;
            }
            if (value < novalue) {
                throw new IllegalStateException("XXX value < novalue : " + value);
            }
            if (value < min) {
                min = value;
            }
            if (value > max) {
                max = value;
            }
            sampleCount++;
        } while (!iter.nextPixelDone());
        iter.startPixels();
        monitor.worked(1);
    // monitor.subTask( String.valueOf( sampleCount ) );
    } while (// http://github.com/Polymap4/polymap4-core/issues/108 will be better/faster
    !iter.nextLineDone() && timer.elapsedTime() < 5000);
    monitor.done();
    log.info("minMax(): " + sampleCount + " samples in " + timer.elapsedTime() + "ms");
    // XXX check novalue
    return new double[] { min, max, novalue };
}
Also used : Timer(org.polymap.core.runtime.Timer) RectIter(javax.media.jai.iterator.RectIter) RenderedImage(java.awt.image.RenderedImage)

Example 12 with Timer

use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.

the class PredefinedColorMapEditor method minMax.

protected double[] minMax(GridCoverage2D grid) {
    GridGeometry2D geometry = grid.getGridGeometry();
    GridEnvelope gridRange = geometry.getGridRange();
    int w = gridRange.getHigh(0);
    int h = gridRange.getHigh(1);
    Timer timer = new Timer();
    Random random = new Random();
    double min = Double.MAX_VALUE;
    double max = Double.MIN_VALUE;
    double[] values = new double[1];
    for (int i = 0; i < 10000 || timer.elapsedTime() < 1000; i++) {
        grid.evaluate(new GridCoordinates2D(random.nextInt(w), random.nextInt(h)), values);
        min = values[0] < min ? values[0] : min;
        max = values[0] > max ? values[0] : max;
    }
    return new double[] { min, max };
}
Also used : GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) Timer(org.polymap.core.runtime.Timer) Random(java.util.Random) GridEnvelope(org.opengis.coverage.grid.GridEnvelope) GridCoordinates2D(org.geotools.coverage.grid.GridCoordinates2D)

Example 13 with Timer

use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.

the class PerformanceCacheTest method tstLoader.

public void tstLoader() throws Exception {
    Timer timer = new Timer();
    int count = 0;
    while (timer.elapsedTime() < 10000) {
        log.println("adding 1000 to " + cache.size());
        for (int i = 0; i < 1000; i++) {
            cache.get(new Object(), key -> new byte[1024]);
            count++;
        }
        Thread.sleep(100);
    }
    long time = timer.elapsedTime();
    log.println("Loops: " + count + " in " + time + "ms -> " + (1000f * count / time) + "/s");
}
Also used : Timer(org.polymap.core.runtime.Timer)

Example 14 with Timer

use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.

the class PerformanceCacheTest method tstRandom.

public void tstRandom() throws Exception {
    Timer timer = new Timer();
    int count = 0;
    Random random = new Random();
    ByteArrayLoader loader = new ByteArrayLoader();
    while (timer.elapsedTime() < 5000) {
        log.println("adding 1000 to " + cache.size());
        for (int i = 0; i < 10000; i++) {
            Integer key = new Integer((int) (Math.abs(random.nextGaussian()) * 400000));
            cache.get(key, loader);
            count++;
        }
    }
    long time = timer.elapsedTime();
    log.println("Loops: " + count + " in " + time + "ms -> " + (1000f * count / time) + "/s");
}
Also used : Timer(org.polymap.core.runtime.Timer) Random(java.util.Random)

Example 15 with Timer

use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.

the class Cache304 method updateLayer.

public void updateLayer(String layer, Geometry changed) {
    // flush queue
    if (!updateQueue.isEmpty()) {
        log.warn("Queue is not empty before updateLayer()!");
    }
    // remove all tiles for layer
    IRecordStore.Updater tx = null;
    try {
        lock.writeLock().tryLock(3, TimeUnit.SECONDS);
        SimpleQuery query = new SimpleQuery();
        query.eq(CachedTile.TYPE.layerId.name(), layer);
        query.setMaxResults(1000000);
        ResultSet resultSet = store.find(query);
        log.debug("Removing tiles: " + resultSet.count());
        Timer timer = new Timer();
        tx = store.prepareUpdate();
        for (IRecordState record : resultSet) {
            deleteTile(record, tx);
        }
        tx.apply(true);
        log.debug("done. (" + timer.elapsedTime() + "ms)");
    } catch (Exception e) {
        if (tx != null) {
            tx.discard();
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : SimpleQuery(org.polymap.recordstore.SimpleQuery) Timer(org.polymap.core.runtime.Timer) IRecordStore(org.polymap.recordstore.IRecordStore) ResultSet(org.polymap.recordstore.ResultSet) IRecordState(org.polymap.recordstore.IRecordState) IOException(java.io.IOException)

Aggregations

Timer (org.polymap.core.runtime.Timer)24 IOException (java.io.IOException)4 IRecordState (org.polymap.recordstore.IRecordState)4 ResultSet (org.polymap.recordstore.ResultSet)4 Random (java.util.Random)3 Iterator (java.util.Iterator)2 Log (org.apache.commons.logging.Log)2 LogFactory (org.apache.commons.logging.LogFactory)2 GridCoordinates2D (org.geotools.coverage.grid.GridCoordinates2D)2 GridGeometry2D (org.geotools.coverage.grid.GridGeometry2D)2 GridEnvelope (org.opengis.coverage.grid.GridEnvelope)2 Filter (org.opengis.filter.Filter)2 RecordQuery (org.polymap.recordstore.RecordQuery)2 SimpleQuery (org.polymap.recordstore.SimpleQuery)2 LuceneRecordQuery (org.polymap.recordstore.lucene.LuceneRecordQuery)2 Auth (io.milton.http.Auth)1 Request (io.milton.http.Request)1 Response (io.milton.http.Response)1 RenderedImage (java.awt.image.RenderedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1