/** * Represents the input port for measurements. * * @param input * Incoming measurements */ @InputPort(eventTypes = { NamedDoubleTimeSeriesPoint.class }, name = ForecastingFilter.INPUT_PORT_NAME_TSPOINT) public void inputEvent(final NamedDoubleTimeSeriesPoint input) { if (this.checkInitialization(input.getName())) { this.processInput(input, input.getTime(), input.getName()); } else { // Initialization of the forecasting variables for a new application this.applicationForecastingWindow.put(input.getName(), new TimeSeries<Double>(input.getTime(), super.recordsTimeUnitFromProjectContext, this.deltat.get(), this.timeSeriesWindowCapacity.get())); this.processInput(input, input.getTime(), input.getName()); } }
/** * Represents the input port for measurements. * * @param input * Incoming measurements */ @InputPort(eventTypes = { NamedDoubleTimeSeriesPoint.class }, name = ForecastingFilter.INPUT_PORT_NAME_TSPOINT) public void inputEvent(final NamedDoubleTimeSeriesPoint input) { if (this.checkInitialization(input.getName())) { this.processInput(input, input.getTime(), input.getName()); } else { // Initialization of the forecasting variables for a new application this.applicationForecastingWindow.put(input.getName(), new TimeSeries<Double>(input.getTime(), super.recordsTimeUnitFromProjectContext, this.deltat.get(), this.timeSeriesWindowCapacity.get())); this.processInput(input, input.getTime(), input.getName()); } }
private void assertAppNames(final List<NamedDoubleTimeSeriesPoint> sinkList, final int firstIndex, final int secondIndex) throws AssertionError { // the order of the app names varies from execution to execution since the aggregation filter uses an unsorted map final String firstAppName = sinkList.get(firstIndex).getName(); final String secondAppName = sinkList.get(secondIndex).getName(); if (OP_SIGNATURE_D.equals(firstAppName)) { Assert.assertEquals(OP_SIGNATURE_C, secondAppName); } else if (OP_SIGNATURE_C.equals(firstAppName)) { Assert.assertEquals(OP_SIGNATURE_D, secondAppName); } else { throw new AssertionError("Unexpected app name: " + firstAppName); } } }
/** * This method represents the input port for the incoming measurements. * * @param input * The next incoming measurement */ @InputPort(eventTypes = { NamedDoubleTimeSeriesPoint.class }, name = TimeSeriesPointAggregatorFilter.INPUT_PORT_NAME_TSPOINT) public void inputTSPoint(final NamedDoubleTimeSeriesPoint input) { final String name = input.getName(); this.aggregationVariables.putIfAbsent(name, new AggregationVariableSet()); if (this.aggregationTimescopeGlobal) { this.processInputGlobalScope(input); } else { this.processInputVariableScope(input); } }
/** * This method represents the input port for the incoming measurements. * * @param input * The next incoming measurement */ @InputPort(eventTypes = { NamedDoubleTimeSeriesPoint.class }, name = TimeSeriesPointAggregatorFilter.INPUT_PORT_NAME_TSPOINT) public void inputTSPoint(final NamedDoubleTimeSeriesPoint input) { final String name = input.getName(); this.aggregationVariables.putIfAbsent(name, new AggregationVariableSet()); if (this.aggregationTimescopeGlobal) { this.processInputGlobalScope(input); } else { this.processInputVariableScope(input); } }
private void calculateAndDeliverAggregationValue(final AggregationVariableSet variables) { final double aggregationValue; final NamedDoubleTimeSeriesPoint tsPoint; synchronized (this) { final int listSize = variables.getAggregationList().size(); final double[] a = new double[listSize]; for (int i = 0; i < listSize; i++) { a[i] = variables.getAggregationList().get(i).getValue(); } aggregationValue = this.aggregationMethod.getAggregationValue(a); tsPoint = new NamedDoubleTimeSeriesPoint(variables.getLastTimestampInCurrentInterval(), aggregationValue, variables.getAggregationList().get(0).getName()); // use name of first element (any will do) variables.getAggregationList().clear(); } super.deliver(OUTPUT_PORT_NAME_AGGREGATED_TSPOINT, tsPoint); }
private void calculateAndDeliverAggregationValue(final AggregationVariableSet variables) { final double aggregationValue; final NamedDoubleTimeSeriesPoint tsPoint; synchronized (this) { final int listSize = variables.getAggregationList().size(); final double[] a = new double[listSize]; for (int i = 0; i < listSize; i++) { a[i] = variables.getAggregationList().get(i).getValue(); } aggregationValue = this.aggregationMethod.getAggregationValue(a); tsPoint = new NamedDoubleTimeSeriesPoint(variables.getLastTimestampInCurrentInterval(), aggregationValue, variables.getAggregationList().get(0).getName()); // use name of first element (any will do) variables.getAggregationList().clear(); } super.deliver(OUTPUT_PORT_NAME_AGGREGATED_TSPOINT, tsPoint); }
private synchronized void processInputGlobalScope(final NamedDoubleTimeSeriesPoint input) { // NOPMD (AvoidSynchronizedAtMethodLevel) final long inputTimestamp = input.getTime(); final AggregationVariableSet inputVariables = this.aggregationVariables.get(input.getName()); final long startOfInputTimestampsInterval = this.computeFirstTimestampInInterval(inputTimestamp, inputVariables); final long endOfInputTimestampsInterval = this.computeLastTimestampInInterval(inputTimestamp, inputVariables);
private synchronized void processInputGlobalScope(final NamedDoubleTimeSeriesPoint input) { // NOPMD (AvoidSynchronizedAtMethodLevel) final long inputTimestamp = input.getTime(); final AggregationVariableSet inputVariables = this.aggregationVariables.get(input.getName()); final long startOfInputTimestampsInterval = this.computeFirstTimestampInInterval(inputTimestamp, inputVariables); final long endOfInputTimestampsInterval = this.computeLastTimestampInInterval(inputTimestamp, inputVariables);
private synchronized void processInputVariableScope(final NamedDoubleTimeSeriesPoint input) { // NOPMD (AvoidSynchronizedAtMethodLevel) final long currentTime = input.getTime(); final String appname = input.getName(); final AggregationVariableSet variables = this.aggregationVariables.get(appname); final long startOfTimestampsInterval = this.computeFirstTimestampInInterval(currentTime, variables); final long endOfTimestampsInterval = this.computeLastTimestampInInterval(currentTime, variables); if (this.recentWindow.getWindowEnd() != endOfTimestampsInterval) { this.recentWindow = new AggregationWindow(startOfTimestampsInterval, endOfTimestampsInterval); super.deliver(OUTPUT_PORT_NAME_AGGREGATION_WINDOW, this.recentWindow); } // check if interval is omitted if (endOfTimestampsInterval > variables.getLastTimestampInCurrentInterval()) { if (variables.getFirstTimestampInCurrentInterval() >= 0) { // don't do this for the first record (only used for initialization of variables) this.calculateAndDeliverAggregationValue(variables); long numIntervalsElapsed = 1; // refined below numIntervalsElapsed = (endOfTimestampsInterval - variables.getLastTimestampInCurrentInterval()) / this.aggregationSpan; if (numIntervalsElapsed > 1) { for (int i = 1; i < numIntervalsElapsed; i++) { super.deliver(OUTPUT_PORT_NAME_AGGREGATED_TSPOINT, new NamedDoubleTimeSeriesPoint(variables.getLastTimestampInCurrentInterval() + (i * this.aggregationSpan), Double.NaN, // Note: Count filter should use 0.0 appname)); } } } variables.setFirstTimestampInCurrentInterval(startOfTimestampsInterval); variables.setLastTimestampInCurrentInterval(endOfTimestampsInterval); variables.getAggregationList().clear(); } variables.getAggregationList().add(input); }
private synchronized void processInputVariableScope(final NamedDoubleTimeSeriesPoint input) { // NOPMD (AvoidSynchronizedAtMethodLevel) final long currentTime = input.getTime(); final String appname = input.getName(); final AggregationVariableSet variables = this.aggregationVariables.get(appname); final long startOfTimestampsInterval = this.computeFirstTimestampInInterval(currentTime, variables); final long endOfTimestampsInterval = this.computeLastTimestampInInterval(currentTime, variables); if (this.recentWindow.getWindowEnd() != endOfTimestampsInterval) { this.recentWindow = new AggregationWindow(startOfTimestampsInterval, endOfTimestampsInterval); super.deliver(OUTPUT_PORT_NAME_AGGREGATION_WINDOW, this.recentWindow); } // check if interval is omitted if (endOfTimestampsInterval > variables.getLastTimestampInCurrentInterval()) { if (variables.getFirstTimestampInCurrentInterval() >= 0) { // don't do this for the first record (only used for initialization of variables) this.calculateAndDeliverAggregationValue(variables); long numIntervalsElapsed = 1; // refined below numIntervalsElapsed = (endOfTimestampsInterval - variables.getLastTimestampInCurrentInterval()) / this.aggregationSpan; if (numIntervalsElapsed > 1) { for (int i = 1; i < numIntervalsElapsed; i++) { super.deliver(OUTPUT_PORT_NAME_AGGREGATED_TSPOINT, new NamedDoubleTimeSeriesPoint(variables.getLastTimestampInCurrentInterval() + (i * this.aggregationSpan), Double.NaN, // Note: Count filter should use 0.0 appname)); } } } variables.setFirstTimestampInCurrentInterval(startOfTimestampsInterval); variables.setLastTimestampInCurrentInterval(endOfTimestampsInterval); variables.getAggregationList().clear(); } variables.getAggregationList().add(input); }
Assert.assertEquals(OP_SIGNATURE_A, sinkList.get(0).getName()); Assert.assertEquals(1500.0, sinkList.get(0).getDoubleValue(), EPSILON); Assert.assertEquals(OP_SIGNATURE_B, sinkList.get(3).getName()); Assert.assertEquals(3000.0, sinkList.get(3).getDoubleValue(), EPSILON); Assert.assertEquals(OP_SIGNATURE_A, sinkList.get(4).getName()); Assert.assertEquals(4000.0, sinkList.get(4).getDoubleValue(), EPSILON); Assert.assertEquals(OP_SIGNATURE_B, sinkList.get(7).getName()); Assert.assertEquals(Double.NaN, sinkList.get(7).getDoubleValue(), EPSILON); Assert.assertEquals(OP_SIGNATURE_A, sinkList.get(8).getName()); Assert.assertEquals(Double.NaN, sinkList.get(8).getDoubleValue(), EPSILON); Assert.assertEquals(OP_SIGNATURE_B, sinkList.get(11).getName()); Assert.assertEquals(6000.0, sinkList.get(11).getDoubleValue(), EPSILON); Assert.assertEquals(OP_SIGNATURE_A, sinkList.get(12).getName()); Assert.assertEquals(Double.NaN, sinkList.get(12).getDoubleValue(), EPSILON); Assert.assertEquals(OP_SIGNATURE_B, sinkList.get(15).getName()); Assert.assertEquals(Double.NaN, sinkList.get(15).getDoubleValue(), EPSILON);