Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.78 KB | None | 0 0
  1. <?php
  2.  
  3. $prefix = 'D:\\Users\\Nicholas\\AppData\\Roaming\\TS3Client\\chats\\M1dQMnhKRVE3RHBjd3luMTdCcG8xOVBpMUZ3PQ==';
  4. $years = array('2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017');
  5. $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
  6. $filename = 'channel_';
  7. $extension = '.txt';
  8.  
  9. $games = array();
  10.  
  11. foreach ($years as $year) {
  12. foreach ($months as $month) {
  13. $file = $prefix . '\\' . $year . '\\' . $filename . $year . '-' . $month . $extension;
  14.  
  15. if (!file_exists($file)) {
  16. continue;
  17. }
  18.  
  19. //error_log('Opening file ' . $file);
  20. $sourceFile = fopen($file, 'r');
  21. if ($sourceFile === false) {
  22. error_log("Could not open " . $file . "\n");
  23. continue;
  24. }
  25.  
  26. $currentDate = null;
  27. $lastPlayedDate = null;
  28. while (($line = fgets($sourceFile)) !== false) {
  29. $chatBegins = strpos($line, '*** Chat begins');
  30. if ($chatBegins !== false) {
  31. $currentDate = null;
  32. $dateHeader = substr($line, $chatBegins + 15, strlen($line));
  33. //error_log('Parsing date: ' . trim($dateHeader));
  34.  
  35. $dateErrors = array();
  36. $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');
  37. for ($i = 0; $i < count($formats); $i++) {
  38. if ($currentDate != null) {
  39. break;
  40. }
  41.  
  42. $currentDate = \DateTime::createFromFormat($formats[$i], trim($dateHeader));
  43. if ($currentDate === false) {
  44. $dateErrors[] = \DateTime::getLastErrors();
  45. //error_log('Could not parse with format ' . $formats[$i]);
  46. $currentDate = null;
  47. continue;
  48. }
  49.  
  50. if ($currentDate > (new \DateTime())->setTimestamp(time()) || $currentDate < new \DateTime('2010-01-01 00:00:00')) {
  51. //error_log('Parsed invalid date ' . $currentDate->format('c') . ' from format ' . $formats[$i]);
  52. $currentDate = null;
  53. }
  54. }
  55.  
  56. if ($currentDate == null) {
  57. var_dump($dateErrors);
  58. throw new Exception('Could not parse any dates.');
  59. }
  60. }
  61.  
  62. $lastPlayed = strpos($line, 'Last played ');
  63. if ($lastPlayed !== false) {
  64. //error_log(trim($line));
  65. //$lastPlayedHeader = substr($line, $lastPlayed - 11, 10);
  66. // Remove timestamp
  67. $lastPlayedHeader = substr($line, 11);
  68. $lastPlayedHeader = trim(explode(':', $lastPlayedHeader, 2)[1]);
  69.  
  70. $lastPlayedDate = null;
  71. $lastPlayedDateString = null;
  72. for ($i = 0; $i < strlen($lastPlayedHeader); $i++) {
  73. $lastPlayedDateString = substr($lastPlayedHeader, $i, 10);
  74. $lastPlayedDate = \DateTime::createFromFormat('Y-m-d', $lastPlayedDateString);
  75. if ($lastPlayedDate !== false) {
  76. break;
  77. }
  78. }
  79.  
  80. if ($lastPlayedDate == null) {
  81. error_log('Last played line has no date: ');
  82. error_log(trim($line));
  83. continue;
  84. }
  85.  
  86. $game = trim(substr($line, $lastPlayed + 12));
  87. switch ($game) {
  88. case 'Age of Empires III':
  89. case 'Age of Empires III: Complete Collection':
  90. $game = "Age of Empires® III: Complete Collection"; // \u00AE
  91. break;
  92.  
  93. case 'Age pf Empires Online':
  94. $game = 'Age of Empires Online';
  95. break;
  96.  
  97. case 'Amnesia: The Dark Descent.':
  98. $game = 'Amnesia: The Dark Descent';
  99. break;
  100.  
  101. case 'Assassin\'s Creed 2 | Started 2015-12-08 12:16:40 AM':
  102. $game = 'Assassin\'s Creed 2';
  103. break;
  104.  
  105. case 'BioShock Infinite.':
  106. $game = 'BioShock Infinite';
  107. break;
  108.  
  109. case 'Battle.Net / Overwatch':
  110. $game = 'Overwatch';
  111. break;
  112.  
  113. case 'Borderlands (1)':
  114. $game = 'Borderlands';
  115. break;
  116.  
  117. case 'Borderladns 2':
  118. $game = 'Borderlands 2';
  119. break;
  120.  
  121. case 'Borderlands: Pre-Sequel':
  122. $game = 'Borderlands: The Pre-Sequel';
  123. break;
  124.  
  125. case 'Dungeon Defender':
  126. $game = 'Dungeon Defenders';
  127. break;
  128.  
  129. case 'Empires/Source SDK Base 2007':
  130. case 'Source SDK Base 2007 (Empires)':
  131. $game = 'Empires';
  132. break;
  133.  
  134. case 'Fable III - Hero 1':
  135. case 'Fable III via Steam':
  136. $game = 'Fable III';
  137. break;
  138.  
  139. case 'CS: GO':
  140. $game = 'Counter-Strike: Global Offensive';
  141. break;
  142.  
  143. case 'Garry\'s MOd':
  144. $game = 'Garry\'s Mod';
  145. break;
  146.  
  147. case 'Grand Theft Auto: V':
  148. $game = 'Grand Theft Auto V';
  149. break;
  150.  
  151. case 'Guns of Icarus/Flight of the Icarus':
  152. $game = 'Guns of Icarus';
  153. break;
  154.  
  155. case 'Guns of Icarus Onlnie':
  156. $game = 'Guns of Icarus Online';
  157. break;
  158.  
  159. case 'Killing Floor 2 [preview 8.15]':
  160. case 'Killing Floor 2 [preview.8.15]':
  161. case 'Killing Floor 2 [preview]':
  162. $game = 'Killing Floor 2';
  163. break;
  164.  
  165. case 'Lambda Wars Beta':
  166. $game = 'Lambda Wars';
  167. break;
  168.  
  169. case 'Mare Nostrum: 2012-10-25.':
  170. $game = 'Mare Nostrum';
  171. break;
  172.  
  173. case 'Nuclear Dasn':
  174. case 'Nuclear Dawn***':
  175. case 'Nuclear Dawn.':
  176. $game = 'Nuclear Dawn';
  177. break;
  178.  
  179. case 'PAYDYA 2':
  180. case 'PAYDYA 21':
  181. case 'PayDay 2':
  182. $game = 'PAYDAY 2';
  183. break;
  184.  
  185. case 'Portal 2 (Last installed?)':
  186. $game = 'Portal 2';
  187. break;
  188.  
  189. case 'Red Orchestra 2: Heroes of Stalingrad - Single Player | Last finished Mission 11':
  190. $game = 'Red Orchestra 2: Heroes of Stalingrad - Single Player';
  191. break;
  192.  
  193. case 'Rising Storm/Red Orchestra 2':
  194. case 'Red Orchestra 2: Heroes of Stalingrad Multiplayer':
  195. case 'Rising Storm/Red Orchestra 2 Multipolayer':
  196. $game = 'Rising Storm/Red Orchestra 2 Multiplayer';
  197. break;
  198.  
  199. case 'RuneScape 2012-07-12':
  200. $game = 'RuneScape';
  201. break;
  202.  
  203. case 'Skull Girls':
  204. case 'SkullGirls':
  205. $game = 'Skullgirls';
  206. break;
  207.  
  208. case 'Terraria - Played 2015-06-26':
  209. case 'Terraria. Played 2015-06-26.':
  210. $game = 'Terraria';
  211. break;
  212.  
  213. case 'The Ultimate Doom':
  214. $game = 'The Ultimate DOOM';
  215. break;
  216.  
  217. case 'Tomc Clancy\'s Rainbow Six Siege':
  218. $game = 'Tom Clancy\'s Rainbow Six Siege';
  219. break;
  220. }
  221.  
  222. $newCheck = substr($line, $lastPlayed - 15, 3);
  223. if ($newCheck == 'New') {
  224. error_log('Last played on ' . $lastPlayedDateString . ', new game ' . $game);
  225. continue;
  226. }
  227.  
  228. error_log('Last played on ' . $lastPlayedDateString . ', game ' . $game);
  229. }
  230.  
  231. if ($currentDate != null && $lastPlayedDate != null) {
  232. if (!isset($games[$game])) {
  233. $games[$game] = array();
  234. }
  235. $games[$game][] = array($lastPlayedDate, $currentDate);
  236. $game = null;
  237. $lastPlayedDate = null;
  238. }
  239. }
  240.  
  241. fclose($sourceFile);
  242. }
  243. }
  244.  
  245. ksort($games);
  246. /*foreach ($games as $game => $entries) {
  247. if (count($entries) > 1) {
  248. error_log($game);
  249. foreach ($entries as $entry) {
  250. error_log($entry[0]->format('Y-m-d') . ' ' . $entry[1]->format('Y-m-d'));
  251. }
  252. }
  253. }*/
  254.  
  255. // Decimal date is days from 12/30/1899. 2013-01-01 is 41275.00. 2013-02-08 is 41313.00, Today is 42848.
  256.  
  257. error_log('---------- Printing graph data... ----------');
  258. $counter = 1;
  259. error_log('games,game_id,start_date,elapsed_time,end_date');
  260. foreach ($games as $game => $entries) {
  261. if (count($entries) > 1) {
  262. for ($i = 0; $i < count($entries); $i++) {
  263. //error_log($entry[0]->format('Y-m-d') . ' ' . $entry[1]->format('Y-m-d'));
  264. 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'));
  265.  
  266. if ($i >= count($entries) - 2) {
  267. break;
  268. }
  269. }
  270. $counter++;
  271. }
  272. }
  273.  
  274. error_log('---------- Printing graph legend... ----------');
  275. $counter = 1;
  276. foreach ($games as $game => $entries) {
  277. if (count($entries) > 1) {
  278. error_log($game . ',' . $counter);
  279. $counter++;
  280. }
  281. }
  282.  
  283. error_log('---------- Games without a second entry... ----------');
  284. foreach ($games as $game => $entries) {
  285. if (count($entries) == 1) {
  286. error_log($game);
  287. }
  288. }
  289. //var_dump($games);
  290. exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement