Skip to content

Commit 1965032

Browse files
authored
Merge pull request #1 from zhblue/master
test
2 parents 06946dc + e148295 commit 1965032

File tree

4 files changed

+91
-15
lines changed

4 files changed

+91
-15
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ Star us, please!
8787

8888
更新日志
8989
------
90+
2020-01-23 更新:修订了[Moodle集成代码](https://github.com/zhblue/hustoj/blob/master/wiki/MoodleIntegration.md),实现HUSTOJ给moodle系统作业自动判分。
91+
9092
2020-01-20 更新:删除noip模式比赛的多余提交记录,允许自定义“noip”关键词,增加privilege表user_id索引。
9193

9294
2019-12-19 更新:增加了judge.conf中的注释,提供了备案号变量$OJ_BEIAN,对系统判题时间分辨率进行了更新优化,提高灵活度。

trunk/install/README

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
HUSTOJ安装说明
22
by zhblue([email protected])
33

4-
debian8 可以用.deb文件安装
54

6-
https://github.com/muzea/hustoj-deb/issues/4
75

8-
9-
或者安装ubuntu16.04(拥有更新的编译器版本),然后用下面脚本快速安装OJ:
10-
11-
wget https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-ubuntu16+.sh
12-
sudo bash install-ubuntu16+.sh
13-
14-
https://www.youtube.com/watch?v=nlhmfZqyHnA
15-
16-
发烧级用户ubuntu18.04(至少1年以上debian系Linux使用经验,欢迎帮忙踩坑测试,有问题会尽快修复)
6+
小白用户推荐ubuntu18.04
177

188
wget https://github.com/zhblue/hustoj/raw/master/trunk/install/install-ubuntu18.04.sh
199
sudo bash install-ubuntu18.04.sh
2010

21-
假如你不得已非要用centos7 (有的语言可能不支持),可以用下面脚本快速安装OJ:  
11+
服务器无法安装ubuntu可以用centos7 (有的语言可能不支持),可以用下面脚本快速安装OJ:
2212

2313
wget https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-centos7.sh
2414
sudo bash install-centos7.sh

trunk/install/moodle.sql

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
DELIMITER $$
2+
DROP trigger IF EXISTS `jol`.`tri_moodle` $$
3+
create trigger tri_moodle
4+
after update on solution
5+
for each row
6+
begin
7+
declare mark int;
8+
declare total int;
9+
10+
select count(1) into total from contest_problem where contest_id=new.contest_id;
11+
if total>0 then
12+
select sum(ac)/total*100 into mark
13+
from (select max(pass_rate) ac from solution where user_id=new.user_id and contest_id=new.contest_id and problem_id>0 group by problem_id) s;
14+
15+
call update_moodle(new.contest_id,new.user_id,mark);
16+
17+
end if;
18+
end $$
19+
20+
21+
CREATE PROCEDURE `update_moodle`(IN `cid` INT, IN `user_id` VARCHAR(20), IN `mark` INT)
22+
top:BEGIN
23+
declare as_id int;
24+
declare u_id int;
25+
declare nowtime int;
26+
declare oldid int;
27+
set nowtime=UNIX_TIMESTAMP(now());
28+
set as_id=0;
29+
select m.id into as_id from
30+
moodle.mdl_assign m
31+
where m.name = concat('[OJ]-C',cid);
32+
if as_id=0 then
33+
leave top;
34+
end if;
35+
set u_id =-1;
36+
select m.id into u_id from moodle.mdl_user m where username=user_id;
37+
select mag.grade into oldid from moodle.mdl_assign_grades mag
38+
where assignment=as_id and userid=u_id;
39+
40+
set oldid=-1;
41+
42+
select id into oldid from moodle.mdl_assign_submission m
43+
where assignment=as_id and userid=u_id;
44+
if oldid =-1 then
45+
46+
insert into moodle.mdl_assign_submission
47+
(assignment,userid,timecreated,timemodified,status,attemptnumber)
48+
values( as_id ,u_id ,nowtime ,nowtime ,'new' ,0);
49+
insert into moodle.mdl_assign_grades(assignment,userid,timecreated,timemodified,grader,grade,attemptnumber)
50+
select ma.id,mas.userid,UNIX_TIMESTAMP( NOW( ) ),UNIX_TIMESTAMP( NOW( ) ),2,mark,0
51+
from moodle.mdl_assign ma
52+
inner join moodle.mdl_assign_submission mas on
53+
mas.assignment=ma.id and mas.status='new'
54+
where concat(ma.id,',',mas.userid) not in (select concat(assignment,',',userid) from moodle.mdl_assign_grades);
55+
56+
else
57+
58+
59+
update moodle.mdl_assign_grades
60+
set grade=mark,timemodified=nowtime where
61+
assignment=as_id and userid=u_id;
62+
63+
end if;
64+
65+
66+
END$$
67+
68+
69+
DELIMITER ;

wiki/MoodleIntegration.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Preparation 预备工作
1212
--
1313

1414
install hustoj using .sh script, add line before ```location / { ``` in /etc/nginx/sites-enbaled/default for install moodle
15+
1516
首先用脚本安装HUSTOJ,然后在/etc/nginx/sites-enbaled/default文件中```location / { ``` 这一行之前添加下面的内容:
1617

1718
```
@@ -34,31 +35,45 @@ sudo service nginx reload
3435
```
3536
install moodle 安装moodle
3637
--
38+
download moodle source files from [Moodle Download](https://download.moodle.org/releases/latest/)
39+
40+
[这里](https://download.moodle.org/releases/latest/)下载最新的moodle源码文件。
3741

3842
unzip/tar -xzf moodle files into /home/judge/src/web/
43+
3944
把下载到的moodle安装文件解压到/home/judge/src/web目录下,得到/home/judge/src/web/moodle目录
4045

4146
fix ownner of src
47+
4248
修改所有目录的属主为www-data
4349

4450
```
4551
chown -R www-data /home/judge/src/
4652
4753
```
4854
refresh OJ web will show the Moodle Link on top left, click to begain install moodle.
55+
4956
刷新OJ页,得到右上角的Moodle入口,点击开始安装流程。
5057

58+
**don't change the moodle default database name: moodle default table name prefix: mdl_**
59+
60+
**moodle的数据库默认moodle,表前缀mdl_ ,请不要修改**
61+
62+
5163
link two system 关联两个系统
5264
--
5365

5466
let students use same username in both system.
67+
5568
让学生在两个系统中用相同的用户名注册。
5669

5770

5871
add a contest in HUSTOJ for example Contest 1000
72+
5973
在HUSTOJ中添加一个比赛,获得比赛编号1000
6074

6175
add a text-homework in moodle with title [OJ]-C1000 for OJ Contest 1000.
76+
6277
在moodle中添加一个文本作业,标题命名为[OJ]-C1000,其中的1000表示OJ中对应的比赛编号。
6378

6479
add trigger 添加触发器
@@ -88,7 +103,7 @@ add procedure 添加存储过程
88103
--
89104
```
90105
DELIMITER $$
91-
CREATE DEFINER=`debian-sys-maint`@`localhost` PROCEDURE `update_moodle`(IN `cid` INT, IN `user_id` VARCHAR(20), IN `mark` INT)
106+
CREATE PROCEDURE `update_moodle`(IN `cid` INT, IN `user_id` VARCHAR(20), IN `mark` INT)
92107
top:BEGIN
93108
declare as_id int;
94109
declare u_id int;
@@ -140,10 +155,10 @@ DELIMITER ;
140155
Expecting Result 预期效果
141156
--
142157
when students submit solution in hustoj , moodle will show the latest mark for the contest in 0-100.
143-
当学生在hustoj中提交代码,moodle将在作业里同步显示他们的最新成绩。
144-
145158

159+
当学生在hustoj中提交代码,moodle将在作业里同步显示他们的最新成绩。
146160

161+
<img src="https://raw.githubusercontent.com/zhblue/hustoj/master/wiki/moodle.png" >
147162

148163

149164

0 commit comments

Comments
 (0)