Mercurial > dive4elements > river
view flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java @ 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 | |
children | 5b54a648f702 |
line wrap: on
line source
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 :