# HG changeset patch # User mschaefer # Date 1588774658 -7200 # Node ID 8a84c9fef8ec528c29e5c21d0ea6b842217eca22 # Parent 692f49b7de631d0dff3e57acc5bfe96f1be63a84 S-info/tkh: d50 average changed from median to arithmetic mean diff -r 692f49b7de63 -r 8a84c9fef8ec artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/BedQualityD50KmValueFinder.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/BedQualityD50KmValueFinder.java Fri Apr 03 13:15:40 2020 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/BedQualityD50KmValueFinder.java Wed May 06 16:17:38 2020 +0200 @@ -68,7 +68,7 @@ + " WHERE (g.name = :name)" // + " AND (p.tiefevon > 0.0) AND (p.tiefebis <= 0.5)" // + " AND (t.datum BETWEEN :fromdate AND :todate)" // - + " ORDER BY s.km ASC, a.d50 ASC"; + + " ORDER BY s.km ASC, a.d50 ASC"; public static final Date MIN_DATE = new Date(-10000000000000l); // Database does not cope with Long.MIN/Long.Max, so we go just a few hundred years // back/forward @@ -127,25 +127,43 @@ // sqlQuery.setDouble("tokm", kmRange.getMaximumDouble()); sqlQuery.setDate("fromdate", startTime); sqlQuery.setDate("todate", endTime); + final List rows = sqlQuery.list(); - final List rows = sqlQuery.list(); + // Aggregate d50 values for each km + // final TDoubleArrayList kmsm = new TDoubleArrayList(); + // final TDoubleArrayList valuesm = new TDoubleArrayList(); final TDoubleArrayList kms = new TDoubleArrayList(); final TDoubleArrayList values = new TDoubleArrayList(); - final TDoubleArrayList kmd50s = new TDoubleArrayList(); - - // Median aggregate d50 values for each km if (rows != null) { + // // median + // final TDoubleArrayList kmd50s = new TDoubleArrayList(); + // for (int i = 0; i <= rows.size() - 1; i++) { + // log.trace("loadValues rows(" + i + ") " + rows.get(i)[0] + " " + rows.get(i)[1] + " " + rows.get(i)[2] + " " + + // rows.get(i)[3] + " " + // + rows.get(i)[4]); + // kmd50s.add((double) rows.get(i)[4]); + // if (((i == rows.size() - 1) || !Utils.epsilonEquals((double) rows.get(i)[0], (double) rows.get(i + 1)[0], 0.0001))) { + // final int k = kmd50s.size() / 2; + // valuesm.add(((k + k < kmd50s.size()) ? kmd50s.get(k) : (kmd50s.get(k - 1) + kmd50s.get(k)) / 2) / 1000); + // kmsm.add((double) rows.get(i)[0]); + // log.debug(String.format("loadValues km %.3f d50(mm) %.1f count %d", kmsm.get(kmsm.size() - 1), + // valuesm.get(valuesm.size() - 1) * 1000, + // kmd50s.size())); + // kmd50s.clear(); + // } + // } + // arithmetic mean + double sum = 0; + int n = 0; for (int i = 0; i <= rows.size() - 1; i++) { - log.trace("loadValues rows(" + i + ") " + rows.get(i)[0] + " " + rows.get(i)[1] + " " + rows.get(i)[2] + " " + rows.get(i)[3] + " " - + rows.get(i)[4]); - kmd50s.add((double) rows.get(i)[4]); + sum += (double) rows.get(i)[4]; + n++; if (((i == rows.size() - 1) || !Utils.epsilonEquals((double) rows.get(i)[0], (double) rows.get(i + 1)[0], 0.0001))) { - final int k = kmd50s.size() / 2; - values.add(((k + k < kmd50s.size()) ? kmd50s.get(k) : (kmd50s.get(k - 1) + kmd50s.get(k)) / 2) / 1000); kms.add((double) rows.get(i)[0]); - log.debug(String.format("loadValues km %.3f d50(mm) %.1f count %d", kms.get(kms.size() - 1), values.get(values.size() - 1) * 1000, - kmd50s.size())); - kmd50s.clear(); + values.add((sum / n) / 1000); + log.debug(String.format("loadValues km %.3f d50(mm) %.1f count %d", kms.get(kms.size() - 1), values.get(values.size() - 1) * 1000, n)); + sum = 0; + n = 0; } } } @@ -178,7 +196,7 @@ try { return this.interpolator.value(km); } - catch (@SuppressWarnings("unused") final ArgumentOutsideDomainException e) { + catch (final ArgumentOutsideDomainException e) { // No stack trace because this might happen a lot (intended) and we produce an error message anyways. // e.printStackTrace();