Example #1
0
func (c SecuredApplication) ProgramDiff(programIdString1 string, programIdString2 string) revel.Result {

	programId1, err := strconv.Atoi(programIdString1)
	if err != nil {
		c.Flash.Error("Invalid program id")
		return c.Render(routes.PublicApplication.Index())
	}
	programId2, err := strconv.Atoi(programIdString2)
	if err != nil {
		c.Flash.Error("Invalid program id")
		return c.Render(routes.PublicApplication.Index())
	}

	user := c.connected()

	prog1, err1 := models.FindProgram(int64(programId1))
	prog2, err2 := models.FindProgram(int64(programId2))

	if err1 != nil || err2 != nil {
		return c.RenderText("error")
	}
	mp1, err1 := models.FindMachineProblem(prog1.MachineProblemInstanceId)
	mp2, err2 := models.FindMachineProblem(prog2.MachineProblemInstanceId)
	if err1 != nil || err2 != nil || mp1.Id != mp2.Id || mp1.UserInstanceId != user.Id || mp2.UserInstanceId != user.Id {
		return c.RenderText("error")
	}

	c.RenderArgs["program1"] = prog1
	c.RenderArgs["program2"] = prog2
	return c.Render()
}
Example #2
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()
}
Example #3
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",
	})
}
Example #4
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()
}
Example #5
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()
}
Example #6
0
func (c PublicApplication) SharedAttempt(runId string) revel.Result {
	attempt, err := models.FindAttemptByRunId(runId)
	if err != nil {
		c.Flash.Error("Shared attempt not found.")
		return c.Redirect(routes.PublicApplication.Index())
	}

	mp, err := models.FindMachineProblem(attempt.MachineProblemInstanceId)
	if err != nil {
		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
	}

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

	conf, _ := ReadMachineProblemConfig(mp.Number)

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

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

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

	return c.Render()
}
Example #7
0
func (c AdminApplication) ShowStudentProgram(studentIdString string, mpNumString string, programIdString 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())
	}

	programId, err := strconv.Atoi(programIdString)
	if err != nil {
		c.Flash.Error("Invalid program 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)
	program, _ := models.FindProgram(int64(programId))

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

	return c.Render()
}
Example #8
0
func (c SecuredApplication) Program(programIdString string) revel.Result {

	programId, err := strconv.Atoi(programIdString)
	if err != nil {
		c.Flash.Error("Invalid program id")
		return c.Render(routes.PublicApplication.Index())
	}

	user := c.connected()

	prog, err := models.FindProgram(int64(programId))
	if err != nil {
		return c.RenderText("error")
	}
	mp, err := models.FindMachineProblem(prog.MachineProblemInstanceId)
	if err != nil || mp.UserInstanceId != user.Id {
		return c.RenderText("error")
	} else {
		c.RenderArgs["program"] = prog
		return c.Render()
	}
}
Example #9
0
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
	}
}
Example #10
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()
}
Example #11
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()
}
Example #12
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()
}
Example #13
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()
}