# HG changeset patch # User Felix Wolfsteller # Date 1315381683 0 # Node ID d90f5bfa3ddf434f0aa2bb2e63e4c2272afd8917 # Parent 073c36bb94ed66fa9b93e8d4c2d27650bb397f70 Fix profile loading of cross section diagram. flys-artifacts/trunk@2659 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 073c36bb94ed -r d90f5bfa3ddf flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Sep 07 07:37:22 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Sep 07 07:48:03 2011 +0000 @@ -1,3 +1,18 @@ +2011-09-07 Felix Wolfsteller + + Fix setting of kilometer for profile (not yet waterlevel) of cross section + diagram. + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: + (getCrossSectionData): Respect corss_section.km data; do naive linear + search for profile data for this km. + + * src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java: + Declare a ComputeType. + + * src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java: + Implement computeFeed. + 2011-09-07 Felix Wolfsteller * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java, diff -r 073c36bb94ed -r d90f5bfa3ddf flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed Sep 07 07:37:22 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed Sep 07 07:48:03 2011 +0000 @@ -655,7 +655,31 @@ * in the form {{x1, x2} {y1, y2}} ). */ public double [][] getCrossSectionData() { - return getCrossSectionProfile(getCrossSections().get(0).getLines().get(0)); + logger.info("getCrossSectionData(), also cross_section.km " + getDataAsString("cross_section.km")); + double wishKM = 0.0f; + try { + wishKM = Double.parseDouble(getDataAsString("cross_section.km")); + } + catch (Exception e) { + ; + } + + // Get the cross section closest to requested km. + // + // Naive, linear approach. + List crossSectionLines = + getCrossSections().get(0).getLines(); + CrossSectionLine oldLine = crossSectionLines.get(0); + double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue()); + for (CrossSectionLine line: crossSectionLines) { + double diff = Math.abs(wishKM - line.getKm().doubleValue()); + if (diff > oldDiff) { + break; + } + oldDiff = diff; + oldLine = line; + } + return getCrossSectionProfile(oldLine); } diff -r 073c36bb94ed -r d90f5bfa3ddf flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java Wed Sep 07 07:37:22 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java Wed Sep 07 07:48:03 2011 +0000 @@ -22,10 +22,12 @@ private static Logger logger = Logger.getLogger(CrossSectionFacet.class); + protected ComputeType type; /** Trivial constructor, set (maybe localized) description. */ public CrossSectionFacet(String description) { super(0, CROSS_SECTION, description); + type = ComputeType.ADVANCE; } @@ -40,6 +42,8 @@ return winfo.getCrossSectionData(); } + + /** Do a deep copy. */ @Override public Facet deepCopy() { CrossSectionFacet copy = new CrossSectionFacet(this.description); diff -r 073c36bb94ed -r d90f5bfa3ddf flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java Wed Sep 07 07:37:22 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java Wed Sep 07 07:48:03 2011 +0000 @@ -36,6 +36,74 @@ } + // TODO This is a duplicate of computeAdvance. Resolve. + public Object computeFeed( + FLYSArtifact artifact, + String hash, + CallContext context, + List facets, + Object old + ) { + WINFOArtifact winfo = (WINFOArtifact)artifact; + + String id = getID(); + + CalculationResult res = old instanceof CalculationResult + ? (CalculationResult)old + : winfo.getWaterlevelData(); + + if (facets == null) { + return res; + } + + WQKms [] wqkms = (WQKms [])res.getData(); + + for (int i = 0; i < wqkms.length; i++) { + String nameW = null; + String nameQ = null; + + if (winfo.isQ()) { + nameQ = wqkms[i].getName(); + nameW = "W(" + nameQ + ")"; + } + else { + nameW = wqkms[i].getName(); + nameQ = "Q(" + nameQ + ")"; + } + + logger.debug("Create facet: " + nameW); + logger.debug("Create facet: " + nameQ); + + Facet w = new WaterlevelFacet( + i, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, id, hash); + Facet q = new WaterlevelFacet( + i, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, id, hash); + + facets.add(w); + facets.add(q); + } + + if (wqkms.length > 0) { + Facet wst = new DataFacet( + WST, "WST data", ComputeType.ADVANCE, hash, id); + Facet csv = new DataFacet( + CSV, "CSV data", ComputeType.ADVANCE, hash, id); + + facets.add(wst); + facets.add(csv); + } + + if (res.getReport().hasProblems()) { + facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); + } + + // Also register the CrossSectionFacet (added to respective out). + facets.add(new CrossSectionFacet("facet.cross_section")); + facets.add(new CrossSectionWaterLineFacet("facet.cross_section_water_line")); + return res; + } + + @Override public Object computeAdvance( FLYSArtifact artifact,