hawkular / hawkular-datamining

Real-time time series prediction library with standalone server
36 stars 22 forks source link

There are issues with the calculation of CollectionInterval and timestamp #90

Open Gezi-lzq opened 9 months ago

Gezi-lzq commented 9 months ago
    /**
     * @param collectionInterval collection interval in seconds
     */
    void setCollectionInterval(Long collectionInterval);

As declared by this interface, the interval of Metric should be in seconds. However, in subsequent use, the modification of timestamp values based on collectionInterval was not consistent.

@Override
    public List<DataPoint> forecast(int nAhead) {

        List<DataPoint> result = new ArrayList<>(nAhead);

        for (int i = 1; i <= nAhead; i++) {
            PredictionResult predictionResult = calculatePrediction(i, null, null);
            DataPoint predictedPoint = new DataPoint(predictionResult.value,
                    lastTimestamp + i*metricContext.getCollectionInterval()*1000,
                    predictionResult.value + predictionIntervalMultiplier*predictionResult.sdOfResiduals,
                    predictionResult.value - predictionIntervalMultiplier*predictionResult.sdOfResiduals);

            result.add(predictedPoint);
        }

        return result;
    }

In this interface implementation, lastTimestamp+i * metricContext. getCollectionInterval() * 1000 is used to calculate the timestamp of the prediction point, indicating that Timestamp is measured in milliseconds.

However, in the subsequent calculation of the timestamp, the CollectionInterval was directly added without converting it to a timestamp in milliseconds.

@Override
    public DataPoint forecast() {
        PredictionResult predictionResult = calculatePrediction(1, null, null);

        return new DataPoint(predictionResult.value, lastTimestamp + metricContext.getCollectionInterval(),
                predictionResult.value + predictionIntervalMultiplier*predictionResult.sdOfResiduals,
                predictionResult.value - predictionIntervalMultiplier*predictionResult.sdOfResiduals);
    }

I am puzzled by the above phenomenon and hope to help answer it. If there is indeed an inconsistency issue, I am willing to assist with the modification.

Gezi-lzq commented 9 months ago

@pavolloffay @jkremser