PageRenderTime 35ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/index.php

https://gitlab.com/novadeviator/distrokid-analytics
PHP | 226 lines | 159 code | 59 blank | 8 comment | 11 complexity | e9f3a8adde3a5973e931fb0c8b84351b MD5 | raw file
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>DistroKid simple analytics</title>
  6. <!--
  7. A simple hack to get a better view of yourDistroKid stats.
  8. See http://gitlab.com/novadeviator/distrokid-analytics/ for
  9. the full code and how to use it by yourself on your server.
  10. -->
  11. <!-- Latest compiled and minified CSS -->
  12. <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  13. <!-- jQuery library -->
  14. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  15. <!-- Latest compiled JavaScript -->
  16. <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  17. <!-- masonry grid -->
  18. <script src="https://npmcdn.com/masonry-layout@4.0/dist/masonry.pkgd.min.js"></script>
  19. <style>
  20. table {
  21. border-spacing: 20px 2px;
  22. border-collapse: separate;
  23. width:100%;
  24. padding-bottom:30px;
  25. }
  26. .grid-item { width:300px; }
  27. h1 {
  28. margin-bottom: 0;
  29. display: inline;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div class="container-fluid">
  35. <h1>distrokid analytics</h1>
  36. [ <small><A href="https://gitlab.com/novadeviator/distrokid-analytics/" target="_blank">code</A></small> ]
  37. <div class="grid" data-masonry='{ "itemSelector": ".grid-item", "columnWidth": 100 }'>
  38. <?php
  39. $dir = "tsv/"; // you can change this folder. it where tsv reports live
  40. // open directory, and read its contents
  41. if (is_dir($dir)) {
  42. if ($dh = opendir($dir)) {
  43. while (($file = readdir($dh)) !== false) {
  44. if ($file != ".") {
  45. if ( $file != "..") {
  46. // for each line in each tsv file create an array of items
  47. if (($handle = fopen("tsv/$file", "r")) !== FALSE) {
  48. while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
  49. if ($data[0] != "Reporting Date") {
  50. $tds[] = $data;
  51. }
  52. }
  53. fclose($handle);
  54. }
  55. $files[] = $file;
  56. }
  57. }
  58. }
  59. closedir($dh);
  60. }
  61. }
  62. $allearnings = 0;
  63. foreach ($tds as $key => $val) {
  64. $allearnings = $val[12] + $allearnings;
  65. @$stores[$val[2]] = $stores[$val[2]] + $val[12];
  66. @$artists[$val[3]] = $artists[$val[3]] + $val[12];
  67. @$titles[$val[4]] = $titles[$val[4]] + $val[12];
  68. @$countries[$val[10]] = $countries[$val[10]] + $val[12];
  69. @$months[$val[1]] = $months[$val[1]] + $val[12];
  70. }
  71. // include misspellings group file, if it exists
  72. //$groups = "groups.php";
  73. //file_exists($groups) AND include $groups;
  74. // sort all the lists ASCENDING
  75. arsort($stores);
  76. arsort($artists);
  77. arsort($titles);
  78. arsort($countries);
  79. arsort($months);
  80. // lets get htmlirty (html-dirty):
  81. $tableseparator = "--------------------------";
  82. ?>
  83. <div class="grid-item">
  84. <table>
  85. <tr><td colspan=2><?php echo $tableseparator; ?></td></tr>
  86. <tr><th>TITLES</th><th></th></tr>
  87. <?php
  88. foreach ($titles as $key => $val){
  89. $val = sprintf('%02.2f', $val);
  90. echo "<tr><td>$key</td><td align=\"right\">$val</td></tr>\n\t\t\t";
  91. }
  92. ?>
  93. </table>
  94. </div>
  95. <div class="grid-item">
  96. <table>
  97. <tr><td colspan=2><?php echo $tableseparator; ?></td></tr>
  98. <tr><th>COUNTRIES</th><th></th></tr>
  99. <?php
  100. foreach ($countries as $key => $val){
  101. $val = sprintf('%02.2f', $val);
  102. echo "<tr><td>$key</td><td align=\"right\">$val</td></tr>\n\t\t\t";
  103. }
  104. echo "\n";
  105. ?>
  106. </table>
  107. </div>
  108. <div class="grid-item">
  109. <table>
  110. <tr><td colspan=2><?php echo $tableseparator; ?></td></tr>
  111. <tr><th>STORES</th><th></th></tr>
  112. <?php
  113. foreach ($stores as $key => $val){
  114. $val = sprintf('%02.2f', $val);
  115. echo "<tr><td>$key</td><td align=\"right\">$val</td></tr>\n\t\t\t";
  116. }
  117. ?>
  118. </table>
  119. </div>
  120. <div class="grid-item">
  121. <table>
  122. <tr><td colspan=2><?php echo $tableseparator; ?></td></tr>
  123. <tr><th>ARTISTS</th><th></th></tr>
  124. <?php
  125. foreach ($artists as $key => $val){
  126. $val = sprintf('%02.2f', $val);
  127. echo "<tr><td>$key</td><td align=\"right\">$val</td></tr>\n\t\t\t";
  128. }
  129. ?>
  130. </table>
  131. </div>
  132. <div class="grid-item">
  133. <table>
  134. <tr><td colspan=2><?php echo $tableseparator; ?></td></tr>
  135. <tr><th>MONTHS</th><th></th></tr>
  136. <?php
  137. foreach ($months as $key => $val){
  138. $val = sprintf('%02.2f', $val);
  139. echo "<tr><td>$key</td><td align=\"right\">$val</td></tr>\n\t\t\t";
  140. }
  141. ?>
  142. </table>
  143. </div>
  144. <!--
  145. <div class="grid-item">
  146. <table>
  147. <tr><td colspan=2><?php echo $tableseparator; ?></td></tr>
  148. <tr><th>FILES</th><th></th></tr>
  149. <?php
  150. foreach ($files as $key => $val){
  151. //$val = sprintf('%02.2f', $val);
  152. echo "<tr><td>$key</td><td align=\"right\">$val</td></tr>";
  153. }
  154. ?>
  155. </table>
  156. </div>
  157. -->
  158. <div class="grid-item">
  159. <table>
  160. <tr><td colspan=2><?php echo $tableseparator; ?></td></tr>
  161. <tr><td>ALL EARNINGS: </td><td align="right"><strong><?php echo "$ ".sprintf('%02.2f', $allearnings); ?></strong></td></tr>
  162. </table>
  163. </div>
  164. </div>
  165. </div>
  166. </body>
  167. </html>