Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/commons/AbstractUInfoExporter.java @ 8996:fb9430250899
Work on uinfo
author | gernotbelger |
---|---|
date | Thu, 12 Apr 2018 19:13:39 +0200 |
parents | |
children | 7134a4c7d1b6 |
comparison
equal
deleted
inserted
replaced
8995:8c3e5682cb60 | 8996:fb9430250899 |
---|---|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.uinfo.commons; | |
11 | |
12 import java.text.DateFormat; | |
13 import java.text.NumberFormat; | |
14 import java.util.Date; | |
15 import java.util.Locale; | |
16 | |
17 import org.apache.commons.lang.math.DoubleRange; | |
18 import org.dive4elements.river.FLYS; | |
19 import org.dive4elements.river.artifacts.common.AbstractCalculationResult; | |
20 import org.dive4elements.river.artifacts.common.AbstractCalculationResults; | |
21 import org.dive4elements.river.artifacts.common.AbstractCommonExporter; | |
22 import org.dive4elements.river.artifacts.common.I18NStrings; | |
23 import org.dive4elements.river.artifacts.resources.Resources; | |
24 import org.dive4elements.river.artifacts.sinfo.util.MetaAndTableJRDataSource; | |
25 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | |
26 | |
27 import au.com.bytecode.opencsv.CSVWriter; | |
28 | |
29 /** | |
30 * @author Gernot Belger | |
31 */ | |
32 public abstract class AbstractUInfoExporter<RESULT extends AbstractCalculationResult, RESULTS extends AbstractCalculationResults<RESULT>> extends AbstractCommonExporter<RESULT, RESULTS> { | |
33 | |
34 @Override | |
35 protected void addJRMetaData(final MetaAndTableJRDataSource source, final RESULTS results) { | |
36 | |
37 /* general metadata */ | |
38 this.addJRMetaDataDefaults(source, results); | |
39 | |
40 /* general metadata */ | |
41 this.addJRMetaDataDefaults(source, results); | |
42 | |
43 final RiverInfo river = results.getRiver(); | |
44 final String wstUnitName = river.getWstUnit(); | |
45 | |
46 source.addMetaData("river_label", msg(I18NStrings.CSV_META_RIVER_LABEL)); | |
47 source.addMetaData("river", river.getName()); | |
48 source.addMetaData("river_unit", wstUnitName); | |
49 | |
50 source.addMetaData("range_label", msg(I18NStrings.CSV_META_RANGE_LABEL)); | |
51 final DoubleRange calcRange = results.getCalcRange(); | |
52 final NumberFormat kmFormatter = getKmFormatter(); | |
53 if (calcRange != null) { | |
54 final String rangeValue = String.format("%s - %s", kmFormatter.format(calcRange.getMinimumDouble()), | |
55 kmFormatter.format(calcRange.getMaximumDouble())); | |
56 source.addMetaData("range", rangeValue); | |
57 } | |
58 | |
59 /* column headings */ | |
60 // source.addMetaData("station_header", GeneralResultType.station.getPdfHeader(this.context.getMeta())); // moved to | |
61 // super | |
62 | |
63 // TODO: move to subs | |
64 // source.addMetaData("flowdepth_header", SInfoResultType.flowdepth.getPdfHeader(this.context.getMeta())); | |
65 // source.addMetaData("flowdepth_tkh_header", SInfoResultType.flowdepthtkh.getPdfHeader(this.context.getMeta())); | |
66 // source.addMetaData("tkh_header", SInfoResultType.tkh.getPdfHeader(this.context.getMeta())); | |
67 // source.addMetaData("waterlevel_header", SInfoResultType.waterlevel.getPdfHeader(this.context.getMeta())); | |
68 // source.addMetaData("discharge_header", SInfoResultType.discharge.getPdfHeader(this.context.getMeta())); | |
69 | |
70 } | |
71 | |
72 @Override | |
73 protected void writeCSVGlobalMetadataDefaults(final CSVWriter writer, final RESULTS results) { | |
74 | |
75 final String calcModeLabel = results.getCalcModeLabel(); | |
76 final RiverInfo river = results.getRiver(); | |
77 final DoubleRange calcRange = results.getCalcRange(); | |
78 | |
79 writeCSVMetaEntry(writer, I18NStrings.CSV_META_HEADER_RESULT, msg(I18NStrings.CSV_META_HEADER_RESULT_LABEL), river.getName(), calcModeLabel); | |
80 | |
81 // "# FLYS-Version: " | |
82 writeCSVMetaEntry(writer, I18NStrings.CSV_META_VERSION, msg(I18NStrings.CSV_META_VERSION_LABEL), FLYS.VERSION); | |
83 | |
84 // "# Bearbeiter: " | |
85 writeCSVMetaEntry(writer, I18NStrings.CSV_META_USER, msg(I18NStrings.CSV_META_USER_LABEL), results.getUser()); | |
86 | |
87 // "# Datum der Erstellung: " | |
88 final Locale locale = Resources.getLocale(this.context.getMeta()); | |
89 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); | |
90 writeCSVMetaEntry(writer, I18NStrings.CSV_META_CREATION, msg(I18NStrings.CSV_META_CREATION_LABEL), df.format(new Date())); | |
91 | |
92 // "# Gewässer: " | |
93 writeCSVMetaEntry(writer, I18NStrings.CSV_META_RIVER, msg(I18NStrings.CSV_META_RIVER_LABEL), river.getName()); | |
94 | |
95 // "# Höhensystem des Flusses: " | |
96 writeCSVMetaEntry(writer, I18NStrings.CSV_META_HEIGHT_UNIT_RIVER, river.getWstUnit()); // move to child? | |
97 | |
98 if (calcRange != null) { | |
99 // "# Ort/Bereich (km): " | |
100 writeCSVMetaEntry(writer, I18NStrings.CSV_META_RANGE, msg(I18NStrings.CSV_META_RANGE_LABEL), getKmFormatter().format(calcRange.getMinimumDouble()), | |
101 getKmFormatter().format(calcRange.getMaximumDouble())); | |
102 } | |
103 } | |
104 | |
105 @Override | |
106 protected void addJRMetaDataDefaults(final MetaAndTableJRDataSource source, final RESULTS results) { | |
107 | |
108 source.addMetaData("header", msg(I18NStrings.CSV_META_HEADER_RESULT_LABEL)); | |
109 source.addMetaData("calcMode", results.getCalcModeLabel()); | |
110 | |
111 source.addMetaData("version_label", msg(I18NStrings.CSV_META_VERSION_LABEL)); | |
112 source.addMetaData("version", FLYS.VERSION); | |
113 | |
114 source.addMetaData("user_label", msg(I18NStrings.CSV_META_USER_LABEL)); | |
115 source.addMetaData("user", results.getUser()); | |
116 | |
117 final Locale locale = Resources.getLocale(this.context.getMeta()); | |
118 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); | |
119 source.addMetaData("date_label", msg(I18NStrings.CSV_META_CREATION_LABEL)); | |
120 source.addMetaData("date", df.format(new Date())); | |
121 | |
122 } | |
123 | |
124 } |