comparison artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java @ 5865:73da40528cf2

River artifacts: Renamed FLYSUtils to RiverUtils.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 15:09:31 +0200
parents 4897a58c8746
children 59ff03ff48f1
comparison
equal deleted inserted replaced
5864:f2e46a668fe6 5865:73da40528cf2
51 import org.dive4elements.river.artifacts.model.WQKms; 51 import org.dive4elements.river.artifacts.model.WQKms;
52 import org.dive4elements.river.artifacts.model.WKmsJRDataSource; 52 import org.dive4elements.river.artifacts.model.WKmsJRDataSource;
53 import org.dive4elements.river.artifacts.model.WQKmsResult; 53 import org.dive4elements.river.artifacts.model.WQKmsResult;
54 import org.dive4elements.river.artifacts.resources.Resources; 54 import org.dive4elements.river.artifacts.resources.Resources;
55 55
56 import org.dive4elements.river.utils.FLYSUtils; 56 import org.dive4elements.river.utils.RiverUtils;
57 import org.dive4elements.river.utils.FLYSUtils.WQ_MODE; 57 import org.dive4elements.river.utils.RiverUtils.WQ_MODE;
58 import org.dive4elements.river.utils.Formatter; 58 import org.dive4elements.river.utils.Formatter;
59 59
60 /** 60 /**
61 * Generates different output formats (wst, csv, pdf) of data that resulted from 61 * Generates different output formats (wst, csv, pdf) of data that resulted from
62 * a waterlevel computation. 62 * a waterlevel computation.
209 String raw = m.group(1); 209 String raw = m.group(1);
210 210
211 try { 211 try {
212 double v = Double.valueOf(raw); 212 double v = Double.valueOf(raw);
213 213
214 String nmv = FLYSUtils.getNamedMainValue(winfo, v); 214 String nmv = RiverUtils.getNamedMainValue(winfo, v);
215 215
216 if (nmv != null && nmv.length() > 0) { 216 if (nmv != null && nmv.length() > 0) {
217 nmv = FLYSUtils.stripNamedMainValue(nmv); 217 nmv = RiverUtils.stripNamedMainValue(nmv);
218 nmv += "=" + String.valueOf(v); 218 nmv += "=" + String.valueOf(v);
219 logger.debug("Set named main value '" + nmv + "'"); 219 logger.debug("Set named main value '" + nmv + "'");
220 220
221 return nmv; 221 return nmv;
222 } 222 }
235 235
236 String name = wqkms.getName(); 236 String name = wqkms.getName();
237 237
238 logger.debug("Name of WQKms = '" + name + "'"); 238 logger.debug("Name of WQKms = '" + name + "'");
239 239
240 WQ_MODE wqmode = FLYSUtils.getWQMode(winfo); 240 WQ_MODE wqmode = RiverUtils.getWQMode(winfo);
241 241
242 if (wqmode == WQ_MODE.WFREE || wqmode == WQ_MODE.QGAUGE) { 242 if (wqmode == WQ_MODE.WFREE || wqmode == WQ_MODE.QGAUGE) {
243 return localizeWQKms(winfo, wqkms); 243 return localizeWQKms(winfo, wqkms);
244 } 244 }
245 245
246 Double v = wqkms.getRawValue(); 246 Double v = wqkms.getRawValue();
247 247
248 String nmv = FLYSUtils.getNamedMainValue(winfo, v); 248 String nmv = RiverUtils.getNamedMainValue(winfo, v);
249 249
250 if (nmv != null && nmv.length() > 0) { 250 if (nmv != null && nmv.length() > 0) {
251 nmv = FLYSUtils.stripNamedMainValue(nmv); 251 nmv = RiverUtils.stripNamedMainValue(nmv);
252 logger.debug("Set named main value '" + nmv + "'"); 252 logger.debug("Set named main value '" + nmv + "'");
253 253
254 return nmv; 254 return nmv;
255 } 255 }
256 256
261 /** 261 /**
262 * Get a string like 'W=' or 'Q=' with a number following in localized 262 * Get a string like 'W=' or 'Q=' with a number following in localized
263 * format. 263 * format.
264 */ 264 */
265 protected String localizeWQKms(WINFOArtifact winfo, WQKms wqkms) { 265 protected String localizeWQKms(WINFOArtifact winfo, WQKms wqkms) {
266 WQ_MODE wqmode = FLYSUtils.getWQMode(winfo); 266 WQ_MODE wqmode = RiverUtils.getWQMode(winfo);
267 Double rawValue = wqkms.getRawValue(); 267 Double rawValue = wqkms.getRawValue();
268 268
269 if (rawValue == null) { 269 if (rawValue == null) {
270 return wqkms.getName(); 270 return wqkms.getName();
271 } 271 }
283 283
284 @Override 284 @Override
285 protected void writeCSVData(CSVWriter writer) { 285 protected void writeCSVData(CSVWriter writer) {
286 logger.info("WaterlevelExporter.writeData"); 286 logger.info("WaterlevelExporter.writeData");
287 287
288 WQ_MODE mode = FLYSUtils.getWQMode((FLYSArtifact)master); 288 WQ_MODE mode = RiverUtils.getWQMode((FLYSArtifact)master);
289 boolean atGauge = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.WGAUGE; 289 boolean atGauge = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.WGAUGE;
290 boolean isQ = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.QFREE; 290 boolean isQ = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.QFREE;
291 FLYSUtils.WQ_INPUT input 291 RiverUtils.WQ_INPUT input
292 = FLYSUtils.getWQInputMode((FLYSArtifact)master); 292 = RiverUtils.getWQInputMode((FLYSArtifact)master);
293 293
294 writeCSVMeta(writer); 294 writeCSVMeta(writer);
295 writeCSVHeader(writer, atGauge, isQ); 295 writeCSVHeader(writer, atGauge, isQ);
296 296
297 for (WQKms[] tmp: data) { 297 for (WQKms[] tmp: data) {
303 303
304 304
305 protected void writeCSVMeta(CSVWriter writer) { 305 protected void writeCSVMeta(CSVWriter writer) {
306 logger.info("WaterlevelExporter.writeCSVMeta"); 306 logger.info("WaterlevelExporter.writeCSVMeta");
307 307
308 // TODO use Access instead of FLYSUtils 308 // TODO use Access instead of RiverUtils
309 309
310 CallMeta meta = context.getMeta(); 310 CallMeta meta = context.getMeta();
311 311
312 FLYSArtifact flys = (FLYSArtifact) master; 312 FLYSArtifact flys = (FLYSArtifact) master;
313 313
314 writer.writeNext(new String[] { 314 writer.writeNext(new String[] {
315 Resources.getMsg( 315 Resources.getMsg(
316 meta, 316 meta,
317 CSV_META_RESULT, 317 CSV_META_RESULT,
318 CSV_META_RESULT, 318 CSV_META_RESULT,
319 new Object[] { FLYSUtils.getRivername(flys) }) 319 new Object[] { RiverUtils.getRivername(flys) })
320 }); 320 });
321 321
322 Locale locale = Resources.getLocale(meta); 322 Locale locale = Resources.getLocale(meta);
323 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); 323 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
324 324
341 writer.writeNext(new String[] { 341 writer.writeNext(new String[] {
342 Resources.getMsg( 342 Resources.getMsg(
343 meta, 343 meta,
344 CSV_META_RIVER, 344 CSV_META_RIVER,
345 CSV_META_RIVER, 345 CSV_META_RIVER,
346 new Object[] { FLYSUtils.getRivername(flys) }) 346 new Object[] { RiverUtils.getRivername(flys) })
347 }); 347 });
348 348
349 RangeAccess rangeAccess = new RangeAccess(flys, null); 349 RangeAccess rangeAccess = new RangeAccess(flys, null);
350 double[] kms = rangeAccess.getKmRange(); 350 double[] kms = rangeAccess.getKmRange();
351 writer.writeNext(new String[] { 351 writer.writeNext(new String[] {
359 writer.writeNext(new String[] { 359 writer.writeNext(new String[] {
360 Resources.getMsg( 360 Resources.getMsg(
361 meta, 361 meta,
362 CSV_META_GAUGE, 362 CSV_META_GAUGE,
363 CSV_META_GAUGE, 363 CSV_META_GAUGE,
364 new Object[] { FLYSUtils.getGaugename(flys) }) 364 new Object[] { RiverUtils.getGaugename(flys) })
365 }); 365 });
366 366
367 FLYSUtils.WQ_MODE wq = FLYSUtils.getWQMode(flys); 367 RiverUtils.WQ_MODE wq = RiverUtils.getWQMode(flys);
368 if (wq == FLYSUtils.WQ_MODE.QFREE || wq == FLYSUtils.WQ_MODE.QGAUGE) { 368 if (wq == RiverUtils.WQ_MODE.QFREE || wq == RiverUtils.WQ_MODE.QGAUGE) {
369 double[] qs = FLYSUtils.getQs(flys); 369 double[] qs = RiverUtils.getQs(flys);
370 FLYSUtils.WQ_INPUT input = FLYSUtils.getWQInputMode(flys); 370 RiverUtils.WQ_INPUT input = RiverUtils.getWQInputMode(flys);
371 371
372 String data = ""; 372 String data = "";
373 373
374 if ((input == FLYSUtils.WQ_INPUT.ADAPTED || 374 if ((input == RiverUtils.WQ_INPUT.ADAPTED ||
375 input == FLYSUtils.WQ_INPUT.RANGE) && 375 input == RiverUtils.WQ_INPUT.RANGE) &&
376 qs != null && qs.length > 0) 376 qs != null && qs.length > 0)
377 { 377 {
378 data = String.valueOf(qs[0]); 378 data = String.valueOf(qs[0]);
379 data += " - " + String.valueOf(qs[qs.length-1]); 379 data += " - " + String.valueOf(qs[qs.length-1]);
380 } 380 }
381 else if (input == FLYSUtils.WQ_INPUT.SINGLE && qs != null){ 381 else if (input == RiverUtils.WQ_INPUT.SINGLE && qs != null){
382 data = String.valueOf(qs[0]); 382 data = String.valueOf(qs[0]);
383 for (int i = 1; i < qs.length; i++) { 383 for (int i = 1; i < qs.length; i++) {
384 data += ", " + String.valueOf(qs[i]); 384 data += ", " + String.valueOf(qs[i]);
385 } 385 }
386 } 386 }
395 CSV_META_Q, 395 CSV_META_Q,
396 new Object[] {data}) 396 new Object[] {data})
397 }); 397 });
398 } 398 }
399 else { 399 else {
400 double[] ws = FLYSUtils.getWs(flys); 400 double[] ws = RiverUtils.getWs(flys);
401 401
402 String lower = ""; 402 String lower = "";
403 String upper = ""; 403 String upper = "";
404 404
405 if (ws != null && ws.length > 0) { 405 if (ws != null && ws.length > 0) {
432 boolean atGauge, 432 boolean atGauge,
433 boolean isQ 433 boolean isQ
434 ) { 434 ) {
435 logger.info("WaterlevelExporter.writeCSVHeader"); 435 logger.info("WaterlevelExporter.writeCSVHeader");
436 436
437 String unit = FLYSUtils.getRiver((FLYSArtifact) master).getWstUnit().getName(); 437 String unit = RiverUtils.getRiver((FLYSArtifact) master).getWstUnit().getName();
438 438
439 if (atGauge) { 439 if (atGauge) {
440 writer.writeNext(new String[] { 440 writer.writeNext(new String[] {
441 msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), 441 msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER),
442 msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { unit }), 442 msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { unit }),
487 487
488 writer.writeNext(new String[] { 488 writer.writeNext(new String[] {
489 kmf.format(wqkm[2]), 489 kmf.format(wqkm[2]),
490 wf.format(wqkm[0]), 490 wf.format(wqkm[0]),
491 qf.format(wqkm[1]), 491 qf.format(wqkm[1]),
492 FLYSUtils.getLocationDescription(flys, wqkm[2]) 492 RiverUtils.getLocationDescription(flys, wqkm[2])
493 }); 493 });
494 } 494 }
495 495
496 496
497 /** Write an csv-row at gauge location. */ 497 /** Write an csv-row at gauge location. */
504 writer.writeNext(new String[] { 504 writer.writeNext(new String[] {
505 kmf.format(wqkm[2]), 505 kmf.format(wqkm[2]),
506 wf.format(wqkm[0]), 506 wf.format(wqkm[0]),
507 qf.format(wqkm[1]), 507 qf.format(wqkm[1]),
508 wOrQDesc, 508 wOrQDesc,
509 FLYSUtils.getLocationDescription(flys, wqkm[2]), 509 RiverUtils.getLocationDescription(flys, wqkm[2]),
510 gaugeName 510 gaugeName
511 }); 511 });
512 } 512 }
513 513
514 514
534 534
535 int size = wqkms.size(); 535 int size = wqkms.size();
536 double[] result = new double[3]; 536 double[] result = new double[3];
537 537
538 FLYSArtifact flys = (FLYSArtifact) master; 538 FLYSArtifact flys = (FLYSArtifact) master;
539 List<Gauge> gauges = FLYSUtils.getGauges(flys); 539 List<Gauge> gauges = RiverUtils.getGauges(flys);
540 Gauge gauge = FLYSUtils.getGauge(flys); 540 Gauge gauge = RiverUtils.getGauge(flys);
541 String gaugeName = gauge.getName(); 541 String gaugeName = gauge.getName();
542 String desc = ""; 542 String desc = "";
543 String notinrange = msg( 543 String notinrange = msg(
544 CSV_NOT_IN_GAUGE_RANGE, 544 CSV_NOT_IN_GAUGE_RANGE,
545 DEFAULT_CSV_NOT_IN_GAUGE_RANGE); 545 DEFAULT_CSV_NOT_IN_GAUGE_RANGE);
549 549
550 if (flys instanceof WINFOArtifact && isQ) { 550 if (flys instanceof WINFOArtifact && isQ) {
551 desc = getCSVRowTitle((WINFOArtifact)flys, wqkms); 551 desc = getCSVRowTitle((WINFOArtifact)flys, wqkms);
552 } 552 }
553 else if (!isQ) { 553 else if (!isQ) {
554 Double value = FLYSUtils.getValueFromWQ(wqkms); 554 Double value = RiverUtils.getValueFromWQ(wqkms);
555 desc = value != null 555 desc = value != null
556 ? Formatter.getWaterlevelW(context).format(value) : null; 556 ? Formatter.getWaterlevelW(context).format(value) : null;
557 } 557 }
558 558
559 long startTime = System.currentTimeMillis(); 559 long startTime = System.currentTimeMillis();
562 List<Segment> segments = null; 562 List<Segment> segments = null;
563 boolean isFixRealize = false; 563 boolean isFixRealize = false;
564 if (flys instanceof WINFOArtifact) { 564 if (flys instanceof WINFOArtifact) {
565 if (wqkms != null && wqkms.getRawValue() != null) { 565 if (wqkms != null && wqkms.getRawValue() != null) {
566 WINFOArtifact winfo = (WINFOArtifact) flys; 566 WINFOArtifact winfo = (WINFOArtifact) flys;
567 colDesc = FLYSUtils.getNamedMainValue(winfo, wqkms.getRawValue()); 567 colDesc = RiverUtils.getNamedMainValue(winfo, wqkms.getRawValue());
568 } 568 }
569 } 569 }
570 else if (flys instanceof FixationArtifact) { 570 else if (flys instanceof FixationArtifact) {
571 // Get W/Q input per gauge for this case. 571 // Get W/Q input per gauge for this case.
572 FixRealizingAccess fixAccess = new FixRealizingAccess(flys, getCallContext()); 572 FixRealizingAccess fixAccess = new FixRealizingAccess(flys, getCallContext());
741 } 741 }
742 742
743 protected WKmsJRDataSource createJRData() { 743 protected WKmsJRDataSource createJRData() {
744 WKmsJRDataSource source = new WKmsJRDataSource(); 744 WKmsJRDataSource source = new WKmsJRDataSource();
745 745
746 WQ_MODE mode = FLYSUtils.getWQMode((FLYSArtifact)master); 746 WQ_MODE mode = RiverUtils.getWQMode((FLYSArtifact)master);
747 boolean atGauge = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.WGAUGE; 747 boolean atGauge = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.WGAUGE;
748 boolean isQ = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.QFREE; 748 boolean isQ = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.QFREE;
749 749
750 addMetaData(source); 750 addMetaData(source);
751 for (WQKms[] tmp: data) { 751 for (WQKms[] tmp: data) {
759 protected void addMetaData(WKmsJRDataSource source) { 759 protected void addMetaData(WKmsJRDataSource source) {
760 CallMeta meta = context.getMeta(); 760 CallMeta meta = context.getMeta();
761 761
762 FLYSArtifact flys = (FLYSArtifact) master; 762 FLYSArtifact flys = (FLYSArtifact) master;
763 763
764 source.addMetaData ("river", FLYSUtils.getRivername(flys)); 764 source.addMetaData ("river", RiverUtils.getRivername(flys));
765 765
766 Locale locale = Resources.getLocale(meta); 766 Locale locale = Resources.getLocale(meta);
767 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); 767 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
768 768
769 source.addMetaData("date", df.format(new Date())); 769 source.addMetaData("date", df.format(new Date()));
770 770
771 RangeAccess rangeAccess = new RangeAccess(flys, null); 771 RangeAccess rangeAccess = new RangeAccess(flys, null);
772 double[] kms = rangeAccess.getKmRange(); 772 double[] kms = rangeAccess.getKmRange();
773 source.addMetaData("range", kms[0] + " - " + kms[kms.length-1]); 773 source.addMetaData("range", kms[0] + " - " + kms[kms.length-1]);
774 774
775 source.addMetaData("gauge", FLYSUtils.getGaugename(flys)); 775 source.addMetaData("gauge", RiverUtils.getGaugename(flys));
776 776
777 source.addMetaData("calculation", Resources.getMsg( 777 source.addMetaData("calculation", Resources.getMsg(
778 locale, 778 locale,
779 PDF_HEADER_MODE, 779 PDF_HEADER_MODE,
780 "Waterlevel")); 780 "Waterlevel"));
799 799
800 int size = wqkms.size(); 800 int size = wqkms.size();
801 double[] result = new double[3]; 801 double[] result = new double[3];
802 802
803 FLYSArtifact flys = (FLYSArtifact) master; 803 FLYSArtifact flys = (FLYSArtifact) master;
804 Gauge gauge = FLYSUtils.getGauge(flys); 804 Gauge gauge = RiverUtils.getGauge(flys);
805 String gaugeName = gauge.getName(); 805 String gaugeName = gauge.getName();
806 String desc = ""; 806 String desc = "";
807 String notinrange = msg( 807 String notinrange = msg(
808 CSV_NOT_IN_GAUGE_RANGE, 808 CSV_NOT_IN_GAUGE_RANGE,
809 DEFAULT_CSV_NOT_IN_GAUGE_RANGE); 809 DEFAULT_CSV_NOT_IN_GAUGE_RANGE);
813 813
814 if (flys instanceof WINFOArtifact && isQ) { 814 if (flys instanceof WINFOArtifact && isQ) {
815 desc = getCSVRowTitle((WINFOArtifact)flys, wqkms); 815 desc = getCSVRowTitle((WINFOArtifact)flys, wqkms);
816 } 816 }
817 else if (!isQ) { 817 else if (!isQ) {
818 Double value = FLYSUtils.getValueFromWQ(wqkms); 818 Double value = RiverUtils.getValueFromWQ(wqkms);
819 desc = value != null 819 desc = value != null
820 ? Formatter.getWaterlevelW(context).format(value) : null; 820 ? Formatter.getWaterlevelW(context).format(value) : null;
821 } 821 }
822 822
823 long startTime = System.currentTimeMillis(); 823 long startTime = System.currentTimeMillis();
829 source.addData(new String[] { 829 source.addData(new String[] {
830 kmf.format(result[2]), 830 kmf.format(result[2]),
831 wf.format(result[0]), 831 wf.format(result[0]),
832 qf.format(result[1]), 832 qf.format(result[1]),
833 desc, 833 desc,
834 FLYSUtils.getLocationDescription(flys, result[2]), 834 RiverUtils.getLocationDescription(flys, result[2]),
835 result[2] >= a && result[2] <= b 835 result[2] >= a && result[2] <= b
836 ? gaugeName 836 ? gaugeName
837 : notinrange 837 : notinrange
838 }); 838 });
839 } 839 }
841 source.addData(new String[] { 841 source.addData(new String[] {
842 kmf.format(result[2]), 842 kmf.format(result[2]),
843 wf.format(result[0]), 843 wf.format(result[0]),
844 qf.format(result[1]), 844 qf.format(result[1]),
845 desc, 845 desc,
846 FLYSUtils.getLocationDescription(flys, result[2]), 846 RiverUtils.getLocationDescription(flys, result[2]),
847 result[2] >= a && result[2] <= b 847 result[2] >= a && result[2] <= b
848 ? gaugeName 848 ? gaugeName
849 : notinrange 849 : notinrange
850 }); 850 });
851 } 851 }

http://dive4elements.wald.intevation.org