Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java @ 171:7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
gnv-artifacts/trunk@208 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 09 Oct 2009 07:54:48 +0000 |
parents | 158e89c2263b |
children | 07650fc6014c |
comparison
equal
deleted
inserted
replaced
170:7be22e76c270 | 171:7fb9441dd8af |
---|---|
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.statistics.exception.StatisticsException; | 28 import de.intevation.gnv.statistics.exception.StatisticsException; |
29 | 29 |
30 | |
31 | |
32 /** | 30 /** |
33 * The class <code>TimeseriesStatistics</code> fulfills the following purposes: | 31 * The class <code>TimeseriesStatistics</code> fulfills the following purposes: |
34 * <ol> | 32 * <ol> |
35 * <li></li> | 33 * <li></li> |
36 * </ol> | 34 * </ol> |
37 * | 35 * |
38 * @author blume | 36 * @author blume |
39 * @author Tim Englich <tim.englich@intevation.de> | 37 * @author Tim Englich <tim.englich@intevation.de> |
40 * @version 1.0 | 38 * @version 1.0 |
41 * @serial 1.0 | 39 * @serial 1.0 |
42 * @see | 40 * @see |
50 private static Logger log = Logger.getLogger(TimeseriesStatistics.class); | 48 private static Logger log = Logger.getLogger(TimeseriesStatistics.class); |
51 private static boolean sDebug = log.isDebugEnabled(); | 49 private static boolean sDebug = log.isDebugEnabled(); |
52 | 50 |
53 private Collection<Statistic> statistics = null; | 51 private Collection<Statistic> statistics = null; |
54 | 52 |
55 public TimeseriesStatistics(){ | 53 public TimeseriesStatistics() { |
56 super(); | 54 super(); |
57 } | 55 } |
58 | 56 |
59 /** | 57 /** |
60 * @see de.intevation.gnv.statistics.Statistics#calculateStatistics(java.util.Collection) | 58 * @see de.intevation.gnv.statistics.Statistics#calculateStatistics(java.util.Collection) |
61 */ | 59 */ |
62 public Collection<Statistic> calculateStatistics(Collection<Result> resultSet) throws StatisticsException { | 60 public Collection<Statistic> calculateStatistics( |
61 Collection<Result> resultSet) | |
62 throws StatisticsException { | |
63 DescriptiveStatistics lStatistics = null; | 63 DescriptiveStatistics lStatistics = null; |
64 SimpleRegression lRegression = null; | 64 SimpleRegression lRegression = null; |
65 statistics = new ArrayList<Statistic>(); | 65 statistics = new ArrayList<Statistic>(); |
66 String break1, break2; | 66 String break1, break2; |
67 int lSeries = 1; | 67 int lSeries = 1; |
68 try{ | 68 try { |
69 | 69 |
70 Iterator<Result> resultIterator = resultSet.iterator(); | 70 Iterator<Result> resultIterator = resultSet.iterator(); |
71 if (resultIterator.hasNext()){ | 71 if (resultIterator.hasNext()) { |
72 Result row = resultIterator.next(); | 72 Result row = resultIterator.next(); |
73 break1 = row.getString("GROUP1"); | 73 break1 = row.getString("GROUP1"); |
74 break2 = row.getString("GROUP2"); | 74 break2 = row.getString("GROUP2"); |
75 lRegression = new SimpleRegression(); | 75 lRegression = new SimpleRegression(); |
76 lStatistics = DescriptiveStatistics.newInstance(); | 76 lStatistics = DescriptiveStatistics.newInstance(); |
77 while (resultIterator.hasNext()) { | 77 while (resultIterator.hasNext()) { |
78 | 78 |
79 if (!break1.equals(row.getString("GROUP1")) | 79 if (!break1.equals(row.getString("GROUP1")) |
80 || !break2.equals(row.getString("GROUP2"))) { | 80 || !break2.equals(row.getString("GROUP2"))) { |
81 addStatisticsValues(lStatistics, lRegression, lSeries); | 81 addStatisticsValues(lStatistics, lRegression, lSeries); |
82 | 82 |
83 lStatistics.clear(); | 83 lStatistics.clear(); |
84 lRegression.clear(); | 84 lRegression.clear(); |
85 | 85 |
86 lStatistics.addValue(row.getDouble("YORDINATE")); | 86 lStatistics.addValue(row.getDouble("YORDINATE")); |
87 Double x = this.calculateXOrdinateValue(row); | 87 Double x = this.calculateXOrdinateValue(row); |
88 lRegression.addData(x ,row.getDouble("YORDINATE")); | 88 lRegression.addData(x, row.getDouble("YORDINATE")); |
89 | 89 |
90 break1 = row.getString("GROUP1"); | 90 break1 = row.getString("GROUP1"); |
91 break2 = row.getString("GROUP2"); | 91 break2 = row.getString("GROUP2"); |
92 row = resultIterator.next(); | 92 row = resultIterator.next(); |
93 lSeries ++; | 93 lSeries++; |
94 } else { | |
95 | |
96 lStatistics.addValue(row.getDouble("YORDINATE")); | |
97 Double x = this.calculateXOrdinateValue(row); | |
98 lRegression.addData(x, row.getDouble("YORDINATE")); | |
99 row = resultIterator.next(); | |
100 } | |
101 | |
94 } | 102 } |
95 else{ | 103 addStatisticsValues(lStatistics, lRegression, lSeries); |
96 | 104 lStatistics.clear(); |
97 lStatistics.addValue(row.getDouble("YORDINATE")); | 105 lRegression.clear(); |
98 Double x = this.calculateXOrdinateValue(row); | |
99 lRegression.addData(x,row.getDouble("YORDINATE")); | |
100 row = resultIterator.next(); | |
101 } | |
102 | |
103 } | 106 } |
104 addStatisticsValues(lStatistics, lRegression,lSeries); | 107 } catch (Exception e) { |
105 lStatistics.clear(); | |
106 lRegression.clear(); | |
107 } | |
108 } | |
109 catch (Exception e){ | |
110 log.error(e.getMessage(), e); | 108 log.error(e.getMessage(), e); |
111 } | 109 } |
112 | 110 |
113 return statistics; | 111 return statistics; |
114 } | 112 } |
115 | 113 |
116 | 114 protected double calculateXOrdinateValue(Result row) throws SQLException { |
117 protected double calculateXOrdinateValue(Result row) throws SQLException{ | 115 return new Double((row.getDate("XORDINATE")).getTime() / 1000 / 3600); |
118 return new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ; | |
119 } | 116 } |
120 | 117 |
121 | |
122 /** | 118 /** |
123 * @param lStatistics | 119 * @param lStatistics |
124 * @param lRegression | 120 * @param lRegression |
125 * @param lStats | 121 * @param lStats |
126 * @param lSeries | 122 * @param lSeries |
127 */ | 123 */ |
128 private void addStatisticsValues(DescriptiveStatistics lStatistics, | 124 private void addStatisticsValues(DescriptiveStatistics lStatistics, |
129 SimpleRegression lRegression, int lSeries) { | 125 SimpleRegression lRegression, int lSeries) { |
130 statistics.add(new Statistic("gnviewer.statistics.series",(double)lSeries)); | 126 statistics.add(new Statistic("gnviewer.statistics.series", |
131 statistics.add(new Statistic("gnviewer.statistics.descriptive.arithmeticMean", lStatistics.getMean())); | 127 lSeries)); |
132 statistics.add(new Statistic("gnviewer.statistics.descriptive.kurtosis", lStatistics.getKurtosis())); | 128 statistics.add(new Statistic( |
133 statistics.add(new Statistic("gnviewer.statistics.descriptive.max", lStatistics.getMax())); | 129 "gnviewer.statistics.descriptive.arithmeticMean", lStatistics |
134 statistics.add(new Statistic("gnviewer.statistics.descriptive.min", lStatistics.getMin())); | 130 .getMean())); |
135 statistics.add(new Statistic("gnviewer.statistics.descriptive.n", lStatistics.getN())); | 131 statistics.add(new Statistic( |
136 statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.90", lStatistics.getPercentile(90))); | 132 "gnviewer.statistics.descriptive.kurtosis", lStatistics |
137 statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.75", lStatistics.getPercentile(75))); | 133 .getKurtosis())); |
138 statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.50", lStatistics.getPercentile(50))); | 134 statistics.add(new Statistic("gnviewer.statistics.descriptive.max", |
139 statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.10", lStatistics.getPercentile(10))); | 135 lStatistics.getMax())); |
140 statistics.add(new Statistic("gnviewer.statistics.descriptive.deviation", lStatistics.getStandardDeviation())); | 136 statistics.add(new Statistic("gnviewer.statistics.descriptive.min", |
141 statistics.add(new Statistic("gnviewer.statistics.descriptive.variance", lStatistics.getVariance())); | 137 lStatistics.getMin())); |
142 statistics.add(new Statistic("gnviewer.statistics.descriptive.intercept", lRegression.getIntercept())); | 138 statistics.add(new Statistic("gnviewer.statistics.descriptive.n", |
143 statistics.add(new Statistic("gnviewer.statistics.descriptive.slope", lRegression.getSlope())); | 139 lStatistics.getN())); |
144 } | 140 statistics.add(new Statistic( |
141 "gnviewer.statistics.descriptive.percentile.90", lStatistics | |
142 .getPercentile(90))); | |
143 statistics.add(new Statistic( | |
144 "gnviewer.statistics.descriptive.percentile.75", lStatistics | |
145 .getPercentile(75))); | |
146 statistics.add(new Statistic( | |
147 "gnviewer.statistics.descriptive.percentile.50", lStatistics | |
148 .getPercentile(50))); | |
149 statistics.add(new Statistic( | |
150 "gnviewer.statistics.descriptive.percentile.10", lStatistics | |
151 .getPercentile(10))); | |
152 statistics.add(new Statistic( | |
153 "gnviewer.statistics.descriptive.deviation", lStatistics | |
154 .getStandardDeviation())); | |
155 statistics.add(new Statistic( | |
156 "gnviewer.statistics.descriptive.variance", lStatistics | |
157 .getVariance())); | |
158 statistics.add(new Statistic( | |
159 "gnviewer.statistics.descriptive.intercept", lRegression | |
160 .getIntercept())); | |
161 statistics.add(new Statistic("gnviewer.statistics.descriptive.slope", | |
162 lRegression.getSlope())); | |
163 } | |
145 } | 164 } |