Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelData.java @ 8881:6b93a2498e06
Slightly better abstraction for extraction waterlevels via datacage
author | gernotbelger |
---|---|
date | Fri, 09 Feb 2018 16:11:34 +0100 |
parents | |
children | a536e1aacf0f |
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde * Software engineering by * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * 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.states; import org.dive4elements.river.artifacts.model.WKms; import org.dive4elements.river.model.Gauge; import org.dive4elements.river.model.River; /** * Represents a waterlevel fetched with the {@link WaterlevelFetcher}. * * @author Gernot Belger */ public class WaterlevelData { private final WKms wkms; private final String name; /** If <code>true</code>, tabular export will show gauges for every station, else only for the first gauge */ private final boolean showAllGauges; public WaterlevelData(final WKms wkms) { this(wkms, false); } public WaterlevelData(final WKms wkms, final boolean showAllGauges) { this(null, wkms, showAllGauges); } public WaterlevelData(final String name, final WKms wkms, final boolean showAllGauges) { this.name = name; this.wkms = wkms; this.showAllGauges = showAllGauges; } public WaterlevelData filterByRange(final double from, final double to) { if (Double.isNaN(from) || Double.isNaN(to)) { return this; } final WKms filteredWkms = this.wkms.filteredKms(from, to); return new WaterlevelData(filteredWkms); } public WaterlevelData withName(final String nameToSet) { return new WaterlevelData(nameToSet, this.wkms, this.showAllGauges); } public String getName() { return this.name; } public WKms getWkms() { return this.wkms; } public boolean isShowAllGauges() { return this.showAllGauges; } public Gauge findReferenceGauge(final River river) { final double[] wstFromTo = findWstFromTo(); return river.determineRefGauge(wstFromTo, true); } private double[] findWstFromTo() { final double from = this.wkms.getKm(0); final double to = this.wkms.getKm(this.wkms.size() - 1); final boolean waterIncreasing = this.wkms.guessWaterIncreasing(); if (waterIncreasing) return new double[] { to, from }; return new double[] { from, to }; } }