Skip to content

Commit

Permalink
better human-readable InstanceReport toString
Browse files Browse the repository at this point in the history
  • Loading branch information
J-morag committed Jan 26, 2023
1 parent daa832b commit 3c2cbd3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/main/java/Environment/Metrics/InstanceReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,28 @@ String getValue(String fieldName){

@Override
public String toString() {
return this.toString(stringFields, integerFields, floatFields);
}

public String toString(Set<String> skipFields) {
if (skipFields.isEmpty()){
return this.toString();
}
HashMap<String, String> strings = new HashMap<>(stringFields);
strings.keySet().removeAll(skipFields);
HashMap<String, Integer> integers = new HashMap<>(integerFields);
integers.keySet().removeAll(skipFields);
HashMap<String, Float> floats = new HashMap<>(floatFields);
floats.keySet().removeAll(skipFields);
return this.toString(strings, integers, floats);
}

public String toString(Map<String, String> strings, Map<String, Integer> integers, Map<String, Float> floats){
return "InstanceReport{" +
"stringFields=" + stringFields +
", integerFields=" + integerFields +
", floatFields=" + floatFields +
'}';
"\nstringFields=" + strings +
"\nintegerFields=" + integers +
"\nfloatFields=" + floats +
"\n}";
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/Environment/Metrics/S_Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ public static String instanceReportToHumanReadableString(InstanceReport instance
return instanceReport.toString() + '\n';
}

/**
* Returns a string representation of the information in an instanceReport, in a format that is suitable for easy
* reading. Useful for outputing to a console to monitor the experiment.
* Skips outputting the solutions because they are long.
* @param instanceReport the InstanceReport to convert to a string. @NotNull.
* @return a string representation of the information in an instanceReport, in a format readable format.
*/
public static String instanceReportToHumanReadableStringSkipSolutions(InstanceReport instanceReport){
return instanceReport.toString(Set.of(InstanceReport.StandardFields.solution)) + '\n';
}

// nicetohave tosrting json

//// outputing to the streams ////
Expand Down

0 comments on commit 3c2cbd3

Please sign in to comment.