Changeset 537
- Timestamp:
- 02/18/11 18:02:15 (2 years ago)
- Location:
- raptor-mua/trunk/src/main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/statistics/AuthenticationStatistic.java
r535 r537 341 341 } 342 342 343 public Boolean average(String groupByField, String sqlWhere) throws StatisticalUnitException {343 public Boolean groupByCountDistinct(String groupByField, String countDistinctField, String sqlWhere) throws StatisticalUnitException { 344 344 log.debug("Performing groupByFrequency Statistical Operation"); 345 345 log.debug("Params for method: {},{}", statisticParameters.getMethodName(), statisticParameters.getUnitName()); 346 log.debug("Grouping field: {} ", groupByField);346 log.debug("Grouping field: {}, count By distinct field {}", groupByField, countDistinctField); 347 347 348 348 DateTime start = startingTime(); 349 349 DateTime end = endingTime(); 350 350 log.debug("groupByFrequency between [start:{}] [end:{}]", start, end); 351 String tableName = ReflectionHelper.findEntrySubclassForMethod(groupByField); 351 //need to find the lowest level class from which to perform these statistics 352 String tableName = ReflectionHelper.determineSubclassForMethods(groupByField,countDistinctField); 353 352 354 log.debug("Select {}, tableName {}", groupByField, tableName); 353 355 List results = getEntryHandler().query( 354 "select " + groupByField + ",count( *) from " + tableName + " where (eventTime between '" + start356 "select " + groupByField + ",count(distinct "+countDistinctField+") from " + tableName + " where (eventTime between '" + start 355 357 + "' and '" + end + "') group by (" + groupByField + ")"); 356 357 358 358 359 -
raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/runtimeutils/ReflectionHelper.java
r417 r537 29 29 import java.util.jar.JarInputStream; 30 30 31 import org.apache.log4j.Logger; 31 import org.slf4j.Logger; 32 import org.slf4j.LoggerFactory; 33 32 34 33 35 import sun.misc.Launcher; … … 35 37 /** 36 38 * @author philsmart 37 * 39 * 38 40 */ 39 41 public class ReflectionHelper { 40 static Logger log = Logger.getLogger(ReflectionHelper.class); 42 static Logger log = LoggerFactory.getLogger(ReflectionHelper.class); 43 44 public static String determineSubclassForMethods(String methodOne, String methodTwo){ 45 Object methodOneObject = findEntrySubclassForMethodAsObject(methodOne); 46 Object methodTwoObject = findEntrySubclassForMethodAsObject(methodTwo); 47 log.debug("Classes found, methodOne {}, methodTwo {}",methodOneObject.getClass(),methodTwoObject.getClass()); 48 //is methodTwoObject a superclass of methodOneObject, if it is, then its either an equivalent class 49 //or its a subclass so return it 50 log.debug("Is methodOne a superclass of methodTwo {}",(methodOneObject.getClass().isAssignableFrom(methodTwoObject.getClass()))); 51 if (methodTwoObject.getClass().isAssignableFrom(methodOneObject.getClass())){ 52 return methodOneObject.getClass().getSimpleName(); 53 } 54 else{ 55 return methodTwoObject.getClass().getSimpleName(); 56 } 57 58 } 59 60 61 public static Object findEntrySubclassForMethodAsObject(String fieldName) { 62 String forPckgName = "uk.ac.cardiff.model"; 63 String jarFile = getJARFilePath(forPckgName); 64 jarFile = jarFile.replace("file:", ""); 65 List<String> classes = getClasseNamesInPackageJAR(jarFile, forPckgName); 66 ArrayList allclasses = new ArrayList(); 67 for (String classname : classes) { 68 try { 69 Object o = Class.forName(classname.replace(".class", "")).newInstance(); 70 if (o instanceof uk.ac.cardiff.model.Entry) { 71 //log.debug("Found classname: "+classname.replace(".class", "")); 72 allclasses.add(o); 73 } 74 } catch (ClassNotFoundException cnfex) { 75 log.error("{}",cnfex); 76 } catch (InstantiationException iex) { 77 // We try to instantiate an interface 78 // or an object that does not have a 79 // default constructor 80 } catch (IllegalAccessException iaex) { 81 // The class is not public 82 } 83 } 84 85 Object objectWithMethod = null; 86 for (Object object : allclasses) { 87 if (hasField(object, fieldName)) { 88 objectWithMethod = object; 89 } 90 } 91 if (objectWithMethod != null) { 92 log.debug("Object " + objectWithMethod.getClass().getName() + " has method " + fieldName 93 + " returning simple name " + objectWithMethod.getClass().getSimpleName()); 94 return objectWithMethod; 95 } 96 97 return null; 98 99 } 41 100 42 101 /** 43 102 * This method finds the simple name of the class in the uk.ac.cardiff.model 44 103 * package that contains the <code>fieldName</code>. 45 * 104 * 46 105 * @param fieldName 47 106 * @return … … 61 120 } 62 121 } catch (ClassNotFoundException cnfex) { 63 log.error( cnfex);122 log.error("{}",cnfex); 64 123 } catch (InstantiationException iex) { 65 124 // We try to instantiate an interface … … 70 129 } 71 130 } 72 131 73 132 Object objectWithMethod = null; 74 133 for (Object object : allclasses) { … … 113 172 * Gets the names of the classes, as strings, in the jar <code>jarName</code> and package 114 173 * <code>packageName</code> 115 * 174 * 116 175 * @param jarName 117 176 * @param packageName … … 143 202 * the uk.ac.cardiff.model.Entry class in the package <code>pckgname</code> if they 144 203 * exist outside any JAR libraries, use <code>getClasseNamesInPackageJAR</code> 145 * 204 * 146 205 * @param pckgname 147 206 * @return … … 182 241 } 183 242 } catch (ClassNotFoundException cnfex) { 184 log.error( cnfex);243 log.error("{}",cnfex); 185 244 } catch (InstantiationException iex) { 186 245 // We try to instantiate an interface … … 198 257 /** 199 258 * Checks whether the Object <code>object</code> has the field <code>fieldName</code> 200 * 259 * 201 260 * @param object 202 261 * @param fieldName -
raptor-mua/trunk/src/main/webapp/WEB-INF/statistical-units.xml
r536 r537 507 507 </property> 508 508 </bean> 509 510 509 510 511 511 <bean id="numberOfUniqueAuthenticationsPerSP" class="uk.ac.cardiff.raptormua.engine.statistics.AuthenticationStatistic"> 512 512 <property name="statisticParameters"> 513 513 <bean class="uk.ac.cardiff.model.StatisticParameters"> 514 <property name="statisticType"><value> User</value></property>514 <property name="statisticType"><value>System</value></property> 515 515 <property name="unitName"><value>numberOfUniqueAuthenticationsPerSP</value></property> 516 <property name="methodName"><value> average</value></property>516 <property name="methodName"><value>groupByCountDistinct</value></property> 517 517 <property name="methodParams"> 518 518 <list> 519 519 <bean class="uk.ac.cardiff.model.wsmodel.MethodParameter"> 520 520 <property name="parameter"><value>requestHost</value></property> 521 522 </bean> 523 <bean class="uk.ac.cardiff.model.wsmodel.MethodParameter"> 524 <property name="parameter"><value>principleName</value></property> 521 525 </bean> 522 526 </list> … … 526 530 <bean class="uk.ac.cardiff.model.Presentation"> 527 531 <property name="graphTitle" value="Number of Unique Authentications Per Service Provider"/> 532 <property name="xAxisLabel" value="Time"/> 533 <property name="yAxisLabel" value="Frequency"/> 534 </bean> 535 </property> 536 537 <property name="series"> 538 <list> 539 <bean class="uk.ac.cardiff.model.Series"> 540 <property name="seriesLabel" value="Number of auths"/> 541 </bean> 542 </list> 543 </property> 544 545 </bean> 546 </property> 547 <property name="postprocessor"> 548 <list> 549 <ref bean="sortDsc"/> 550 <ref bean="cut"/> 551 <ref bean="ShibbolethMetadataNameFormatter"/> 552 </list> 553 </property> 554 </bean> 555 556 <bean id="bottom5Resources" class="uk.ac.cardiff.raptormua.engine.statistics.AuthenticationStatistic"> 557 <property name="statisticParameters"> 558 <bean class="uk.ac.cardiff.model.StatisticParameters"> 559 <property name="statisticType"><value>System</value></property> 560 <property name="unitName"><value>bottom5Resources</value></property> 561 <property name="methodName"><value>groupByFrequency</value></property> 562 <property name="methodParams"> 563 <list> 564 <bean class="uk.ac.cardiff.model.wsmodel.MethodParameter"> 565 <property name="parameter"><value>requestHost</value></property> 566 </bean> 567 </list> 568 </property> 569 570 <property name="presentation"> 571 <bean class="uk.ac.cardiff.model.Presentation"> 572 <property name="graphTitle" value="Bottom 5 Resources"/> 528 573 <property name="xAxisLabel" value="Time"/> 529 574 <property name="yAxisLabel" value="Frequency"/> … … 550 595 </bean> 551 596 552 <bean id="bottom5Resources" class="uk.ac.cardiff.raptormua.engine.statistics.AuthenticationStatistic">553 <property name="statisticParameters">554 <bean class="uk.ac.cardiff.model.StatisticParameters">555 <property name="statisticType"><value>System</value></property>556 <property name="unitName"><value>bottom5Resources</value></property>557 <property name="methodName"><value>groupByFrequency</value></property>558 <property name="methodParams">559 <list>560 <bean class="uk.ac.cardiff.model.wsmodel.MethodParameter">561 <property name="parameter"><value>requestHost</value></property>562 </bean>563 </list>564 </property>565 566 <property name="presentation">567 <bean class="uk.ac.cardiff.model.Presentation">568 <property name="graphTitle" value="Bottom 5 Resources"/>569 <property name="xAxisLabel" value="Time"/>570 <property name="yAxisLabel" value="Frequency"/>571 </bean>572 </property>573 574 <property name="series">575 <list>576 <bean class="uk.ac.cardiff.model.Series">577 <property name="seriesLabel" value="Number of auths"/>578 </bean>579 </list>580 </property>581 582 </bean>583 </property>584 <property name="postprocessor">585 <list>586 <ref bean="sortAsc"/>587 <ref bean="cut"/>588 <ref bean="ShibbolethMetadataNameFormatter"/>589 </list>590 </property>591 </bean>592 593 597 594 598 </beans>
Note: See TracChangeset
for help on using the changeset viewer.
