func (c AdminApplication) ShowStudentAttempts(studentIdString string, mpNumString string) revel.Result { studentId, err := strconv.Atoi(studentIdString) if err != nil { c.Flash.Error("Invalid user Id") return c.Render(routes.PublicApplication.Index()) } mpNum, err := strconv.Atoi(mpNumString) if err != nil { c.Flash.Error("Invalid mp Id") return c.Render(routes.PublicApplication.Index()) } admin := c.connected() if !models.IsAdmin(admin) { c.Flash.Error("No admin privilages") return c.Render(routes.PublicApplication.Index()) } student, err := models.FindUser(int64(studentId)) if err != nil { c.Flash.Error("Cannot find user") return c.Render(routes.PublicApplication.Index()) } mp, _ := models.FindMachineProblemByUser(student, mpNum) attempts, _ := models.FindAttemptsByMachineProblem(mp) c.RenderArgs["mp_num"] = mpNum c.RenderArgs["mp"] = mp c.RenderArgs["student"] = student c.RenderArgs["attempts"] = attempts return c.Render() }
func getAttemptsSummary(user models.User, mp models.MachineProblem) []attemptSummary { attempts, err := models.FindAttemptsByMachineProblem(mp) if err != nil { return nil } else { attemptListSummary := make([]attemptSummary, len(attempts)) for i, attempt := range attempts { progId := attempt.ProgramInstanceId prog, _ := models.FindProgram(progId) attemptListSummary[i] = attemptSummary{ Id: attempts[i].Id, Snippet: summarizeProgram(prog.Text), Status: attemptFailed(attempt), StatusMessage: attemptFailedMessage(attempt), AlertTag: attemptAlertTag(attempt), DatasetId: attempt.DatasetId, Created: attempt.Created, } } return attemptListSummary } }