Mercurial > dive4elements > river
changeset 8025:c915e99d9e52
Renamed SedimentYield to SedimentLoadLS and SedimentYieldValue to SedimentLoadLSValue. Adjust the names of the parsers and the rest of the glue.
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/backend/FLYSCredentials.java Wed Jul 09 17:33:57 2014 +0200 +++ b/backend/src/main/java/org/dive4elements/river/backend/FLYSCredentials.java Wed Jul 09 18:13:13 2014 +0200 @@ -75,8 +75,8 @@ import org.dive4elements.river.model.SobekKind; import org.dive4elements.river.model.SedimentDensity; import org.dive4elements.river.model.SedimentDensityValue; -import org.dive4elements.river.model.SedimentYield; -import org.dive4elements.river.model.SedimentYieldValue; +import org.dive4elements.river.model.SedimentLoadLS; +import org.dive4elements.river.model.SedimentLoadLSValue; import org.dive4elements.river.model.TimeInterval; import org.dive4elements.river.model.Unit; import org.dive4elements.river.model.Wst; @@ -196,8 +196,8 @@ SobekKind.class, SedimentDensity.class, SedimentDensityValue.class, - SedimentYield.class, - SedimentYieldValue.class, + SedimentLoadLS.class, + SedimentLoadLSValue.class, SQRelation.class, SQRelationValue.class, TimeInterval.class,
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java Wed Jul 09 17:33:57 2014 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java Wed Jul 09 18:13:13 2014 +0200 @@ -29,7 +29,7 @@ import org.dive4elements.river.importer.parsers.PorosityParser; import org.dive4elements.river.importer.parsers.SQRelationParser; import org.dive4elements.river.importer.parsers.SedimentDensityParser; -import org.dive4elements.river.importer.parsers.SedimentYieldParser; +import org.dive4elements.river.importer.parsers.SedimentLoadLSParser; import org.dive4elements.river.importer.parsers.W80Parser; import org.dive4elements.river.importer.parsers.W80CSVParser; import org.dive4elements.river.importer.parsers.WaterlevelDifferencesParser; @@ -595,7 +595,7 @@ private void parseSedimentYieldDir( File[] files, - SedimentYieldParser parser + SedimentLoadLSParser parser ) throws IOException { for (File file: files) { if (file.isDirectory()) { @@ -628,7 +628,7 @@ File[] epochs = epochDir.listFiles(); File[] offEpochs = offEpochDir.listFiles(); - SedimentYieldParser parser = new SedimentYieldParser(); + SedimentLoadLSParser parser = new SedimentLoadLSParser(); if (singles == null || singles.length == 0) { log.warn("Cannot read directory '" + singleDir + "'");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadLSValue.java Wed Jul 09 18:13:13 2014 +0200 @@ -0,0 +1,66 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.importer; + +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.Query; + +import org.dive4elements.river.model.SedimentLoadLS; +import org.dive4elements.river.model.SedimentLoadLSValue; + + +public class ImportSedimentLoadLSValue { + + private Double station; + private Double value; + + private SedimentLoadLSValue peer; + + + public ImportSedimentLoadLSValue(Double station, Double value) { + this.station = station; + this.value = value; + } + + + public void storeDependencies(SedimentLoadLS sedimentYield) { + getPeer(sedimentYield); + } + + + public SedimentLoadLSValue getPeer(SedimentLoadLS sedimentYield) { + if (peer == null) { + Session session = ImporterSession.getInstance().getDatabaseSession(); + Query query = session.createQuery( + "from SedimentYieldValue where " + + " sedimentYield=:sedimentYield and " + + " station=:station and " + + " value=:value" + ); + + query.setParameter("sedimentYield", sedimentYield); + query.setParameter("station", station); + query.setParameter("value", value); + + List<SedimentLoadLSValue> values = query.list(); + if (values.isEmpty()) { + peer = new SedimentLoadLSValue(sedimentYield, station, value); + session.save(peer); + } + else { + peer = values.get(0); + } + } + + return peer; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportSedimentYield.java Wed Jul 09 17:33:57 2014 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportSedimentYield.java Wed Jul 09 18:13:13 2014 +0200 @@ -18,7 +18,7 @@ import org.dive4elements.river.model.GrainFraction; import org.dive4elements.river.model.River; -import org.dive4elements.river.model.SedimentYield; +import org.dive4elements.river.model.SedimentLoadLS; import org.dive4elements.river.model.TimeInterval; import org.dive4elements.river.model.Unit; @@ -37,12 +37,12 @@ private Integer kind; - private List<ImportSedimentYieldValue> values; + private List<ImportSedimentLoadLSValue> values; - private SedimentYield peer; + private SedimentLoadLS peer; public ImportSedimentYield(String description) { - this.values = new ArrayList<ImportSedimentYieldValue>(); + this.values = new ArrayList<ImportSedimentLoadLSValue>(); this.description = description; } @@ -62,7 +62,7 @@ this.kind = kind; } - public void addValue(ImportSedimentYieldValue value) { + public void addValue(ImportSedimentLoadLSValue value) { this.values.add(value); } @@ -73,12 +73,12 @@ grainFraction.storeDependencies(); } - SedimentYield peer = getPeer(river); + SedimentLoadLS peer = getPeer(river); if (peer != null) { int i = 0; - for (ImportSedimentYieldValue value : values) { + for (ImportSedimentLoadLSValue value : values) { value.storeDependencies(peer); i++; } @@ -87,7 +87,7 @@ } } - public SedimentYield getPeer(River river) { + public SedimentLoadLS getPeer(River river) { log.debug("get peer"); GrainFraction gf = grainFraction != null ? grainFraction.getPeer() @@ -117,11 +117,11 @@ query.setParameter("timeInterval", ti); query.setParameter("description", description); - List<SedimentYield> yields = query.list(); + List<SedimentLoadLS> yields = query.list(); if (yields.isEmpty()) { log.debug("create new SedimentYield"); - peer = new SedimentYield(river, u, ti, gf, description); + peer = new SedimentLoadLS(river, u, ti, gf, description); peer.setKind(this.kind); session.save(peer); }
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportSedimentYieldValue.java Wed Jul 09 17:33:57 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU AGPL (>=v3) - * and comes with ABSOLUTELY NO WARRANTY! Check out the - * documentation coming with Dive4Elements River for details. - */ - -package org.dive4elements.river.importer; - -import java.util.List; - -import org.hibernate.Session; -import org.hibernate.Query; - -import org.dive4elements.river.model.SedimentYield; -import org.dive4elements.river.model.SedimentYieldValue; - - -public class ImportSedimentYieldValue { - - private Double station; - private Double value; - - private SedimentYieldValue peer; - - - public ImportSedimentYieldValue(Double station, Double value) { - this.station = station; - this.value = value; - } - - - public void storeDependencies(SedimentYield sedimentYield) { - getPeer(sedimentYield); - } - - - public SedimentYieldValue getPeer(SedimentYield sedimentYield) { - if (peer == null) { - Session session = ImporterSession.getInstance().getDatabaseSession(); - Query query = session.createQuery( - "from SedimentYieldValue where " + - " sedimentYield=:sedimentYield and " + - " station=:station and " + - " value=:value" - ); - - query.setParameter("sedimentYield", sedimentYield); - query.setParameter("station", station); - query.setParameter("value", value); - - List<SedimentYieldValue> values = query.list(); - if (values.isEmpty()) { - peer = new SedimentYieldValue(sedimentYield, station, value); - session.save(peer); - } - else { - peer = values.get(0); - } - } - - return peer; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentLoadLSParser.java Wed Jul 09 18:13:13 2014 +0200 @@ -0,0 +1,414 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.importer.parsers; + +import java.io.File; +import java.io.IOException; + +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 org.apache.log4j.Logger; + +import org.dive4elements.river.importer.ImportGrainFraction; +import org.dive4elements.river.importer.ImportSedimentYield; +import org.dive4elements.river.importer.ImportSedimentLoadLSValue; +import org.dive4elements.river.importer.ImportTimeInterval; +import org.dive4elements.river.importer.ImportUnit; +import org.dive4elements.river.model.GrainFraction; +import org.dive4elements.river.utils.DateUtil; + + +/** Parses Sediment Yield files. */ +public class SedimentLoadLSParser extends LineParser { + + private static final Logger log = + Logger.getLogger(SedimentLoadLSParser.class); + + + public static final NumberFormat nf = NumberFormat.getInstance(DEFAULT_LOCALE); + + + public static final String FRAKTION_START = "Fraktion:"; + + public static final String FRACTION_COARSE_STR = + ".*Grobkorn.*"; + + public static final String FRACTION_FINE_MIDDLE_STR = + ".*Fein.Mittel.Kies.*"; + + public static final String FRACTION_SAND = + ".*Sand.*"; + + public static final String FRACTION_SUSP_SAND = + ".*susp.Sand.*"; + + public static final String FRACTION_SUSP_SAND_BED = + ".*bettbild.Anteil.susp.Sand.*"; + + public static final String FRACTION_SUSP_SAND_BED_EPOCH = + ".*susp.Sand.bettbildAnteil.*"; + + public static final String FRACTION_SUSPENDED_SEDIMENT = + ".*Schwebstoff.*"; + + public static final String FRACTION_TOTAL = + ".*gesamt.*"; + + + public static final Pattern TIMEINTERVAL_SINGLE = + Pattern.compile("\\D*([0-9]+?)\\D*"); + + public static final Pattern TIMEINTERVAL_EPOCH = + Pattern.compile("\\D*([0-9]+?)\\s*-\\s*([0-9]+?)\\D*"); + + public static final Pattern META_FRACTION = + Pattern.compile("^Fraktion: (.*)"); + + public static final Pattern META_UNIT = + Pattern.compile("^Einheit: \\[(.*)\\].*"); + + public static final Pattern META_COLUMN_NAMES = + Pattern.compile("^Fluss-km.*"); + + public static final Pattern META_GRAIN_FRACTION_A = + Pattern.compile("\\D*(([0-9]+?,[0-9]+?)\\s*-|([0-9]++)\\s*-)(([0-9]+?,[0-9]+?)|([0-9]++))\\s*([a-zA-Z]+?)\\W*\\D*"); + + public static final Pattern META_GRAIN_FRACTION_B = + Pattern.compile("(<|>){1}\\s*(\\w++)\\s*(([0-9]+?,[0-9]+?)\\s*-|([0-9]++)\\s*-)(([0-9]+?,[0-9]+?)|([0-9]++))\\s*([a-zA-Z]+?)"); + + public static final Pattern META_GRAIN_FRACTION_C = + Pattern.compile("(<|>){1}\\s*((([0-9]+?,[0-9]+?)|([0-9]++))\\s*(\\w+))"); + + + protected List<ImportSedimentYield> sedimentYields; + + protected ImportSedimentYield[] current; + + protected ImportGrainFraction grainFraction; + + protected ImportUnit unit; + + protected String description; + + protected String[] columnNames; + + + public SedimentLoadLSParser() { + sedimentYields = new ArrayList<ImportSedimentYield>(); + } + + + @Override + public void parse(File file) throws IOException { + description = file.getName(); + + super.parse(file); + } + + + @Override + protected void reset() { + current = null; + grainFraction = null; + unit = null; + } + + + @Override + protected void finish() { + if (current != null) { + for (ImportSedimentYield isy: current) { + sedimentYields.add(isy); + } + } + + description = null; + } + + + @Override + protected void handleLine(int lineNum, String line) { + if (line.startsWith(START_META_CHAR)) { + handleMetaLine(stripMetaLine(line)); + } + else { + handleDataLine(line); + } + } + + + protected void handleMetaLine(String line) { + if (handleMetaUnit(line)) { + return; + } + else if (handleMetaFraction(line)) { + return; + } + else if (handleColumnNames(line)) { + return; + } + else { + log.warn("SYP: Unknown meta line: '" + line + "'"); + } + } + + + protected boolean handleMetaUnit(String line) { + Matcher m = META_UNIT.matcher(line); + + if (m.matches()) { + unit = new ImportUnit(m.group(1)); + return true; + } + + return false; + } + + + public boolean handleMetaFraction(String line) { + Matcher m = META_FRACTION.matcher(line); + + if (m.matches()) { + String tmp = m.group(1); + + this.grainFraction = buildGrainFraction(tmp); + + return true; + } + else if (line.startsWith(FRAKTION_START)) { + String newLine = line.replace(FRAKTION_START, "").trim(); + if (newLine.length() == 0) { + log.debug("Found total grain fraction."); + this.grainFraction = new ImportGrainFraction(GrainFraction.UNKNOWN); + + return true; + } + } + + return false; + } + + + public boolean handleColumnNames(String line) { + Matcher m = META_COLUMN_NAMES.matcher(line); + + if (m.matches()) { + columnNames = line.split(SEPERATOR_CHAR); + + initializeSedimentYields(); + + return true; + } + + return false; + } + + + protected void handleDataLine(String line) { + String[] vals = line.split(SEPERATOR_CHAR); + + if (vals == null || vals.length < columnNames.length-1) { + log.warn("SYP: skip invalid data line: '" + line + "'"); + return; + } + + try { + Double km = nf.parse(vals[0]).doubleValue(); + + for (int i = 1, n = columnNames.length-1; i < n; i++) { + String curVal = vals[i]; + + if (curVal != null && curVal.length() > 0) { + current[i-1].addValue(new ImportSedimentLoadLSValue( + km, nf.parse(vals[i]).doubleValue() + )); + } + } + } + catch (ParseException pe) { + log.warn("SYP: unparseable number in data row '" + line + "':", pe); + } + } + + + /** Initialize SedimentYields from columns, set the kind + * with respect to file location (offical epoch or not?) */ + private void initializeSedimentYields() { + // skip first column (Fluss-km) and last column (Hinweise) + current = new ImportSedimentYield[columnNames.length-2]; + + Integer kind; + + if (inputFile.getAbsolutePath().contains("amtliche Epochen")) { + kind = new Integer(1); + } + else { + kind = new Integer(0); + } + + for (int i = 0, n = columnNames.length; i < n-2; i++) { + current[i] = new ImportSedimentYield(this.description); + current[i].setTimeInterval(getTimeInterval(columnNames[i+1])); + current[i].setUnit(unit); + current[i].setGrainFraction(grainFraction); + current[i].setKind(kind); + } + } + + + private ImportTimeInterval getTimeInterval(String column) { + try { + Matcher a = TIMEINTERVAL_EPOCH.matcher(column); + if (a.matches()) { + int yearA = nf.parse(a.group(1)).intValue(); + int yearB = nf.parse(a.group(2)).intValue(); + + return new ImportTimeInterval( + DateUtil.getStartDateFromYear(yearA), + DateUtil.getEndDateFromYear(yearB) + ); + } + + Matcher b = TIMEINTERVAL_SINGLE.matcher(column); + if (b.matches()) { + int year = nf.parse(b.group(1)).intValue(); + + return new ImportTimeInterval(DateUtil.getStartDateFromYear(year)); + } + + log.warn("SYP: Unknown time interval string: '" + column + "'"); + } + catch (ParseException pe) { + log.warn("SYP: Could not parse years: " + column, pe); + } + + return null; + } + + + private ImportGrainFraction buildGrainFraction(String gfStr) { + Matcher a = META_GRAIN_FRACTION_A.matcher(gfStr); + if (a.matches()) { + String lowerA = a.group(2); + String lowerB = a.group(3); + + String upperA = a.group(4); + String upperB = a.group(5); + + String lower = lowerA != null ? lowerA : lowerB; + String upper = upperA != null ? upperA : upperB; + + try { + return new ImportGrainFraction( + getGrainFractionTypeName(this.description), + nf.parse(lower).doubleValue(), + nf.parse(upper).doubleValue() + ); + } + catch (ParseException pe) { + log.warn("SYP: Could not parse ranges of: '" + gfStr + "'"); + } + } + + Matcher b = META_GRAIN_FRACTION_B.matcher(gfStr); + if (b.matches()) { + String lowerA = b.group(4); + String lowerB = b.group(5); + String upperA = b.group(6); + String upperB = b.group(7); + + String lower = lowerA != null ? lowerA : lowerB; + String upper = upperA != null ? upperA : upperB; + + try { + return new ImportGrainFraction( + getGrainFractionTypeName(this.description), + nf.parse(lower).doubleValue(), + nf.parse(upper).doubleValue() + ); + } + catch (ParseException pe) { + log.warn("SYP: Could not parse ranges of: '" + gfStr + "'"); + } + } + + Matcher c = META_GRAIN_FRACTION_C.matcher(gfStr); + if (c.matches()) { + String oper = c.group(1); + String valueStr = c.group(3); + + try { + Double value = nf.parse(valueStr).doubleValue(); + + if (oper.equals(">")) { + return new ImportGrainFraction( + getGrainFractionTypeName(this.description), + value, + null + ); + } + else { + return new ImportGrainFraction( + getGrainFractionTypeName(this.description), + null, + value + ); + } + } + catch (ParseException pe) { + log.warn("SYP: Could not parse ranges of: '" + gfStr + "'"); + } + } + + log.warn("SYP: Unknown grain fraction: '" + gfStr + "'"); + return new ImportGrainFraction(GrainFraction.UNKNOWN); + } + + + public static String getGrainFractionTypeName(String filename) { + if (Pattern.matches(FRACTION_COARSE_STR, filename)) { + return GrainFraction.COARSE; + } + else if (Pattern.matches(FRACTION_FINE_MIDDLE_STR, filename)) { + return GrainFraction.FINE_MIDDLE; + } + else if (Pattern.matches(FRACTION_SUSP_SAND_BED, filename) || + Pattern.matches(FRACTION_SUSP_SAND_BED_EPOCH, filename)) { + return GrainFraction.SUSP_SAND_BED; + } + else if (Pattern.matches(FRACTION_SUSP_SAND, filename)) { + return GrainFraction.SUSP_SAND; + } + else if (Pattern.matches(FRACTION_SAND, filename)) { + return GrainFraction.SAND; + } + else if (Pattern.matches(FRACTION_SUSPENDED_SEDIMENT, filename)) { + return GrainFraction.SUSPENDED_SEDIMENT; + } + else if (Pattern.matches(FRACTION_TOTAL, filename)) { + return GrainFraction.TOTAL; + } + else { + log.warn("SYP: Unknown grain fraction '" + filename + "'"); + return GrainFraction.UNKNOWN; + } + } + + + public List<ImportSedimentYield> getSedimentYields() { + return sedimentYields; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentYieldParser.java Wed Jul 09 17:33:57 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,414 +0,0 @@ -/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU AGPL (>=v3) - * and comes with ABSOLUTELY NO WARRANTY! Check out the - * documentation coming with Dive4Elements River for details. - */ - -package org.dive4elements.river.importer.parsers; - -import java.io.File; -import java.io.IOException; - -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 org.apache.log4j.Logger; - -import org.dive4elements.river.importer.ImportGrainFraction; -import org.dive4elements.river.importer.ImportSedimentYield; -import org.dive4elements.river.importer.ImportSedimentYieldValue; -import org.dive4elements.river.importer.ImportTimeInterval; -import org.dive4elements.river.importer.ImportUnit; -import org.dive4elements.river.model.GrainFraction; -import org.dive4elements.river.utils.DateUtil; - - -/** Parses Sediment Yield files. */ -public class SedimentYieldParser extends LineParser { - - private static final Logger log = - Logger.getLogger(SedimentYieldParser.class); - - - public static final NumberFormat nf = NumberFormat.getInstance(DEFAULT_LOCALE); - - - public static final String FRAKTION_START = "Fraktion:"; - - public static final String FRACTION_COARSE_STR = - ".*Grobkorn.*"; - - public static final String FRACTION_FINE_MIDDLE_STR = - ".*Fein.Mittel.Kies.*"; - - public static final String FRACTION_SAND = - ".*Sand.*"; - - public static final String FRACTION_SUSP_SAND = - ".*susp.Sand.*"; - - public static final String FRACTION_SUSP_SAND_BED = - ".*bettbild.Anteil.susp.Sand.*"; - - public static final String FRACTION_SUSP_SAND_BED_EPOCH = - ".*susp.Sand.bettbildAnteil.*"; - - public static final String FRACTION_SUSPENDED_SEDIMENT = - ".*Schwebstoff.*"; - - public static final String FRACTION_TOTAL = - ".*gesamt.*"; - - - public static final Pattern TIMEINTERVAL_SINGLE = - Pattern.compile("\\D*([0-9]+?)\\D*"); - - public static final Pattern TIMEINTERVAL_EPOCH = - Pattern.compile("\\D*([0-9]+?)\\s*-\\s*([0-9]+?)\\D*"); - - public static final Pattern META_FRACTION = - Pattern.compile("^Fraktion: (.*)"); - - public static final Pattern META_UNIT = - Pattern.compile("^Einheit: \\[(.*)\\].*"); - - public static final Pattern META_COLUMN_NAMES = - Pattern.compile("^Fluss-km.*"); - - public static final Pattern META_GRAIN_FRACTION_A = - Pattern.compile("\\D*(([0-9]+?,[0-9]+?)\\s*-|([0-9]++)\\s*-)(([0-9]+?,[0-9]+?)|([0-9]++))\\s*([a-zA-Z]+?)\\W*\\D*"); - - public static final Pattern META_GRAIN_FRACTION_B = - Pattern.compile("(<|>){1}\\s*(\\w++)\\s*(([0-9]+?,[0-9]+?)\\s*-|([0-9]++)\\s*-)(([0-9]+?,[0-9]+?)|([0-9]++))\\s*([a-zA-Z]+?)"); - - public static final Pattern META_GRAIN_FRACTION_C = - Pattern.compile("(<|>){1}\\s*((([0-9]+?,[0-9]+?)|([0-9]++))\\s*(\\w+))"); - - - protected List<ImportSedimentYield> sedimentYields; - - protected ImportSedimentYield[] current; - - protected ImportGrainFraction grainFraction; - - protected ImportUnit unit; - - protected String description; - - protected String[] columnNames; - - - public SedimentYieldParser() { - sedimentYields = new ArrayList<ImportSedimentYield>(); - } - - - @Override - public void parse(File file) throws IOException { - description = file.getName(); - - super.parse(file); - } - - - @Override - protected void reset() { - current = null; - grainFraction = null; - unit = null; - } - - - @Override - protected void finish() { - if (current != null) { - for (ImportSedimentYield isy: current) { - sedimentYields.add(isy); - } - } - - description = null; - } - - - @Override - protected void handleLine(int lineNum, String line) { - if (line.startsWith(START_META_CHAR)) { - handleMetaLine(stripMetaLine(line)); - } - else { - handleDataLine(line); - } - } - - - protected void handleMetaLine(String line) { - if (handleMetaUnit(line)) { - return; - } - else if (handleMetaFraction(line)) { - return; - } - else if (handleColumnNames(line)) { - return; - } - else { - log.warn("SYP: Unknown meta line: '" + line + "'"); - } - } - - - protected boolean handleMetaUnit(String line) { - Matcher m = META_UNIT.matcher(line); - - if (m.matches()) { - unit = new ImportUnit(m.group(1)); - return true; - } - - return false; - } - - - public boolean handleMetaFraction(String line) { - Matcher m = META_FRACTION.matcher(line); - - if (m.matches()) { - String tmp = m.group(1); - - this.grainFraction = buildGrainFraction(tmp); - - return true; - } - else if (line.startsWith(FRAKTION_START)) { - String newLine = line.replace(FRAKTION_START, "").trim(); - if (newLine.length() == 0) { - log.debug("Found total grain fraction."); - this.grainFraction = new ImportGrainFraction(GrainFraction.UNKNOWN); - - return true; - } - } - - return false; - } - - - public boolean handleColumnNames(String line) { - Matcher m = META_COLUMN_NAMES.matcher(line); - - if (m.matches()) { - columnNames = line.split(SEPERATOR_CHAR); - - initializeSedimentYields(); - - return true; - } - - return false; - } - - - protected void handleDataLine(String line) { - String[] vals = line.split(SEPERATOR_CHAR); - - if (vals == null || vals.length < columnNames.length-1) { - log.warn("SYP: skip invalid data line: '" + line + "'"); - return; - } - - try { - Double km = nf.parse(vals[0]).doubleValue(); - - for (int i = 1, n = columnNames.length-1; i < n; i++) { - String curVal = vals[i]; - - if (curVal != null && curVal.length() > 0) { - current[i-1].addValue(new ImportSedimentYieldValue( - km, nf.parse(vals[i]).doubleValue() - )); - } - } - } - catch (ParseException pe) { - log.warn("SYP: unparseable number in data row '" + line + "':", pe); - } - } - - - /** Initialize SedimentYields from columns, set the kind - * with respect to file location (offical epoch or not?) */ - private void initializeSedimentYields() { - // skip first column (Fluss-km) and last column (Hinweise) - current = new ImportSedimentYield[columnNames.length-2]; - - Integer kind; - - if (inputFile.getAbsolutePath().contains("amtliche Epochen")) { - kind = new Integer(1); - } - else { - kind = new Integer(0); - } - - for (int i = 0, n = columnNames.length; i < n-2; i++) { - current[i] = new ImportSedimentYield(this.description); - current[i].setTimeInterval(getTimeInterval(columnNames[i+1])); - current[i].setUnit(unit); - current[i].setGrainFraction(grainFraction); - current[i].setKind(kind); - } - } - - - private ImportTimeInterval getTimeInterval(String column) { - try { - Matcher a = TIMEINTERVAL_EPOCH.matcher(column); - if (a.matches()) { - int yearA = nf.parse(a.group(1)).intValue(); - int yearB = nf.parse(a.group(2)).intValue(); - - return new ImportTimeInterval( - DateUtil.getStartDateFromYear(yearA), - DateUtil.getEndDateFromYear(yearB) - ); - } - - Matcher b = TIMEINTERVAL_SINGLE.matcher(column); - if (b.matches()) { - int year = nf.parse(b.group(1)).intValue(); - - return new ImportTimeInterval(DateUtil.getStartDateFromYear(year)); - } - - log.warn("SYP: Unknown time interval string: '" + column + "'"); - } - catch (ParseException pe) { - log.warn("SYP: Could not parse years: " + column, pe); - } - - return null; - } - - - private ImportGrainFraction buildGrainFraction(String gfStr) { - Matcher a = META_GRAIN_FRACTION_A.matcher(gfStr); - if (a.matches()) { - String lowerA = a.group(2); - String lowerB = a.group(3); - - String upperA = a.group(4); - String upperB = a.group(5); - - String lower = lowerA != null ? lowerA : lowerB; - String upper = upperA != null ? upperA : upperB; - - try { - return new ImportGrainFraction( - getGrainFractionTypeName(this.description), - nf.parse(lower).doubleValue(), - nf.parse(upper).doubleValue() - ); - } - catch (ParseException pe) { - log.warn("SYP: Could not parse ranges of: '" + gfStr + "'"); - } - } - - Matcher b = META_GRAIN_FRACTION_B.matcher(gfStr); - if (b.matches()) { - String lowerA = b.group(4); - String lowerB = b.group(5); - String upperA = b.group(6); - String upperB = b.group(7); - - String lower = lowerA != null ? lowerA : lowerB; - String upper = upperA != null ? upperA : upperB; - - try { - return new ImportGrainFraction( - getGrainFractionTypeName(this.description), - nf.parse(lower).doubleValue(), - nf.parse(upper).doubleValue() - ); - } - catch (ParseException pe) { - log.warn("SYP: Could not parse ranges of: '" + gfStr + "'"); - } - } - - Matcher c = META_GRAIN_FRACTION_C.matcher(gfStr); - if (c.matches()) { - String oper = c.group(1); - String valueStr = c.group(3); - - try { - Double value = nf.parse(valueStr).doubleValue(); - - if (oper.equals(">")) { - return new ImportGrainFraction( - getGrainFractionTypeName(this.description), - value, - null - ); - } - else { - return new ImportGrainFraction( - getGrainFractionTypeName(this.description), - null, - value - ); - } - } - catch (ParseException pe) { - log.warn("SYP: Could not parse ranges of: '" + gfStr + "'"); - } - } - - log.warn("SYP: Unknown grain fraction: '" + gfStr + "'"); - return new ImportGrainFraction(GrainFraction.UNKNOWN); - } - - - public static String getGrainFractionTypeName(String filename) { - if (Pattern.matches(FRACTION_COARSE_STR, filename)) { - return GrainFraction.COARSE; - } - else if (Pattern.matches(FRACTION_FINE_MIDDLE_STR, filename)) { - return GrainFraction.FINE_MIDDLE; - } - else if (Pattern.matches(FRACTION_SUSP_SAND_BED, filename) || - Pattern.matches(FRACTION_SUSP_SAND_BED_EPOCH, filename)) { - return GrainFraction.SUSP_SAND_BED; - } - else if (Pattern.matches(FRACTION_SUSP_SAND, filename)) { - return GrainFraction.SUSP_SAND; - } - else if (Pattern.matches(FRACTION_SAND, filename)) { - return GrainFraction.SAND; - } - else if (Pattern.matches(FRACTION_SUSPENDED_SEDIMENT, filename)) { - return GrainFraction.SUSPENDED_SEDIMENT; - } - else if (Pattern.matches(FRACTION_TOTAL, filename)) { - return GrainFraction.TOTAL; - } - else { - log.warn("SYP: Unknown grain fraction '" + filename + "'"); - return GrainFraction.UNKNOWN; - } - } - - - public List<ImportSedimentYield> getSedimentYields() { - return sedimentYields; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backend/src/main/java/org/dive4elements/river/model/SedimentLoadLS.java Wed Jul 09 18:13:13 2014 +0200 @@ -0,0 +1,166 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.GeneratedValue; +import javax.persistence.Column; +import javax.persistence.SequenceGenerator; +import javax.persistence.GenerationType; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; + +import org.apache.log4j.Logger; + + +/** SedimentYield of a certain Fraction with possibly many values. */ +@Entity +@Table(name = "sediment_yield") +public class SedimentLoadLS +implements Serializable +{ + private static Logger logger = Logger.getLogger(SedimentLoadLS.class); + + private Integer id; + + private River river; + + private GrainFraction grainFraction; + + private Unit unit; + + private TimeInterval timeInterval; + + private String description; + + private List<SedimentLoadLSValue> values; + + private Integer kind; + + + public SedimentLoadLS() { + this.values = new ArrayList<SedimentLoadLSValue>(); + } + + public SedimentLoadLS(River river, Unit unit, TimeInterval timeInterval) { + this(); + + this.river = river; + this.unit = unit; + this.timeInterval = timeInterval; + } + + + public SedimentLoadLS( + River river, + Unit unit, + TimeInterval timeInterval, + GrainFraction grainFraction + ) { + this(river, unit, timeInterval); + + this.grainFraction = grainFraction; + } + + + public SedimentLoadLS( + River river, + Unit unit, + TimeInterval timeInterval, + GrainFraction grainFraction, + String description + ) { + this(river, unit, timeInterval, grainFraction); + + this.description = description; + } + + @Id + @SequenceGenerator( + name = "SEQUENCE_SEDIMENT_YIELD_ID_SEQ", + sequenceName = "SEDIMENT_YIELD_ID_SEQ", + allocationSize = 1) + @GeneratedValue( + strategy = GenerationType.SEQUENCE, + generator = "SEQUENCE_SEDIMENT_YIELD_ID_SEQ") + @Column(name = "id") + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + @OneToOne + @JoinColumn(name = "river_id") + public River getRiver() { + return river; + } + + public void setRiver(River river) { + this.river = river; + } + + @OneToOne + @JoinColumn(name="grain_fraction_id") + public GrainFraction getGrainFraction() { + return grainFraction; + } + + public void setGrainFraction(GrainFraction grainFraction) { + this.grainFraction = grainFraction; + } + + @OneToOne + @JoinColumn(name = "unit_id") + public Unit getUnit() { + return unit; + } + + public void setUnit(Unit unit) { + this.unit = unit; + } + + @OneToOne + @JoinColumn(name = "time_interval_id") + public TimeInterval getTimeInterval() { + return timeInterval; + } + + public void setTimeInterval(TimeInterval timeInterval) { + this.timeInterval = timeInterval; + } + + @Column(name = "description") + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + /** kind == 0: "normal", kind == 1: "official epoch". */ + @Column(name = "kind") + public Integer getKind() { + return kind; + } + + public void setKind(Integer newKind) { + this.kind = newKind; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backend/src/main/java/org/dive4elements/river/model/SedimentLoadLSValue.java Wed Jul 09 18:13:13 2014 +0200 @@ -0,0 +1,101 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.model; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.GeneratedValue; +import javax.persistence.Column; +import javax.persistence.SequenceGenerator; +import javax.persistence.GenerationType; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; + +import org.apache.log4j.Logger; + + +@Entity +@Table(name = "sediment_yield_values") +public class SedimentLoadLSValue +implements Serializable +{ + private static Logger logger = Logger.getLogger(SedimentLoadLSValue.class); + + private Integer id; + + private SedimentLoadLS sedimentYield; + + private Double station; + private Double value; + + private Unit unit; + + + public SedimentLoadLSValue() { + } + + public SedimentLoadLSValue( + SedimentLoadLS sedimentYield, + Double station, + Double value + ) { + this.sedimentYield = sedimentYield; + this.station = station; + this.value = value; + } + + @Id + @SequenceGenerator( + name = "SEQUENCE_SEDIMENT_YIELD_VALuES_ID_SEQ", + sequenceName = "SEDIMENT_YIELD_VALUES_ID_SEQ", + allocationSize = 1) + @GeneratedValue( + strategy = GenerationType.SEQUENCE, + generator = "SEQUENCE_SEDIMENT_YIELD_VALuES_ID_SEQ") + @Column(name = "id") + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + @OneToOne + @JoinColumn(name = "sediment_yield_id" ) + public SedimentLoadLS getSedimentYield() { + return sedimentYield; + } + + public void setSedimentYield(SedimentLoadLS sedimentYield) { + this.sedimentYield = sedimentYield; + } + + @Column(name="station") + public Double getStation() { + return station; + } + + public void setStation(Double station) { + this.station = station; + } + + @Column(name = "value") + public Double getValue() { + return value; + } + + public void setValue(Double value) { + this.value = value; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/backend/src/main/java/org/dive4elements/river/model/SedimentYield.java Wed Jul 09 17:33:57 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,166 +0,0 @@ -/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU AGPL (>=v3) - * and comes with ABSOLUTELY NO WARRANTY! Check out the - * documentation coming with Dive4Elements River for details. - */ - -package org.dive4elements.river.model; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.GeneratedValue; -import javax.persistence.Column; -import javax.persistence.SequenceGenerator; -import javax.persistence.GenerationType; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; - -import org.apache.log4j.Logger; - - -/** SedimentYield of a certain Fraction with possibly many values. */ -@Entity -@Table(name = "sediment_yield") -public class SedimentYield -implements Serializable -{ - private static Logger logger = Logger.getLogger(SedimentYield.class); - - private Integer id; - - private River river; - - private GrainFraction grainFraction; - - private Unit unit; - - private TimeInterval timeInterval; - - private String description; - - private List<SedimentYieldValue> values; - - private Integer kind; - - - public SedimentYield() { - this.values = new ArrayList<SedimentYieldValue>(); - } - - public SedimentYield(River river, Unit unit, TimeInterval timeInterval) { - this(); - - this.river = river; - this.unit = unit; - this.timeInterval = timeInterval; - } - - - public SedimentYield( - River river, - Unit unit, - TimeInterval timeInterval, - GrainFraction grainFraction - ) { - this(river, unit, timeInterval); - - this.grainFraction = grainFraction; - } - - - public SedimentYield( - River river, - Unit unit, - TimeInterval timeInterval, - GrainFraction grainFraction, - String description - ) { - this(river, unit, timeInterval, grainFraction); - - this.description = description; - } - - @Id - @SequenceGenerator( - name = "SEQUENCE_SEDIMENT_YIELD_ID_SEQ", - sequenceName = "SEDIMENT_YIELD_ID_SEQ", - allocationSize = 1) - @GeneratedValue( - strategy = GenerationType.SEQUENCE, - generator = "SEQUENCE_SEDIMENT_YIELD_ID_SEQ") - @Column(name = "id") - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - @OneToOne - @JoinColumn(name = "river_id") - public River getRiver() { - return river; - } - - public void setRiver(River river) { - this.river = river; - } - - @OneToOne - @JoinColumn(name="grain_fraction_id") - public GrainFraction getGrainFraction() { - return grainFraction; - } - - public void setGrainFraction(GrainFraction grainFraction) { - this.grainFraction = grainFraction; - } - - @OneToOne - @JoinColumn(name = "unit_id") - public Unit getUnit() { - return unit; - } - - public void setUnit(Unit unit) { - this.unit = unit; - } - - @OneToOne - @JoinColumn(name = "time_interval_id") - public TimeInterval getTimeInterval() { - return timeInterval; - } - - public void setTimeInterval(TimeInterval timeInterval) { - this.timeInterval = timeInterval; - } - - @Column(name = "description") - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - /** kind == 0: "normal", kind == 1: "official epoch". */ - @Column(name = "kind") - public Integer getKind() { - return kind; - } - - public void setKind(Integer newKind) { - this.kind = newKind; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/backend/src/main/java/org/dive4elements/river/model/SedimentYieldValue.java Wed Jul 09 17:33:57 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU AGPL (>=v3) - * and comes with ABSOLUTELY NO WARRANTY! Check out the - * documentation coming with Dive4Elements River for details. - */ - -package org.dive4elements.river.model; - -import java.io.Serializable; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.GeneratedValue; -import javax.persistence.Column; -import javax.persistence.SequenceGenerator; -import javax.persistence.GenerationType; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; - -import org.apache.log4j.Logger; - - -@Entity -@Table(name = "sediment_yield_values") -public class SedimentYieldValue -implements Serializable -{ - private static Logger logger = Logger.getLogger(SedimentYieldValue.class); - - private Integer id; - - private SedimentYield sedimentYield; - - private Double station; - private Double value; - - private Unit unit; - - - public SedimentYieldValue() { - } - - public SedimentYieldValue( - SedimentYield sedimentYield, - Double station, - Double value - ) { - this.sedimentYield = sedimentYield; - this.station = station; - this.value = value; - } - - @Id - @SequenceGenerator( - name = "SEQUENCE_SEDIMENT_YIELD_VALuES_ID_SEQ", - sequenceName = "SEDIMENT_YIELD_VALUES_ID_SEQ", - allocationSize = 1) - @GeneratedValue( - strategy = GenerationType.SEQUENCE, - generator = "SEQUENCE_SEDIMENT_YIELD_VALuES_ID_SEQ") - @Column(name = "id") - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - @OneToOne - @JoinColumn(name = "sediment_yield_id" ) - public SedimentYield getSedimentYield() { - return sedimentYield; - } - - public void setSedimentYield(SedimentYield sedimentYield) { - this.sedimentYield = sedimentYield; - } - - @Column(name="station") - public Double getStation() { - return station; - } - - public void setStation(Double station) { - this.station = station; - } - - @Column(name = "value") - public Double getValue() { - return value; - } - - public void setValue(Double value) { - this.value = value; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :