Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
8879:64ca63f79f6f | 8881:6b93a2498e06 |
---|---|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.states; | |
11 | |
12 import org.dive4elements.river.artifacts.model.WKms; | |
13 import org.dive4elements.river.model.Gauge; | |
14 import org.dive4elements.river.model.River; | |
15 | |
16 /** | |
17 * Represents a waterlevel fetched with the {@link WaterlevelFetcher}. | |
18 * | |
19 * @author Gernot Belger | |
20 */ | |
21 public class WaterlevelData { | |
22 private final WKms wkms; | |
23 | |
24 private final String name; | |
25 | |
26 /** If <code>true</code>, tabular export will show gauges for every station, else only for the first gauge */ | |
27 private final boolean showAllGauges; | |
28 | |
29 public WaterlevelData(final WKms wkms) { | |
30 this(wkms, false); | |
31 } | |
32 | |
33 public WaterlevelData(final WKms wkms, final boolean showAllGauges) { | |
34 this(null, wkms, showAllGauges); | |
35 } | |
36 | |
37 public WaterlevelData(final String name, final WKms wkms, final boolean showAllGauges) { | |
38 this.name = name; | |
39 this.wkms = wkms; | |
40 this.showAllGauges = showAllGauges; | |
41 } | |
42 | |
43 public WaterlevelData filterByRange(final double from, final double to) { | |
44 if (Double.isNaN(from) || Double.isNaN(to)) { | |
45 return this; | |
46 } | |
47 | |
48 final WKms filteredWkms = this.wkms.filteredKms(from, to); | |
49 return new WaterlevelData(filteredWkms); | |
50 } | |
51 | |
52 public WaterlevelData withName(final String nameToSet) { | |
53 return new WaterlevelData(nameToSet, this.wkms, this.showAllGauges); | |
54 } | |
55 | |
56 public String getName() { | |
57 return this.name; | |
58 } | |
59 | |
60 public WKms getWkms() { | |
61 return this.wkms; | |
62 } | |
63 | |
64 public boolean isShowAllGauges() { | |
65 return this.showAllGauges; | |
66 } | |
67 | |
68 public Gauge findReferenceGauge(final River river) { | |
69 final double[] wstFromTo = findWstFromTo(); | |
70 return river.determineRefGauge(wstFromTo, true); | |
71 } | |
72 | |
73 private double[] findWstFromTo() { | |
74 | |
75 final double from = this.wkms.getKm(0); | |
76 final double to = this.wkms.getKm(this.wkms.size() - 1); | |
77 | |
78 final boolean waterIncreasing = this.wkms.guessWaterIncreasing(); | |
79 if (waterIncreasing) | |
80 return new double[] { to, from }; | |
81 | |
82 return new double[] { from, to }; | |
83 } | |
84 } |