示例#1
0
func (c SecuredApplication) AttemptRunInformation(mpNumString string, runIdString string) revel.Result {

	runId := runIdString

	attempt, err := models.FindAttemptByRunId(runId)

	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error-not-found",
			"title":  "Did not finish running attempt.",
			"data":   "Cannot find attempt with run id = " + runIdString,
		})
	} else if attemptFailed(attempt) {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  attemptFailedReason(attempt),
			"data":   attemptFailedMessage(attempt),
			"link":   fmt.Sprint("/attempt/", attempt.Id),
		})
	} else {
		return c.RenderJson(map[string]interface{}{
			"status": "success",
			"data":   attempt,
			"id":     attempt.Id,
		})
	}
}
示例#2
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()
}