Example #1
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 #2
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"))
}
Example #3
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()
}