Changeset 510
- Timestamp:
- 02/06/11 23:43:18 (2 years ago)
- Location:
- raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua
- Files:
-
- 1 added
- 4 edited
-
engine/statistics/AuthenticationStatistic.java (modified) (4 diffs)
-
engine/statistics/ObservationSeries.java (added)
-
engine/statistics/Statistic.java (modified) (1 diff)
-
engine/statistics/StatisticsHandler.java (modified) (5 diffs)
-
model/PersistantEntryHandler.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/statistics/AuthenticationStatistic.java
r506 r510 154 154 // + timeInterval + " minutes, where "+sqlWhere+")"); 155 155 // } 156 157 observations = buckets; 156 ObservationSeries series= new ObservationSeries(); 157 series.setObservations(buckets); 158 getObservationSeries().add(series); 159 158 160 159 161 // finished successfully, no exception thrown … … 257 259 // } 258 260 259 observations = buckets; 260 261 ObservationSeries series= new ObservationSeries(); 262 series.setObservations(buckets); 263 getObservationSeries().add(series); 264 261 265 return true; 262 266 … … 315 319 // } 316 320 317 observations = groups.toArray(new Group[0]); 318 319 if (observations.length == 0) 321 if (groups.size() == 0) 320 322 return false; 323 321 324 // finished successfully, no exception thrown 325 ObservationSeries series= new ObservationSeries(); 326 series.setObservations(groups.toArray(new Group[0])); 327 getObservationSeries().add(series); 328 322 329 return true; 323 330 … … 366 373 // statisticParameters.getSeries().setSeriesLabel("Distinct Values " + groupByField); 367 374 368 observations = groups.toArray(new Group[0]); 369 370 if (observations.length == 0) 375 if (groups.size() == 0) 371 376 return false; 377 378 // finished successfully, no exception thrown 379 ObservationSeries series= new ObservationSeries(); 380 series.setObservations(groups.toArray(new Group[0])); 381 getObservationSeries().add(series); 382 372 383 // finished successfully, no exception thrown 373 384 return true; -
raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/statistics/Statistic.java
r506 r510 39 39 import uk.ac.cardiff.raptormua.exceptions.PostprocessorException; 40 40 import uk.ac.cardiff.raptormua.exceptions.PreprocessorException; 41 import uk.ac.cardiff.raptormua.exceptions.StatisticalUnitException; 41 42 import uk.ac.cardiff.raptormua.model.EntryHandler; 42 43 import uk.ac.cardiff.raptormua.runtimeutils.EntryClone; 43 44 44 45 /** 45 * @author philsmart Holds a statistics unit or one statistics operation on one piece of data 46 * @author philsmart Holds a statistics unit or one statistics operation on one 47 * piece of data 46 48 */ 47 49 public class Statistic { 48 50 49 static Logger log = LoggerFactory.getLogger(Statistic.class); 50 51 private EntryHandler entryHandler; 52 53 protected StatisticParameters statisticParameters; 54 55 /* add a preprocessing module to the statistical method */ 56 private StatisticsPreProcessor preprocessor; 57 58 /* add a postprocessing module to the statistical method */ 59 private List<StatisticsPostProcessor> postprocessor; 60 61 /* 62 * each statistical method produces objects (observations) which are stored in this array variable ready for postprocessing or construction of an 63 * <code>AggregatorGraphModel</code> 64 */ 65 protected Observation[] observations; 66 67 public void setEntryHandler(EntryHandler entryHandler) { 68 if (preprocessor != null) 69 try { 70 log.info("Invoking statistical preprocessor " + preprocessor.getClass()); 71 preprocessor.preProcess(entryHandler); 72 } catch (PreprocessorException e) { 73 log.error("Could not preprocess entries " + preprocessor.getClass()); 74 } 75 this.entryHandler = entryHandler; 76 } 77 78 79 /** 80 * <p> 81 * construct a graph model from the data observations and groupings stored in the buckets 82 * </p> 83 * 84 * @return 85 */ 86 public AggregatorGraphModel constructGraphModel() { 87 AggregatorGraphModel gmodel = new AggregatorGraphModel(); 88 89 log.debug("Observations type " + observations); 90 91 if (observations instanceof Group[]) { 92 log.info("Constructing graph model for Group type"); 93 Group[] groups = (Group[]) observations; 94 gmodel.setPresentation(statisticParameters.getPresentation()); 95 96 ArrayList<String> seriesLabels = new ArrayList<String>(); 97 for (Series series : statisticParameters.getSeries()){ 98 seriesLabels.add(series.getSeriesLabel()); 99 } 100 gmodel.setSeriesLabels(seriesLabels); 101 102 for (int i=0; i < statisticParameters.getSeries().size();i++){ 103 for (Group group : groups) { 104 gmodel.addGroupLabel(group.getGroupName()); 105 List<Double> values = new ArrayList(); 106 Double valueDouble = new Double(group.getValue()); 107 values.add(valueDouble); 108 gmodel.addGroupValue(values); 109 } 110 } 111 } else if (observations instanceof Bucket[]) { 112 log.info("Constructing graph model for Bucket type"); 113 Bucket[] buckets = (Bucket[]) observations; 114 gmodel.setPresentation(statisticParameters.getPresentation()); 115 116 ArrayList<String> seriesLabels = new ArrayList<String>(); 117 for (Series series : statisticParameters.getSeries()){ 118 seriesLabels.add(series.getSeriesLabel()); 119 } 120 gmodel.setSeriesLabels(seriesLabels); 121 122 DateTimeFormatter startParser = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm"); 123 DateTimeFormatter endParser = DateTimeFormat.forPattern("HH:mm"); 124 for (Bucket bucket : buckets) { 125 gmodel.addGroupLabel(startParser.print(bucket.getStart()) + "-" + endParser.print(bucket.getEnd())); 126 List<Double> values = new ArrayList(); 127 Double valueDouble = new Double(bucket.getValue()); 128 values.add(valueDouble); 129 gmodel.addGroupValue(values); 130 } 131 } 132 133 return gmodel; 134 } 135 136 /** 137 * <p> 138 * pre processing effects the entries that go into the statistical unit post processing effects the observations that result form the statistical unit 139 * </p> 140 */ 141 public void postProcess() { 142 try { 143 if (getPostprocessor() != null) { 144 for (StatisticsPostProcessor post : postprocessor){ 145 observations = post.postProcess(observations); 146 } 147 } 148 } catch (PostprocessorException e) { 149 log.error("Could not post process entries, using " + getPostprocessor().getClass()); 150 } 151 } 152 153 public void setField(String field) { 154 155 } 156 157 public void setPreprocessor(StatisticsPreProcessor preprocessor) { 158 this.preprocessor = preprocessor; 159 } 160 161 public StatisticsPreProcessor getPreprocessor() { 162 return preprocessor; 163 } 164 165 public List<StatisticsPostProcessor> getPostprocessor() { 166 return postprocessor; 167 } 168 169 public void setPostprocessor(List<StatisticsPostProcessor> postprocessor) { 170 this.postprocessor = postprocessor; 171 } 172 173 public void setStatisticParameters(StatisticParameters statisticParameters) { 174 this.statisticParameters = statisticParameters; 175 } 176 177 public StatisticParameters getStatisticParameters() { 178 return statisticParameters; 179 } 180 181 182 public EntryHandler getEntryHandler() { 183 return entryHandler; 184 } 51 static Logger log = LoggerFactory.getLogger(Statistic.class); 52 53 private EntryHandler entryHandler; 54 55 protected StatisticParameters statisticParameters; 56 57 /* add a preprocessing module to the statistical method */ 58 private StatisticsPreProcessor preprocessor; 59 60 /* add a postprocessing module to the statistical method */ 61 private List<StatisticsPostProcessor> postprocessor; 62 63 private List<ObservationSeries> observationSeries; 64 65 public Statistic() { 66 setObservationSeries(new ArrayList<ObservationSeries>()); 67 } 68 69 public void setEntryHandler(EntryHandler entryHandler) { 70 if (preprocessor != null) 71 try { 72 log.info("Invoking statistical preprocessor " + preprocessor.getClass()); 73 preprocessor.preProcess(entryHandler); 74 } catch (PreprocessorException e) { 75 log.error("Could not preprocess entries " + preprocessor.getClass()); 76 } 77 this.entryHandler = entryHandler; 78 } 79 80 /** 81 * <p> 82 * construct a graph model from the data observations and groupings stored 83 * in the buckets 84 * </p> 85 * 86 * @return 87 */ 88 public AggregatorGraphModel constructGraphModel() { 89 AggregatorGraphModel gmodel = new AggregatorGraphModel(); 90 int countGroup = 0; 91 int countBucket = 0; 92 93 for (ObservationSeries obsSeries : observationSeries) { 94 if (obsSeries.getObservations() instanceof Group[]) 95 countGroup++; 96 if (obsSeries.getObservations() instanceof Bucket[]) 97 countBucket++; 98 } 99 if (countGroup==0 && countBucket==0)return gmodel; 100 log.debug("Statistic has {} series and {} observations",this.getStatisticParameters().getSeries().size(),observationSeries.size()); 101 if (countGroup == observationSeries.size()) { 102 log.info("Constructing graph model for Group type"); 103 //construct the groups from the first series (each series will have the same grouping) 104 Observation[] observations = observationSeries.get(0).getObservations(); 105 Group[] groups = (Group[]) observations; 106 for (Group group : groups) { 107 gmodel.addGroupLabel(group.getGroupName()); 108 } 109 //now add each series and their values 110 for (int i=0; i < observationSeries.size(); i++){ 111 groups = (Group[]) observations; 112 log.debug("Trying to get series label {}, which is {}",i,statisticParameters.getSeries().get(i).getSeriesLabel()); 113 gmodel.getSeriesLabels().add(statisticParameters.getSeries().get(i).getSeriesLabel()); 114 115 for (Group group : groups) { 116 List<Double> values = new ArrayList(); 117 Double valueDouble = new Double(group.getValue()); 118 values.add(valueDouble); 119 gmodel.addGroupValue(values); 120 } 121 } 122 123 } else if (countBucket==observationSeries.size()) { 124 // log.info("Constructing graph model for {} type", observations.getClass()); 125 // Bucket[] buckets = (Bucket[]) observations; 126 // 127 // ArrayList<String> seriesLabels = new ArrayList<String>(); 128 // for (Series series : statisticParameters.getSeries()) { 129 // seriesLabels.add(series.getSeriesLabel()); 130 // } 131 // gmodel.setSeriesLabels(seriesLabels); 132 // 133 // DateTimeFormatter startParser = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm"); 134 // DateTimeFormatter endParser = DateTimeFormat.forPattern("HH:mm"); 135 // for (Bucket bucket : buckets) { 136 // gmodel.addGroupLabel(startParser.print(bucket.getStart()) + "-" + endParser.print(bucket.getEnd())); 137 // List<Double> values = new ArrayList(); 138 // Double valueDouble = new Double(bucket.getValue()); 139 // values.add(valueDouble); 140 // gmodel.addGroupValue(values); 141 // } 142 } 143 else{ 144 log.error("Statistic had series with mixed observation types, which is currently not supported"); 145 } 146 147 return gmodel; 148 } 149 150 /** 151 * <p> 152 * pre processing effects the entries that go into the statistical unit post 153 * processing effects the observations that result form the statistical unit 154 * </p> 155 */ 156 public void postProcess() { 157 try { 158 if (getPostprocessor() != null) { 159 for (StatisticsPostProcessor post : postprocessor) { 160 // perform the same post process on each observationseries 161 for (ObservationSeries obsSeries : getObservationSeries()) { 162 obsSeries.setObservations(post.postProcess(obsSeries.getObservations())); 163 } 164 } 165 } 166 } catch (PostprocessorException e) { 167 log.error("Could not post process entries, using " + getPostprocessor().getClass()); 168 } 169 } 170 171 public void setField(String field) { 172 173 } 174 175 public void setPreprocessor(StatisticsPreProcessor preprocessor) { 176 this.preprocessor = preprocessor; 177 } 178 179 public StatisticsPreProcessor getPreprocessor() { 180 return preprocessor; 181 } 182 183 public List<StatisticsPostProcessor> getPostprocessor() { 184 return postprocessor; 185 } 186 187 public void setPostprocessor(List<StatisticsPostProcessor> postprocessor) { 188 this.postprocessor = postprocessor; 189 } 190 191 public void setStatisticParameters(StatisticParameters statisticParameters) { 192 this.statisticParameters = statisticParameters; 193 } 194 195 public StatisticParameters getStatisticParameters() { 196 return statisticParameters; 197 } 198 199 public EntryHandler getEntryHandler() { 200 return entryHandler; 201 } 202 203 public void setObservationSeries(List<ObservationSeries> observationSeries) { 204 this.observationSeries = observationSeries; 205 } 206 207 public List<ObservationSeries> getObservationSeries() { 208 return observationSeries; 209 } 185 210 186 211 } -
raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/statistics/StatisticsHandler.java
r506 r510 27 27 28 28 import uk.ac.cardiff.model.Entry; 29 import uk.ac.cardiff.model.Series; 29 30 import uk.ac.cardiff.model.Graph.AggregatorGraphModel; 30 31 import uk.ac.cardiff.model.sql.SQLFilter; … … 68 69 statistic.setEntryHandler(entryHandler); 69 70 Boolean success = invoke(statistic); 70 log.info("Statistic succedded " +success);71 log.info("Statistic {} succedded {}",statistic.getStatisticParameters().getUnitName(),success); 71 72 if (success) { 72 73 // now send through post processor … … 74 75 return statistic.constructGraphModel(); 75 76 } 77 //always reset the observationseries for the statistic, so the next execution is not 78 //an accumulation of the ones before it 79 statistic.getObservationSeries().clear(); 76 80 return null; 77 81 } … … 92 96 try { 93 97 List<MethodParameter> params = statistic.getStatisticParameters().getMethodParams(); 94 SQLFilter sqlFilter = statistic.getStatisticParameters().getSqlFilter(); 95 String whereClause=null; 96 if (sqlFilter !=null){ 97 SQLFilterConstructor sqlConstructor = new SQLFilterConstructor(sqlFilter); 98 whereClause = sqlConstructor.convertFilterToString(); 98 List<Series> listOfSeries = statistic.getStatisticParameters().getSeries(); 99 boolean success = true; 100 for (Series series : listOfSeries){ 101 SQLFilter sqlFilter = statistic.getStatisticParameters().getSqlFilter(); 102 String whereClause=null; 103 if (sqlFilter !=null){ 104 SQLFilterConstructor sqlConstructor = new SQLFilterConstructor(sqlFilter); 105 whereClause = sqlConstructor.convertFilterToString(); 106 } 107 Object[] paramsO = new Object[params.size() + 1]; 108 for (int i = 0; i < paramsO.length-1; i++) { 109 paramsO[i] = params.get(i).getParameter(); 110 } 111 if (whereClause!=null) 112 paramsO[paramsO.length - 1] = whereClause; 113 else 114 paramsO[paramsO.length - 1] = new String(); 115 success= invoke(statistic.getStatisticParameters().getMethodName(), paramsO, statistic); 99 116 } 100 Object[] paramsO = new Object[params.size() + 1]; 101 for (int i = 0; i < paramsO.length-1; i++) { 102 paramsO[i] = params.get(i).getParameter(); 103 } 104 if (whereClause!=null) 105 paramsO[paramsO.length - 1] = whereClause; 106 else 107 paramsO[paramsO.length - 1] = new String(); 108 return invoke(statistic.getStatisticParameters().getMethodName(), paramsO, statistic); 117 return success; 109 118 } catch (Exception e) { 110 119 log.error("Failed to invoke statistics {} -> {}",statistic.getStatisticParameters().getUnitName(),e.getMessage()); … … 128 137 return success; 129 138 } catch (Throwable e) { 130 log.error("F ield name '" + fieldname + "' does not match internal model attribute");139 log.error("Failed to invoke statistics {} -> {}",fieldname,e.getMessage()); 131 140 e.printStackTrace(); 132 141 // System.exit(1); -
raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/model/PersistantEntryHandler.java
r495 r510 87 87 @Override 88 88 public List query(String query) { 89 log.debug("SQL query to entry handler [{}]",query);89 //log.debug("SQL query to entry handler [{}]",query); 90 90 return dataConnection.runQuery(query, null); 91 91 } … … 99 99 @Override 100 100 public Object queryUnique(String query) { 101 log.debug("SQL query to entry handler [{}]",query);101 //log.debug("SQL query to entry handler [{}]",query); 102 102 return dataConnection.runQueryUnique(query, null); 103 103 }
Note: See TracChangeset
for help on using the changeset viewer.
