public MultiHistogramDataModel buildHistogramDataModel(List<Integer> costs,
Function<Integer, Double> scalingFunction) {
int binCount = min(MAX_HISTOGRAM_BINS, 10 * (int) log(costs.size()) + 1);
int binWidth = (int) ceil((double) findMax(costs) / binCount);
Histogram overallHistogram = new Histogram(0, binWidth, binCount, scalingFunction);
Histogram excellentHistogram = new Histogram(0, binWidth, binCount, scalingFunction);
Histogram goodHistogram = new Histogram(0, binWidth, binCount, scalingFunction);
Histogram needsWorkHistogram = new Histogram(0, binWidth, binCount, scalingFunction);
for (int overallCost : costs) {
if (overallCost <= maxExcellentCost) {
excellentHistogram.value(overallCost);
} else if (overallCost <= maxAcceptableCost) {
goodHistogram.value(overallCost);
} else {
needsWorkHistogram.value(overallCost);
}
overallHistogram.value(overallCost);
}
int maxBin = overallHistogram.getMaxBin();
excellentHistogram.setMaxBin(maxBin);
goodHistogram.setMaxBin(maxBin);
needsWorkHistogram.setMaxBin(maxBin);
return new MultiHistogramDataModel(excellentHistogram, goodHistogram, needsWorkHistogram,
overallHistogram, binCount, binWidth);
}