Mercurial > dive4elements > river
changeset 2828:ac13e466a55e
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
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 17 Apr 2012 09:37:52 +0000 |
parents | 85b25e74594f |
children | 4074777afcfa |
files | flys-backend/ChangeLog flys-backend/doc/schema/oracle-minfo.sql flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModelValue.java flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModelValue.java |
diffstat | 7 files changed, 181 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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 <ingo@intevation.de> + + * 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 <ingo@intevation.de> * src/main/java/de/intevation/flys/importer/ImportDischargeZone.java,
--- 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,
--- 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<ImportFlowVelocityModelValue>(); + } + + 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);
--- 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); }
--- 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) {
--- /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<ImportFlowVelocityModel> models; + + private ImportFlowVelocityModel current; + + + public FlowVelocityModelParser() { + models = new ArrayList<ImportFlowVelocityModel>(); + } + + + public List<ImportFlowVelocityModel> 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 :
--- 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;