# HG changeset patch # User Felix Wolfsteller # Date 1371807731 -7200 # Node ID 43ef4943e0c218a5b47a375c8a338264b17ff8c2 # Parent df1a3826c691c8a093d1910363b758b5f825d4b5 SedimentLoadFacet: Now that we have total load values with correct ranges in place, use them accordingly instead of guessing ranges based on point data. diff -r df1a3826c691 -r 43ef4943e0c2 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFacet.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFacet.java Fri Jun 21 11:41:10 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFacet.java Fri Jun 21 11:42:11 2013 +0200 @@ -8,6 +8,8 @@ package org.dive4elements.river.artifacts.model.minfo; +import gnu.trove.TDoubleArrayList; + import org.dive4elements.artifactdatabase.state.Facet; import org.dive4elements.artifacts.Artifact; @@ -70,6 +72,11 @@ return null; } + // These complicated calculations were necessary because + // SedimentLoad/Fraction did not contain the ranges of the given + // values. Since this changed, the code is somewhat obsolete, but stable. + // For an example of easier calculation, see the "total" part below. + List sortedStarts = new ArrayList(); // Filter stations according to type. List stations = new ArrayList(); @@ -90,7 +97,31 @@ } Collections.sort(sortedStarts); - // Access data according to type. + // Handle sediment load differently, as it respects already + // the ranges that were added to SedimentLoad/Fraction. + if (getName().equals(FacetTypes.SEDIMENT_LOAD_TOTAL)) { + SedimentLoad load = result.getLoad(); + TDoubleArrayList xPos = new TDoubleArrayList(); + TDoubleArrayList yPos = new TDoubleArrayList(); + double lastX = -1d; + for (double km: load.getKms()) { + SedimentLoadFraction fraction = load.getFraction(km); + if (fraction.getTotal() != 0) { + if (Math.abs(lastX-km) >= EPSILON) { + xPos.add(Double.NaN); + yPos.add(Double.NaN); + } + xPos.add(km); + yPos.add(fraction.getTotal()); + xPos.add(fraction.getTotalRange().getEnd()); + yPos.add(fraction.getTotal()); + lastX = fraction.getTotalRange().getEnd(); + } + } + return new double[][] {xPos.toNativeArray(), yPos.toNativeArray()}; + } + + // Access data according to type (except total - see above). double[][] sd = getLoadData(result); // Sort by km.