diff --git a/tools/compile-results/src/main/java/moobench/tools/compile/results/CompileResultsMain.java b/tools/compile-results/src/main/java/moobench/tools/compile/results/CompileResultsMain.java index 6b40cdeeaf7f66bb47dfe1f73beed3516b6bd5ef..5bbf3fa2a58e4325907af44e35040a3d76b8fbd3 100644 --- a/tools/compile-results/src/main/java/moobench/tools/compile/results/CompileResultsMain.java +++ b/tools/compile-results/src/main/java/moobench/tools/compile/results/CompileResultsMain.java @@ -7,6 +7,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -21,13 +22,14 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.DoubleNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.LongNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ObjectMapper; /** * Read the CSV output of the R script and the existing JSON file and append a * record to the JSON file based on the CSV dataset. - * + * * @author Reiner Jung * */ @@ -51,6 +53,24 @@ public class CompileResultsMain { ArrayNode arrayResultsNode = (ArrayNode)resultsNode; + long build = arrayResultsNode.size(); + + /** Fix old data in necessary. */ + for (int i=0;i<arrayResultsNode.size();i++) { + JsonNode node = arrayResultsNode.get(i); + if (node instanceof ObjectNode) { + ObjectNode objectNode = (ObjectNode)node; + JsonNode timeValue = objectNode.get("time"); + if (timeValue == null) { + objectNode.put("time", new Date().getTime()); + } + JsonNode buildValue = objectNode.get("build"); + if (buildValue == null) { + objectNode.put("build", i); + } + } + } + /** Read CSV file. */ final CSVParser csvParser = new CSVParser(Files.newBufferedReader(Paths.get(args[0])), CSVFormat.DEFAULT.withHeader()); @@ -59,13 +79,18 @@ public class CompileResultsMain { JsonNodeFactory factory = JsonNodeFactory.instance; /** Put CSV in JSON. */ - for (CSVRecord record : csvParser.getRecords()) { + for (CSVRecord record : csvParser.getRecords()) { Map<String, JsonNode> recordMap = new HashMap<>(); + recordMap.put("time",new LongNode(new Date().getTime())); + recordMap.put("build",new LongNode(build++)); for (int i=0; i < record.size(); i++) { recordMap.put(header.get(i), new DoubleNode(Double.parseDouble(record.get(i)))); } arrayResultsNode.add(new ObjectNode(factory, recordMap)); } + + /** Check consistency. */ + /** Write JSON file. */ ObjectMapper mapper = new ObjectMapper();