diff --git a/rank.awk b/rank.awk index 6522a02..ee9615d 100755 --- a/rank.awk +++ b/rank.awk @@ -75,6 +75,7 @@ END { printf("" reason[me] ""); printf("" lasterr[me] ""); printf("\n"); + printf("\n"); } } } diff --git a/summary.awk b/summary.awk index c44b340..77fbde5 100755 --- a/summary.awk +++ b/summary.awk @@ -9,6 +9,7 @@ function esc(s) { BEGIN { ngames = 20; + getline rounds < "next-round"; print ""; print ""; @@ -22,59 +23,46 @@ BEGIN { print "

New here? Read the introduction.

"; print "

New round every minute.

"; print "

Rankings

"; - print "

Over the last 20 games only.

"; + print "

Over the last " ngames" games only.

"; print "
    "; - for (i = 1; i < ARGC; i += 1) { - id = ARGV[i]; + for (i = rounds - ngames - 1; i < rounds; i += 1) { + fn = sprintf("round-%04d.html", i) + while (getline < fn) { + if ($2 == "score") { + scores[$3] += $4 + if (scores[$3] > topscore) { + topscore = scores[$3] + } + } + } + } + for (id in scores) { if (1 == getline < (id "/name")) { - names[id] = esc($0); + names[id] = esc($0) } else { - names[id] = "Unnamed"; + names[id] = "Unnamed" } - getline < (id "/color"); + getline < (id "/color") if (/^#[0-9A-Fa-f]+$/) { - color[id] = $0; + color[id] = $0 } else { - color[id] = "#c0c0c0"; - } - - - for (j = 0; 1 == getline < (id "/points"); j += 1) { - pts[id, j % ngames] = int($0); - } - total = 0; - for (j = 0; j < ngames; j += 1) { - total += pts[id, j]; - } - scores[total] = total; - points[id] = total; - } - while (1) { - # Find highest score - maxscore = -1; - for (p in scores) { - if (int(p) > maxscore) { - maxscore = int(p); - } - } - if (maxscore == -1) { - break; - } - delete scores[maxscore]; - - for (id in points) { - if (points[id] == maxscore) { - printf("
  1. # %s (%d points)
  2. \n", color[id], names[id], points[id]); - } + color[id] = "#c0c0c0" } } + + for (s = topscore; s >= 0; s -= 1) { + for (id in scores) { + if (scores[id] == s) { + printf("
  3. # %s (%d points)
  4. \n", color[id], names[id], scores[id]); + } + } + } print "
"; print "

Rounds

"; print "