Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java @ 428:88cd37c3b5e4
Adjusted sql queries and configuration for verticalcrosssection products. Some code refactoring and improved error handling.
gnv-artifacts/trunk@476 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 22 Dec 2009 13:18:07 +0000 |
parents | 04a242c67fe6 |
children | bed9735adf84 |
comparison
equal
deleted
inserted
replaced
427:a95aaeb206f7 | 428:88cd37c3b5e4 |
---|---|
23 import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; | 23 import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; |
24 import org.apache.commons.math.stat.regression.SimpleRegression; | 24 import org.apache.commons.math.stat.regression.SimpleRegression; |
25 import org.apache.log4j.Logger; | 25 import org.apache.log4j.Logger; |
26 | 26 |
27 import de.intevation.gnv.geobackend.base.Result; | 27 import de.intevation.gnv.geobackend.base.Result; |
28 import de.intevation.gnv.geobackend.base.ResultDescriptor; | |
28 import de.intevation.gnv.state.describedata.KeyValueDescibeData; | 29 import de.intevation.gnv.state.describedata.KeyValueDescibeData; |
29 import de.intevation.gnv.statistics.exception.StatisticsException; | 30 import de.intevation.gnv.statistics.exception.StatisticsException; |
30 | 31 |
31 /** | 32 /** |
32 * The class <code>TimeseriesStatistics</code> fulfills the following purposes: | 33 * The class <code>TimeseriesStatistics</code> fulfills the following purposes: |
69 DescriptiveStatistics lStatistics = null; | 70 DescriptiveStatistics lStatistics = null; |
70 SimpleRegression lRegression = null; | 71 SimpleRegression lRegression = null; |
71 Collection<StatisticSet> statisticSets = new ArrayList<StatisticSet>(); | 72 Collection<StatisticSet> statisticSets = new ArrayList<StatisticSet>(); |
72 String break1, break2, break3; | 73 String break1, break2, break3; |
73 int lSeries = 1; | 74 int lSeries = 1; |
75 | |
76 int b1Idx = -1; | |
77 int b2Idx = -1; | |
78 int b3Idx = -1; | |
79 int yIdx = -1; | |
74 try { | 80 try { |
75 | 81 |
76 Iterator<Result> resultIterator = resultSet.iterator(); | 82 Iterator<Result> resultIterator = resultSet.iterator(); |
77 if (resultIterator.hasNext()) { | 83 if (resultIterator.hasNext()) { |
78 Result row = resultIterator.next(); | 84 Result row = resultIterator.next(); |
79 Result previousRow = row; | 85 Result previousRow = row; |
80 break1 = row.getString("GROUP1"); | 86 |
81 break2 = row.getString("GROUP2"); | 87 if (b1Idx == -1) { |
82 break3 = row.getString("GROUP3"); | 88 ResultDescriptor rd = row.getResultDescriptor(); |
89 b1Idx = rd.getColumnIndex("GROUP1"); | |
90 b2Idx = rd.getColumnIndex("GROUP2"); | |
91 b3Idx = rd.getColumnIndex("GROUP3"); | |
92 yIdx = rd.getColumnIndex("YORDINATE"); | |
93 | |
94 if (b1Idx == -1 || b2Idx == -1 || b3Idx == -1 || yIdx == -1) { | |
95 return statisticSets; | |
96 } | |
97 } | |
98 break1 = row.getString(b1Idx); | |
99 break2 = row.getString(b2Idx); | |
100 break3 = row.getString(b3Idx); | |
83 lRegression = new SimpleRegression(); | 101 lRegression = new SimpleRegression(); |
84 lStatistics = new DescriptiveStatistics(); | 102 lStatistics = new DescriptiveStatistics(); |
85 while (resultIterator.hasNext()) { | 103 while (resultIterator.hasNext()) { |
86 | 104 |
87 if (!break1.equals(row.getString("GROUP1")) | 105 if (!break1.equals(row.getString(b1Idx)) |
88 || !break2.equals(row.getString("GROUP2")) | 106 || !break2.equals(row.getString(b2Idx)) |
89 || !break3.equals(row.getString("GROUP3")) | 107 || !break3.equals(row.getString(b3Idx)) |
90 ) { | 108 ) { |
91 String statisticsName = this.generateStatisticsName(break1, break2, | 109 String statisticsName = generateStatisticsName( |
92 break3, parameters, | 110 break1, break2, |
93 measurements, dates); | 111 break3, parameters, |
94 statisticSets.add(this.generateStatisticsValues(lStatistics, | 112 measurements, dates); |
95 lRegression, | 113 |
96 statisticsName)); | 114 statisticSets.add( |
115 generateStatisticsValues( | |
116 lStatistics, | |
117 lRegression, | |
118 statisticsName)); | |
97 | 119 |
98 lStatistics.clear(); | 120 lStatistics.clear(); |
99 lRegression.clear(); | 121 lRegression.clear(); |
100 | 122 |
101 this.clearStatistics(); | 123 clearStatistics(); |
102 | 124 |
103 lStatistics.addValue(row.getDouble("YORDINATE")); | 125 Double yValue = row.getDouble(yIdx); |
104 Double x = this.calculateXOrdinateValue(previousRow,row); | 126 |
105 lRegression.addData(x, row.getDouble("YORDINATE")); | 127 if (yValue != null) { |
106 | 128 lStatistics.addValue(yValue); |
107 break1 = row.getString("GROUP1"); | 129 Double x = calculateXOrdinateValue(previousRow,row); |
108 break2 = row.getString("GROUP2"); | 130 lRegression.addData(x, yValue); |
109 break3 = row.getString("GROUP3"); | 131 } |
132 | |
133 break1 = row.getString(b1Idx); | |
134 break2 = row.getString(b2Idx); | |
135 break3 = row.getString(b3Idx); | |
110 previousRow = row; | 136 previousRow = row; |
111 row = resultIterator.next(); | 137 row = resultIterator.next(); |
112 lSeries++; | 138 lSeries++; |
113 } else { | 139 } else { |
114 | 140 |
115 Double value = row.getDouble("YORDINATE"); | 141 Double value = row.getDouble(yIdx); |
116 if (value != null) { | 142 if (value != null) { |
117 lStatistics.addValue(value.doubleValue()); | 143 lStatistics.addValue(value.doubleValue()); |
118 Double x = calculateXOrdinateValue(previousRow,row); | 144 Double x = calculateXOrdinateValue(previousRow,row); |
119 lRegression.addData(x, value.doubleValue()); | 145 lRegression.addData(x, value.doubleValue()); |
120 } | 146 } |
121 previousRow = row; | 147 previousRow = row; |
122 row = resultIterator.next(); | 148 row = resultIterator.next(); |
123 } | 149 } |
124 | 150 |
125 } | 151 } |
152 | |
153 Double yValue = row.getDouble(yIdx); | |
154 | |
155 if (yValue != null) { | |
156 lStatistics.addValue(yValue); | |
157 Double x = calculateXOrdinateValue(previousRow, row); | |
158 lRegression.addData(x, yValue); | |
159 } | |
126 | 160 |
127 lStatistics.addValue(row.getDouble("YORDINATE")); | 161 String statisticsName = generateStatisticsName( |
128 Double x = this.calculateXOrdinateValue(previousRow, row); | 162 break1, break2, |
129 lRegression.addData(x, row.getDouble("YORDINATE")); | 163 break3, parameters, |
164 measurements, dates); | |
130 | 165 |
131 String statisticsName = this.generateStatisticsName(break1, break2, | 166 statisticSets.add(generateStatisticsValues( |
132 break3, parameters, | 167 lStatistics, |
133 measurements, dates); | 168 lRegression, |
134 | 169 statisticsName)); |
135 statisticSets.add(this.generateStatisticsValues(lStatistics, | |
136 lRegression, | |
137 statisticsName)); | |
138 lStatistics.clear(); | 170 lStatistics.clear(); |
139 lRegression.clear(); | 171 lRegression.clear(); |
140 } | 172 } |
141 } catch (Exception e) { | 173 } catch (Exception e) { |
142 log.error(e.getMessage(), e); | 174 log.error(e.getMessage(), e); |