# HG changeset patch # User Sascha L. Teichmann # Date 1341939844 0 # Node ID 3570abdf7daab983c134b6162263e3d38d0839a0 # Parent 43e42315ce228af5fa8cac46a0050966f1b0ae77 SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists. flys-artifacts/trunk@4919 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 43e42315ce22 -r 3570abdf7daa flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Jul 10 16:37:48 2012 +0000 +++ b/flys-artifacts/ChangeLog Tue Jul 10 17:04:04 2012 +0000 @@ -1,3 +1,8 @@ +2012-07-12 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/model/SQOverview.java: + Made km separating of dates epsilon tolerant and avoid empty date lists. + 2012-07-10 Raimund Renkert * src/main/java/de/intevation/flys/artifacts/services/SQKMChartService.java: diff -r 43e42315ce22 -r 3570abdf7daa flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/SQOverview.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/SQOverview.java Tue Jul 10 16:37:48 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/SQOverview.java Tue Jul 10 17:04:04 2012 +0000 @@ -83,14 +83,14 @@ private static Logger log = Logger.getLogger(FixingsOverview.class); - public static final double EPSILON = 1e-1; + public static final double EPSILON = 1e-4; public static final String DATE_FORMAT = "dd.MM.yyyy"; public static final String SQL_SQ = "SELECT" + - " s.km," + - " m.datum " + + " s.km AS km," + + " m.datum AS datum " + "FROM messung m " + " JOIN station s" + " on m.stationid = s.stationid " + @@ -114,6 +114,10 @@ this.riverName = riverName; } + private static final boolean epsilonEquals(double a, double b) { + return Math.abs(a - b) < EPSILON; + } + protected void loadData(Session session) { SQLQuery query = session.createSQLQuery(SQL_SQ) .addScalar("km", StandardBasicTypes.DOUBLE) @@ -127,22 +131,22 @@ log.warn("No river '" + riverName + "' found."); } - Double prevKm = -1d; + Double prevKm = -Double.MAX_VALUE; List dates = new ArrayList(); - for (int i = 0; i < list.size(); i++) { - Object[] row = list.get(i); - Double km = (Double) row[0]; - Date date = (Date) row[1]; - if (km.equals(prevKm)) { - dates.add(date); - } - else { + + for (Object [] row: list) { + Double km = (Double)row[0]; + if (!epsilonEquals(km, prevKm) && !dates.isEmpty()) { entries.add(prevKm, dates); dates = new ArrayList(); - dates.add(date); } + dates.add((Date)row[1]); prevKm = km; } + + if (!dates.isEmpty()) { + entries.add(prevKm, dates); + } } public boolean load(Session session) { @@ -158,6 +162,7 @@ } public KMIndex> filter(Filter f) { + // TODO: Apply filter return entries; } @@ -203,4 +208,4 @@ document.appendChild(sqElement); } } -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : \ No newline at end of file +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :