#include "average.hpp"

#include <cassert>

std::optional<Average::averageValue>
    Average::getAverageValue(const Average::averageKey& sensorKey) const
{
    const auto it = _previousAverageMap.find(sensorKey);
    if (it == _previousAverageMap.end())
    {
        return {};
    }

    return std::optional(it->second);
}

void Average::setAverageValue(const Average::averageKey& sensorKey,
                              const Average::averageValue& sensorValue)
{
    _previousAverageMap[sensorKey] = sensorValue;
}

std::optional<int64_t> Average::calcAverage(int64_t preAverage,
                                            int64_t preInterval,
                                            int64_t curAverage,
                                            int64_t curInterval)
{
    int64_t value = 0;
    // Estimate that the interval will overflow about 292471
    // years after it starts counting, so consider it won't
    // overflow
    int64_t delta = curInterval - preInterval;

    assert(delta >= 0);
    // 0 means the delta interval is too short, the value of
    // power*_average_interval is not changed yet
    if (delta == 0)
    {
        return {};
    }
    // Change formula (a2*i2-a1*i1)/(i2-i1) to be the
    // following formula, to avoid multiplication overflow.
    // (a2*i2-a1*i1)/(i2-i1) =
    // (a2*(i1+delta)-a1*i1)/delta =
    // (a2-a1)(i1/delta)+a2
    value = (curAverage - preAverage) *
                (static_cast<double>(preInterval) / delta) +
            curAverage;

    return value;
}
