private void printSample(PrintStream ps, Sample sample) {
ps.print("Scenario '" + getScenarioName() + "' "); //$NON-NLS-1$ //$NON-NLS-2$
DataPoint[] dataPoints= sample.getDataPoints();
if (dataPoints.length > 0) {
StatisticsSession s= new StatisticsSession(dataPoints);
Dim[] dimensions= dataPoints[0].getDimensions();
Arrays.sort(dimensions, new DimensionComparator());
if (dimensions.length > 0) {
List badDimensions= new ArrayList();
long n= s.getCount(dimensions[0]);
MessageFormat format= new MessageFormat("({0,number,percent} in [{1}, {2}])"); //$NON-NLS-1$
String spaces= " "; //$NON-NLS-1$
ps.println("(average over " + n + " samples):"); //$NON-NLS-1$ //$NON-NLS-2$
for (int i= 0; i < dimensions.length; i++) {
Dim dimension= dimensions[i];
double mean= s.getAverage(dimension);
String nameString= " " + dimension.getName() + ":"; //$NON-NLS-1$ //$NON-NLS-2$
String meanString= dimension.getDisplayValue(mean);
int align= firstNonDigit(meanString);
meanString= spaces.substring(0, 30 - align - nameString.length()) + meanString;
align= nameString.length() + meanString.length();
Percentile percentile= StatisticsUtil.T95;
double[] confidenceInterval= s.getConfidenceInterval(dimension, percentile);
String confidenceString= n <= 2
? " (no confidence)" //$NON-NLS-1$
: spaces.substring(0, 40 - align) + format.format(new Object[] {new Double(percentile.inside()), dimension.getDisplayValue(confidenceInterval[0]), dimension.getDisplayValue(confidenceInterval[1])});