-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathupgrade.php
More file actions
91 lines (74 loc) · 1.97 KB
/
Copy pathupgrade.php
File metadata and controls
91 lines (74 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
return function ($type) {
if ($type == 'up_after_sql') {
DB::init();
for ($i = 0; $i < 10; $i++) {
for ($j = 0; $j < 10; $j++) {
echo "Tag: {$i}.{$j}\n";
$tag_info = DB::selectAll([
"select *",
"from problems_tags",
"where", [
"tag" => "{$i}.{$j}",
]
]);
foreach ($tag_info as $tag) {
DB::delete([
"delete from problems_tags",
"where", [
"id" => $tag['id'],
],
]);
$problem = UOJProblem::query($tag['problem_id']);
$extra_config = $problem->getExtraConfig();
$extra_config['difficulty'] = doubleval("{$i}.{$j}");
DB::update([
"update problems",
"set", [
"extra_config" => json_encode($extra_config, JSON_FORCE_OBJECT),
],
"where", [
"id" => $problem->info['id'],
],
]);
echo "{$problem->info['id']}: {$extra_config['difficulty']}\n";
}
}
}
echo "Tag: DONE";
$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 = $extra_config['difficulty'];
if (0 <= $old_difficulty && $old_difficulty < 2) {
$difficulty = 1;
} else if (2 <= $old_difficulty && $old_difficulty < 3) {
$difficulty = 2;
} else if (3 <= $old_difficulty && $old_difficulty < 4) {
$difficulty = 2;
} else if (4 <= $old_difficulty && $old_difficulty < 5) {
$difficulty = 4;
} else if (5 <= $old_difficulty && $old_difficulty < 6) {
$difficulty = 6;
} else if (6 <= $old_difficulty && $old_difficulty < 8) {
$difficulty = 8;
} else if (8 <= $old_difficulty) {
$difficulty = 10;
}
}
DB::update([
"update problems",
"set", [
"difficulty" => $difficulty,
],
"where", [
"id" => $problem->info['id'],
]
]);
echo "Problem: {$problem->info['id']}";
}
}
};