Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java @ 2228:4db19a88bddb
Implemented the first step of Calculation6; create Facets for each calculation results.
flys-artifacts/trunk@3868 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 01 Feb 2012 14:48:00 +0000 |
parents | 4b6e9b377a84 |
children | 59af81364eb1 |
comparison
equal
deleted
inserted
replaced
2227:2e6f0ef36352 | 2228:4db19a88bddb |
---|---|
1 package de.intevation.flys.artifacts.model; | 1 package de.intevation.flys.artifacts.model; |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.Date; | |
5 import java.util.List; | |
2 | 6 |
3 import org.apache.log4j.Logger; | 7 import org.apache.log4j.Logger; |
4 | 8 |
9 import de.intevation.flys.model.DischargeTable; | |
5 import de.intevation.flys.model.Gauge; | 10 import de.intevation.flys.model.Gauge; |
11 import de.intevation.flys.model.TimeInterval; | |
6 | 12 |
7 | 13 |
8 /** | 14 /** |
9 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 15 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
10 */ | 16 */ |
11 public class Calculation6 extends Calculation { | 17 public class Calculation6 extends Calculation { |
12 | 18 |
13 private static final Logger logger = Logger.getLogger(Calculation6.class); | 19 private static final Logger logger = Logger.getLogger(Calculation6.class); |
14 | 20 |
15 private int mode; | 21 private int mode; |
16 private int[] timerange; | 22 private long[] timerange; |
17 private double[] values; | 23 private double[] values; |
18 | 24 |
19 | 25 |
20 public static final int MODE_W = 0; | 26 public static final int MODE_W = 0; |
21 public static final int MODE_Q = 1; | 27 public static final int MODE_Q = 1; |
22 | 28 |
23 | 29 |
24 public Calculation6(int mode, int[] timerange, double[] values) { | 30 public Calculation6(int mode, long[] timerange, double[] values) { |
25 this.mode = mode; | 31 this.mode = mode; |
26 this.timerange = timerange; | 32 this.timerange = timerange; |
27 this.values = values; | 33 this.values = values; |
28 } | 34 } |
29 | 35 |
37 | 43 |
38 if (logger.isDebugEnabled()) { | 44 if (logger.isDebugEnabled()) { |
39 debug(); | 45 debug(); |
40 } | 46 } |
41 | 47 |
42 logger.warn("TODO: IMPLEMENT ME"); | 48 List<DischargeTable> dts = fetchDischargeTables(gauge); |
43 | 49 |
44 return null; | 50 logger.debug("Take " + dts.size() + " into account."); |
51 | |
52 WQTimerange[] wqt = prepareCalculationData(dts); | |
53 | |
54 return new CalculationResult(wqt, this); | |
45 } | 55 } |
46 | 56 |
47 | 57 |
48 protected boolean checkParameters() { | 58 protected boolean checkParameters() { |
49 if (!(mode == MODE_W || mode == MODE_Q)) { | 59 if (!(mode == MODE_W || mode == MODE_Q)) { |
63 | 73 |
64 return true; | 74 return true; |
65 } | 75 } |
66 | 76 |
67 | 77 |
78 protected List<DischargeTable> fetchDischargeTables(Gauge gauge) { | |
79 List<DischargeTable> relevant = new ArrayList<DischargeTable>(); | |
80 List<DischargeTable> all = gauge.getDischargeTables(); | |
81 | |
82 for (DischargeTable dt: all) { | |
83 if (isDischargeTableRelevant(dt)) { | |
84 relevant.add(dt); | |
85 } | |
86 } | |
87 | |
88 return relevant; | |
89 } | |
90 | |
91 | |
92 protected boolean isDischargeTableRelevant(DischargeTable dt) { | |
93 TimeInterval ti = dt.getTimeInterval(); | |
94 | |
95 Date start = ti.getStartTime(); | |
96 long startTime = start.getTime(); | |
97 | |
98 if (startTime >= timerange[0] && startTime <= timerange[1]) { | |
99 return true; | |
100 } | |
101 | |
102 Date stop = ti.getStopTime(); | |
103 long stopTime = stop != null ? stop.getTime() : -1l; | |
104 | |
105 if (stopTime >= timerange[0] && stopTime <= timerange[1]) { | |
106 return true; | |
107 } | |
108 | |
109 logger.debug("DischargeTable not in range: " + start + " -> " + stop); | |
110 | |
111 return false; | |
112 } | |
113 | |
114 | |
115 protected WQTimerange[] prepareCalculationData(List<DischargeTable> dts) { | |
116 List<WQTimerange> wqts = new ArrayList<WQTimerange>(values.length); | |
117 | |
118 for (double value: values) { | |
119 logger.debug("Prepare data for value: " + value); | |
120 | |
121 String name = mode == MODE_W ? "W=" + value : "Q=" + value; | |
122 WQTimerange wqt = new WQTimerange(name); | |
123 | |
124 for (DischargeTable dt: dts) { | |
125 TimeInterval ti = dt.getTimeInterval(); | |
126 | |
127 Timerange t = new Timerange(ti.getStartTime(),ti.getStopTime()); | |
128 double w; | |
129 double q; | |
130 | |
131 if (mode == MODE_W) { | |
132 w = value; | |
133 q = findValueForW(dt, w); | |
134 } | |
135 else { | |
136 q = value; | |
137 w = findValueForQ(dt, q); | |
138 } | |
139 | |
140 wqt.add(w, q, t); | |
141 } | |
142 | |
143 wqts.add(wqt); | |
144 } | |
145 | |
146 return (WQTimerange[]) wqts.toArray(new WQTimerange[wqts.size()]); | |
147 } | |
148 | |
149 | |
150 protected double findValueForW(DischargeTable dt, double w) { | |
151 logger.warn("TODO: IMPLEMENT ME!"); | |
152 return 5; | |
153 } | |
154 | |
155 | |
156 protected double findValueForQ(DischargeTable dt, double q) { | |
157 logger.warn("TODO: IMPLEMENT ME!"); | |
158 return 10; | |
159 } | |
160 | |
161 | |
68 /** | 162 /** |
69 * Writes the parameters used for this calculation to logger. | 163 * Writes the parameters used for this calculation to logger. |
70 */ | 164 */ |
71 public void debug() { | 165 public void debug() { |
72 StringBuilder sb = new StringBuilder(); | 166 StringBuilder sb = new StringBuilder(); |