Exemplo n.º 1
0
// /contest/:name/:pid/submit
func (this *ContestController) submit() {
	if !this.isLoggedIn() {
		this.Redirect("/user/login", 302)
		return
	}
	contestName := this.Ctx.Input.Param(":name")
	pid, err := strconv.Atoi(this.Ctx.Input.Param(":pid"))
	if err != nil {
		log.Println(err)
		this.Redirect("/", 302)
		return
	}
	contest := models.Contest{}
	contest.Name = contestName
	if err := contest.GetByName(); !err {
		this.Redirect("/", 302)
		return
	}
	currTime := time.Now()
	if contest.EndTime.Before(currTime) {
		this.Redirect("/contest/"+contestName, 302)
		return
	}
	uid := this.GetSession("id")
	code := this.GetString("code")
	lang := this.GetString("language")

	problemLog := models.Problemlogs{}
	problemLog.Uid = uid.(int)
	problemLog.Pid = pid
	problemLog.GetByPidUid()

	output := models.SubmitUpdateScore(uid.(int), pid, code, lang)

	contestLog := models.Contestlogs{}
	contestLog.Uid = uid.(int)
	contestLog.Cid = contest.Id
	status := contestLog.GetByUidCid()
	if !status {
		contestLog.Points = output.Score
		contestLog.Add()
	} else {
		if output.Score > problemLog.Points {
			contestLog.Points += output.Score - problemLog.Points
			contestLog.Update()
		}
	}

	js, _ := json.Marshal(output)
	this.Data["json"] = string(js)
	this.ServeJson()

}
Exemplo n.º 2
0
// Format of submission
// Status - crashes on submission, code and lang are empty
func (this *ProblemController) SaveSubmission() {
	if !this.isLoggedIn() {
		this.Redirect("/user/login", 302)
		return
	}

	uid := this.GetSession("id")
	pid, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
	code := this.GetString("code")
	lang := this.GetString("language")
	output := models.SubmitUpdateScore(uid.(int), pid, code, lang)
	js, _ := json.Marshal(output)
	this.Data["json"] = string(js)
	this.ServeJson()

}