Commit 29031d5e authored by w-mj's avatar w-mj

init git

parents
.idea/
result/
*.tar.gz
\ No newline at end of file
# GPU-Judge-v2
from postwork import postwork
from prework import prework
from run import run
import pygrading.general_test as gg
from utils import Env
if __name__ == '__main__':
env = Env()
env.load_config()
job = gg.Job(prework=prework, run=run, postwork=postwork, config=env.config)
job.start()
job.print()
import pygrading.general_test as gg
def postwork(job: gg.Job):
pass
import pygrading.general_test as gg
def prework(job: gg.Job):
pass
\ No newline at end of file
from pygrading.html import *
# data = {
# 'name': '4位全加器',
# 'score': 100,
# 'detail': [
# {'name': 'TestCase1', 'time': 750, 'stdout': "balabala", 'answer': "hahahahha", 'score': "14", 'verdict': 'Accept'},
# {'name': 'TestCase1', 'time': 750, 'stdout': "balabala", 'answer': "hahahahha", 'score': "14", 'verdict': 'Accept'},
# ]
# }
#
# title = ['name', 'score'] # 输出报告标头内容
# summary = ['name', 'time', 'score', 'verdict'] # 摘要内容
# details = ['input', 'stdout', 'answer'] # 细节内容
js = "<script>function ec(a){var b=document.getElementById(a);b.style.display=(b.style.display=='none')?'table':'none';}</script>"
def make_html(data, title, summary, details):
ans = make_title(data, title)
if summary and data.get('detail'):
ans += make_summary(data, summary, True if details else False)
if details:
ans += make_details(data, details)
ans += js
return ans
def make_title(data, title):
ans = div()
for key in title:
ans << h4().set_text(str2html(f'{key}: {data[key]}'))
return str(ans)
def make_summary(data, summary, have_details=False):
ans = table(border="1")
# 创建表头
thead = tr()
for key in summary:
thead << th().set_text(key)
# if have_details:
# thead << th().set_text('details')
ans << thead
# 创建表主体
for test in data['detail']:
# print(data)
row = tr()
for key in summary:
row << td().set_text(str2html(str(test[key])))
# if have_details:
# row << td().set_text(f"<button onclick=\"ec('{test['name']}d')\">expand/collapse</button>")
# row << td(a(onclick=f'ec("{test["name"]}d")').set_text('expand/collapse'))
ans << row
return str(ans)
def make_details(data, details):
ans = div()
for test in data['detail']:
tab = table(id=f"{test['name']}d", style="display: table", border="1")
# 创建表头
tab << tr(th(colspan=str(len(details))).set_text(test['name']))
thead = tr()
for key in details:
thead << th().set_text(key)
tab << thead
# 创建表主体
row = tr()
for key in details:
row << td().set_text(str2html(str(test[key])))
tab << row
ans << tab
return str(ans)
# verdicts = ['Accept', 'Accept', 'Wrong Answer']
def make_verdict(verdicts: list):
for x in verdicts:
if x not in ('Accept', 'AC'):
return x
return 'Accept'
import pygrading.general_test as gg
def run(job: gg.Job, testcase: gg.TestCases.SingleTestCase):
pass
import sys
import os
import pygrading.general_test as gg
import re
import tempfile
def Singleton(cls):
_instance = {}
def inner():
if cls not in _instance:
_instance[cls] = cls()
return _instance[cls]
return inner
@Singleton
class Env:
def __init__(self):
self.is_debug = False
self.config = {
'submit_dir': '/coursegrader/submit',
'testcase_dir': '/coursegrader/testdata',
'errcode': 0,
"exec_dir": tempfile.mkdtemp()
}
def load_config(self, config_src=None):
if os.environ.get("CONFIG_SRC"):
self.config.update(gg.load_config(os.environ.get("CONFIG_SRC")))
if not config_src:
config_src = os.path.join(self.config['testcase_dir'], "config.json")
if os.path.exists(config_src):
self.config.update(gg.load_config(config_src))
self.is_debug = self.config.get("debug", False)
if "testcase_num" not in self.config:
self.config["testcase_num"] = count_testcase(self.config["testcase_dir"])
self.config["exec_path"] = os.path.join(self.config["exec_dir"], "exec.out")
loge(self.config)
return self
def __getitem__(self, item):
return self.config[item]
def __setitem__(self, key, value):
self.config[key] = value
def loge(*args, **kwargs):
if Env().is_debug:
print(*args, file=sys.stderr, flush=True, **kwargs)
def count_testcase(input_dir: str):
input_dir = os.path.join(input_dir, "input")
testcase_num = len(list(filter(lambda x: re.match(r"input\d+\.txt", x), os.listdir(input_dir))))
return testcase_num
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment