Skip to content
Snippets Groups Projects
Commit df17e6dd authored by Reiner Jung's avatar Reiner Jung
Browse files

Improved compile results with time and build numbers.

parent fd27dac1
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import java.io.File; ...@@ -7,6 +7,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -21,13 +22,14 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -21,13 +22,14 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.DoubleNode; import com.fasterxml.jackson.databind.node.DoubleNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory; 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.node.ObjectNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
/** /**
* Read the CSV output of the R script and the existing JSON file and append a * 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. * record to the JSON file based on the CSV dataset.
* *
* @author Reiner Jung * @author Reiner Jung
* *
*/ */
...@@ -51,6 +53,24 @@ public class CompileResultsMain { ...@@ -51,6 +53,24 @@ public class CompileResultsMain {
ArrayNode arrayResultsNode = (ArrayNode)resultsNode; 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. */ /** Read CSV file. */
final CSVParser csvParser = new CSVParser(Files.newBufferedReader(Paths.get(args[0])), final CSVParser csvParser = new CSVParser(Files.newBufferedReader(Paths.get(args[0])),
CSVFormat.DEFAULT.withHeader()); CSVFormat.DEFAULT.withHeader());
...@@ -59,13 +79,18 @@ public class CompileResultsMain { ...@@ -59,13 +79,18 @@ public class CompileResultsMain {
JsonNodeFactory factory = JsonNodeFactory.instance; JsonNodeFactory factory = JsonNodeFactory.instance;
/** Put CSV in JSON. */ /** Put CSV in JSON. */
for (CSVRecord record : csvParser.getRecords()) { for (CSVRecord record : csvParser.getRecords()) {
Map<String, JsonNode> recordMap = new HashMap<>(); 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++) { for (int i=0; i < record.size(); i++) {
recordMap.put(header.get(i), new DoubleNode(Double.parseDouble(record.get(i)))); recordMap.put(header.get(i), new DoubleNode(Double.parseDouble(record.get(i))));
} }
arrayResultsNode.add(new ObjectNode(factory, recordMap)); arrayResultsNode.add(new ObjectNode(factory, recordMap));
} }
/** Check consistency. */
/** Write JSON file. */ /** Write JSON file. */
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment