changeset 200:88048d4f6e4d

Add a hack to repair the units in WST files extraction. flys-backend/trunk@1542 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 23 Mar 2011 10:46:58 +0000
parents ed38839a6b08
children 3169b559ca3c
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java
diffstat 2 files changed, 45 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Tue Mar 22 15:48:09 2011 +0000
+++ b/flys-backend/ChangeLog	Wed Mar 23 10:46:58 2011 +0000
@@ -1,3 +1,10 @@
+2011-03-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/importer/WstParser.java:
+	  The unit extraction in the WST parser of desktop FLYS
+	  is broken! Add a hack here to repair this for our
+	  importer. Desktop FLYS needs a fix, too!
+
 2011-03-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/importer/WstParser.java:
--- a/flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java	Tue Mar 22 15:48:09 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java	Wed Mar 23 10:46:58 2011 +0000
@@ -16,6 +16,9 @@
 
 import de.intevation.flys.utils.StringUtil;
 
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
 public class WstParser
 {
     private static Logger log = Logger.getLogger(WstParser.class);
@@ -29,6 +32,12 @@
 
     public static final String ENCODING = "ISO-8859-1";
 
+    public static final Pattern UNIT_COMMENT =
+        Pattern.compile("\\*\\s*[kK][mM]\\s+(.+)");
+
+    public static final Pattern UNIT =
+        Pattern.compile("[^\\[]*\\[([^]]+)\\].*");
+
     public WstParser() {
     }
 
@@ -64,7 +73,7 @@
 
             double lastKm = Double.MAX_VALUE;
 
-            String einheit = "Wassserstand [NN + m]";
+            String einheit = "Wasserstand [NN + m]";
 
             HashMap<String, Double> oldEscapeLine = null;
 
@@ -167,13 +176,20 @@
                     continue;
                 }
 
+                if (line.length() < 11) {
+                    continue;
+                }
+
                 if (line.startsWith("*")) {
-                    if (bFirstComment && line.length() >= 11) {
-                        String yAxis = line.substring(10).trim();
-                        if (yAxis.length() > 0) {
-                            einheit = yAxis;
-                        }
-                        bFirstComment = false;
+                    Matcher m = UNIT_COMMENT.matcher(line);
+                    if (m.matches()) {
+                        log.debug("unit comment found");
+                        // XXX: This hack is needed because desktop 
+                        // FLYS is broken figuring out the unit
+                        String [] units = m.group(1).split("\\s{2,}");
+                        m = UNIT.matcher(units[0]);
+                        einheit = m.matches() ? m.group(1) : units[0];
+                        log.debug("unit: " + einheit);
                     }
                     continue;
                 }
@@ -187,14 +203,14 @@
                                 double q = firstAbfluesse[i];
                                 if (q < 0.001) {
                                     lsBezeichner[i] =
-                                        "<unbekannt#" + unknownCount + ">";
+                                        "<unbekannt #" + unknownCount + ">";
                                     ++unknownCount;
                                 }
                                 else {
                                     lsBezeichner[i] = "Q="+format(q);
                                 }
                             }
-                            lsHeader[i] = lsBezeichner[i] + " " + einheit;
+                            lsHeader[i] = lsBezeichner[i];
                         }
                         columnHeaderChecked = true;
                     }
@@ -276,10 +292,22 @@
         double              to, 
         Map<String, Double> values
     ) {
-        log.debug("addInterval: " + from + " " + to);
         if (values == null) {
             return;
         }
+        if (log.isDebugEnabled()) {
+            log.debug("addInterval: " + from + " " + to);
+            StringBuilder sb = new StringBuilder();
+            for (Map.Entry<String, Double> entry: values.entrySet()) {
+                if (sb.length() > 0) {
+                    sb.append("; ");
+                }
+                sb.append('"').append(entry.getKey())
+                  .append("\": ")
+                  .append(entry.getValue());
+            }
+            log.debug("entries: " + sb.toString());
+        }
     }
 
     private static final Double [] parseLineAsDouble(

http://dive4elements.wald.intevation.org