songHashMap now has the path
authorCameron Ball <cameron@moodle.com>
Wed, 8 May 2019 03:18:01 +0000 (11:18 +0800)
committerCameron Ball <cameron@moodle.com>
Wed, 8 May 2019 03:18:01 +0000 (11:18 +0800)
.gitignore
src/cachehashmap.php
src/gnb.php
src/prankdigest.php

index e269de0..d8e3fa3 100644 (file)
@@ -6,3 +6,4 @@ src/setWebHook.php
 tesseract.txt
 faves.txt
 composer.lock
+hashmap.txt
index 2698990..5504242 100644 (file)
@@ -2,8 +2,15 @@
 
 require('common.php');
 
+// $songHashMap = foldMap(
+//     ☐(∘(field(0), delemit(' ')))(∘(field(5), delemit('/')))
+// )(foldMap(∘(lines, 'trim', 'file_get_contents'))(glob(PATH_TO_GROOVENET . '/songs.*.txt')));
+
 $songHashMap = foldMap(
-    ☐(∘(field(0), delemit(' ')))(∘(field(5), delemit('/')))
+    function($line) {
+        $delim = delemit('/')($line);
+        return [explode(' ', $line)[0] => $delim[4] . '/' . $delim[5]];
+    }
 )(foldMap(∘(lines, 'trim', 'file_get_contents'))(glob(PATH_TO_GROOVENET . '/songs.*.txt')));
 
 file_put_contents(__DIR__ . '/hashmap.txt', serialize($songHashMap));
index 02f3ef4..413af56 100644 (file)
@@ -36,6 +36,7 @@ getTelegram()->addCommand(
             }
 
             $songs = map(function ($song) use ($arguments) {
+                $justTitle = explode('/', $song)[1];
                 similar_text(strtolower($arguments), strtolower($song), $perc);
                 return ['title' => $song, 'similarity' => $perc];
             })(unserialize(file_get_contents(__DIR__ . '/hashmap.txt')));
@@ -43,7 +44,7 @@ getTelegram()->addCommand(
 
             $this->replyWithMessage(
                 [
-                    'text' => "Here are the 5 most similar favourites I could find...\n\n" . $top5($songs)
+                    'text' => "Here are the 5 most similar songs I could find...\n\n" . $top5($songs)
                 ]
             );
         }
@@ -70,7 +71,7 @@ getTelegram()->addCommand(
             $hashes = map(map(☐(produceValue(0))(null)))(array_values($faveFiles));
             $songHashMap = unserialize(file_get_contents(__DIR__ . '/hashmap.txt'));
             $faveMap = ∘(map(∘(flip(concat)("'s Faves"), 'ucwords', field(0), delemit('.'), 'basename')), foldMap(☐(field(1))(field(0))), foldMap(id))(zzipWith(∘(map, aaray_merge))($names)($hashes));
-            $newFaves = zzipWith(∘(concat, flip(concat)(" in "), flip(field)($songHashMap)))(array_keys($faveMap))(array_values($faveMap));
+            $newFaves = zzipWith(∘(concat, flip(concat)(" in "), field(1), delemit(' '),  flip(field)($songHashMap)))(array_keys($faveMap))(array_values($faveMap));
 
             $thing = map(function ($fave) use ($arguments) {
                 $justTitle = join(' ', array_slice(explode(' ', $fave), 0 , -2));
@@ -131,7 +132,7 @@ getTelegram()->addCommand(
                     "——————————————\n",
                     $diffEmojiMap[$k[1]],
                     $k[2] == 'dance-double' ? $diffEmojiMap[$k[1]] : '',
-                    ' ' . $songHashMap[$k[0]],
+                    ' ' . explode('/', $songHashMap[$k[0]])[1],
                     "\n    ",
                     truncate($v*100, 2) . "%"
                 ]);
index f401759..96867f6 100644 (file)
@@ -34,6 +34,7 @@ $scoreTesseract = map(map(map(maxKey)))(
 $diff = array_diff_assoc_recursive($scoreTesseract, $oldScoreTesseract);
 $asdf = prefixKey('', $diff);
 $pranks = [];
+
 foreach ($asdf as $k => $v) {
     $k = explode('.', $k);
 
@@ -50,7 +51,7 @@ foreach ($asdf as $k => $v) {
             "——————————————\n",
             $diffEmojiMap[$k[1]],
             $k[2] == 'dance-double' ? $diffEmojiMap[$k[1]] : '',
-            ' ' . $songHashMap[$k[0]],
+            ' ' . explode('/', $songHashMap[$k[0]])[1],
             "\n",
             $k[3] . ": " . truncate($v*100, 2) . "%",
             " (was $scorer: " . truncate($score*100, 2) . "%)"
@@ -64,7 +65,7 @@ if ($pranks) {
 }
 
 $faveDiff = array_diff_assoc($faveMap, $oldFaveMap);
-$newFaves = zzipWith(∘(concat, flip(concat)(" in "), flip(field)($songHashMap)))(array_keys($faveDiff))(array_values($faveDiff));
+$newFaves = zzipWith(∘(concat, flip(concat)(" in "), field(1),delemit('/'), ∘(flip(field))($songHashMap)))(array_keys($faveDiff))(array_values($faveDiff));
 
 if ($pranks || $newFaves) {
     getTelegram()->sendMessage(