com.datastax.data.exploration.biz.stat.bar.BarStat Maven / Gradle / Ivy
package com.datastax.data.exploration.biz.stat.bar;
import com.datastax.data.exploration.biz.datatable.column.DataColumn;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public abstract class BarStat {
C column;
private Stat stat;//统计内容
private String most;//最多
private String least;//最少
private long mostCount;
private long leastCount;
BarStat(C column) {
this.column = column;
int count = this.column.getNotNullValues().size();
stat = new Stat();
agg().forEach((k, v) -> {
if (most == null) {
most = k;
least = k;
mostCount = v;
leastCount = v;
} else if (v > mostCount) {
most = k;
mostCount = v;
} else if (v < leastCount) {
least = k;
leastCount = v;
}
stat.xAxis.add(k);
stat.yAxis.add(v);
stat.percent.add(percent(v, count));
});
}
abstract Map agg();
public Stat getStat() {
return this.stat;
}
public String getMost() {
return most;
}
public String getLeast() {
return least;
}
public long getMostCount() {
return mostCount;
}
public long getLeastCount() {
return leastCount;
}
private class Stat {
List percent = new ArrayList<>();
List xAxis = new ArrayList<>();
List yAxis = new ArrayList<>();
public List getPercent() {
return percent;
}
public List getXAxis() {
return xAxis;
}
public List getYAxis() {
return yAxis;
}
}
private BigDecimal percent(Long current, int count) {
return BigDecimal.valueOf(current).divide(BigDecimal.valueOf(count), 4, RoundingMode.UP);
}
}