mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-22 15:28:41 +00:00
chore(web): add upgrader for #21
This commit is contained in:
parent
586df479f6
commit
83ffb72577
43
web/app/upgrade/21_problem_difficulty/upgrade.php
Normal file
43
web/app/upgrade/21_problem_difficulty/upgrade.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
return function ($type) {
|
||||
if ($type == 'up') {
|
||||
DB::init();
|
||||
|
||||
$problems = DB::selectAll("select * from problems");
|
||||
|
||||
foreach ($problems as $info) {
|
||||
$problem = new UOJProblem($info);
|
||||
|
||||
$difficulty = -1;
|
||||
$extra_config = $problem->getExtraConfig();
|
||||
|
||||
if (isset($extra_config['difficulty'])) {
|
||||
$old_difficulty = (float)$extra_config['difficulty'];
|
||||
|
||||
$difficulty = (int)(3.0 * $old_difficulty + 5) * 100;
|
||||
$difficulty = (function ($search, $arr) {
|
||||
$closest = null;
|
||||
foreach ($arr as $item) {
|
||||
if ($closest === null || abs($search - $closest) > abs($item - $search)) {
|
||||
$closest = $item;
|
||||
}
|
||||
}
|
||||
return $closest;
|
||||
})($difficulty, UOJProblem::$difficulty);
|
||||
}
|
||||
|
||||
DB::update([
|
||||
"update problems",
|
||||
"set", [
|
||||
"difficulty" => $difficulty,
|
||||
],
|
||||
"where", [
|
||||
"id" => $problem->info['id'],
|
||||
]
|
||||
]);
|
||||
|
||||
echo "Problem: {$problem->info['id']} ({$difficulty})\n";
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user