forked from Eagle-OJ/eagle-oj-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Eagle-OJ#17 from Eagle-OJ/master
update
- Loading branch information
Showing
304 changed files
with
9,940 additions
and
6,140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM openjdk:8u151-jre-alpine3.7 | ||
|
||
WORKDIR /eagle-oj | ||
|
||
COPY ./eagle-oj-web/target/eagle-oj-web-1.0.jar /eagle-oj | ||
|
||
# ENV MYSQL_URL=101.132.164.120:3306 MYSQL_DATABASE=eagle_oj MYSQL_USERNAME=root MYSQL_PASSWORD=eagle_oj | ||
|
||
CMD ["java", "-Dspring.profiles.active=prod", "-jar", "eagle-oj-web-1.0.jar"] | ||
|
||
EXPOSE 8080 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../org.inlighting.oj.judge/JudgeHelper.java → ...n/java/com/eagleoj/judge/JudgeHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.inlighting.oj.judge; | ||
package com.eagleoj.judge; | ||
|
||
import com.alibaba.fastjson.JSONArray; | ||
|
||
|
4 changes: 2 additions & 2 deletions
4
...org.inlighting.oj.judge/LanguageEnum.java → .../java/com/eagleoj/judge/LanguageEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.eagleoj.judge; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.eagleoj.judge.judger.Judger; | ||
import com.eagleoj.judge.entity.RequestEntity; | ||
import com.eagleoj.judge.entity.ResponseEntity; | ||
import com.eagleoj.judge.entity.TestCaseRequestEntity; | ||
import com.eagleoj.judge.judger.eagle.Eagle; | ||
import com.eagleoj.judge.judger.judge0.Judge0; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Smith | ||
**/ | ||
public class Main { | ||
public static void main(String[] args) { | ||
List<TestCaseRequestEntity> list = new ArrayList<>(2); | ||
TestCaseRequestEntity testCaseRequestEntity1 = new TestCaseRequestEntity(null, "hll\n"); | ||
TestCaseRequestEntity testCaseRequestEntity2 = new TestCaseRequestEntity(null, "hello"); | ||
list.add(testCaseRequestEntity1); | ||
list.add(testCaseRequestEntity2); | ||
/*RequestEntity requestEntity = new RequestEntity(LanguageEnum.PYTHON35, "print(\"hello\")", 3,public class Main {public static void main(String[] args) {System.out.println(\"hll\");}} | ||
128, list);*/ | ||
RequestEntity requestEntity = new RequestEntity(LanguageEnum.JAVA8, "public class Main {public static void main(String[] args) {System.out.println(\"hll\");}}", 3, | ||
128, list); | ||
Judger judger = eagle(requestEntity); | ||
ResponseEntity responseEntity = judger.judge(); | ||
} | ||
|
||
private static Judger judge0(RequestEntity requestEntity) { | ||
return new Judger("http://www.funnytu.com:3000", requestEntity, new Judge0()); | ||
} | ||
|
||
private static Judger eagle(RequestEntity requestEntity) { | ||
return new Judger("http://101.132.164.120:5000", requestEntity, new Eagle()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...a/org.inlighting.oj.judge/ResultEnum.java → ...in/java/com/eagleoj/judge/ResultEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.inlighting.oj.judge; | ||
package com.eagleoj.judge; | ||
|
||
/** | ||
* @author Smith | ||
|
4 changes: 2 additions & 2 deletions
4
...ghting.oj.judge/entity/RequestEntity.java → ...m/eagleoj/judge/entity/RequestEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...hting.oj.judge/entity/ResponseEntity.java → .../eagleoj/judge/entity/ResponseEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...j.judge/entity/TestCaseRequestEntity.java → ...j/judge/entity/TestCaseRequestEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.inlighting.oj.judge.entity; | ||
package com.eagleoj.judge.entity; | ||
|
||
/** | ||
* @author Smith | ||
|
4 changes: 2 additions & 2 deletions
4
....judge/entity/TestCaseResponseEntity.java → .../judge/entity/TestCaseResponseEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...hting.oj.judge/judger/AbstractJudger.java → .../eagleoj/judge/judger/AbstractJudger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
...rg.inlighting.oj.judge/judger/Judger.java → ...java/com/eagleoj/judge/judger/Judger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
eagle-oj-judge/src/main/java/com/eagleoj/judge/judger/JudgerApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.eagleoj.judge.judger; | ||
|
||
import com.eagleoj.judge.entity.ResponseEntity; | ||
import com.eagleoj.judge.entity.RequestEntity; | ||
|
||
/** | ||
* @author Smith | ||
**/ | ||
public interface JudgerApi { | ||
ResponseEntity judge(String url, RequestEntity requestEntity) throws Exception; | ||
} |
97 changes: 97 additions & 0 deletions
97
eagle-oj-judge/src/main/java/com/eagleoj/judge/judger/eagle/Eagle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.eagleoj.judge.judger.eagle; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONArray; | ||
import com.alibaba.fastjson.JSONObject; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
import com.eagleoj.judge.ResultEnum; | ||
import com.eagleoj.judge.entity.TestCaseResponseEntity; | ||
import okhttp3.*; | ||
import com.eagleoj.judge.entity.RequestEntity; | ||
import com.eagleoj.judge.entity.ResponseEntity; | ||
import com.eagleoj.judge.judger.JudgerApi; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Smith | ||
**/ | ||
public class Eagle implements JudgerApi { | ||
|
||
private final OkHttpClient CLIENT = new OkHttpClient(); | ||
|
||
private String REQUEST_URL; | ||
|
||
private RequestEntity REQUEST_ENTITY; | ||
|
||
@Override | ||
public ResponseEntity judge(String url, RequestEntity requestEntity) throws Exception { | ||
REQUEST_URL = url+"/judge"; | ||
this.REQUEST_ENTITY = requestEntity; | ||
return send(); | ||
} | ||
|
||
private ResponseEntity send() throws Exception { | ||
Request request = new Request.Builder() | ||
.url(REQUEST_URL) | ||
.header("Content-Type", "application/json") | ||
.post(formRequestBody()) | ||
.build(); | ||
Response response = CLIENT.newCall(request).execute(); | ||
if (!response.isSuccessful()) { | ||
throw new IOException("Unexpected code " + response); | ||
} | ||
String json = response.body().string(); | ||
return parseResponse(json); | ||
} | ||
|
||
private RequestBody formRequestBody() { | ||
String json = JSON.toJSONString(REQUEST_ENTITY, SerializerFeature.WriteMapNullValue); | ||
return RequestBody | ||
.create(MediaType.parse("application/json;charset=utf-8"), json); | ||
} | ||
|
||
private ResponseEntity parseResponse(String json) throws Exception { | ||
JSONObject obj = JSON.parseObject(json); | ||
ResultEnum result = convertStringToResult(obj.getString("result")); | ||
if (result.equals(ResultEnum.SE)) { | ||
throw new Exception("远程判卷错误:"+obj.getString("error_message")); | ||
} | ||
|
||
JSONArray testCases = obj.getJSONArray("test_cases"); | ||
List<TestCaseResponseEntity> testCaseList = new ArrayList<>(testCases.size()); | ||
for (int i = 0; i<testCases.size(); i++) { | ||
JSONObject tempObj = testCases.getJSONObject(i); | ||
String tempErrorMessage = tempObj.getString("error_message"); | ||
ResultEnum tempResult = convertStringToResult(tempObj.getString("result")); | ||
TestCaseResponseEntity testCaseResponseEntity = new TestCaseResponseEntity(tempResult, tempErrorMessage); | ||
testCaseList.add(testCaseResponseEntity); | ||
} | ||
|
||
ResponseEntity responseEntity = new ResponseEntity(obj.getDouble("time"), obj.getInteger("memory"), | ||
result, testCaseList); | ||
return responseEntity; | ||
} | ||
|
||
private ResultEnum convertStringToResult(String result) { | ||
switch (result) { | ||
case "SE": | ||
return ResultEnum.SE; | ||
case "WA": | ||
return ResultEnum.WA; | ||
case "AC": | ||
return ResultEnum.AC; | ||
case "RTE": | ||
return ResultEnum.RTE; | ||
case "CE": | ||
return ResultEnum.CE; | ||
case "TLE": | ||
return ResultEnum.TLE; | ||
default: | ||
return ResultEnum.SE; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.