comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeDischargeState.java @ 3051:49727e9dcfde

Polished Gauge Discharges in computed discharge curves. flys-artifacts/trunk@4625 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 07 Jun 2012 20:47:17 +0000
parents 89731cb8c385
children bb576facbe50
comparison
equal deleted inserted replaced
3050:02254d763bc0 3051:49727e9dcfde
21 import de.intevation.flys.artifacts.model.CalculationResult; 21 import de.intevation.flys.artifacts.model.CalculationResult;
22 22
23 import de.intevation.flys.artifacts.resources.Resources; 23 import de.intevation.flys.artifacts.resources.Resources;
24 import de.intevation.flys.utils.FLYSUtils; 24 import de.intevation.flys.utils.FLYSUtils;
25 25
26 import de.intevation.flys.model.Gauge;
27
26 28
27 /** 29 /**
28 * The only state for an GaugeDischargeState (River and km known). 30 * The only state for an GaugeDischargeState (River and km known).
29 */ 31 */
30 public class GaugeDischargeState 32 public class GaugeDischargeState
33 { 35 {
34 /** Developer-centric description of facet. */ 36 /** Developer-centric description of facet. */
35 public static final String I18N_DESCRIPTION = "facet.discharge.curve"; 37 public static final String I18N_DESCRIPTION = "facet.discharge.curve";
36 38
37 /** The logger that is used in this state. */ 39 /** The logger that is used in this state. */
38 private static final Logger logger = Logger.getLogger(GaugeDischargeState.class); 40 private static final Logger logger =
41 Logger.getLogger(GaugeDischargeState.class);
42
43
44 /**
45 * Create i18ned name for gaugedischargeFacet.
46 * @param artifact The artifact which has information about the gauge.
47 * @param meta used for i18n.
48 * @return localized name for gaugedischargefacet.
49 */
50 protected String createFacetName(GaugeDischargeArtifact artifact,
51 CallMeta meta) {
52
53 Gauge gauge = artifact.getGauge();
54 Object[] args = new Object[] {
55 gauge.getName(),
56 gauge.getStation()
57 };
58
59 String name = Resources.getMsg(
60 meta,
61 "chart.computed.discharge.curve.gauge",
62 "",
63 args);
64
65 return name;
66 }
39 67
40 68
41 /** 69 /**
42 * Add an GaugeDischargeFacet to list of Facets. 70 * Add an GaugeDischargeFacet to list of Facets.
43 * 71 *
57 CallMeta meta, 85 CallMeta meta,
58 List<Facet> facets 86 List<Facet> facets
59 ) { 87 ) {
60 logger.debug("GaugeDischargeState.computeInit()"); 88 logger.debug("GaugeDischargeState.computeInit()");
61 89
62 // TODO caching, / CalculationResultusage 90 // TODO caching, / CalculationResultUsage
63 91
64 GaugeDischargeFacet facet = new GaugeDischargeFacet( 92 GaugeDischargeFacet facet = new GaugeDischargeFacet(
65 0, 93 0,
66 DISCHARGE_CURVE, 94 DISCHARGE_CURVE,
67 DISCHARGE_CURVE); 95 createFacetName((GaugeDischargeArtifact) artifact, meta));
68 //Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION)); 96
69 facets.add(facet); 97 facets.add(facet);
70 98
71 return null; 99 return null;
72 } 100 }
73 //WINFOArtifact#getDischargeCurveData
74 101
75 102
103 /**
104 * 'Calculate' Discharge at Gauge.
105 */
76 @Override 106 @Override
77 public Object computeAdvance( 107 public Object computeAdvance(
78 FLYSArtifact artifact, 108 FLYSArtifact artifact,
79 String hash, 109 String hash,
80 CallContext context, 110 CallContext context,
81 List<Facet> facets, 111 List<Facet> facets,
82 Object old 112 Object old
83 ) { 113 ) {
84 // TODO why are the facets null here?
85 //if (facets == null) facets = new List<Facet>();
86 if (artifact instanceof GaugeDischargeArtifact) { 114 if (artifact instanceof GaugeDischargeArtifact) {
87 logger.debug("GaugeDischargeState.computeAdvance()"); 115 logger.debug("GaugeDischargeState.computeAdvance()");
88 GaugeDischargeArtifact dischargeArtifact = (GaugeDischargeArtifact) artifact; 116 GaugeDischargeArtifact dischargeArtifact = (GaugeDischargeArtifact) artifact;
89 117
90 CalculationResult res; 118 CalculationResult res;
98 126
99 WQKms[] wqkms = (WQKms[]) res.getData(); 127 WQKms[] wqkms = (WQKms[]) res.getData();
100 128
101 if (wqkms != null && facets != null) { 129 if (wqkms != null && facets != null) {
102 logger.debug("GaugeDischargeState.computeAdvance(): create facets"); 130 logger.debug("GaugeDischargeState.computeAdvance(): create facets");
103 // Create an i18ed name for a (w or q) duration curve facet.
104 Object[] args = new Object[] {
105 FLYSUtils.getRiver(dischargeArtifact).getName(),
106 FLYSUtils.getLocations(dischargeArtifact)[0]
107 };
108 131
109 String nameW = Resources.getMsg(
110 context.getMeta(),
111 "chart.duration.curve.curve.w",
112 "",
113 args);
114
115 String nameQ = Resources.getMsg(
116 context.getMeta(),
117 "chart.duration.curve.curve.q",
118 "",
119 args);
120
121 /*Facet w = new DurationCurveFacet(DURATION_W, nameW);
122 Facet q = new DurationCurveFacet(DURATION_Q, nameQ);
123
124 facets.add(w);*/
125 GaugeDischargeFacet facet = new GaugeDischargeFacet( 132 GaugeDischargeFacet facet = new GaugeDischargeFacet(
126 0, 133 0,
127 "A"+DISCHARGE_CURVE, 134 DISCHARGE_CURVE,
128 "A"+DISCHARGE_CURVE); 135 createFacetName(dischargeArtifact, context.getMeta()));
129 //Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION)); 136
130 facets.add(facet); 137 facets.add(facet);
131 138
132 //facets.add(new DataFacet(CSV, "CSV data")); 139 //facets.add(new DataFacet(CSV, "CSV data"));
133 //facets.add(new DataFacet(PDF, "PDF data")); 140 //facets.add(new DataFacet(PDF, "PDF data"));
134 141
136 facets.add(new ReportFacet()); 143 facets.add(new ReportFacet());
137 } 144 }
138 } 145 }
139 else { 146 else {
140 if (wqkms == null) 147 if (wqkms == null)
141 logger.debug("GaugeDischargeState.computeAdvance(): wqkms 0"); 148 logger.debug("GaugeDischargeState.computeAdvance(): wqkms 0");
142 else 149 else
143 logger.debug("GaugeDischargeState.computeAdvance(): facets 0"); 150 logger.debug("GaugeDischargeState.computeAdvance(): facets 0");
144 } 151 }
145 152
146 return res; 153 return res;
147 } 154 }
148 else if (artifact instanceof ChartArtifact) { 155 else if (artifact instanceof ChartArtifact) {
150 facets.add(new EmptyFacet()); 157 facets.add(new EmptyFacet());
151 return null; 158 return null;
152 } 159 }
153 return null; 160 return null;
154 } 161 }
155
156 } 162 }
157 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 163 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org