Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java @ 2833:5b54a648f702
Finished flow velocity data import: finished parsing meta data of model files and repaired broken HQL statements.
flys-backend/trunk@4259 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 18 Apr 2012 08:54:55 +0000 |
parents | ac13e466a55e |
children | f63b39799d2d |
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java Tue Apr 17 13:00:04 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java Wed Apr 18 08:54:55 2012 +0000 @@ -8,10 +8,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.text.ParseException; - import org.apache.log4j.Logger; +import de.intevation.flys.importer.ImportDischargeZone; import de.intevation.flys.importer.ImportFlowVelocityModel; import de.intevation.flys.importer.ImportFlowVelocityModelValue; @@ -24,6 +23,24 @@ private static final Pattern META_REGEX = Pattern.compile(".*Rechnung (.*) \\(Pegel (.*)\\).*"); + private static final Pattern META_GAUGE = + Pattern.compile("(.*) Q=(\\w*)m3/s"); + + private static final Pattern META_MAINVALUE_A = + Pattern.compile("([a-zA-Z]+)+(\\d+)*"); + + private static final Pattern META_MAINVALUE_B = + Pattern.compile("(([a-zA-Z]+)+(\\d+)*)\\s*-\\s*(([a-zA-Z]+)+(\\d+)*)"); + + private static final Pattern META_MAINVALUE_C = + Pattern.compile("([0-9]++)\\s?(\\w*)|([0-9]++,[0-9]++)\\s?(\\w*)"); + + private static final Pattern META_MAINVALUE_D = + Pattern.compile("(([0-9]*)\\s?(\\w*)|([0-9]++,[0-9]++)\\s?(\\w*)) bis (([0-9]*)\\s?(\\w*)|([0-9]++,[0-9]++)\\s?(\\w*))"); + + private static final Pattern META_MAINVALUE_E = + Pattern.compile("(([a-zA-Z]+)+(\\d+)*) bis (([a-zA-Z]+)+(\\d+)*)"); + private static final NumberFormat nf = NumberFormat.getInstance(DEFAULT_LOCALE); @@ -65,22 +82,133 @@ } - public void handleMetaLine(String line) { + protected void handleMetaLine(String line) { Matcher m = META_REGEX.matcher(line); if (m.matches()) { - String zoneStr = m.group(1); - String gaugeStr = m.group(2); + String mainValueStr = m.group(1); + String gaugeStr = m.group(2); - log.debug("Found zone string: '" + zoneStr + "'"); - log.debug("Found gauge string: '" + gaugeStr + "'"); + Object[] valueData = handleMainValueString(mainValueStr); + Object[] gaugeData = handleGaugeString(gaugeStr); - // TODO Do something with these information + if (valueData == null || valueData.length < 2) { + log.warn("skip invalid MainValue part: '" + line + "'"); + return; + } + + if (gaugeData == null || gaugeData.length < 2) { + log.warn("skip invalid gauge part: '" + line + "'"); + return; + } + + if (log.isDebugEnabled()) { + log.debug("Found meta information:"); + log.debug(" Gauge: " + gaugeData[0]); + log.debug(" Value: " + gaugeData[1]); + log.debug(" Lower: " + valueData[0]); + log.debug(" upper: " + valueData[1]); + } + + current.setDischargeZone(new ImportDischargeZone( + (String) gaugeData[0], + (BigDecimal) gaugeData[1], + (String) valueData[0], + (String) valueData[1] + )); } } - public void handleDataLine(String line) { + protected Object[] handleMainValueString(String mainValueStr) { + Matcher mA = META_MAINVALUE_A.matcher(mainValueStr); + if (mA.matches()) { + String name = mA.group(0); + + return new Object[] { name, name }; + } + + Matcher mB = META_MAINVALUE_B.matcher(mainValueStr); + if (mB.matches()) { + String lower = mB.group(1); + String upper = mB.group(4); + + return new Object[] { lower, upper }; + } + + Matcher mC = META_MAINVALUE_C.matcher(mainValueStr); + if (mC.matches()) { + String facA = mC.group(1); + String nameA = mC.group(2); + String facB = mC.group(3); + String nameB = mC.group(4); + + String fac = facA != null ? facA : facB; + String name = nameA != null ? nameA : nameB; + + String mainValue = fac + " " + name; + + return new Object[] { mainValue, mainValue }; + } + + Matcher mD = META_MAINVALUE_D.matcher(mainValueStr); + if (mD.matches()) { + String loFacA = mD.group(2); + String loNameA = mD.group(3); + String loFacB = mD.group(4); + String loNameB = mD.group(5); + + String upFacA = mD.group(7); + String upNameA = mD.group(8); + String upFacB = mD.group(9); + String upNameB = mD.group(10); + + String loFac = loFacA != null ? loFacA : loFacB; + String loName = loNameA != null ? loNameA : loNameB; + + String upFac = upFacA != null ? upFacA : upFacB; + String upName = upNameA != null ? upNameA : upNameB; + + String loMainValue = loFac + " " + loName; + String upMainValue = upFac + " " + upName; + + return new Object[] { loMainValue, upMainValue }; + } + + Matcher mE = META_MAINVALUE_E.matcher(mainValueStr); + if (mE.matches()) { + String lower = mE.group(1); + String upper = mE.group(4); + + return new Object[] { lower, upper }; + } + + return null; + } + + + protected Object[] handleGaugeString(String gaugeStr) { + Matcher m = META_GAUGE.matcher(gaugeStr); + + if (m.matches()) { + String name = m.group(1); + String qStr = m.group(2); + + try { + return new Object[] { + name, + new BigDecimal(nf.parse(qStr).doubleValue()) }; + } + catch (ParseException pe) { + log.warn("Error while parsing Q value: '" + qStr + "'"); + } + } + + return null; + } + + + protected void handleDataLine(String line) { String[] cols = line.split(SEPERATOR_CHAR); if (cols.length < 5) {