Search in sources :

Example 1 with ComponentStatistics

use of alma.acs.monitoring.DAO.ComponentStatistics in project ACS by ACS-Community.

the class BlobData method calculateStatistics.

/**
	 * Calculates the statistics and stores it in {@link #statistics}
	 * if our monitor point data is represented as Number objects;
	 * otherwise this call is ignored.
	 * 
	 * @param inDataList
	 */
void calculateStatistics() {
    if (getDataSize() > 0) {
        // We trust that the data is homogeneous and check only the first MonitorPointValue
        MonitorPointValue sampleMonitorPointValue = mpTs.getDataList().get(0);
        if (sampleMonitorPointValue.getData().isEmpty()) {
            logger.finer("Ignoring calculateStatistics() call for a time series of MonitorPointValue objects that hold no data.");
            return;
        }
        // and so far we keep this behavior. 
        if (sampleMonitorPointValue.isMultiValued()) {
            logger.finer("Ignoring calculateStatistics() call for a time series of multi-valued MonitorPointValue objects.");
            return;
        }
        // After the above checks, there should be a single data item in our sampleMonitorPointValue
        // We now verify that it has one of the expected numeric types.
        Object sampleData = sampleMonitorPointValue.getData().get(0);
        if (!(sampleData instanceof Integer || sampleData instanceof Long || sampleData instanceof Float || sampleData instanceof Double)) {
            logger.finer("Ignoring calculateStatistics() call for data type " + sampleData.getClass().getName());
            return;
        }
        // Now we calculate the statistics, 
        // using apache math lib that works only with 'double' type
        SummaryStatistics stat = new SummaryStatistics();
        for (MonitorPointValue blobData : mpTs.getDataList()) {
            Number value = (Number) blobData.getData().get(0);
            stat.addValue(value.doubleValue());
        }
        statistics = new ComponentStatistics();
        // converting to original data types where it makes sense
        if (sampleData instanceof Integer) {
            statistics.min = new Integer((int) Math.round(stat.getMin()));
            statistics.max = new Integer((int) Math.round(stat.getMax()));
            // or Float, to indicate lower precision?
            statistics.mean = new Double(stat.getMean());
            // or Float, to indicate lower precision?
            statistics.stdDev = new Double(stat.getStandardDeviation());
        } else if (sampleData instanceof Long) {
            statistics.min = new Long(Math.round(stat.getMin()));
            statistics.max = new Long(Math.round(stat.getMax()));
            statistics.mean = new Double(stat.getMean());
            statistics.stdDev = new Double(stat.getStandardDeviation());
        } else if (sampleData instanceof Float) {
            statistics.min = new Float(stat.getMin());
            statistics.max = new Float(stat.getMax());
            statistics.mean = new Float(stat.getMean());
            statistics.stdDev = new Float(stat.getStandardDeviation());
        } else if (sampleData instanceof Double) {
            statistics.min = new Double(stat.getMin());
            statistics.max = new Double(stat.getMax());
            statistics.mean = new Double(stat.getMean());
            statistics.stdDev = new Double(stat.getStandardDeviation());
        }
    }
}
Also used : ComponentStatistics(alma.acs.monitoring.DAO.ComponentStatistics) SummaryStatistics(org.apache.commons.math.stat.descriptive.SummaryStatistics) MonitorPointValue(alma.acs.monitoring.MonitorPointValue)

Aggregations

ComponentStatistics (alma.acs.monitoring.DAO.ComponentStatistics)1 MonitorPointValue (alma.acs.monitoring.MonitorPointValue)1 SummaryStatistics (org.apache.commons.math.stat.descriptive.SummaryStatistics)1