moth/bin/points

45 lines
593 B
Plaintext
Raw Normal View History

2015-04-08 17:28:18 -06:00
#! /usr/bin/awk -f
BEGIN {
nteams = 0;
print "{";
print " \"points\": [";
}
{
ts = $1;
hash = $2;
cat = $3;
points = $4;
teamno = teams[hash];
if (! teamno) {
teamno = ++nteams;
teams[hash] = teamno;
getline teamnames[teamno] < ("state/teams/" hash)
}
if (NR > 1) {
# JSON sucks.
print ",";
}
printf("[%d, \"%d\", \"%s\", %d]", ts, teamno, cat, points);
}
END {
print "";
print " ],";
print " \"teams\": {";
for (i in teamnames) {
if (i > 1) {
print ",";
}
printf("\"%d\": \"%s\"", i, teamnames[i]);
}
print "";
print " }";
print "}";
}