Mercurial > dive4elements > river
changeset 4241:49cb65d5932d
Improved the historical discharge calculation.
The calculation now creates new HistoricalWQKms (new subclass of WQKms). Those WQKms are used
to create new facets from (new) type 'HistoricalDischargeCurveFacet'. The chart generator is
improved to support those facets.
line wrap: on
line diff
--- a/flys-artifacts/doc/conf/artifacts/winfo.xml Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/doc/conf/artifacts/winfo.xml Wed Oct 24 14:34:35 2012 +0200 @@ -575,6 +575,13 @@ <facet name="historical_discharge.manualpoints"/> </facets> </outputmode> + <outputmode name="historical_discharge_wq" description="output.historical_discharge_wq.description" mime-type="image/png" type="chart"> + <facets> + <facet name="historical_discharge.wq.q"/> + <facet name="historical_discharge.wq.w"/> + <facet name="historical_discharge.wq.curve"/> + </facets> + </outputmode> <outputmode name="historical_discharge_export" description="output.historical_discharge.export" mime-type="text/plain" type="export"> <facets> <facet name="csv" description="facet.historical_discharge.csv" />
--- a/flys-artifacts/doc/conf/conf.xml Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/doc/conf/conf.xml Wed Oct 24 14:34:35 2012 +0200 @@ -288,6 +288,8 @@ <output-generator name="reference_curve_export">de.intevation.flys.exports.ReferenceCurveExporter</output-generator> <output-generator name="historical_discharge">de.intevation.flys.exports.HistoricalDischargeCurveGenerator</output-generator> <output-generator name="historical_discharge_chartinfo">de.intevation.flys.exports.HistoricalDischargeCurveInfoGenerator</output-generator> + <output-generator name="historical_discharge_wq">de.intevation.flys.exports.HistoricalDischargeWQCurveGenerator</output-generator> + <output-generator name="historical_discharge_wq_chartinfo">de.intevation.flys.exports.HistoricalDischargeWQCurveInfoGenerator</output-generator> <output-generator name="historical_discharge_export">de.intevation.flys.exports.HistoricalDischargeCurveExporter</output-generator> <output-generator name="flow_velocity">de.intevation.flys.exports.FlowVelocityGenerator</output-generator> <output-generator name="flow_velocity_chartinfo">de.intevation.flys.exports.FlowVelocityInfoGenerator</output-generator>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java Wed Oct 24 14:34:35 2012 +0200 @@ -1,6 +1,7 @@ package de.intevation.flys.artifacts.model; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; @@ -55,11 +56,13 @@ addProblem("cannot.find.hist.q.tables"); } - WQTimerange[] wqt = prepareCalculationData(refTable, dts); + WQTimerange[] wqt = prepareTimerangeData(refTable, dts); + WQKms[] wqs = prepareWQData(dts); logger.debug("Number of calculation results: " + wqt.length); - return new CalculationResult(wqt, this); + return new CalculationResult(new HistoricalDischargeData(wqt, wqs), + this); } protected boolean checkParameters() { @@ -124,7 +127,7 @@ return false; } - protected WQTimerange[] prepareCalculationData(DischargeTable refTable, + protected WQTimerange[] prepareTimerangeData(DischargeTable refTable, List<DischargeTable> dts) { if (refTable == null) { addProblem("cannot.find.hist.q.reftable"); @@ -135,6 +138,41 @@ } } + protected WQKms[] prepareWQData(List<DischargeTable> dts) { + WQKms[] wqs = new WQKms[dts.size()]; + + int idx = 0; + + for (DischargeTable dt : dts) { + double[][] values = null; + + if (dt.getKind() == DischargeTables.MASTER) { + values = DischargeTables.loadDischargeTableValues(dt, + DischargeTables.MASTER_SCALE); + + } + else { + values = DischargeTables.loadDischargeTableValues(dt, + DischargeTables.HISTORICAL_SCALE); + + } + + wqs[idx++] = prepareWQ(dt, values); + } + + return wqs; + } + + protected WQKms prepareWQ(DischargeTable dt, double[][] values) { + double km = dt.getGauge().getStation().doubleValue(); + + double[] kms = new double[values[0].length]; + Arrays.fill(kms, km); + + return new HistoricalWQKms(kms, values[1], values[0], + String.valueOf(km), dt.getTimeInterval()); + } + protected WQTimerange[] prepareSimpleData(List<DischargeTable> dts) { List<WQTimerange> wqts = new ArrayList<WQTimerange>(values.length);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java Wed Oct 24 14:34:35 2012 +0200 @@ -218,6 +218,9 @@ String HISTORICAL_DISCHARGE_Q_DIFF = "historical_discharge.historicalq.diff"; String HISTORICAL_DISCHARGE_W = "historical_discharge.historicalw"; String HISTORICAL_DISCHARGE_W_DIFF = "historical_discharge.historicalw.diff"; + String HISTORICAL_DISCHARGE_WQ_Q = "historical_discharge.wq.q"; + String HISTORICAL_DISCHARGE_WQ_W = "historical_discharge.wq.w"; + String HISTORICAL_DISCHARGE_WQ_CURVE = "historical_discharge.wq.curve"; String REFERENCE_CURVE = "reference_curve"; String REFERENCE_CURVE_NORMALIZED = "reference_curve_normalized";
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HistoricalDischargeCurveFacet.java Wed Oct 24 14:34:35 2012 +0200 @@ -0,0 +1,48 @@ +package de.intevation.flys.artifacts.model; + +import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.states.DefaultState.ComputeType; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class HistoricalDischargeCurveFacet extends DataFacet { + + public HistoricalDischargeCurveFacet() { + } + + public HistoricalDischargeCurveFacet(int index, String name, + String description, ComputeType type, String stateID, String hash + + ) { + super(index, name, description, type, hash, stateID); + } + + @Override + public Facet deepCopy() { + WaterlevelFacet copy = new WaterlevelFacet(); + copy.set(this); + copy.type = type; + copy.hash = hash; + copy.stateId = stateId; + return copy; + } + + @Override + public Object getData(Artifact artifact, CallContext context) { + FLYSArtifact flys = (FLYSArtifact) artifact; + + CalculationResult res = (CalculationResult) flys.compute(context, hash, + stateId, type, false); + + HistoricalDischargeData data = (HistoricalDischargeData) res.getData(); + WQKms[] wqkms = (WQKms[]) data.getWQs(); + + return wqkms[index]; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HistoricalDischargeData.java Wed Oct 24 14:34:35 2012 +0200 @@ -0,0 +1,26 @@ +package de.intevation.flys.artifacts.model; + +import java.io.Serializable; + + +public class HistoricalDischargeData implements Serializable { + + private WQKms[] wqs; + private WQTimerange[] wqTimeranges; + + public HistoricalDischargeData() { + } + + public HistoricalDischargeData(WQTimerange[] wqTimeranges, WQKms[] wqs) { + this.wqTimeranges = wqTimeranges; + this.wqs = wqs; + } + + public WQTimerange[] getWQTimeranges() { + return wqTimeranges; + } + + public WQ[] getWQs() { + return wqs; + } +}
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HistoricalDischargeDifferenceFacet.java Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HistoricalDischargeDifferenceFacet.java Wed Oct 24 14:34:35 2012 +0200 @@ -53,7 +53,8 @@ CalculationResult res = (CalculationResult) flys.compute(context, hash, stateId, type, false); - HistoricalWQTimerange[] wqts = (HistoricalWQTimerange[]) res.getData(); + HistoricalDischargeData data = (HistoricalDischargeData) res.getData(); + WQTimerange[] wqts = (WQTimerange[]) data.getWQTimeranges(); return wqts[index]; }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HistoricalDischargeFacet.java Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HistoricalDischargeFacet.java Wed Oct 24 14:34:35 2012 +0200 @@ -65,7 +65,8 @@ CalculationResult res = (CalculationResult) flys.compute(context, hash, stateId, type, false); - WQTimerange[] wqts = (WQTimerange[]) res.getData(); + HistoricalDischargeData data = (HistoricalDischargeData) res.getData(); + WQTimerange[] wqts = (WQTimerange[]) data.getWQTimeranges(); return wqts[index]; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HistoricalDischargeWQFacet.java Wed Oct 24 14:34:35 2012 +0200 @@ -0,0 +1,36 @@ +package de.intevation.flys.artifacts.model; + +import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class HistoricalDischargeWQFacet extends DataFacet { + + private double value; + + public HistoricalDischargeWQFacet() { + } + + public HistoricalDischargeWQFacet(String name, String desc, double value) { + super(name, desc); + this.value = value; + } + + @Override + public Facet deepCopy() { + HistoricalDischargeWQFacet copy = new HistoricalDischargeWQFacet(); + copy.set(this); + copy.value = value; + return copy; + } + + @Override + public Object getData(Artifact artifact, CallContext context) { + return value; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/HistoricalDischargeComputeState.java Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/HistoricalDischargeComputeState.java Wed Oct 24 14:34:35 2012 +0200 @@ -16,11 +16,18 @@ import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.HistoricalDischargeCurveFacet; +import de.intevation.flys.artifacts.model.HistoricalDischargeData; import de.intevation.flys.artifacts.model.HistoricalDischargeDifferenceFacet; import de.intevation.flys.artifacts.model.HistoricalDischargeFacet; +import de.intevation.flys.artifacts.model.HistoricalDischargeWQFacet; +import de.intevation.flys.artifacts.model.HistoricalWQKms; import de.intevation.flys.artifacts.model.HistoricalWQTimerange; import de.intevation.flys.artifacts.model.ReportFacet; +import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.artifacts.model.WQTimerange; +import de.intevation.flys.artifacts.resources.Resources; +import de.intevation.flys.model.TimeInterval; /** @@ -35,6 +42,8 @@ .getLogger(HistoricalDischargeComputeState.class); public static final String DEFAULT_UNIT = "cm"; + public static final String I18N_WQ_CURVE_FACET_RANGE = "historical_discharge.wq.curve_range"; + public static final String I18N_WQ_CURVE_FACET_SINCE = "historical_discharge.wq.curve_since"; @Override protected void appendItems(Artifact artifact, ElementCreator creator, @@ -60,19 +69,25 @@ facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); } - WQTimerange[] data = (WQTimerange[]) res.getData(); - if (data == null || data.length == 0) { - logger.warn("Historical Discharge calculation has no results!"); - return res; + HistoricalDischargeData data = (HistoricalDischargeData) res.getData(); + HistoricalDischargeAccess access = new HistoricalDischargeAccess( + artifact); + + WQTimerange[] wqts = (WQTimerange[]) data.getWQTimeranges(); + if (wqts != null && wqts.length > 0) { + facets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, + hash, id)); + + facets.add(new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, + hash, id)); + + prepareFacets(facets, wqts, access); } - facets - .add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); - - facets - .add(new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, hash, id)); - - prepareFacets(facets, data, new HistoricalDischargeAccess(artifact)); + WQKms[] wqs = (WQKms[]) data.getWQs(); + if (wqs != null && wqs.length > 0) { + prepareWQFacets(context, facets, wqs, access, hash); + } return res; } @@ -116,6 +131,53 @@ } } + protected void prepareWQFacets(CallContext cc, List<Facet> facets, + WQKms[] wqs, HistoricalDischargeAccess access, String hash) { + double[] ws = access.getWs(); + double[] qs = access.getQs(); + + for (int k = 0; k < ws.length; k++) { + facets.add(new HistoricalDischargeWQFacet( + HISTORICAL_DISCHARGE_WQ_W, "W=" + ws[k], ws[k])); + } + + for (int k = 0; k < qs.length; k++) { + facets.add(new HistoricalDischargeWQFacet( + HISTORICAL_DISCHARGE_WQ_W, "Q=" + ws[k], qs[k])); + } + + int idx = 0; + for (WQKms wqkms : wqs) { + String title = null; + if (wqkms instanceof HistoricalWQKms) { + title = createDischargeCurveTitle(cc, (HistoricalWQKms) wqkms); + } + else { + title = wqkms.getName(); + } + + facets.add(new HistoricalDischargeCurveFacet(idx, + HISTORICAL_DISCHARGE_WQ_CURVE, title, ComputeType.ADVANCE, + getID(), hash)); + idx++; + } + } + + protected String createDischargeCurveTitle(CallContext cc, + HistoricalWQKms wqkms) { + TimeInterval timeInterval = wqkms.getTimeInterval(); + + if (timeInterval.getStopTime() != null) { + return Resources.format(cc.getMeta(), I18N_WQ_CURVE_FACET_RANGE, + I18N_WQ_CURVE_FACET_RANGE, timeInterval.getStartTime(), + timeInterval.getStopTime()); + } + else { + return Resources.format(cc.getMeta(), I18N_WQ_CURVE_FACET_SINCE, + I18N_WQ_CURVE_FACET_SINCE, timeInterval.getStartTime()); + } + } + protected String createFacetTitle(WQTimerange wqt) { String name = wqt.getName();
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveExporter.java Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveExporter.java Wed Oct 24 14:34:35 2012 +0200 @@ -28,6 +28,7 @@ import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.HistoricalDischargeData; import de.intevation.flys.artifacts.model.Timerange; import de.intevation.flys.artifacts.model.WQTimerange; import de.intevation.flys.artifacts.model.WQTJRDataSource; @@ -85,9 +86,13 @@ logger.debug("Internal data of CalculationResult: " + d.getClass()); - if (d instanceof WQTimerange[]) { - logger.debug("Add new data of type WQTimerange"); - data.add((WQTimerange[]) d); + if (d instanceof HistoricalDischargeData) { + d = (WQTimerange[]) ((HistoricalDischargeData) d).getWQTimeranges(); + + if (d instanceof WQTimerange[]) { + logger.debug("Add new data of type WQTimerange"); + data.add((WQTimerange[]) d); + } } } }
--- a/flys-artifacts/src/main/resources/messages.properties Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/src/main/resources/messages.properties Wed Oct 24 14:34:35 2012 +0200 @@ -59,6 +59,8 @@ historical.mode.w = Waterlevel Analyse historical.mode.q = Discharge Analyse +historical_discharge.wq.curve_range = Discharge Curve {0,date,short} - {1,date,short} +historical_discharge.wq.curve_since = Discharge Curve {0,date,short} calc.surface.curve = Water Level/Surface Curve calc.flood.map = Flood Plain
--- a/flys-artifacts/src/main/resources/messages_de.properties Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/src/main/resources/messages_de.properties Wed Oct 24 14:34:35 2012 +0200 @@ -59,6 +59,8 @@ historical.mode.w = Wasserstandsanalyse historical.mode.q = Abflussanalyse +historical_discharge.wq.curve_range = Abflusskurve {0,date,short} - {1,date,short} +historical_discharge.wq.curve_since = Abflusskurve ab {0,date,short} calc.surface.curve = Wasserstand/Wasserspiegellage calc.flood.map = \u00dcberschwemmungsfl\u00e4che
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/src/main/resources/messages_de_DE.properties Wed Oct 24 14:34:35 2012 +0200 @@ -59,6 +59,8 @@ historical.mode.w = Wasserstandsanalyse historical.mode.q = Abflussanalyse +historical_discharge.wq.curve_range = Abflusskurve {0,date,short} - {1,date,short} +historical_discharge.wq.curve_since = Abflusskurve ab {0,date,short} calc.surface.curve = Wasserstand/Wasserspiegellage calc.flood.map = \u00dcberschwemmungsfl\u00e4che
--- a/flys-artifacts/src/main/resources/messages_en.properties Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-artifacts/src/main/resources/messages_en.properties Wed Oct 24 14:34:35 2012 +0200 @@ -59,6 +59,8 @@ historical.mode.w = Waterlevel Analyse historical.mode.q = Discharge Analyse +historical_discharge.wq.curve_range = Discharge Curve {0,date,short} - {1,date,short} +historical_discharge.wq.curve_since = Discharge Curve {0,date,short} calc.surface.curve = Water Level/Surface Curve calc.flood.map = Flood Plain
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Wed Oct 24 14:34:35 2012 +0200 @@ -452,6 +452,8 @@ String historical_discharge(); + String historical_discharge_wq(); + String fix_wq_curve(); String fix_deltawt_curve();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Wed Oct 24 14:34:35 2012 +0200 @@ -202,7 +202,8 @@ duration_curve = Duration Curve discharge_longitudinal_section = Discharge Longitudinal Section floodmap = Floodmap -historical_discharge = Historical Discharge Curves +historical_discharge = Time Chart +historical_discharge_wq = WQ Chart flow_velocity = Flow Velocity flow_velocity_export = Flow Velocity Export bedheight_middle = Middle Bed Height
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Wed Oct 24 14:34:35 2012 +0200 @@ -201,7 +201,8 @@ duration_curve = Dauerlinie discharge_longitudinal_section = W f\u00fcr ungleichwertigen Abflussl\u00e4ngsschnitt floodmap = \u00dcberschwemmungsfl\u00e4che -historical_discharge = Historische Abflusskurven +historical_discharge = Zeit Diagramm +historical_discharge_wq = WQ Diagramm flow_velocity = Flie\u00dfgeschwindigkeiten flow_velocity_export = Flie\u00dfgeschwindigkeiten Export bedheight_middle = Mittlere Sohlh\u00f6he
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Wed Oct 24 14:35:59 2012 +0200 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Wed Oct 24 14:34:35 2012 +0200 @@ -202,7 +202,8 @@ duration_curve = Duration Curve discharge_longitudinal_section = Discharge Longitudinal Section floodmap = Floodmap -historical_discharge = Historical Discharge Curves +historical_discharge = Time Chart +historical_discharge_wq = WQ Chart flow_velocity = Flow Velocity flow_velocity_export = Flow Velocity Export bedheight_middle = Middle Bed Height