# HG changeset patch # User gernotbelger # Date 1527237864 -7200 # Node ID 42c15e2f95fb389db8b9639c2f2b07cdfd1484fb # Parent a0feac6ea1ba523db7df3fd7fdd6a82a819fef8c 2.3.4.1.4 Wasserstand falsche Einheit FixAnalysis PDF start diff -r a0feac6ea1ba -r 42c15e2f95fb artifacts/doc/conf/artifacts/bundu.xml --- a/artifacts/doc/conf/artifacts/bundu.xml Fri May 25 09:10:19 2018 +0200 +++ b/artifacts/doc/conf/artifacts/bundu.xml Fri May 25 10:44:24 2018 +0200 @@ -122,8 +122,9 @@ + - + diff -r a0feac6ea1ba -r 42c15e2f95fb artifacts/doc/conf/artifacts/fixanalysis.xml --- a/artifacts/doc/conf/artifacts/fixanalysis.xml Fri May 25 09:10:19 2018 +0200 +++ b/artifacts/doc/conf/artifacts/fixanalysis.xml Fri May 25 10:44:24 2018 +0200 @@ -1,337 +1,306 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r a0feac6ea1ba -r 42c15e2f95fb artifacts/doc/conf/jasper/waterlevel.jasper Binary file artifacts/doc/conf/jasper/waterlevel.jasper has changed diff -r a0feac6ea1ba -r 42c15e2f95fb artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/FixAnalysisCompute.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/FixAnalysisCompute.java Fri May 25 09:10:19 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/FixAnalysisCompute.java Fri May 25 10:44:24 2018 +0200 @@ -14,7 +14,6 @@ import java.util.List; import org.apache.log4j.Logger; - import org.dive4elements.artifactdatabase.state.Facet; import org.dive4elements.artifactdatabase.state.FacetActivity; import org.dive4elements.artifacts.Artifact; @@ -49,15 +48,11 @@ /** * @author Raimund Renkert */ -public class FixAnalysisCompute -extends DefaultState -implements FacetTypes -{ +public class FixAnalysisCompute extends DefaultState implements FacetTypes { /** The log used in this class. */ private static Logger log = Logger.getLogger(FixAnalysisCompute.class); - private static final String I18N_REFERENCEPERIOD_SHORT = - "fix.reference.period.event.short"; + private static final String I18N_REFERENCEPERIOD_SHORT = "fix.reference.period.event.short"; private static final String I18N_ANALYSISPERIODS = "fix.analysis.periods"; @@ -69,84 +64,54 @@ private static final String I18N_DEVIATION = "fix.deviation"; - private static final String I18N_REFERENCEDEVIATION = - "fix.reference.deviation"; - - private static final String I18N_REFERENCEPERIOD = - "state.fix.analysis.referenceperiod"; + private static final String I18N_REFERENCEDEVIATION = "fix.reference.deviation"; - public static final String [] SECTOR_LABELS = { - "fix.mnq", - "fix.mq", - "fix.mhq", - "fix.hq5" - }; + private static final String I18N_REFERENCEPERIOD = "state.fix.analysis.referenceperiod"; + + public static final String[] SECTOR_LABELS = { "fix.mnq", "fix.mq", "fix.mhq", "fix.hq5" }; static { // Active/deactivate facets. - FacetActivity.Registry.getInstance().register( - "fixanalysis", - new FacetActivity() { - @Override - public Boolean isInitialActive( - Artifact artifact, - Facet facet, - String output - ) { - if ( - output.contains(FacetTypes.ChartType.FLSC.toString()) - ) { - // Longitudinal section chart - String name = facet.getName(); + FacetActivity.Registry.getInstance().register("fixanalysis", new FacetActivity() { + @Override + public Boolean isInitialActive(final Artifact artifact, final Facet facet, final String output) { + if (output.contains(FacetTypes.ChartType.FLSC.toString())) { + // Longitudinal section chart + final String name = facet.getName(); - if (name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_DWT) - || name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_LS) - || name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_WQ) - || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_DWT) - || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_LS) - || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_WQ) - ) { - return Boolean.FALSE; - } - } - if (output.contains(FacetTypes.ChartType.FDWC.toString()) - && facet.getName().contains( - FacetTypes.FIX_SECTOR_AVERAGE_DWT)) { + if (name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_DWT) || name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_LS) + || name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_WQ) || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_DWT) + || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_LS) || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_WQ)) { return Boolean.FALSE; } - - return Boolean.TRUE; } - }); + if (output.contains(FacetTypes.ChartType.FDWC.toString()) && facet.getName().contains(FacetTypes.FIX_SECTOR_AVERAGE_DWT)) { + return Boolean.FALSE; + } + + return Boolean.TRUE; + } + }); } - /** * The default constructor that initializes an empty State object. */ public FixAnalysisCompute() { } - @Override - public Object computeAdvance( - D4EArtifact artifact, - String hash, - CallContext context, - List facets, - Object old - ) { + public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List facets, final Object old) { log.debug("FixAnalysisCompute.computeAdvance"); CalculationResult res; - FixAnalysisAccess access = new FixAnalysisAccess(artifact); + final FixAnalysisAccess access = new FixAnalysisAccess(artifact); if (old instanceof CalculationResult) { - res = (CalculationResult)old; - } - else { - FixAnalysisCalculation calc = new FixAnalysisCalculation(access); + res = (CalculationResult) old; + } else { + final FixAnalysisCalculation calc = new FixAnalysisCalculation(access); res = calc.calculate(); } @@ -155,40 +120,35 @@ } if (res.getReport().hasProblems()) { - facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); + facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); } - FixAnalysisResult fr = (FixAnalysisResult)res.getData(); + final FixAnalysisResult fr = (FixAnalysisResult) res.getData(); if (fr == null) { return res; } - facets.add( - new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); - facets.add( - new DataFacet( - FIX_PARAMETERS, "parameters", ComputeType.ADVANCE, hash, id)); - facets.add( - new DataFacet(AT, "AT data", ComputeType.ADVANCE, hash, id)); + facets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, this.id)); + facets.add(new DataFacet(FIX_PARAMETERS, "parameters", ComputeType.ADVANCE, hash, this.id)); + facets.add(new DataFacet(AT, "AT data", ComputeType.ADVANCE, hash, this.id)); + facets.add(new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, hash, this.id)); int maxId = -100; - int sectorMask = fr.getUsedSectorsInAnalysisPeriods(); - - int qsS = access.getQSectorStart(); - int qsE = access.getQSectorEnd(); + final int sectorMask = fr.getUsedSectorsInAnalysisPeriods(); - DateFormat df = Formatter.getDateFormatter( - context.getMeta(), "dd.MM.yyyy"); - DateFormat lf = Formatter.getDateFormatter( - context.getMeta(), "dd.MM.yyyy'T'HH:mm"); + final int qsS = access.getQSectorStart(); + final int qsE = access.getQSectorEnd(); - DateRange [] periods = access.getAnalysisPeriods(); + final DateFormat df = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy"); + final DateFormat lf = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy'T'HH:mm"); + + final DateRange[] periods = access.getAnalysisPeriods(); for (int i = 0; i < periods.length; i++) { - DateRange period = periods[i]; - String startDate = df.format(period.getFrom()); - String endDate = df.format(period.getTo()); + final DateRange period = periods[i]; + final String startDate = df.format(period.getFrom()); + final String endDate = df.format(period.getTo()); for (int j = qsS; j <= qsE; j++) { @@ -197,14 +157,10 @@ continue; } - String sector = SECTOR_LABELS[j]; - String description = "\u0394W (" + - Resources.getMsg(context.getMeta(), - sector, - sector) + - ")"; + final String sector = SECTOR_LABELS[j]; + final String description = "\u0394W (" + Resources.getMsg(context.getMeta(), sector, sector) + ")"; - int sectorNdx = j - qsS; + final int sectorNdx = j - qsS; int facetNdx = i << 2; facetNdx = facetNdx | j; @@ -212,139 +168,75 @@ maxId = facetNdx; } + facets.add(new FixAvSectorFacet(facetNdx, FIX_SECTOR_AVERAGE_DWT + "_" + sectorNdx, description)); facets.add( - new FixAvSectorFacet( - facetNdx, - FIX_SECTOR_AVERAGE_DWT + "_" + sectorNdx, - description)); - facets.add( - new FixLongitudinalAvSectorFacet( - facetNdx, - FIX_SECTOR_AVERAGE_LS + "_" + sectorNdx, - description + ":" + startDate + " - " + endDate)); + new FixLongitudinalAvSectorFacet(facetNdx, FIX_SECTOR_AVERAGE_LS + "_" + sectorNdx, description + ":" + startDate + " - " + endDate)); // TODO: i18n - String dev = "Abweichung: " + description; - facets.add( - new FixLongitudinalAvSectorFacet( - facetNdx, - FIX_SECTOR_AVERAGE_LS_DEVIATION + "_" + sectorNdx, - dev)); - facets.add( - new FixAvSectorFacet( - facetNdx, - FIX_SECTOR_AVERAGE_WQ + "_" + sectorNdx, - description)); + final String dev = "Abweichung: " + description; + facets.add(new FixLongitudinalAvSectorFacet(facetNdx, FIX_SECTOR_AVERAGE_LS_DEVIATION + "_" + sectorNdx, dev)); + facets.add(new FixAvSectorFacet(facetNdx, FIX_SECTOR_AVERAGE_WQ + "_" + sectorNdx, description)); } - String eventDesc = - Resources.getMsg(context.getMeta(), - I18N_ANALYSIS, - I18N_ANALYSIS); + final String eventDesc = Resources.getMsg(context.getMeta(), I18N_ANALYSIS, I18N_ANALYSIS); - Collection aeds = fr.getAnalysisEventsDates(i); - UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, aeds); + final Collection aeds = fr.getAnalysisEventsDates(i); + final UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, aeds); int k = 0; - for (Date d: aeds) { + for (final Date d : aeds) { int anaNdx = i << 8; anaNdx = anaNdx | k; - facets.add(new FixAnalysisEventsFacet(anaNdx, - FIX_ANALYSIS_EVENTS_DWT, - eventDesc + (i+1) + " - " + cf.format(d))); - facets.add(new FixLongitudinalAnalysisFacet(anaNdx, - FIX_ANALYSIS_EVENTS_LS, - eventDesc + (i+1) + " - " + cf.format(d))); - facets.add(new FixAnalysisEventsFacet(anaNdx, - FIX_ANALYSIS_EVENTS_WQ, - eventDesc + (i+1) +" - " + cf.format(d))); + facets.add(new FixAnalysisEventsFacet(anaNdx, FIX_ANALYSIS_EVENTS_DWT, eventDesc + (i + 1) + " - " + cf.format(d))); + facets.add(new FixLongitudinalAnalysisFacet(anaNdx, FIX_ANALYSIS_EVENTS_LS, eventDesc + (i + 1) + " - " + cf.format(d))); + facets.add(new FixAnalysisEventsFacet(anaNdx, FIX_ANALYSIS_EVENTS_WQ, eventDesc + (i + 1) + " - " + cf.format(d))); k++; } } - IdGenerator idg = new IdGenerator(maxId + 1); + final IdGenerator idg = new IdGenerator(maxId + 1); - String i18n_ref = Resources.getMsg(context.getMeta(), - I18N_REFERENCEPERIOD_SHORT, - I18N_REFERENCEPERIOD_SHORT); - String i18n_dev = Resources.getMsg(context.getMeta(), - I18N_REFERENCEDEVIATION, - I18N_REFERENCEDEVIATION); + final String i18n_ref = Resources.getMsg(context.getMeta(), I18N_REFERENCEPERIOD_SHORT, I18N_REFERENCEPERIOD_SHORT); + final String i18n_dev = Resources.getMsg(context.getMeta(), I18N_REFERENCEDEVIATION, I18N_REFERENCEDEVIATION); - Collection reds = fr.getReferenceEventsDates(); - UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, reds); + final Collection reds = fr.getReferenceEventsDates(); + final UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, reds); int i = 0; - for (Date d: reds) { + for (final Date d : reds) { int refNdx = idg.next() << 8; - refNdx |= i; - facets.add(new FixReferenceEventsFacet(refNdx, - FIX_REFERENCE_EVENTS_DWT, - i18n_ref + " - " + cf.format(d))); + refNdx |= i; + facets.add(new FixReferenceEventsFacet(refNdx, FIX_REFERENCE_EVENTS_DWT, i18n_ref + " - " + cf.format(d))); refNdx = idg.next() << 8; refNdx = refNdx | i; - facets.add(new FixLongitudinalReferenceFacet(refNdx, - FIX_REFERENCE_EVENTS_LS, - i18n_ref + " - " + cf.format(d))); + facets.add(new FixLongitudinalReferenceFacet(refNdx, FIX_REFERENCE_EVENTS_LS, i18n_ref + " - " + cf.format(d))); refNdx = idg.next() << 8; refNdx |= i; - facets.add(new FixReferenceEventsFacet(refNdx, - FIX_REFERENCE_EVENTS_WQ, - i18n_ref + " - " + cf.format(d))); + facets.add(new FixReferenceEventsFacet(refNdx, FIX_REFERENCE_EVENTS_WQ, i18n_ref + " - " + cf.format(d))); i++; } - facets.add(new FixLongitudinalDeviationFacet(idg.next(), - FIX_DEVIATION_LS, - i18n_dev)); + facets.add(new FixLongitudinalDeviationFacet(idg.next(), FIX_DEVIATION_LS, i18n_dev)); - String i18n_ana = Resources.getMsg(context.getMeta(), - I18N_ANALYSISPERIODS, - I18N_ANALYSISPERIODS); - facets.add(new FixAnalysisPeriodsFacet(idg.next(), - FIX_ANALYSIS_PERIODS_DWT, - i18n_ana)); - facets.add(new FixAnalysisPeriodsFacet(idg.next(), - FIX_ANALYSIS_PERIODS_LS, - i18n_ana)); - facets.add(new FixAnalysisPeriodsFacet(idg.next(), - FIX_ANALYSIS_PERIODS_WQ, - i18n_ana)); + final String i18n_ana = Resources.getMsg(context.getMeta(), I18N_ANALYSISPERIODS, I18N_ANALYSISPERIODS); + facets.add(new FixAnalysisPeriodsFacet(idg.next(), FIX_ANALYSIS_PERIODS_DWT, i18n_ana)); + facets.add(new FixAnalysisPeriodsFacet(idg.next(), FIX_ANALYSIS_PERIODS_LS, i18n_ana)); + facets.add(new FixAnalysisPeriodsFacet(idg.next(), FIX_ANALYSIS_PERIODS_WQ, i18n_ana)); - String i18n_refp = Resources.getMsg(context.getMeta(), - I18N_REFERENCEPERIOD, - I18N_REFERENCEPERIOD); - facets.add(new DataFacet(idg.next(), - FIX_REFERENCE_PERIOD_DWT, - i18n_refp, - ComputeType.ADVANCE, null, null)); + final String i18n_refp = Resources.getMsg(context.getMeta(), I18N_REFERENCEPERIOD, I18N_REFERENCEPERIOD); + facets.add(new DataFacet(idg.next(), FIX_REFERENCE_PERIOD_DWT, i18n_refp, ComputeType.ADVANCE, null, null)); facets.add(new FixWQCurveFacet(idg.next(), "W/Q")); - Boolean preprocessing = access.getPreprocessing(); + final Boolean preprocessing = access.getPreprocessing(); if (preprocessing != null && preprocessing) { - facets.add(new FixOutlierFacet( - idg.next(), - FIX_OUTLIER, - Resources.getMsg( - context.getMeta(), I18N_OUTLIER, I18N_OUTLIER))); + facets.add(new FixOutlierFacet(idg.next(), FIX_OUTLIER, Resources.getMsg(context.getMeta(), I18N_OUTLIER, I18N_OUTLIER))); } - facets.add(new FixDerivateFacet( - idg.next(), - FIX_DERIVATE_CURVE, - Resources.getMsg( - context.getMeta(), - I18N_DERIVATIVE, - I18N_DERIVATIVE))); + facets.add(new FixDerivateFacet(idg.next(), FIX_DERIVATE_CURVE, Resources.getMsg(context.getMeta(), I18N_DERIVATIVE, I18N_DERIVATIVE))); - facets.add(new FixDeviationFacet( - idg.next(), - FIX_DEVIATION_DWT, - Resources.getMsg(context.getMeta(), - I18N_DEVIATION, - I18N_DEVIATION))); + facets.add(new FixDeviationFacet(idg.next(), FIX_DEVIATION_DWT, Resources.getMsg(context.getMeta(), I18N_DEVIATION, I18N_DEVIATION))); return res; } } diff -r a0feac6ea1ba -r 42c15e2f95fb artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/FixRealizingCompute.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/FixRealizingCompute.java Fri May 25 09:10:19 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/FixRealizingCompute.java Fri May 25 10:44:24 2018 +0200 @@ -14,7 +14,6 @@ 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; @@ -58,26 +57,18 @@ public FixRealizingCompute() { } - @Override - public Object computeAdvance( - D4EArtifact artifact, - String hash, - CallContext context, - List facets, - Object old - ) { + public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List facets, final Object old) { log.debug("FixRealizingCompute.computeAdvance"); CalculationResult res; - FixRealizingAccess access = new FixRealizingAccess(artifact); + final FixRealizingAccess access = new FixRealizingAccess(artifact); if (old instanceof CalculationResult) { res = (CalculationResult) old; - } - else { - FixRealizingCalculation calc = new FixRealizingCalculation(access); + } else { + final FixRealizingCalculation calc = new FixRealizingCalculation(access); res = calc.calculate(); } @@ -89,11 +80,11 @@ facets.add(new ReportFacet()); } - String id = getID(); - CallMeta meta = context.getMeta(); + final String id = getID(); + final CallMeta meta = context.getMeta(); - FixRealizingResult fixRes = (FixRealizingResult) res.getData(); - WQKms [] wqkms = fixRes != null ? fixRes.getWQKms() : new WQKms[0]; + final FixRealizingResult fixRes = (FixRealizingResult) res.getData(); + final WQKms[] wqkms = fixRes != null ? fixRes.getWQKms() : new WQKms[0]; for (int i = 0; i < wqkms.length; i++) { String nameW = null; @@ -102,21 +93,17 @@ if (access.isQ()) { nameQ = wqkms[i].getName(); nameW = "W(" + nameQ + ")"; - } - else { + } else { nameW = wqkms[i].getName(); nameQ = "Q(" + nameW + ")"; } - Facet wq = new FixWaterlevelFacet( - i, FIX_WQ_LS, nameW, ComputeType.ADVANCE, hash, id); + final Facet wq = new FixWaterlevelFacet(i, FIX_WQ_LS, nameW, ComputeType.ADVANCE, hash, id); - Facet w = new FixWaterlevelFacet( - i, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, hash, id); + final Facet w = new FixWaterlevelFacet(i, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, hash, id); - Facet q = new FixWaterlevelFacet( - i, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, hash, id); - Facet csFacet = new CrossSectionWaterLineFacet(i, nameW); + final Facet q = new FixWaterlevelFacet(i, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, hash, id); + final Facet csFacet = new CrossSectionWaterLineFacet(i, nameW); facets.add(wq); facets.add(w); @@ -125,61 +112,42 @@ // XXX: THIS CAN NOT HAPPEN! REMOVE IT! if (wqkms[i] instanceof WQCKms) { - String nameC = nameW.replace( - "benutzerdefiniert", - "benutzerdefiniert [korrigiert]"); + final String nameC = nameW.replace("benutzerdefiniert", "benutzerdefiniert [korrigiert]"); - Facet c = new FixWaterlevelFacet( - i, DISCHARGE_LONGITUDINAL_C, nameC); + final Facet c = new FixWaterlevelFacet(i, DISCHARGE_LONGITUDINAL_C, nameC); facets.add(c); } } if (wqkms.length > 0) { - DateFormat df = Formatter.getDateFormatter(context.getMeta(), - "dd.MM.yyyy"); - DateFormat lf = Formatter.getDateFormatter(context.getMeta(), - "dd.MM.yyyy'T'HH:mm"); + final DateFormat df = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy"); + final DateFormat lf = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy'T'HH:mm"); - Collection reds = fixRes.getReferenceEventsDates(); - UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, reds); + final Collection reds = fixRes.getReferenceEventsDates(); + final UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, reds); int i = 0; - for (Date d: reds) { - facets.add(new FixReferenceEventsFacet( - (1 << 9) | i, - FIX_EVENTS, - cf.format(d))); + for (final Date d : reds) { + facets.add(new FixReferenceEventsFacet((1 << 9) | i, FIX_EVENTS, cf.format(d))); i++; } - facets.add( - new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); + facets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); - facets.add( - new DataFacet(WST, "WST data", ComputeType.ADVANCE, hash, id)); + facets.add(new DataFacet(WST, "WST data", ComputeType.ADVANCE, hash, id)); - facets.add( - new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, hash, id)); + facets.add(new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, hash, id)); } - facets.add( - new DataFacet(AT, "AT data", ComputeType.ADVANCE, hash, id)); + facets.add(new DataFacet(AT, "AT data", ComputeType.ADVANCE, hash, id)); - facets.add(new FixWQCurveFacet( - 0, - Resources.getMsg(meta, I18N_WQ_CURVE, I18N_WQ_CURVE) + " (" - + access.getFunction() + ")")); + facets.add(new FixWQCurveFacet(0, Resources.getMsg(meta, I18N_WQ_CURVE, I18N_WQ_CURVE) + " (" + access.getFunction() + ")")); if (access.getPreprocessing()) { - facets.add(new FixOutlierFacet( - 0, - FIX_OUTLIER, - Resources.getMsg(meta, I18N_WQ_OUTLIER, I18N_WQ_OUTLIER))); + facets.add(new FixOutlierFacet(0, FIX_OUTLIER, Resources.getMsg(meta, I18N_WQ_OUTLIER, I18N_WQ_OUTLIER))); } return res; } } -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r a0feac6ea1ba -r 42c15e2f95fb artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java --- a/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java Fri May 25 09:10:19 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java Fri May 25 10:44:24 2018 +0200 @@ -13,52 +13,45 @@ import java.text.DateFormat; import java.text.NumberFormat; import java.util.ArrayList; -import java.util.Map; +import java.util.Date; import java.util.HashMap; -import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.log4j.Logger; - -import au.com.bytecode.opencsv.CSVWriter; - -import gnu.trove.TDoubleArrayList; - -import org.dive4elements.river.artifacts.model.ConstantWQKms; - -import net.sf.jasperreports.engine.JasperExportManager; -import net.sf.jasperreports.engine.JasperFillManager; -import net.sf.jasperreports.engine.JasperPrint; -import net.sf.jasperreports.engine.JRException; - import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.CallMeta; import org.dive4elements.artifacts.common.utils.Config; - -import org.dive4elements.river.model.Gauge; - +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.FixationArtifact; +import org.dive4elements.river.artifacts.StaticWQKmsArtifact; +import org.dive4elements.river.artifacts.WINFOArtifact; import org.dive4elements.river.artifacts.access.FixRealizingAccess; import org.dive4elements.river.artifacts.access.IsOfficialAccess; import org.dive4elements.river.artifacts.access.RangeAccess; -import org.dive4elements.river.artifacts.FixationArtifact; -import org.dive4elements.river.artifacts.D4EArtifact; -import org.dive4elements.river.artifacts.WINFOArtifact; -import org.dive4elements.river.artifacts.StaticWQKmsArtifact; import org.dive4elements.river.artifacts.model.CalculationResult; +import org.dive4elements.river.artifacts.model.ConstantWQKms; import org.dive4elements.river.artifacts.model.Segment; +import org.dive4elements.river.artifacts.model.WKmsJRDataSource; import org.dive4elements.river.artifacts.model.WQCKms; import org.dive4elements.river.artifacts.model.WQKms; +import org.dive4elements.river.artifacts.model.WQKmsResult; import org.dive4elements.river.artifacts.model.WstLine; -import org.dive4elements.river.artifacts.model.WKmsJRDataSource; -import org.dive4elements.river.artifacts.model.WQKmsResult; import org.dive4elements.river.artifacts.resources.Resources; - +import org.dive4elements.river.model.Gauge; +import org.dive4elements.river.utils.Formatter; import org.dive4elements.river.utils.RiverUtils; import org.dive4elements.river.utils.RiverUtils.WQ_MODE; -import org.dive4elements.river.utils.Formatter; + +import au.com.bytecode.opencsv.CSVWriter; +import gnu.trove.TDoubleArrayList; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JasperExportManager; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; /** * Generates different output formats (wst, csv, pdf) of data that resulted from @@ -68,7 +61,7 @@ */ public class WaterlevelExporter extends AbstractExporter { - /** The log used in this exporter.*/ + /** The log used in this exporter. */ private static Logger log = Logger.getLogger(WaterlevelExporter.class); public static final String FACET_WST = "wst"; @@ -76,166 +69,141 @@ /* This should be the same as in the StaticWQKmsArtifact */ public static final String STATICWQKMSNAME = "staticwqkms"; - public static final String CSV_KM_HEADER = - "export.waterlevel.csv.header.km"; - - public static final String CSV_W_HEADER = - "export.waterlevel.csv.header.w"; + public static final String CSV_KM_HEADER = "export.waterlevel.csv.header.km"; - public static final String CSV_Q_HEADER = - "export.waterlevel.csv.header.q"; + public static final String CSV_W_HEADER = "export.waterlevel.csv.header.w"; - /** - * @deprecated Use {@link WaterlevelDescriptionBuilder} instead. - */ - @Deprecated - public static final String CSV_Q_DESC_HEADER = - "export.waterlevel.csv.header.q.desc"; + public static final String CSV_Q_HEADER = "export.waterlevel.csv.header.q"; /** * @deprecated Use {@link WaterlevelDescriptionBuilder} instead. */ @Deprecated - public static final String CSV_W_DESC_HEADER = - "export.waterlevel.csv.header.w.desc"; - - public static final String CSV_LOCATION_HEADER = - "export.waterlevel.csv.header.location"; - - public static final String CSV_GAUGE_HEADER = - "export.waterlevel.csv.header.gauge"; - - public static final String CSV_META_RESULT = - "export.waterlevel.csv.meta.result"; - - public static final String CSV_META_CREATION = - "export.waterlevel.csv.meta.creation"; - - public static final String CSV_META_CALCULATIONBASE = - "export.waterlevel.csv.meta.calculationbase"; - - public static final String CSV_META_RIVER = - "export.waterlevel.csv.meta.river"; + public static final String CSV_Q_DESC_HEADER = "export.waterlevel.csv.header.q.desc"; - public static final String CSV_META_RANGE = - "export.waterlevel.csv.meta.range"; - - public static final String CSV_META_GAUGE = - "export.waterlevel.csv.meta.gauge"; - - public static final String CSV_META_Q = - "export.waterlevel.csv.meta.q"; - - public static final String CSV_META_W = - "export.waterlevel.csv.meta.w"; - - public static final String CSV_NOT_IN_GAUGE_RANGE = - "export.waterlevel.csv.not.in.gauge.range"; - - public static final Pattern NUMBERS_PATTERN = - Pattern.compile("\\D*(\\d++.\\d*)\\D*"); - - public static final String DEFAULT_CSV_KM_HEADER = "Fluss-Km"; - public static final String DEFAULT_CSV_W_HEADER = "W [NN + m]"; - public static final String DEFAULT_CSV_Q_HEADER = "Q [m\u00b3/s]"; /** * @deprecated Use {@link WaterlevelDescriptionBuilder} instead. */ @Deprecated - public static final String DEFAULT_CSV_Q_DESC_HEADER = "Bezeichnung"; + public static final String CSV_W_DESC_HEADER = "export.waterlevel.csv.header.w.desc"; + + public static final String CSV_LOCATION_HEADER = "export.waterlevel.csv.header.location"; + + public static final String CSV_GAUGE_HEADER = "export.waterlevel.csv.header.gauge"; + + public static final String CSV_META_RESULT = "export.waterlevel.csv.meta.result"; + + public static final String CSV_META_CREATION = "export.waterlevel.csv.meta.creation"; + + public static final String CSV_META_CALCULATIONBASE = "export.waterlevel.csv.meta.calculationbase"; + + public static final String CSV_META_RIVER = "export.waterlevel.csv.meta.river"; + + public static final String CSV_META_RANGE = "export.waterlevel.csv.meta.range"; + + public static final String CSV_META_GAUGE = "export.waterlevel.csv.meta.gauge"; + + public static final String CSV_META_Q = "export.waterlevel.csv.meta.q"; + + public static final String CSV_META_W = "export.waterlevel.csv.meta.w"; + + public static final String CSV_NOT_IN_GAUGE_RANGE = "export.waterlevel.csv.not.in.gauge.range"; + + public static final Pattern NUMBERS_PATTERN = Pattern.compile("\\D*(\\d++.\\d*)\\D*"); + + public static final String DEFAULT_CSV_KM_HEADER = "Fluss-Km"; + public static final String DEFAULT_CSV_W_HEADER = "W [NN + m]"; + public static final String DEFAULT_CSV_Q_HEADER = "Q [m\u00b3/s]"; /** * @deprecated Use {@link WaterlevelDescriptionBuilder} instead. */ @Deprecated - public static final String DEFAULT_CSV_W_DESC_HEADER = "W/Pegel [cm]"; + public static final String DEFAULT_CSV_Q_DESC_HEADER = "Bezeichnung"; + /** + * @deprecated Use {@link WaterlevelDescriptionBuilder} instead. + */ + @Deprecated + public static final String DEFAULT_CSV_W_DESC_HEADER = "W/Pegel [cm]"; public static final String DEFAULT_CSV_LOCATION_HEADER = "Lage"; - public static final String DEFAULT_CSV_GAUGE_HEADER = "Bezugspegel"; - public static final String DEFAULT_CSV_NOT_IN_GAUGE_RANGE = - "außerhalb des gewählten Bezugspegels"; + public static final String DEFAULT_CSV_GAUGE_HEADER = "Bezugspegel"; + public static final String DEFAULT_CSV_NOT_IN_GAUGE_RANGE = "außerhalb des gewählten Bezugspegels"; public static final String PDF_HEADER_MODE = "export.waterlevel.pdf.mode"; - public static final String JASPER_FILE = "export.waterlevel.pdf.file"; + public static final String JASPER_FILE = "export.waterlevel.pdf.file"; - /** The storage that contains all WQKms objects that are calculated.*/ + /** The storage that contains all WQKms objects that are calculated. */ protected List data; - /** The storage that contains official fixings if available.*/ + /** The storage that contains official fixings if available. */ protected List officalFixings; public WaterlevelExporter() { - data = new ArrayList(); + this.data = new ArrayList<>(); } @Override - public void generate() - throws IOException - { + public void generate() throws IOException { log.debug("WaterlevelExporter.generate"); - /* Check for official fixings. They should also be included in the - * export but only the calculation result is added with addData */ - - officalFixings = new ArrayList(); + /* + * Check for official fixings. They should also be included in the + * export but only the calculation result is added with addData + */ - for (Artifact art: collection.getArtifactsByName( - STATICWQKMSNAME, context) - ) { + this.officalFixings = new ArrayList<>(); + + for (final Artifact art : this.collection.getArtifactsByName(STATICWQKMSNAME, this.context)) { if (art instanceof StaticWQKmsArtifact) { - IsOfficialAccess access = - new IsOfficialAccess((D4EArtifact)art); - StaticWQKmsArtifact sart = (StaticWQKmsArtifact) art; + final IsOfficialAccess access = new IsOfficialAccess((D4EArtifact) art); + final StaticWQKmsArtifact sart = (StaticWQKmsArtifact) art; if (!access.isOfficial()) { continue; } /* Check that we add the data only once */ - WQKms toAdd = sart.getWQKms(); - String newName = toAdd.getName(); + final WQKms toAdd = sart.getWQKms(); + final String newName = toAdd.getName(); boolean exists = false; - for (WQKms wqkm: officalFixings) { - /* The same official fixing could be in two - artifacts/outs so let's deduplicate */ + for (final WQKms wqkm : this.officalFixings) { + /* + * The same official fixing could be in two + * artifacts/outs so let's deduplicate + */ if (wqkm.getName().equals(newName)) { exists = true; } } if (!exists) { - officalFixings.add(toAdd); + this.officalFixings.add(toAdd); log.debug("Adding additional offical fixing: " + newName); } } } - if (facet != null && facet.equals(AbstractExporter.FACET_CSV)) { + if (this.facet != null && this.facet.equals(AbstractExporter.FACET_CSV)) { generateCSV(); - } - else if (facet != null && facet.equals(FACET_WST)) { + } else if (this.facet != null && this.facet.equals(FACET_WST)) { generateWST(); - } - else if (facet != null && facet.equals(AbstractExporter.FACET_PDF)) { + } else if (this.facet != null && this.facet.equals(AbstractExporter.FACET_PDF)) { generatePDF(); - } - else { + } else { throw new IOException("invalid facet for exporter"); } } - @Override protected void addData(Object d) { if (d instanceof CalculationResult) { - d = ((CalculationResult)d).getData(); - if (d instanceof WQKms []) { - data.add((WQKms [])d); - } - else if (d instanceof WQKmsResult) { - data.add(((WQKmsResult) d).getWQKms()); + d = ((CalculationResult) d).getData(); + if (d instanceof WQKms[]) { + this.data.add((WQKms[]) d); + } else if (d instanceof WQKmsResult) { + this.data.add(((WQKmsResult) d).getWQKms()); } } } - /** * Prepare the column titles of waterlevel exports. * Titles in this export include the Q value. If a Q value matches a named @@ -243,13 +211,15 @@ * title. This method resets the name of the wqkms object if such * named main value fits to the chosen Q. * - * @param winfo A WINFO Artifact. - * @param wqkms A WQKms object that should be prepared. + * @param winfo + * A WINFO Artifact. + * @param wqkms + * A WQKms object that should be prepared. */ - protected String getColumnTitle(WINFOArtifact winfo, WQKms wqkms) { + protected String getColumnTitle(final WINFOArtifact winfo, final WQKms wqkms) { log.debug("WaterlevelExporter.getColumnTitle"); - String name = wqkms.getName(); + final String name = wqkms.getName(); log.debug("Name of WQKms = '" + name + "'"); @@ -257,25 +227,25 @@ return name; } - Matcher m = NUMBERS_PATTERN.matcher(name); + final Matcher m = NUMBERS_PATTERN.matcher(name); if (m.matches()) { - String raw = m.group(1); + final String raw = m.group(1); try { - double v = Double.valueOf(raw); + final double v = Double.valueOf(raw); String nmv = RiverUtils.getNamedMainValue(winfo, v); if (nmv != null && nmv.length() > 0) { - nmv = RiverUtils.stripNamedMainValue(nmv); + nmv = RiverUtils.stripNamedMainValue(nmv); nmv += "=" + String.valueOf(v); log.debug("Set named main value '" + nmv + "'"); return nmv; } } - catch (NumberFormatException nfe) { + catch (final NumberFormatException nfe) { // do nothing here } } @@ -283,25 +253,24 @@ return name; } - /** * @deprecated Use {@link WaterlevelDescriptionBuilder} instead. */ @Deprecated - protected String getCSVRowTitle(WINFOArtifact winfo, WQKms wqkms) { + protected String getCSVRowTitle(final WINFOArtifact winfo, final WQKms wqkms) { log.debug("WaterlevelExporter.prepareNamedValue"); - String name = wqkms.getName(); + final String name = wqkms.getName(); log.debug("Name of WQKms = '" + name + "'"); - WQ_MODE wqmode = RiverUtils.getWQMode(winfo); + final WQ_MODE wqmode = RiverUtils.getWQMode(winfo); if (wqmode == WQ_MODE.WFREE || wqmode == WQ_MODE.QGAUGE) { return localizeWQKms(winfo, wqkms); } - Double v = wqkms.getRawValue(); + final Double v = wqkms.getRawValue(); String nmv = RiverUtils.getNamedMainValue(winfo, v); @@ -315,42 +284,38 @@ return localizeWQKms(winfo, wqkms); } - /** * Get a string like 'W=' or 'Q=' with a number following in localized * format. - * + * * @deprecated Use {@link WaterlevelDescriptionBuilder} instead. */ @Deprecated - protected String localizeWQKms(WINFOArtifact winfo, WQKms wqkms) { - WQ_MODE wqmode = RiverUtils.getWQMode(winfo); - Double rawValue = wqkms.getRawValue(); + protected String localizeWQKms(final WINFOArtifact winfo, final WQKms wqkms) { + final WQ_MODE wqmode = RiverUtils.getWQMode(winfo); + final Double rawValue = wqkms.getRawValue(); if (rawValue == null) { return wqkms.getName(); } - NumberFormat nf = Formatter.getRawFormatter(context); + final NumberFormat nf = Formatter.getRawFormatter(this.context); if (wqmode == WQ_MODE.WFREE || wqmode == WQ_MODE.WGAUGE) { return "W=" + nf.format(rawValue); - } - else { + } else { return "Q=" + nf.format(rawValue); } } - @Override - protected void writeCSVData(CSVWriter writer) { + protected void writeCSVData(final CSVWriter writer) { log.info("WaterlevelExporter.writeData"); - WQ_MODE mode = RiverUtils.getWQMode((D4EArtifact)master); - boolean atGauge = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.WGAUGE; - boolean isQ = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.QFREE; - RiverUtils.WQ_INPUT input - = RiverUtils.getWQInputMode((D4EArtifact)master); + final WQ_MODE mode = RiverUtils.getWQMode((D4EArtifact) this.master); + final boolean atGauge = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.WGAUGE; + final boolean isQ = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.QFREE; + final RiverUtils.WQ_INPUT input = RiverUtils.getWQInputMode((D4EArtifact) this.master); writeCSVMeta(writer); writeCSVHeader(writer, atGauge, isQ); @@ -358,19 +323,21 @@ Double first = Double.NaN; Double last = Double.NaN; - for (WQKms[] tmp: data) { - for (WQKms wqkms: tmp) { + for (final WQKms[] tmp : this.data) { + for (final WQKms wqkms : tmp) { wQKms2CSV(writer, wqkms, atGauge, isQ); - double[] firstLast = wqkms.getFirstLastKM(); + final double[] firstLast = wqkms.getFirstLastKM(); if (first.isNaN()) { /* Initialize */ first = firstLast[0]; last = firstLast[1]; } if (firstLast[0] > firstLast[1]) { - /* Calculating upstream we assert that it is + /* + * Calculating upstream we assert that it is * impossible that the direction changes during this - * loop */ + * loop + */ first = Math.max(first, firstLast[0]); last = Math.min(last, firstLast[1]); } else if (firstLast[0] < firstLast[1]) { @@ -382,35 +349,38 @@ } } /* Append the official fixing at the bottom */ - for (WQKms wqkms: officalFixings) { + for (final WQKms wqkms : this.officalFixings) { wQKms2CSV(writer, filterWQKms(wqkms, first, last), atGauge, isQ); } } - - /** Filter a wqkms object to a distance. + /** + * Filter a wqkms object to a distance. * * To handle upstream / downstream and to limit * the officialFixings to the calculation distance * we create a new wqkms object here and fill it only * with the relevant data. * - * @param wqkms: The WQKms Object to filter - * @param first: The fist kilometer of the range - * @param last: The last kilometer of the range + * @param wqkms: + * The WQKms Object to filter + * @param first: + * The fist kilometer of the range + * @param last: + * The last kilometer of the range * * @return A new WQKms with the relevant data sorted by direction */ - private WQKms filterWQKms(WQKms wqkms, Double first, Double last) { + private WQKms filterWQKms(final WQKms wqkms, final Double first, final Double last) { if (first.isNaN() || last.isNaN()) { log.warn("Filtering official fixing without valid first/last."); return wqkms; } - int firstIdx = first > last ? wqkms.size() - 1 : 0; - int lastIdx = first > last ? 0 : wqkms.size() -1; - WQKms filtered = new WQKms (wqkms.size()); + final int firstIdx = first > last ? wqkms.size() - 1 : 0; + final int lastIdx = first > last ? 0 : wqkms.size() - 1; + final WQKms filtered = new WQKms(wqkms.size()); filtered.setName(wqkms.getName()); - double [] dp = new double [3]; + double[] dp = new double[3]; if (first > last) { for (int i = wqkms.size() - 1; i >= 0; i--) { @@ -430,172 +400,101 @@ return filtered; } - - protected void writeCSVMeta(CSVWriter writer) { + protected void writeCSVMeta(final CSVWriter writer) { log.info("WaterlevelExporter.writeCSVMeta"); // TODO use Access instead of RiverUtils - CallMeta meta = context.getMeta(); - - D4EArtifact flys = (D4EArtifact) master; - - writer.writeNext(new String[] { - Resources.getMsg( - meta, - CSV_META_RESULT, - CSV_META_RESULT, - new Object[] { RiverUtils.getRivername(flys) }) - }); + final CallMeta meta = this.context.getMeta(); - Locale locale = Resources.getLocale(meta); - DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); + final D4EArtifact flys = (D4EArtifact) this.master; - writer.writeNext(new String[] { - Resources.getMsg( - meta, - CSV_META_CREATION, - CSV_META_CREATION, - new Object[] { df.format(new Date()) }) - }); + writer.writeNext(new String[] { Resources.getMsg(meta, CSV_META_RESULT, CSV_META_RESULT, new Object[] { RiverUtils.getRivername(flys) }) }); - writer.writeNext(new String[] { - Resources.getMsg( - meta, - CSV_META_CALCULATIONBASE, - CSV_META_CALCULATIONBASE, - new Object[] { "" }) // TODO what is required at this place? + final Locale locale = Resources.getLocale(meta); + final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); + + writer.writeNext(new String[] { Resources.getMsg(meta, CSV_META_CREATION, CSV_META_CREATION, new Object[] { df.format(new Date()) }) }); + + writer.writeNext(new String[] { Resources.getMsg(meta, CSV_META_CALCULATIONBASE, CSV_META_CALCULATIONBASE, new Object[] { "" }) // TODO what is required + // at this place? }); - writer.writeNext(new String[] { - Resources.getMsg( - meta, - CSV_META_RIVER, - CSV_META_RIVER, - new Object[] { RiverUtils.getRivername(flys) }) - }); + writer.writeNext(new String[] { Resources.getMsg(meta, CSV_META_RIVER, CSV_META_RIVER, new Object[] { RiverUtils.getRivername(flys) }) }); - RangeAccess rangeAccess = new RangeAccess(flys); - double[] kms = rangeAccess.getKmRange(); - writer.writeNext(new String[] { - Resources.getMsg( - meta, - CSV_META_RANGE, - CSV_META_RANGE, - new Object[] { kms[0], kms[kms.length-1] }) - }); + final RangeAccess rangeAccess = new RangeAccess(flys); + final double[] kms = rangeAccess.getKmRange(); + writer.writeNext(new String[] { Resources.getMsg(meta, CSV_META_RANGE, CSV_META_RANGE, new Object[] { kms[0], kms[kms.length - 1] }) }); - writer.writeNext(new String[] { - Resources.getMsg( - meta, - CSV_META_GAUGE, - CSV_META_GAUGE, - new Object[] { RiverUtils.getGaugename(flys) }) - }); + writer.writeNext(new String[] { Resources.getMsg(meta, CSV_META_GAUGE, CSV_META_GAUGE, new Object[] { RiverUtils.getGaugename(flys) }) }); // TODO: code extracted into WaterlevelDescriptionBuilder, should be used instead. - RiverUtils.WQ_MODE wq = RiverUtils.getWQMode(flys); + final RiverUtils.WQ_MODE wq = RiverUtils.getWQMode(flys); if (wq == RiverUtils.WQ_MODE.QFREE || wq == RiverUtils.WQ_MODE.QGAUGE) { - double[] qs = RiverUtils.getQs(flys); - RiverUtils.WQ_INPUT input = RiverUtils.getWQInputMode(flys); + final double[] qs = RiverUtils.getQs(flys); + final RiverUtils.WQ_INPUT input = RiverUtils.getWQInputMode(flys); String data = ""; - if ((input == RiverUtils.WQ_INPUT.ADAPTED || - input == RiverUtils.WQ_INPUT.RANGE) && - qs != null && qs.length > 0) - { + if ((input == RiverUtils.WQ_INPUT.ADAPTED || input == RiverUtils.WQ_INPUT.RANGE) && qs != null && qs.length > 0) { data = String.valueOf(qs[0]); - data += " - " + String.valueOf(qs[qs.length-1]); - } - else if (input == RiverUtils.WQ_INPUT.SINGLE && qs != null){ + data += " - " + String.valueOf(qs[qs.length - 1]); + } else if (input == RiverUtils.WQ_INPUT.SINGLE && qs != null) { data = String.valueOf(qs[0]); for (int i = 1; i < qs.length; i++) { data += ", " + String.valueOf(qs[i]); } - } - else { + } else { log.warn("Could not determine Q range!"); } - writer.writeNext(new String[] { - Resources.getMsg( - meta, - CSV_META_Q, - CSV_META_Q, - new Object[] {data}) - }); - } - else { - double[] ws = RiverUtils.getWs(flys); + writer.writeNext(new String[] { Resources.getMsg(meta, CSV_META_Q, CSV_META_Q, new Object[] { data }) }); + } else { + final double[] ws = RiverUtils.getWs(flys); String lower = ""; String upper = ""; if (ws != null && ws.length > 0) { lower = String.valueOf(ws[0]); - upper = String.valueOf(ws[ws.length-1]); - } - else { + upper = String.valueOf(ws[ws.length - 1]); + } else { log.warn("Could not determine W range!"); } - writer.writeNext(new String[] { - Resources.getMsg( - meta, - CSV_META_W, - CSV_META_W, - new Object[] { lower, upper }) - }); + writer.writeNext(new String[] { Resources.getMsg(meta, CSV_META_W, CSV_META_W, new Object[] { lower, upper }) }); } writer.writeNext(new String[] { "" }); } - /** * Write the header, with different headings depending on whether at a * gauge or at a location. */ - protected void writeCSVHeader( - CSVWriter writer, - boolean atGauge, - boolean isQ - ) { + protected void writeCSVHeader(final CSVWriter writer, final boolean atGauge, final boolean isQ) { log.info("WaterlevelExporter.writeCSVHeader"); - String unit = RiverUtils.getRiver( - (D4EArtifact) master).getWstUnit().getName(); + final String unit = RiverUtils.getRiver((D4EArtifact) this.master).getWstUnit().getName(); if (atGauge) { - writer.writeNext(new String[] { - msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), - msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { unit }), - msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER), - - // FIXME: use WaterlevelDescriptionBuilder instead and also remove all this duplicate code. - (isQ - ? msg(CSV_Q_DESC_HEADER, DEFAULT_CSV_Q_DESC_HEADER) - : msg(CSV_W_DESC_HEADER, DEFAULT_CSV_W_DESC_HEADER)), - msg(CSV_LOCATION_HEADER, DEFAULT_CSV_LOCATION_HEADER), - msg(CSV_GAUGE_HEADER, DEFAULT_CSV_GAUGE_HEADER) - }); - } - else { - writer.writeNext(new String[] { - msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), + writer.writeNext(new String[] { msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { unit }), + msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER), + + // FIXME: use WaterlevelDescriptionBuilder instead and also remove all this duplicate code. + (isQ ? msg(CSV_Q_DESC_HEADER, DEFAULT_CSV_Q_DESC_HEADER) : msg(CSV_W_DESC_HEADER, DEFAULT_CSV_W_DESC_HEADER)), + msg(CSV_LOCATION_HEADER, DEFAULT_CSV_LOCATION_HEADER), msg(CSV_GAUGE_HEADER, DEFAULT_CSV_GAUGE_HEADER) }); + } else { + writer.writeNext(new String[] { msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), // TODO flys/issue1128 (unit per river) - msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { unit }), - msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER), - msg(CSV_LOCATION_HEADER, DEFAULT_CSV_LOCATION_HEADER) - }); + msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { unit }), msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER), + msg(CSV_LOCATION_HEADER, DEFAULT_CSV_LOCATION_HEADER) }); } } - /** Linearly search for gauge which is valid at km. */ - private static Gauge findGauge(double km, List gauges) { - for (Gauge gauge: gauges) { + private static Gauge findGauge(final double km, final List gauges) { + for (final Gauge gauge : gauges) { if (gauge.getRange().contains(km)) { return gauge; } @@ -603,8 +502,8 @@ return null; } - private static Segment findSegment(double km, List segments) { - for (Segment segment: segments) { + private static Segment findSegment(final double km, final List segments) { + for (final Segment segment : segments) { if (segment.inside(km)) { return segment; } @@ -612,70 +511,55 @@ return null; } - - private void writeRow4(CSVWriter writer, double wqkm[], D4EArtifact flys) { - NumberFormat kmf = getKmFormatter(); - NumberFormat wf = getWFormatter(); - NumberFormat qf = getQFormatter(); - writer.writeNext(new String[] { - kmf.format(wqkm[2]), - wf.format(wqkm[0]), - qf.format(RiverUtils.roundQ(wqkm[1])), - RiverUtils.getLocationDescription(flys, wqkm[2]) - }); + private void writeRow4(final CSVWriter writer, final double wqkm[], final D4EArtifact flys) { + final NumberFormat kmf = getKmFormatter(); + final NumberFormat wf = getWFormatter(); + final NumberFormat qf = getQFormatter(); + writer.writeNext(new String[] { kmf.format(wqkm[2]), wf.format(wqkm[0]), qf.format(RiverUtils.roundQ(wqkm[1])), + RiverUtils.getLocationDescription(flys, wqkm[2]) }); } /** Write an csv-row at gauge location. */ - private void writeRow6(CSVWriter writer, double wqkm[], String wOrQDesc, - D4EArtifact flys, String gaugeName) { - NumberFormat kmf = getKmFormatter(); - NumberFormat wf = getWFormatter(); - NumberFormat qf = getQFormatter(); + private void writeRow6(final CSVWriter writer, final double wqkm[], final String wOrQDesc, final D4EArtifact flys, final String gaugeName) { + final NumberFormat kmf = getKmFormatter(); + final NumberFormat wf = getWFormatter(); + final NumberFormat qf = getQFormatter(); - writer.writeNext(new String[] { - kmf.format(wqkm[2]), - wf.format(wqkm[0]), - qf.format(RiverUtils.roundQ(wqkm[1])), - wOrQDesc, - RiverUtils.getLocationDescription(flys, wqkm[2]), - gaugeName - }); + writer.writeNext(new String[] { kmf.format(wqkm[2]), wf.format(wqkm[0]), qf.format(RiverUtils.roundQ(wqkm[1])), wOrQDesc, + RiverUtils.getLocationDescription(flys, wqkm[2]), gaugeName }); } /** * @deprecated Use {@link WaterlevelDescriptionBuilder} instead. */ @Deprecated - private String getDesc(WQKms wqkms, boolean isQ) - { - D4EArtifact flys = (D4EArtifact) master; + private String getDesc(final WQKms wqkms, final boolean isQ) { + final D4EArtifact flys = (D4EArtifact) this.master; String colDesc = ""; if (flys instanceof WINFOArtifact && isQ) { - colDesc = getCSVRowTitle((WINFOArtifact)flys, wqkms); - } - else if (!isQ) { - Double value = RiverUtils.getValueFromWQ(wqkms); - colDesc = (value != null) ? - Formatter.getWaterlevelW(context).format(value) : null; + colDesc = getCSVRowTitle((WINFOArtifact) flys, wqkms); + } else if (!isQ) { + final Double value = RiverUtils.getValueFromWQ(wqkms); + colDesc = (value != null) ? Formatter.getWaterlevelW(this.context).format(value) : null; } if (flys instanceof WINFOArtifact) { if (wqkms != null && wqkms.getRawValue() != null) { - WINFOArtifact winfo = (WINFOArtifact) flys; - colDesc = RiverUtils.getNamedMainValue( - winfo, wqkms.getRawValue()); + final WINFOArtifact winfo = (WINFOArtifact) flys; + colDesc = RiverUtils.getNamedMainValue(winfo, wqkms.getRawValue()); // For 'W am Pegel' s if (colDesc == null) { - Double value = RiverUtils.getValueFromWQ(wqkms); - colDesc = (value != null) ? - Formatter.getWaterlevelW(context).format(value) : null; + final Double value = RiverUtils.getValueFromWQ(wqkms); + colDesc = (value != null) ? Formatter.getWaterlevelW(this.context).format(value) : null; } } } if (colDesc != null) { - /* Quick hack. Can be removed when database strings are - * adapted or left in here as it should never be harmful. */ + /* + * Quick hack. Can be removed when database strings are + * adapted or left in here as it should never be harmful. + */ colDesc = colDesc.replace("Amtl.Festlegung_", "Amtl. "); } @@ -685,12 +569,7 @@ /** * Write "rows" of csv data from wqkms with writer. */ - protected void wQKms2CSV( - CSVWriter writer, - WQKms wqkms, - boolean atGauge, - boolean isQ - ) { + protected void wQKms2CSV(final CSVWriter writer, final WQKms wqkms, final boolean atGauge, final boolean isQ) { log.debug("WaterlevelExporter.wQKms2CSV"); // Skip constant data. @@ -698,38 +577,35 @@ return; } - NumberFormat kmf = getKmFormatter(); - NumberFormat wf = getWFormatter(); - NumberFormat qf = getQFormatter(); + final NumberFormat kmf = getKmFormatter(); + final NumberFormat wf = getWFormatter(); + final NumberFormat qf = getQFormatter(); - int size = wqkms.size(); + final int size = wqkms.size(); double[] result = new double[3]; - D4EArtifact flys = (D4EArtifact) master; - RangeAccess rangeAccess = new RangeAccess(flys); - - List gauges = RiverUtils.getGauges(flys); + final D4EArtifact flys = (D4EArtifact) this.master; + final RangeAccess rangeAccess = new RangeAccess(flys); - Gauge gauge = rangeAccess.getRiver().determineRefGauge( - rangeAccess.getKmRange(), rangeAccess.isRange()); + final List gauges = RiverUtils.getGauges(flys); - String gaugeName = gauge.getName(); - String desc = ""; - String notinrange = msg( - CSV_NOT_IN_GAUGE_RANGE, - DEFAULT_CSV_NOT_IN_GAUGE_RANGE); + final Gauge gauge = rangeAccess.getRiver().determineRefGauge(rangeAccess.getKmRange(), rangeAccess.isRange()); + + final String gaugeName = gauge.getName(); + String desc = ""; + final String notinrange = msg(CSV_NOT_IN_GAUGE_RANGE, DEFAULT_CSV_NOT_IN_GAUGE_RANGE); List segments = null; boolean isFixRealize = false; - double a = gauge.getRange().getA().doubleValue(); - double b = gauge.getRange().getB().doubleValue(); - long startTime = System.currentTimeMillis(); + final double a = gauge.getRange().getA().doubleValue(); + final double b = gauge.getRange().getB().doubleValue(); + final long startTime = System.currentTimeMillis(); desc = getDesc(wqkms, isQ); if (flys instanceof FixationArtifact) { // Get W/Q input per gauge for this case. - FixRealizingAccess fixAccess = new FixRealizingAccess(flys); + final FixRealizingAccess fixAccess = new FixRealizingAccess(flys); segments = fixAccess.getSegments(); if (segments != null && !segments.isEmpty()) { isFixRealize = true; @@ -741,20 +617,16 @@ // Kms tend to be close together so caching the last sector // is a good time saving heuristic. Segment lastSegment = null; - Gauge lastGauge = null; + Gauge lastGauge = null; - NumberFormat nf = - Formatter.getFormatter(context.getMeta(), 0, 0); + final NumberFormat nf = Formatter.getFormatter(this.context.getMeta(), 0, 0); for (int i = 0; i < size; ++i) { result = wqkms.get(i, result); - double km = result[2]; + final double km = result[2]; if (segments != null) { - Segment found = lastSegment != null - && lastSegment.inside(km) - ? lastSegment - : findSegment(km, segments); + final Segment found = lastSegment != null && lastSegment.inside(km) ? lastSegment : findSegment(km, segments); if (found != null) { desc = nf.format(found.getValues()[0]); @@ -764,67 +636,55 @@ String gaugeN; if (isFixRealize) { - Gauge found = lastGauge != null - && lastGauge.getRange().contains(km) - ? lastGauge - : findGauge(km, gauges); + final Gauge found = lastGauge != null && lastGauge.getRange().contains(km) ? lastGauge : findGauge(km, gauges); gaugeN = found != null ? found.getName() : notinrange; lastGauge = found; - } - else { + } else { // TODO issue1114: Take correct gauge - gaugeN = km >= a && km <= b - ? gaugeName - : notinrange; + gaugeN = km >= a && km <= b ? gaugeName : notinrange; } writeRow6(writer, result, desc, flys, gaugeN); } - } - else { // Not at gauge. + } else { // Not at gauge. for (int i = 0; i < size; ++i) { result = wqkms.get(i, result); writeRow4(writer, result, flys); } } - long stopTime = System.currentTimeMillis(); + final long stopTime = System.currentTimeMillis(); if (log.isDebugEnabled()) { - log.debug("Writing CSV took " + - (float)(stopTime-startTime)/1000f + " secs."); + log.debug("Writing CSV took " + (stopTime - startTime) / 1000f + " secs."); } } - /** * Generates the output in WST format. */ - protected void generateWST() - throws IOException - { + protected void generateWST() throws IOException { log.info("WaterlevelExporter.generateWST"); - int cols = data.get(0).length + officalFixings.size(); - WstWriter writer = new WstWriter(cols); + final int cols = this.data.get(0).length + this.officalFixings.size(); + final WstWriter writer = new WstWriter(cols); writeWSTData(writer); - writer.write(out); + writer.write(this.out); } - - protected void writeWSTData(WstWriter writer) { + protected void writeWSTData(final WstWriter writer) { log.debug("WaterlevelExporter.writeWSTData"); double[] result = new double[4]; - for (WQKms[] tmp: data) { - for (WQKms wqkms: tmp) { + for (final WQKms[] tmp : this.data) { + for (final WQKms wqkms : tmp) { if (wqkms instanceof ConstantWQKms) { continue; } - int size = wqkms != null ? wqkms.size() : 0; + final int size = wqkms != null ? wqkms.size() : 0; addWSTColumn(writer, wqkms); @@ -850,21 +710,21 @@ // // There was some confusion how to implement this. see flys/issue1620 // for details. - for (WQKms wqkms: officalFixings) { + for (final WQKms wqkms : this.officalFixings) { // To add some spaces here or to add them in the writer,.. writer.addColumn(getDesc(wqkms, true)); // Get all lines from the calculation - Map calcLines = writer.getLines(); + final Map calcLines = writer.getLines(); // All KM values where we have a point for - TDoubleArrayList officialKms = wqkms.allKms(); + final TDoubleArrayList officialKms = wqkms.allKms(); - for (Map.Entry entry : calcLines.entrySet()) { + for (final Map.Entry entry : calcLines.entrySet()) { // Bad for perfomance but the user can wait a bit for WST // so lets not spend time optimizing too much,.. *hides* - double km = entry.getKey().doubleValue(); - int idx = officialKms.indexOf(km); + final double km = entry.getKey().doubleValue(); + final int idx = officialKms.indexOf(km); if (idx != -1) { entry.getValue().add(wqkms.getW(idx), wqkms.getQ(idx)); } @@ -872,7 +732,6 @@ } } - /** * Register a new column at writer. The name / * title of the column depends on the Q or W value of wqkms. If a Q @@ -880,72 +739,68 @@ * the named main value. Otherwise, the name returned by * WQKms.getName() is set. * - * @param writer The WstWriter. - * @param wqkms The new WST column. + * @param writer + * The WstWriter. + * @param wqkms + * The new WST column. */ - protected void addWSTColumn(WstWriter writer, WQKms wqkms) { + protected void addWSTColumn(final WstWriter writer, final WQKms wqkms) { if (wqkms instanceof ConstantWQKms) { return; } - if (master instanceof WINFOArtifact) { - writer.addColumn(getColumnTitle((WINFOArtifact) master, wqkms)); - } - else { + if (this.master instanceof WINFOArtifact) { + writer.addColumn(getColumnTitle((WINFOArtifact) this.master, wqkms)); + } else { writer.addColumn(wqkms.getName()); } } - @Override - protected void writePDF(OutputStream out) { + protected void writePDF(final OutputStream out) { log.debug("write PDF"); - WKmsJRDataSource source = createJRData(); + final WKmsJRDataSource source = createJRData(); - String jasperFile = Resources.getMsg( - context.getMeta(), - JASPER_FILE, - "/jasper/waterlevel_en.jasper"); - String confPath = Config.getConfigDirectory().toString(); + final String jasperFile = // "/jasper/waterlevel_en.jasper"; + Resources.getMsg(this.context.getMeta(), JASPER_FILE, "/jasper/waterlevel_en.jasper"); + final String confPath = Config.getConfigDirectory().toString(); - - Map parameters = new HashMap(); + final Map parameters = new HashMap(); parameters.put("ReportTitle", "Exported Data"); try { - JasperPrint print = JasperFillManager.fillReport( - confPath + jasperFile, - parameters, - source); + final JasperPrint print = JasperFillManager.fillReport(confPath + jasperFile, parameters, source); JasperExportManager.exportReportToPdfStream(print, out); } - catch(JRException je) { + catch (final JRException je) { log.warn("Error generating PDF Report!", je); } } protected WKmsJRDataSource createJRData() { - WKmsJRDataSource source = new WKmsJRDataSource(); + final WKmsJRDataSource source = new WKmsJRDataSource(); - WQ_MODE mode = RiverUtils.getWQMode((D4EArtifact)master); - boolean atGauge = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.WGAUGE; - boolean isQ = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.QFREE; + final WQ_MODE mode = RiverUtils.getWQMode((D4EArtifact) this.master); + final boolean atGauge = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.WGAUGE; + final boolean isQ = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.QFREE; Double first = Double.NaN; Double last = Double.NaN; addMetaData(source); - for (WQKms[] tmp: data) { - for (WQKms wqkms: tmp) { + for (final WQKms[] tmp : this.data) { + for (final WQKms wqkms : tmp) { addWKmsData(wqkms, atGauge, isQ, source); - double[] firstLast = wqkms.getFirstLastKM(); + final double[] firstLast = wqkms.getFirstLastKM(); if (first.isNaN()) { /* Initialize */ first = firstLast[0]; last = firstLast[1]; } if (firstLast[0] > firstLast[1]) { - /* Calculating upstream we assert that it is + /* + * Calculating upstream we assert that it is * impossible that the direction changes during this - * loop */ + * loop + */ first = Math.max(first, firstLast[0]); last = Math.min(last, firstLast[1]); } else if (firstLast[0] < firstLast[1]) { @@ -958,44 +813,35 @@ } /* Append the official fixing at the bottom */ - for (WQKms wqkms: officalFixings) { + for (final WQKms wqkms : this.officalFixings) { addWKmsData(filterWQKms(wqkms, first, last), atGauge, isQ, source); } return source; } - protected void addMetaData(WKmsJRDataSource source) { - CallMeta meta = context.getMeta(); - - D4EArtifact flys = (D4EArtifact) master; + protected void addMetaData(final WKmsJRDataSource source) { + final CallMeta meta = this.context.getMeta(); - source.addMetaData ("river", RiverUtils.getRivername(flys)); + final D4EArtifact flys = (D4EArtifact) this.master; - Locale locale = Resources.getLocale(meta); - DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); - NumberFormat kmf = getKmFormatter(); + source.addMetaData("river", RiverUtils.getRivername(flys)); + + final Locale locale = Resources.getLocale(meta); + final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); + final NumberFormat kmf = getKmFormatter(); source.addMetaData("date", df.format(new Date())); - RangeAccess rangeAccess = new RangeAccess(flys); - double[] kms = rangeAccess.getKmRange(); - source.addMetaData("range", - kmf.format(kms[0]) + " - " + kmf.format(kms[kms.length-1])); + final RangeAccess rangeAccess = new RangeAccess(flys); + final double[] kms = rangeAccess.getKmRange(); + source.addMetaData("range", kmf.format(kms[0]) + " - " + kmf.format(kms[kms.length - 1])); source.addMetaData("gauge", RiverUtils.getGaugename(flys)); - source.addMetaData("calculation", Resources.getMsg( - locale, - PDF_HEADER_MODE, - "Waterlevel")); + source.addMetaData("calculation", Resources.getMsg(locale, PDF_HEADER_MODE, "Waterlevel")); } - protected void addWKmsData( - WQKms wqkms, - boolean atGauge, - boolean isQ, - WKmsJRDataSource source) - { + protected void addWKmsData(final WQKms wqkms, final boolean atGauge, final boolean isQ, final WKmsJRDataSource source) { log.debug("WaterlevelExporter.addWKmsData"); // Skip constant data. @@ -1003,65 +849,44 @@ return; } - NumberFormat kmf = getKmFormatter(); - NumberFormat wf = getWFormatter(); - NumberFormat qf = getQFormatter(); + final NumberFormat kmf = getKmFormatter(); + final NumberFormat wf = getWFormatter(); + final NumberFormat qf = getQFormatter(); - int size = wqkms.size(); + final int size = wqkms.size(); double[] result = new double[3]; - D4EArtifact flys = (D4EArtifact) master; - RangeAccess rangeAccess = new RangeAccess(flys); - - Gauge gauge = rangeAccess.getRiver().determineRefGauge( - rangeAccess.getKmRange(), rangeAccess.isRange()); + final D4EArtifact flys = (D4EArtifact) this.master; + final RangeAccess rangeAccess = new RangeAccess(flys); - String gaugeName = gauge.getName(); - String desc = ""; - String notinrange = msg( - CSV_NOT_IN_GAUGE_RANGE, - DEFAULT_CSV_NOT_IN_GAUGE_RANGE); + final Gauge gauge = rangeAccess.getRiver().determineRefGauge(rangeAccess.getKmRange(), rangeAccess.isRange()); - double a = gauge.getRange().getA().doubleValue(); - double b = gauge.getRange().getB().doubleValue(); + final String gaugeName = gauge.getName(); + String desc = ""; + final String notinrange = msg(CSV_NOT_IN_GAUGE_RANGE, DEFAULT_CSV_NOT_IN_GAUGE_RANGE); + + final double a = gauge.getRange().getA().doubleValue(); + final double b = gauge.getRange().getB().doubleValue(); desc = getDesc(wqkms, isQ); - long startTime = System.currentTimeMillis(); + final long startTime = System.currentTimeMillis(); - for (int i = 0; i < size; i ++) { + for (int i = 0; i < size; i++) { result = wqkms.get(i, result); if (atGauge) { - source.addData(new String[] { - kmf.format(result[2]), - wf.format(result[0]), - qf.format(RiverUtils.roundQ(result[1])), - desc, - RiverUtils.getLocationDescription(flys, result[2]), - result[2] >= a && result[2] <= b - ? gaugeName - : notinrange - }); - } - else { - source.addData(new String[] { - kmf.format(result[2]), - wf.format(result[0]), - qf.format(RiverUtils.roundQ(result[1])), - desc, - RiverUtils.getLocationDescription(flys, result[2]), - result[2] >= a && result[2] <= b - ? gaugeName - : notinrange - }); + source.addData(new String[] { kmf.format(result[2]), wf.format(result[0]), qf.format(RiverUtils.roundQ(result[1])), desc, + RiverUtils.getLocationDescription(flys, result[2]), result[2] >= a && result[2] <= b ? gaugeName : notinrange }); + } else { + source.addData(new String[] { kmf.format(result[2]), wf.format(result[0]), qf.format(RiverUtils.roundQ(result[1])), desc, + RiverUtils.getLocationDescription(flys, result[2]), result[2] >= a && result[2] <= b ? gaugeName : notinrange }); } } - long stopTime = System.currentTimeMillis(); + final long stopTime = System.currentTimeMillis(); if (log.isDebugEnabled()) { - log.debug("Writing PDF data took " + - (float)(stopTime-startTime)/1000f + " secs."); + log.debug("Writing PDF data took " + (stopTime - startTime) / 1000f + " secs."); } } } diff -r a0feac6ea1ba -r 42c15e2f95fb artifacts/src/main/java/org/dive4elements/river/exports/fixings/DeltaWtExporter.java --- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/DeltaWtExporter.java Fri May 25 09:10:19 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/DeltaWtExporter.java Fri May 25 10:44:24 2018 +0200 @@ -8,63 +8,48 @@ package org.dive4elements.river.exports.fixings; -import au.com.bytecode.opencsv.CSVWriter; - -import org.dive4elements.artifacts.CallMeta; - -import org.dive4elements.river.artifacts.model.CalculationResult; - -import org.dive4elements.river.artifacts.model.fixings.AnalysisPeriod; -import org.dive4elements.river.artifacts.model.fixings.FixAnalysisResult; -import org.dive4elements.river.artifacts.model.fixings.QWD; - -import org.dive4elements.river.artifacts.resources.Resources; - -import org.dive4elements.river.exports.AbstractExporter; - -import org.dive4elements.river.utils.Formatter; -import org.dive4elements.river.utils.KMIndex; - import java.io.IOException; import java.io.OutputStream; - import java.text.DateFormat; import java.text.MessageFormat; import java.text.NumberFormat; - import java.util.ArrayList; import java.util.List; import java.util.TreeMap; import org.apache.log4j.Logger; +import org.dive4elements.artifacts.CallMeta; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.access.RiverAccess; +import org.dive4elements.river.artifacts.model.CalculationResult; +import org.dive4elements.river.artifacts.model.fixings.AnalysisPeriod; +import org.dive4elements.river.artifacts.model.fixings.FixAnalysisResult; +import org.dive4elements.river.artifacts.model.fixings.QWD; +import org.dive4elements.river.artifacts.resources.Resources; +import org.dive4elements.river.exports.AbstractExporter; +import org.dive4elements.river.utils.Formatter; +import org.dive4elements.river.utils.KMIndex; + +import au.com.bytecode.opencsv.CSVWriter; /** Exports fixation analysis deltaw(t) computation results to csv. */ -public class DeltaWtExporter -extends AbstractExporter -{ +public class DeltaWtExporter extends AbstractExporter { /** Private log. */ private static Logger log = Logger.getLogger(DeltaWtExporter.class); - public static final String CSV_KM_HEADER = - "export.fixings.deltawt.csv.header.km"; - - public static final String CSV_DELTA_W_HEADER = - "export.fixings.deltawt.csv.header.deltaw"; - - public static final String CSV_Q_HEADER = - "export.fixings.deltawt.csv.header.q"; + public static final String CSV_KM_HEADER = "export.fixings.deltawt.csv.header.km"; - public static final String CSV_W_HEADER = - "export.fixings.deltawt.csv.header.w"; + public static final String CSV_DELTA_W_HEADER = "export.fixings.deltawt.csv.header.deltaw"; - public static final String CSV_TRANGE_HEADER = - "export.fixings.deltawt.csv.header.time.range"; + public static final String CSV_Q_HEADER = "export.fixings.deltawt.csv.header.q"; - public static final String CSV_T_HEADER = - "export.fixings.deltawt.csv.header.t"; + public static final String CSV_W_HEADER = "export.fixings.deltawt.csv.header.w"; - public static final String CSV_T_FORMAT = - "export.fixings.deltawt.csv.t.format"; + public static final String CSV_TRANGE_HEADER = "export.fixings.deltawt.csv.header.time.range"; + + public static final String CSV_T_HEADER = "export.fixings.deltawt.csv.header.t"; + + public static final String CSV_T_FORMAT = "export.fixings.deltawt.csv.t.format"; public static final String DEFAULT_CSV_KM_HEADER = "km"; @@ -76,143 +61,122 @@ public static final String DEFAULT_CSV_T_HEADER = "Datum"; - public static final String DEFAULT_CSV_TRANGE_DESC_HEADER = - "Status"; - - public static final String CSV_REFERENCE = - "export.fixings.deltawt.csv.reference"; - - public static final String CSV_ANALYSIS = - "export.fixings.deltawt.csv.analysis"; + public static final String DEFAULT_CSV_TRANGE_DESC_HEADER = "Status"; - public static final String DEFAULT_CSV_REFERENCE = - "B"; + public static final String CSV_REFERENCE = "export.fixings.deltawt.csv.reference"; - public static final String DEFAULT_CSV_ANALYSIS = - "A{0,number,integer}"; + public static final String CSV_ANALYSIS = "export.fixings.deltawt.csv.analysis"; - public static final String DEFAULT_CSV_T_FORMAT = - "dd.MM.yyyy"; + public static final String DEFAULT_CSV_REFERENCE = "B"; - protected List> analysisPeriods; + public static final String DEFAULT_CSV_ANALYSIS = "A{0,number,integer}"; + + public static final String DEFAULT_CSV_T_FORMAT = "dd.MM.yyyy"; + + protected List> analysisPeriods; protected List> referenceEvents; public DeltaWtExporter() { - analysisPeriods = new ArrayList>(); - referenceEvents = new ArrayList>(); + this.analysisPeriods = new ArrayList<>(); + this.referenceEvents = new ArrayList<>(); } @Override - protected void addData(Object d) { + protected void addData(final Object d) { log.debug("DeltaWtExporter.addData"); if (!(d instanceof CalculationResult)) { log.warn("Invalid data type"); return; } - Object data = ((CalculationResult)d).getData(); + final Object data = ((CalculationResult) d).getData(); if (!(data instanceof FixAnalysisResult)) { log.warn("Invalid data stored in result."); } - FixAnalysisResult result = (FixAnalysisResult)data; - analysisPeriods.add(result.getAnalysisPeriods()); - referenceEvents.add(result.getReferenced()); + final FixAnalysisResult result = (FixAnalysisResult) data; + this.analysisPeriods.add(result.getAnalysisPeriods()); + this.referenceEvents.add(result.getReferenced()); } @Override - protected void writeCSVData(CSVWriter writer) throws IOException { + protected void writeCSVData(final CSVWriter writer) throws IOException { - boolean debug = log.isDebugEnabled(); + final boolean debug = log.isDebugEnabled(); writeCSVHeader(writer); - NumberFormat kmF = getKMFormatter(); - NumberFormat dwF = getDeltaWFormatter(); - NumberFormat qF = getQFormatter(); - NumberFormat wF = getWFormatter(); - - DateFormat dF = getDateFormatter(); + final NumberFormat kmF = getKMFormatter(); + final NumberFormat dwF = getDeltaWFormatter(); + final NumberFormat qF = getQFormatter(); + final NumberFormat wF = getWFormatter(); - TreeMap> sorted = - new TreeMap>(); - - String referenceS = getReference(); + final DateFormat dF = getDateFormatter(); - for (KMIndex reference: referenceEvents) { + final TreeMap> sorted = new TreeMap<>(); - for (KMIndex.Entry kmEntry: reference) { + final String referenceS = getReference(); - Double km = kmEntry.getKm(); + for (final KMIndex reference : this.referenceEvents) { - ArrayList list = sorted.get(km); + for (final KMIndex.Entry kmEntry : reference) { + + final Double km = kmEntry.getKm(); + + ArrayList list = sorted.get(km); if (list == null) { - list = new ArrayList(); + list = new ArrayList<>(); sorted.put(km, list); } - String kmS = kmF.format(kmEntry.getKm()); - for (QWD qwd: kmEntry.getValue()) { - String deltaWS = dwF.format(qwd.getDeltaW()); - String qS = qF.format(qwd.getQ()); - String wS = wF.format(qwd.getW()); - String dateS = dF.format(qwd.getDate()); + final String kmS = kmF.format(kmEntry.getKm()); + for (final QWD qwd : kmEntry.getValue()) { + final String deltaWS = dwF.format(qwd.getDeltaW()); + final String qS = qF.format(qwd.getQ()); + final String wS = wF.format(qwd.getW()); + final String dateS = dF.format(qwd.getDate()); - list.add(new String[] { - kmS, - dateS, - qS, - wS, - referenceS, - deltaWS - }); + list.add(new String[] { kmS, dateS, qS, wS, referenceS, deltaWS }); } } } if (debug) { - log.debug("AnalysisPeriods: " + analysisPeriods.size()); + log.debug("AnalysisPeriods: " + this.analysisPeriods.size()); } - String analysisTemplate = getAnalysisTemplate(); - - for (KMIndex periods: analysisPeriods) { + final String analysisTemplate = getAnalysisTemplate(); - for (KMIndex.Entry kmEntry: periods) { + for (final KMIndex periods : this.analysisPeriods) { - Double km = kmEntry.getKm(); + for (final KMIndex.Entry kmEntry : periods) { - ArrayList list = sorted.get(km); + final Double km = kmEntry.getKm(); + + ArrayList list = sorted.get(km); if (list == null) { - list = new ArrayList(); + list = new ArrayList<>(); sorted.put(km, list); } - String kmS = kmF.format(kmEntry.getKm()); + final String kmS = kmF.format(kmEntry.getKm()); int analysisCount = 1; - for (AnalysisPeriod period: kmEntry.getValue()) { + for (final AnalysisPeriod period : kmEntry.getValue()) { // Typically resulting in A1,A2... - String analyisS = MessageFormat.format(analysisTemplate, - analysisCount); - QWD [] qwds = period.getQWDs(); + final String analyisS = MessageFormat.format(analysisTemplate, analysisCount); + final QWD[] qwds = period.getQWDs(); if (qwds != null) { - for (QWD qwd: qwds) { - String deltaWS = dwF.format(qwd.getDeltaW()); - String qS = qF.format(qwd.getQ()); - String wS = wF.format(qwd.getW()); - String dateS = dF.format(qwd.getDate()); + for (final QWD qwd : qwds) { + final String deltaWS = dwF.format(qwd.getDeltaW()); + final String qS = qF.format(qwd.getQ()); + final String wS = wF.format(qwd.getW()); + final String dateS = dF.format(qwd.getDate()); - list.add(new String[] { - kmS, - dateS, - qS, - wS, - analyisS, - deltaWS }); + list.add(new String[] { kmS, dateS, qS, wS, analyisS, deltaWS }); } } ++analysisCount; @@ -220,8 +184,8 @@ } } - for (ArrayList list: sorted.values()) { - for (String [] row: list) { + for (final ArrayList list : sorted.values()) { + for (final String[] row : list) { writer.writeNext(row); } } @@ -231,64 +195,56 @@ /** Template to create "State" strings like A1,A2... */ protected String getAnalysisTemplate() { - return Resources.getMsg( - context.getMeta(), - CSV_ANALYSIS, DEFAULT_CSV_ANALYSIS); + return Resources.getMsg(this.context.getMeta(), CSV_ANALYSIS, DEFAULT_CSV_ANALYSIS); } protected String getReference() { - return Resources.getMsg( - context.getMeta(), - CSV_REFERENCE, DEFAULT_CSV_REFERENCE); + return Resources.getMsg(this.context.getMeta(), CSV_REFERENCE, DEFAULT_CSV_REFERENCE); } protected NumberFormat getKMFormatter() { - return Formatter.getFixDeltaWKM(context); + return Formatter.getFixDeltaWKM(this.context); } protected NumberFormat getDeltaWFormatter() { - return Formatter.getFixDeltaWDeltaW(context); + return Formatter.getFixDeltaWDeltaW(this.context); } + @Override protected NumberFormat getQFormatter() { - return Formatter.getFixDeltaWQ(context); + return Formatter.getFixDeltaWQ(this.context); } + @Override protected NumberFormat getWFormatter() { - return Formatter.getFixDeltaWW(context); + return Formatter.getFixDeltaWW(this.context); } protected DateFormat getDateFormatter() { - CallMeta meta = context.getMeta(); - return Formatter.getDateFormatter( - meta, - Resources.getMsg( - meta, - CSV_T_FORMAT, - DEFAULT_CSV_T_FORMAT)); + final CallMeta meta = this.context.getMeta(); + return Formatter.getDateFormatter(meta, Resources.getMsg(meta, CSV_T_FORMAT, DEFAULT_CSV_T_FORMAT)); } - protected void writeCSVHeader(CSVWriter writer) { + protected void writeCSVHeader(final CSVWriter writer) { log.debug("DeltaWtExporter.writeCSVHeader"); - /* issue825 - km; Ereignis, Abfluss, GEMESSENER Wasserstand; - Status (RECHTSBÜNDIG), del W - */ + /* + * issue825 + * km; Ereignis, Abfluss, GEMESSENER Wasserstand; + * Status (RECHTSBÜNDIG), del W + */ + final RiverAccess river = new RiverAccess((D4EArtifact) this.master); + final String unit = river.getRiver().getWstUnit().getName(); - writer.writeNext(new String[] { - msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), - msg(CSV_T_HEADER, DEFAULT_CSV_T_HEADER), - msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER), - msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER), - msg(CSV_TRANGE_HEADER, DEFAULT_CSV_TRANGE_DESC_HEADER), - msg(CSV_DELTA_W_HEADER, DEFAULT_CSV_DELTA_W_HEADER) - }); + writer.writeNext(new String[] { msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), msg(CSV_T_HEADER, DEFAULT_CSV_T_HEADER), + msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER), msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { unit }), + msg(CSV_TRANGE_HEADER, DEFAULT_CSV_TRANGE_DESC_HEADER), msg(CSV_DELTA_W_HEADER, DEFAULT_CSV_DELTA_W_HEADER) }); } @Override - protected void writePDF(OutputStream out) { + protected void writePDF(final OutputStream out) { // TODO: Implement me! + // wird doch NICHT erledigt vom WaterlevelExporter } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r a0feac6ea1ba -r 42c15e2f95fb artifacts/src/main/resources/messages.properties --- a/artifacts/src/main/resources/messages.properties Fri May 25 09:10:19 2018 +0200 +++ b/artifacts/src/main/resources/messages.properties Fri May 25 10:44:24 2018 +0200 @@ -695,7 +695,7 @@ export.fixings.deltawt.csv.header.km=km export.fixings.deltawt.csv.header.deltaw=\u0394 W [cm] export.fixings.deltawt.csv.header.q=Discharge [m\u00b3/s] -export.fixings.deltawt.csv.header.w=Waterlevel [m] +export.fixings.deltawt.csv.header.w=Waterlevel [{0}] export.fixings.deltawt.csv.header.t=Date export.fixings.deltawt.csv.t.format=yyyy/MM/dd export.fixings.deltawt.csv.header.time.range=State diff -r a0feac6ea1ba -r 42c15e2f95fb artifacts/src/main/resources/messages_de.properties --- a/artifacts/src/main/resources/messages_de.properties Fri May 25 09:10:19 2018 +0200 +++ b/artifacts/src/main/resources/messages_de.properties Fri May 25 10:44:24 2018 +0200 @@ -695,7 +695,7 @@ export.fixings.deltawt.csv.header.km=km export.fixings.deltawt.csv.header.deltaw=\u0394 W [cm] export.fixings.deltawt.csv.header.q=Abfluss [m\u00b3/s] -export.fixings.deltawt.csv.header.w=Wasserstand [m] +export.fixings.deltawt.csv.header.w=Wasserstand [{0}] export.fixings.deltawt.csv.header.t=Datum export.fixings.deltawt.csv.t.format=dd.MM.yyyy export.fixings.deltawt.csv.header.time.range=Status