Fixed csv
- added examples.csv - fixed csv logic for header and first line
This commit is contained in:
@@ -151,4 +151,16 @@ public class Parameters {
|
||||
throw new IllegalArgumentException("Invalid arguments");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file or the example file if it is present.
|
||||
*
|
||||
* @param file the file to get
|
||||
* @return the file or the example file
|
||||
*/
|
||||
public static String getFileOrExample(String file) {
|
||||
if (file.startsWith("example"))
|
||||
file = Main.class.getClassLoader().getResource(file).getPath();
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ public class Plot {
|
||||
*/
|
||||
public Plot(String[] args) throws IOException {
|
||||
var arguments = Plot.parseParameters(args);
|
||||
var csv = arguments.get("csv");
|
||||
if (csv == null)
|
||||
var file = Parameters.getFileOrExample(arguments.get("csv"));
|
||||
if (file == null)
|
||||
throw new IllegalArgumentException("CSV file needed! Use -csv <file>");
|
||||
|
||||
var results = new CsvResult(csv).loadResults();
|
||||
var results = new CsvResult(file).loadResults();
|
||||
this.results = new ResultMultiple(results);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,12 +36,9 @@ public class Simulation {
|
||||
this.csv = arguments.getOrDefault("csv", null);
|
||||
this.parallel = arguments.containsKey("p");
|
||||
|
||||
var file = arguments.get("net");
|
||||
if (file == null)
|
||||
this.file = Parameters.getFileOrExample(arguments.get("net"));
|
||||
if (this.file == null)
|
||||
throw new IllegalArgumentException("Net file needed! Use -net <file>");
|
||||
if (file.startsWith("example"))
|
||||
file = Main.class.getClassLoader().getResource(file).getPath();
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,7 +36,9 @@ public class CsvResult {
|
||||
*/
|
||||
public void saveResults(Result[] results) throws IOException {
|
||||
var builder = new StringBuilder();
|
||||
builder.append("seed,node,");
|
||||
builder.append(String.join(",", Statistics.getOrderOfApply()));
|
||||
builder.append('\n');
|
||||
|
||||
try (var writer = new FileWriter(this.file)) {
|
||||
for (var result : results) {
|
||||
@@ -97,6 +99,8 @@ public class CsvResult {
|
||||
builder.append(val).append(",");
|
||||
return val;
|
||||
});
|
||||
|
||||
builder.deleteCharAt(builder.length() - 1); // remove the last comma
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
2001
src/main/resources/example1.csv
Normal file
2001
src/main/resources/example1.csv
Normal file
File diff suppressed because it is too large
Load Diff
3001
src/main/resources/example2.csv
Normal file
3001
src/main/resources/example2.csv
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user