Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/HistoricalDischargeComputeState.java @ 5380:75371c9ef472
I1174: Changed label for some themes in fix analysis.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 22 Mar 2013 11:55:14 +0100 |
parents | 1b73b731f7bd |
children |
line wrap: on
line source
package de.intevation.flys.artifacts.states; import java.text.NumberFormat; import java.util.List; import org.apache.log4j.Logger; import org.w3c.dom.Element; import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.WINFOArtifact; import de.intevation.flys.artifacts.access.HistoricalDischargeAccess; import de.intevation.flys.artifacts.access.HistoricalDischargeAccess.EvaluationMode; 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; /** * State to calculate historical discharge curves. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class HistoricalDischargeComputeState extends DefaultState implements FacetTypes { private static final Logger logger = Logger .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, String name, CallContext context, Element select) { // TODO IMPLEMENT ME } @Override public Object computeAdvance(FLYSArtifact artifact, String hash, CallContext context, List<Facet> facets, Object old) { logger.debug("HistoricalDischargeComputeState.computeAdvance"); WINFOArtifact winfo = (WINFOArtifact) artifact; CalculationResult res = old instanceof CalculationResult ? (CalculationResult) old : winfo.getHistoricalDischargeData(); if (facets == null) { return res; } if (res.getReport().hasProblems()) { facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); } 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); } WQKms[] wqs = (WQKms[]) data.getWQs(); if (wqs != null && wqs.length > 0) { prepareWQFacets(context, facets, wqs, access, hash); } return res; } protected void prepareFacets(List<Facet> facets, WQTimerange[] wqts, HistoricalDischargeAccess access) { int i = 0; for (WQTimerange wqt : wqts) { logger.debug("Prepare facet for: " + wqt.getName()); EvaluationMode evalMode = access.getEvaluationMode(); if (evalMode == EvaluationMode.W) { facets.add(new HistoricalDischargeFacet(i, HISTORICAL_DISCHARGE_Q, createFacetTitle(wqt))); if (wqt instanceof HistoricalWQTimerange) { logger .debug("Create another facet for historical differences."); // TODO CREATE BETTER TITLE FOR FACETS (issue1180) facets.add(new HistoricalDischargeDifferenceFacet(i, HISTORICAL_DISCHARGE_Q_DIFF, "DIFF: " + wqt.getName())); } } else { facets.add(new HistoricalDischargeFacet(i, HISTORICAL_DISCHARGE_W, createFacetTitle(wqt))); if (wqt instanceof HistoricalWQTimerange) { logger .debug("Create another facet for historical differences."); // TODO CREATE BETTER TITLE FOR FACETS facets.add(new HistoricalDischargeDifferenceFacet(i, HISTORICAL_DISCHARGE_W_DIFF, "DIFF: " + wqt.getName())); } } i++; } } protected void prepareWQFacets(CallContext cc, List<Facet> facets, WQKms[] wqs, HistoricalDischargeAccess access, String hash) { double[] ws = access.getWs(); double[] qs = access.getQs(); NumberFormat format = NumberFormat.getInstance( Resources.getLocale(cc.getMeta())); for (int k = 0; k < ws.length; k++) { facets.add(new HistoricalDischargeWQFacet(k, HISTORICAL_DISCHARGE_WQ_W, "W=" + format.format(ws[k]), ComputeType.ADVANCE, hash, getID(), ws[k])); } for (int k = 0; k < qs.length; k++) { facets.add(new HistoricalDischargeWQFacet(k, HISTORICAL_DISCHARGE_WQ_Q, "Q=" + format.format(qs[k]), ComputeType.ADVANCE, hash, getID(), 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++; } } /** Create title for a Discharge-curve, including date. */ 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()); } } /** Create string for facets name/description. */ protected String createFacetTitle(WQTimerange wqt) { String name = wqt.getName(); return name != null && name.indexOf("W") >= 0 ? createFacetTitleW(wqt) : createFacetTitleQ(wqt); } protected String createFacetTitleW(WQTimerange wqt) { String name = wqt.getName(); return name + " " + DEFAULT_UNIT; } protected String createFacetTitleQ(WQTimerange wqt) { return wqt.getName(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :