Mercurial > dive4elements > river
changeset 5049:b5e3df1feeb4
WaterlevelParser: Add Wst-Converting functionality.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 20 Feb 2013 12:14:11 +0100 |
parents | 1c34acb084ee |
children | e6dc908297e8 |
files | flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelParser.java |
diffstat | 1 files changed, 63 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelParser.java Wed Feb 20 11:52:52 2013 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelParser.java Wed Feb 20 12:14:11 2013 +0100 @@ -2,6 +2,7 @@ import java.io.File; import java.io.IOException; +import java.math.BigDecimal; import java.text.NumberFormat; import java.text.ParseException; import java.util.ArrayList; @@ -16,7 +17,19 @@ import de.intevation.flys.importer.ImportWaterlevelQRange; import de.intevation.flys.importer.ImportWaterlevelValue; +import de.intevation.flys.importer.ImportWstColumn; +import de.intevation.flys.importer.ImportRange; +import de.intevation.flys.importer.ImportWst; +import de.intevation.flys.importer.ImportWstQRange; + +/** + * Parse CSV Waterlevel files. + * As these waterlevels are probably used in fixation analysis + * only, functionality to export them to "fixation"-wsts + * has been added (the ImportWaterlevel*- stuff is actually + * not needed to do so.) + */ public class WaterlevelParser extends LineParser { private static final Logger log = Logger.getLogger(WaterlevelParser.class); @@ -44,6 +57,56 @@ } + /** + * Create ImportWst objects from ImportWaterlevel + * objects. + */ + public List<ImportWst> exportWsts() { + List<ImportWst> wsts = new ArrayList<ImportWst>(); + for(ImportWaterlevel waterlevel: getWaterlevels()) { + String description = waterlevel.getDescription(); + ImportWst wst = new ImportWst(); + wsts.add(wst); + wst.setDescription(description); + // Fixation kind. + wst.setKind(2); + wst.setUnit(waterlevel.getUnit()); + + // Fake WST has but 1 column. + wst.setNumberColumns(1); + ImportWstColumn column = wst.getColumn(0); + column.setDescription(description); + column.setName(description); + column.setPosition(0); + + // Build Q Range. + List<ImportWaterlevelQRange> qRanges = waterlevel.getQRanges(); + for(ImportWaterlevelQRange range: qRanges) { + List<ImportWaterlevelValue> values = range.getValues(); + if (values.size() < 2) { + log.warn ("Not enough values to build valid QRange"); + continue; + } + ImportRange iRange = new ImportRange( + BigDecimal.valueOf(values.get(0).getStation()), + BigDecimal.valueOf(values.get(values.size() -1).getStation())); + column.addColumnQRange( + new ImportWstQRange(iRange, BigDecimal.valueOf(range.getQ()))); + } + + // The other W/KM values. + for(ImportWaterlevelQRange range: qRanges) { + for(ImportWaterlevelValue value: range.getValues()) { + column.addColumnValue(BigDecimal.valueOf(value.getStation()), + BigDecimal.valueOf(value.getW())); + } + } + // TODO Maybe set a timeinterval. + } + return wsts; + } + + public List<ImportWaterlevel> getWaterlevels() { return waterlevels; }