package com.fizz.business.dto;

import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.math.BigDecimal;

@Data
public class SegValue implements Serializable {
    private BigDecimal max;
    private BigDecimal min;
    private BigDecimal avg;
    private BigDecimal std;
    private int cnt;
    private BigDecimal sum = BigDecimal.ZERO;

    public void add(BigDecimal value) {
        if (value == null) {
            return;
        }
        this.sum = this.sum.add(value);
        this.cnt++;
    }

    public BigDecimal getAverage() {
        if (cnt == 0) {
            return BigDecimal.ZERO;
        }
        return sum.divide(new BigDecimal(cnt), 2, BigDecimal.ROUND_HALF_UP);
    }
}
