# HG changeset patch # User Ingo Weinzierl # Date 1334655472 0 # Node ID ac13e466a55e314708f9f2903edef1a3ded0f969 # Parent 85b25e74594f10783ca070cdc46764fcb88696d5 Added a parser for flow velocity model data and adjusted the db relation schema (missing q column). flys-backend/trunk@4245 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 85b25e74594f -r ac13e466a55e flys-backend/ChangeLog --- a/flys-backend/ChangeLog Tue Apr 17 08:50:15 2012 +0000 +++ b/flys-backend/ChangeLog Tue Apr 17 09:37:52 2012 +0000 @@ -1,3 +1,22 @@ +2012-04-17 Ingo Weinzierl + + * src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java: + New. Parser for model files of MINFO specific flow velocity data. + + * doc/schema/oracle-minfo.sql: Added a missing q column to + flow_velocity_model_values relation. + + * src/main/java/de/intevation/flys/importer/ImportFlowVelocityModelValue.java, + src/main/java/de/intevation/flys/model/FlowVelocityModelValue.java: + Added missing q column. + + * src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java: + Added setter methods for meta data and an addValue() for adding new + ImportFlowVelocityModelValues. + + * src/main/java/de/intevation/flys/importer/ImportRiver.java: Use + FlowVelocityModelParser for parsing model data of flow velocity files. + 2012-04-17 Ingo Weinzierl * src/main/java/de/intevation/flys/importer/ImportDischargeZone.java, diff -r 85b25e74594f -r ac13e466a55e flys-backend/doc/schema/oracle-minfo.sql --- a/flys-backend/doc/schema/oracle-minfo.sql Tue Apr 17 08:50:15 2012 +0000 +++ b/flys-backend/doc/schema/oracle-minfo.sql Tue Apr 17 09:37:52 2012 +0000 @@ -203,6 +203,7 @@ id NUMBER(38,0) NOT NULL, flow_velocity_model_id NUMBER(38,0) NOT NULL, station NUMBER(38,3) NOT NULL, + q NUMBER(38,3) NOT NULL, total_channel NUMBER(38,3) NOT NULL, main_channel NUMBER(38,3) NOT NULL, shear_stress NUMBER(38,3) NOT NULL, diff -r 85b25e74594f -r ac13e466a55e flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java Tue Apr 17 08:50:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java Tue Apr 17 09:37:52 2012 +0000 @@ -1,6 +1,7 @@ package de.intevation.flys.importer; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; @@ -29,20 +30,47 @@ private FlowVelocityModel peer; + public ImportFlowVelocityModel() { + values = new ArrayList(); + } + + public ImportFlowVelocityModel( ImportDischargeZone dischargeZone, String description ) { + this(); + this.dischargeZone = dischargeZone; this.description = description; } + public void setDischargeZone(ImportDischargeZone dischargeZone) { + this.dischargeZone = dischargeZone; + } + + + public void setDescription(String description) { + this.description = description; + } + + + public void addValue(ImportFlowVelocityModelValue value) { + this.values.add(value); + } + + public void storeDependencies(River river) throws SQLException, ConstraintViolationException { log.debug("store dependencies"); + if (dischargeZone == null) { + log.warn("skip flow velocity model: No discharge zone specified."); + return; + } + dischargeZone.storeDependencies(river); FlowVelocityModel peer = getPeer(river); diff -r 85b25e74594f -r ac13e466a55e flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModelValue.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModelValue.java Tue Apr 17 08:50:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModelValue.java Tue Apr 17 09:37:52 2012 +0000 @@ -15,6 +15,7 @@ public class ImportFlowVelocityModelValue { private BigDecimal station; + private BigDecimal q; private BigDecimal totalChannel; private BigDecimal mainChannel; private BigDecimal shearStress; @@ -24,11 +25,13 @@ public ImportFlowVelocityModelValue( BigDecimal station, + BigDecimal q, BigDecimal totalChannel, BigDecimal mainChannel, BigDecimal shearStress ) { this.station = station; + this.q = q; this.totalChannel = totalChannel; this.mainChannel = mainChannel; this.shearStress = shearStress; @@ -59,7 +62,7 @@ if (values.isEmpty()) { peer = new FlowVelocityModelValue( - model, station, totalChannel, mainChannel, shearStress); + model, station, q, totalChannel, mainChannel, shearStress); session.save(peer); } diff -r 85b25e74594f -r ac13e466a55e flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Tue Apr 17 08:50:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Tue Apr 17 09:37:52 2012 +0000 @@ -25,6 +25,7 @@ import de.intevation.flys.importer.parsers.BedHeightEpochParser; import de.intevation.flys.importer.parsers.BedHeightSingleParser; +import de.intevation.flys.importer.parsers.FlowVelocityModelParser; import de.intevation.flys.importer.parsers.PRFParser; import de.intevation.flys.importer.parsers.HYKParser; import de.intevation.flys.importer.parsers.MorphologicalWidthParser; @@ -351,10 +352,14 @@ log.warn("Cannot parse directory '" + modelDir + "'"); } else { - // TODO + FlowVelocityModelParser parser = new FlowVelocityModelParser(); + for (File model: modelFiles) { log.debug("Parse file '" + model + "'"); + parser.parse(model); } + + flowVelocityModels = parser.getModels(); } if (measureFiles == null) { diff -r 85b25e74594f -r ac13e466a55e flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java Tue Apr 17 09:37:52 2012 +0000 @@ -0,0 +1,111 @@ +package de.intevation.flys.importer.parsers; + +import java.math.BigDecimal; +import java.text.NumberFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import java.text.ParseException; + +import org.apache.log4j.Logger; + +import de.intevation.flys.importer.ImportFlowVelocityModel; +import de.intevation.flys.importer.ImportFlowVelocityModelValue; + + +public class FlowVelocityModelParser extends LineParser { + + private static final Logger log = + Logger.getLogger(FlowVelocityModelParser.class); + + private static final Pattern META_REGEX = + Pattern.compile(".*Rechnung (.*) \\(Pegel (.*)\\).*"); + + private static final NumberFormat nf = + NumberFormat.getInstance(DEFAULT_LOCALE); + + + private List models; + + private ImportFlowVelocityModel current; + + + public FlowVelocityModelParser() { + models = new ArrayList(); + } + + + public List getModels() { + return models; + } + + @Override + protected void reset() { + current = new ImportFlowVelocityModel(); + } + + + @Override + protected void finish() { + models.add(current); + } + + + @Override + protected void handleLine(String line) { + if (line.startsWith(START_META_CHAR)) { + handleMetaLine(stripMetaLine(line)); + } + else { + handleDataLine(line); + } + } + + + public void handleMetaLine(String line) { + Matcher m = META_REGEX.matcher(line); + + if (m.matches()) { + String zoneStr = m.group(1); + String gaugeStr = m.group(2); + + log.debug("Found zone string: '" + zoneStr + "'"); + log.debug("Found gauge string: '" + gaugeStr + "'"); + + // TODO Do something with these information + } + } + + + public void handleDataLine(String line) { + String[] cols = line.split(SEPERATOR_CHAR); + + if (cols.length < 5) { + log.warn("skip invalid data line: '" + line + "'"); + return; + } + + try { + double km = nf.parse(cols[0]).doubleValue(); + double q = nf.parse(cols[1]).doubleValue(); + double total = nf.parse(cols[2]).doubleValue(); + double main = nf.parse(cols[3]).doubleValue(); + double stress = nf.parse(cols[4]).doubleValue(); + + current.addValue(new ImportFlowVelocityModelValue( + new BigDecimal(km), + new BigDecimal(q), + new BigDecimal(total), + new BigDecimal(main), + new BigDecimal(stress) + )); + } + catch (ParseException pe) { + log.warn("Error while parsing flow velocity values.", pe); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 85b25e74594f -r ac13e466a55e flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModelValue.java --- a/flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModelValue.java Tue Apr 17 08:50:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModelValue.java Tue Apr 17 09:37:52 2012 +0000 @@ -30,6 +30,7 @@ private FlowVelocityModel flowVelocity; private BigDecimal station; + private BigDecimal q; private BigDecimal totalChannel; private BigDecimal mainChannel; private BigDecimal shearStress; @@ -42,12 +43,14 @@ public FlowVelocityModelValue( FlowVelocityModel flowVelocity, BigDecimal station, + BigDecimal q, BigDecimal totalChannel, BigDecimal mainChannel, BigDecimal shearStress ) { this.flowVelocity = flowVelocity; this.station = station; + this.q = q; this.totalChannel = totalChannel; this.mainChannel = mainChannel; this.shearStress = shearStress; @@ -89,6 +92,15 @@ this.station = station; } + @Column(name = "q") + public BigDecimal getQ() { + return q; + } + + public void setQ(BigDecimal q) { + this.q = q; + } + @Column(name = "total_channel") public BigDecimal getTotalChannel() { return totalChannel;