Skip to content

Commit

Permalink
Add initial support for contest penalty config
Browse files Browse the repository at this point in the history
  • Loading branch information
bobby285271 committed Oct 18, 2021
1 parent 5315f4c commit 0a2bfcc
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SCNUOJ 可对用户在线提交的源代码进行编译和执行,并通过预
### 华南师大软院在线评测系统

- [oj.socoding.cn](https://oj.socoding.cn/) - 外网入口
- [oj-internal.socoding.cn](https://oj-internal.socoding.cn/) - 校园网入口
- [10.191.65.243:5000](http://10.191.65.243:5000/) - 校园网入口

### 帮助文档

Expand Down
3 changes: 2 additions & 1 deletion messages/zh-CN/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,6 @@
'Current time' => '当前时间',
'Register' => '注册',
'Kanban' => '看板',
'The submission interval is %d seconds, and you can submit again after %d seconds.' => '提交间隔为 %d 秒,%d 秒后可以再次提交。'
'The submission interval is %d seconds, and you can submit again after %d seconds.' => '提交间隔为 %d 秒,%d 秒后可以再次提交。',
'Punish time' => '罚时'
];
40 changes: 40 additions & 0 deletions migrations/m211018_061720_add_contest_penalty_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use yii\db\Migration;

/**
* Class m211018_061720_add_contest_penalty_config
*/
class m211018_061720_add_contest_penalty_config extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%contest}}', 'punish_time', $this->smallInteger()->defaultValue(20));
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('{{%contest}}', 'punish_time');
}

/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m211018_061720_add_contest_penalty_config cannot be reverted.\n";
return false;
}
*/
}
7 changes: 5 additions & 2 deletions models/Contest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @property int $created_by
* @property string $ext_link
* @property string $invite_code
* @property int $punish_time
*/
class Contest extends \yii\db\ActiveRecord
{
Expand Down Expand Up @@ -85,7 +86,7 @@ public function rules()
[['title', 'start_time', 'end_time'], 'required'],
[['start_time', 'end_time', 'lock_board_time'], 'safe'],
[['description', 'editorial', 'invite_code', 'ext_link'], 'string'],
[['id', 'status', 'type', 'scenario', 'created_by', 'group_id', 'enable_print', 'enable_clarify'], 'integer'],
[['id', 'status', 'type', 'scenario', 'created_by', 'group_id', 'enable_print', 'enable_clarify', 'punish_time'], 'integer'],
[['title'], 'string', 'max' => 255],
];
}
Expand All @@ -108,6 +109,7 @@ public function attributeLabels()
'scenario' => Yii::t('app', 'Scenario'),
'ext_link' => '站外比赛',
'invite_code' => '邀请码',
'punish_time' => '罚时',
];
}

Expand Down Expand Up @@ -435,6 +437,7 @@ public function getICPCRankData($lock = true, $endtime = null)
$start_time = strtotime($this->start_time);
$lock_time = 0x7fffffff;
$contest_end_time = strtotime($this->end_time);
$punish_time = intval($this->punish_time ?? 20);
if ($endtime == null) {
$endtime = $contest_end_time;
}
Expand Down Expand Up @@ -528,7 +531,7 @@ public function getICPCRankData($lock = true, $endtime = null)
} else {
$result[$user]['ac_time'][$pid] = 0;
}
$result[$user]['time'] += $sec + $result[$user]['wa_count'][$pid] * 60 * 20;
$result[$user]['time'] += $sec + $result[$user]['wa_count'][$pid] * 60 * $punish_time;
} else if ($row['result'] <= 3) {
// 还未测评
++$result[$user]['pending'][$pid];
Expand Down
6 changes: 6 additions & 0 deletions modules/admin/views/contest/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
])->label(false) ?>
<p></p>

<div class="alert alert-light"><i class="fas fa-fw fa-info-circle"></i> 设置比赛的罚时(分钟),仅在 ICPC 赛制生效,不填则默认 20 分钟。</div>
<?= $form->field($model, 'punish_time', [
'template' => "<div class=\"input-group\"><div class=\"input-group-prepend\"><span class=\"input-group-text\">罚时</span></div>{input}</div>",
'options' => ['class' => '']
])->textInput()->label(false) ?>
<p></p>

<div class="alert alert-light"><i class="fas fa-fw fa-info-circle"></i> 设置比赛可见性。公开:任何用户均可参加比赛,若启用邀请码则正确填写邀请码的用户均可参赛。私有:任何时候比赛均只能由参赛用户访问,且比赛用户需要在后台手动添加。隐藏:前台无法看到比赛。</div>

Expand Down
1 change: 1 addition & 0 deletions modules/admin/views/contest/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
$model->scenario = $model::SCENARIO_ONLINE;
$model->enable_clarify = 1;
$model->enable_print = 0;
$model->punish_time = 20; //罚时初始值
?>
<div class="contest-create">

Expand Down
1 change: 1 addition & 0 deletions modules/admin/views/contest/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
'end_time',
'lock_board_time',
'description:html',
'punish_time',
],
]) ?>
</div>
Expand Down

0 comments on commit 0a2bfcc

Please sign in to comment.