Skip to content

Commit

Permalink
Merge pull request Eagle-OJ#17 from Eagle-OJ/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
JackGouDan authored Feb 10, 2018
2 parents 41681f3 + a8b27d5 commit 218dcb6
Show file tree
Hide file tree
Showing 304 changed files with 9,940 additions and 6,140 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
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
225 changes: 186 additions & 39 deletions design/database.sql

Large diffs are not rendered by default.

50 changes: 0 additions & 50 deletions design/judger_standard.json

This file was deleted.

4 changes: 2 additions & 2 deletions eagle-oj-judge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>eagle-oj</artifactId>
<groupId>org.inlighting.oj</groupId>
<version>1.0-SNAPSHOT</version>
<groupId>com.eagleoj</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.inlighting.oj.judge;
package com.eagleoj.judge;

/**
* @author Smith
**/
public enum LanguageEnum {
JAVA8("Java8"), PYTHON27("Python2.7"), PYTHON36("Python3.6"), CPP("C++"), C("C");
JAVA8("Java8"), PYTHON27("Python2.7"), PYTHON35("Python3.5"), CPP("C++"), C("C");

private String name;

Expand Down
39 changes: 39 additions & 0 deletions eagle-oj-judge/src/main/java/com/eagleoj/judge/Main.java
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());
}
}
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.inlighting.oj.judge.entity;
package com.eagleoj.judge.entity;

import com.alibaba.fastjson.annotation.JSONField;
import org.inlighting.oj.judge.LanguageEnum;
import com.eagleoj.judge.LanguageEnum;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.inlighting.oj.judge.entity;
package com.eagleoj.judge.entity;

import com.alibaba.fastjson.annotation.JSONField;
import org.inlighting.oj.judge.ResultEnum;
import com.eagleoj.judge.ResultEnum;

import java.util.List;

Expand Down
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.inlighting.oj.judge.entity;
package com.eagleoj.judge.entity;

import com.alibaba.fastjson.annotation.JSONField;
import org.inlighting.oj.judge.ResultEnum;
import com.eagleoj.judge.ResultEnum;

/**
* @author Smith
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.inlighting.oj.judge.judger;
package com.eagleoj.judge.judger;

import org.inlighting.oj.judge.entity.ResponseEntity;
import com.eagleoj.judge.entity.ResponseEntity;

/**
* @author Smith
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.inlighting.oj.judge.judger;
package com.eagleoj.judge.judger;

import com.alibaba.fastjson.JSON;
import org.inlighting.oj.judge.ResultEnum;
import org.inlighting.oj.judge.entity.RequestEntity;
import org.inlighting.oj.judge.entity.ResponseEntity;
import org.inlighting.oj.judge.entity.TestCaseResponseEntity;
import com.eagleoj.judge.ResultEnum;
import com.eagleoj.judge.entity.RequestEntity;
import com.eagleoj.judge.entity.ResponseEntity;
import com.eagleoj.judge.entity.TestCaseResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
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;
}
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;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.inlighting.oj.judge.judger.judge0;
package com.eagleoj.judge.judger.judge0;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import org.inlighting.oj.judge.LanguageEnum;
import org.inlighting.oj.judge.ResultEnum;
import org.inlighting.oj.judge.entity.RequestEntity;
import org.inlighting.oj.judge.entity.ResponseEntity;
import org.inlighting.oj.judge.entity.TestCaseRequestEntity;
import org.inlighting.oj.judge.entity.TestCaseResponseEntity;
import org.inlighting.oj.judge.judger.JudgerApi;
import com.eagleoj.judge.LanguageEnum;
import com.eagleoj.judge.ResultEnum;
import com.eagleoj.judge.entity.RequestEntity;
import com.eagleoj.judge.entity.ResponseEntity;
import com.eagleoj.judge.entity.TestCaseRequestEntity;
import com.eagleoj.judge.entity.TestCaseResponseEntity;
import com.eagleoj.judge.judger.JudgerApi;

import java.io.IOException;
import java.text.DecimalFormat;
Expand All @@ -21,7 +21,7 @@
**/
public class Judge0 implements JudgerApi {

private final OkHttpClient client = new OkHttpClient();
private final OkHttpClient CLIENT = new OkHttpClient();

private String REQUEST_URL = null;

Expand Down Expand Up @@ -86,7 +86,7 @@ private ResponseEntity judgeEach(int index) throws Exception {
.post(formBody)
.build();
String json = null;
try (Response response = client.newCall(request).execute()) {
try (Response response = CLIENT.newCall(request).execute()) {
if (! response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
Expand All @@ -95,15 +95,9 @@ private ResponseEntity judgeEach(int index) throws Exception {
return parse(json);
}

private ResponseEntity parse(String json) {
private ResponseEntity parse(String json) throws Exception {
// System.out.println(json);
JSONObject jsonObject = JSON.parseObject(json);
if (json == null) {
List<TestCaseResponseEntity> testCases = new ArrayList<>(1);
TestCaseResponseEntity testCase = new TestCaseResponseEntity(ResultEnum.SE, ResultEnum.SE.getName());
testCases.add(testCase);
return new ResponseEntity(0, 0, ResultEnum.SE, testCases);
}
JSONObject status = jsonObject.getJSONObject("status");
ResultEnum result = getResult(status.getInteger("id"));
double time = 0;
Expand Down Expand Up @@ -158,8 +152,8 @@ private int getLanguageId(LanguageEnum lang) {
switch (lang) {
case JAVA8:
return 27;
case PYTHON36:
return 34;
case PYTHON35:
return 35;
case PYTHON27:
return 36;
case C:
Expand Down
Loading

0 comments on commit 218dcb6

Please sign in to comment.