Commit 67a1dc9f authored by Mario Teixeira Parente's avatar Mario Teixeira Parente
Browse files

Add timestamp option for output folder

If timestamp option in json is set to false, no timestamp is written in the output's folder name.
parent db12ac1c
......@@ -214,8 +214,12 @@ public class ScenarioRunManager implements Runnable {
}
public void setOutputPaths(final Path outputPath) {
String dateString = new SimpleDateFormat(IOUtils.DATE_FORMAT).format(new Date());
this.outputPath = Paths.get(outputPath.toString(), String.format("%s_%s", this.getName(), dateString));
if (this.dataProcessingJsonManager.isTimestamped()) {
String dateString = new SimpleDateFormat(IOUtils.DATE_FORMAT).format(new Date());
this.outputPath = Paths.get(outputPath.toString(), String.format("%s_%s", this.getName(), dateString));
} else {
this.outputPath = Paths.get(outputPath.toString(), this.getName());
}
}
public void setName(String name) {
......
......@@ -44,6 +44,8 @@ public class DataProcessingJsonManager {
private static final String ATTRIBUTESTYPE_KEY = "attributesType";
public static final String ATTRIBUTES_KEY = "attributes";
private static final String TIMESTAMP_KEY = "isTimestamped";
public static final String DEFAULT_SEPARATOR = " ";
private static ObjectMapper mapper;
......@@ -54,6 +56,7 @@ public class DataProcessingJsonManager {
private List<OutputFile<?>> outputFiles;
private List<DataProcessor<?, ?>> dataProcessors;
private boolean isTimestamped;
static {
mapper = JsonConverter.getMapper();
......@@ -66,6 +69,7 @@ public class DataProcessingJsonManager {
public DataProcessingJsonManager() {
this.outputFiles = new ArrayList<>();
this.dataProcessors = new ArrayList<>();
this.isTimestamped = true;
}
public void addOutputFile(final OutputFileStore fileStore) {
......@@ -86,6 +90,14 @@ public class DataProcessingJsonManager {
this.dataProcessors.add(dataProcessor);
}
public boolean isTimestamped() {
return this.isTimestamped;
}
private void setTimestamped(boolean isTimestamped) {
this.isTimestamped = isTimestamped;
}
private static JsonNode serializeOutputFile(final OutputFile outputFile) {
ObjectNode node = mapper.createObjectNode();
......@@ -125,22 +137,23 @@ public class DataProcessingJsonManager {
public JsonNode serializeToNode() {
ObjectNode main = mapper.createObjectNode();
ArrayNode outputFilesArrayNode = mapper.createArrayNode();
ArrayNode processorsArrayNode = mapper.createArrayNode();
// part 1: output files
ArrayNode outputFilesArrayNode = mapper.createArrayNode();
this.outputFiles.forEach(file -> {
outputFilesArrayNode.add(serializeOutputFile(file));
});
main.set(FILES_KEY, outputFilesArrayNode);
// part 2: processor
// part 2: processors
ArrayNode processorsArrayNode = mapper.createArrayNode();
this.dataProcessors.forEach(proc -> {
processorsArrayNode.add(serializeProcessor(proc));
});
main.set(FILES_KEY, outputFilesArrayNode);
main.set(PROCESSORS_KEY, processorsArrayNode);
// part 3: timestamp
main.put(TIMESTAMP_KEY, this.isTimestamped);
return main;
}
......@@ -170,23 +183,28 @@ public class DataProcessingJsonManager {
public static DataProcessingJsonManager deserializeFromNode(JsonNode node) throws JsonProcessingException {
DataProcessingJsonManager manager = new DataProcessingJsonManager();
ArrayNode outputFilesArrayNode = (ArrayNode) node.get(FILES_KEY);
ArrayNode processorsArrayNode = (ArrayNode) node.get(PROCESSORS_KEY);
// part 1: output files
ArrayNode outputFilesArrayNode = (ArrayNode) node.get(FILES_KEY);
if (outputFilesArrayNode != null)
for (JsonNode fileNode : outputFilesArrayNode) {
OutputFileStore fileStore = mapper.treeToValue(fileNode, OutputFileStore.class);
manager.addOutputFile(fileStore);
}
// part 2: processor
// part 2: processors
ArrayNode processorsArrayNode = (ArrayNode) node.get(PROCESSORS_KEY);
if (processorsArrayNode != null)
for (JsonNode processorNode : processorsArrayNode) {
DataProcessorStore dataProcessorStore = deserializeProcessorStore(processorNode);
manager.addProcessor(dataProcessorStore);
}
// part 3: timestamp
JsonNode timestampArrayNode = node.get(TIMESTAMP_KEY);
if (timestampArrayNode != null) {
manager.setTimestamped(timestampArrayNode.asBoolean());
}
return manager;
}
......
......@@ -33,6 +33,8 @@ public final class OutputPresets {
outputFile.setFilename(DataProcessingJsonManager.TRAJECTORIES_FILENAME);
outputFile.setProcessors(Arrays.asList(1, 2));
this.outputDefinition.addOutputFile(outputFile);
this.outputDefinition.setTimestamped(true);
}
public static OutputDefinitionStore getOutputDefinition() {
......
......@@ -6,10 +6,12 @@ import java.util.List;
public class OutputDefinitionStore {
private List<OutputFileStore> files;
private List<DataProcessorStore> processors;
private boolean isTimestamped;
public OutputDefinitionStore() {
this.files = new ArrayList<>();
this.processors = new ArrayList<>();
this.isTimestamped = true;
}
public void addOutputFile(OutputFileStore file) {
......@@ -19,4 +21,8 @@ public class OutputDefinitionStore {
public void addProcessor(DataProcessorStore processor) {
this.processors.add(processor);
}
public void setTimestamped(boolean isTimestamped) {
this.isTimestamped = isTimestamped;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment