Ejemplo n.º 1
0
func newRunContext(ctx *grader.Context, db *sql.DB, id int64) (*grader.RunContext, error) {
	runCtx := grader.NewEmptyRunContext(ctx)
	runCtx.ID = id
	runCtx.GradeDir = path.Join(
		ctx.Config.Grader.RuntimePath,
		"grade",
		fmt.Sprintf("%02d", id%100),
		fmt.Sprintf("%d", id),
	)
	var contestName sql.NullString
	var contestPoints sql.NullFloat64
	err := db.QueryRow(
		`SELECT
			s.guid, c.alias, s.language, p.alias, pv.hash, cp.points
		FROM
			Runs r
		INNER JOIN
			Submissions s ON r.submission_id = s.submission_id
		INNER JOIN
			Problems p ON p.problem_id = s.problem_id
		INNER JOIN
			Problem_Versions pv ON pv.version_id = r.version_id
		LEFT JOIN
			Contests c ON c.contest_id = s.contest_id
		LEFT JOIN
			Contest_Problems cp ON cp.problem_id = s.problem_id AND
			cp.contest_id = s.contest_id
		WHERE
			r.run_id = ?;`, id).Scan(
		&runCtx.GUID, &contestName, &runCtx.Run.Language, &runCtx.ProblemName,
		&runCtx.Run.InputHash, &contestPoints)
	if err != nil {
		return nil, err
	}
	if contestName.Valid {
		runCtx.Contest = &contestName.String
	}
	if contestPoints.Valid {
		runCtx.Run.MaxScore = contestPoints.Float64
	}
	runCtx.Result.MaxScore = runCtx.Run.MaxScore
	contents, err := ioutil.ReadFile(
		path.Join(
			ctx.Config.Grader.RuntimePath,
			"submissions",
			runCtx.GUID[:2],
			runCtx.GUID[2:],
		),
	)
	if err != nil {
		return nil, err
	}
	runCtx.Run.Source = string(contents)
	return runCtx, nil
}
Ejemplo n.º 2
0
func v1CompatNewRunContext(
	ctx *grader.Context,
	db *sql.DB,
	guid string,
) (*grader.RunContext, error) {
	runCtx := grader.NewEmptyRunContext(ctx)
	runCtx.GUID = guid
	runCtx.GradeDir = path.Join(
		ctx.Config.Grader.V1.RuntimeGradePath,
		guid[:2],
		guid[2:],
	)
	var contestName sql.NullString
	var contestPoints sql.NullFloat64
	err := db.QueryRow(
		`SELECT
			r.run_id, c.alias, r.language, p.alias, cp.points
		FROM
			Runs r
		INNER JOIN
			Problems p ON p.problem_id = r.problem_id
		LEFT JOIN
			Contests c ON c.contest_id = r.contest_id
		LEFT JOIN
			Contest_Problems cp ON cp.problem_id = r.problem_id AND
			cp.contest_id = r.contest_id
		WHERE
			r.guid = ?;`, guid).Scan(
		&runCtx.ID, &contestName, &runCtx.Run.Language, &runCtx.ProblemName,
		&contestPoints)
	if err != nil {
		return nil, err
	}

	runCtx.Run.InputHash, err = v1CompatGetTreeId(path.Join(
		ctx.Config.Grader.V1.RuntimePath,
		"problems.git",
		runCtx.ProblemName,
	))
	if err != nil {
		return nil, err
	}

	if contestName.Valid {
		runCtx.Contest = &contestName.String
	}
	if contestPoints.Valid {
		runCtx.Run.MaxScore = contestPoints.Float64
	} else {
		runCtx.Run.MaxScore = 1.0
	}
	runCtx.Result.MaxScore = runCtx.Run.MaxScore
	contents, err := ioutil.ReadFile(
		path.Join(
			ctx.Config.Grader.V1.RuntimePath,
			"submissions",
			runCtx.GUID[:2],
			runCtx.GUID[2:],
		),
	)
	if err != nil {
		return nil, err
	}
	runCtx.Run.Source = string(contents)
	return runCtx, nil
}