BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

economic_stats.php 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php
  2. #declare(strict_types=1);
  3. /*
  4. Tools necessary for economic management
  5. 1. Current overall stats (!economy)
  6. 2. Statistical traffic trends in a graph
  7. a. All time / 1 year (whichever is smaller)
  8. b. 1 month
  9. c. 1 week
  10. d. 1 day
  11. 3. Freeleech analysis
  12. a. total download average during freeleech vs. normal conditions
  13. b. total stats of a freeleech - uploaded torrents, upload amount, download amount, snatches, etc.
  14. 4. Traffic trends over an account's life, on average
  15. a. at one week, one month, whatever (selectable range in weeks) - averages (up/down/ratio)
  16. b. given a selected timespan, average ratio (users who are 4-5 months old have X ratio)
  17. c. average date at which >50% of accounts with ratios >1 reach 1.0 and never dip below, stockpiling buffer
  18. 5. Raw numbers
  19. a. total torrents, seeders, leechers
  20. b. average seeds/leechs per torrent
  21. c. average snatches/user
  22. d. average seeding torrents/user
  23. e. users on ratio watch
  24. 6. Distribution graph of seedership vs. torrent percentage
  25. a. graph showing that the top 1% of torrents has 50% of seeders or whatever the numbers might be
  26. 7. Effects of economic changes
  27. a. number of users changed by ratio being changed
  28. b. project effects with intelligent mathematical analysis of a 24, 48 or 72 hour freeleech
  29. */
  30. if (!check_perms('site_view_flow')) {
  31. error(403);
  32. }
  33. View::show_header('Economy');
  34. if (!$EconomicStats = $Cache->get_value('new_economic_stats')) {
  35. $DB->prepared_query("
  36. SELECT SUM(Uploaded), SUM(Downloaded), COUNT(ID)
  37. FROM users_main
  38. WHERE Enabled = '1'");
  39. list($TotalUpload, $TotalDownload, $NumUsers) = $DB->next_record();
  40. $DB->prepared_query("
  41. SELECT SUM(Bounty)
  42. FROM requests_votes");
  43. list($TotalBounty) = $DB->next_record();
  44. $DB->prepared_query("
  45. SELECT SUM(rv.Bounty)
  46. FROM requests_votes AS rv
  47. JOIN requests AS r ON r.ID = rv.RequestID
  48. WHERE TorrentID > 0");
  49. list($AvailableBounty) = $DB->next_record();
  50. $DB->prepared_query("
  51. SELECT SUM(Snatched), COUNT(ID)
  52. FROM torrents");
  53. list($TotalSnatches, $TotalTorrents) = $DB->next_record(); // This is the total number of snatches for torrents that still exist
  54. $DB->prepared_query("
  55. SELECT COUNT(uid)
  56. FROM xbt_snatched");
  57. list($TotalOverallSnatches) = $DB->next_record();
  58. if (($PeerStats = $Cache->get_value('stats_peers')) === false) {
  59. $DB->prepared_query("
  60. SELECT COUNT(fid)
  61. FROM xbt_files_users
  62. WHERE remaining = 0");
  63. list($TotalSeeders) = $DB->next_record();
  64. $DB->prepared_query("
  65. SELECT COUNT(fid)
  66. FROM xbt_files_users
  67. WHERE remaining > 0");
  68. list($TotalLeechers) = $DB->next_record();
  69. } else {
  70. list($TotalLeechers, $TotalSeeders) = $PeerStats;
  71. }
  72. $TotalPeers = $TotalLeechers + $TotalSeeders;
  73. $DB->prepared_query("
  74. SELECT COUNT(ID)
  75. FROM users_main
  76. WHERE (
  77. SELECT COUNT(uid)
  78. FROM xbt_files_users
  79. WHERE uid = users_main.ID
  80. ) > 0");
  81. list($TotalPeerUsers) = $DB->next_record();
  82. $Cache->cache_value(
  83. 'new_economic_stats',
  84. array($TotalUpload, $TotalDownload, $NumUsers, $TotalBounty,
  85. $AvailableBounty, $TotalSnatches, $TotalTorrents,
  86. $TotalOverallSnatches, $TotalSeeders, $TotalPeers,
  87. $TotalPeerUsers),
  88. 3600
  89. );
  90. } else {
  91. list($TotalUpload, $TotalDownload, $NumUsers, $TotalBounty, $AvailableBounty,
  92. $TotalSnatches, $TotalTorrents, $TotalOverallSnatches, $TotalSeeders,
  93. $TotalPeers, $TotalPeerUsers) = $EconomicStats;
  94. }
  95. $TotalLeechers = $TotalPeers - $TotalSeeders;
  96. ?>
  97. <div>
  98. <div class="box">
  99. <div class="head">Overall stats</div>
  100. <div class="pad">
  101. <ul class="stats nobullet">
  102. <li>
  103. <strong>Total upload:</strong>
  104. <?=Format::get_size($TotalUpload)?>
  105. </li>
  106. <li>
  107. <strong>Total download:</strong>
  108. <?=Format::get_size($TotalDownload)?>
  109. </li>
  110. <li>
  111. <strong>Total buffer:</strong>
  112. <?=Format::get_size($TotalUpload - $TotalDownload)?>
  113. </li>
  114. <br />
  115. <li>
  116. <strong>Mean ratio:</strong>
  117. <?=Format::get_ratio_html($TotalUpload, $TotalDownload)?>
  118. </li>
  119. <li>
  120. <strong>Mean upload:</strong>
  121. <?=Format::get_size($TotalUpload / $NumUsers)?>
  122. </li>
  123. <li>
  124. <strong>Mean download:</strong>
  125. <?=Format::get_size($TotalDownload / $NumUsers)?>
  126. </li>
  127. <li>
  128. <strong>Mean buffer:</strong>
  129. <?=Format::get_size(($TotalUpload - $TotalDownload) / $NumUsers)?>
  130. </li>
  131. <br />
  132. <li>
  133. <strong>Total request bounty:</strong>
  134. <?=Format::get_size($TotalBounty)?>
  135. </li>
  136. <li>
  137. <strong>Available request bounty:</strong>
  138. <?=Format::get_size($AvailableBounty)?>
  139. </li>
  140. </ul>
  141. </div>
  142. </div>
  143. <br />
  144. <div class="box">
  145. <div class="head">Swarms and snatches</div>
  146. <div class="pad">
  147. <ul class="stats nobullet">
  148. <li>
  149. <strong>Total seeders:</strong>
  150. <?=number_format($TotalSeeders)?>
  151. </li>
  152. <li>
  153. <strong>Total leechers:</strong>
  154. <?=number_format($TotalLeechers)?>
  155. </li>
  156. <li>
  157. <strong>Total peers:</strong>
  158. <?=number_format($TotalSeeders + $TotalLeechers)?>
  159. </li>
  160. <li>
  161. <strong>Total snatches:</strong>
  162. <?=number_format($TotalOverallSnatches)?>
  163. </li>
  164. <li>
  165. <strong>Seeder/leecher ratio:</strong>
  166. <?=Format::get_ratio_html($TotalSeeders, $TotalLeechers)?>
  167. </li>
  168. <li>
  169. <strong>Seeder/snatch ratio:</strong>
  170. <?=Format::get_ratio_html($TotalSeeders, $TotalOverallSnatches)?>
  171. </li>
  172. <br />
  173. <li>
  174. <strong>Mean seeders per torrent:</strong>
  175. <?=number_format($TotalSeeders / $TotalTorrents, 2)?>
  176. </li>
  177. <li>
  178. <strong>Mean leechers per torrent:</strong>
  179. <?=number_format($TotalLeechers / $TotalTorrents, 2)?>
  180. </li>
  181. <li>
  182. <strong>Mean snatches per torrent:</strong>
  183. <?=number_format($TotalSnatches / $TotalTorrents, 2)?>
  184. </li>
  185. <br />
  186. <li>
  187. <strong>Mean seeding per user:</strong>
  188. <?=number_format($TotalSeeders / $NumUsers, 2)?>
  189. </li>
  190. <li>
  191. <strong>Mean leeching per user:</strong>
  192. <?=number_format($TotalLeechers / $NumUsers, 2)?>
  193. </li>
  194. <li>
  195. <strong>Mean snatches per user:</strong>
  196. <?=number_format($TotalOverallSnatches / $NumUsers, 2)?>
  197. </li>
  198. <br />
  199. <li>
  200. <strong>Total users in at least 1 swarm:</strong>
  201. <?=number_format($TotalPeerUsers)?>
  202. </li>
  203. <li>
  204. <strong>Mean seeding per user in at least 1 swarm:</strong>
  205. <?=number_format($TotalSeeders / $TotalPeerUsers, 2)?>
  206. </li>
  207. <li>
  208. <strong>Mean leeching per user in at least 1 swarm:</strong>
  209. <?=number_format($TotalLeechers / $TotalPeerUsers, 2)?>
  210. </li>
  211. <li>
  212. <strong>Mean snatches per user in at least 1 swarm:</strong>
  213. <?=number_format($TotalSnatches / $TotalPeerUsers, 2)?>
  214. </li>
  215. </ul>
  216. </div>
  217. </div>
  218. </div>
  219. <?php
  220. View::show_footer();