Example #1
0
func (z *ZJGSUJudger) Submit(user vjudger.UserInterface) error {
	z.compile(user)

	if user.GetResult() != config.JudgeCE {
		user.SetResult(config.JudgeRJ)
		logger.Println("compile success")
		user.UpdateSolution()

		cmd := exec.Command("cp", "-r", dataPath+"/"+strconv.Itoa(user.GetVid()), runPath+"/"+strconv.Itoa(user.GetSid()))
		err := cmd.Run()
		if err != nil {
			log.Println(err)
		}
	} else {
		b, err := ioutil.ReadFile(z.workdir + "/ce.txt")
		if err != nil {
			log.Println(err)
		}

		log.Println(string(b))
		user.SetErrorInfo(string(b))
		logger.Println("compiler error")
		log.Println("compiler error")

		return ErrCompile
	}
	return nil
}
Example #2
0
//Get problem Info
func (z *ZJGSUJudger) Login(user vjudger.UserInterface) error {
	proModel := &model.ProblemModel{}
	logger.Println(user.GetVid())
	pro, _ := proModel.Detail(user.GetVid())
	z.time = pro.Time
	z.mem = pro.Memory
	return nil
}
Example #3
0
func (z *ZJGSUJudger) Run(u vjudger.UserInterface) error {
	defer os.RemoveAll(runPath + "/" + strconv.Itoa(u.GetSid()))
	u.SetResult(config.JudgePD)
	for _, apply := range []func(vjudger.UserInterface) error{z.Init, z.Login, z.Submit, z.GetStatus} {
		if err := apply(u); err != nil {
			logger.Println(err)
			return err
		}
	}
	return nil
}
Example #4
0
func (z *ZJGSUJudger) compile(user vjudger.UserInterface) {
	cmd := exec.Command("compiler", strconv.Itoa(user.GetLang()), z.workdir)
	err := cmd.Run()
	if err != nil {
		log.Println(err)
	}

	if cmd.ProcessState.String() != "exit status 0" {
		log.Println(cmd.ProcessState.String())
		user.SetResult(config.JudgeCE) //compiler error
	}
}
Example #5
0
func (z *ZJGSUJudger) Init(user vjudger.UserInterface) error {
	z.token = ZJGSUToken

	z.workdir = runPath + "/" + strconv.Itoa(user.GetSid()) + "/" + strconv.Itoa(user.GetVid())
	logger.Println("workdir is ", z.workdir)

	log.Println(z.workdir)

	cmd := exec.Command("mkdir", "-p", z.workdir)
	cmd.Run()

	z.files(user, z.workdir)
	return nil
}
Example #6
0
func (z *ZJGSUJudger) files(user vjudger.UserInterface, workdir string) {
	var codefilename string

	switch user.GetLang() {
	case config.LanguageC:
		codefilename = workdir + "/Main.c"
	case config.LanguageCPP:
		codefilename = workdir + "/Main.cc"
	case config.LanguageJAVA:
		codefilename = workdir + "/Main.java"
	}

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

	_, err = codefile.WriteString(user.GetCode())
	if err != nil {
		logger.Println("source code writing to file failed")
	}
}
Example #7
0
func (z *ZJGSUJudger) GetStatus(user vjudger.UserInterface) error {
	logger.Println("run solution")

	var out bytes.Buffer
	cmd := exec.Command("runner", strconv.Itoa(user.GetLang()), strconv.Itoa(z.time), strconv.Itoa(z.mem), z.workdir)
	cmd.Stdout = &out
	cmd.Run()

	sp := strings.Split(out.String(), " ")
	var err error
	Result, err := strconv.Atoi(sp[0])

	if err != nil {
		logger.Println(err)
		logger.Println(Result)
	}
	user.SetResult(Result)
	Time, _ := strconv.Atoi(sp[1])
	Mem, _ := strconv.Atoi(sp[2])
	Mem = Mem / 1024 //b->Kb
	user.SetResource(Time, Mem, len(user.GetCode()))
	return nil
}