Mercurial > dive4elements > river
changeset 3434:1a636be7612b
FixA: Moved more common calculation code into base class.
flys-artifacts/trunk@5097 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 22 Jul 2012 09:49:56 +0000 |
parents | c3fb41e73ffb |
children | 262e7d7e58fe |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java |
diffstat | 3 files changed, 139 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Sat Jul 21 17:59:13 2012 +0000 +++ b/flys-artifacts/ChangeLog Sun Jul 22 09:49:56 2012 +0000 @@ -1,3 +1,9 @@ +2012-07-22 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java, + src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisCalculation.java: + Moved more common code into base class. + 2012-07-21 Sascha L. Teichmann <sascha.teichmann@intevation.de> * contrib/fixoverview2html.xsl: Clip the displayed from/to ranges
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisCalculation.java Sat Jul 21 17:59:13 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisCalculation.java Sun Jul 22 09:49:56 2012 +0000 @@ -34,9 +34,7 @@ import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; @@ -109,8 +107,6 @@ return new CalculationResult(this); } - double [] kms = DoubleUtil.explode(from, to, step / 1000.0); - final double [] qs = new double[eventColumns.size()]; final double [] ws = new double[qs.length]; final boolean [] interpolated = new boolean[ws.length]; @@ -147,6 +143,8 @@ boolean invalid = false; + double [] kms = DoubleUtil.explode(from, to, step / 1000.0); + if (debug) { log.debug("number of kms: " + kms.length); } @@ -223,44 +221,15 @@ return new CalculationResult(fr, this); } - protected String toString(String [] parameterNames, double [] values) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < parameterNames.length; ++i) { - if (i > 0) sb.append(", "); - sb.append(parameterNames[i]).append(": ").append(values[i]); - } - return sb.toString(); - } - - protected List<Column> getEventColumns(FixingsOverview overview) { - - FixingsColumnFactory fcf = FixingsColumnFactory.getInstance(); - - IdsFilter ids = new IdsFilter(events); + @Override + protected Filter createFilter() { + Filter ids = super.createFilter(); DateRangeFilter rdf = new DateRangeFilter( referencePeriod.getFrom(), referencePeriod.getTo()); - Filter filter = new AndFilter().add(rdf).add(ids); - - List<Fixing.Column> metas = overview.filter(null, filter); - - List<Column> columns = new ArrayList<Column>(metas.size()); - - for (Fixing.Column meta: metas) { - - FixingsColumn data = fcf.getColumnData(meta); - if (data == null) { - addProblem("fix.cannot.load.data"); - } - else { - columns.add(new Column(meta, data)); - } - } - - return columns; + return new AndFilter().add(rdf).add(ids); } - protected KMIndex<AnalysisPeriod []> calculateAnalysisPeriods( Function function, Parameters parameters, @@ -425,76 +394,6 @@ return results; } - /** Helper class to bundle the meta information of a column - * and the real data. - */ - protected static class Column { - - protected Fixing.Column meta; - protected FixingsColumn data; - - public Column() { - } - - public Column(Fixing.Column meta, FixingsColumn data) { - this.meta = meta; - this.data = data; - } - - public Date getDate() { - return meta.getStartTime(); - } - - public String getDescription() { - return meta.getDescription(); - } - - public boolean getQW( - double km, - double [] qs, - double [] ws, - int index - ) { - qs[index] = data.getQ(km); - return data.getW(km, ws, index); - } - - public boolean getQW(double km, double [] wq) { - data.getW(km, wq, 0); - if (Double.isNaN(wq[0])) return false; - wq[1] = data.getQ(km); - return !Double.isNaN(wq[1]); - } - } // class Column - - - /** - * Helper class to find the data belonging to meta info more quickly. - */ - public static class ColumnCache { - - protected Map<Integer, Column> columns; - - public ColumnCache() { - columns = new HashMap<Integer, Column>(); - } - - public Column getColumn(Fixing.Column meta) { - Integer key = meta.getId(); - Column column = columns.get(key); - if (column == null) { - FixingsColumn data = FixingsColumnFactory - .getInstance() - .getColumnData(meta); - if (data != null) { - column = new Column(meta, data); - columns.put(key, column); - } - } - return column; - } - } // class ColumnCache - /** Fetch meta and data columns for analysis periods. */ protected Column [][] getAnalysisColumns(FixingsOverview overview) { @@ -516,13 +415,12 @@ // Construct filter for period. DateRange period = analysisPeriods[i]; - AndFilter filter = new AndFilter(); - DateRangeFilter dateRangeFilter = new DateRangeFilter(period.getFrom(), period.getTo()); - filter.add(dateRangeFilter); - filter.add(sectorRangeFilter); + Filter filter = new AndFilter() + .add(dateRangeFilter) + .add(sectorRangeFilter); List<Fixing.Column> metaCols = overview.filter(range, filter);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java Sat Jul 21 17:59:13 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java Sun Jul 22 09:49:56 2012 +0000 @@ -3,6 +3,21 @@ import de.intevation.flys.artifacts.access.FixAccess; import de.intevation.flys.artifacts.model.Calculation; +import de.intevation.flys.artifacts.model.FixingsColumn; +import de.intevation.flys.artifacts.model.FixingsColumnFactory; + +import de.intevation.flys.artifacts.model.FixingsOverview.Fixing.Filter; + +import de.intevation.flys.artifacts.model.FixingsOverview.Fixing; +import de.intevation.flys.artifacts.model.FixingsOverview.IdsFilter; + +import de.intevation.flys.artifacts.model.FixingsOverview; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; @@ -11,6 +26,76 @@ { private static Logger log = Logger.getLogger(FixCalculation.class); + /** Helper class to bundle the meta information of a column + * and the real data. + */ + protected static class Column { + + protected Fixing.Column meta; + protected FixingsColumn data; + + public Column() { + } + + public Column(Fixing.Column meta, FixingsColumn data) { + this.meta = meta; + this.data = data; + } + + public Date getDate() { + return meta.getStartTime(); + } + + public String getDescription() { + return meta.getDescription(); + } + + public boolean getQW( + double km, + double [] qs, + double [] ws, + int index + ) { + qs[index] = data.getQ(km); + return data.getW(km, ws, index); + } + + public boolean getQW(double km, double [] wq) { + data.getW(km, wq, 0); + if (Double.isNaN(wq[0])) return false; + wq[1] = data.getQ(km); + return !Double.isNaN(wq[1]); + } + } // class Column + + /** + * Helper class to find the data belonging to meta info more quickly. + */ + protected static class ColumnCache { + + protected Map<Integer, Column> columns; + + public ColumnCache() { + columns = new HashMap<Integer, Column>(); + } + + public Column getColumn(Fixing.Column meta) { + Integer key = meta.getId(); + Column column = columns.get(key); + if (column == null) { + FixingsColumn data = FixingsColumnFactory + .getInstance() + .getColumnData(meta); + if (data != null) { + column = new Column(meta, data); + columns.put(key, column); + } + } + return column; + } + } // class ColumnCache + + protected String river; protected double from; protected double to; @@ -82,7 +167,46 @@ this.qSectorEnd = qSectorEnd; this.preprocessing = preprocessing; } + } + protected static String toString( + String [] parameterNames, + double [] values + ) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < parameterNames.length; ++i) { + if (i > 0) sb.append(", "); + sb.append(parameterNames[i]).append(": ").append(values[i]); + } + return sb.toString(); + } + + protected Filter createFilter() { + return new IdsFilter(events); + } + + protected List<Column> getEventColumns(FixingsOverview overview) { + + FixingsColumnFactory fcf = FixingsColumnFactory.getInstance(); + + Filter filter = createFilter(); + + List<Fixing.Column> metas = overview.filter(null, filter); + + List<Column> columns = new ArrayList<Column>(metas.size()); + + for (Fixing.Column meta: metas) { + + FixingsColumn data = fcf.getColumnData(meta); + if (data == null) { + addProblem("fix.cannot.load.data"); + } + else { + columns.add(new Column(meta, data)); + } + } + + return columns; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :