Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java @ 95:13402ac8d8fe
Put the Statisticscalulation to the Outmethod of the OutputTransition.
gnv-artifacts/trunk@140 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Mon, 28 Sep 2009 08:20:28 +0000 |
parents | 6a825a184883 |
children | fce237b6fdb8 |
comparison
equal
deleted
inserted
replaced
94:6a825a184883 | 95:13402ac8d8fe |
---|---|
44 public class TimeseriesStatistics implements Statistics { | 44 public class TimeseriesStatistics implements Statistics { |
45 | 45 |
46 /** | 46 /** |
47 * Default Logging instance | 47 * Default Logging instance |
48 */ | 48 */ |
49 private static Logger sLogger = Logger.getLogger(TimeseriesStatistics.class); | 49 private static Logger log = Logger.getLogger(TimeseriesStatistics.class); |
50 private static boolean sDebug = sLogger.isDebugEnabled(); | 50 private static boolean sDebug = log.isDebugEnabled(); |
51 | 51 |
52 private Statistic[] mStatistics = null; | 52 private Collection<Statistic> statistics = null; |
53 | 53 |
54 | 54 public TimeseriesStatistics(){ |
55 public TimeseriesStatistics(Collection<Result> resultSet) throws StatisticsException { | 55 super(); |
56 } | |
57 | |
58 public Collection<Statistic> calculateStatistics(Collection<Result> resultSet) throws StatisticsException { | |
56 DescriptiveStatistics lStatistics = null; | 59 DescriptiveStatistics lStatistics = null; |
57 SimpleRegression lRegression = null; | 60 SimpleRegression lRegression = null; |
58 ArrayList<Statistic> lStats = new ArrayList<Statistic>(); | 61 statistics = new ArrayList<Statistic>(); |
59 int break1, break2; | 62 int break1, break2; |
60 int lSeries = 1; | 63 int lSeries = 1; |
61 if (sDebug) sLogger.debug("TimeseriesStatistics() lImageFile != null"); | 64 if (sDebug) log.debug("TimeseriesStatistics() lImageFile != null"); |
62 try{ | 65 try{ |
63 | 66 |
64 Iterator<Result> resultIterator = resultSet.iterator(); | 67 Iterator<Result> resultIterator = resultSet.iterator(); |
65 if (resultIterator.hasNext()){ | 68 if (resultIterator.hasNext()){ |
66 Result row = resultIterator.next(); | 69 Result row = resultIterator.next(); |
70 lStatistics = DescriptiveStatistics.newInstance(); | 73 lStatistics = DescriptiveStatistics.newInstance(); |
71 while (resultIterator.hasNext()) { | 74 while (resultIterator.hasNext()) { |
72 | 75 |
73 if (break1 != row.getInteger("GROUP1") | 76 if (break1 != row.getInteger("GROUP1") |
74 || break2 != row.getInteger("GROUP2")) { | 77 || break2 != row.getInteger("GROUP2")) { |
75 //lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd); | 78 |
76 //lRegression = createSimpleRegressionObject(pResults,mStart,mEnd); | 79 addStatisticsValues(lStatistics, lRegression, lSeries); |
77 | |
78 addStatisticsValues(lStatistics, lRegression, lStats, lSeries); | |
79 | 80 |
80 lStatistics.clear(); | 81 lStatistics.clear(); |
81 lRegression.clear(); | 82 lRegression.clear(); |
82 | 83 |
83 row = resultIterator.next(); | 84 row = resultIterator.next(); |
95 Double x = new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ; | 96 Double x = new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ; |
96 lRegression.addData(x,row.getDouble("YORDINATE")); | 97 lRegression.addData(x,row.getDouble("YORDINATE")); |
97 } | 98 } |
98 | 99 |
99 } | 100 } |
100 addStatisticsValues(lStatistics, lRegression, lStats, lSeries); | 101 addStatisticsValues(lStatistics, lRegression,lSeries); |
101 lStatistics.clear(); | 102 lStatistics.clear(); |
102 lRegression.clear(); | 103 lRegression.clear(); |
103 mStatistics = new Statistic[lStats.size()]; | |
104 mStatistics = lStats.toArray(mStatistics); | |
105 } | 104 } |
106 } | 105 } |
107 catch (Exception e){ | 106 catch (Exception e){ |
108 sLogger.error(e.getMessage(), e); | 107 log.error(e.getMessage(), e); |
109 } | 108 } |
109 | |
110 return statistics; | |
110 } | 111 } |
112 | |
111 /** | 113 /** |
112 * @param lStatistics | 114 * @param lStatistics |
113 * @param lRegression | 115 * @param lRegression |
114 * @param lStats | 116 * @param lStats |
115 * @param lSeries | 117 * @param lSeries |
116 */ | 118 */ |
117 private void addStatisticsValues(DescriptiveStatistics lStatistics, | 119 private void addStatisticsValues(DescriptiveStatistics lStatistics, |
118 SimpleRegression lRegression, ArrayList<Statistic> lStats, | 120 SimpleRegression lRegression, int lSeries) { |
119 int lSeries) { | 121 statistics.add(new Statistic("gnviewer.statistics.series",(double)lSeries)); |
120 lStats.add(new Statistic("gnviewer.statistics.series",(double)lSeries)); | 122 statistics.add(new Statistic("gnviewer.statistics.descriptive.arithmeticMean", lStatistics.getMean())); |
121 lStats.add(new Statistic("gnviewer.statistics.descriptive.arithmeticMean", lStatistics.getMean())); | 123 statistics.add(new Statistic("gnviewer.statistics.descriptive.kurtosis", lStatistics.getKurtosis())); |
122 lStats.add(new Statistic("gnviewer.statistics.descriptive.kurtosis", lStatistics.getKurtosis())); | 124 statistics.add(new Statistic("gnviewer.statistics.descriptive.max", lStatistics.getMax())); |
123 lStats.add(new Statistic("gnviewer.statistics.descriptive.max", lStatistics.getMax())); | 125 statistics.add(new Statistic("gnviewer.statistics.descriptive.min", lStatistics.getMin())); |
124 lStats.add(new Statistic("gnviewer.statistics.descriptive.min", lStatistics.getMin())); | 126 statistics.add(new Statistic("gnviewer.statistics.descriptive.n", lStatistics.getN())); |
125 lStats.add(new Statistic("gnviewer.statistics.descriptive.n", lStatistics.getN())); | 127 statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.90", lStatistics.getPercentile(90))); |
126 lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.90", lStatistics.getPercentile(90))); | 128 statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.75", lStatistics.getPercentile(75))); |
127 lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.75", lStatistics.getPercentile(75))); | 129 statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.50", lStatistics.getPercentile(50))); |
128 lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.50", lStatistics.getPercentile(50))); | 130 statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.10", lStatistics.getPercentile(10))); |
129 lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.10", lStatistics.getPercentile(10))); | 131 statistics.add(new Statistic("gnviewer.statistics.descriptive.deviation", lStatistics.getStandardDeviation())); |
130 lStats.add(new Statistic("gnviewer.statistics.descriptive.deviation", lStatistics.getStandardDeviation())); | 132 statistics.add(new Statistic("gnviewer.statistics.descriptive.variance", lStatistics.getVariance())); |
131 lStats.add(new Statistic("gnviewer.statistics.descriptive.variance", lStatistics.getVariance())); | 133 statistics.add(new Statistic("gnviewer.statistics.descriptive.intercept", lRegression.getIntercept())); |
132 lStats.add(new Statistic("gnviewer.statistics.descriptive.intercept", lRegression.getIntercept())); | 134 statistics.add(new Statistic("gnviewer.statistics.descriptive.slope", lRegression.getSlope())); |
133 lStats.add(new Statistic("gnviewer.statistics.descriptive.slope", lRegression.getSlope())); | |
134 } | 135 } |
135 | |
136 /** | |
137 * | |
138 * @return | |
139 */ | |
140 public Statistic[] getStatistics() { | |
141 return mStatistics; | |
142 } | |
143 } | 136 } |