#include "statistical_class.hh"
#include <sstream>

StatisticalClass::StatisticalClass(
    double min, double max, int count, const std::string& name) :
    min_(min), max_(max), count_(count), name_(name)
{}

std::string StatisticalClass::name() const
{
    return name_;
}

double StatisticalClass::min() const
{
    return min_;
}

double StatisticalClass::max() const
{
    return max_;
}

int StatisticalClass::count() const
{
    return count_;
}

double StatisticalClass::center() const
{
    return (max_ + min_) / 2.0;
}

bool StatisticalClass::isMember(double value) const
{
    return value > min_ && value <= max_;
}

double StatisticalClass::interpolate(
    double value, double minY, double maxY) const
{
    return minY + (value - min_) * ((maxY - minY) / (max_ - min_));
}

std::string StatisticalClass::toString() const
{
    std::ostringstream stream;
    stream << name_ << ": " << min_ << " to " << max_;
    stream << " (" << count_ << ")";
    return stream.str();
}

void StatisticalClass::operator++(int)
{
    count_++;
}

void StatisticalClass::operator--(int)
{
    count_--;
}

void StatisticalClass::operator+=(int count)
{
    count_ += count;
}

void StatisticalClass::operator-=(int count)
{
    count_ -= count;
}
