Skip to content

Commit

Permalink
i_999 CI bug fixes to SubmitSampleRunsPane
Browse files Browse the repository at this point in the history
CI: While testing the new sandbox time grace periods, a couple of bugs were found in the SubmitSampleRunsPane (which is used to submit the judge's sample solutions by an administrator.    The following were fixed/added to support SubmitSampleRuns.
1) Add alphanumeric sorting instead of pure numeric sorting for some columns since some columns may have both text and numbers in them.
2) Synchronize the add runs since we appear to get 2 runAdded notifications for each run from different worker threads.
3) Fixed bug in Filter where if a custom filter group is used alone, it would not allow you to enable filtering.
  • Loading branch information
johnbrvc committed Aug 6, 2024
1 parent 6d849ec commit 5363556
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 69 deletions.
53 changes: 53 additions & 0 deletions src/edu/csus/ecs/pc2/core/list/AlphaNumericComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (C) 1989-2024 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
package edu.csus.ecs.pc2.core.list;

import java.io.Serializable;
import java.util.Comparator;

/**
* Compare the two strings as numbers
* <P>
* Compare things that may be words or numbers
*
* @author John Buck
*/

// $HeadURL$
// $Id$

public class AlphaNumericComparator implements Comparator<String>, Serializable {

private static final long serialVersionUID = 1L;

@Override
public int compare(String ValOne, String ValTwo) {
boolean b1Alpha = false;
boolean b2Alpha = false;
int cmpVal1 = 0;
int cmpVal2 = 0;

try {
cmpVal1 = Integer.parseInt(ValOne);
} catch(Exception exception) {
b1Alpha = true;
}
try {
cmpVal2 = Integer.parseInt(ValTwo);
} catch(Exception exception) {
b2Alpha = true;
}
if(b1Alpha) {
// If both are alpha, then just compare the strings.
if(b2Alpha) {
return(ValOne.compareToIgnoreCase(ValTwo));
}
// ValTwo is a number, and it comes before the alpha
return(1);
}
if(b2Alpha) {
// ValOne is a number, it comes before the alpha string
return(-1);
}
return(cmpVal1 - cmpVal2);
}
}
64 changes: 64 additions & 0 deletions src/edu/csus/ecs/pc2/core/list/LabelToDoubleComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (C) 1989-2024 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
package edu.csus.ecs.pc2.core.list;

import java.io.Serializable;
import java.util.Comparator;

import javax.swing.JLabel;

/**
* Compare the two strings as numbers
* <P>
* Simply convert to integers and compare
*
* @version $Id$
* @author John Buck
*/

// $HeadURL$
// $Id$

public class LabelToDoubleComparator implements Comparator<JLabel>, Serializable {

private static final long serialVersionUID = 1L;

@Override
public int compare(JLabel LabOne, JLabel LabTwo) {
String valOne = LabOne.getText();
String valTwo = LabTwo.getText();
boolean b1Alpha = false;
boolean b2Alpha = false;
double cmpVal1 = 0;
double cmpVal2 = 0;

try {
cmpVal1 = Double.parseDouble(valOne);
} catch(Exception exception) {
b1Alpha = true;
}
try {
cmpVal2 = Double.parseDouble(valTwo);
} catch(Exception exception) {
b2Alpha = true;
}
if(b1Alpha) {
// If both are alpha, then just compare the strings.
if(b2Alpha) {
return(valOne.compareToIgnoreCase(valTwo));
}
// ValTwo is a number, and it comes before the alpha
return(1);
}
if(b2Alpha) {
// ValOne is a number, it comes before the alpha string
return(-1);
}
double dResult = cmpVal1 - cmpVal2;
if(dResult < 0) {
return(-1);
} else if(dResult > 0) {
return(1);
}
return(0);
}
}
38 changes: 0 additions & 38 deletions src/edu/csus/ecs/pc2/core/list/StringToDoubleComparator.java

This file was deleted.

6 changes: 5 additions & 1 deletion src/edu/csus/ecs/pc2/core/model/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,9 @@ public String toString() {
if (filteringGroups) {
filterInfo += " groups(s)";
}
if (filteringCustom) {
filterInfo += " custom";
}

return filterInfo;
} else {
Expand Down Expand Up @@ -1373,7 +1376,8 @@ public boolean isFilterOn() {
|| filteringJudgements || filteringLanguages || filteringElapsedTime || filteringRunStates
|| filteringPermissions
|| thisSiteOnly
|| filteringGroups;
|| filteringGroups
|| filteringCustom;
} else {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/edu/csus/ecs/pc2/list/SubmissionSolutionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static List<String> getAllDirectoryEntries(String directory) {
* @return the acronym, or null if the folder is non-standard
*/
public String getAcronymForSubmissionDirectory(String dir) {
if(submissionDirectoryToAcronym.containsKey(dir)) {
if(dir != null && submissionDirectoryToAcronym.containsKey(dir)) {
return submissionDirectoryToAcronym.get(dir);
}
return null;
Expand Down
68 changes: 39 additions & 29 deletions src/edu/csus/ecs/pc2/ui/SubmitSampleRunsPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
import edu.csus.ecs.pc2.core.FileUtilities;
import edu.csus.ecs.pc2.core.IInternalController;
import edu.csus.ecs.pc2.core.Utilities;
import edu.csus.ecs.pc2.core.list.StringToDoubleComparator;
import edu.csus.ecs.pc2.core.list.StringToNumberComparator;
import edu.csus.ecs.pc2.core.list.AlphaNumericComparator;
import edu.csus.ecs.pc2.core.list.LabelToDoubleComparator;
import edu.csus.ecs.pc2.core.log.Log;
import edu.csus.ecs.pc2.core.log.StaticLog;
import edu.csus.ecs.pc2.core.model.ClientId;
Expand Down Expand Up @@ -310,7 +310,9 @@ protected void updateCDPDirAndFields(String cdpConfigDir) {
public SubmissionSolutionList getSubmissionSolutionList() {
String cdpPath = cdpTextField.getText();

submissionSolutionList = new SubmissionSolutionList(getContest(), cdpPath);
if(submissionSolutionList == null) {
submissionSolutionList = new SubmissionSolutionList(getContest(), cdpPath);
}

return submissionSolutionList;
}
Expand Down Expand Up @@ -547,7 +549,9 @@ public void run() {
private void clearSubmissionFiles() {
submissionFileList = null;
currentSubmission = -1;
runsAdded.clear();
synchronized(runsAdded) {
runsAdded.clear();
}
}

private void stopSubmissionTimer() {
Expand Down Expand Up @@ -781,7 +785,7 @@ public Component prepareRenderer(TableCellRenderer renderer, int row, int column
// Object[] fullColumns = { "Run Id", "Time", "Problem", "Expected", "Status", "Source", "Judge", "Language", "SubmissionSample" };

int modelRow = convertRowIndexToModel(row);
String submissionAcronym = submissionSolutionList.getAcronymForSubmissionDirectory((String)runTableModel.getValueAt(modelRow, 3));
String submissionAcronym = getSubmissionSolutionList().getAcronymForSubmissionDirectory((String)runTableModel.getValueAt(modelRow, 3));

if(submissionAcronym == null) {
c.setBackground(matchColorMaybe);
Expand Down Expand Up @@ -897,8 +901,8 @@ public boolean isCellEditable(int row, int col) {

runTable.getColumnModel().getColumn(ELAPSED_TIME_COLUMN).setCellRenderer(new LinkCellRenderer());

StringToNumberComparator numericStringSorter = new StringToNumberComparator();
StringToDoubleComparator doubleStringSorter = new StringToDoubleComparator();
AlphaNumericComparator numericStringSorter = new AlphaNumericComparator();
LabelToDoubleComparator doubleStringSorter = new LabelToDoubleComparator();

int idx = 0;

Expand Down Expand Up @@ -1051,7 +1055,7 @@ protected Object[] buildRunRow(SubmissionSample sub, ClientId judgeId) {
if(maxMS == -1) {
s[idx++] = new JLabel("N/A");
} else {
s[idx++] = new JLabel(String.format("%d.%03ds", maxMS/1000, maxMS%1000));
s[idx++] = new JLabel(String.format("%d.%03d", maxMS/1000, maxMS%1000));
}
s[idx++] = sub.getSourceFile().getName();
s[idx++] = getJudgesTitle(run, judgeId, autoJudgedRun);
Expand Down Expand Up @@ -1313,14 +1317,16 @@ public void runAdded(RunEvent event) {
Run run = event.getRun();
Integer runNum = new Integer(run.getNumber());

if(runsAdded.contains(runNum)) {
log.log(Level.WARNING, "Duplicate runAdded event for Run id " + run.getNumber() + " ignored.");
if(Utilities.isDebugMode()) {
System.out.println("Duplicate runAdded (" + run.getNumber() + ") ignored - currentSubmission #" + currentSubmission);
synchronized (runsAdded) {
if(runsAdded.contains(runNum)) {
log.log(Level.WARNING, "Duplicate runAdded event for Run id " + run.getNumber() + " ignored.");
if(Utilities.isDebugMode()) {
System.out.println("Duplicate runAdded (" + run.getNumber() + ") ignored - currentSubmission #" + currentSubmission);
}
return;
}
return;
runsAdded.add(runNum);
}
runsAdded.add(runNum);
if(Utilities.isDebugMode()) {
System.out.println("Got runAdded for run ID " + run.getNumber() + " - added to runsAdded hashset");
}
Expand All @@ -1329,21 +1335,25 @@ public void runAdded(RunEvent event) {

// We are only interested in runs we submitted
if(run.getSubmitter().equals(me)) {
// This is the last run - it has to be the one that was just added by us
sub = submissionList.get(currentSubmission);
if(sub != null) {
stopSubmissionTimer();
sub.setRun(run);
if(Utilities.isDebugMode()) {
System.out.println("Received runAdded currentSubmission #" + currentSubmission + " for problem " + sub.toString());
}
updateRunRow(sub, event.getWhoModifiedRun(), true);
// setup for next submission; if last one clean things up.
currentSubmission++;
if(currentSubmission >= submissionFileList.size()) {
clearSubmissionFiles();
} else {
submitNextSubmission();
// Since we get run added events for each run, it's possible that the currentSubmission could be -1
// in the event of the very last submission, since clearSubmissionFiles() below would set it to -1
if(currentSubmission >= 0) {
// This is the last run - it has to be the one that was just added by us
sub = submissionList.get(currentSubmission);
if(sub != null) {
stopSubmissionTimer();
sub.setRun(run);
if(Utilities.isDebugMode()) {
System.out.println("Received runAdded currentSubmission #" + currentSubmission + " for problem " + sub.toString());
}
updateRunRow(sub, event.getWhoModifiedRun(), true);
// setup for next submission; if last one clean things up.
currentSubmission++;
if(currentSubmission >= submissionFileList.size()) {
clearSubmissionFiles();
} else {
submitNextSubmission();
}
}
}
}
Expand Down

0 comments on commit 5363556

Please sign in to comment.