Skip to content

Commit

Permalink
Merge pull request #998 from johnbrvc/i966_results_compare_fixes
Browse files Browse the repository at this point in the history
Two approvals.
Tested on multiple contest's data sets as well.
  • Loading branch information
johnbrvc authored Aug 27, 2024
2 parents 9bbe5a3 + d640123 commit b76eea2
Show file tree
Hide file tree
Showing 19 changed files with 112,649 additions and 7,094 deletions.
182 changes: 132 additions & 50 deletions src/edu/csus/ecs/pc2/core/StringUtilities.java

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions src/edu/csus/ecs/pc2/core/imports/clics/FieldCompareRecord.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 1989-2023 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
// Copyright (C) 1989-2024 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
package edu.csus.ecs.pc2.core.imports.clics;

import java.util.logging.Level;
Expand All @@ -13,7 +13,7 @@

/**
* Information about a comparison of two fields.
*
*
* @author Douglas A. Lane, PC^2 team [email protected]
*/
public class FieldCompareRecord {
Expand All @@ -39,7 +39,7 @@ public class FieldCompareRecord {
public FieldCompareRecord(String fieldName, String valueOne, String valueTwo, String details) {
this(fieldName, valueOne, valueTwo, details, null);
}

public FieldCompareRecord(String fieldName, String valueOne, String valueTwo, String details, String key) {
super();
this.fieldName = fieldName;
Expand All @@ -48,6 +48,9 @@ public FieldCompareRecord(String fieldName, String valueOne, String valueTwo, St
this.details = details;
this.key = key;

if(key == null) {
this.key = "any";
}
createComparisonState(valueOne, valueTwo);
}

Expand Down Expand Up @@ -106,18 +109,18 @@ public String getDetails() {
public void setDetails(String details) {
this.details = details;
}

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

/**
* Returns a JSON string representation of this SerializedFile object.
*
*
* @return a String containing a JSON representation of this object, or null if an error occurs during creation of the JSON string
*/
// TODO REFACTOR Move into a JSON Utility class
Expand All @@ -137,7 +140,7 @@ public String toJSON() {
return null;
}
}

@Override
public String toString() {
return toJSON();
Expand Down
31 changes: 24 additions & 7 deletions src/edu/csus/ecs/pc2/core/report/FieldCompareRecordComparator.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 1989-2023 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
// Copyright (C) 1989-2024 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
package edu.csus.ecs.pc2.core.report;

import java.util.Comparator;
Expand All @@ -7,20 +7,37 @@
import edu.csus.ecs.pc2.core.imports.clics.FieldCompareRecord;

/**
* Compare by key then by fieldName.
*
* Compare by State (type of error), then key then by fieldName.
*
* @author Douglas A. Lane, PC^2 team [email protected]
*/
public class FieldCompareRecordComparator implements Comparator<FieldCompareRecord> {

@Override
public int compare(FieldCompareRecord o1, FieldCompareRecord o2) {

if (o1.getKey().equals(o2.getKey())) {
return StringUtilities.nullSafeCompareTo(o1.getFieldName(), o2.getFieldName());
} else {
return StringUtilities.nullSafeCompareTo(o1.getKey(), o2.getKey());
// Reverse sort by state number, since we want the non-matches first, then the missings.
int cmpResult = o2.getState().ordinal() - o1.getState().ordinal();
if(cmpResult == 0) {
String k1 = o1.getKey();
String k2 = o2.getKey();

// Paranoia with the keys
if(k1 == null){
if(k2 == null) {
return(0);
}
return(-1);
} else if(k2 == null) {
return(1);
}
if (o1.getKey().equals(o2.getKey())) {
cmpResult = StringUtilities.nullSafeNaturalCompareTo(o1.getFieldName(), o2.getFieldName(), false);
} else {
cmpResult = StringUtilities.nullSafeNaturalCompareTo(o1.getKey(), o2.getKey(), false);
}
}
return(cmpResult);
}

}
Loading

0 comments on commit b76eea2

Please sign in to comment.