Advertisement
Guest User

AngelShares PHP by wasthatawolf

a guest
Jan 5th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.79 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>
  4. AngelShares Distro
  5. </title>
  6. <style>
  7.     #left {
  8.         float: left;
  9.         width: 50%;
  10.     }
  11.     #right {
  12.         float: right;
  13.         width: 50%;
  14.     }
  15.     #infobox {
  16.         margin: auto;
  17.         padding: 20px;
  18.         width: 300px;
  19.         text-align: left;
  20.     }
  21.     .clear {
  22.         clear:both;    
  23.     }
  24.     .header {
  25.         font-weight: bold;
  26.         text-decoration: underline;
  27.     }
  28.     #bottominfo {
  29.         position: fixed;
  30.         bottom: 0px;
  31.         width: 100%;
  32.         text-align: center;
  33.         background-color: #fff;
  34.     }
  35. </style>
  36. </head>
  37. <body>
  38. <?php
  39.  
  40.  
  41. $time = microtime();
  42. $time = explode(' ', $time);
  43. $time = $time[1] + $time[0];
  44. $start = $time;
  45.  
  46.  
  47. date_default_timezone_set('UTC');
  48. $time = time();
  49. $day_one = 1388534400;
  50.  
  51. //convert seconds to time for time remaining in period
  52. function secondsToTime($inputSeconds) {
  53.  
  54.     $secondsInAMinute = 60;
  55.     $secondsInAnHour  = 60 * $secondsInAMinute;
  56.     $secondsInADay    = 24 * $secondsInAnHour;
  57.  
  58.     // extract hours
  59.     $hourSeconds = $inputSeconds % $secondsInADay;
  60.     $hours = sprintf('%02d',floor($hourSeconds / $secondsInAnHour));
  61.  
  62.     // extract minutes
  63.     $minuteSeconds = $hourSeconds % $secondsInAnHour;
  64.     $minutes = sprintf('%02d',floor($minuteSeconds / $secondsInAMinute));
  65.  
  66.     // extract the remaining seconds
  67.     $remainingSeconds = $minuteSeconds % $secondsInAMinute;
  68.     $seconds = sprintf('%02d',ceil($remainingSeconds));
  69.        
  70.     return $hours . ":" . $minutes . ":" . $seconds;
  71. }
  72.  
  73. //Collect BTC and PTS blockchain data parsed by donschoe
  74. $fileName_btc  = "http://q39.qhor.net/ags/btc.csv.txt";
  75. $fileName_pts  = "http://q39.qhor.net/ags/pts.csv.txt";
  76. $csvData_btc = file_get_contents($fileName_btc);
  77. $csvData_pts = file_get_contents($fileName_pts);
  78. $lines_btc = explode("\n", $csvData_btc);
  79. $lines_pts = explode("\n", $csvData_pts);
  80.  
  81.  
  82. //BTC - collect all blockchain data in array
  83. $i = 0;
  84.  
  85. foreach ($lines_btc as $line) {
  86.  
  87.     $pattern = "/\"/";
  88.     $replace = "";
  89.     $line = preg_replace($pattern,$replace,$line);
  90.     $lineex = explode(";",$line);
  91.  
  92.     $all_btc[$i]['block'] = $lineex[0];
  93.     $all_btc[$i]['datetime'] = $lineex[1];
  94.     $all_btc[$i]['sender'] = $lineex[2];
  95.     $all_btc[$i]['donation'] = $lineex[3];
  96.     $all_btc[$i]['sum'] = $lineex[4];
  97.     $all_btc[$i]['rate'] = $lineex[5];
  98.     $i++;
  99.    
  100. }  
  101.  
  102. unset($all_btc[0]);
  103. unset($all_btc[($i-1)]);
  104.  
  105.  
  106. //PTS - collect all blockchain data in array
  107. $j = 0;
  108.  
  109. foreach ($lines_pts as $line) {
  110.  
  111.     $pattern = "/\"/";
  112.     $replace = "";
  113.     $line = preg_replace($pattern,$replace,$line);
  114.     $lineex = explode(";",$line);
  115.  
  116.     $all_pts[$j]['block'] = $lineex[0];
  117.     $all_pts[$j]['datetime'] = $lineex[1];
  118.     $all_pts[$j]['sender'] = $lineex[2];
  119.     $all_pts[$j]['donation'] = $lineex[3];
  120.     $all_pts[$j]['sum'] = $lineex[4];
  121.     $all_pts[$j]['rate'] = $lineex[5];
  122.     $j++;
  123.    
  124. }  
  125.  
  126. unset($all_pts[0]);
  127. unset($all_pts[($j-1)]);
  128.  
  129.  
  130. //find current period using BTC data
  131. $last_date_val = $all_btc[($i-2)]['datetime'];
  132. $last_date_val_f = substr($last_date_val, 0, 10);
  133. $current_day = strtotime($last_date_val_f);
  134.  
  135. //find time left in current period
  136. $sec_til_next = (86400 - ($time-$current_day));
  137. $pct_day_gone = (86400-$sec_til_next)/86400;
  138.  
  139. //count total periods (including current period)
  140. $total_days = (($current_day-$day_one)/86400)+1;
  141.  
  142.  
  143. //BTC - filter donation data for all periods
  144. $all_btc_donation = array();
  145. $all_btc_datetime = array();
  146. $k = 0;
  147. foreach ($all_btc as $p) {
  148.     $all_btc_donation[] = $p['donation'];
  149.     $all_btc_datetime[] = $p['datetime'];
  150.  
  151. //BTC - collect current period btc data in separate array
  152.     if (substr($p['datetime'],0,10) == $last_date_val_f){
  153.         $k++;
  154.         $period_btc[$k]['block'] = $p['block'];
  155.         $period_btc[$k]['datetime'] = $p['datetime'];
  156.         $period_btc[$k]['sender'] = $p['sender'];
  157.         $period_btc[$k]['donation'] = $p['donation'];
  158.         $period_btc[$k]['sum'] = $p['sum'];
  159.         $period_btc[$k]['rate'] = $p['rate'];
  160.     }
  161. }
  162.  
  163. //BTC - filter donation data for current period
  164. $period_btc_donation = array();
  165. foreach ($period_btc as $q) {
  166.     $period_btc_donation[] = $q['donation'];
  167. }
  168.  
  169.  
  170. $top_all_btc = max($all_btc_donation); //BTC all - calculate top donation
  171. $sum_all_btc = array_sum($all_btc_donation); //BTC all - calculate sum of donation
  172. $amt_all_btc = $i-1; //BTC all - calculate number of donations
  173. $ags_all_btc = $sum_all_btc / (5000*$total_days); //BTC all - calculate AGS/BTC
  174. $wt_ags_all_btc = $sum_all_btc / ((5000*($total_days-1))+(5000*$pct_day_gone)); //BTC all - calculate weighted AGS/BTC
  175.  
  176. $top_period_btc = max($period_btc_donation); //BTC period - calculate top donation
  177. $sum_period_btc = array_sum($period_btc_donation); //BTC period - calculate sum of donation
  178. $amt_period_btc = count($period_btc); //BTC period - calculate number of donations
  179. $ags_period_btc = $sum_period_btc / (5000); //BTC period - calculate AGS/BTC
  180. $wt_ags_period_btc = $sum_period_btc / (5000*$pct_day_gone); //BTC period - calculate weighted AGS/BTC
  181.  
  182. //PTS - filter donation data for all periods
  183. $all_pts_donation = array();
  184. $all_pts_datetime = array();
  185. $k = 0;
  186. foreach ($all_pts as $p) {
  187.     $all_pts_donation[] = $p['donation'];
  188.     $all_pts_datetime[] = $p['datetime'];
  189.  
  190. //PTS - collect current period btc data in separate array
  191.     if (substr($p['datetime'],0,10) == $last_date_val_f){
  192.         $k++;
  193.         $period_pts[$k]['block'] = $p['block'];
  194.         $period_pts[$k]['datetime'] = $p['datetime'];
  195.         $period_pts[$k]['sender'] = $p['sender'];
  196.         $period_pts[$k]['donation'] = $p['donation'];
  197.         $period_pts[$k]['sum'] = $p['sum'];
  198.         $period_pts[$k]['rate'] = $p['rate'];
  199.     }
  200. }
  201.  
  202. //PTS - filter donation data for current period
  203. $period_pts_donation = array();
  204. foreach ($period_pts as $r) {
  205.     $period_pts_donation[] = $r['donation'];
  206. }
  207.  
  208. $top_all_pts = max($all_pts_donation); //PTS all - calculate top donation
  209. $sum_all_pts = array_sum($all_pts_donation); //PTS all - calculate sum of donation
  210. $amt_all_pts = $j-1; //PTS all - calculate number of donations
  211. $ags_all_pts = $sum_all_pts / (5000*$total_days); //PTS all - calculate AGS/PTS
  212. $wt_ags_all_pts = $sum_all_pts / ((5000*($total_days-1))+(5000*$pct_day_gone)); //PTS all - calculate weighted AGS/PTS
  213.  
  214. $top_period_pts = max($period_pts_donation); //PTS period - calculate top donation
  215. $sum_period_pts = array_sum($period_pts_donation); //PTS period - calculate sum of donation
  216. $amt_period_pts = count($period_pts); //PTS period - calculate number of donations
  217. $ags_period_pts = $sum_period_pts / (5000); //PTS period - calculate AGS/PTS
  218. $wt_ags_period_pts = $sum_period_pts / (5000*$pct_day_gone); //PTS period - calculate weighted AGS/PTS
  219.  
  220.  
  221. //display results
  222. echo "<p align='center'>AGS distributed to date: ".number_format((($total_days-1)*5000), 0, '.', ',')." of 1,000,000</p>";
  223. echo "<p align='center'>Current Period: ".$total_days." of 200";
  224. echo "<p align='center'>Today's date: ".$last_date_val_f."</p>";
  225. echo "<p align='center'>Time to next Period: ".secondsToTime($sec_til_next)."</p>";
  226.  
  227.  
  228. echo "<div id='left'>";
  229. echo "<div id='infobox'>";
  230. echo "<p class='header' align='center'>Current Period BTC</p>";
  231. echo "Sum of Donations: ".$sum_period_btc."<br>Amt of Donations: ".$amt_period_btc."<br>Top Donation: ".$top_period_btc."<br>Price per AGS: ".$ags_period_btc."<br>Wtd Price per AGS: ".$wt_ags_period_btc;
  232. echo "</div>";
  233. echo "</div>";
  234.  
  235. echo "<div id='right'>";
  236. echo "<div id='infobox'>";
  237. echo "<p class='header' align='center'>Current Period PTS</p>";
  238. echo "Sum of Donations: ".$sum_period_pts."<br>Amt of Donations: ".$amt_period_pts."<br>Top Donation: ".$top_period_pts."<br>Price per AGS: ".$ags_period_pts."<br>Wtd Price per AGS: ".$wt_ags_period_pts;
  239. echo "</div>";
  240. echo "</div>";
  241.  
  242. echo "<div id='left'>";
  243. echo "<div id='infobox'>";
  244. echo "<p class='header' align='center'>Overall BTC</p>";
  245. echo "Sum of Donations: ".$sum_all_btc."<br>Amt of Donations: ".$amt_all_btc."<br>Top Donation: ".$top_all_btc."<br>Price per AGS: ".$ags_all_btc."<br>Wtd Price per AGS: ".$wt_ags_all_btc;
  246. echo "</div>";
  247. echo "</div>";
  248.  
  249. echo "<div id='right'>";
  250. echo "<div id='infobox'>";
  251. echo "<p class='header' align='center'>Overall PTS</p>";
  252. echo "Sum of Donations: ".$sum_all_pts."<br>Amt of Donations: ".$amt_all_pts."<br>Top Donation: ".$top_all_pts."<br>Price per AGS: ".$ags_all_pts."<br>Wtd Price per AGS: ".$wt_ags_all_pts;
  253. echo "</div>";
  254. echo "</div>";
  255.  
  256.  
  257.  
  258. $time = microtime();
  259. $time = explode(' ', $time);
  260. $time = $time[1] + $time[0];
  261. $finish = $time;
  262. $total_time = round(($finish - $start), 4);
  263.  
  264. echo "<div id='bottominfo' class='clear'>";
  265. echo "<p style='font-size: 14px;'>NOTE:  Weighted prices assume a linear increase of AGS from 0 to 5000 in current period.</p>";
  266. echo "<p style='font-size: 12px;'>Page generated in ".$total_time." seconds.";
  267. echo "<p style='font-size: 12px;'>Blockchain data provided by <a href='https://bitsharestalk.org/index.php?topic=1853.0'>donschoe</a> (v0.2)</p>";
  268. echo "</div>";
  269.  
  270.  
  271. ?>
  272.  
  273. </body>
  274. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement