Skip to content

Commit

Permalink
[New] special judge (#136)
Browse files Browse the repository at this point in the history
[graphql]
`contestSubmissions`
indexをsubmission-contestID-indexにしないとこちらではコンテストの提出結果が見れなかったため修正しました。

`problem`
ジャッジサーバーからジャッジ設定を取得するためのリゾルバー

`problemDetail`
新たに`judgeType`,`judgeLang`を返すように変更。`judgeType`がNullの場合デフォルトでNORMALを設定します。

[judge-image]
`appsync.go` レスポンスを受け取れるように変更を加えました
`compile.go` ダウンロード部分をprocessCode部分に出しました
`language_test.go` 言語の設定ファイルの整合性を確認するものです
`run.go` 実行ディレクトリ、実行時引数を指定できるようにしました。引数が多くなったので構造体にまとめました。

[lambda]
`judgecode-url-resolver` ジャッジコードを取得するためのURLを発行する関数です

[frontend]
`judgecode.tsx` ジャッジコードを表示するページを作成しました

スペシャルジャッジのステータスを表示させるためにいくつか変更を加えました
  • Loading branch information
ocha98 authored Jan 4, 2024
1 parent 4a3b04e commit 8884d20
Show file tree
Hide file tree
Showing 40 changed files with 1,183 additions and 240 deletions.
2 changes: 1 addition & 1 deletion mojacoder-backend/graphql/contestSubmissions/request.vtl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
}
},
"nextToken": $util.toJson($util.defaultIfNullOrEmpty($context.arguments.nextToken, null)),
"index" : "contestID-index",
"index" : "submission-contestID-index",
"scanIndexForward": false
}
7 changes: 7 additions & 0 deletions mojacoder-backend/graphql/problem/request.vtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version" : "2018-05-29",
"operation" : "GetItem",
"key" : {
"id" : $util.dynamodb.toDynamoDBJson($context.arguments.id)
},
}
25 changes: 25 additions & 0 deletions mojacoder-backend/graphql/problem/response.vtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if($util.isNull($context.result.judgeType))
#set($context.result.judgeType = "NORMAL")
#end
#set($result = {
"id": $context.result.id,
"slug": $context.result.slug,
"user": { "userID": $context.result.userID },
"datetime": $context.result.datetime,
"status": $context.result.status,
"title": $context.result.title,
"likeCount": $context.result.likeCount,
"commentCount": $context.result.commentCount,
"statement": $context.result.statement,
"hasEditorial": $context.result.hasEditorial,
"editorial": $context.result.editorial,
"hasDifficulty": $context.result.hasDifficulty,
"difficulty": $context.result.difficulty,
"testcaseNames": $context.result.testcaseNames,
"submission": $context.result.submission,
"submissions": $context.result.submissions,
"judgeType": $context.result.judgeType,
"judgeLang": $context.result.judgeLang
}
)
$util.toJson($result)
50 changes: 48 additions & 2 deletions mojacoder-backend/graphql/problemDetail/response.vtl
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
#if($util.isNull($context.arguments.slug))
#set($result = {"id": $context.result.id, "slug": $context.result.slug, "user": { "userID": $context.result.userID }, "datetime": $context.result.datetime, "status": $context.result.status, "title": $context.result.title, "likeCount": $context.result.likeCount, "commentCount": $context.result.commentCount, "statement": $context.result.statement, "hasEditorial": $context.result.hasEditorial, "editorial": $context.result.editorial, "hasDifficulty": $context.result.hasDifficulty, "difficulty": $context.result.difficulty, "testcaseNames": $context.result.testcaseNames, "submission": $context.result.submission, "submissions": $context.result.submissions})
#if($util.isNull($context.result.judgeType))
#set($context.result.judgeType = "NORMAL")
#end
#set($result = {
"id": $context.result.id,
"slug": $context.result.slug,
"user": { "userID": $context.result.userID },
"datetime": $context.result.datetime,
"status": $context.result.status,
"title": $context.result.title,
"likeCount": $context.result.likeCount,
"commentCount": $context.result.commentCount,
"statement": $context.result.statement,
"hasEditorial": $context.result.hasEditorial,
"editorial": $context.result.editorial,
"hasDifficulty": $context.result.hasDifficulty,
"difficulty": $context.result.difficulty,
"testcaseNames": $context.result.testcaseNames,
"submission": $context.result.submission,
"submissions": $context.result.submissions,
"judgeType": $context.result.judgeType,
"judgeLang": $context.result.judgeLang
}
)
#if($util.isNull($context.arguments.id))
$util.toJson($result)
#else
Expand All @@ -14,6 +37,29 @@
null
#else
#set($item = $context.result.items[0])
$util.toJson({"id": $item.id, "slug": $item.slug, "user": { "userID": $item.userID }, "datetime": $item.datetime, "status": $item.status, "title": $item.title, "likeCount": $item.likeCount, "commentCount": $item.commentCount, "statement": $item.statement, "hasEditorial": $item.hasEditorial, "editorial": $item.editorial, "hasDifficulty": "$item.hasDifficulty", "difficulty": $item.difficulty, "testcaseNames": $item.testcaseNames, "submission": $item.submission, "submissions": $item.submissions})
#if($util.isNull($item.judgeType))
#set($item.judgeType = "NORMAL")
#end
$util.toJson({
"id": $item.id,
"slug": $item.slug,
"user": { "userID": $item.userID },
"datetime": $item.datetime,
"status": $item.status,
"title": $item.title,
"likeCount": $item.likeCount,
"commentCount": $item.commentCount,
"statement": $item.statement,
"hasEditorial": $item.hasEditorial,
"editorial": $item.editorial,
"hasDifficulty": "$item.hasDifficulty",
"difficulty": $item.difficulty,
"testcaseNames": $item.testcaseNames,
"submission": $item.submission,
"submissions": $item.submissions,
"judgeType": $item.judgeType,
"judgeLang": $item.judgeLang
}
)
#end
#end
22 changes: 17 additions & 5 deletions mojacoder-backend/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ type Problem @aws_cognito_user_pools @aws_api_key {
detail: ProblemDetail
}

type ProblemDetail @aws_cognito_user_pools @aws_api_key {
enum JudgeTypes {
NORMAL
SPECIAL
}

type ProblemDetail @aws_cognito_user_pools @aws_api_key @aws_iam {
id: ID!
slug: String!
user: User!
Expand All @@ -102,6 +107,9 @@ type ProblemDetail @aws_cognito_user_pools @aws_api_key {
testcaseNames: [String]!
submission(id: ID!): Submission
submissions(nextToken: String, userID: ID): SubmissionConnection!
judgeType: JudgeTypes!
judgeLang: String
judgeCodeUrl: AWSURL
}

type SubmissionConnection @aws_cognito_user_pools @aws_api_key {
Expand All @@ -116,6 +124,8 @@ enum TestcaseResultStatus {
TLE
MLE
RE
JTLE
JMLE
}

type TestcaseResult @aws_api_key @aws_cognito_user_pools @aws_iam {
Expand All @@ -130,6 +140,7 @@ enum SubmissionStatus {
CE
JUDGED
IE
JCE
}

type Submission @aws_cognito_user_pools @aws_api_key {
Expand Down Expand Up @@ -237,10 +248,11 @@ type ResponsePlayground @aws_cognito_user_pools @aws_iam {
userID: ID!
}

type Query @aws_cognito_user_pools @aws_api_key {
user(userID: ID, username: String): UserDetail
newProblems(nextToken: String): ProblemConnection!
newContests: [Contest]!
type Query {
user(userID: ID, username: String): UserDetail @aws_cognito_user_pools @aws_api_key
newProblems(nextToken: String): ProblemConnection! @aws_cognito_user_pools @aws_api_key
newContests: [Contest]! @aws_cognito_user_pools @aws_api_key
problem(id: ID!): ProblemDetail @aws_iam
}

type Subscription {
Expand Down
20 changes: 15 additions & 5 deletions mojacoder-backend/judge-image/appsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type GraphQLResponse struct {

var signer *v4.Signer

func requestGraphql(query string, variables map[string]interface{}, responseData ...interface{}) error {
func requestGraphql(query string, variables map[string]interface{}, responseData interface{}) error {
var err error
var response GraphQLResponse
client := &http.Client{}
Expand All @@ -61,17 +61,27 @@ func requestGraphql(query string, variables map[string]interface{}, responseData
if err != nil {
return err
}
defer res.Body.Close()
bodyData, err := ioutil.ReadAll(res.Body)
if len(responseData) > 0 {
response.Data = responseData
}

err = json.Unmarshal(bodyData, &response)
if err != nil {
return err
}
if len(response.Errors) > 0 {
return &response.Errors
}

if responseData != nil {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return err
}
err = json.Unmarshal(dataBytes, responseData)
if err != nil {
return err
}
}
return nil
}

Expand Down Expand Up @@ -101,6 +111,6 @@ func responsePlayground(sessionID string, userID string, exitCode int, time, mem
}
`
variables["input"] = ResponsePlaygroundInput{sessionID, userID, exitCode, time, memory, stdout, stderr}
err := requestGraphql(query, variables)
err := requestGraphql(query, variables, nil)
return err
}
6 changes: 5 additions & 1 deletion mojacoder-backend/judge-image/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (

const CHECK_SCANNER_BUFFER_SIZE = 1024 * 1024

type NormalJudge struct{}

func (n NormalJudge) isJudgeType() {}

func isValidDecimal(s string) bool {
re := regexp.MustCompile(`^\d+(\.\d+)?$`)
return re.MatchString(s)
Expand Down Expand Up @@ -45,7 +49,7 @@ func compareValue(answer string, solution string, accuracy *big.Float, precision
return isOkAbsolute || isOkRelative
}

func check(answer, solution io.Reader, accuracy *big.Float, precision uint) (bool, error) {
func (n NormalJudge) check(answer, solution io.Reader, accuracy *big.Float, precision uint) (bool, error) {
const errorMessage = "Failed to check an answer: %v"
var err error
var testScan, answerScan bool
Expand Down
10 changes: 2 additions & 8 deletions mojacoder-backend/judge-image/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ package main
import (
"os"
"os/exec"
"path/filepath"
)

func compile(definition LanguageDefinition, bucket, key string) (bool, string, error) {
func compile(definition LanguageDefinition, dir string) (bool, string, error) {
var err error
codePath := filepath.Join(TEMP_DIR, definition.Filename)
err = downloadFromStorage(codePath, bucket, key)
if err != nil {
return false, "", err
}
if definition.CompileCommand == "" {
return true, "", nil
}
Expand All @@ -21,7 +15,7 @@ func compile(definition LanguageDefinition, bucket, key string) (bool, string, e
"PATH=" + os.Getenv("PATH"),
"HOME=" + os.Getenv("HOME"),
}
cmd.Dir = TEMP_DIR
cmd.Dir = dir
_, err = cmd.Output()
res, exist := err.(*exec.ExitError)
if exist {
Expand Down
2 changes: 1 addition & 1 deletion mojacoder-backend/judge-image/health.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"net/http"
"fmt"
"log"
"net/http"
)

func healthHandler(w http.ResponseWriter, r *http.Request) {
Expand Down
Loading

0 comments on commit 8884d20

Please sign in to comment.