Example #1
0
func (this *RanklistController) List(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("RankList")
	this.InitContest(w, r)
	qry := make(map[string]string)
	qry["module"] = strconv.Itoa(config.ModuleC)
	qry["mid"] = strconv.Itoa(this.Cid)
	qry["/sort"] = "resort"

	solutionModel := model.SolutionModel{}
	solutionList, err := solutionModel.List(qry)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	UserMap := make(map[string]*userRank)
	var pro *probleminfo
	var user *userRank
	for _, v := range solutionList {
		user = UserMap[v.Uid]
		if user == nil {
			user = &userRank{}
			UserMap[v.Uid] = user
			user.ProblemList = make([]*probleminfo, len(this.Index), len(this.Index))
		}
		user.Uid = v.Uid
		pid := this.Index[v.Pid]
		pro = user.ProblemList[pid]
		if pro == nil {
			pro = &probleminfo{}
			user.ProblemList[pid] = pro
		}
		if pro.Judge == config.JudgeAC {
			continue
		}
		pro.Pid = pid
		if v.Judge != config.JudgeAC && v.Judge != config.JudgePD && v.Judge != config.JudgeRJ {
			pro.Count++
			pro.Time += 20 * 60 //罚时20分钟
		} else if v.Judge == config.JudgeAC {
			pro.Time += v.Create - this.ContestDetail.Start
			pro.Judge = config.JudgeAC
			user.Time += pro.Time
			user.Solved += 1
		}
	}
	UserList := newSorter(UserMap)
	sort.Sort(UserList)

	this.Data["UserList"] = UserList
	this.Data["IsContestRanklist"] = true
	this.Data["Cid"] = this.Cid
	this.Data["ProblemList"] = this.Index
	err = this.Execute(w, "view/layout.tpl", "view/contest/ranklist.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
	return
}
Example #2
0
func (this *StatusController) List(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Contest Status List")
	this.InitContest(w, r)

	solutionModel := model.SolutionModel{}
	qry := make(map[string]string)

	qry["module"] = strconv.Itoa(config.ModuleC)
	qry["mid"] = strconv.Itoa(this.Cid)
	solutionList, err := solutionModel.List(qry)

	if err != nil {
		http.Error(w, "load error", 400)
		return
	}
	for i, v := range solutionList {
		solutionList[i].Pid = this.Index[v.Pid]
	}
	this.Data["Solution"] = solutionList
	this.Data["Privilege"] = this.Privilege
	this.Data["IsContestStatus"] = true
	err = this.Execute(w, "view/layout.tpl", "view/contest/status_list.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
Example #3
0
//ranklist 实时计算排名
func (rc *ContestRanklist) ranklist() UserSorter {
	qry := make(map[string]string)
	qry["module"] = strconv.Itoa(config.ModuleC)
	qry["mid"] = strconv.Itoa(rc.Cid)
	qry["sort"] = "resort"

	solutionModel := model.SolutionModel{}
	solutionList, err := solutionModel.List(qry)
	if err != nil {
		restweb.Logger.Debug(err)
		return nil
	}

	UserMap := make(map[string]*userRank)
	var pro *probleminfo
	var user *userRank
	for _, v := range solutionList {
		user = UserMap[v.Uid]
		if user == nil {
			user = &userRank{}
			UserMap[v.Uid] = user
			user.ProblemList = make([]*probleminfo, len(rc.Index), len(rc.Index))
		}
		user.Uid = v.Uid
		pid := rc.Index[v.Pid]
		pro = user.ProblemList[pid]
		if pro == nil {
			pro = &probleminfo{}
			user.ProblemList[pid] = pro
		}
		if pro.Judge == config.JudgeAC {
			continue
		}
		pro.Pid = pid
		if v.Judge != config.JudgeAC && v.Judge != config.JudgePD && v.Judge != config.JudgeRJ && v.Judge != config.JudgeNA {
			pro.Count++
			pro.Time += 20 * 60 //罚时20分钟
		} else if v.Judge == config.JudgeAC {
			user.Time += pro.Time
			pro.Time = v.Create - rc.ContestDetail.Start
			pro.Judge = config.JudgeAC
			user.Time += pro.Time
			user.Solved += 1
		}
	}
	UserList := newSorter(UserMap)
	sort.Sort(UserList)
	return UserList
}
Example #4
0
//@URL: /status @method: GET
func (sc *StatusController) List() {
	restweb.Logger.Debug("Status List")

	searchUrl := ""
	qry := make(map[string]string)
	// Search
	if v, ok := sc.Input["uid"]; ok {
		searchUrl += "uid=" + v[0] + "&"
		sc.Output["SearchUid"] = v[0]
		qry["uid"] = v[0]
	}
	if v, ok := sc.Input["pid"]; ok {
		searchUrl += "pid=" + v[0] + "&"
		sc.Output["SearchPid"] = v[0]
		qry["pid"] = v[0]
	}
	if v, ok := sc.Input["judge"]; ok {
		searchUrl += "judge=" + v[0] + "&"
		sc.Output["SearchJudge"+v[0]] = v[0]
		qry["judge"] = v[0]
	}
	if v, ok := sc.Input["language"]; ok {
		searchUrl += "language=" + v[0] + "&"
		sc.Output["SearchLanguage"+v[0]] = v[0]
		qry["language"] = v[0]
	}
	sc.Output["URL"] = "/status?" + searchUrl

	// Page
	qry["page"] = "1"

	if v, ok := sc.Input["page"]; ok {
		qry["page"] = v[0]
	}

	solutionModel := model.SolutionModel{}
	qry["module"] = strconv.Itoa(config.ModuleP)
	qry["action"] = "submit"
	count, err := solutionModel.Count(qry)
	if err != nil {
		sc.Error(err.Error(), 400)
		return
	}
	var pageCount = (count-1)/config.SolutionPerPage + 1

	page, err := strconv.Atoi(qry["page"])
	if err != nil {
		sc.Error("args error", 400)
		return
	}
	if page > pageCount {
		sc.Error("args error", 400)
		return
	}
	qry["offset"] = strconv.Itoa((page - 1) * config.SolutionPerPage)
	qry["limit"] = strconv.Itoa(config.SolutionPerPage)

	pageData := sc.GetPage(page, pageCount)
	for k, v := range pageData {
		sc.Output[k] = v
	}

	list, err := solutionModel.List(qry)
	if err != nil {
		sc.Error(err.Error(), 500)
		return
	}

	sc.Output["Solution"] = list
	sc.Output["Title"] = "Status List"
	sc.Output["IsStatus"] = true
	sc.Output["Privilege"] = sc.Privilege
	sc.Output["Uid"] = sc.Uid

	sc.RenderTemplate("view/layout.tpl", "view/status_list.tpl")
}
Example #5
0
//@URL: /contests/(\d+)/status @method: GET
func (sc *ContestStatus) List(Cid string) {
	restweb.Logger.Debug("Contest Status List")

	sc.InitContest(Cid)
	solutionModel := model.SolutionModel{}
	qry := make(map[string]string)

	qry["module"] = strconv.Itoa(config.ModuleC)
	qry["mid"] = Cid
	searchUrl := ""
	// Search
	if v, ok := sc.Input["uid"]; ok {
		searchUrl += "uid=" + v[0] + "&"
		sc.Output["SearchUid"] = v[0]
		qry["uid"] = v[0]
	}
	if v, ok := sc.Input["pid"]; ok {
		searchUrl += "pid=" + v[0] + "&"
		sc.Output["SearchPid"] = v[0]
		idx, _ := strconv.Atoi(v[0])
		if idx < len(sc.ContestDetail.List) {
			qry["pid"] = strconv.Itoa(sc.ContestDetail.List[idx])
			restweb.Logger.Debug(qry["pid"], idx)
		}
	}
	if v, ok := sc.Input["judge"]; ok {
		searchUrl += "judge=" + v[0] + "&"
		sc.Output["SearchJudge"+v[0]] = v[0]
		qry["judge"] = v[0]
	}
	if v, ok := sc.Input["language"]; ok {
		searchUrl += "language=" + v[0] + "&"
		sc.Output["SearchLanguage"+v[0]] = v[0]
		qry["language"] = v[0]
	}

	qry["page"] = "1"
	if v, ok := sc.Input["page"]; ok {
		qry["page"] = v[0]
	}

	sc.Output["URL"] = "/contests/" + Cid + "/status?" + searchUrl

	qry["action"] = "submit"
	count, err := solutionModel.Count(qry)
	if err != nil {
		sc.Error(err.Error(), 400)
		return
	}
	var pageCount = (count-1)/config.SolutionPerPage + 1

	page, err := strconv.Atoi(qry["page"])
	if err != nil {
		sc.Error("args error", 400)
		return
	}
	if page > pageCount {
		sc.Error("args error", 400)
		return
	}
	qry["offset"] = strconv.Itoa((page - 1) * config.SolutionPerPage)
	qry["limit"] = strconv.Itoa(config.SolutionPerPage)

	pageData := sc.GetPage(page, pageCount)
	for k, v := range pageData {
		sc.Output[k] = v
	}

	solutionList, err := solutionModel.List(qry)

	if err != nil {
		sc.Error("load error", 400)
		return
	}
	for i, v := range solutionList {
		solutionList[i].Pid = sc.Index[v.Pid]
	}
	sc.Output["Solution"] = solutionList
	sc.Output["Privilege"] = sc.Privilege
	sc.Output["IsContestStatus"] = true
	sc.Output["Privilege"] = sc.Privilege
	sc.Output["Uid"] = sc.Uid

	sc.RenderTemplate("view/layout.tpl", "view/contest/status_list.tpl")
}
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
}
Example #8
0
func (this *StatusController) List(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Status List")
	this.Init(w, r)
	args := this.ParseURL(r.URL.String())
	url := "/solution?list"
	searchUrl := ""
	qry := make(map[string]string)
	// Search
	if v, ok := args["uid"]; ok {
		searchUrl += "/uid?" + v
		this.Data["SearchUid"] = v
		qry["uid"] = v
	}
	if v, ok := args["pid"]; ok {
		searchUrl += "/pid?" + v
		this.Data["SearchPid"] = v
		qry["pid"] = v
	}
	if v, ok := args["judge"]; ok {
		searchUrl += "/judge?" + v
		this.Data["SearchJudge"+v] = v
		qry["judge"] = v
	}
	if v, ok := args["language"]; ok {
		searchUrl += "/language?" + v
		this.Data["SearchLanguage"+v] = v
		qry["language"] = v
	}
	url += searchUrl
	this.Data["URL"] = "/status?list" + searchUrl

	// Page
	if _, ok := args["page"]; !ok {
		args["page"] = "1"
	}

	solutionModel := model.SolutionModel{}
	qry["module"] = strconv.Itoa(config.ModuleP)
	qry["action"] = "submit"
	count, err := solutionModel.Count(qry)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	var pageCount = (count-1)/config.SolutionPerPage + 1

	page, err := strconv.Atoi(args["page"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}
	if page > pageCount {
		http.Error(w, "args error", 400)
		return
	}
	qry["offset"] = strconv.Itoa((page - 1) * config.SolutionPerPage)
	qry["limit"] = strconv.Itoa(config.SolutionPerPage)

	pageData := this.GetPage(page, pageCount)
	for k, v := range pageData {
		this.Data[k] = v
	}

	list, err := solutionModel.List(qry)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	this.Data["Solution"] = list
	this.Data["Title"] = "Status List"
	this.Data["IsStatus"] = true
	err = this.Execute(w, "view/layout.tpl", "view/status_list.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}