Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadCalculate.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadCalculate.java@bd047b71ab37 |
children | 4897a58c8746 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadCalculate.java Thu Apr 25 15:23:37 2013 +0200 @@ -0,0 +1,432 @@ +package org.dive4elements.river.artifacts.states.minfo; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import org.dive4elements.artifactdatabase.state.Facet; +import org.dive4elements.artifacts.CallContext; +import org.dive4elements.artifacts.CallMeta; +import org.dive4elements.river.artifacts.FLYSArtifact; +import org.dive4elements.river.artifacts.access.SedimentLoadAccess; +import org.dive4elements.river.artifacts.model.CalculationResult; +import org.dive4elements.river.artifacts.model.DataFacet; +import org.dive4elements.river.artifacts.model.FacetTypes; +import org.dive4elements.river.artifacts.model.ReportFacet; +import org.dive4elements.river.artifacts.model.minfo.SedimentLoadCalculation; +import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFacet; +import org.dive4elements.river.artifacts.model.minfo.SedimentLoadResult; +import org.dive4elements.river.artifacts.resources.Resources; +import org.dive4elements.river.artifacts.states.DefaultState; + + +public class SedimentLoadCalculate +extends DefaultState +implements FacetTypes +{ + + private static final long serialVersionUID = 1L; + + private static final Logger logger = Logger + .getLogger(SedimentLoadCalculate.class); + + public static final String I18N_FACET_SEDIMENTLOAD_COARSE = "facet.sedimentload.coarse"; + public static final String I18N_FACET_SEDIMENTLOAD_SAND = "facet.sedimentload.sand"; + public static final String I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE = "facet.sedimentload.fine_middle"; + public static final String I18N_FACET_SEDIMENTLOAD_SUSPSAND = "facet.sedimentload.susp_sand"; + public static final String I18N_FACET_SEDIMENTLOAD_SUSPSANDBED = "facet.sediemntload.susp_sand_bed"; + public static final String I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT = "facet.sedimentload.susp_sediment"; + public static final String I18N_FACET_SEDIMENTLOAD_TOTAL_LOAD = "facet.sedimentload.total_load"; + public static final String I18N_FACET_SEDIMENTLOAD_TOTAL = "facet.sedimentload.total"; + + @Override + public Object computeAdvance(FLYSArtifact artifact, String hash, + CallContext context, List<Facet> facets, Object old) { + logger.debug("SedimentLoadCalculate.computeAdvance"); + + List<Facet> newFacets = new ArrayList<Facet>(); + + SedimentLoadAccess access = new SedimentLoadAccess(artifact, context); + + CalculationResult res = old instanceof CalculationResult ? (CalculationResult) old + : new SedimentLoadCalculation().calculate(access); + + if (facets == null || res == null) { + return res; + } + + SedimentLoadResult[] results = (SedimentLoadResult[]) res.getData(); + + if (results == null || results.length == 0) { + logger.warn("Calculation computed no results!"); + return res; + } + + String type = access.getYearEpoch(); + if (type.equals("year")) { + generateYearFacets(context, newFacets, results, getID(), hash); + } + else if (type.equals("epoch")) { + generateEpochFacets(context, newFacets, results, getID(), hash); + } + else if (type.equals("off_epoch")) { + generateOffEpochFacets(context, newFacets, results, getID(), hash); + } + logger.debug("Created " + newFacets.size() + " new Facets."); + if (res.getReport().hasProblems()) { + newFacets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); + } + facets.addAll(newFacets); + + return res; + } + + protected void generateYearFacets(CallContext context, List<Facet> newFacets, + SedimentLoadResult[] results, String stateId, String hash) { + logger.debug("SedimentLoadCalculate.generateFacets"); + + CallMeta meta = context.getMeta(); + +// newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); + for (int idx = 0; idx < results.length; idx++) { + SedimentLoadResult res = results[idx]; + if (res.hasCoarseData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_COARSE, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_COARSE, + I18N_FACET_SEDIMENTLOAD_COARSE) + + " - " + res.getStartYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSandData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SAND, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SAND, + I18N_FACET_SEDIMENTLOAD_SAND) + + " - " + res.getStartYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasFineMiddleData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_FINEMIDDLE, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE, + I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE) + + " - " + res.getStartYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSuspSandData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SUSP_SAND, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SUSPSAND, + I18N_FACET_SEDIMENTLOAD_SUSPSAND) + + " - " + res.getStartYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSuspSandBedData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SUSP_SAND_BED, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SUSPSANDBED, + I18N_FACET_SEDIMENTLOAD_SUSPSANDBED) + + " - " + res.getStartYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSuspSedimentData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SUSP_SEDIMENT, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT, + I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT) + + " - " + res.getStartYear(), + ComputeType.ADVANCE, + stateId, + hash)); + + } + if (res.hasTotalData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_TOTAL, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_TOTAL, + I18N_FACET_SEDIMENTLOAD_TOTAL) + + " - " + res.getStartYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + } + } + + protected void generateEpochFacets( + CallContext context, + List<Facet> newFacets, + SedimentLoadResult[] results, + String stateId, + String hash + ) { + logger.debug("SedimentLoadCalculate.generateEpochFacets"); + + CallMeta meta = context.getMeta(); + +// newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); + for (int idx = 0; idx < results.length; idx++) { + SedimentLoadResult res = results[idx]; + if (res.hasCoarseData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_COARSE, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_COARSE, + I18N_FACET_SEDIMENTLOAD_COARSE) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSandData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SAND, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SAND, + I18N_FACET_SEDIMENTLOAD_SAND) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasFineMiddleData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_FINEMIDDLE, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE, + I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE) + + " - " + res.getStartYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSuspSandData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SUSP_SAND, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SUSPSAND, + I18N_FACET_SEDIMENTLOAD_SUSPSAND) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSuspSandBedData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SUSP_SAND_BED, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SUSPSANDBED, + I18N_FACET_SEDIMENTLOAD_SUSPSANDBED) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSuspSedimentData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SUSP_SEDIMENT, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT, + I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + + } + if (res.hasTotalLoadData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_TOTAL_LOAD, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_TOTAL_LOAD, + I18N_FACET_SEDIMENTLOAD_TOTAL_LOAD) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasTotalData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_TOTAL, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_TOTAL, + I18N_FACET_SEDIMENTLOAD_TOTAL) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + } + } + + protected void generateOffEpochFacets( + CallContext context, + List<Facet> newFacets, + SedimentLoadResult[] results, + String stateId, + String hash + ) { + logger.debug("SedimentLoadCalculate.generateOffEpochFacets"); + + CallMeta meta = context.getMeta(); + +// newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); + for (int idx = 0; idx < results.length; idx++) { + SedimentLoadResult res = results[idx]; + if (res.hasCoarseData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_COARSE, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_COARSE, + I18N_FACET_SEDIMENTLOAD_COARSE) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSandData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SAND, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SAND, + I18N_FACET_SEDIMENTLOAD_SAND) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasFineMiddleData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_FINEMIDDLE, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE, + I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSuspSandData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SUSP_SAND, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SUSPSAND, + I18N_FACET_SEDIMENTLOAD_SUSPSAND) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSuspSandBedData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SUSP_SAND_BED, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SUSPSANDBED, + I18N_FACET_SEDIMENTLOAD_SUSPSANDBED) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasSuspSedimentData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_SUSP_SEDIMENT, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT, + I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + + } + if (res.hasTotalLoadData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_TOTAL_LOAD, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_TOTAL_LOAD, + I18N_FACET_SEDIMENTLOAD_TOTAL_LOAD) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + if (res.hasTotalData()) { + newFacets.add(new SedimentLoadFacet( + idx, + SEDIMENT_LOAD_TOTAL, + Resources.getMsg( + meta, + I18N_FACET_SEDIMENTLOAD_TOTAL, + I18N_FACET_SEDIMENTLOAD_TOTAL) + + " - " + res.getStartYear() + "-" + res.getEndYear(), + ComputeType.ADVANCE, + stateId, + hash)); + } + } + } +}