Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/MiddleBedHeightCalculation.java @ 7983:62befca02480 facet-metadata
Moved MiddleBedHeight classes to minfo package. Facet now returns double[][] data.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 01 Jul 2014 13:25:46 +0200 |
parents | |
children | 98e25342df73 |
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde * Software engineering by Intevation GmbH * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.artifacts.model.minfo; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.common.utils.DateUtils; import org.dive4elements.river.model.BedHeightSingle; import org.dive4elements.river.model.BedHeightSingleValue; import org.dive4elements.river.model.TimeInterval; import org.dive4elements.river.artifacts.access.BedHeightAccess; import org.dive4elements.river.artifacts.model.Calculation; import org.dive4elements.river.artifacts.model.CalculationResult; import org.dive4elements.river.artifacts.model.minfo.MiddleBedHeightData; public class MiddleBedHeightCalculation extends Calculation { private static final Logger logger = Logger.getLogger(MiddleBedHeightCalculation.class); public CalculationResult calculate(BedHeightAccess access) { logger.info("MiddleBedHeightCalculation.calculate"); int[] singleIds = access.getBedHeightSingleIDs(); if (logger.isDebugEnabled()) { Artifact artifact = access.getArtifact(); logger.debug("Artifact '" + artifact.identifier() + "' contains:"); if (singleIds != null) { logger.debug(" " + singleIds.length + " single bedheight ids"); } } List<BedHeightSingle> singles = getSingles(access, singleIds); return buildCalculationResult(access, singles); } protected List<BedHeightSingle> getSingles( BedHeightAccess access, int[] ids ) { List<BedHeightSingle> singles = new ArrayList<BedHeightSingle>(); for (int id: ids) { BedHeightSingle s = BedHeightSingle.getBedHeightSingleById(id); if (s != null) { singles.add(s); } else { logger.warn("Cannot find Single by id: " + id); // TODO ADD WARNING } } return singles; } protected CalculationResult buildCalculationResult( BedHeightAccess access, List<BedHeightSingle> singles ) { logger.info("MiddleBedHeightCalculation.buildCalculationResult"); double kmLo = access.getLowerKM(); double kmHi = access.getUpperKM(); List<MiddleBedHeightData> data = new ArrayList<MiddleBedHeightData>(); for (BedHeightSingle single: singles) { MiddleBedHeightData d = prepareSingleData(single, kmLo, kmHi); if (d != null) { data.add(d); } } logger.debug("Calculation results in " + data.size() + " data objects."); return new CalculationResult((MiddleBedHeightData[]) data.toArray(new MiddleBedHeightData[data.size()]), this); } protected MiddleBedHeightData prepareSingleData( BedHeightSingle single, double kmLo, double kmHi ) { logger.debug("Prepare data for single: " + single.getDescription()); List<BedHeightSingleValue> values = BedHeightSingleValue.getBedHeightSingleValues(single, kmLo, kmHi); int year = single.getYear() != null ? single.getYear() : 0; MiddleBedHeightData data = new MiddleBedHeightData( year, year, single.getEvaluationBy(), single.getDescription()); for (BedHeightSingleValue value: values) { if (value.getHeight() != null) { double uncert = value.getUncertainty() != null ? value.getUncertainty().doubleValue() : Double.NaN; double sounding = value.getSoundingWidth() != null ? value.getSoundingWidth().doubleValue() : Double.NaN; double gap = value.getDataGap() != null ? value.getDataGap().doubleValue() : Double.NaN; data.addAll(value.getStation().doubleValue(), value.getHeight().doubleValue(), uncert, sounding, gap, value.getWidth().doubleValue(), false); } else { data.addAll(value.getStation().doubleValue(), 0, 0, 0, 0, 0, true); } } logger.debug("Single contains " + values.size() + " values"); return data; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :