func (c AdminApplication) ShowAllStudentsMachineProblems(mpNumString string) revel.Result { 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()) } conf, _ := ReadMachineProblemConfig(mpNum) students, err := models.FindUsersByMachineProblemNumber(mpNum) if err != nil { c.Flash.Error("Invalid mp number") return c.Render(routes.PublicApplication.Index()) } class_roster := make([]studentRecord, len(students)) for idx, student := range students { mp, _ := models.FindMachineProblemByUser(student, mpNum) grade, _ := models.FindGradeByMachineProblem(mp) attempt, _ := models.FindAttempt(grade.AttemptInstanceId) program, _ := models.FindProgram(attempt.ProgramInstanceId) qs, _ := models.FindQuestionsByMachineProblem(mp) qis, _ := models.FindQuestionItems(mp, qs) class_roster[idx] = studentRecord{ Id: student.Id, Student: student, MachineProblem: mp, Questions: qis, Grade: grade, Program: program, Attempt: attempt, } } c.RenderArgs["admin"] = admin c.RenderArgs["mp_num"] = mpNum c.RenderArgs["mp_config"] = conf c.RenderArgs["class_roster"] = class_roster return c.Render() }
func (c AdminApplication) ExportMachineProblemsGradesToCSV(mpNumString string) revel.Result { mpNum, err := strconv.Atoi(mpNumString) if err != nil { c.Flash.Error("Invalid mp Id") return c.Render(routes.PublicApplication.Index()) } user := c.connected() if !models.IsAdmin(user) { c.Flash.Error("No admin privilages") return c.Render(routes.PublicApplication.Index()) } students, err := models.FindUsersByMachineProblemNumber(mpNum) if err != nil { c.Flash.Error("Invalid mp number") return c.Render(routes.PublicApplication.Index()) } csv := make([]string, len(students)+1) csv[0] = "username,email,mp_num,code_grade,questions_grade,total_grade,updated" for idx, student := range students { mp, _ := models.FindMachineProblemByUser(student, mpNum) grade, _ := models.FindGradeByMachineProblem(mp) csv[idx+1] = strings.Join([]string{ student.UserName, student.Email, strconv.Itoa(mpNum), strconv.Itoa(int(grade.CodeScore)), strconv.Itoa(int(grade.PeerReviewScore)), strconv.Itoa(int(grade.TotalScore)), grade.Updated.Format(time.RFC3339), }, ",") } return c.RenderText(strings.Join(csv, "\n")) }
func (c SecuredApplication) ShowGrade(mpNumString string) revel.Result { mpNum, err := strconv.Atoi(mpNumString) if err != nil { c.Flash.Error("Invalid mp Id") return c.Render(routes.PublicApplication.Index()) } user := c.connected() mp, err := models.FindOrCreateMachineProblemByUser(user, mpNum) if err != nil { c.Flash.Error("Invalid mp Id") return c.Render(routes.PublicApplication.Index()) } grade, err := models.FindGradeByMachineProblem(mp) if err != nil { c.Flash.Error("Invalid grade Id") return c.Render(routes.PublicApplication.Index()) } return c.Grade(strconv.Itoa(int(grade.Id))) }
func (c AdminApplication) ShowStudentMachineProblem(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()) } conf, _ := ReadMachineProblemConfig(mpNum) 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) grade, _ := models.FindGradeByMachineProblem(mp) attempt, _ := models.FindAttempt(grade.AttemptInstanceId) program, _ := models.FindProgram(attempt.ProgramInstanceId) qs, _ := models.FindQuestionsByMachineProblem(mp) qis, _ := models.FindQuestionItems(mp, qs) c.RenderArgs["admin"] = admin c.RenderArgs["mp_num"] = mpNum c.RenderArgs["mp_config"] = conf c.RenderArgs["student"] = student c.RenderArgs["mp"] = mp c.RenderArgs["attempt"] = attempt c.RenderArgs["program"] = program c.RenderArgs["questions"] = qis c.RenderArgs["grade"] = grade bg, err := getBigCodeSuggestion(mpNum, program) if err != nil { revel.INFO.Println("Failed to get big code suggestion ::: ", err) } else if len(bg) != 3 { revel.INFO.Println("The number of suggestions recieved was ::: ", len(bg), " was expecting 3") } else { //revel.INFO.Println("Got bigcode suggestions") //revel.INFO.Println("min = ", bg[0]) c.RenderArgs["bigcode"] = bg c.RenderArgs["bigcode_min"] = bg[0] c.RenderArgs["bigcode_max"] = bg[1] c.RenderArgs["bigcode_random"] = bg[2] randomSelection := rand.Intn(3) switch randomSelection { case 0: c.RenderArgs["bigcode_min_active"] = "active" c.RenderArgs["bigcode_max_active"] = "" c.RenderArgs["bigcode_random_active"] = "" case 1: c.RenderArgs["bigcode_min_active"] = "" c.RenderArgs["bigcode_max_active"] = "active" c.RenderArgs["bigcode_random_active"] = "" case 2: c.RenderArgs["bigcode_min_active"] = "" c.RenderArgs["bigcode_max_active"] = "" c.RenderArgs["bigcode_random_active"] = "active" } } return c.Render() }
func (c AdminApplication) MachineProblemClassRoster(mpNumString, startIdxString, endIdxString string) revel.Result { mpNum, err := strconv.Atoi(mpNumString) if err != nil { c.Flash.Error("Invalid mp Id") return c.Render(routes.PublicApplication.Index()) } startIdx, err := strconv.Atoi(startIdxString) if err != nil { c.Flash.Error("Invalid start index") return c.Render(routes.PublicApplication.Index()) } endIdx, err := strconv.Atoi(endIdxString) if err != nil { c.Flash.Error("Invalid end index") 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()) } conf, _ := ReadMachineProblemConfig(mpNum) c.RenderArgs["admin"] = admin c.RenderArgs["mp_num"] = mpNum c.RenderArgs["mp_config"] = conf students, err := models.FindUsersByMachineProblemNumber(mpNum) if err != nil { c.Flash.Error("Invalid mp number") return c.Render(routes.PublicApplication.Index()) } if startIdx < 0 { startIdx = 0 } if endIdx > len(students) || endIdx == 0 { endIdx = len(students) } students = students[startIdx:endIdx] class_roster := make([]studentRecord, len(students)) for idx, student := range students { mp, _ := models.FindMachineProblemByUser(student, mpNum) grade, _ := models.FindGradeByMachineProblem(mp) //qs, _ := models.FindQuestionsByMachineProblem(mp) //qis, _ := models.FindQuestionItems(mp, qs) class_roster[idx] = studentRecord{ Id: student.Id, Student: student, MachineProblem: mp, //Questions: qis, Grade: grade, } } c.RenderArgs["class_roster"] = class_roster return c.Render() }