Skip to content

Commit

Permalink
add ref_id attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Jun 13, 2024
1 parent 16998d3 commit d04715c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
public class TripAnalysis implements MATSimAppCommand {

private static final Logger log = LogManager.getLogger(TripAnalysis.class);

/**
* Attributes which relates this person to a reference person.
*/
public static String ATTR_REF_ID = "ref_id";
/**
* Person attribute that contains the reference modes of a person. Multiple modes are delimited by "-".
*/
Expand All @@ -56,6 +61,7 @@ public class TripAnalysis implements MATSimAppCommand {
* Person attribute containing its weight for analysis purposes.
*/
public static String ATTR_REF_WEIGHT = "ref_weight";

@CommandLine.Mixin
private InputOptions input = InputOptions.ofCommand(TripAnalysis.class);
@CommandLine.Mixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public TripChoiceAnalysis(Table persons, Table trips, List<String> modeOrder) {

if (n < split.length) {
String trueMode = split[n];
data.add(new Entry(person, weight, n, trip.getLong("euclidean_distance"), trueMode, predMode));
data.add(new Entry((String) trip.getObject(TripAnalysis.ATTR_REF_ID),
person, weight, n, trip.getLong("euclidean_distance"), trueMode, predMode));
} else
log.warn("Person {} trip {} does not match ref data ({})", person, n, split.length);
}
Expand Down Expand Up @@ -166,9 +167,9 @@ private Counts countPredictions(String mode, List<Entry> data) {
*/
public void writeChoices(Path path) throws IOException {
try (CSVPrinter csv = new CSVPrinter(Files.newBufferedWriter(path), CSVFormat.DEFAULT)) {
csv.printRecord("person", "weight", "n", "euclidean_distance", "true_mode", "pred_mode");
csv.printRecord("ref_id", "person", "weight", "n", "euclidean_distance", "true_mode", "pred_mode");
for (Entry e : data) {
csv.printRecord(e.person, e.weight, e.n, e.dist, e.trueMode, e.predMode);
csv.printRecord(e.refId, e.person, e.weight, e.n, e.dist, e.trueMode, e.predMode);
}
}
}
Expand Down Expand Up @@ -270,7 +271,7 @@ public void writeModePredictionError(Path path) throws IOException {
}
}

record Entry(String person, double weight, int n, long dist, String trueMode, String predMode) {
record Entry(String refId, String person, double weight, int n, long dist, String trueMode, String predMode) {
}

record Pair(String trueMode, String predMode) {
Expand Down

0 comments on commit d04715c

Please sign in to comment.