Fixed csv

- added examples.csv
- fixed csv logic for header and first line
This commit is contained in:
2025-01-30 11:46:25 +01:00
parent 5e5b51e38c
commit 8c349d6eec
8 changed files with 5045 additions and 10 deletions

1
.gitignore vendored
View File

@@ -27,4 +27,3 @@ replay_pid*
# mine
target/*
pdf/*
*.csv

21
.vscode/launch.json vendored
View File

@@ -25,5 +25,26 @@
"mainClass": "net.berack.upo.valpre.Main",
"args": "simulation -net example1.net -runs 10"
},
{
"type": "java",
"name": "Run10",
"request": "launch",
"mainClass": "net.berack.upo.valpre.Main",
"args": "simulation -net example1.net -runs 10"
},
{
"type": "java",
"name": "Plot Simple",
"request": "launch",
"mainClass": "net.berack.upo.valpre.Main",
"args": "plot -csv example1.csv"
},
{
"type": "java",
"name": "Plot Complex",
"request": "launch",
"mainClass": "net.berack.upo.valpre.Main",
"args": "plot -csv example2.csv"
},
]
}

View File

@@ -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;
}
}

View 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);
}

View File

@@ -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;
}
/**

View 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();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff