Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ContestModel/src/org/icpc/tools/contest/model/IAward.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public enum DisplayMode {
AwardType GROUP_HIGHLIGHT = new AwardType("Group Highlight", "group-highlight-.*");
AwardType SOLVED = new AwardType("Solved", "solved-.*");
AwardType TOP = new AwardType("Top", "top-.*");
AwardType HONORS = new AwardType("Honors", "honors-.*");
AwardType HONORS = new AwardType("Honors", "(honors-.*|.*-honors|honors)");
// AwardType HONORABLE_MENTION = new AwardType("Honorable Mention", "honorable-mention");
AwardType EXPECTED_TO_ADVANCE = new AwardType("Expected to Advance", "expected-to-advance");
AwardType OTHER = new AwardType("Other", ".*");
Expand Down Expand Up @@ -101,4 +101,4 @@ public enum DisplayMode {
* @return
*/
DisplayMode getDisplayMode();
}
}
112 changes: 92 additions & 20 deletions ContestModel/src/org/icpc/tools/contest/model/util/AwardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,33 +556,70 @@ public static void createHonorsAwards(Contest contest, int percentile) {
}

public static void createHonorsAwards(Contest contest, IAward template) throws IllegalArgumentException {
int percentileTop = 0;
int percentileBottom = 100;
int solvedTop = -1;
int solvedBottom = -1;
int percentileTop = -1;
int percentileBottom = -1;
DisplayMode mode = template.getDisplayMode();
if (!template.hasDisplayMode())
mode = IAward.DisplayMode.LIST;

// find teams we're going to base this on
ITeam[] teams = contest.getOrderedTeams();
if (teams.length == 0)
return;

try {
String param = template.getParameter();
int ind = param.indexOf("-");
percentileTop = Integer.parseInt(param.substring(0, ind));
percentileBottom = Integer.parseInt(param.substring(ind + 1, param.length()));

if (percentileTop < 0 || percentileTop > 99)
throw new IllegalArgumentException("Honor parameter invalid");
if (percentileBottom < 1 || percentileBottom > 100)
throw new IllegalArgumentException("Honor parameter invalid");
if (percentileBottom < percentileTop)
throw new IllegalArgumentException("Honor parameter invalid");
if (param.startsWith("p")) {
percentileTop = Integer.parseInt(param.substring(1, ind));
} else {
solvedTop = Integer.parseInt(param.substring(0, ind));
}
if (param.substring(ind + 1).startsWith("p")) {
percentileBottom = Integer.parseInt(param.substring(ind + 2));
} else {
solvedBottom = Integer.parseInt(param.substring(ind + 1));
}

if (percentileTop < 0 && solvedTop < 0)
throw new IllegalArgumentException("Honor solved parameter invalid");
if (percentileBottom < 0 && solvedBottom < 0)
throw new IllegalArgumentException("Honor solved parameter invalid");
if (percentileBottom >= 0 && percentileTop >= 0 && percentileBottom < percentileTop)
throw new IllegalArgumentException("Honor solved parameter invalid");
if (percentileTop > 99 || percentileBottom > 100)
throw new IllegalArgumentException("Honor solved parameter invalid");
if (solvedBottom >= 0 && solvedTop >= 0 && solvedBottom < solvedTop)
throw new IllegalArgumentException("Honor solved parameter invalid");
if (solvedBottom > teams.length || solvedTop > teams.length)
throw new IllegalArgumentException("Honor solved parameter invalid");

} catch (Exception e) {
throw new IllegalArgumentException("Could not parse honor parameter: " + template.getParameter());
}

IAward[] awards = contest.getAwards();

// Determine how many problems the lowest medalist solved. We need this for the solvedTop/solvedBottom case.
int lowestMedalNumSolved = Integer.MAX_VALUE;
int numMedalists = 0;
for (IAward a : awards) {
if (a.getAwardType() == IAward.MEDAL) {
numMedalists += a.getTeamIds().length;
for (String tid : a.getTeamIds()) {
IStanding s = contest.getStanding(contest.getTeamById(tid));
if (s != null && s.getNumSolved() > 0) {
lowestMedalNumSolved = Math.min(lowestMedalNumSolved, s.getNumSolved());
}
}
}
}

// find teams we're going to base this on
ITeam[] teams = contest.getOrderedTeams();
if (teams.length == 0)
return;

// Find the top team
int n = teams.length;
int t = 0;
if (percentileTop > 0) {
Expand All @@ -593,17 +630,29 @@ public static void createHonorsAwards(Contest contest, IAward template) throws I
while (t < n && contest.getStanding(teams[t]).getNumSolved() == numSolved) {
t++;
}
} else if (solvedTop > 0) {
while (t < n && contest.getStanding(teams[t]).getNumSolved() > lowestMedalNumSolved - solvedTop) {
t++;
}
} else {
// solvedTop == 0, start just below the medalists.
t = numMedalists;
}

// find the bottom team
int b = n;
if (percentileBottom < 100) {
if (percentileBottom >= 0 && percentileBottom < 100) {
b = (int) Math.round(percentileBottom * n / 100.0);
IStanding standing = contest.getStanding(teams[b]);
int numSolved = standing.getNumSolved();
while (b < n && contest.getStanding(teams[b]).getNumSolved() == numSolved) {
b++;
}
} else if (solvedBottom >= 0) {
b = 0;
while (b < n && contest.getStanding(teams[b]).getNumSolved() > lowestMedalNumSolved - solvedBottom) {
b++;
}
}

String[] teamIds = new String[b - t];
Expand All @@ -612,18 +661,32 @@ public static void createHonorsAwards(Contest contest, IAward template) throws I
}

String citation = template.getCitation();
if (citation == null || citation.trim().length() < 1) {
if (percentileTop > 1 && percentileBottom == 100)
if (citation == null || citation.trim().isEmpty()) {
if (template.getId().equals("highest-honors"))
citation = Messages.getString("awardHighestHonors");
else if (template.getId().equals("high-honors"))
citation = Messages.getString("awardHighHonors");
else if (template.getId().equals("honors"))
citation = Messages.getString("awardHonors2");
else if (percentileTop > 1 && percentileBottom == 100)
citation = Messages.getString("awardHonorableMention");
else
// TODO: this seems wrong. Entry 'awardHonors' is "{0}% Honors"
// The "{0}" should be replaced by something!
citation = Messages.getString("awardHonors");
}

Award award = new Award(IAward.HONORS, template.getId().substring(7), teamIds, citation, mode);
Award award = new Award(IAward.HONORS, template.getId(), teamIds, citation, mode);
// Overwrite the ID to the actual ID, since we know what we are doing
award.add("id", template.getId());
IStanding standing = contest.getStanding(teams[t]);
award.setParameter(standing.getNumSolved() + "");

// If the top of our list is just below the medalists or in the medalists, show it before the medalists
if (t <= numMedalists) {
award.setParameter("before:" + numMedalists);
} else {
award.setParameter(standing.getNumSolved() + "");
}
contest.add(award);
}

Expand Down Expand Up @@ -719,9 +782,11 @@ public static void applyAwards(Contest contest, IAward[] awardTemplate) {
List<IAward> gold = new ArrayList<>();
List<IAward> silver = new ArrayList<>();
List<IAward> bronze = new ArrayList<>();
List<IAward> honors = new ArrayList<>();

List<IAward> solvedAwards = new ArrayList<>();


for (IAward award : awardTemplate) {
if (award.getAwardType() == IAward.WINNER) {
createWinnerAward(contest, award);
Expand All @@ -736,7 +801,7 @@ public static void applyAwards(Contest contest, IAward[] awardTemplate) {
} else if (award.getAwardType() == IAward.EXPECTED_TO_ADVANCE) {
createExpectedToAdvanceAwards(contest, award);
} else if (award.getAwardType() == IAward.HONORS) {
createHonorsAwards(contest, award);
honors.add(award);
} else if (award.getAwardType() == IAward.SOLVED) {
solvedAwards.add(award);
} else if (award.getAwardType() == IAward.MEDAL) {
Expand All @@ -753,6 +818,13 @@ else if (award.getId().contains("bronze"))
createMedalAwards(contest, gold, silver, bronze);
}

// We need to do this after the medals are created, because we need to know the number of solved problems for the lowest medalist
if (!honors.isEmpty()) {
for (IAward award : honors) {
createHonorsAwards(contest, award);
}
}

if (!solvedAwards.isEmpty()) {
for (IAward award : solvedAwards) {
createSolutionAwards(contest, award);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ awardSolving={0}, and solving {1} problems in {2} minutes
awardTop=Top {0}% of teams
awardHonors={0}% Honors
awardHonorableMention=Honorable mention
teamListSubtitle=Solving {0} problems
awardHighestHonors=Highest Honors
awardHighHonors=High Honors
awardHonors2=Honors
teamListSubtitle=Solving {0} problems
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ awardSolving={0}, y resueltos {1} problemas en {2} minutos
awardTop={0}% mejores equipos
awardHonors={0}% Honors
awardHonorableMention=Mención de honor
teamListSubtitle=Resueltos {0} problemas
awardHighestHonors=Honores máximos
awardHighHonors=Honores altos
awardHonors2=Honores
teamListSubtitle=Resueltos {0} problemas
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ public class TemplateAwardDialog extends AbstractAwardDialog {
"{\"id\":\"silver-medal\",\"parameter\":\"4\"}\n" + // silver medals
"{\"id\":\"bronze-medal\",\"parameter\":\"4\"}\n" + // bronze medals
"{\"id\":\"first-to-solve-*\"}\n" + // first to solve awards
"{\"id\":\"top-25\",\"parameter\":\"25\"}\n" + // top 25% of teams
"{\"id\":\"honors-mention\",\"parameter\":\"50-100\"}\n" + // honorable mention for teams
"{\"id\":\"highest-honors\",\"parameter\":\"0-1\"}\n" + // All medalists + all solving the same number of problems as the lowest medalist
"{\"id\":\"high-honors\",\"parameter\":\"1-2\"}\n" + // All teams solving one fewer than the lowest medalist
"{\"id\":\"honors\",\"parameter\":\"2-p50\"}\n" + // All teams not receiving highest honors or high honors solving the same or more problems than the median scoring team
"{\"id\":\"honors-mention\",\"parameter\":\"p50-p100\"}\n" + // honorable mention for teams
// scoring below 50th percentile
"{\"id\":\"solved-*\"}\n" + // solution awards
"{\"id\":\"group-winner-*\"}"; // group winners

protected Text text;
Expand Down Expand Up @@ -172,4 +173,4 @@ protected void applyAwards(Contest aContest) {
status.setText("Couldn't apply: " + e.getMessage());
}
}
}
}