package com.gyee.generation.util.math;

import org.springframework.stereotype.Service;

@Service
public class ShortTermPowerPredictionAccuracyCalculator {


    public double calculateAccuracy(double[] predictedPower, double[] actualPower, double installedCapacity) {
        int n = predictedPower.length;
        double totalError = 0.0;
        int validPoints = 0;

        for (int i = 0; i < n; i++) {
            double errorPercentage = 0.0;

            if (Math.abs(predictedPower[i] - actualPower[i]) <= 0.03 * installedCapacity) {
                // 该点不计入误差计算
                continue;
            }

            errorPercentage = Math.abs(predictedPower[i] - actualPower[i]) / installedCapacity * 100;

            totalError += errorPercentage;
            validPoints++;
        }

        if (validPoints == 0) {
            return 100.0; // 所有点均在3%以内，准确率为100%
        } else {
            double accuracy = 100 - totalError / validPoints;
            return accuracy;
        }
    }
}

