Ejemplo n.º 1
0
func (c AdminApplication) ShowStudentGrades(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)
	grades, _ := models.FindGradesByMachineProblem(mp)

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

	return c.Render()
}
Ejemplo n.º 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()
}
Ejemplo 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()
}
Ejemplo 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()
}
Ejemplo n.º 5
0
func (c PublicApplication) connected() models.User {
	var user models.User
	//revel.TRACE.Println(c.Action)
	if val, ok := c.RenderArgs["user"]; ok && val.(models.User).Id != 0 {
		user = val.(models.User)
	} else if username, ok := c.Session["user"]; ok && username != "" {
		user = c.getUser(username)
		c.RenderArgs["user"] = user
	}
	if user.Id != 0 {
		c.RenderArgs["is_ece408_student"] = models.IsECE408Student(user)
		c.RenderArgs["is_ece598_student"] = models.IsECE598Student(user)
		c.RenderArgs["is_ece408_admin"] = models.IsECE408Admin(user)
		c.RenderArgs["is_ece598_admin"] = models.IsECE598Admin(user)
		c.RenderArgs["is_admin"] = models.IsAdmin(user)
	} /* else {
	    revel.TRACE.Println("not able to find check for = " + user.UserName)
	    revel.TRACE.Println("response from " + c.Request.RemoteAddr)
	}*/
	return user
}
Ejemplo n.º 6
0
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"))
}
Ejemplo n.º 7
0
func (c AdminApplication) UpdateStudentMachineProblem(studentIdString string, mpNumString string) revel.Result {
	type gradeInformation struct {
		CodeScore           int64  `json:"code_score"`
		CodeInspectionScore int64  `json:"code_inspection_score"`
		CodeComment         string `json:"code_comment"`
		QuestionsScore      int64  `json:"questions_score"`
		QuestionsComment    string `json:"questions_comment"`
		TaCodeText          string `json:"ta_code_text"`
	}
	var gradeUpdate gradeInformation
	var gradeString string

	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())
	}

	student, err := models.FindUser(int64(studentId))
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "No user found",
			"data":   "Cannot find user.",
			"error":  err,
		})
	}

	admin := c.connected()
	if !models.IsAdmin(admin) {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "No admin privilages",
			"data":   "Cannot perform request because of lack of admin privilages.",
			"error":  "",
		})
	}

	c.Params.Bind(&gradeString, "grade")
	if err := json.Unmarshal([]byte(gradeString), &gradeUpdate); err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot parse grade update request.",
			"data":   "The system was not able to parse your grade update request.",
			"error":  err,
		})
	}

	mp, _ := models.FindMachineProblemByUser(student, mpNum)

	if _, err := models.UpdateGradeTA(mp, gradeUpdate.CodeScore, gradeUpdate.CodeInspectionScore,
		gradeUpdate.QuestionsScore, gradeUpdate.CodeComment, gradeUpdate.QuestionsComment,
		gradeUpdate.TaCodeText); err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Not able to update the database",
			"data":   "Cannot update the grades database.",
			"error":  err,
		})
	}
	//sendEmailToStudent(student)
	link := "/admin/student/" + strconv.Itoa(int(student.Id)) + "/mp/" + strconv.Itoa(int(mp.Number))
	return c.RenderJson(map[string]interface{}{
		"status": "success",
		"title":  "Grade has been updated",
		"link":   link,
	})
}
Ejemplo n.º 8
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()
}
Ejemplo n.º 9
0
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()
}