comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java @ 99:bb45c5097cb6

ehcache Integration for storing the chartresultvalues gnv-artifacts/trunk@146 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 28 Sep 2009 14:17:15 +0000
parents 156db25ad4b4
children ef157bd2fa92
comparison
equal deleted inserted replaced
98:156db25ad4b4 99:bb45c5097cb6
75 } 75 }
76 76
77 /** 77 /**
78 * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, java.util.Collection, java.io.OutputStream) 78 * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, java.util.Collection, java.io.OutputStream)
79 */ 79 */
80 public void out(String outputMode, Collection<InputData> inputData, OutputStream outputStream) throws TransitionException { 80 public void out(String outputMode, Collection<InputData> inputData, OutputStream outputStream, String uuid) throws TransitionException {
81 log.debug("TimeSeriesOutputTransition.out"); 81 log.debug("TimeSeriesOutputTransition.out");
82 try { 82 try {
83 this.advance(); 83
84 this.advance(uuid);
85 Collection<Result> chartResult = this.getChartResult(uuid);
84 if (outputMode.equalsIgnoreCase("chart")){ 86 if (outputMode.equalsIgnoreCase("chart")){
85 log.debug("Chart will be generated."); 87 log.debug("Chart will be generated.");
86 int chartWidth = 600; 88 int chartWidth = 600;
87 int chartHeight = 400; 89 int chartHeight = 400;
88 try { 90 try {
104 Collection<KeyValueDescibeData> parameters = this.getParameters(); 106 Collection<KeyValueDescibeData> parameters = this.getParameters();
105 Collection<KeyValueDescibeData> measurements = this.getMeasurements(); 107 Collection<KeyValueDescibeData> measurements = this.getMeasurements();
106 ChartStyle chartStyle = this.creatStyle(chartWidth,chartHeight); 108 ChartStyle chartStyle = this.creatStyle(chartWidth,chartHeight);
107 ChartLabels chartLables = new ChartLabels(this.getSelectedFeatureName(),this.domainLable); 109 ChartLabels chartLables = new ChartLabels(this.getSelectedFeatureName(),this.domainLable);
108 this.createChart(outputStream, parameters, measurements, 110 this.createChart(outputStream, parameters, measurements,
109 chartStyle, chartLables); 111 chartStyle, chartLables,uuid);
110 }else if (outputMode.equalsIgnoreCase("csv")){ 112 }else if (outputMode.equalsIgnoreCase("csv")){
111 log.debug("CSV-File will be generated."); 113 log.debug("CSV-File will be generated.");
112 if(this.chartResult != null){ 114 if(chartResult != null){
113 CSVWriter writer = new CSVWriter(new OutputStreamWriter(outputStream,"ISO-8859-1"), ','); // USE THIS ENCODING BECAUSE OF PROBLEMS WITH EXCEL AND UTF-8 115 CSVWriter writer = new CSVWriter(new OutputStreamWriter(outputStream,"ISO-8859-1"), ','); // USE THIS ENCODING BECAUSE OF PROBLEMS WITH EXCEL AND UTF-8
114 Iterator<Result>it = this.chartResult.iterator(); 116 Iterator<Result>it = chartResult.iterator();
115 while (it.hasNext()){ 117 while (it.hasNext()){
116 Result result = it.next(); 118 Result result = it.next();
117 int i = 0; 119 int i = 0;
118 String[] entries = new String[5]; 120 String[] entries = new String[5];
119 entries[i++] = result.getString("XORDINATE"); 121 entries[i++] = result.getString("XORDINATE");
129 throw new TransitionException("No Data given for generation an CSV-File."); 131 throw new TransitionException("No Data given for generation an CSV-File.");
130 } 132 }
131 }else if (outputMode.equalsIgnoreCase("statistics")){ 133 }else if (outputMode.equalsIgnoreCase("statistics")){
132 log.debug("Statistics will be generated."); 134 log.debug("Statistics will be generated.");
133 Statistics s = getStatisticsGenerator(); 135 Statistics s = getStatisticsGenerator();
134 Collection<Statistic> statistics = s.calculateStatistics(this.chartResult); 136 Collection<Statistic> statistics = s.calculateStatistics(chartResult);
135 Document doc = this.writeStatistics2XML(statistics); 137 Document doc = this.writeStatistics2XML(statistics);
136 this.writeDocument2OutputStream(doc, outputStream); 138 this.writeDocument2OutputStream(doc, outputStream);
137 } 139 }
138 } catch (IOException e) { 140 } catch (IOException e) {
139 log.error(e,e); 141 log.error(e,e);
217 * @throws TechnicalChartException 219 * @throws TechnicalChartException
218 */ 220 */
219 protected void createChart(OutputStream outputStream, 221 protected void createChart(OutputStream outputStream,
220 Collection<KeyValueDescibeData> parameters, 222 Collection<KeyValueDescibeData> parameters,
221 Collection<KeyValueDescibeData> measurements, 223 Collection<KeyValueDescibeData> measurements,
222 ChartStyle chartStyle, ChartLabels chartLables) throws IOException, 224 ChartStyle chartStyle, ChartLabels chartLables, String uuid) throws IOException,
223 TechnicalChartException { 225 TechnicalChartException {
224 ChartFactory chartFactory = new ChartFactory(); 226 ChartFactory chartFactory = new ChartFactory();
225 chartFactory.createSimpleTimeSeriesChart(chartLables, chartStyle, 227 chartFactory.createSimpleTimeSeriesChart(chartLables, chartStyle,
226 parameters, measurements, 228 parameters, measurements,
227 outputStream, this.chartResult); 229 outputStream, this.getChartResult(uuid));
228 }
229
230 /**
231 * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection)
232 */
233 @Override
234 protected void purifyResult(Collection<Result> result) {
235 this.chartResult = result;
236 } 230 }
237 231
238 protected ChartStyle creatStyle(int witdh, int height){ 232 protected ChartStyle creatStyle(int witdh, int height){
239 // TODO Konfigurierbar machen 233 // TODO Konfigurierbar machen
240 de.intevation.gnv.chart.Insets lInsets = new de.intevation.gnv.chart.Insets(5d, 5d, 5d, 5d); 234 de.intevation.gnv.chart.Insets lInsets = new de.intevation.gnv.chart.Insets(5d, 5d, 5d, 5d);

http://dive4elements.wald.intevation.org