Esempio n. 1
0
func (c AdminApplication) ShowStudentGrade(studentIdString string, mpNumString string, gradeIdString 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())
	}
	gradeId, err := strconv.Atoi(gradeIdString)
	if err != nil {
		c.Flash.Error("Invalid grade 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)
	grade, _ := models.FindGrade(int64(gradeId))
	attempt, _ := models.FindAttempt(grade.AttemptInstanceId)
	program, _ := models.FindProgram(attempt.ProgramInstanceId)
	qs, _ := models.FindQuestionsByMachineProblem(mp)
	qis, _ := models.FindQuestionItems(mp, qs)

	c.RenderArgs["mp_num"] = mpNum
	c.RenderArgs["mp"] = mp
	c.RenderArgs["student"] = student
	c.RenderArgs["grade"] = grade
	c.RenderArgs["attempt"] = attempt
	c.RenderArgs["program"] = program
	c.RenderArgs["questions"] = qis
	bg, err := getBigCodeSuggestion(mpNum, program)
	if err != nil {
		revel.INFO.Println("Failed to get big code suggestion  :::  ", err)
	} else {
		revel.INFO.Println("Got bigcode suggestions")
		c.RenderArgs["bigcode"] = bg
		c.RenderArgs["bigcode_min"] = bg[0]
		c.RenderArgs["bigcode_max"] = bg[1]
		c.RenderArgs["bigcode_random"] = bg[2]
	}

	return c.Render()
}
Esempio n. 2
0
func (c SecuredApplication) ComputeGrade(attemptIdString string) revel.Result {

	attemptId, err := strconv.Atoi(attemptIdString)
	if err != nil {
		c.Flash.Error("Invalid attempt Id")
		return c.Render(routes.PublicApplication.Index())
	}

	attempt, err := models.FindAttempt(int64(attemptId))
	if err != nil || attempt.Id == 0 {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Failed to grade machine problem",
			"data":   "Cannot find attempt " + attemptIdString + ".",
		})
	}

	mp, err := models.FindMachineProblem(attempt.MachineProblemInstanceId)
	if err != nil || mp.Id == 0 {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Failed to grade",
			"data":   "Cannot find machine problem instance.",
		})
	}

	user := c.connected()

	if mp.UserInstanceId != user.Id {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Failed to grade",
			"data":   "Invalid user.",
		})
	}

	runId := generateRunId(user)

	conf, _ := ReadMachineProblemConfig(mp.Number)

	stats.Incr("App", "GradeSubmission")

	prog, _ := models.FindProgram(attempt.ProgramInstanceId)
	server.SubmitProgram(mp, prog.Text, -1, conf.Language, runId, true)

	return c.RenderJson(map[string]interface{}{
		"status":  "success",
		"mpId":    strconv.Itoa(int(mp.Id)),
		"runId":   runId,
		"attempt": "Grade submitted",
	})
}
Esempio n. 3
0
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()
}
Esempio n. 4
0
func (c AdminApplication) ShowStudentAttempt(studentIdString string, mpNumString string, attemptIdString 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())
	}
	attemptId, err := strconv.Atoi(attemptIdString)
	if err != nil {
		c.Flash.Error("Invalid attempt 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)
	attempt, _ := models.FindAttempt(int64(attemptId))
	program, _ := models.FindProgram(attempt.ProgramInstanceId)
	qs, _ := models.FindQuestionsByMachineProblem(mp)
	qis, _ := models.FindQuestionItems(mp, qs)

	c.RenderArgs["mp_num"] = mpNum
	c.RenderArgs["mp"] = mp
	c.RenderArgs["student"] = student
	c.RenderArgs["attempt"] = attempt
	c.RenderArgs["program"] = program
	c.RenderArgs["questions"] = qis

	return c.Render()
}
Esempio n. 5
0
func (c SecuredApplication) GradeRunInformation(attemptIdString string, runIdString string) revel.Result {

	attemptId, err := strconv.Atoi(attemptIdString)
	if err != nil {
		c.Flash.Error("Invalid attempt Id")
		return c.Render(routes.PublicApplication.Index())
	}

	user := c.connected()

	attempt, err := models.FindAttempt(int64(attemptId))
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error-not-found",
			"title":  "Did not finish running attempt.",
			"data": "Cannot find attempt with attempt id = " +
				attemptIdString + " ... " +
				fmt.Sprint(err),
		})
	}

	mp, err := models.FindMachineProblem(attempt.MachineProblemInstanceId)
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error-not-found",
			"title":  "Did not finish running attempt.",
			"data": "Cannot find mp with mp id = " +
				fmt.Sprint(attempt.MachineProblemInstanceId, " .... ", err),
		})
	}

	grade, err := models.FindGradeByRunId(runIdString)
	if err != nil {
		//revel.TRACE.Println("did not find grade...")
		return c.RenderJson(map[string]interface{}{
			"status": "error-not-found",
			"title":  "Did not finish running attempt.",
			"data": "Cannot find mp with grade with runid  = " +
				runIdString + " ... " + fmt.Sprint(err),
		})
	}

	if !models.AllGraded(grade) {
		//revel.TRACE.Println("not all graded...")
		return c.RenderJson(map[string]interface{}{
			"status": "error-not-found",
			"title":  "Did not finish grading.",
			"data":   "Cannot display incomplete grade for mp = " + strconv.Itoa(int(mp.Number)),
		})
	} else if err := doPostCourseraGrade(user, mp, grade, "code", false); err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "success",
			"title":  "Info: Did not save grade to Coursera.",
			"data":   "Make sure you are connected to Coursera",
			"id":     grade.Id,
		})
	}

	grade, err = models.FindGradeByRunId(runIdString)

	return c.RenderJson(map[string]interface{}{
		"status": "success",
		"data":   grade,
		"id":     grade.Id,
	})
}
Esempio n. 6
0
func (c SecuredApplication) Grade(gradeIdString string) revel.Result {

	gradeId, err := strconv.Atoi(gradeIdString)
	if err != nil {
		c.Flash.Error("Invalid grade Id")
		return c.Render(routes.PublicApplication.Index())
	}

	grade, err := models.FindGrade(int64(gradeId))
	if err != nil {
		c.Flash.Error("Invalid grade Id")
		return c.Render(routes.PublicApplication.Index())
	}

	attempt, err := models.FindAttempt(grade.AttemptInstanceId)
	if err != nil || attempt.Id == 0 {
		c.Flash.Error("Invalid attempt")
		return c.Render(routes.PublicApplication.Index())
	}

	mp, err := models.FindMachineProblem(attempt.MachineProblemInstanceId)
	if err != nil {
		c.Flash.Error("Invalid mp")
		return c.Render(routes.PublicApplication.Index())
	}

	c.RenderArgs["grade"] = grade
	if grade.Reasons != "" {
		c.RenderArgs["reasons"] = strings.Split(grade.Reasons, ",")
	}

	c.RenderArgs["mp"] = mp

	conf, _ := ReadMachineProblemConfig(mp.Number)
	c.RenderArgs["title"] = conf.Name + " Grade"

	c.RenderArgs["grade"] = grade

	if qs, err := models.FindQuestionsByMachineProblem(mp); err == nil {
		if q, err := models.FindQuestionItems(mp, qs); err == nil {
			c.RenderArgs["questions"] = q
		}
	}

	c.RenderArgs["attempt"] = attempt

	if prog, err := models.FindProgram(attempt.ProgramInstanceId); err == nil {
		c.RenderArgs["program"] = prog

		conf, _ := ReadMachineProblemConfig(mp.Number)
		if MachineProblemCodingDeadlineExpiredQ(conf) {
			bg, err := getBigCodeSuggestion(mp.Number, prog)
			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["Program"] = prog
				c.RenderArgs["mp_config"] = conf
				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"
				}
			}
		}
	}

	if grade.PeerReviewScore > 0 {
		if pr, err := models.FindPeerReviewsWithGrade(grade); err == nil {
			c.RenderArgs["peer_reviews"] = pr
		}
	}

	return c.Render()
}
Esempio n. 7
0
func (c SecuredApplication) Attempt(attemptIdString string) revel.Result {

	attemptId, err := strconv.Atoi(attemptIdString)
	if err != nil {
		c.Flash.Error("Invalid attempt Id")
		return c.Render(routes.PublicApplication.Index())
	}

	user := c.connected()

	attempt, err := models.FindAttempt(int64(attemptId))
	if err != nil {
		c.Flash.Error("Cannot query attempt id")
		return c.Render(routes.PublicApplication.Index())
	}

	mp, err := models.FindMachineProblem(attempt.MachineProblemInstanceId)
	if err != nil || mp.UserInstanceId != user.Id {
		c.Flash.Error("Cannot query attempt id")
		return c.Render(routes.PublicApplication.Index())
	}

	attempt_c_data := new(server.InternalCData)

	if err := json.Unmarshal([]byte(attempt.InternalCData), attempt_c_data); err == nil {
		c.RenderArgs["attempt_c_data"] = attempt_c_data
	}

	conf, _ := ReadMachineProblemConfig(mp.Number)
	if !MachineProblemCodingDeadlineExpiredQ(conf) {
		c.RenderArgs["show_grade_button"] = true
	}

	prog, err := models.FindProgram(attempt.ProgramInstanceId)
	if err != nil {
		c.Flash.Error("Cannot find program.")
		return c.Render(routes.PublicApplication.Index())
	}

	c.RenderArgs["mp"] = mp
	c.RenderArgs["title"] = conf.Name + " Attempt"

	c.RenderArgs["mp_config"] = conf
	c.RenderArgs["attempt"] = attempt
	c.RenderArgs["program"] = prog

	qs, err := models.FindQuestionsByMachineProblem(mp)
	if err != nil {
		c.Flash.Error("Invalid questions")
		return c.Render(routes.PublicApplication.Index())
	}

	q, err := models.FindQuestionItems(mp, qs)
	if err != nil {
		c.Flash.Error("Invalid question items")
		return c.Render(routes.PublicApplication.Index())
	} else {
		c.RenderArgs["questions"] = q
	}

	if attemptFailed(attempt) {
		c.RenderArgs["status"] = attemptFailedMessage(attempt)
	} else {
		c.RenderArgs["status"] = "Correct solution for this dataset."
	}

	return c.Render()
}
Esempio n. 8
0
func (c SecuredApplication) PeerReview(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())
	}

	conf, _ := ReadMachineProblemConfig(mpNum)

	c.RenderArgs["mp_config"] = conf
	c.RenderArgs["title"] = conf.Name + " Peer Review"

	if MachineProblemPeerReviewDeadlineExpiredQ(conf) {
		c.RenderArgs["past_deadline"] = true
	} else if MachineProblemCodingDeadlineExpiredQ(conf) {

		reviews, err := models.GetPeerReviewsByReviewerAndMachineProblem(user, mp)

		if err != nil || len(reviews) < 3 {
			ii := 0
			for len(reviews) < 3 && ii < 100 {
				if rev, err := models.CreatePeerReviewWithReviewerAndMachineProblem(user, mp); err == nil {
					reviews = append(reviews, rev)
				}
				ii++
			}
		}

		type reviewT struct {
			Index         int
			Review        models.PeerReview
			Questions     models.Questions
			QuestionItems []models.QuestionItem
			Program       models.Program
		}

		var res []reviewT

		for _, r := range reviews {
			if grade, err := models.FindGrade(r.GradeInstanceId); err == nil {
				if attempt, err := models.FindAttempt(grade.AttemptInstanceId); err == nil {
					program, _ := models.FindProgram(attempt.ProgramInstanceId)
					tmp, _ := models.FindMachineProblem(grade.MachineProblemId)
					q, _ := models.FindQuestionsByMachineProblem(tmp)
					qs, _ := models.FindQuestionItems(mp, q)
					k := reviewT{
						Index:         len(res) + 1,
						Review:        r,
						Questions:     q,
						QuestionItems: qs,
						Program:       program,
					}
					res = append(res, k)
				}
			}
		}

		c.RenderArgs["reviews"] = res
	} else {
		c.RenderArgs["still_coding"] = true
	}

	return c.Render()
}
Esempio n. 9
0
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()
}