diff --git a/src/scoreboard b/src/scoreboard index 817384c..dab44c8 100755 --- a/src/scoreboard +++ b/src/scoreboard @@ -1,30 +1,61 @@ #! /usr/bin/awk -f -function output() { +function qsort(A, left, right, i, last) { + if (left >= right) + return + swap(A, left, left+int((right-left+1)*rand())) + last = left + for (i = left+1; i <= right; i++) + if (A[i] < A[left]) + swap(A, ++last, i) + swap(A, left, last) + qsort(A, left, last-1) + qsort(A, last+1, right) +} +function swap(A, i, j, t) { + t = A[i]; A[i] = A[j]; A[j] = t +} + +function escape(s) { + gsub("&", "&", s) + gsub("<", "<", s) + gsub(">", ">", s) + return s +} + +function output( t, c) { for (t in teams) { score = 0; for (c in points_by_cat) { - score += points_by_cat_team[c, t] / points_by_cat[c]; + if (points_by_cat[c] > 0) { + score += points_by_cat_team[c, t] / points_by_cat[c]; + } } if (score > maxscore) { maxscore = score } + if (score > maxscores_by_team[t]) { + maxscores_by_team[t] = score + } scores_by_team_time[t, lasttime] = score } timestamps[tslen++] = lasttime } BEGIN { - # High-contrast colors for accessibility - colors[0] = "e41a1c" - colors[1] = "377eb8" - colors[2] = "4daf4a" - colors[3] = "984ea3" - colors[4] = "ff7f00" - colors[5] = "ffff33" - colors[6] = "a65628" - colors[7] = "f781bf" - + # It took me like 7 hours to find a color palette that worked for + # people with protanopia. Don't change these colors. + colors[0] = "33cc33" + colors[1] = "863a3a" + colors[2] = "5c5ce6" + colors[3] = "bfbf4d" + colors[4] = "408080" + colors[5] = "b336b2" + colors[6] = "ffa500" + colors[7] = "00bfff" + colors[8] = "8db6cd" + ncolors = 9 + # Every 2.5 minutes interval = 150 tslen = 0 @@ -52,34 +83,138 @@ BEGIN { output() + # Get team colors and names + for (team in teams) { + fn = "/var/lib/ctf/teams/colors/" team ".color" + getline colors_by_team[team] < fn + close(fn) + + fn = "/var/lib/ctf/teams/" team + getline names_by_team[team] < fn + close(fn) + } + + # Get team names + width = lasttime - start print "" print "" print "
" print "Overall | " + + # Sort categories + ncats = 0 + for (cat in points_by_cat) { + cats[ncats++] = cat + } + qsort(cats, 0, ncats-1) + + # Print out category names + for (i = 0; i < ncats; i += 1) { + cat = cats[i] + points = points_by_cat[cat] + if (0 == points) continue + printf("%s (%d) | \n", cat, points) + } + print "
---|---|
"
+ print "
| "
+ for (i = 0; i < ncats; i += 1) {
+ cat = cats[i]
+ points = points_by_cat[cat]
+ if (0 == points) break;
+
+ print ""
+
+ # Create sorted list of scores in this category
+ n = 0
+ for (team in teams) {
+ l[n++] = points_by_cat_team[cat, team];
+ }
+ qsort(l, 0, n)
+
+ # Print out teams, ranked by points
+ for (j = n; j > 0; j -= 1) {
+ if (l[j] == l[j-1]) continue;
+ if (0 == l[j]) break;
+ for (team in teams) {
+ points = points_by_cat_team[cat, team]
+ if (l[j] == points) {
+ name = names_by_team[team]
+ printf(" \n",
+ team,
+ 100 * points / points_by_cat[cat],
+ colors_by_team[team])
+ printf(" %s: %d\n",
+ cat, escape(name), points)
+ printf(" \n")
+ }
+ }
+ }
+
+ print " | "
+ }
+ print "