changeset 5084:ca45dd039b54 slt-simplify-cross-sections

Log the number of points of cross sections to see the effect of the simplification.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 24 Feb 2013 21:38:09 +0100 (2013-02-24)
parents 7bbee0cfc171
children e1b831fe435a
files flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java
diffstat 1 files changed, 52 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Sun Feb 24 17:29:52 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Sun Feb 24 21:38:09 2013 +0100
@@ -172,19 +172,19 @@
     implements    CrossSectionParser.Callback {
 
         private Set<HashedFile> files = new HashSet<HashedFile>();
-        private String type;
-
+        private String          type;
 
         /**
          * Create new Callback, given type which is used for logging
          * purposes only.
          */
-        public ImportRiverCrossSectionParserCallback (String type) {
+        public ImportRiverCrossSectionParserCallback(String type) {
             this.type = type;
         }
 
 
         /** Accept file if not duplicate. */
+        @Override
         public boolean accept(File file) {
             HashedFile hf = new HashedFile(file);
             boolean success = files.add(hf);
@@ -196,14 +196,60 @@
 
 
         /** Add crosssection. */
+        @Override
         public void parsed(CrossSectionParser parser) {
            log.debug("callback from " + type + " parser");
 
-           addCrossSections(parser);
+            String  description = parser.getDescription();
+            Integer year        = parser.getYear();
+            ImportTimeInterval ti = year != null
+                ? new ImportTimeInterval(yearToDate(year))
+                : null;
+
+            Map<Double, List<XY>> data = parser.getData();
+
+            List<ImportCrossSectionLine> lines =
+                new ArrayList<ImportCrossSectionLine>(data.size());
+
+            Double simplificationEpsilon =
+                Config.INSTANCE.getCrossSectionSimplificationEpsilon();
+
+            long numReadPoints      = 0L;
+            long numRemainingPoints = 0L;
+
+            for (Map.Entry<Double, List<XY>> entry: data.entrySet()) {
+                Double   km     = entry.getKey();
+                List<XY> points = entry.getValue();
+                numReadPoints += points.size();
+                if (simplificationEpsilon != null) {
+                    points = DouglasPeuker.simplify(points, simplificationEpsilon);
+                }
+                numRemainingPoints += points.size();
+                lines.add(new ImportCrossSectionLine(km, points));
+            }
+
+            ImportRiver.this.addCrossSections(description, ti, lines);
+
+            double percent = numReadPoints > 0L
+                ? ((double)numRemainingPoints/numReadPoints)*100d
+                : 0d;
+
+            log.info(String.format(
+                "Number of points in cross section: %d / %d (%.2f%%)",
+                numReadPoints, numRemainingPoints, percent));
         }
     } // ImportRiverCrossSectionParserCallback 
 
 
+    private void addCrossSections(
+        String                       description,
+        ImportTimeInterval           ti,
+        List<ImportCrossSectionLine> lines
+    ) {
+        crossSections.add(new ImportCrossSection(this, description, ti, lines));
+    }
+
+
     public ImportRiver() {
         hyks                      = new ArrayList<ImportHYK>();
         crossSections             = new ArrayList<ImportCrossSection>();
@@ -938,36 +984,6 @@
     }
 
 
-    /** Add cross sections with description, years and lines to
-     * store. */
-    private void addCrossSections(CrossSectionParser parser) {
-        String  description = parser.getDescription();
-        Integer year        = parser.getYear();
-        ImportTimeInterval ti = year != null
-            ? new ImportTimeInterval(yearToDate(year))
-            : null;
-
-        Map<Double, List<XY>> data = parser.getData();
-
-        List<ImportCrossSectionLine> lines =
-            new ArrayList<ImportCrossSectionLine>(data.size());
-
-        Double simplificationEpsilon =
-            Config.INSTANCE.getCrossSectionSimplificationEpsilon();
-
-        for (Map.Entry<Double, List<XY>> entry: data.entrySet()) {
-            Double   km     = entry.getKey();
-            List<XY> points = entry.getValue();
-            if (simplificationEpsilon != null) {
-                points = DouglasPeuker.simplify(points, simplificationEpsilon);
-            }
-            lines.add(new ImportCrossSectionLine(km, points));
-        }
-
-        crossSections.add(new ImportCrossSection(
-            this, description, ti, lines));
-    }
-
     /** Create a W80 Parser and parse w80 files found. */
     public void parseW80s() {
         if (Config.INSTANCE.skipW80s()) {
@@ -1003,6 +1019,7 @@
 
         ImportRiverCrossSectionParserCallback da50Callback =
             new ImportRiverCrossSectionParserCallback("da50");
+
         parser.parseDA50s(riverDir, da50Callback);
     }
 
@@ -1024,6 +1041,7 @@
 
         ImportRiverCrossSectionParserCallback da66Callback =
             new ImportRiverCrossSectionParserCallback("da66");
+
         parser.parseDA66s(riverDir, da66Callback);
     }
 

http://dive4elements.wald.intevation.org