mirror of https://github.com/dirtbags/moth.git
fix weighting bug with sandia tokens
This commit is contained in:
parent
ab838fb8a4
commit
038e707301
|
@ -8,152 +8,151 @@
|
||||||
##
|
##
|
||||||
|
|
||||||
function qsort(A, left, right, i, last) {
|
function qsort(A, left, right, i, last) {
|
||||||
if (left >= right)
|
if (left >= right)
|
||||||
return
|
return
|
||||||
swap(A, left, left+int((right-left+1)*rand()))
|
swap(A, left, left+int((right-left+1)*rand()))
|
||||||
last = left
|
last = left
|
||||||
for (i = left+1; i <= right; i++)
|
for (i = left+1; i <= right; i++)
|
||||||
if (A[i] < A[left])
|
if (A[i] < A[left])
|
||||||
swap(A, ++last, i)
|
swap(A, ++last, i)
|
||||||
swap(A, left, last)
|
swap(A, left, last)
|
||||||
qsort(A, left, last-1)
|
qsort(A, left, last-1)
|
||||||
qsort(A, last+1, right)
|
qsort(A, last+1, right)
|
||||||
}
|
}
|
||||||
function swap(A, i, j, t) {
|
function swap(A, i, j, t) {
|
||||||
t = A[i]; A[i] = A[j]; A[j] = t
|
t = A[i]; A[i] = A[j]; A[j] = t
|
||||||
}
|
}
|
||||||
|
|
||||||
function escape(s) {
|
function escape(s) {
|
||||||
gsub("&", "&", s)
|
gsub("&", "&", s)
|
||||||
gsub("<", "<", s)
|
gsub("<", "<", s)
|
||||||
gsub(">", ">", s)
|
gsub(">", ">", s)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
function head() {
|
function head() {
|
||||||
print "<!DOCTYPE html>"
|
print "<!DOCTYPE html>"
|
||||||
print "<html><head><title>Project 2 Scoreboard</title>"
|
print "<html><head><title>Project 2 Scoreboard</title>"
|
||||||
print "<meta http-equiv=\"refresh\" content=\"60\">"
|
print "<meta http-equiv=\"refresh\" content=\"60\">"
|
||||||
print "<link rel=\"stylesheet\" href=\"ctf.css\" type=\"text/css\">"
|
print "<link rel=\"stylesheet\" href=\"ctf.css\" type=\"text/css\">"
|
||||||
print "<style>"
|
print "<style>"
|
||||||
print "body {opacity: 0.9; margin: 0; padding: 0; max-width: inherit;}"
|
print "body {opacity: 0.9; margin: 0; padding: 0; max-width: inherit;}"
|
||||||
print "p {margin: 0; padding:0; line-height: inherit;}"
|
print "p {margin: 0; padding:0; line-height: inherit;}"
|
||||||
print "span {display: inline-block; margin: 0; border: 0; padding: 0;}"
|
print "span {display: inline-block; margin: 0; border: 0; padding: 0;}"
|
||||||
print ".cat0 {background-color: #a6cee3; color: black;}"
|
print ".cat0 {background-color: #a6cee3; color: black;}"
|
||||||
print ".cat1 {background-color: #1f78b4;}"
|
print ".cat1 {background-color: #1f78b4;}"
|
||||||
print ".cat2 {background-color: #b2df8a; color: black;}"
|
print ".cat2 {background-color: #b2df8a; color: black;}"
|
||||||
print ".cat3 {background-color: #33a02c;}"
|
print ".cat3 {background-color: #33a02c;}"
|
||||||
print ".cat4 {background-color: #fb9a99;}"
|
print ".cat4 {background-color: #fb9a99;}"
|
||||||
print ".cat5 {background-color: #e31a1c;}"
|
print ".cat5 {background-color: #e31a1c;}"
|
||||||
print ".cat6 {background-color: #fdbf6f;}"
|
print ".cat6 {background-color: #fdbf6f;}"
|
||||||
print ".cat7 {background-color: #ff7f00;}"
|
print ".cat7 {background-color: #ff7f00;}"
|
||||||
print ".cat8 {background-color: #cab2d6;}"
|
print ".cat8 {background-color: #cab2d6;}"
|
||||||
|
|
||||||
print ".name {position: absolute; right: 10px;}"
|
print ".name {position: absolute; right: 10px;}"
|
||||||
print "#scores p {margin: 0; padding: 0; border: thin solid #222; opacity: 0.92;}"
|
print "#scores p {margin: 0; padding: 0; border: thin solid #222; opacity: 0.92;}"
|
||||||
print "#scores p:hover {border: thin solid yellow;}"
|
print "#scores p:hover {border: thin solid yellow;}"
|
||||||
print "</style>"
|
print "</style>"
|
||||||
print "</head><body>"
|
print "</head><body>"
|
||||||
print "<div id=\"scores\">"
|
print "<div id=\"scores\">"
|
||||||
}
|
}
|
||||||
|
|
||||||
function foot() {
|
function foot() {
|
||||||
|
|
||||||
|
|
||||||
print " </div>"
|
print " </div>"
|
||||||
print " </body>"
|
print " </body>"
|
||||||
print "</body></html>"
|
print "</body></html>"
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
base = ENVIRON["CTF_BASE"]
|
base = ENVIRON["CTF_BASE"]
|
||||||
if (! base) {
|
if (! base) {
|
||||||
base = "/var/lib/ctf"
|
base = "/var/lib/ctf"
|
||||||
}
|
}
|
||||||
|
|
||||||
head()
|
head()
|
||||||
}
|
}
|
||||||
|
|
||||||
# MAINLOOP
|
# MAINLOOP
|
||||||
{
|
{
|
||||||
time = $1
|
time = $1
|
||||||
hash = $2
|
hash = $2
|
||||||
cat = $3
|
cat = $3
|
||||||
points = int($4)
|
points = int($4)
|
||||||
|
|
||||||
# Build a list of team names
|
# Build a list of team names
|
||||||
if (! (hash in team_names)) {
|
if (! (hash in team_names)) {
|
||||||
fn = sprintf("%s/state/teams/names/%s", base, hash)
|
fn = sprintf("%s/state/teams/names/%s", base, hash)
|
||||||
getline team_names[hash] < fn
|
getline team_names[hash] < fn
|
||||||
close(fn)
|
close(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Total points possible so far in this category
|
# Enumerate categories
|
||||||
if (! ((cat, points) in cat_pointval)) {
|
if (! (cat in seen_cats)) {
|
||||||
cat_total[cat] += points
|
seen_cats[cat] = 1
|
||||||
cat_pointval[cat, points] = 1
|
categories[ncats++] = cat
|
||||||
}
|
}
|
||||||
|
|
||||||
# Enumerate categories
|
# Points this team has in this category
|
||||||
if (! (cat in seen_cats)) {
|
cat_points[hash, cat] += points
|
||||||
seen_cats[cat] = 1
|
|
||||||
categories[ncats++] = cat
|
|
||||||
}
|
|
||||||
|
|
||||||
# Points this team has in this category
|
# Token-based categories can make cat_pointval irrelevant
|
||||||
cat_points[hash, cat] += points
|
if (cat_points[hash, cat] > cat_total[cat]) {
|
||||||
|
cat_total[cat] = cat_points[hash, cat]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
END {
|
END {
|
||||||
# Adjust per-category points to a per-category percentage complete
|
# Adjust per-category points to a per-category percentage complete
|
||||||
for (hash in team_names) {
|
for (hash in team_names) {
|
||||||
for (cat in cat_total) {
|
for (cat in cat_total) {
|
||||||
cat_score[hash, cat] = cat_points[hash, cat] / cat_total[cat]
|
cat_score[hash, cat] = cat_points[hash, cat] / cat_total[cat]
|
||||||
total_score[hash] += cat_score[hash, cat]
|
total_score[hash] += cat_score[hash, cat]
|
||||||
}
|
}
|
||||||
scores[nteams++] = total_score[hash]
|
scores[nteams++] = total_score[hash]
|
||||||
if (total_score[hash] > max_score) {
|
if (total_score[hash] > max_score) {
|
||||||
max_score = total_score[hash]
|
max_score = total_score[hash]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sort scores
|
# Sort scores
|
||||||
qsort(scores, 0, nteams-1)
|
qsort(scores, 0, nteams-1)
|
||||||
|
|
||||||
print "<p>"
|
print "<p>"
|
||||||
for (ncat = 0; ncat < ncats; ncat += 1) {
|
for (ncat = 0; ncat < ncats; ncat += 1) {
|
||||||
printf("<span class=\"cat%d\">%s</span>\n", ncat, categories[ncat]);
|
printf("<span class=\"cat%d\">%s</span>\n", ncat, categories[ncat]);
|
||||||
}
|
}
|
||||||
print "</p>"
|
print "</p>"
|
||||||
|
|
||||||
for (i = nteams-1; i >= 0; i -= 1) {
|
for (i = nteams-1; i >= 0; i -= 1) {
|
||||||
score = scores[i];
|
score = scores[i];
|
||||||
if (score == scores[i-1]) continue; # Skip duplicates
|
if (score == scores[i-1]) continue; # Skip duplicates
|
||||||
|
|
||||||
for (hash in team_names) {
|
for (hash in team_names) {
|
||||||
if (total_score[hash] != score) {
|
if (total_score[hash] != score) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = escape(team_names[hash])
|
name = escape(team_names[hash])
|
||||||
print "<p>"
|
print "<p>"
|
||||||
printf("<span class=\"name\">%s</span>\n", name)
|
printf("<span class=\"name\">%s</span>\n", name)
|
||||||
|
|
||||||
for (ncat = 0; ncat < ncats; ncat += 1) {
|
for (ncat = 0; ncat < ncats; ncat += 1) {
|
||||||
cat = categories[ncat];
|
cat = categories[ncat];
|
||||||
points = cat_points[hash, cat];
|
points = cat_points[hash, cat];
|
||||||
|
|
||||||
if (cat_points[hash, cat] > 0) {
|
if (cat_points[hash, cat] > 0) {
|
||||||
width = cat_score[hash, cat] / max_score * 90
|
width = cat_score[hash, cat] / max_score * 90
|
||||||
printf("<!-- %s %s %s -->", cat, points, name)
|
printf("<!-- %s %s %s -->", cat, points, name)
|
||||||
printf("<span class=\"cat%d\" style=\"width: %.2f%%;\">%d</span>",
|
printf("<span class=\"cat%d\" style=\"width: %.2f%%;\">%d</span>",
|
||||||
ncat, width, cat_points[hash, cat])
|
ncat, width, cat_points[hash, cat])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print "</p>"
|
print "</p>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foot()
|
foot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue