# HG changeset patch # User Ingo Weinzierl # Date 1334149972 0 # Node ID b57c95094b68cc2ead087957211c3d9a7ce33d1d # Parent 5ac1db5156be366a4cf247800f10dd66222b0a5f Finished work on parsing meta information and data specific to single bed heights files in MINFO. flys-backend/trunk@4216 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 5ac1db5156be -r b57c95094b68 flys-backend/ChangeLog --- a/flys-backend/ChangeLog Wed Apr 11 13:09:46 2012 +0000 +++ b/flys-backend/ChangeLog Wed Apr 11 13:12:52 2012 +0000 @@ -1,3 +1,16 @@ +2012-04-11 Ingo Weinzierl + + * src/main/java/de/intevation/flys/importer/parsers/BedHeightSingleParser.java: + Finished work on parsing meta information and data specific to single bed + heights. + + * src/main/java/de/intevation/flys/importer/ImportBedHeightSingleValue.java, + src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java, + src/main/java/de/intevation/flys/importer/ImportElevationModel.java, + src/main/java/de/intevation/flys/importer/ImportLocationSystem.java, + src/main/java/de/intevation/flys/importer/ImportBedHeightType.java: Some + new and modified temp storages used during MINFO import. + 2012-04-11 Ingo Weinzierl * doc/schema/oracle-minfo.sql, diff -r 5ac1db5156be -r b57c95094b68 flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java Wed Apr 11 13:09:46 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java Wed Apr 11 13:12:52 2012 +0000 @@ -1,5 +1,8 @@ package de.intevation.flys.importer; +import java.util.ArrayList; +import java.util.List; + import org.apache.log4j.Logger; import de.intevation.flys.model.River; @@ -9,12 +12,24 @@ { private static Logger log = Logger.getLogger(ImportBedHeightSingle.class); + protected int year; + protected int soundingWidth; + protected String evaluationBy; protected String description; + protected ImportRange range; + protected ImportBedHeightType type; + protected ImportLocationSystem locationSystem; + protected ImportElevationModel curElevationModel; + protected ImportElevationModel oldElevationModel; + + protected List values; + public ImportBedHeightSingle(String description) { this.description = description; + this.values = new ArrayList(); } @@ -23,6 +38,46 @@ } + public void setYear(int year) { + this.year = year; + } + + public void setSoundingWidth(int soundingWidth) { + this.soundingWidth = soundingWidth; + } + + public void setEvaluationBy(String evaluationBy) { + this.evaluationBy = evaluationBy; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setRange(ImportRange range) { + this.range = range; + } + + public void setType(ImportBedHeightType type) { + this.type = type; + } + + public void setLocationSystem(ImportLocationSystem locationSystem) { + this.locationSystem = locationSystem; + } + + public void setCurElevationModel(ImportElevationModel curElevationModel) { + this.curElevationModel = curElevationModel; + } + + public void setOldElevationModel(ImportElevationModel oldElevationModel) { + this.oldElevationModel = oldElevationModel; + } + + public void addValue(ImportBedHeightSingleValue value) { + values.add(value); + } + public void storeDependencies(River river) { log.info("Store dependencies for single: '" + getDescription() + "'"); log.error("TODO: IMPLEMENT ME!"); diff -r 5ac1db5156be -r b57c95094b68 flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingleValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingleValue.java Wed Apr 11 13:12:52 2012 +0000 @@ -0,0 +1,36 @@ +package de.intevation.flys.importer; + +import java.math.BigDecimal; + + +public class ImportBedHeightSingleValue { + + protected ImportBedHeightSingle bedHeight; + + protected BigDecimal station; + protected BigDecimal height; + protected BigDecimal uncertainty; + protected BigDecimal dataGap; + protected BigDecimal soundingWidth; + protected BigDecimal width; + + + public ImportBedHeightSingleValue( + ImportBedHeightSingle bedHeight, + BigDecimal station, + BigDecimal height, + BigDecimal uncertainty, + BigDecimal dataGap, + BigDecimal soundingWidth, + BigDecimal width + ) { + this.bedHeight = bedHeight; + this.station = station; + this.height = height; + this.uncertainty = uncertainty; + this.dataGap = dataGap; + this.soundingWidth = soundingWidth; + this.width = width; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 5ac1db5156be -r b57c95094b68 flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightType.java Wed Apr 11 13:12:52 2012 +0000 @@ -0,0 +1,34 @@ +package de.intevation.flys.importer; + +import org.apache.log4j.Logger; + + +public class ImportBedHeightType { + + private static final Logger log = + Logger.getLogger(ImportBedHeightType.class); + + protected String name; + protected String description; + + + public ImportBedHeightType(String name, String description) { + this.name = name; + this.description = description; + } + + + public static String getBedHeightName(String description) { + if (description.equals("Flächenpeilung")) { + return "FP"; + } + else if ("Querprofile".equals(description)) { + return "QP"; + } + else { + log.warn("Unknown bed height type: " + description); + return null; + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 5ac1db5156be -r b57c95094b68 flys-backend/src/main/java/de/intevation/flys/importer/ImportElevationModel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportElevationModel.java Wed Apr 11 13:12:52 2012 +0000 @@ -0,0 +1,17 @@ +package de.intevation.flys.importer; + + + +public class ImportElevationModel { + + protected String name; + + protected ImportUnit unit; + + + public ImportElevationModel(String name, ImportUnit unit) { + this.name = name; + this.unit = unit; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 5ac1db5156be -r b57c95094b68 flys-backend/src/main/java/de/intevation/flys/importer/ImportLocationSystem.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportLocationSystem.java Wed Apr 11 13:12:52 2012 +0000 @@ -0,0 +1,16 @@ +package de.intevation.flys.importer; + + + +public class ImportLocationSystem { + + protected String name; + protected String description; + + + public ImportLocationSystem(String name, String description) { + this.name = name; + this.description = description; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 5ac1db5156be -r b57c95094b68 flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightSingleParser.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightSingleParser.java Wed Apr 11 13:09:46 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightSingleParser.java Wed Apr 11 13:12:52 2012 +0000 @@ -2,8 +2,17 @@ import java.io.File; +import java.math.BigDecimal; + +import java.text.NumberFormat; +import java.text.ParseException; + +import java.util.ArrayList; import java.util.List; -import java.util.ArrayList; +import java.util.Locale; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.io.IOException; import java.io.LineNumberReader; @@ -13,17 +22,57 @@ import org.apache.log4j.Logger; import de.intevation.flys.importer.ImportBedHeightSingle; +import de.intevation.flys.importer.ImportBedHeightSingleValue; +import de.intevation.flys.importer.ImportBedHeightType; +import de.intevation.flys.importer.ImportElevationModel; +import de.intevation.flys.importer.ImportLocationSystem; +import de.intevation.flys.importer.ImportRange; +import de.intevation.flys.importer.ImportUnit; public class BedHeightSingleParser { public static final String ENCODING = "ISO-8859-1"; + public static final Locale DEFAULT_LOCALE = Locale.GERMAN; + + public static final String START_META_CHAR = "#"; + public static final String SEPERATOR_CHAR = ";"; + + public static final Pattern META_YEAR = + Pattern.compile("^Jahr: (\\d*).*"); + + public static final Pattern META_TYPE = + Pattern.compile("^Aufnahmeart: (.*).*"); + + public static final Pattern META_LOCATION_SYSTEM = + Pattern.compile("^Lagesystem: (.*).*"); + + public static final Pattern META_CUR_ELEVATION_SYSTEM = + Pattern.compile("^H.hensystem:\\s(\\w++) (.* )??\\[(.*)\\].*"); + + public static final Pattern META_OLD_ELEVATION_SYSTEM = + Pattern.compile("^urspr.ngliches H.hensystem:\\s(\\w++) (.* )??\\[(.*)\\].*"); + + public static final Pattern META_SOUNDING_WIDTH = + Pattern.compile("^ausgewertete Peilbreite: (\\d*).*"); + + public static final Pattern META_RANGE = + Pattern.compile("^Strecke:\\D*(\\d++.\\d*)-(\\d++.\\d*).*"); + + public static final Pattern META_EVALUATION_BY = + Pattern.compile("^Auswerter: (.*).*"); + + public static final Pattern META_COMMENTS = + Pattern.compile("^Weitere Bemerkungen: (.*).*"); private static final Logger log = Logger.getLogger(BedHeightSingleParser.class); + protected static NumberFormat nf = NumberFormat.getInstance(DEFAULT_LOCALE); + + protected List bedHeights; @@ -40,6 +89,8 @@ public void parse(File file) throws IOException { log.info("Parsing bed height single file '" + file + "'"); + ImportBedHeightSingle obj = new ImportBedHeightSingle(file.getName()); + LineNumberReader in = null; try { in = @@ -52,6 +103,13 @@ if ((line = line.trim()).length() == 0) { continue; } + + if (line.startsWith(START_META_CHAR)) { + handleMetaLine(obj, line); + } + else { + handleDataLine(obj, line); + } } } finally { @@ -60,5 +118,260 @@ } } } + + + protected void handleMetaLine(ImportBedHeightSingle obj, String line) { + String meta = stripMetaLine(line); + + if (handleMetaYear(obj, meta)) { + return; + } + else if (handleMetaSoundingWidth(obj, meta)) { + return; + } + else if (handleMetaComment(obj, meta)) { + return; + } + else if (handleMetaEvaluationBy(obj, meta)) { + return; + } + else if (handleMetaRange(obj, meta)) { + return; + } + else if (handleMetaType(obj, meta)) { + return; + } + else if (handleMetaLocationSystem(obj, meta)) { + return; + } + else if (handleMetaCurElevationModel(obj, meta)) { + return; + } + else if (handleMetaOldElevationModel(obj, meta)) { + return; + } + else { + log.warn("Meta line did not match any known type: " + line); + } + } + + + protected boolean handleMetaYear(ImportBedHeightSingle obj, String line) { + Matcher m = META_YEAR.matcher(line); + + if (m.matches()) { + String tmp = m.group(1); + + try { + obj.setYear(Integer.valueOf(tmp)); + return true; + } + catch (NumberFormatException e) { + log.warn("Error while parsing year!", e); + } + } + + return false; + } + + + protected boolean handleMetaSoundingWidth(ImportBedHeightSingle obj, String line) { + Matcher m = META_SOUNDING_WIDTH.matcher(line); + + if (m.matches()) { + String tmp = m.group(1); + + try { + obj.setSoundingWidth(Integer.valueOf(tmp)); + return true; + } + catch (NumberFormatException e) { + log.warn("Error while parsing sounding width!", e); + } + } + + return false; + } + + + protected boolean handleMetaComment(ImportBedHeightSingle obj, String line) { + Matcher m = META_COMMENTS.matcher(line); + + if (m.matches()) { + String tmp = m.group(1); + + obj.setDescription(tmp); + + return true; + } + + return false; + } + + + protected boolean handleMetaEvaluationBy( + ImportBedHeightSingle obj, + String line + ) { + Matcher m = META_EVALUATION_BY.matcher(line); + + if (m.matches()) { + String tmp = m.group(1); + tmp = tmp.replace(";", ""); + + obj.setEvaluationBy(tmp); + + return true; + } + + return false; + } + + + protected boolean handleMetaRange(ImportBedHeightSingle obj, String line) { + Matcher m = META_RANGE.matcher(line); + + if (m.matches() && m.groupCount() >= 2) { + String a = m.group(1).replace(";", ""); + String b = m.group(2).replace(";", ""); + + try { + BigDecimal lower = new BigDecimal(nf.parse(a).doubleValue()); + BigDecimal upper = new BigDecimal(nf.parse(b).doubleValue()); + + obj.setRange(new ImportRange(lower, upper)); + + return true; + } + catch (ParseException e) { + log.warn("Error while parsing range!", e); + } + } + + return false; + } + + + protected boolean handleMetaType(ImportBedHeightSingle obj, String line) { + Matcher m = META_TYPE.matcher(line); + + if (m.matches()) { + String tmp = m.group(1).replace(";", ""); + + obj.setType(new ImportBedHeightType( + ImportBedHeightType.getBedHeightName(tmp), + tmp)); + + return true; + } + + return false; + } + + + protected boolean handleMetaLocationSystem( + ImportBedHeightSingle obj, + String line + ) { + Matcher m = META_LOCATION_SYSTEM.matcher(line); + + if (m.matches()) { + String tmp = m.group(1).replace(";", ""); + + obj.setLocationSystem(new ImportLocationSystem(tmp, tmp)); + + return true; + } + + return false; + } + + + protected boolean handleMetaCurElevationModel( + ImportBedHeightSingle obj, + String line + ) { + Matcher m = META_CUR_ELEVATION_SYSTEM.matcher(line); + + if (m.matches()) { + String name = m.group(1); + String num = m.group(2); + String unit = m.group(3); + + obj.setCurElevationModel(new ImportElevationModel( + name + " " + num, + new ImportUnit(unit) + )); + + return true; + } + + return false; + } + + + protected boolean handleMetaOldElevationModel( + ImportBedHeightSingle obj, + String line + ) { + Matcher m = META_OLD_ELEVATION_SYSTEM.matcher(line); + + if (m.matches()) { + String name = m.group(1); + String num = m.group(2); + String unit = m.group(3); + + obj.setOldElevationModel(new ImportElevationModel( + name + " " + num, + new ImportUnit(unit) + )); + + return true; + } + + return false; + } + + + protected void handleDataLine(ImportBedHeightSingle obj, String line) { + log.debug("Handle data line: '" + line + "'"); + + String[] values = line.split(SEPERATOR_CHAR); + + if (values == null || values.length < 6) { + log.warn("Error while parsing data line: '" + line + "'"); + return; + } + + + try { + ImportBedHeightSingleValue value = new ImportBedHeightSingleValue( + obj, + new BigDecimal(nf.parse(values[0]).doubleValue()), + new BigDecimal(nf.parse(values[1]).doubleValue()), + new BigDecimal(nf.parse(values[2]).doubleValue()), + new BigDecimal(nf.parse(values[3]).doubleValue()), + new BigDecimal(nf.parse(values[4]).doubleValue()), + new BigDecimal(nf.parse(values[5]).doubleValue()) + ); + + obj.addValue(value); + } + catch (ParseException e) { + log.warn("Error while parsing data row.", e); + } + } + + + protected static String stripMetaLine(String line) { + String tmp = line.substring(1, line.length()-1); + + if (tmp.startsWith(" ")) { + return tmp.substring(1, tmp.length()-1); + } + else { + return tmp; + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :