1
0
Fork 0
mirror of https://github.com/dirtbags/moth.git synced 2025-01-05 11:30:41 -07:00
moth/bin/points
2015-05-28 11:40:41 -06:00

46 lines
612 B
Awk
Executable file

#! /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[hash] < ("state/teams/" hash)
}
if (NR > 1) {
# JSON sucks.
print ",";
}
printf("[%d, \"%s\", \"%s\", %d]", ts, hash, cat, points);
}
END {
print "";
print " ],";
print " \"teams\": {";
i = 0
for (hash in teamnames) {
if (i++) {
print ",";
}
printf("\"%s\": \"%s\"", hash, teamnames[hash]);
}
print "";
print " }";
print "}";
}