Locale locale = Locale.getDefault ( ) ;
NumberFormat format = NumberFormat.getNumberInstance( locale ) ;
//new DecimalFormat("##########.##");
ToolExperience toolExp = null;
List<String> allProperties = new ArrayList<String>();
Map<String, DetailedExperimentInfo> accumulatedAvg = new HashMap<String,DetailedExperimentInfo>();
for (MassMigrationExperiment e : setup.getExperiments()) {
/* calculate average per experiment */
/* put measurements of sample files to toolExp */
toolExp = MeasurementStatistics.generateToolExperience(e.getResult());
/* get calculated average per property */
DetailedExperimentInfo average = MeasurementStatistics.getAverage(toolExp);
accumulatedAvg.put(e.getAction().getShortname(), average);
e.getAverages().clear();
e.getAverages().put(average);
/* a list of all properties to iterate over the values */
allProperties.clear();
allProperties.addAll(toolExp.getMeasurements().keySet());
Collections.sort(allProperties);
/*
* write all measurements of this experiment to a file
*/
String statistics = FileUtils.makeFilename(makeUniqueActionName(e.getAction()));
File statisticsFile = new File(currentResultdir, statistics+".csv");
try {
BufferedWriter out = new BufferedWriter(new FileWriter(statisticsFile));
StringBuffer header = new StringBuffer();
header.append("sample");
for (String key : allProperties) {
header.append(CSV_SEPARATOR).append(key);
}
/* write header */
out.append(header);
out.newLine();
List<String> keySet = new ArrayList<String>(e.getResult().keySet());
String[] toSort = keySet.toArray(new String[]{});
java.util.Arrays.sort(toSort,String.CASE_INSENSITIVE_ORDER);
/* write measured values for all samples */
for (int i = 0; i<toSort.length; i++){
String sample = toSort[i];
/* 1. column: sample name */
out.append(sample);
/* followed by all properties */
DetailedExperimentInfo info = e.getResult().get(sample);
for(String prop: allProperties){
out.append(CSV_SEPARATOR);
Measurement m = info.getMeasurements().get(prop);
if (m != null) {
if (m.getValue() instanceof INumericValue) {
/* */
double value = ((INumericValue)m.getValue()).value();
out.append(format.format(value));
} else
out.append(m.getValue().toString());
}
}
out.newLine();
}
/* write header again */
out.append(header);
out.newLine();
/* and write calculated average */
out.append("average");
for (String key : allProperties) {
out.append(CSV_SEPARATOR);
Measurement m = e.getAverages().getMeasurements().get(key);
if (m != null) {
if (m.getValue() instanceof INumericValue) {
double value = ((INumericValue)m.getValue()).value();
out.append(format.format(value));
} else
out.append(m.getValue().toString());
}
}
out.newLine();
out.append("startupTime");
out.append(CSV_SEPARATOR);
try {
out.append(Double.toString(toolExp.getStartupTime()));
} catch (Exception ex) {
log.error("Error in calculating the startup time (linear regression): " + ex.getMessage());
out.append("Err");
}
out.newLine();
out.close();
} catch (IOException e1) {
log.error("Could not write statistics for: " + statistics, e1);
}
}
/*
* and write accumulated values
*/
File statisticsFile = new File(currentResultdir, "accumulated.csv");
allProperties.clear();
allProperties.add(MigrationResult.MIGRES_ELAPSED_TIME_PER_MB);
allProperties.add(MigrationResult.MIGRES_USED_TIME_PER_MB);
allProperties.add(MigrationResult.MIGRES_ELAPSED_TIME);
allProperties.add(MigrationResult.MIGRES_USED_TIME);
//...
try {
BufferedWriter out = new BufferedWriter(new FileWriter(statisticsFile));
/* write machine info */
if (toolExp != null) {
// use machine info of last experiment!
for (String prop: toolExp.getMeasurements().keySet()) {
if (prop.startsWith("machine:")){
out.append(prop)
.append(CSV_SEPARATOR)
.append(toolExp.getMeasurements().get(prop).getList().get(0).getValue().getFormattedValue());
out.newLine();
}
}
out.newLine();
}