-
Notifications
You must be signed in to change notification settings - Fork 3
/
groups.php
77 lines (51 loc) · 1.73 KB
/
groups.php
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
<?php
ini_set('max_execution_time', 0);
ini_set('memory_limit', -1);
require_once(__DIR__ . '/common/reduce.php');
require_once(__DIR__ . '/common/map.php');
require_once(__DIR__ . '/common/neighbor.php');
require_once(__DIR__ . '/common/merge.php');
require_once(__DIR__ . '/common/group.php');
$start_time = time();
$articles = json_decode(file_get_contents(__DIR__ . '/articles.json'), true);
$skips = array();
foreach ($articles as $key => $article) {
if (isset($article['mode']) && $article['mode'] === '廣編特輯') {
$skips[$key] = true;
}
}
$keywords = json_decode(file_get_contents(__DIR__ . '/keywords.json'), true);
$map = merge(map($keywords, $skips, 100, 25), map($keywords, $skips, 400, 80));
$map = merge($map, neighbor($articles, $keywords, $skips, 0, 400, 50));
$groups = group($map);
usort($groups, function ($a, $b) {
global $articles;
$score = 0;
$order = 0;
foreach (array_keys($a) as $key) {
$article = $articles[$key];
$score += $article['score'];
$order += $article['order'];
}
$score2 = 0;
$order2 = 0;
foreach (array_keys($b) as $key) {
$article = $articles[$key];
$score2 += $article['score'];
$order2 += $article['order'];
}
return $score === $score2 ? $order - $order2 : $score2 - $score;
});
foreach ($groups as &$group) {
uksort($group, function ($a, $b) {
global $articles;
$article = $articles[$a];
$article2 = $articles[$b];
$score = $article2['score'] - $article['score'];
return $score === 0 ? $article['order'] - $article2['order'] : $score;
});
}
file_put_contents(__DIR__ . '/groups/taiwan.json', json_encode($groups));
$spent_time = time() - $start_time;
echo "Spent: $spent_time sec\n";
?>