Fixes #1765; csv grade export messed up

@jbau please.

Re-written to conform to new tables.