# HG changeset patch # User Ingo Weinzierl # Date 1334667604 0 # Node ID ac5bd90697c131f1eee253e9027cc1647a0c4878 # Parent 8fe9c6584b931a167bdc7c847701f55fef9bb3ae Added new parser for flow velocity measurements and fixed some smaller bugs while importing flow velocity data. flys-backend/trunk@4250 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 8fe9c6584b93 -r ac5bd90697c1 flys-backend/ChangeLog --- a/flys-backend/ChangeLog Tue Apr 17 12:00:13 2012 +0000 +++ b/flys-backend/ChangeLog Tue Apr 17 13:00:04 2012 +0000 @@ -1,3 +1,20 @@ +2012-04-17 Ingo Weinzierl + + * src/main/java/de/intevation/flys/importer/parsers/FlowVelocityMeasurementParser.java: + New parser for flow velocity measurements. + + * src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurementValue.java, + src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.java, + src/main/java/de/intevation/flys/importer/ImportFlowVelocityModelValue.java, + src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java: + Fixed broken HQL statements. + + * src/main/java/de/intevation/flys/importer/ImportRiver.java: Store flow + velocity measurements into database after parsing them. + + * src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java: + Registered new model classes for flow velocity measurements. + 2012-04-17 Ingo Weinzierl * src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurementValue.java, diff -r 8fe9c6584b93 -r ac5bd90697c1 flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java --- a/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Tue Apr 17 12:00:13 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Tue Apr 17 13:00:04 2012 +0000 @@ -45,6 +45,8 @@ import de.intevation.flys.model.Fixpoint; import de.intevation.flys.model.Floodmaps; import de.intevation.flys.model.Floodplain; +import de.intevation.flys.model.FlowVelocityMeasurement; +import de.intevation.flys.model.FlowVelocityMeasurementValue; import de.intevation.flys.model.FlowVelocityModel; import de.intevation.flys.model.FlowVelocityModelValue; import de.intevation.flys.model.Gauge; @@ -249,6 +251,8 @@ cfg.addAnnotatedClass(Fixpoint.class); cfg.addAnnotatedClass(Floodplain.class); cfg.addAnnotatedClass(Floodmaps.class); + cfg.addAnnotatedClass(FlowVelocityMeasurement.class); + cfg.addAnnotatedClass(FlowVelocityMeasurementValue.class); cfg.addAnnotatedClass(FlowVelocityModel.class); cfg.addAnnotatedClass(FlowVelocityModelValue.class); cfg.addAnnotatedClass(Gauge.class); diff -r 8fe9c6584b93 -r ac5bd90697c1 flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.java Tue Apr 17 12:00:13 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.java Tue Apr 17 13:00:04 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; @@ -33,6 +34,17 @@ public ImportFlowVelocityMeasurement(String description) { this.description = description; + this.values = new ArrayList(); + } + + + public void setDescription(String description) { + this.description = description; + } + + + public void addValue(ImportFlowVelocityMeasurementValue value) { + this.values.add(value); } @@ -55,8 +67,8 @@ Query query = session.createQuery( "from FlowVelocityMeasurement where " + - " river:=river and " + - " description:=description" + " river=:river and " + + " description=:description" ); query.setParameter("river", river); diff -r 8fe9c6584b93 -r ac5bd90697c1 flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurementValue.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurementValue.java Tue Apr 17 12:00:13 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurementValue.java Tue Apr 17 13:00:04 2012 +0000 @@ -66,12 +66,14 @@ Query query = session.createQuery( "from FlowVelocityMeasurementValue where " + - " measurement:=measurement and " + - " station:=station" + " measurement=:measurement and " + + " station=:station and " + + " datetime=:datetime" ); query.setParameter("measurement", m); query.setParameter("station", station); + query.setParameter("datetime", datetime); List values = query.list(); diff -r 8fe9c6584b93 -r ac5bd90697c1 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 12:00:13 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java Tue Apr 17 13:00:04 2012 +0000 @@ -89,7 +89,7 @@ Query query = session.createQuery( "from FlowVelocityModel where " + - " river:=river and " + + " river=:river and " + " dischargeZone=:dischargeZone" ); diff -r 8fe9c6584b93 -r ac5bd90697c1 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 12:00:13 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModelValue.java Tue Apr 17 13:00:04 2012 +0000 @@ -51,7 +51,7 @@ Query query = session.createQuery( "from FlowVelocityModelValue where " + - " model:=model and " + + " model=:model and " + " station=:station" ); diff -r 8fe9c6584b93 -r ac5bd90697c1 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 12:00:13 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Tue Apr 17 13:00:04 2012 +0000 @@ -26,6 +26,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.FlowVelocityMeasurementParser; import de.intevation.flys.importer.parsers.PRFParser; import de.intevation.flys.importer.parsers.HYKParser; import de.intevation.flys.importer.parsers.MorphologicalWidthParser; @@ -115,6 +116,8 @@ protected List flowVelocityModels; + protected List flowVelocityMeasurements; + protected ImportWst wst; protected ImportUnit wstUnit; @@ -124,16 +127,17 @@ protected River peer; public ImportRiver() { - hyks = new ArrayList(); - crossSections = new ArrayList(); - extraWsts = new ArrayList(); - fixations = new ArrayList(); - officialLines = new ArrayList(); - floodWater = new ArrayList(); - floodProtection = new ArrayList(); - sedimentDensities = new ArrayList(); - morphologicalWidths = new ArrayList(); - flowVelocityModels = new ArrayList(); + hyks = new ArrayList(); + crossSections = new ArrayList(); + extraWsts = new ArrayList(); + fixations = new ArrayList(); + officialLines = new ArrayList(); + floodWater = new ArrayList(); + floodProtection = new ArrayList(); + sedimentDensities = new ArrayList(); + morphologicalWidths = new ArrayList(); + flowVelocityModels = new ArrayList(); + flowVelocityMeasurements = new ArrayList(); } public ImportRiver( @@ -366,10 +370,15 @@ log.warn("Cannot parse directory '" + measureDir + "'"); } else { - // TODO + FlowVelocityMeasurementParser parser = + new FlowVelocityMeasurementParser(); + for (File measurement: measureFiles) { log.debug("Parse file '" + measurement + "'"); + parser.parse(measurement); } + + flowVelocityMeasurements = parser.getMeasurements(); } } @@ -965,6 +974,18 @@ log.error("Error while storing flow velocity model.", cve); } } + + for (ImportFlowVelocityMeasurement m: flowVelocityMeasurements) { + try { + m.storeDependencies(river); + } + catch (SQLException sqle) { + log.error("Error while storing flow velocity measurement.", sqle); + } + catch (ConstraintViolationException cve) { + log.error("Error while storing flow velocity measurement.", cve); + } + } } } diff -r 8fe9c6584b93 -r ac5bd90697c1 flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityMeasurementParser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityMeasurementParser.java Tue Apr 17 13:00:04 2012 +0000 @@ -0,0 +1,105 @@ +package de.intevation.flys.importer.parsers; + +import java.math.BigDecimal; +import java.text.DateFormat; +import java.text.NumberFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +import java.text.ParseException; + +import org.apache.log4j.Logger; + +import de.intevation.flys.importer.ImportFlowVelocityMeasurement; +import de.intevation.flys.importer.ImportFlowVelocityMeasurementValue; + + +public class FlowVelocityMeasurementParser extends LineParser { + + private static final Logger log = + Logger.getLogger(FlowVelocityMeasurementParser.class); + + private static final NumberFormat nf = + NumberFormat.getInstance(DEFAULT_LOCALE); + + private static final DateFormat df = + new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); + + + private List measurements; + + private ImportFlowVelocityMeasurement current; + + + public FlowVelocityMeasurementParser() { + measurements = new ArrayList(); + } + + + public List getMeasurements() { + return measurements; + } + + @Override + protected void reset() { + current = new ImportFlowVelocityMeasurement(); + } + + + @Override + protected void finish() { + measurements.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) { + line = line.replace(";", ""); + current.setDescription(line); + } + + + public void handleDataLine(String line) { + String[] cols = line.split(SEPERATOR_CHAR); + + if (cols.length < 8) { + log.warn("skip invalid data line: '" + line + "'"); + return; + } + + try { + double km = nf.parse(cols[1]).doubleValue(); + double w = nf.parse(cols[5]).doubleValue(); + double q = nf.parse(cols[6]).doubleValue(); + double v = nf.parse(cols[7]).doubleValue(); + + String timestr = cols[3] + " " + cols[4]; + String description = cols.length > 8 ? cols[8] : null; + + current.addValue(new ImportFlowVelocityMeasurementValue( + df.parse(timestr), + new BigDecimal(km), + new BigDecimal(w), + new BigDecimal(q), + new BigDecimal(v), + description + )); + } + 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 :