diff --git a/app/Parser.php b/app/Parser.php index b74cf7b9f7..558ad20d22 100644 --- a/app/Parser.php +++ b/app/Parser.php @@ -2,12 +2,34 @@ namespace App; -use Exception; +use Throwable; + +use function Tempest\Support\Str\slice; final class Parser { + public function parse(string $inputPath, string $outputPath): void { - throw new Exception('TODO'); + $file = fopen($inputPath, "r"); + $arr = []; + $row = fgets($file); + $originLength = strpos($row, '/', 8); + fseek($file, 0); + + while ($row = fgets($file)) { + [$url, $time] = explode(',', $row); + $url = substr($url, $originLength); + $time = substr($time, 0, 10); + $arr[$url][$time] ??= 0; + $arr[$url][$time]++; + } + fclose($file); + foreach ($arr as &$xf2) { + ksort($xf2, SORT_STRING); + } + $f = fopen($outputPath, "w"); + fwrite($f, json_encode($arr, JSON_PRETTY_PRINT)); + fclose($f); } } \ No newline at end of file