コード例 #1
0
ファイル: admin_app.go プロジェクト: thnguyn2/WebGPU
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()
}
コード例 #2
0
ファイル: secured_app.go プロジェクト: thnguyn2/WebGPU
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()
}
コード例 #3
0
ファイル: secured_app.go プロジェクト: thnguyn2/WebGPU
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()
}
コード例 #4
0
ファイル: coursera.go プロジェクト: thnguyn2/WebGPU
func (c CourseraApplication) PostGrade(gradeIdString string, toPostString string, forceString string) revel.Result {

	gradeId, err := strconv.Atoi(gradeIdString)
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot Submit Grade to Coursera.",
			"data":   "Invalid grade Id.",
		})
	}

	user := c.connected()

	grade, err := models.FindGrade(int64(gradeId))
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot Submit Grade to Coursera.",
			"data":   "Cannot find grade record.",
		})
	}

	mp, err := models.FindMachineProblem(grade.MachineProblemId)
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot Submit Grade to Coursera.",
			"data":   "Cannot find machine problem record.",
		})
	}

	mpUser, err := models.FindUser(mp.UserInstanceId)
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot Submit Grade to Coursera.",
			"data":   "User not found.",
		})
	}

	if mpUser.Id != user.Id {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot Submit Grade to Coursera.",
			"data":   "User did not match.",
		})
	}

	forceQ := forceString == "true"

	if forceQ == false && grade.PeerReviewScore > 0 && grade.PeerReviewScore < grade.CourseraPeerReviewGrade {
		s := fmt.Sprint("Trying to post a code grade of ", grade.PeerReviewScore,
			" to Coursera, while Coursera has a higher score of ", grade.CourseraPeerReviewGrade)
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: PeerReview Grade lower than what has been previously posted to Coursera",
			"data":   s,
		})
	}
	if forceQ == false && grade.CodeScore > 0 && grade.CodeScore < grade.CourseraCodingGrade {
		s := fmt.Sprint("Trying to post a code grade of ", grade.CodeScore,
			" to Coursera, while Coursera has a higher score of ", grade.CourseraCodingGrade)
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Code Grade lower than what has been previously posted to Coursera",
			"data":   s,
		})
	}

	if err = doPostCourseraGrade(user, mp, grade, toPostString, forceQ); err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"data":   "Was not able to post coursera grade. Make sure you are connected to coursera first.",
		})
	}

	c.Flash.Success("Grade has been posted to Coursera.")

	return c.RenderJson(map[string]interface{}{
		"status": "success",
		"title":  "Grade has been posted to Coursera.",
		"data":   "Grade has been posted to Coursera.",
	})
}