submission_history: add more sanity checks

The StudentModuleHistory db entries are filled with incomplete/invalid
entries. Add more checks to ensure the state is complete with attempts,
correct_map, and student_answers and ensure that both grade and
max_grade are not null. There are also some entries whose score doesn't
match the correct_map which we filter by manually counting the
'correctness'='correct' entries in the correct_map and comparing that to
the grade.