Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/MiddleBedHeightCalculation.java @ 8532:73a4c3c202e5
(issue1051) Use a list of single years in SedimentLoadYear mode
Instead of a range you can now select multiple distinct years
in the sedimentload calculation.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 11 Feb 2015 18:00:48 +0100 |
parents | e4606eae8ea5 |
children | 3a0522f1a532 |
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.river.model.BedHeightSingle; import org.dive4elements.river.model.BedHeightSingleValue; import org.dive4elements.river.artifacts.access.BedHeightAccess; import org.dive4elements.river.artifacts.model.Calculation; import org.dive4elements.river.artifacts.model.CalculationResult; public class MiddleBedHeightCalculation extends Calculation { private static final Logger log = Logger.getLogger(MiddleBedHeightCalculation.class); public CalculationResult calculate(BedHeightAccess access) { log.info("MiddleBedHeightCalculation.calculate"); int[] singleIds = access.getBedHeightSingleIDs(); if (log.isDebugEnabled()) { Artifact artifact = access.getArtifact(); log.debug("Artifact '" + artifact.identifier() + "' contains:"); if (singleIds != null) { log.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 { log.warn("Cannot find Single by id: " + id); // TODO ADD WARNING } } return singles; } protected CalculationResult buildCalculationResult( BedHeightAccess access, List<BedHeightSingle> singles ) { log.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); } } log.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 ) { log.debug("Prepare data for single: " + single.getDescription()); List<BedHeightSingleValue> values = BedHeightSingleValue.getBedHeightSingleValues(single, kmLo, kmHi); int year = single.getYear() != null ? single.getYear() : 0; String curElevModel = single.getCurElevationModel() != null ? single.getCurElevationModel().getName() : ""; String oldElevModel = single.getOldElevationModel() != null ? single.getOldElevationModel().getName() : ""; String riverElevModel = single.getRiver().getWstUnit() != null ? single.getRiver().getWstUnit().getName() : ""; String type = single.getType() != null ? single.getType().getName() : ""; String locationSystem = single.getLocationSystem() != null ? single.getLocationSystem().getName() : ""; MiddleBedHeightData data = new MiddleBedHeightData( year, year, single.getEvaluationBy(), single.getDescription(), curElevModel, oldElevModel, riverElevModel, type, locationSystem, single.getSoundingWidth()); 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); } } log.debug("Single contains " + values.size() + " values"); return data; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :