Changeset 1078


Ignore:
Timestamp:
08/14/11 22:46:52 (9 years ago)
Author:
philsmart
Message:
 
Location:
raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/MUAEngine.java

    r1040 r1078  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptormua.engine; 
    2021 
     
    3637import uk.ac.cardiff.model.wsmodel.LogFileUploadResult; 
    3738import uk.ac.cardiff.model.wsmodel.StatisticalUnitInformation; 
    38 import uk.ac.cardiff.model.wsmodel.SuggestionValues; 
    3939import uk.ac.cardiff.raptor.parse.BaseEventParser; 
    4040import uk.ac.cardiff.raptor.parse.DataAccessRegister; 
     
    4444import uk.ac.cardiff.raptor.remoting.client.EventReleaseClient; 
    4545import uk.ac.cardiff.raptor.remoting.client.ReleaseFailureException; 
    46 import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 
    4746import uk.ac.cardiff.raptor.store.StorageEngine; 
    4847import uk.ac.cardiff.raptor.store.TransactionInProgressException; 
    4948import uk.ac.cardiff.raptormua.engine.classification.ResourceClassificationBackgroundService; 
    50 import uk.ac.cardiff.raptormua.engine.statistics.Statistic; 
    5149import uk.ac.cardiff.raptormua.engine.statistics.StatisticsHandler; 
    52 import uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor; 
    5350import uk.ac.cardiff.raptormua.model.Users; 
    5451import uk.ac.cardiff.raptormua.upload.BatchFile; 
     
    8885     */ 
    8986    private int maxReleaseEventSize; 
    90      
     87 
    9188    /** Constructor for creating and storing this MUAs capabilities */ 
    9289    private CapabilitiesConstructor capabilitiesConstructor; 
     
    10198     * Sets the statisticalhandler. 
    10299     *  
    103      * @param statisticsHandler 
    104      *            the statistichandler to set 
     100     * @param statisticsHandler the statistichandler to set 
    105101     */ 
    106102    public final void setStatisticsHandler(final StatisticsHandler statisticsHandler) { 
     
    123119 
    124120    /** 
    125      * First, find the earliest event that needs to be retrieved from the storage engine - which may contain duplicates to those already sent, but these are 
    126      * filtered by the releaseClient later. Then send those events to the event release client. 
     121     * First, find the earliest event that needs to be retrieved from the storage engine - which may contain duplicates 
     122     * to those already sent, but these are filtered by the releaseClient later. Then send those events to the event 
     123     * release client. 
    127124     *  
    128125     * @return 
     
    158155 
    159156    /** 
    160      * Gets the capabilities of this MUA, also sets some default values and possible values for the calling view component to 
    161      * display to the user 
     157     * Gets the capabilities of this MUA, also sets some default values and possible values for the calling view 
     158     * component to display to the user 
    162159     *  
    163160     * @return the capabilities of this MUA 
    164161     */ 
    165     public final Capabilities getCapabilities() {    
    166         if (capabilitiesConstructor!=null) 
     162    public final Capabilities getCapabilities() { 
     163        if (capabilitiesConstructor != null) 
    167164            return capabilitiesConstructor.constructCapabilities(statisticsHandler, storageEngine, muaMetadata); 
    168165        else 
     
    174171     * Use the configured raptor parsing library to store the incomming <code>uploadFiles</code> 
    175172     *  
    176      * @param uploadFiles 
    177      *            the files to parse and store 
     173     * @param uploadFiles the files to parse and store 
    178174     * @throws TransactionInProgressException 
    179175     */ 
    180     public final List<LogFileUploadResult> batchParse(final List<LogFileUpload> uploadFiles) throws TransactionInProgressException { 
     176    public final List<LogFileUploadResult> batchParse(final List<LogFileUpload> uploadFiles) 
     177            throws TransactionInProgressException { 
    181178        log.info("Going to parse {} batch uploaded files", uploadFiles.size()); 
    182179        ArrayList<Event> allEvents = new ArrayList<Event>(); 
     
    188185            result.setId(logfileUpload.getId()); 
    189186            try { 
    190                 BaseEventParser parser = dataAccessRegister.getParsingModuleForType(logfileUpload.getEventType().friendlyName); 
    191                 log.debug("Parsing {} using parser {} for type {}", new Object[] { logfileUpload.getName(), parser.getClass(), logfileUpload.getEventType() }); 
     187                BaseEventParser parser = 
     188                        dataAccessRegister.getParsingModuleForType(logfileUpload.getEventType().friendlyName); 
     189                log.debug("Parsing {} using parser {} for type {}", 
     190                        new Object[] {logfileUpload.getName(), parser.getClass(), logfileUpload.getEventType()}); 
    192191                parser.parse(logfileUpload.getData()); 
    193192                allEvents.addAll(parser.getEntryHandler().getEntries()); 
     
    197196 
    198197            } catch (ParserException e) { 
    199                 log.error("Error Parsing the batch uploaded log file {}, with reason", logfileUpload.getName(), e.getMessage()); 
     198                log.error("Error Parsing the batch uploaded log file {}, with reason", logfileUpload.getName(), 
     199                        e.getMessage()); 
    200200 
    201201                result.setStatus("Failed To Parse"); 
    202202                result.setProcessed(false); 
    203203            } catch (EventParserNotFoundException e) { 
    204                 log.error("Event parser could not be found for {}, with reason {}", logfileUpload.getName(), e.getMessage()); 
     204                log.error("Event parser could not be found for {}, with reason {}", logfileUpload.getName(), 
     205                        e.getMessage()); 
    205206 
    206207                result.setStatus("Failed To Parse"); 
     
    222223        for (BatchFile batchFile : uploadFiles) { 
    223224            try { 
    224                 BaseEventParser parser = dataAccessRegister.getParsingModuleForType(batchFile.getEventType().friendlyName); 
    225                 log.debug("Parsing {} using parser {} for type {}", new Object[] { batchFile.getLogFile().getName(), parser.getClass(), batchFile.getEventType() }); 
     225                BaseEventParser parser = 
     226                        dataAccessRegister.getParsingModuleForType(batchFile.getEventType().friendlyName); 
     227                log.debug("Parsing {} using parser {} for type {}", new Object[] {batchFile.getLogFile().getName(), 
     228                        parser.getClass(), batchFile.getEventType()}); 
    226229                parser.parse(batchFile.getLogFile()); 
    227230                List<Event> events = parser.getEntryHandler().getEntries(); 
     
    233236 
    234237            } catch (ParserException e) { 
    235                 log.error("Error Parsing the batch uploaded log file {}, with reason", batchFile.getLogFile().getName(), e.getMessage()); 
     238                log.error("Error Parsing the batch uploaded log file {}, with reason", 
     239                        batchFile.getLogFile().getName(), e.getMessage()); 
    236240            } catch (EventParserNotFoundException e) { 
    237                 log.error("Event parser could not be found for {}, with reason {}", batchFile.getLogFile().getName(), e.getMessage()); 
     241                log.error("Event parser could not be found for {}, with reason {}", batchFile.getLogFile().getName(), 
     242                        e.getMessage()); 
    238243            } 
    239         }        
     244        } 
    240245 
    241246    } 
     
    245250     */ 
    246251    public final void updateStatisticalUnit(final StatisticalUnitInformation statisticalUnitInformation) { 
    247         log.debug("Updating Statistical Unit {}", statisticalUnitInformation.getStatisticParameters().getUnitName()); 
    248252        statisticsHandler.updateStatisticalUnit(statisticalUnitInformation); 
    249253 
     
    251255 
    252256    public void saveAndApplyResourceClassification(List<ResourceMetadata> resourceMetadata) { 
    253         ResourceClassificationBackgroundService backgroundService = new ResourceClassificationBackgroundService(storageEngine.getEntryHandler()); 
     257        ResourceClassificationBackgroundService backgroundService = 
     258                new ResourceClassificationBackgroundService(storageEngine.getEntryHandler()); 
    254259        backgroundService.saveResourceMetadataAndApplyAsync(resourceMetadata); 
    255260    } 
     
    271276 
    272277    /** 
    273      * If <code>pushed</code contains events to add then sent them to the <code>storageEngine</code> for 
    274      * processing, otherwise do nothing. 
     278     * If <code>pushed</code contains events to add then sent them to the <code>storageEngine</code> for processing, 
     279     * otherwise do nothing. 
    275280     *  
    276281     * @param pushed the {@link uk.ac.cardiff.model.wsmodel.EventPushMessage} received from the client. 
     
    278283     */ 
    279284    public final void addAuthentications(final EventPushMessage pushed) throws TransactionInProgressException { 
    280         if (pushed.getEvents().size() > 0){ 
     285        if (pushed.getEvents().size() > 0) { 
    281286            int transactionId = (int) (Math.random() * 1000000); 
    282287            storageEngine.performAsynchronousEntryStoragePipeline(transactionId, pushed.getEvents()); 
     
    301306 
    302307    /** 
    303      * @param storageEngine 
    304      *            the storageEngine to set 
     308     * @param storageEngine the storageEngine to set 
    305309     */ 
    306310    public final void setStorageEngine(final StorageEngine storageEngine) { 
     
    316320 
    317321    /** 
    318      * @param dataAccessRegister 
    319      *            the dataAccessRegister to set 
     322     * @param dataAccessRegister the dataAccessRegister to set 
    320323     */ 
    321324    public final void setDataAccessRegister(final DataAccessRegister dataAccessRegister) { 
     
    331334 
    332335    /** 
    333      * @param maxReleaseEventSize 
    334      *            the maxReleaseEventSize to set 
     336     * @param maxReleaseEventSize the maxReleaseEventSize to set 
    335337     */ 
    336338    public void setMaxReleaseEventSize(int maxReleaseEventSize) { 
  • raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/statistics/StatisticsHandler.java

    r1040 r1078  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptormua.engine.statistics; 
    2021 
    21 import java.lang.reflect.Method; 
    2222import java.util.List; 
    23 import java.util.Set; 
    2423 
    2524import org.slf4j.Logger; 
    2625import org.slf4j.LoggerFactory; 
    2726 
    28 import uk.ac.cardiff.model.event.Event; 
    2927import uk.ac.cardiff.model.report.AggregatorGraphModel; 
    3028import uk.ac.cardiff.model.report.Series; 
    31 import uk.ac.cardiff.model.sql.SQLFilter; 
    3229import uk.ac.cardiff.model.wsmodel.MethodParameter; 
    3330import uk.ac.cardiff.model.wsmodel.ProcessorInformation; 
     
    3936 */ 
    4037public class StatisticsHandler { 
    41      
    42         /** Class Logger */ 
    43         private final Logger log = LoggerFactory.getLogger(StatisticsHandler.class); 
    4438 
    45         /** List of {@link uk.ac.cardiff.raptormua.engine.statistics.Statistic} that have been registered 
    46          * with this handler 
    47          */ 
    48         private List<Statistic> statisticalUnits; 
     39    /** Class Logger */ 
     40    private final Logger log = LoggerFactory.getLogger(StatisticsHandler.class); 
    4941 
    50         /** A reference to the entry handler that is used to access all underlying events*/ 
    51         private EventHandler entryHandler; 
     42    /** 
     43     * List of {@link uk.ac.cardiff.raptormua.engine.statistics.Statistic} that have been registered with this handler 
     44     */ 
     45    private List<Statistic> statisticalUnits; 
    5246 
    53         /**  
    54          * Registers a List of statistics with this StatisticsHandler  
    55          */ 
    56         public void setStatisticalUnits(List<Statistic> statisticalUnits) { 
    57             for (Statistic stat : statisticalUnits){ 
    58                 log.info("Registering statistic {}, role {}",stat.getStatisticParameters().getUnitName(),stat.getStatisticParameters().getType()); 
    59             } 
    60             this.statisticalUnits = statisticalUnits; 
    61         } 
     47    /** A reference to the event handler that is used to access all underlying events */ 
     48    private EventHandler entryHandler; 
    6249 
    63         public List<Statistic> getStatisticalUnits() { 
    64                 return statisticalUnits; 
    65         } 
     50    /** 
     51     * Registers a List of statistics with this StatisticsHandler 
     52     */ 
     53    public void setStatisticalUnits(List<Statistic> statisticalUnits) { 
     54        for (Statistic stat : statisticalUnits) { 
     55            log.info("Registering statistic [{}], role {}", stat.getStatisticParameters().getUnitName(), stat 
     56                    .getStatisticParameters().getType()); 
     57        } 
     58        this.statisticalUnits = statisticalUnits; 
     59    } 
    6660 
    67         /** 
    68          * @param statisticName 
    69          */ 
    70         public AggregatorGraphModel peformStatistic(String statisticName) { 
    71                 for (Statistic statistic : statisticalUnits) { 
    72                         if (statistic.getStatisticParameters().getUnitName().equals(statisticName)) { 
    73                                 return performStatiticalPipeline(statistic); 
    74                         } 
    75                 } 
    76                 return null; 
    77         } 
     61    public List<Statistic> getStatisticalUnits() { 
     62        return statisticalUnits; 
     63    } 
    7864 
    79         private AggregatorGraphModel performStatiticalPipeline(Statistic statistic) { 
    80                 statistic.setEntryHandler(entryHandler); 
    81                 Boolean success = invoke(statistic); 
    82                 log.info("Statistic {} succedded {}",statistic.getStatisticParameters().getUnitName(),success); 
    83                 if (success) { 
    84                         // now send through post processor 
    85                         statistic.postProcess(); 
    86                         try{ 
    87                             AggregatorGraphModel graphModel = statistic.constructGraphModel(); 
    88                             statistic.reset(); 
    89                             return graphModel; 
    90                         } 
    91                         catch(Exception e){ 
    92                             //must catch this error here, so we can clear the observations that the statistic has generated 
    93                             statistic.reset(); 
    94                             log.error("Problem constructing graph model for statistic {}, {}",statistic.getStatisticParameters().getUnitName(),e.getMessage()); 
    95                             return null; 
    96                         } 
    97                 } 
    98                 /* always reset the observationseries for the statistic, so the next execution is not 
    99                 *  an accumulation of the ones before it 
    100                 */ 
    101                 statistic.reset(); 
    102                 return null; 
    103         } 
     65    /** 
     66     * @param statisticName 
     67     */ 
     68    public AggregatorGraphModel peformStatistic(String statisticName) { 
     69        for (Statistic statistic : statisticalUnits) { 
     70            if (statistic.getStatisticParameters().getUnitName().equals(statisticName)) { 
     71                return performStatiticalPipeline(statistic); 
     72            } 
     73        } 
     74        return null; 
     75    } 
    10476 
    105         /** 
    106          * @param statistic 
    107          */ 
    108         private Boolean invoke(Statistic statistic) { 
    109                 if (this.getEntryHandler() != null) 
    110                         log.debug("Working off " + this.getEntryHandler().getNumberOfEvents() + " entries"); 
     77    private AggregatorGraphModel performStatiticalPipeline(Statistic statistic) { 
     78        statistic.setEntryHandler(entryHandler); 
     79        Boolean success = invoke(statistic); 
     80        log.info("Statistic [{}] succedded {}", statistic.getStatisticParameters().getUnitName(), success); 
     81        if (success) { 
     82            // now send through post processor 
     83            statistic.postProcess(); 
     84            try { 
     85                AggregatorGraphModel graphModel = statistic.constructGraphModel(); 
     86                statistic.reset(); 
     87                return graphModel; 
     88            } catch (Exception e) { 
     89                // must catch this error here, so we can clear the observations that the statistic has generated 
     90                statistic.reset(); 
     91                log.error("Problem constructing graph model for statistic {}, {}", statistic.getStatisticParameters() 
     92                        .getUnitName(), e.getMessage()); 
     93                return null; 
     94            } 
     95        } 
     96        /* 
     97         * always reset the observationseries for the statistic, so the next execution is not an accumulation of the 
     98         * ones before it 
     99         */ 
     100        statistic.reset(); 
     101        return null; 
     102    } 
    111103 
    112                 /* stop processing if there are no valid entries */ 
    113                 if (this.getEntryHandler() == null || this.getEntryHandler().getNumberOfEvents() == 0) { 
    114                         log.error("Not enough entries to perform statistic countEntryPerInterval"); 
    115                         return false; 
    116                 } 
     104    /** 
     105     * @param statistic 
     106     */ 
     107    private Boolean invoke(Statistic statistic) { 
     108        if (this.getEntryHandler() != null) 
     109            log.debug("Invoking statistic [{}], working off {} entries", statistic.getStatisticParameters() 
     110                    .getUnitName(), this.getEntryHandler().getNumberOfEvents()); 
    117111 
    118                 try { 
    119                         List<MethodParameter> params = statistic.getStatisticParameters().getMethodParams(); 
    120                         List<Series> listOfSeries = statistic.getStatisticParameters().getSeries(); 
    121                         boolean success = true; 
    122                         for (Series series : listOfSeries){ 
    123                                 String whereClause=series.computeComparisonAsSQL();      
    124                                 if (whereClause==null) 
    125                                     whereClause =""; 
    126                                 log.debug("statistical to invoke {}",statistic); 
    127                                 success = statistic.performStatistic(params, whereClause); 
    128                         } 
    129                         return success; 
    130                 } catch (StatisticalUnitException e) { 
    131                         log.error("Failed to invoke statistics {}",statistic.getStatisticParameters().getUnitName(),e); 
    132                          
    133                 } 
    134                 return false; 
     112        /* stop processing if there are no valid entries */ 
     113        if (this.getEntryHandler() == null || this.getEntryHandler().getNumberOfEvents() == 0) { 
     114            log.error("Not enough entries to perform statistic countEntryPerInterval"); 
     115            return false; 
     116        } 
    135117 
    136         } 
     118        try { 
     119            List<MethodParameter> params = statistic.getStatisticParameters().getMethodParams(); 
     120            List<Series> listOfSeries = statistic.getStatisticParameters().getSeries(); 
     121            boolean success = true; 
     122            for (Series series : listOfSeries) { 
     123                String whereClause = series.computeComparisonAsSQL(); 
     124                if (whereClause == null) { 
     125                    whereClause = ""; 
     126                } 
     127                success = statistic.performStatistic(params, whereClause); 
     128            } 
     129            return success; 
     130        } catch (StatisticalUnitException e) { 
     131            log.error("Failed to invoke statistics [{}]", statistic.getStatisticParameters().getUnitName(), e); 
    137132 
     133        } 
     134        return false; 
    138135 
    139         /** 
    140          * updates a statistical unit based on the values in the 
    141          * <code>statisticalUnitInformation</code> parameter Not a very good primary 
    142          * key (unit name) should be something else 
    143          * 
    144          * @param statisticalUnitInformation 
    145          */ 
    146         public void updateStatisticalUnit(StatisticalUnitInformation statisticalUnitInformation) { 
    147                 log.info("Updating statistical unit {} ", statisticalUnitInformation.getStatisticParameters().getUnitName()); 
    148                 Statistic toUpdate = null; 
    149                 for (Statistic statistic : statisticalUnits) { 
    150                         if (statistic.getStatisticParameters().getUnitName() 
    151                                         .equals(statisticalUnitInformation.getStatisticParameters().getUnitName())) 
    152                                 toUpdate = statistic; 
    153                 } 
    154                 log.debug("Found Statistic {} to update", toUpdate); 
    155                 update(toUpdate, statisticalUnitInformation); 
     136    } 
    156137 
    157         } 
     138    /** 
     139     * updates a statistical unit based on the values in the <code>statisticalUnitInformation</code> parameter Not a 
     140     * very good primary key (unit name) should be something else 
     141     *  
     142     * @param statisticalUnitInformation 
     143     */ 
     144    public void updateStatisticalUnit(StatisticalUnitInformation statisticalUnitInformation) { 
     145        Statistic toUpdate = null; 
     146        for (Statistic statistic : statisticalUnits) { 
     147            if (statistic.getStatisticParameters().getUnitName() 
     148                    .equals(statisticalUnitInformation.getStatisticParameters().getUnitName())) 
     149                toUpdate = statistic; 
     150        } 
     151        log.debug("Found statistic [{}] to update", toUpdate.getStatisticParameters().getUnitName()); 
     152        update(toUpdate, statisticalUnitInformation); 
     153        log.debug("Finished updating statistic [{}]", toUpdate.getStatisticParameters().getUnitName()); 
    158154 
    159         /** 
    160          * Updates the statistical parameters of the statistic, does not yet handle the post processors 
    161          * 
    162          * @param statistic 
    163          * @param statisticalUnitInformation 
    164          */ 
    165         private void update(Statistic statistic, StatisticalUnitInformation statisticalUnitInformation) { 
    166                 statistic.setStatisticParameters(statisticalUnitInformation.getStatisticParameters()); 
    167                 //now deal with the post processors 
    168                 List<ProcessorInformation> postprocessors = statisticalUnitInformation.getPostprocessors(); 
    169                 for (ProcessorInformation processor : postprocessors){ 
    170                         log.debug("Post processor {}, added to {}",processor.getBeanName(),statisticalUnitInformation.getStatisticParameters().getUnitName()); 
    171                 } 
    172         } 
     155    } 
    173156 
    174         /** 
    175          * 
    176          * @param entryHandler 
    177          */ 
    178         public void setEntryHandler(EventHandler entryHandler) { 
    179                 this.entryHandler = entryHandler; 
    180         } 
     157    /** 
     158     * Updates the statistical parameters of the passed statistic, does not yet handle the post processors 
     159     *  
     160     * @param statistic - the statistic to update 
     161     * @param statisticalUnitInformation - the statistical unit information to used update the <code>statistic</code> 
     162     */ 
     163    private void update(Statistic statistic, StatisticalUnitInformation statisticalUnitInformation) { 
     164        statistic.setStatisticParameters(statisticalUnitInformation.getStatisticParameters()); 
     165        // now deal with the post processors 
     166        List<ProcessorInformation> postprocessors = statisticalUnitInformation.getPostprocessors(); 
     167        statisticalUnitInformation.setPostprocessors(postprocessors); 
     168    } 
    181169 
    182         /** 
    183          * 
    184          * @return 
    185          */ 
    186         public EventHandler getEntryHandler() { 
    187                 return entryHandler; 
    188         } 
     170    /** 
     171     *  
     172     * @param entryHandler 
     173     */ 
     174    public void setEntryHandler(EventHandler entryHandler) { 
     175        this.entryHandler = entryHandler; 
     176    } 
     177 
     178    /** 
     179     *  
     180     * @return 
     181     */ 
     182    public EventHandler getEntryHandler() { 
     183        return entryHandler; 
     184    } 
    189185 
    190186} 
  • raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/statistics/processor/CutRowsPostProcessor.java

    r1020 r1078  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptormua.engine.statistics.processor; 
    20  
    21 import java.util.Arrays; 
    22 import java.util.Collections; 
    23 import java.util.List; 
    2421 
    2522import org.slf4j.Logger; 
    2623import org.slf4j.LoggerFactory; 
    2724 
    28 import uk.ac.cardiff.model.event.Event; 
    2925import uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor; 
    30 import uk.ac.cardiff.raptormua.engine.statistics.helper.ObservationComparator; 
    3126import uk.ac.cardiff.raptormua.engine.statistics.records.Bucket; 
    3227import uk.ac.cardiff.raptormua.engine.statistics.records.Group; 
     
    3530/** 
    3631 * @author philsmart 
    37  * 
     32 *  
    3833 */ 
    3934public class CutRowsPostProcessor implements StatisticsPostProcessor { 
     
    4540 
    4641    /** 
    47      * <p> performs all actions directly (inplace or 'live') on the input object,and passes that back as a reference to conform with the 
    48      * <code>StatisticsPostProcessor</code> interface </p> 
    49      * 
     42     * <p> 
     43     * performs all actions directly (inplace or 'live') on the input object,and passes that back as a reference to 
     44     * conform with the <code>StatisticsPostProcessor</code> interface 
     45     * </p> 
     46     *  
    5047     * (non-Javadoc) 
    51      * 
     48     *  
    5249     * @see uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor#postProcess(uk.ac.cardiff.raptormua.engine.statistics.records.Observation[]) 
    5350     */ 
    5451 
    5552    public Observation[] postProcess(Observation[] observations) throws PostprocessorException { 
    56         log.debug("Entries into postprocessor: " + observations.length); 
    57         log.info("Post Processor " + this.getClass()); 
    58         int rowsToKeep = (observations.length < numberOfRowsToKeep) ? observations.length : numberOfRowsToKeep; 
    59         log.debug("Keeping {} rows", rowsToKeep); 
    60         if (rowsToKeep > 0) { 
    61             if (observations instanceof Group[]) { 
    62                 Group[] cut = new Group[rowsToKeep]; 
    63                 for (int i = 0; (i < observations.length) && (i < rowsToKeep); i++) { 
    64                     cut[i] = (Group) observations[i]; 
    65                 } 
    66                 log.debug("Cut has {} rows", cut.length); 
    67                 return cut; 
    68             } 
    69             if (observations instanceof Bucket[]) { 
    70                 Bucket[] cut = new Bucket[rowsToKeep]; 
    71                 for (int i = 0; (i < observations.length) && (i < rowsToKeep); i++) { 
    72                     cut[i] = (Bucket) observations[i]; 
    73                 } 
    74                 log.debug("Cut has {} rows", cut.length); 
    75                 return cut; 
    76             } 
    77         } 
    78         return observations; 
     53        log.debug("{} post processor called, entries into postprocessor: {}", this.getClass(), observations.length); 
     54        int rowsToKeep = (observations.length < numberOfRowsToKeep) ? observations.length : numberOfRowsToKeep; 
     55        log.debug("Keeping {} rows", rowsToKeep); 
     56        if (rowsToKeep > 0) { 
     57            if (observations instanceof Group[]) { 
     58                Group[] cut = new Group[rowsToKeep]; 
     59                for (int i = 0; (i < observations.length) && (i < rowsToKeep); i++) { 
     60                    cut[i] = (Group) observations[i]; 
     61                } 
     62                log.debug("Cut has {} rows", cut.length); 
     63                return cut; 
     64            } 
     65            if (observations instanceof Bucket[]) { 
     66                Bucket[] cut = new Bucket[rowsToKeep]; 
     67                for (int i = 0; (i < observations.length) && (i < rowsToKeep); i++) { 
     68                    cut[i] = (Bucket) observations[i]; 
     69                } 
     70                log.debug("Cut has {} rows", cut.length); 
     71                return cut; 
     72            } 
     73        } 
     74        return observations; 
    7975    } 
    8076 
    8177    public void setNumberOfRowsToKeep(int numberOfRowsToKeep) { 
    82         this.numberOfRowsToKeep = numberOfRowsToKeep; 
     78        this.numberOfRowsToKeep = numberOfRowsToKeep; 
    8379    } 
    8480 
    8581    public int getNumberOfRowsToKeep() { 
    86         return numberOfRowsToKeep; 
     82        return numberOfRowsToKeep; 
    8783    } 
    8884 
  • raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/statistics/processor/NumberFormatterPostProcessor.java

    r1020 r1078  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptormua.engine.statistics.processor; 
    2021 
    2122import java.text.DecimalFormat; 
    2223import java.text.DecimalFormatSymbols; 
    23 import java.util.Arrays; 
    24 import java.util.Collections; 
    25 import java.util.List; 
    2624 
    2725import org.slf4j.Logger; 
    2826import org.slf4j.LoggerFactory; 
    2927 
    30  
    31 import uk.ac.cardiff.model.event.Event; 
    3228import uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor; 
    33 import uk.ac.cardiff.raptormua.engine.statistics.helper.ObservationComparator; 
    3429import uk.ac.cardiff.raptormua.engine.statistics.records.Observation; 
    3530 
    3631/** 
    3732 * @author philsmart 
    38  * 
     33 *  
    3934 */ 
    40 public class NumberFormatterPostProcessor implements StatisticsPostProcessor{ 
     35public class NumberFormatterPostProcessor implements StatisticsPostProcessor { 
    4136 
    42         /* class logger */ 
    43         static Logger log = LoggerFactory.getLogger(NumberFormatterPostProcessor.class); 
     37    /* class logger */ 
     38    static Logger log = LoggerFactory.getLogger(NumberFormatterPostProcessor.class); 
    4439 
     40    /* 
     41     * <p> performs all actions directly ('live') on the input object, and passes that back as a reference to conform 
     42     * with the <code>StatisticsPostProcessor</code> interface </p> 
     43     *  
     44     * (non-Javadoc) 
     45     *  
     46     * @see 
     47     * uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor#postProcess(uk.ac.cardiff.raptormua.engine. 
     48     * statistics.records.Observation[]) 
     49     */ 
     50    public Observation[] postProcess(Observation[] observations) throws PostprocessorException { 
     51        log.debug("{} post processor called, entries into postprocessor: {}", this.getClass(), observations.length); 
     52        for (Observation obs : observations) { 
    4553 
     54        } 
     55        return observations; 
     56    } 
    4657 
    47         /* 
    48          * <p> performs all actions directly ('live') on the input object, and passes that back as a reference 
    49          * to conform with the <code>StatisticsPostProcessor</code> interface </p> 
    50          * 
    51          * (non-Javadoc) 
    52          * @see uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor#postProcess(uk.ac.cardiff.raptormua.engine.statistics.records.Observation[]) 
    53          */ 
    54         public Observation[] postProcess(Observation[] observations)    throws PostprocessorException { 
    55                 log.debug("Entries into postprocessor: "+observations.length); 
    56                 log.info("Post Processor "+this.getClass()); 
    57                 for (Observation obs : observations){ 
    58                          
    59                 } 
    60                 return observations; 
    61         } 
    62          
    63         private String formatDoubleWithCommas(double number){ 
    64             DecimalFormat df = new DecimalFormat(); 
    65             DecimalFormatSymbols dfs = new DecimalFormatSymbols(); 
    66             dfs.setGroupingSeparator(','); 
    67             df.setDecimalFormatSymbols(dfs); 
    68             String formattedNumber = df.format((int)number); 
    69             return formattedNumber; 
    70         } 
    71  
     58    private String formatDoubleWithCommas(double number) { 
     59        DecimalFormat df = new DecimalFormat(); 
     60        DecimalFormatSymbols dfs = new DecimalFormatSymbols(); 
     61        dfs.setGroupingSeparator(','); 
     62        df.setDecimalFormatSymbols(dfs); 
     63        String formattedNumber = df.format((int) number); 
     64        return formattedNumber; 
     65    } 
    7266 
    7367} 
  • raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/statistics/processor/PercentagePostProcessor.java

    r1020 r1078  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptormua.engine.statistics.processor; 
    20  
    21 import java.util.List; 
    2221 
    2322import org.slf4j.Logger; 
    2423import org.slf4j.LoggerFactory; 
    2524 
    26 import uk.ac.cardiff.model.event.Event; 
    2725import uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor; 
    2826import uk.ac.cardiff.raptormua.engine.statistics.records.Observation; 
     
    3028/** 
    3129 * @author philsmart 
    32  * 
     30 *  
    3331 */ 
    34 public class PercentagePostProcessor implements StatisticsPostProcessor{ 
     32public class PercentagePostProcessor implements StatisticsPostProcessor { 
    3533 
    36         /* class logger */ 
    37         private final Logger log = LoggerFactory.getLogger(PercentagePostProcessor.class); 
     34    /* class logger */ 
     35    private final Logger log = LoggerFactory.getLogger(PercentagePostProcessor.class); 
    3836 
     37    /** 
     38     * <p> 
     39     * performs all actions directly ('live') on the input object, and passes that back as a reference to conform with 
     40     * the <code>StatisticsPostProcessor</code> interface 
     41     * </p> 
     42     *  
     43     * (non-Javadoc) 
     44     *  
     45     * @see uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor#postProcess(uk.ac.cardiff.raptormua.engine.statistics.records.Observation[]) 
     46     */ 
     47    public Observation[] postProcess(Observation[] observations) throws PostprocessorException { 
     48        log.debug("{} post processor called, entries into postprocessor: {}", this.getClass(), observations.length); 
     49        // find total value (sum) 
     50        double sum = 0; 
     51        for (Observation obs : observations) { 
     52            sum += obs.getValue(); 
     53        } 
    3954 
    40         /** 
    41          * <p> performs all actions directly ('live') on the input object, and passes that back as a reference 
    42          * to conform with the <code>StatisticsPostProcessor</code> interface </p> 
    43          * 
    44          * (non-Javadoc) 
    45          * @see uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor#postProcess(uk.ac.cardiff.raptormua.engine.statistics.records.Observation[]) 
    46          */ 
    47         public Observation[] postProcess(Observation[] observations)    throws PostprocessorException { 
    48                 log.debug("Entries into postprocessor: "+observations.length); 
    49                 log.info("Post Processor "+this.getClass()); 
     55        // now set all values as percentages of the max 
     56        for (Observation obs : observations) { 
     57            double percentage = (obs.getValue() / sum) * 100; 
     58            obs.setValue(percentage); 
     59        } 
     60        return observations; 
    5061 
    51                 //find total value (sum) 
    52                 double sum =0; 
    53                 for (Observation obs : observations){ 
    54                         sum+= obs.getValue(); 
    55                 } 
    56  
    57                 //now set all values as percentages of the max 
    58                 for (Observation obs: observations){ 
    59                         double percentage = (obs.getValue()/sum)*100; 
    60                         obs.setValue(percentage); 
    61                 } 
    62                 return observations; 
    63  
    64         } 
     62    } 
    6563 
    6664} 
  • raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/statistics/processor/RowSortPostProcessor.java

    r1020 r1078  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptormua.engine.statistics.processor; 
    2021 
    2122import java.util.Arrays; 
    22 import java.util.Collections; 
    23 import java.util.List; 
    2423 
    2524import org.slf4j.Logger; 
    2625import org.slf4j.LoggerFactory; 
    2726 
    28 import uk.ac.cardiff.model.event.Event; 
    2927import uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor; 
    3028import uk.ac.cardiff.raptormua.engine.statistics.helper.ObservationComparator; 
     
    3331/** 
    3432 * @author philsmart 
    35  * 
     33 *  
    3634 */ 
    37 public class RowSortPostProcessor implements StatisticsPostProcessor{ 
     35public class RowSortPostProcessor implements StatisticsPostProcessor { 
    3836 
    39         /** class logger */ 
    40         private final Logger log = LoggerFactory.getLogger(RowSortPostProcessor.class); 
     37    /** class logger */ 
     38    private final Logger log = LoggerFactory.getLogger(RowSortPostProcessor.class); 
    4139 
    42         private boolean ascending; 
     40    private boolean ascending; 
    4341 
    44         public RowSortPostProcessor(){ 
    45             ascending=true; 
    46         } 
     42    public RowSortPostProcessor() { 
     43        ascending = true; 
     44    } 
    4745 
     46    /** 
     47     * <p> 
     48     * performs all actions directly ('live') on the input object, and passes that back as a reference to conform with 
     49     * the <code>StatisticsPostProcessor</code> interface 
     50     * </p> 
     51     *  
     52     * (non-Javadoc) 
     53     *  
     54     * @see uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor#postProcess(uk.ac.cardiff.raptormua.engine.statistics.records.Observation[]) 
     55     */ 
     56    public Observation[] postProcess(Observation[] observations) throws PostprocessorException { 
     57        log.debug("{} post processor called, entries into postprocessor: {}", this.getClass(), observations.length); 
     58        Arrays.sort(observations, new ObservationComparator(ascending)); 
     59        return observations; 
     60    } 
    4861 
    49         /** 
    50          * <p> performs all actions directly ('live') on the input object, and passes that back as a reference 
    51          * to conform with the <code>StatisticsPostProcessor</code> interface </p> 
    52          * 
    53          * (non-Javadoc) 
    54          * @see uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor#postProcess(uk.ac.cardiff.raptormua.engine.statistics.records.Observation[]) 
    55          */ 
    56         public Observation[] postProcess(Observation[] observations)    throws PostprocessorException { 
    57                 log.debug("Entries into postprocessor: "+observations.length); 
    58                 log.info("Post Processor "+this.getClass()); 
    59                 Arrays.sort(observations,new ObservationComparator(ascending)); 
    60                 return observations; 
    61         } 
     62    public void setAscending(boolean ascending) { 
     63        this.ascending = ascending; 
     64    } 
    6265 
    63  
    64         public void setAscending(boolean ascending) { 
    65             this.ascending = ascending; 
    66         } 
    67  
    68  
    69         public boolean isAscending() { 
    70             return ascending; 
    71         } 
     66    public boolean isAscending() { 
     67        return ascending; 
     68    } 
    7269 
    7370} 
  • raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/statistics/processor/SortGroupsAlphabeticallyPostProcessor.java

    r1020 r1078  
    1717 * 
    1818 */ 
     19 
    1920package uk.ac.cardiff.raptormua.engine.statistics.processor; 
    2021 
    2122import java.util.Arrays; 
    22 import java.util.Collections; 
    23 import java.util.List; 
    2423 
    2524import org.slf4j.Logger; 
    2625import org.slf4j.LoggerFactory; 
    2726 
    28 import uk.ac.cardiff.model.event.Event; 
    2927import uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor; 
    30 import uk.ac.cardiff.raptormua.engine.statistics.helper.ObservationComparator; 
    3128import uk.ac.cardiff.raptormua.engine.statistics.helper.StringGroupComparator; 
    3229import uk.ac.cardiff.raptormua.engine.statistics.records.Group; 
     
    3936public class SortGroupsAlphabeticallyPostProcessor implements StatisticsPostProcessor { 
    4037 
    41         /** class logger */ 
    42         private final Logger log = LoggerFactory.getLogger(SortGroupsAlphabeticallyPostProcessor.class); 
     38    /** class logger */ 
     39    private final Logger log = LoggerFactory.getLogger(SortGroupsAlphabeticallyPostProcessor.class); 
    4340 
    44         private boolean ascending; 
     41    private boolean ascending; 
    4542 
    46         public SortGroupsAlphabeticallyPostProcessor() { 
    47                 ascending = true; 
    48         } 
     43    public SortGroupsAlphabeticallyPostProcessor() { 
     44        ascending = true; 
     45    } 
    4946 
    50         /** 
    51          * <p> 
    52          * performs all actions directly ('live') on the input object, and passes 
    53          * that back as a reference to conform with the 
    54          * <code>StatisticsPostProcessor</code> interface 
    55          * </p> 
    56          *  
    57          * (non-Javadoc) 
    58          *  
    59          * @see uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor#postProcess(uk.ac.cardiff.raptormua.engine.statistics.records.Observation[]) 
    60          */ 
    61         public Observation[] postProcess(Observation[] observations) throws PostprocessorException { 
    62                 log.debug("Entries into postprocessor: " + observations.length); 
    63                 log.info("Post Processor " + this.getClass()); 
    64                 if (observations instanceof Group[]) { 
    65                         Arrays.sort((Group[])observations, new StringGroupComparator(ascending)); 
    66                         return observations; 
    67                 } else { 
    68                         log.error("Wrong observation type passed into {}", this.getClass().getSimpleName()); 
    69                         return observations; 
    70                 } 
    71         } 
     47    /** 
     48     * <p> 
     49     * performs all actions directly ('live') on the input object, and passes that back as a reference to conform with 
     50     * the <code>StatisticsPostProcessor</code> interface 
     51     * </p> 
     52     *  
     53     * (non-Javadoc) 
     54     *  
     55     * @see uk.ac.cardiff.raptormua.engine.statistics.StatisticsPostProcessor#postProcess(uk.ac.cardiff.raptormua.engine.statistics.records.Observation[]) 
     56     */ 
     57    public Observation[] postProcess(Observation[] observations) throws PostprocessorException { 
     58        log.debug("{} post processor called, entries into postprocessor: {}", this.getClass(), observations.length); 
     59        if (observations instanceof Group[]) { 
     60            Arrays.sort((Group[]) observations, new StringGroupComparator(ascending)); 
     61            return observations; 
     62        } else { 
     63            log.error("Wrong observation type passed into {}", this.getClass().getSimpleName()); 
     64            return observations; 
     65        } 
     66    } 
    7267 
    73         public void setAscending(boolean ascending) { 
    74                 this.ascending = ascending; 
    75         } 
     68    public void setAscending(boolean ascending) { 
     69        this.ascending = ascending; 
     70    } 
    7671 
    77         public boolean isAscending() { 
    78                 return ascending; 
    79         } 
     72    public boolean isAscending() { 
     73        return ascending; 
     74    } 
    8075 
    8176} 
Note: See TracChangeset for help on using the changeset viewer.