Example #1
0
func (this *StatusController) Code(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Status Code")
	this.Init(w, r)
	this.InitContest(w, r)

	args := this.ParseURL(r.URL.String())
	sid, err := strconv.Atoi(args["sid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

	solutionModel := model.SolutionModel{}
	one, err := solutionModel.Detail(sid)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if one.Uid == this.Uid || this.Privilege > config.PrivilegeTC {
		this.Data["Solution"] = one
		this.Data["Privilege"] = this.Privilege
		this.Data["Title"] = "View Code"
		this.Data["IsCode"] = true
		err = this.Execute(w, "view/layout.tpl", "view/contest/status_code.tpl")
		if err != nil {
			class.Logger.Debug(err)
			http.Error(w, "tpl error", 500)
			return
		}
	}
}
Example #2
0
//@URL: /status/code @method: GET
func (sc *StatusController) Code() {
	restweb.Logger.Debug("Status Code")

	sid, err := strconv.Atoi(sc.Input.Get("sid"))
	if err != nil {
		http.Error(sc.W, "args error", 400)
		return
	}

	solutionModel := model.SolutionModel{}
	one, err := solutionModel.Detail(sid)
	if err != nil {
		http.Error(sc.W, err.Error(), 400)
		return
	}
	if one.Error != "" {
		one.Code = one.Code + "\n/*\n" + one.Error + "*/\n"
	}

	if one.Uid == sc.Uid || sc.Privilege > config.PrivilegePU || one.Share {
		sc.Output["Solution"] = one
		sc.Output["Title"] = "View Code"
		sc.Output["IsCode"] = true
		sc.RenderTemplate("view/layout.tpl", "view/status_code.tpl")
	} else {
		sc.Err400("Warning", "You can't see it!")
	}
}
Example #3
0
//@URL: /contests/(\d+)/status/(\d+)/code @method:GET
func (sc *ContestStatus) Code(Cid string, Sid string) {
	restweb.Logger.Debug("Status Code")

	sc.InitContest(Cid)
	sid, err := strconv.Atoi(Sid)
	if err != nil {
		sc.Error("args error", 400)
		return
	}

	solutionModel := model.SolutionModel{}
	one, err := solutionModel.Detail(sid)
	if err != nil {
		sc.Error(err.Error(), 500)
		return
	}

	if one.Error != "" {
		one.Code += "\n/*\n" + one.Error + "\n*/"
	}
	if one.Uid == sc.Uid || sc.Privilege >= config.PrivilegeTC {
		sc.Output["Solution"] = one
		sc.Output["Privilege"] = sc.Privilege
		sc.Output["Title"] = "View Code"
		sc.Output["IsCode"] = true
		sc.Output["Pid"] = sc.Index[one.Pid]
		sc.RenderTemplate("view/layout.tpl", "view/contest/status_code.tpl")
	} else {
		sc.Err400("Warning", "You can't see it!")
	}
}
Example #4
0
func (s *solution) Init(info Info) {
	logger.Println(info)

	solutionModel := model.SolutionModel{}
	sol, err := solutionModel.Detail(info.Sid)
	if err != nil {
		logger.Println(err)
		return
	}
	s.Solution = *sol

	s.OJ = info.OJ
	s.Vid = info.Pid
}
Example #5
0
//UpdateSolution 更新判题结果
func (this *solution) UpdateSolution() {
	sid, err := strconv.Atoi(strconv.Itoa(this.Sid))

	solutionModel := model.SolutionModel{}
	ori, err := solutionModel.Detail(sid)
	if err != nil {
		logger.Println(err)
		return
	}

	ori.Judge = this.Judge
	ori.Time = this.Time
	ori.Memory = this.Memory
	ori.Sim = this.Sim
	ori.Sim_s_id = this.Sim_s_id
	ori.Error = this.Error

	err = solutionModel.Update(sid, *ori)
	if err != nil {
		logger.Println(err)
		return
	}
}
Example #6
0
func (this *ProblemController) Rejudge(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Problem Rejudge")
	this.Init(w, r)

	if this.Privilege < config.PrivilegeTC {
		this.Err400(w, r, "Warning", "Error Privilege to Rejudge problem")
		return
	}

	args := this.ParseURL(r.URL.String())
	types := args["type"]
	id, err := strconv.Atoi(args["id"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

	hint := make(map[string]string)

	if types == "Pid" {
		pid := id
		proModel := model.ProblemModel{}
		pro, err := proModel.Detail(pid)
		if err != nil {
			class.Logger.Debug(err)
			hint["info"] = "Problem does not exist!"

			b, _ := json.Marshal(&hint)
			w.WriteHeader(400)
			w.Write(b)

			return
		}
		qry := make(map[string]string)
		qry["pid"] = strconv.Itoa(pro.Pid)

		solutionModel := model.SolutionModel{}
		list, err := solutionModel.List(qry)

		for i := range list {
			sid := list[i].Sid

			time.Sleep(1 * time.Second)
			go func() {
				cmd := exec.Command("./RunServer", "-sid", strconv.Itoa(sid), "-time", strconv.Itoa(pro.Time), "-memory", strconv.Itoa(pro.Memory), "-rejudge", strconv.Itoa(1)) //Run Judge
				err = cmd.Run()
				if err != nil {
					class.Logger.Debug(err)
				}
			}()
		}
	} else if types == "Sid" {
		sid := id

		solutionModel := model.SolutionModel{}
		sol, err := solutionModel.Detail(sid)
		if err != nil {
			class.Logger.Debug(err)

			hint["info"] = "Solution does not exist!"
			b, _ := json.Marshal(&hint)
			w.WriteHeader(400)
			w.Write(b)

			return
		}

		problemModel := model.ProblemModel{}
		pro, err := problemModel.Detail(sol.Pid)
		if err != nil {
			http.Error(w, err.Error(), 500)
			return
		}

		go func() {
			cmd := exec.Command("./RunServer", "-sid", strconv.Itoa(sid), "-time", strconv.Itoa(pro.Time), "-memory", strconv.Itoa(pro.Memory), "-rejudge", strconv.Itoa(1)) //Run Judge
			err = cmd.Run()
			if err != nil {
				class.Logger.Debug(err)
			}
		}()
	}
}
Example #7
0
//get_sim 相似度检测,返回值为相似度和相似的id
func (this *solution) get_sim(Sid, Language int) (sim, Sim_s_id int) {
	var extension string

	if this.Language == config.LanguageC {
		extension = "c"
	} else if this.Language == config.LanguageCPP {
		extension = "cc"
	} else if this.Language == config.LanguageJAVA {
		extension = "java"
	}

	qry := make(map[string]string)
	qry["pid"] = strconv.Itoa(this.Pid)
	qry["action"] = "solve"

	solutionModel := model.SolutionModel{}
	list, err := solutionModel.List(qry)
	workdir := runPath + "/" + strconv.Itoa(this.Sid)

	sim_test_dir := workdir + "/sim_test"

	cmd := exec.Command("mkdir", "-p", sim_test_dir)
	err = cmd.Run()
	if err != nil {
		logger.Println(err)
		return
	}
	defer os.RemoveAll(workdir)

	codefile, err := os.Create(sim_test_dir + "/../Main." + extension)
	defer codefile.Close()

	_, err = codefile.WriteString(this.Code)
	if err != nil {
		logger.Println("source code writing to file failed")
	}

	var count int

	for i := range list {
		sid := list[i].Sid

		sol, err := solutionModel.Detail(sid)
		if sid < this.Sid && err == nil {
			filepath := sim_test_dir + "/" + strconv.Itoa(sid) + "." + extension

			codefile, err := os.Create(filepath)
			defer codefile.Close()

			_, err = codefile.WriteString(sol.Code)
			if err != nil {
				logger.Println("source code writing to file failed")
			}
			count++
		}
	}

	cmd = exec.Command("sim.sh", sim_test_dir, extension)

	if err = cmd.Run(); err != nil {
		return
	}
	defer os.Remove("./simfile")

	if _, err := os.Stat("./simfile"); err == nil {

		simfile, err := os.Open("./simfile")

		if err != nil {
			logger.Println("sim file open error")
			return
		}
		defer simfile.Close()
		fmt.Fscanf(simfile, "%d %d", &sim, &Sim_s_id)
	}
	return sim, Sim_s_id
}