package com.gyee.generation.util.math;

import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PowerCalculator {
    /**
     * 用功率计算电量
     *
     * @param powerDataList 实际功率
     * @param hours         总的小时数
     * @param maxPower      最大功率
     * @return 电量
     */
    public double updateTheoryGeneration(List<Double> powerDataList, double hours, double maxPower) {
        double result = 0;
        double T = hours;
        int f = powerDataList.size();

        if (f != 0) {
            for (int i = 0; i < f; i++) {
                double P = powerDataList.get(i);
                if (P >= 0 && P <= maxPower) {
                    result += (T / f) * P;
                }
            }
        }
        return result;
    }
}
