Mercurial > dive4elements > river
changeset 1712:7e19449d7826
#253 Modified the title creation of chart curves - titles will now equal the Facet's description.
flys-artifacts/trunk@2984 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Oct 17 08:45:26 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon Oct 17 10:47:36 2011 +0000 @@ -1,3 +1,25 @@ +2011-10-17 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/GaugesFactory.java: + Added a function that returns a Gauge based on its name. + + * src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java: + Create proper descriptions for facets. + + * src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java: Added a + setter for labels. + + * src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java, + src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java, + src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java, + src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java, + src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java, + src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java: + Use the string returned by Facet.getDescription() as series names. The + ThemePanel and the Legend will always display the same titles for curves + now. + + 2011-10-17 Felix Wolfsteller <felix.wolfsteller@intevation.de> Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugesFactory.java Mon Oct 17 08:45:26 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugesFactory.java Mon Oct 17 10:47:36 2011 +0000 @@ -17,6 +17,19 @@ return getGauges(river.getName()); } + + public static Gauge getGauge(String gaugeName) { + Session session = SessionHolder.HOLDER.get(); + Query query = session.createQuery( + "from Gauge where name=:name"); + query.setParameter("name", gaugeName); + + List<Gauge> res = query.list(); + + return res.isEmpty() ? null : res.get(0); + } + + public static List<Gauge> getGauges(String river) { Session session = SessionHolder.HOLDER.get(); Query query = session.createQuery(
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java Mon Oct 17 08:45:26 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java Mon Oct 17 10:47:36 2011 +0000 @@ -1,5 +1,6 @@ package de.intevation.flys.artifacts.states; +import java.util.Date; import java.util.List; import org.apache.log4j.Logger; @@ -15,12 +16,16 @@ import de.intevation.artifactdatabase.data.StateData; import de.intevation.artifactdatabase.state.Facet; +import de.intevation.flys.model.DischargeTable; +import de.intevation.flys.model.Gauge; import de.intevation.flys.model.River; +import de.intevation.flys.model.TimeInterval; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.WINFOArtifact; import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.GaugesFactory; import de.intevation.flys.artifacts.model.RiverFactory; import de.intevation.flys.artifacts.model.WaterlevelFacet; import de.intevation.flys.artifacts.model.WQKms; @@ -173,7 +178,7 @@ String stateID = winfo.getCurrentStateId(); for (int i = 0; i < wqkms.length; ++i) { - String name = wqkms[i].getName(); + String name = getSeriesName(context, wqkms[i].getName()); facets.add(new WaterlevelFacet( i, DISCHARGE_CURVE, name, ComputeType.FEED, stateID, hash)); } @@ -182,6 +187,47 @@ return res; } + protected String getSeriesName(CallContext cc, String gaugeName) { + Gauge gauge = GaugesFactory.getGauge(gaugeName); + + if (gauge == null) { + logger.warn("Cannot determine Gauge for name: " + gaugeName); + return gaugeName; + } + + List<DischargeTable> dts = gauge.getDischargeTables(); + + for (DischargeTable dt: dts) { + if (dt.getKind() == 0) { + TimeInterval ti = dt.getTimeInterval(); + + Date start = ti.getStartTime(); + Date end = ti.getStopTime(); + + String name = gauge.getName(); + + if (end == null) { + Object[] args = new Object[] { name, start }; + return Resources.getMsg( + cc.getMeta(), + "chart.discharge.curve.curve.valid.from", + "", + args); + } + else { + Object[] args = new Object[] { name, start, end }; + return Resources.getMsg( + cc.getMeta(), + "chart.discharge.curve.curve.valid.range", + "", + args); + } + } + } + + return gauge.getName(); + } + @Override protected double[] getMinMax(Artifact artifact) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java Mon Oct 17 08:45:26 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java Mon Oct 17 10:47:36 2011 +0000 @@ -74,8 +74,8 @@ // TODO DO i18n String nameC = nameW.replace( - "Benutzerdefiniert", - "Benutzerdefiniert [korrigiert]"); + "benutzerdefiniert", + "benutzerdefiniert [korrigiert]"); Facet c = new WaterlevelFacet( i, DISCHARGE_LONGITUDINAL_C, nameC);
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Mon Oct 17 08:45:26 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Mon Oct 17 10:47:36 2011 +0000 @@ -100,13 +100,15 @@ Facet f = flys.getNativeFacet(facet); if (name.equals(COMPUTED_DISCHARGE_Q)) { - doQOut((WQKms) f.getData(artifact, context), attr, visible); + doQOut((WQKms) f.getData(artifact, context), facet, attr, visible); } else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)) { - doMainValueQAnnotations(f.getData(artifact, context), attr,visible); + doMainValueQAnnotations( + f.getData(artifact, context), facet, attr,visible); } else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)) { - doMainValueWAnnotations(f.getData(artifact, context), attr,visible); + doMainValueWAnnotations( + f.getData(artifact, context), facet, attr,visible); } else { logger.warn("Unknown facet type for computed discharge: " + name); @@ -120,6 +122,7 @@ */ protected void doMainValueWAnnotations( Object o, + Facet facet, Document theme, boolean visible ) { @@ -127,6 +130,7 @@ FLYSAnnotation fa = (FLYSAnnotation) o; fa.setTheme(theme); + fa.setLabel(facet.getDescription()); addAnnotations(fa, visible); } @@ -136,6 +140,7 @@ */ protected void doMainValueQAnnotations( Object o, + Facet facet, Document theme, boolean visible ) { @@ -143,6 +148,7 @@ FLYSAnnotation fa = (FLYSAnnotation) o; fa.setTheme(theme); + fa.setLabel(facet.getDescription()); addAnnotations(fa, visible); } @@ -152,12 +158,17 @@ * @param wqkms actual data * @param theme theme to use. */ - protected void doQOut(WQKms wqkms, Document theme, boolean visible) { + protected void doQOut( + WQKms wqkms, + Facet facet, + Document theme, + boolean visible + ) { int size = wqkms.size(); double[] res = new double[3]; - XYSeries series = new StyledXYSeries(getSeriesName(wqkms), theme); + XYSeries series = new StyledXYSeries(facet.getDescription(), theme); for (int i = 0; i < size; i++) { res = wqkms.get(i, res); series.add(res[1], res[0]); @@ -165,21 +176,5 @@ addFirstAxisSeries(series, visible); } - - - /** - * Get the series name to display in legend. - */ - protected String getSeriesName(WQKms wqkms) { - Object[] args = new Object[] { - getRiverName(), - wqkms.getName() - }; - - return msg( - "chart.computed.discharge.curve.curve.label", - "", - args); - } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java Mon Oct 17 08:45:26 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java Mon Oct 17 10:47:36 2011 +0000 @@ -1,8 +1,5 @@ package de.intevation.flys.exports; -import java.util.Date; -import java.util.List; - import org.apache.log4j.Logger; import org.w3c.dom.Document; @@ -17,10 +14,8 @@ import de.intevation.artifactdatabase.state.Facet; -import de.intevation.flys.model.DischargeTable; import de.intevation.flys.model.Gauge; import de.intevation.flys.model.River; -import de.intevation.flys.model.TimeInterval; import de.intevation.flys.artifacts.WINFOArtifact; @@ -111,14 +106,14 @@ WINFOArtifact flysArtifact = (WINFOArtifact) artifact; - facet = flysArtifact.getNativeFacet(facet); + Facet nativeFacet = flysArtifact.getNativeFacet(facet); - if (facet == null) { + if (nativeFacet == null) { logger.debug("no facet found"); return; } - WQKms wqkms = (WQKms)facet.getData(flysArtifact, context); + WQKms wqkms = (WQKms)nativeFacet.getData(flysArtifact, context); String gaugeName = wqkms.getName(); @@ -136,14 +131,12 @@ return; } - String seriesName = getSeriesName(gauge); - double [][] values = new double [][] { wqkms.getQs(), wqkms.getWs() }; int size = values != null ? values[0].length : 0; - XYSeries series = new StyledXYSeries(seriesName, attr); + XYSeries series = new StyledXYSeries(facet.getDescription(), attr); for (int i = 0; i < size; i++) { series.add(values[0][i], values[1][i]); @@ -151,42 +144,5 @@ addFirstAxisSeries(series, visible); } - - - protected String getSeriesName(Gauge gauge) { - //XXX The following code stops the artifact server accepting new HTTP - //requests. It needs more analysis! Is loading the discharge table a - //memory problem? Or is the time interval the problem? - - List<DischargeTable> dts = gauge.getDischargeTables(); - - for (DischargeTable dt: dts) { - if (dt.getKind() == 0) { - TimeInterval ti = dt.getTimeInterval(); - - Date start = ti.getStartTime(); - Date end = ti.getStopTime(); - - String name = gauge.getName(); - - if (end == null) { - Object[] args = new Object[] { name, start }; - return msg( - "chart.discharge.curve.curve.valid.from", - "", - args); - } - else { - Object[] args = new Object[] { name, start, end }; - return msg( - "chart.discharge.curve.curve.valid.range", - "", - args); - } - } - } - - return gauge.getName(); - } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java Mon Oct 17 08:45:26 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java Mon Oct 17 10:47:36 2011 +0000 @@ -56,14 +56,15 @@ Facet f = flys.getNativeFacet(facet); if (name.equals(DISCHARGE_LONGITUDINAL_W)) { - doWOut((WQKms) f.getData(artifact, context), attr, visible); + doWOut((WQKms) f.getData(artifact, context), facet, attr, visible); } else if (name.equals(DISCHARGE_LONGITUDINAL_Q)) { - doQOut((WQKms) f.getData(artifact, context), attr, visible); + doQOut((WQKms) f.getData(artifact, context), facet, attr, visible); } else if (name.equals(DISCHARGE_LONGITUDINAL_C)) { doCorrectedWOut( (WQCKms) f.getData(artifact, context), + facet, attr, visible); } @@ -81,6 +82,7 @@ */ protected void doCorrectedWOut( WQCKms wqckms, + Facet facet, Document theme, boolean visible ) { @@ -90,7 +92,7 @@ if (size > 0) { XYSeries series = new StyledXYSeries( - getSeriesNameForCorrected(wqckms, "W"), + facet.getDescription(), theme); for (int i = 0; i < size; i++) { @@ -104,20 +106,5 @@ setInverted(true); } } - - - protected String getSeriesNameForCorrected(WQKms wqkms, String mode) { - String name = wqkms.getName(); - - name = name.replace( - "benutzerdefiniert", - "benutzerdefiniert [korrigiert]"); - - String prefix = name.indexOf(mode) >= 0 ? null : mode; - - return prefix != null && prefix.length() > 0 - ? prefix + "(" + name + ")" - : name; - } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Mon Oct 17 08:45:26 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Mon Oct 17 10:47:36 2011 +0000 @@ -259,13 +259,13 @@ } if (name.equals(LONGITUDINAL_W)) { - doWOut((WQKms) f.getData(artifact, context), attr, visible); + doWOut((WQKms) f.getData(artifact, context), facet, attr, visible); } else if (name.equals(LONGITUDINAL_Q)) { - doQOut((WQKms) f.getData(artifact, context), attr, visible); + doQOut((WQKms) f.getData(artifact, context), facet, attr, visible); } else if (name.equals(LONGITUDINAL_ANNOTATION)) { - doAnnotationsOut(f.getData(artifact, context), attr, visible); + doAnnotationsOut(f.getData(artifact, context), facet, attr,visible); } else { logger.warn("Unknown facet name: " + name); @@ -278,13 +278,23 @@ * Register annotations available for the diagram. * * @param o list of annotations (data of facet). + * @param facet The facet. This facet does NOT support any data objects. Use + * FLYSArtifact.getNativeFacet() instead to retrieve a Facet which supports + * data. * @param theme yet ignored. + * @param visible The visibility of the annotations. */ - protected void doAnnotationsOut(Object o, Document theme, boolean visible) { + protected void doAnnotationsOut( + Object o, + Facet facet, + Document theme, + boolean visible + ) { logger.debug("LongitudinalSectionGenerator.doAnnotationsOut"); // Add all annotations in list o to our annotation pool. FLYSAnnotation fa = (FLYSAnnotation) o; + fa.setLabel(facet.getDescription()); addAnnotations(fa, visible); } @@ -293,12 +303,21 @@ * Process the output for W facets in a longitudinal section curve. * * @param wqkms An array of WQKms values. + * @param facet The facet. This facet does NOT support any data objects. Use + * FLYSArtifact.getNativeFacet() instead to retrieve a Facet which supports + * data. * @param theme The theme that contains styling information. + * @param visible The visibility of the curve. */ - protected void doWOut(WQKms wqkms, Document theme, boolean visible) { + protected void doWOut( + WQKms wqkms, + Facet facet, + Document theme, + boolean visible + ) { logger.debug("LongitudinalSectionGenerator.doWOut"); - XYSeries series = new StyledXYSeries(getSeriesName(wqkms, "W"), theme); + XYSeries series = new StyledXYSeries(facet.getDescription(), theme); int size = wqkms.size(); @@ -318,12 +337,21 @@ * Process the output for Q facets in a longitudinal section curve. * * @param wqkms An array of WQKms values. + * @param facet The facet. This facet does NOT support any data objects. Use + * FLYSArtifact.getNativeFacet() instead to retrieve a Facet which supports + * data. * @param theme The theme that contains styling information. + * @param visible The visibility of the curve. */ - protected void doQOut(WQKms wqkms, Document theme, boolean visible) { + protected void doQOut( + WQKms wqkms, + Facet facet, + Document theme, + boolean visible + ) { logger.debug("LongitudinalSectionGenerator.doQOut"); - XYSeries series = new StyledXYSeries(getSeriesName(wqkms, "Q"), theme); + XYSeries series = new StyledXYSeries(facet.getDescription(), theme); int size = wqkms.size();
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Mon Oct 17 08:45:26 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Mon Oct 17 10:47:36 2011 +0000 @@ -138,12 +138,12 @@ if (name.equals(W_DIFFERENCES)) { doWDifferencesOut( (WKms) f.getData(artifact, context), - f.getDescription(), + facet, attr, visible); } else if (name.equals(LONGITUDINAL_W)) { - doWOut((WQKms) f.getData(artifact, context), attr, visible); + doWOut((WQKms) f.getData(artifact, context), facet, attr, visible); } else { logger.warn("Unknown facet name: " + name); @@ -160,10 +160,15 @@ * @param theme The theme that contains styling information. */ @Override - protected void doWOut(WQKms wqkms, Document theme, boolean visible) { + protected void doWOut( + WQKms wqkms, + Facet facet, + Document theme, + boolean visible + ) { logger.debug("WDifferencesCurveGenerator.doWOut"); - XYSeries series = new StyledXYSeries(getSeriesName(wqkms, "W"), theme); + XYSeries series = new StyledXYSeries(facet.getDescription(), theme); int size = wqkms.size(); @@ -187,7 +192,7 @@ */ protected void doWDifferencesOut( WKms wkms, - String seriesName, + Facet facet, Document theme, boolean visible ) { @@ -198,7 +203,7 @@ } int size = wkms.size(); - XYSeries series = new StyledXYSeries(seriesName, theme); + XYSeries series = new StyledXYSeries(facet.getDescription(), theme); if (logger.isDebugEnabled()) { if (wkms.size() > 0) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java Mon Oct 17 08:45:26 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java Mon Oct 17 10:47:36 2011 +0000 @@ -21,6 +21,10 @@ this.annotations = annotations; } + public void setLabel(String label) { + this.label = label; + } + public String getLabel() { return label; }