Search in sources :

Example 1 with MonitorPointValue

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

the class Clobber method generateClob.

/**
	 * @param mpTs
	 * @return The CLOB, or null if the monitor point is of a floating number type and contains NaN
	 */
public String generateClob(MonitorPointTimeSeries mpTs) {
    List<MonitorPointValue> timeSeriesData = mpTs.getDataList();
    StringBuilder clobBld = new StringBuilder();
    for (int i = 0; i < timeSeriesData.size(); i++) {
        MonitorPointValue mpVal = timeSeriesData.get(i);
        List<Object> mpValData = mpVal.getData();
        if (!mpValData.isEmpty()) {
            // print the time
            if (i > 0) {
                clobBld.append('|');
            }
            clobBld.append(mpVal.getTime()).append('|');
            // We check only the first object;
            // other objects in mpValData are expected to be of the same type and same NaN status
            Object sampleObj = mpValData.get(0);
            // This if-else structure will allow us to use type-specific DecimalFormat etc masks
            if (sampleObj instanceof Integer) {
                appendValueString(mpValData, clobBld);
            } else if (sampleObj instanceof Long) {
                appendValueString(mpValData, clobBld);
            } else if (sampleObj instanceof Float) {
                // Skip NaN values (COMP-5564)
                if (((Float) sampleObj).isNaN()) {
                    return null;
                }
                appendValueString(mpValData, clobBld);
            } else if (sampleObj instanceof Double) {
                // Skip NaN values (COMP-5564)
                if (((Double) sampleObj).isNaN()) {
                    return null;
                }
                appendValueString(mpValData, clobBld);
            } else if (sampleObj instanceof Boolean) {
                // according to http://jira.alma.cl/browse/COMP-8496, we want to store
                // "1" for true and "0" for false. Thus cannot use Boolean.toString().
                List<Object> boolStrings = new ArrayList<Object>(mpValData.size());
                for (int j = 0; j < mpValData.size(); j++) {
                    boolStrings.add((((Boolean) mpValData.get(j)).booleanValue() ? "1" : "0"));
                }
                appendValueString(boolStrings, clobBld);
            } else if (sampleObj instanceof String) {
                appendValueString(mpValData, clobBld);
            } else {
                logger.info("Unexpected data type " + sampleObj.getClass().getName() + " found, coming from Corba type " + mpTs.getCorbaTypeId());
                clobBld.append("?");
            }
        }
    }
    // TODO: Must we keep this trailing newline char from the legacy implementation?
    clobBld.append('\n');
    return clobBld.toString();
}
Also used : ArrayList(java.util.ArrayList) MonitorPointValue(alma.acs.monitoring.MonitorPointValue)

Example 2 with MonitorPointValue

use of alma.acs.monitoring.MonitorPointValue 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)

Example 3 with MonitorPointValue

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

the class CorbaAnyExtractionTest method testExtractData_longLongBlobDataSeq.

/**
	 * Test of extractData method for 'longLongBlobDataSeq' data.
	 */
@Test
public void testExtractData_longLongBlobDataSeq() throws Exception {
    String propertyName = "VOLTAGE_MID_1";
    Any any = create_any();
    // We try out a rather large outlyer value. Note that for even larger numbers
    // such as 0x7f0fffffffffffffL, the double-based statistics yield a max value wrong by +-1,
    // which is probably acceptable, but we avoid it here in the test and use
    // only a number of the order of a quadrillion.
    long[] longLongDataArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0x000fffffffffffffL };
    longLongBlobData[] longLongBlobDataArray = createLongLongBlobData(longLongDataArray);
    longLongBlobDataSeqHelper.insert(any, longLongBlobDataArray);
    List<MonitorPointTimeSeries> extractedData = anyExtractor.extractData(any, propertyName);
    assertThat(extractedData, hasSize(1));
    // Check the raw data
    MonitorPointTimeSeries mpTs = extractedData.get(0);
    assertThat(mpTs.getCorbaTypeId(), equalTo("IDL:alma/TMCDB/longLongBlobDataSeq:1.0"));
    assertThat(mpTs.getMonitorPointIndex(), equalTo(0));
    List<MonitorPointValue> dataList = mpTs.getDataList();
    assertThat(dataList, hasSize(longLongBlobDataArray.length));
    for (int i = 0; i < longLongBlobDataArray.length; i++) {
        MonitorPointValue mpVal = dataList.get(i);
        assertThat(mpVal.getTime(), equalTo(BASE_TIME + i));
        assertThat(mpVal.getData(), contains((Object) new Long(longLongDataArray[i])));
    }
    logger.info("Validated longLongBlobDataSeq.");
    // As a variation we test also "BlobberWorker.createBlobData" which in real life surrounds the AnyExtractor call 
    String componentName = "CONTROL/DV01/PSA";
    String serialNumber = "3456328928847";
    MonitorBlob blob = new MonitorBlob(false, (short) 0, new String[] {}, "wrong:" + propertyName, any);
    MonitorBlob[] blobs = new MonitorBlob[] { blob };
    long startTime = BASE_TIME + 100;
    long stopTime = BASE_TIME + 101;
    MonitorDataBlock block = new MonitorDataBlock(startTime, stopTime, componentName, serialNumber, blobs);
    BlobData blobData = BlobberWorker.createBlobData(block, blob, extractedData.get(0), propertyName, serialNumber, logger);
    String clobExpected = BASE_TIME + "|1|" + (BASE_TIME + 1) + "|2|" + (BASE_TIME + 2) + "|3|" + (BASE_TIME + 3) + "|4|" + (BASE_TIME + 4) + "|5|" + (BASE_TIME + 5) + "|6|" + (BASE_TIME + 6) + "|7|" + (BASE_TIME + 7) + "|8|" + (BASE_TIME + 8) + "|9|" + (BASE_TIME + 9) + "|4503599627370495\n";
    String statisticsExpected = "min: 1 max: 4503599627370495 mean: 4.50359962737054E14 stdDev: 1.4241632491976338E15\n";
    checkComponentData(blobData, clobExpected, 10, componentName, propertyName, serialNumber, startTime, stopTime, 0, statisticsExpected);
}
Also used : MonitorPointValue(alma.acs.monitoring.MonitorPointValue) Any(org.omg.CORBA.Any) MonitorBlob(alma.TMCDB.MonitorBlob) TMCDB.longLongBlobData(alma.TMCDB.longLongBlobData) TMCDB.floatBlobData(alma.TMCDB.floatBlobData) TMCDB.booleanSeqBlobData(alma.TMCDB.booleanSeqBlobData) TMCDB.longLongBlobData(alma.TMCDB.longLongBlobData) TMCDB.doubleBlobData(alma.TMCDB.doubleBlobData) TMCDB.doubleSeqBlobData(alma.TMCDB.doubleSeqBlobData) TMCDB.floatSeqBlobData(alma.TMCDB.floatSeqBlobData) MonitorPointTimeSeries(alma.acs.monitoring.MonitorPointTimeSeries) MonitorDataBlock(alma.TMCDB.MonitorDataBlock) Test(org.junit.Test)

Example 4 with MonitorPointValue

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

the class CorbaAnyExtractionTest method testExtractData_booleanSeqBlobDataSeq_singlevalued.

/**
	 * Test of extractData method for 'booleanSeqBlobDataSeq' data for a sequence property 
	 * that expands into multiple single-valued MPs.
	 */
@Test
public void testExtractData_booleanSeqBlobDataSeq_singlevalued() throws Exception {
    String propertyName = "SYSTEM_STATUS";
    Any any = create_any();
    boolean[] booleanData_time1 = { false, true, false };
    boolean[] booleanData_time2 = { true, true, true };
    boolean[][] booleanDataMatrix = { booleanData_time1, booleanData_time2 };
    booleanSeqBlobData[] booleanSeqBlobDataArray = createBooleanSeqBlobData(booleanDataMatrix);
    booleanSeqBlobDataSeqHelper.insert(any, booleanSeqBlobDataArray);
    monitorPointExpert.setMultivalued(propertyName, false);
    // Test the AnyExtractor stand-alone
    List<MonitorPointTimeSeries> extractedData = anyExtractor.extractData(any, propertyName);
    assertThat("Demultiplexing into several MonitorPointTimeSeries instances expected", extractedData, hasSize(booleanData_time1.length));
    for (int index = 0; index < extractedData.size(); index++) {
        // check one of the expanded logical properties at a time
        MonitorPointTimeSeries mpTs = extractedData.get(index);
        assertThat(mpTs.getCorbaTypeId(), equalTo("IDL:alma/TMCDB/booleanBlobDataSeq:1.0"));
        assertThat(mpTs.getMonitorPointIndex(), equalTo(index));
        List<MonitorPointValue> dataList = mpTs.getDataList();
        assertThat(dataList, hasSize(booleanDataMatrix.length));
        for (int i = 0; i < booleanDataMatrix.length; i++) {
            MonitorPointValue mpVal = dataList.get(i);
            assertThat(mpVal.getTime(), equalTo(BASE_TIME + i));
            // This should be the transpose of matrix booleanDataMatrix
            assertThat(mpVal.getData(), contains((Object) new Boolean(booleanDataMatrix[i][index])));
        }
    }
    logger.info("Validated booleanSeqBlobDataSeq interpreted as coming from a multiple single-valued MPs.");
    // As a variation we test also "BlobberWorker.createBlobData" which in real life surrounds the AnyExtractor call.
    // It includes generation of CLOB data.
    String componentName = "CONTROL/DV01/PSA";
    String serialNumber = "3456328928847";
    MonitorBlob blob = new MonitorBlob(false, (short) 0, new String[] {}, "wrong:" + propertyName, any);
    MonitorBlob[] blobs = new MonitorBlob[] { blob };
    long startTime = BASE_TIME + 100;
    long stopTime = BASE_TIME + 101;
    MonitorDataBlock block = new MonitorDataBlock(startTime, stopTime, componentName, serialNumber, blobs);
    String[] clobsExpected = new String[] { BASE_TIME + "|0|" + (BASE_TIME + 1) + "|1\n", BASE_TIME + "|1|" + (BASE_TIME + 1) + "|1\n", BASE_TIME + "|0|" + (BASE_TIME + 1) + "|1\n" };
    String[] statisticsExpected = { null, null, null };
    for (int i = 0; i < extractedData.size(); i++) {
        BlobData blobData = BlobberWorker.createBlobData(block, blob, extractedData.get(i), propertyName, serialNumber, logger);
        checkComponentData(blobData, clobsExpected[i], 2, componentName, propertyName, serialNumber, startTime, stopTime, i, statisticsExpected[i]);
    }
}
Also used : TMCDB.booleanSeqBlobData(alma.TMCDB.booleanSeqBlobData) MonitorPointValue(alma.acs.monitoring.MonitorPointValue) Any(org.omg.CORBA.Any) MonitorBlob(alma.TMCDB.MonitorBlob) TMCDB.floatBlobData(alma.TMCDB.floatBlobData) TMCDB.booleanSeqBlobData(alma.TMCDB.booleanSeqBlobData) TMCDB.longLongBlobData(alma.TMCDB.longLongBlobData) TMCDB.doubleBlobData(alma.TMCDB.doubleBlobData) TMCDB.doubleSeqBlobData(alma.TMCDB.doubleSeqBlobData) TMCDB.floatSeqBlobData(alma.TMCDB.floatSeqBlobData) MonitorPointTimeSeries(alma.acs.monitoring.MonitorPointTimeSeries) MonitorDataBlock(alma.TMCDB.MonitorDataBlock) Test(org.junit.Test)

Example 5 with MonitorPointValue

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

the class CorbaAnyExtractionTest method testExtractData_doubleSeqBlobDataSeq_singlevalued.

/**
	 * Test of extractData method for 'doubleSeqBlobDataSeq' data for a sequence property 
	 * that expands into multiple single-valued MPs.
	 */
@Test
public void testExtractData_doubleSeqBlobDataSeq_singlevalued() throws Exception {
    String propertyName = "SYSTEM_STATUS";
    Any any = create_any();
    double[] doubleData_time1 = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
    double[] doubleData_time2 = { 11.1, 12.2, 13.3, 14.4, 15.5, 16.6, 17.7, 18.8, 19.9, 20.0 };
    double[] doubleData_time3 = { 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0 };
    double[][] doubleDataMatrix = { doubleData_time1, doubleData_time2, doubleData_time3 };
    doubleSeqBlobData[] doubleSeqBlobDataArray = createDoubleSeqBlobData(doubleDataMatrix);
    doubleSeqBlobDataSeqHelper.insert(any, doubleSeqBlobDataArray);
    monitorPointExpert.setMultivalued(propertyName, false);
    // Test the AnyExtractor stand-alone
    List<MonitorPointTimeSeries> extractedData = anyExtractor.extractData(any, propertyName);
    assertThat("Demultiplexing into several MonitorPointTimeSeries instances expected", extractedData, hasSize(doubleData_time1.length));
    for (int index = 0; index < extractedData.size(); index++) {
        // check one of the expanded logical properties at a time
        MonitorPointTimeSeries mpTs = extractedData.get(index);
        assertThat(mpTs.getCorbaTypeId(), equalTo("IDL:alma/TMCDB/doubleBlobDataSeq:1.0"));
        assertThat(mpTs.getMonitorPointIndex(), equalTo(index));
        List<MonitorPointValue> dataList = mpTs.getDataList();
        assertThat(dataList, hasSize(doubleDataMatrix.length));
        for (int i = 0; i < doubleDataMatrix.length; i++) {
            MonitorPointValue mpVal = dataList.get(i);
            assertThat(mpVal.getTime(), equalTo(BASE_TIME + i));
            // This should be the transpose of matrix doubleDataMatrix
            assertThat(mpVal.getData(), contains((Object) new Double(doubleDataMatrix[i][index])));
        }
    }
    logger.info("Validated doubleSeqBlobDataSeq interpreted as coming from a multiple single-valued MPs.");
    // As a variation we test also "BlobberWorker.createBlobData" which in real life surrounds the AnyExtractor call.
    // It includes generation of statistics and CLOB data.
    String componentName = "CONTROL/DV01/PSA";
    String serialNumber = "3456328928847";
    MonitorBlob blob = new MonitorBlob(false, (short) 0, new String[] {}, "wrong:" + propertyName, any);
    MonitorBlob[] blobs = new MonitorBlob[] { blob };
    long startTime = BASE_TIME + 100;
    long stopTime = BASE_TIME + 101;
    MonitorDataBlock block = new MonitorDataBlock(startTime, stopTime, componentName, serialNumber, blobs);
    String[] clobsExpected = new String[] { BASE_TIME + "|1.0|" + (BASE_TIME + 1) + "|11.1|" + (BASE_TIME + 2) + "|21.0\n", BASE_TIME + "|2.0|" + (BASE_TIME + 1) + "|12.2|" + (BASE_TIME + 2) + "|22.0\n", BASE_TIME + "|3.0|" + (BASE_TIME + 1) + "|13.3|" + (BASE_TIME + 2) + "|23.0\n", BASE_TIME + "|4.0|" + (BASE_TIME + 1) + "|14.4|" + (BASE_TIME + 2) + "|24.0\n", BASE_TIME + "|5.0|" + (BASE_TIME + 1) + "|15.5|" + (BASE_TIME + 2) + "|25.0\n", BASE_TIME + "|6.0|" + (BASE_TIME + 1) + "|16.6|" + (BASE_TIME + 2) + "|26.0\n", BASE_TIME + "|7.0|" + (BASE_TIME + 1) + "|17.7|" + (BASE_TIME + 2) + "|27.0\n", BASE_TIME + "|8.0|" + (BASE_TIME + 1) + "|18.8|" + (BASE_TIME + 2) + "|28.0\n", BASE_TIME + "|9.0|" + (BASE_TIME + 1) + "|19.9|" + (BASE_TIME + 2) + "|29.0\n", BASE_TIME + "|10.0|" + (BASE_TIME + 1) + "|20.0|" + (BASE_TIME + 2) + "|30.0\n" };
    String[] statisticsExpected = { "min: 1.0 max: 21.0 mean: 11.033333333333333 stdDev: 10.000166665277801\n", "min: 2.0 max: 22.0 mean: 12.066666666666666 stdDev: 10.000666644445925\n", "min: 3.0 max: 23.0 mean: 13.100000000000001 stdDev: 10.001499887516873\n", "min: 4.0 max: 24.0 mean: 14.133333333333333 stdDev: 10.002666311205894\n", "min: 5.0 max: 25.0 mean: 15.166666666666668 stdDev: 10.004165798972613\n", "min: 6.0 max: 26.0 mean: 16.2 stdDev: 10.00599820107919\n", "min: 7.0 max: 27.0 mean: 17.233333333333334 stdDev: 10.008163334665024\n", "min: 8.0 max: 28.0 mean: 18.266666666666666 stdDev: 10.010660983837848\n", "min: 9.0 max: 29.0 mean: 19.3 stdDev: 10.013490899781155\n", "min: 10.0 max: 30.0 mean: 20.0 stdDev: 10.0\n" };
    for (int i = 0; i < extractedData.size(); i++) {
        BlobData blobData = BlobberWorker.createBlobData(block, blob, extractedData.get(i), propertyName, serialNumber, logger);
        checkComponentData(blobData, clobsExpected[i], 3, componentName, propertyName, serialNumber, startTime, stopTime, i, statisticsExpected[i]);
    }
}
Also used : MonitorPointValue(alma.acs.monitoring.MonitorPointValue) Any(org.omg.CORBA.Any) TMCDB.doubleSeqBlobData(alma.TMCDB.doubleSeqBlobData) MonitorBlob(alma.TMCDB.MonitorBlob) TMCDB.floatBlobData(alma.TMCDB.floatBlobData) TMCDB.booleanSeqBlobData(alma.TMCDB.booleanSeqBlobData) TMCDB.longLongBlobData(alma.TMCDB.longLongBlobData) TMCDB.doubleBlobData(alma.TMCDB.doubleBlobData) TMCDB.doubleSeqBlobData(alma.TMCDB.doubleSeqBlobData) TMCDB.floatSeqBlobData(alma.TMCDB.floatSeqBlobData) MonitorPointTimeSeries(alma.acs.monitoring.MonitorPointTimeSeries) MonitorDataBlock(alma.TMCDB.MonitorDataBlock) Test(org.junit.Test)

Aggregations

MonitorPointValue (alma.acs.monitoring.MonitorPointValue)10 MonitorPointTimeSeries (alma.acs.monitoring.MonitorPointTimeSeries)8 TMCDB.doubleBlobData (alma.TMCDB.doubleBlobData)7 TMCDB.floatBlobData (alma.TMCDB.floatBlobData)7 Test (org.junit.Test)7 Any (org.omg.CORBA.Any)7 TMCDB.booleanSeqBlobData (alma.TMCDB.booleanSeqBlobData)6 TMCDB.doubleSeqBlobData (alma.TMCDB.doubleSeqBlobData)6 TMCDB.floatSeqBlobData (alma.TMCDB.floatSeqBlobData)6 TMCDB.longLongBlobData (alma.TMCDB.longLongBlobData)6 MonitorBlob (alma.TMCDB.MonitorBlob)5 MonitorDataBlock (alma.TMCDB.MonitorDataBlock)5 ArrayList (java.util.ArrayList)2 TMCDB.booleanBlobData (alma.TMCDB.booleanBlobData)1 TMCDB.enumBlobData (alma.TMCDB.enumBlobData)1 TMCDB.longBlobData (alma.TMCDB.longBlobData)1 TMCDB.longLongSeqBlobData (alma.TMCDB.longLongSeqBlobData)1 TMCDB.longSeqBlobData (alma.TMCDB.longSeqBlobData)1 TMCDB.patternBlobData (alma.TMCDB.patternBlobData)1 TMCDB.stringBlobData (alma.TMCDB.stringBlobData)1