Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java @ 9612:f8308db94634
#20 UI, Diagramme
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 09 Oct 2019 16:17:16 +0200 |
parents | aa6ee96071b7 |
children | d889ffe2fb05 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java Wed Oct 09 15:58:46 2019 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java Wed Oct 09 16:17:16 2019 +0200 @@ -9,13 +9,19 @@ */ package org.dive4elements.river.artifacts.sinfo.flood_duration; +import java.io.Serializable; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map.Entry; +import java.util.Set; import org.apache.commons.collections.Predicate; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; import org.dive4elements.river.artifacts.common.AbstractExportContext; import org.dive4elements.river.artifacts.common.ExportContextCSV; @@ -24,6 +30,7 @@ import org.dive4elements.river.artifacts.common.IResultType; import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; import org.dive4elements.river.artifacts.common.ResultRow; +import org.dive4elements.river.artifacts.resources.Resources; import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; import org.dive4elements.river.model.Attribute.AttributeKey; @@ -37,19 +44,19 @@ */ public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { - private final static class RiversidePredicate implements Predicate { + private final static class InfrastructurePredicate implements Predicate { - private final AttributeKey riverside; + private final Infrastructure m_infrastructure; - public RiversidePredicate(final AttributeKey riverside) { - this.riverside = riverside; + public InfrastructurePredicate(final Infrastructure infrastructure) { + this.m_infrastructure = infrastructure; } @Override public boolean evaluate(final Object object) { final ResultRow row = (ResultRow) object; - - return row.getValue(SInfoResultType.riverside) == this.riverside; + final Infrastructure test = new Infrastructure(row); + return this.m_infrastructure.equals(test); } } @@ -63,6 +70,73 @@ } } + public static final class Infrastructure implements Serializable { + + private static final long serialVersionUID = 1L; + + private final String m_type; + + private final String m_part; + + private final AttributeKey m_riverside; + + private static final String FACET_FLOOD_DURATION_DESCRIPTION = "sinfo_facet_flood_duration"; + + private static final String FACET_ABSOLUTE_HEIGHT = "sinfo.flood_duration.absolute.height"; + + public Infrastructure(final ResultRow row) { + this.m_type = String.valueOf(row.getValue(SInfoResultType.infrastructuretype)); + this.m_part = String.valueOf(row.getValue(SInfoResultType.infrastructurepart)); + final String riversideStr = String.valueOf(row.getValue(SInfoResultType.riverside)); + this.m_riverside = riversideStr.equals("null") ? AttributeKey.NONE : AttributeKey.valueOf(riversideStr); + } + + public AttributeKey getRiverside() { + return this.m_riverside; + } + + @Override + public int hashCode() { + return new HashCodeBuilder() // + .append(this.m_type)// + .append(this.m_part)// + .append(this.m_riverside)// + .toHashCode(); + } + + @Override + public boolean equals(final Object obj) { + + if (obj == null) + return false; + if (obj == this) + return true; + if (obj.getClass() != getClass()) + return false; + + final Infrastructure other = (Infrastructure) obj; + return new EqualsBuilder() // + .append(this.m_type, other.m_type) // + .append(this.m_part, other.m_part) // + .append(this.m_riverside, other.m_riverside) // + .isEquals(); + } + + public String getFloodHeightLabel(final CallContext context) { + return Resources.getMsg(context.getMeta(), FACET_ABSOLUTE_HEIGHT, FACET_ABSOLUTE_HEIGHT) + " " + this.m_type + " - " + this.m_part + " (" + + getLocalizedRiverside(context) + ")"; + } + + public String getFloodDurationLabel(final CallContext context) { + return Resources.getMsg(context.getMeta(), FACET_FLOOD_DURATION_DESCRIPTION, FACET_FLOOD_DURATION_DESCRIPTION) + " " + this.m_type + " - " + + this.m_part + " (" + getLocalizedRiverside(context) + ")"; + } + + private String getLocalizedRiverside(final CallContext callContext) { + return SInfoResultType.localizeRiverside(callContext, this.m_riverside); + } + } + private static final long serialVersionUID = 1L; private final boolean isUseWspl; @@ -71,6 +145,8 @@ private final int maxWaterlevelPdf = 3; + private final Set<Infrastructure> m_infastructures; + public interface ValueGetter { double getValue(DurationWaterlevel waterlevel); } @@ -79,10 +155,16 @@ pdf, csv } - public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows, final boolean isUseWspl) { + public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows, final boolean isUseWspl, + final Set<Infrastructure> infrastructures) { super(label, rows); this.waterlevelLabels = mainvalueLabels; this.isUseWspl = isUseWspl; + this.m_infastructures = infrastructures; + } + + public Set<Infrastructure> getInfastructureMap() { + return this.m_infastructures; } /** @@ -96,7 +178,7 @@ final List<ResultRow> infrasOnlyRows = new ArrayList<>(); for (final ResultRow row : rows) { - if (row.getValue(SInfoResultType.infrastructuretype) != null) + if (row.getValue(SInfoResultType.infrastructuretype) != null && row.getValue(SInfoResultType.infrastructurepart) != null) infrasOnlyRows.add(row); } return Collections.unmodifiableCollection(infrasOnlyRows); @@ -130,9 +212,12 @@ lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.riverside)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDuration)); + lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDischarge)); + lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype)); + lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructurepart)); final List<DurationWaterlevel> waterlevelList = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel); @@ -178,6 +263,7 @@ header.add(exportContextCSV.msgUnitCSV(SInfoResultType.floodDischarge, SInfoResultType.floodDischarge.getUnit())); header.add(exportContextCSV.msgUnitCSV(SInfoResultType.infrastructureHeight, river.getWstUnit())); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype)); + header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructurepart)); // add dynamic headers final int waterlevelCount = // results. @@ -227,6 +313,7 @@ exportContextPDF.addJRMetadata(source, "inundationduration_q_header", SInfoResultType.floodDischarge); exportContextPDF.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeight); exportContextPDF.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype); + exportContextPDF.addJRMetadata(source, "infrastructure_part_header", SInfoResultType.infrastructurepart); for (int i = 1; i <= this.getWaterlevelCount(); i++) { @@ -262,8 +349,9 @@ /** * Gets the longitudinal section of a result value type for one river side */ - public final double[][] getInfrastructurePoints(final IResultType type, final AttributeKey riverside) { - return getPoints(GeneralResultType.station, type, new RiversidePredicate(riverside)); + public final double[][] getInfrastructurePoints(final IResultType type, final Infrastructure infrastructure) { + + return getPoints(GeneralResultType.station, type, new InfrastructurePredicate(infrastructure)); } /** @@ -295,4 +383,9 @@ public boolean isUseWspl() { return this.isUseWspl; } + + public Collection<Entry<String, String>> getUniqueInfrastruktureTypes() { + // TODO Auto-generated method stub + return null; + } } \ No newline at end of file