func (c SecuredApplication) SubmitProgram(mpNumString string) (res revel.Result) { var program string var datasetId int mpNum, err := strconv.Atoi(mpNumString) if err != nil { c.Flash.Error("Invalid machine problem") return c.Render(routes.PublicApplication.Index()) } user := c.connected() c.Params.Bind(&program, "program") c.Params.Bind(&datasetId, "datasetId") mp, err := models.FindOrCreateMachineProblemByUser(user, mpNum) if err != nil { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Error finding MP record", "data": "System was not able to save program.", }) } if lastAttempt, err := models.FindLastAttemptByMachineProblem(mp); err == nil && time.Since(lastAttempt.Created).Seconds() < 5 { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Attempt limiter", "data": "Too many attempts. Please wait 10 seconds between attempts.", }) } if _, err := models.CreateProgram(mp, program); err != nil { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Error Saving Program", "data": "System was not able to save program.", }) } runId := generateRunId(user) conf, _ := ReadMachineProblemConfig(mpNum) stats.Incr("App", "ProgramSubmission") server.SubmitProgram(mp, program, datasetId, conf.Language, runId, false) return c.RenderJson(map[string]interface{}{ "status": "success", "runId": runId, "attempt": "Attempt submitted", }) }
func (c SecuredApplication) UpdatePeerReview(mpNumString string) revel.Result { mpNum, err := strconv.Atoi(mpNumString) if err != nil { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Cannot Find Machine Problem", "data": "Cannot find machine problem --- invalid MP Id.", "error": err, }) } user := c.connected() mp, err := models.FindOrCreateMachineProblemByUser(user, mpNum) if err != nil { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Cannot Find Machine Problem", "data": "Cannot find machine problem.", "error": err, }) } if _, err := models.FindLastAttemptByMachineProblem(mp); err != nil { if _, err = models.CreateDummyAttemptByMachineProblem(mp); err != nil { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Error: Cannot Submit Peer Review.", "data": "We require that you have attempted the MP to submit a peer review.", "error": err, }) } } var reviewsString string c.Params.Bind(&reviewsString, "reviews") //revel.TRACE.Println(reviewsString) var reviews []PeerReviewRecord if err := json.Unmarshal([]byte(reviewsString), &reviews); err != nil { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Error: Cannot Parse Review Request.", "data": "The system was not able to parse your review request.", "error": err, }) } prs := make([]models.PeerReview, len(reviews)) for ii, review := range reviews { pr, err := models.FindPeerReview(review.Id) if err != nil || pr.Reviewer != user.Id { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Error: Cannot Submit Review.", "data": "Cannot submit review request -- invalid reviewer.", }) } if strings.TrimSpace(review.QuestionComment) == "" || strings.TrimSpace(review.CodeComment) == "" { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Error: Cannot Submit Empty Review.", "data": "Cannot submit review. Please make sure to offer useful comments to your peers.", }) } prs[ii] = pr } for ii, pr := range prs { review := reviews[ii] _, err := models.UpdatePeerReview(pr, review.CodeScore, review.CodeComment, review.QuestionScore, review.QuestionComment) if err != nil { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Error: Cannot Save Review", "data": "The system was not able to submit your review to the database. Report this issue if problem presists.", }) } } var grade models.Grade if grade, err = models.UpdateGradePeerReview(user, mp); err != nil { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Error: Peer Review Grade was not Updated.", "data": "The system was not able to update your peer review grade. " + "Report this issue if problem presists. " + fmt.Sprint(err), }) } if err := doPostCourseraGrade(user, mp, grade, "peer", false); err != nil { return c.RenderJson(map[string]interface{}{ "status": "error", "title": "Error: Did not save grade to Coursera.", "data": "Make sure you are connected to Coursera", }) } link := "/grade/" + strconv.Itoa(int(grade.Id)) return c.RenderJson(map[string]interface{}{ "status": "success", "title": "Peer Review has been Submitted", "data": "Review has been logged and submitted. Make sure to visit the <a href=\"" + link + "\"> machine problem grade page</a> and re-submit your grade to Coursera.", "link": link, }) }