Specify paths correctly
[GrooveNet.git] / test.php
1 <?php declare(strict_types=1);
2
3 require_once('bootstrap.php');
4
5 $c = array_map(
6 function($l) {
7 $split = explode(' ', $l, 2);
8 return ['hash' => $split[0], 'path' => explode('/', $split[1])[5]];
9 },
10 lines(trim(file_get_contents(glob(PATH_TO_GROOVENET . '/songs.*.txt')[0])))
11 );
12
13 $d = array_combine(array_column($c, 'hash'), array_column($c, 'path'));
14
15 $camFaves = lines(trim(file_get_contents(PATH_TO_GROOVENET . '/cam.favourites.txt')));
16 $jayceFaves = lines(trim(file_get_contents(PATH_TO_GROOVENET . '/jayce.favourites.txt')));
17 $allFaves = array_merge($camFaves, $jayceFaves);
18 $hashMap = unserialize(file_get_contents(PATH_TO_HASHMAP));
19
20 $camScores = array_reduce(
21 lines(trim(file_get_contents(PATH_TO_GROOVENET . '/cam.scores.txt'))),
22 function($c, $v) use ($d) {
23 $split = explode(':', $v);
24
25 return array_merge($c, isset($split[2]) ? [implode(":", [$split[0], $split[1], $split[2]]) => $split[3]] : []);
26 },
27 []
28 );
29
30 $jayceScores = array_reduce(
31 lines(trim(file_get_contents(PATH_TO_GROOVENET . '/jayce.scores.txt'))),
32 function($c, $v) use ($d) {
33 $split = explode(':', $v);
34
35 return array_merge($c, isset($split[2]) ? [implode(":", [$split[0], $split[1], $split[2]]) => $split[3]] : []);
36 },
37 []
38 );
39
40 $everything = array_reduce(
41 $allFaves,
42 function($c, $fave) use ($camScores, $jayceScores) {
43 $camCandidates = array_filter(
44 $camScores,
45 function($key) use ($fave) {
46 return strpos($key, $fave) !== false;
47 },
48 ARRAY_FILTER_USE_KEY
49 );
50
51 $jayceCandidates = array_filter(
52 $jayceScores,
53 function($key) use ($fave) {
54 return strpos($key, $fave) !== false;
55 },
56 ARRAY_FILTER_USE_KEY
57 );
58
59 $conflicts = array_intersect(array_keys($camCandidates), array_keys($jayceCandidates));
60 $nonConflicts = array_merge(
61 array_diff(array_keys($camCandidates), $conflicts),
62 array_diff(array_keys($jayceCandidates), $conflicts)
63 );
64
65 $soFar = array_map(function($nonConflict) use ($jayceCandidates, $camCandidates){
66 $e = explode(':', $nonConflict);
67 return isset($jayceCandidates[$nonConflict])
68 ? ['hash' => $e[0], 'diff' => $e[1], 'who' => 'JCE', 'score' => $jayceCandidates[$nonConflict]]
69 : ['hash' => $e[0], 'diff' => $e[1], 'who' => 'CAM', 'score' => $camCandidates[$nonConflict]];
70 }, $nonConflicts);
71
72 if ($conflicts = array_intersect(array_keys($camCandidates), array_keys($jayceCandidates))) {
73 $resolvedConflicts = array_map(function($conflict) use ($camCandidates, $jayceCandidates) {
74 $e = explode(':', $conflict);
75 return $camCandidates[$conflict] > $jayceCandidates[$conflict]
76 ? ['hash' => $e[0], 'diff' => $e[1], 'who' => 'JCE', 'score' => $jayceCandidates[$conflict]]
77 : ['hash' => $e[0], 'diff' => $e[1], 'who' => 'CAM', 'score' => $camCandidates[$conflict]];
78 //['who' => 'cam', 'key' => $conflict] : ['who' => 'jayce', 'key' => $conflict];
79 }, $conflicts);
80 }
81
82 $ret = array_merge($soFar, $resolvedConflicts ?? []);
83
84 // echo '<pre>';
85 // echo "ret is";
86 // print_r($ret);
87 // echo '</pre>';
88
89 if ($ret) {
90 return array_merge($c, $ret);
91 } else {
92 return array_merge($c, [['hash' => $fave, 'diff' => 'NONE', 'who' => 'NOONE', 'score' => 'NONE']]);
93 }
94 },
95 []
96 );
97
98 $camsFolder = array_filter(array_map(
99 function($row) use ($camFaves, $hashMap) {
100 if (in_array($row['hash'], $camFaves)) {
101 return [
102 explode('/', $hashMap[$row['hash']])[1],
103 $row['diff'],
104 $row['who'],
105 $row['score']
106 ];
107 }
108 },
109 $everything
110 ));
111
112 $jaycesFolder = array_filter(array_map(
113 function($row) use ($jayceFaves, $hashMap) {
114 if (in_array($row['hash'], $jayceFaves)) {
115 return [
116 explode('/', $hashMap[$row['hash']])[1],
117 $row['diff'],
118 $row['who'],
119 $row['score']
120 ];
121 }
122 },
123 $everything
124 ));
125
126 usort($camsFolder, function($a, $b) { return $a[0] <=> $b[0];});
127 usort($jaycesFolder, function($a, $b) { return $a[0] <=> $b[0];});
128
129 return ['cam' => $camsFolder, 'jayce' => $jaycesFolder];