コード例 #1
0
ファイル: submissions.go プロジェクト: jango2015/ojsite
func (this *Submissions) GetSubmissionStatus(id int) (string, error) {

	jdg := judger.Get("default")
	response, err := jdg.GetStatus(int64(id))

	if err != nil {
		log.Warnln("send Request failed:", err)
	}

	info := response["info"].(map[string]interface{})

	o := orm.NewOrm()
	var subm Submissions
	subm.Id = id
	err = o.Read(&subm, "Id")

	if err != nil {
		log.Warnf("记录[%d]不存在\n", id)
		return "", err
	} else {

		status := info["run_result"].(string)

		if status == "PEN" {
			subm.Status = "AC"
		} else if status == "PRE" {
			subm.Status = "RE"
		} else if status == "POM" {
			subm.Status = "MLE"
		} else if status == "POT" {
			subm.Status = "TLE"
		} else if status == "POL" {
			subm.Status = "OLE"
		} else if status == "PSF" {
			subm.Status = "PSF"
		} else if status == "EC" {
			subm.Status = "CE"
		} else {
			subm.Status = "UK"
		}

		subm.BuildLog = info["build_log"].(string)
		exe_debug, ok := info["executer_debug"].(string)
		if ok {
			subm.ExecuterDebug = exe_debug
		}
		o.Update(&subm)

		return subm.Status, err
	}
}
コード例 #2
0
ファイル: submissions.go プロジェクト: jango2015/ojsite
// update submission status
func (this *Submissions) UpdateSubmissionStatus(id int, status string) error {
	o := orm.NewOrm()
	var subm Submissions
	subm.Id = id
	err := o.Read(&subm, "Id")

	if err != nil {
		log.Warnf("记录[%d]不存在\n", id)
		return err
	} else {
		subm.Status = status

		if _, err := o.Update(&subm); err != nil {
			log.Warnln("状态更新失败")
			return err
		} else {
			return nil
		}
	}
}
コード例 #3
0
ファイル: client.go プロジェクト: kien8995/judger
// send request
func (this *JClient) Request(msg map[string]interface{}) (map[string]interface{}, error) {
	msgStr, err := com.JsonEncode(msg)

	if err != nil {
		return nil, err
	}

	if this.conn == nil {
		log.Warnln("Connection Not Exist")
		return nil, errors.New("Connection Not Exist")
	}

	_, err = this.conn.Write([]byte(msgStr + this.mark))
	if err != nil {
		log.Warnln("[Write Error]", err)
		this.conn.Close()
		return nil, err
	}

	content, err := this.read()

	if err != nil {
		return nil, err
	}

	// kick sep char
	reg := regexp.MustCompile(this.mark)
	content = reg.ReplaceAllString(content, "")

	if this.debug {
		log.Bluef("[judger/send:%s]\n%s\n", time.Now(), msgStr)
		log.Warnf("[judger/recv:%s]\n%s\n", time.Now(), content)
	}

	resp, err := com.JsonDecode(content)

	return resp.(map[string]interface{}), err
}
コード例 #4
0
ファイル: functions.go プロジェクト: jango2015/ojsite
func Warn(format string, v ...interface{}) {
	log.Warnf(format, v...)
}