Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $prefix = 'D:\\Users\\Nicholas\\AppData\\Roaming\\TS3Client\\chats\\M1dQMnhKRVE3RHBjd3luMTdCcG8xOVBpMUZ3PQ==';
- $years = array('2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017');
- $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
- $filename = 'channel_';
- $extension = '.txt';
- $games = array();
- foreach ($years as $year) {
- foreach ($months as $month) {
- $file = $prefix . '\\' . $year . '\\' . $filename . $year . '-' . $month . $extension;
- if (!file_exists($file)) {
- continue;
- }
- //error_log('Opening file ' . $file);
- $sourceFile = fopen($file, 'r');
- if ($sourceFile === false) {
- error_log("Could not open " . $file . "\n");
- continue;
- }
- $currentDate = null;
- $lastPlayedDate = null;
- while (($line = fgets($sourceFile)) !== false) {
- $chatBegins = strpos($line, '*** Chat begins');
- if ($chatBegins !== false) {
- $currentDate = null;
- $dateHeader = substr($line, $chatBegins + 15, strlen($line));
- //error_log('Parsing date: ' . trim($dateHeader));
- $dateErrors = array();
- $formats = array('n/j/Y g:i:s A', 'y/m/d g:i:s A', 'Y/m/d g:i:s A', 'Y-m-d g:i:s A', 'Y-m-d G:i:s');
- for ($i = 0; $i < count($formats); $i++) {
- if ($currentDate != null) {
- break;
- }
- $currentDate = \DateTime::createFromFormat($formats[$i], trim($dateHeader));
- if ($currentDate === false) {
- $dateErrors[] = \DateTime::getLastErrors();
- //error_log('Could not parse with format ' . $formats[$i]);
- $currentDate = null;
- continue;
- }
- if ($currentDate > (new \DateTime())->setTimestamp(time()) || $currentDate < new \DateTime('2010-01-01 00:00:00')) {
- //error_log('Parsed invalid date ' . $currentDate->format('c') . ' from format ' . $formats[$i]);
- $currentDate = null;
- }
- }
- if ($currentDate == null) {
- var_dump($dateErrors);
- throw new Exception('Could not parse any dates.');
- }
- }
- $lastPlayed = strpos($line, 'Last played ');
- if ($lastPlayed !== false) {
- //error_log(trim($line));
- //$lastPlayedHeader = substr($line, $lastPlayed - 11, 10);
- // Remove timestamp
- $lastPlayedHeader = substr($line, 11);
- $lastPlayedHeader = trim(explode(':', $lastPlayedHeader, 2)[1]);
- $lastPlayedDate = null;
- $lastPlayedDateString = null;
- for ($i = 0; $i < strlen($lastPlayedHeader); $i++) {
- $lastPlayedDateString = substr($lastPlayedHeader, $i, 10);
- $lastPlayedDate = \DateTime::createFromFormat('Y-m-d', $lastPlayedDateString);
- if ($lastPlayedDate !== false) {
- break;
- }
- }
- if ($lastPlayedDate == null) {
- error_log('Last played line has no date: ');
- error_log(trim($line));
- continue;
- }
- $game = trim(substr($line, $lastPlayed + 12));
- switch ($game) {
- case 'Age of Empires III':
- case 'Age of Empires III: Complete Collection':
- $game = "Age of Empires® III: Complete Collection"; // \u00AE
- break;
- case 'Age pf Empires Online':
- $game = 'Age of Empires Online';
- break;
- case 'Amnesia: The Dark Descent.':
- $game = 'Amnesia: The Dark Descent';
- break;
- case 'Assassin\'s Creed 2 | Started 2015-12-08 12:16:40 AM':
- $game = 'Assassin\'s Creed 2';
- break;
- case 'BioShock Infinite.':
- $game = 'BioShock Infinite';
- break;
- case 'Battle.Net / Overwatch':
- $game = 'Overwatch';
- break;
- case 'Borderlands (1)':
- $game = 'Borderlands';
- break;
- case 'Borderladns 2':
- $game = 'Borderlands 2';
- break;
- case 'Borderlands: Pre-Sequel':
- $game = 'Borderlands: The Pre-Sequel';
- break;
- case 'Dungeon Defender':
- $game = 'Dungeon Defenders';
- break;
- case 'Empires/Source SDK Base 2007':
- case 'Source SDK Base 2007 (Empires)':
- $game = 'Empires';
- break;
- case 'Fable III - Hero 1':
- case 'Fable III via Steam':
- $game = 'Fable III';
- break;
- case 'CS: GO':
- $game = 'Counter-Strike: Global Offensive';
- break;
- case 'Garry\'s MOd':
- $game = 'Garry\'s Mod';
- break;
- case 'Grand Theft Auto: V':
- $game = 'Grand Theft Auto V';
- break;
- case 'Guns of Icarus/Flight of the Icarus':
- $game = 'Guns of Icarus';
- break;
- case 'Guns of Icarus Onlnie':
- $game = 'Guns of Icarus Online';
- break;
- case 'Killing Floor 2 [preview 8.15]':
- case 'Killing Floor 2 [preview.8.15]':
- case 'Killing Floor 2 [preview]':
- $game = 'Killing Floor 2';
- break;
- case 'Lambda Wars Beta':
- $game = 'Lambda Wars';
- break;
- case 'Mare Nostrum: 2012-10-25.':
- $game = 'Mare Nostrum';
- break;
- case 'Nuclear Dasn':
- case 'Nuclear Dawn***':
- case 'Nuclear Dawn.':
- $game = 'Nuclear Dawn';
- break;
- case 'PAYDYA 2':
- case 'PAYDYA 21':
- case 'PayDay 2':
- $game = 'PAYDAY 2';
- break;
- case 'Portal 2 (Last installed?)':
- $game = 'Portal 2';
- break;
- case 'Red Orchestra 2: Heroes of Stalingrad - Single Player | Last finished Mission 11':
- $game = 'Red Orchestra 2: Heroes of Stalingrad - Single Player';
- break;
- case 'Rising Storm/Red Orchestra 2':
- case 'Red Orchestra 2: Heroes of Stalingrad Multiplayer':
- case 'Rising Storm/Red Orchestra 2 Multipolayer':
- $game = 'Rising Storm/Red Orchestra 2 Multiplayer';
- break;
- case 'RuneScape 2012-07-12':
- $game = 'RuneScape';
- break;
- case 'Skull Girls':
- case 'SkullGirls':
- $game = 'Skullgirls';
- break;
- case 'Terraria - Played 2015-06-26':
- case 'Terraria. Played 2015-06-26.':
- $game = 'Terraria';
- break;
- case 'The Ultimate Doom':
- $game = 'The Ultimate DOOM';
- break;
- case 'Tomc Clancy\'s Rainbow Six Siege':
- $game = 'Tom Clancy\'s Rainbow Six Siege';
- break;
- }
- $newCheck = substr($line, $lastPlayed - 15, 3);
- if ($newCheck == 'New') {
- error_log('Last played on ' . $lastPlayedDateString . ', new game ' . $game);
- continue;
- }
- error_log('Last played on ' . $lastPlayedDateString . ', game ' . $game);
- }
- if ($currentDate != null && $lastPlayedDate != null) {
- if (!isset($games[$game])) {
- $games[$game] = array();
- }
- $games[$game][] = array($lastPlayedDate, $currentDate);
- $game = null;
- $lastPlayedDate = null;
- }
- }
- fclose($sourceFile);
- }
- }
- ksort($games);
- /*foreach ($games as $game => $entries) {
- if (count($entries) > 1) {
- error_log($game);
- foreach ($entries as $entry) {
- error_log($entry[0]->format('Y-m-d') . ' ' . $entry[1]->format('Y-m-d'));
- }
- }
- }*/
- // Decimal date is days from 12/30/1899. 2013-01-01 is 41275.00. 2013-02-08 is 41313.00, Today is 42848.
- error_log('---------- Printing graph data... ----------');
- $counter = 1;
- error_log('games,game_id,start_date,elapsed_time,end_date');
- foreach ($games as $game => $entries) {
- if (count($entries) > 1) {
- for ($i = 0; $i < count($entries); $i++) {
- //error_log($entry[0]->format('Y-m-d') . ' ' . $entry[1]->format('Y-m-d'));
- error_log($game . ',' . $counter . ',' . $entries[$i][1]->format('Y-m-d') . ',' . (($entries[$i + 1][0]->diff($entries[$i][1])->format('%d') + 1) * 24) . ':00' . ',' . $entries[$i + 1][0]->format('Y-m-d'));
- if ($i >= count($entries) - 2) {
- break;
- }
- }
- $counter++;
- }
- }
- error_log('---------- Printing graph legend... ----------');
- $counter = 1;
- foreach ($games as $game => $entries) {
- if (count($entries) > 1) {
- error_log($game . ',' . $counter);
- $counter++;
- }
- }
- error_log('---------- Games without a second entry... ----------');
- foreach ($games as $game => $entries) {
- if (count($entries) == 1) {
- error_log($game);
- }
- }
- //var_dump($games);
- exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement