comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java @ 8946:5d5d482da3e9

Implementing SINFO - FlowDepthMinMax calculation
author gernotbelger
date Tue, 13 Mar 2018 18:49:33 +0100
parents 11bf13cf0463
children 798d9dcbccdd
comparison
equal deleted inserted replaced
8945:4a6b6a3c279c 8946:5d5d482da3e9
15 import java.util.Map.Entry; 15 import java.util.Map.Entry;
16 import java.util.NavigableMap; 16 import java.util.NavigableMap;
17 import java.util.TreeMap; 17 import java.util.TreeMap;
18 18
19 import org.apache.commons.lang.math.DoubleRange; 19 import org.apache.commons.lang.math.DoubleRange;
20 import org.dive4elements.artifacts.CallContext;
21 import org.dive4elements.river.artifacts.BedHeightsArtifact;
20 import org.dive4elements.river.artifacts.math.Linear; 22 import org.dive4elements.river.artifacts.math.Linear;
23 import org.dive4elements.river.artifacts.model.Calculation;
21 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo; 24 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo;
22 import org.dive4elements.river.model.BedHeight; 25 import org.dive4elements.river.model.BedHeight;
23 import org.dive4elements.river.model.BedHeightValue; 26 import org.dive4elements.river.model.BedHeightValue;
27 import org.dive4elements.river.utils.RiverUtils;
24 28
25 /** 29 /**
26 * Provides bed heigts for vcarious calculations. 30 * Provides bed heigts for vcarious calculations.
27 * 31 *
28 * @author Gernot Belger 32 * @author Gernot Belger
45 } 49 }
46 50
47 return result; 51 return result;
48 } 52 }
49 53
54 public static BedHeightsFinder forId(final CallContext context, final String soundingId, final DoubleRange calcRange, final Calculation problems) {
55
56 // REMARK: absolutely unbelievable....
57 // The way how bed-heights (and other data too) is accessed is different for nearly every calculation-type
58 // throughout flys.
59 // The knowledge on how to parse the datacage-ids is spread through the complete code-base...
60
61 // We use here the way on how bed-heights are accessed by the BedDifferenceAccess/BedDifferenceCalculation, but
62 // this is plain random
63 final String[] parts = soundingId.split(";");
64
65 final BedHeightsArtifact artifact = (BedHeightsArtifact) RiverUtils.getArtifact(parts[0], context);
66
67 final Integer bedheightId = artifact.getDataAsInteger("height_id");
68
69 // REMARK: this only works with type 'single'; unclear on how to distinguish from epoch data (or whatever the
70 // other type means)
71 // Luckily, the requirement is to only access 'single' data here.
72 // final String bedheightType = artifact.getDataAsString("type");
73
74 // REMARK: BedDifferences uses this, but we also need the metadata of the BedHeight
75 // REMARK: second absolutely awful thing: BedHeight is a hibernate binding class, accessing the database via
76 // hibernate stuff
77 // BedHeightFactory uses its own (direct) way of accessing the data, with its own implemented data classes.
78 // return BedHeightFactory.getHeight(bedheightType, bedheightId, from, to);
79
80 final BedHeightsFinder bedHeight = bedheightId == null ? null : BedHeightsFinder.forId(bedheightId, calcRange);
81 if (bedHeight != null)
82 return bedHeight;
83
84 // FIXME: 10n
85 problems.addProblem("Failed to access sounding with id '{0}'", soundingId);
86 return null;
87 }
88
50 /** 89 /**
51 * Creates a {@link BedHeightsFinder} for a dataset from the database, specified by its id. 90 * Creates a {@link BedHeightsFinder} for a dataset from the database, specified by its id.
52 * 91 *
53 * @return <code>null</code> if no bed height with the given id exists. 92 * @return <code>null</code> if no bed height with the given id exists.
54 */ 93 */
55 public static BedHeightsFinder forId(final int id, final DoubleRange range) { 94 private static BedHeightsFinder forId(final int id, final DoubleRange range) {
56 95
57 final BedHeight bedHeight = BedHeight.getBedHeightById(id); 96 final BedHeight bedHeight = BedHeight.getBedHeightById(id);
58 if (bedHeight == null) 97 if (bedHeight == null)
59 return null; 98 return null;
60 99

http://dive4elements.wald.intevation.org