Advertisement
Guest User

AGS Stats

a guest
Jan 7th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.48 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>
  4. AngelShares Summary
  5. </title>
  6. <link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css" />
  7.  
  8. <style>
  9.     .bold {
  10.         font-weight: bold;
  11.         text-align: center;
  12.     }
  13.     #left {
  14.         float: left;
  15.         width: 450px;
  16.         height: 285px;
  17.     }
  18.     #right {
  19.         float: right;
  20.         width: 450px;
  21.         height: 285px;
  22.     }
  23.     #infobox {
  24.         margin: auto;
  25.         padding: 10px 20px 5px 20px;
  26.     }
  27.     .clear {
  28.         clear:both;    
  29.     }
  30.     .header {
  31.         font-weight: bold;
  32.         text-decoration: underline;
  33.     }
  34.     #bottominfo {
  35.         position: fixed;
  36.         bottom: 0px;
  37.         width: 100%;
  38.         text-align: center;
  39.         background-color: #fff;
  40.     }
  41.     #centerbox  {
  42.         margin-left: 450px;
  43.         margin-right: 450px;
  44.         position:absolute;
  45.         top:0px;
  46.         height:500px;
  47.         width: 300px;
  48.     }
  49.     h4 {
  50.         line-height:200%
  51.     }
  52.     #container {
  53.         width: 1200px;
  54.         height: 675px;
  55.         padding-top: 10px;
  56.     }
  57. .Absolute-Center {
  58.         margin: auto;
  59.    
  60.         top: 0;
  61.     }
  62.     .highlight {
  63.  
  64.         color: #009051;
  65.     }
  66.    
  67. </style>
  68. </head>
  69. <body>
  70.     <div id="container" class="Absolute-Center">
  71. <?php
  72.  
  73.  
  74. $time = microtime();
  75. $time = explode(' ', $time);
  76. $time = $time[1] + $time[0];
  77. $start = $time;
  78.  
  79. function GetJsonFeed($json_url)
  80. {
  81.     $feed = file_get_contents($json_url);
  82.     return json_decode($feed, true);
  83. };
  84.  
  85.  
  86. $pts_btc = GetJsonFeed("http://bter.com/api/1/ticker/pts_btc/");
  87. $btc_usd = GetJsonFeed("https://api.bitcoinaverage.com/ticker/USD");
  88.  
  89.  
  90. date_default_timezone_set('UTC');
  91. $time = time();
  92. $day_one = 1388534400;
  93.  
  94. //convert seconds to time for time remaining in period
  95. function secondsToTime($inputSeconds) {
  96.  
  97.     $secondsInAMinute = 60;
  98.     $secondsInAnHour  = 60 * $secondsInAMinute;
  99.     $secondsInADay    = 24 * $secondsInAnHour;
  100.  
  101.     // extract hours
  102.     $hourSeconds = $inputSeconds % $secondsInADay;
  103.     $hours = sprintf('%02d',floor($hourSeconds / $secondsInAnHour));
  104.  
  105.     // extract minutes
  106.     $minuteSeconds = $hourSeconds % $secondsInAnHour;
  107.     $minutes = sprintf('%02d',floor($minuteSeconds / $secondsInAMinute));
  108.  
  109.     // extract the remaining seconds
  110.     $remainingSeconds = $minuteSeconds % $secondsInAMinute;
  111.     $seconds = sprintf('%02d',ceil($remainingSeconds));
  112.        
  113.     return $hours . ":" . $minutes . ":" . $seconds;
  114. }
  115.  
  116. //Collect BTC and PTS blockchain data parsed by donschoe
  117. $fileName_btc  = "http://q39.qhor.net/ags/3/btc.csv.txt";
  118. //$fileName_btc  = "../btctemp.txt";
  119. $fileName_pts  = "http://q39.qhor.net/ags/3/pts.csv.txt";
  120. $csvData_btc = file_get_contents($fileName_btc);
  121. $csvData_pts = file_get_contents($fileName_pts);
  122. $lines_btc = explode("\n", $csvData_btc);
  123. $lines_pts = explode("\n", $csvData_pts);
  124.  
  125.  
  126. //BTC - collect all blockchain data in array
  127. $i = 0;
  128.  
  129. foreach ($lines_btc as $line) {
  130.  
  131.     $pattern = "/\"/";
  132.     $replace = "";
  133.     $line = preg_replace($pattern,$replace,$line);
  134.     $lineex = explode(";",$line);
  135.  
  136.     //$all_btc[$i]['block'] = $lineex[0];
  137.     $all_btc[$i]['datetime'] = $lineex[1];
  138.     //$all_btc[$i]['sender'] = $lineex[2];
  139.     $all_btc[$i]['donation'] = $lineex[4];
  140.     //$all_btc[$i]['sum'] = $lineex[4];
  141.     //$all_btc[$i]['rate'] = $lineex[5];
  142.     $i++;
  143.    
  144. }  
  145.  
  146. unset($all_btc[0]);
  147. unset($all_btc[($i-1)]);
  148.  
  149.  
  150. //PTS - collect all blockchain data in array
  151. $j = 0;
  152.  
  153. foreach ($lines_pts as $line) {
  154.  
  155.     $pattern = "/\"/";
  156.     $replace = "";
  157.     $line = preg_replace($pattern,$replace,$line);
  158.     $lineex = explode(";",$line);
  159.  
  160.  //$all_pts[$i]['block'] = $lineex[0];
  161.     $all_pts[$j]['datetime'] = $lineex[1];
  162.     //$all_pts[$i]['sender'] = $lineex[2];
  163.     $all_pts[$j]['donation'] = $lineex[4];
  164.     //$all_pts[$i]['sum'] = $lineex[4];
  165.     //$all_pts[$i]['rate'] = $lineex[5];
  166.     $j++;
  167.    
  168. }  
  169.  
  170. unset($all_pts[0]);
  171. unset($all_pts[($j-1)]);
  172.  
  173.  
  174. //find current period using PTS data
  175. $last_date_val = $all_pts[($j-2)]['datetime'];
  176. $last_date_val_f = substr($last_date_val, 0, 10);
  177. $current_day = strtotime($last_date_val_f);
  178.  
  179. //find time left in current period
  180. $sec_til_next = (86400 - ($time-$current_day));
  181. $pct_day_gone = (86400-$sec_til_next)/86400;
  182.  
  183. //count total periods (including current period)
  184. $total_days = (($current_day-$day_one)/86400)+1;
  185.  
  186.  
  187. //BTC - filter donation data for all periods
  188. $all_btc_donation = array();
  189. $all_btc_datetime = array();
  190. $k = 0;
  191. foreach ($all_btc as $p) {
  192.     $all_btc_donation[] = $p['donation'];
  193.     $all_btc_datetime[] = $p['datetime'];
  194.  
  195. //BTC - collect current period btc data in separate array
  196.     if (substr($p['datetime'],0,10) == $last_date_val_f){
  197.         $k++;
  198.         $period_btc[$k]['block'] = $p['block'];
  199.         $period_btc[$k]['datetime'] = $p['datetime'];
  200.         $period_btc[$k]['sender'] = $p['sender'];
  201.         $period_btc[$k]['donation'] = $p['donation'];
  202.         $period_btc[$k]['sum'] = $p['sum'];
  203.         $period_btc[$k]['rate'] = $p['rate'];
  204.     }
  205. }
  206.  
  207.  
  208.  
  209.  
  210. $top_all_btc = max($all_btc_donation); //BTC all - calculate top donation
  211. $sum_all_btc = array_sum($all_btc_donation); //BTC all - calculate sum of donation
  212. $amt_all_btc = $i-1; //BTC all - calculate number of donations
  213. $ags_all_btc = $sum_all_btc / (5000*$total_days); //BTC all - calculate AGS/BTC
  214. $wt_ags_all_btc = $sum_all_btc / ((5000*($total_days-1))+(5000*$pct_day_gone)); //BTC all - calculate weighted AGS/BTC
  215.  
  216. if (isset($period_btc)){
  217.    
  218. //BTC - filter donation data for current period
  219. $period_btc_donation = array();
  220. foreach ($period_btc as $q) {
  221.     $period_btc_donation[] = $q['donation'];
  222. }
  223.  
  224. $top_period_btc = max($period_btc_donation); //BTC period - calculate top donation
  225. $sum_period_btc = array_sum($period_btc_donation); //BTC period - calculate sum of donation
  226. $amt_period_btc = count($period_btc); //BTC period - calculate number of donations
  227. $ags_period_btc = $sum_period_btc / (5000); //BTC period - calculate AGS/BTC
  228. $wt_ags_period_btc = $sum_period_btc / (5000*$pct_day_gone); //BTC period - calculate weighted AGS/BTC
  229.  
  230. if ($wt_ags_period_btc < $wt_ags_all_btc) { $btc_status = "<span style='color: #009d00'>Undervalued by ".round(((($wt_ags_all_btc/$wt_ags_period_btc)-1)*100),2)."%*</span>";}
  231. if ($wt_ags_period_btc > $wt_ags_all_btc) { $btc_status = "<span style='color: #ff0000'>Overvalued by ".round(((($wt_ags_period_btc/$wt_ags_all_btc)-1)*100),2)."%*</span>";}
  232. if ($wt_ags_period_btc == $wt_ags_all_btc) { $btc_status = "<span style='color: #0000ff'>Fairvalued*</span>";}
  233.  
  234. }
  235.  
  236.  
  237.  
  238. //PTS - filter donation data for all periods
  239. $all_pts_donation = array();
  240. $all_pts_datetime = array();
  241. $k = 0;
  242. foreach ($all_pts as $p) {
  243.     $all_pts_donation[] = $p['donation'];
  244.     $all_pts_datetime[] = $p['datetime'];
  245.  
  246. //PTS - collect current period btc data in separate array
  247.     if (substr($p['datetime'],0,10) == $last_date_val_f){
  248.         $k++;
  249.         $period_pts[$k]['block'] = $p['block'];
  250.         $period_pts[$k]['datetime'] = $p['datetime'];
  251.         $period_pts[$k]['sender'] = $p['sender'];
  252.         $period_pts[$k]['donation'] = $p['donation'];
  253.         $period_pts[$k]['sum'] = $p['sum'];
  254.         $period_pts[$k]['rate'] = $p['rate'];
  255.     }
  256. }
  257.  
  258. //PTS - filter donation data for current period
  259. $period_pts_donation = array();
  260. foreach ($period_pts as $r) {
  261.     $period_pts_donation[] = $r['donation'];
  262. }
  263.  
  264. $top_all_pts = max($all_pts_donation); //PTS all - calculate top donation
  265. $sum_all_pts = array_sum($all_pts_donation); //PTS all - calculate sum of donation
  266. $amt_all_pts = $j-1; //PTS all - calculate number of donations
  267. $ags_all_pts = $sum_all_pts / (5000*$total_days); //PTS all - calculate AGS/PTS
  268. $wt_ags_all_pts = $sum_all_pts / ((5000*($total_days-1))+(5000*$pct_day_gone)); //PTS all - calculate weighted AGS/PTS
  269.  
  270. $top_period_pts = max($period_pts_donation); //PTS period - calculate top donation
  271. $sum_period_pts = array_sum($period_pts_donation); //PTS period - calculate sum of donation
  272. $amt_period_pts = count($period_pts); //PTS period - calculate number of donations
  273. $ags_period_pts = $sum_period_pts / (5000); //PTS period - calculate AGS/PTS
  274. $wt_ags_period_pts = $sum_period_pts / (5000*$pct_day_gone); //PTS period - calculate weighted AGS/PTS
  275.  
  276.  
  277.  
  278. if ($wt_ags_period_pts < $wt_ags_all_pts) { $pts_status = "<span style='color: #009d00'>Undervalued by ".round(((($wt_ags_all_pts/$wt_ags_period_pts)-1)*100),2)."%*</span>";}
  279. if ($wt_ags_period_pts > $wt_ags_all_pts) { $pts_status = "<span style='color: #ff0000'>Overvalued by ".round(((($wt_ags_period_pts/$wt_ags_all_pts)-1)*100),2)."%*</span>";}
  280. if ($wt_ags_period_pts == $wt_ags_all_pts) { $pts_status = "<span style='color: #0000ff'>Fairvalued*</span>";}
  281.  
  282. //display results
  283.  
  284.  
  285. echo "<div id='centerbox'>";
  286. echo "<h3 align='center'><b><u>AngelShares Statistics</u></b></h4>";
  287. echo "<h4 align='center'><b>AGS distributed to date:</b><br><span class='lead'> ".number_format((($total_days-1)*5000*2), 0, '.', ',')." of 2,000,000</span></h4>";
  288. echo "<h4 align='center'><b>Current Period:</b><br><span class='lead'> ".$total_days." of 200</span></h4>";
  289. echo "<h4 align='center'><b>Today's date:</b><br><span class='lead'> ".$last_date_val_f."</span></h4>";
  290. echo "<h4 align='center'><b>Time to next Period:</b><br><span class='lead'> ".secondsToTime($sec_til_next)."</span></h4>";
  291. echo "<h4 align='center'><b>AGS/BTC is currently</b><br><span class='lead'> ".$btc_status."</span></h4>";
  292. echo "<h4 align='center'><b>AGS/PTS is currently</b><br><span class='lead'> ".$pts_status."</span></h4>";
  293.  
  294. echo "<p align='center'><small>* comparing current period to overall weighted prices</small></p>";
  295. echo "<p align='center'><small>** bter.com (BTC/PTS), bitcoinaverage.com (USD/BTC)</small></p>";
  296.  
  297. echo "</div>";
  298.  
  299.  
  300. echo "<div id='left'>";
  301. echo "<div id='infobox'>";
  302. if (isset($period_btc)){
  303. echo "<p class='header' align='center'>Current Period BTC</p>";
  304. } else {
  305. echo "<p class='header' align='center'>BTC Data is parsing...</p>";
  306. }
  307. echo "<table class='table table-striped'>";
  308. echo "<tr><td align='right'>Sum of Donations:</td><td>".$sum_period_btc."</td></tr>";
  309. echo "<tr><td align='right'>Amt of Donations:</td><td>".$amt_period_btc."</td></tr>";
  310. echo "<tr><td align='right'>Top Donation:</td><td>".$top_period_btc."</td></tr>";
  311. echo "<tr><td align='right'>Price per AGS:</td><td>".$ags_period_btc."</td></tr>";
  312. echo "<tr><td align='right'>Wtd Price per AGS:</td><td>".$wt_ags_period_btc."</td></tr>";
  313. echo "<tr class='highlight'><td align='right'>Wtd USD per AGS:</td><td class='bold'>$".number_format(($wt_ags_period_btc*$btc_usd['last']), 2, '.', ',')."**</td></tr>";
  314.  
  315. echo "</table>";
  316.  
  317. echo "</div>";
  318. echo "</div>";
  319.  
  320.  
  321. echo "<div id='right'>";
  322. echo "<div id='infobox'>";
  323. echo "<p class='header' align='center'>Current Period PTS</p>";
  324. echo "<table class='table table-striped'>";
  325. echo "<tr><td align='right'>Sum of Donations:</td><td>".$sum_period_pts."</td></tr>";
  326. echo "<tr><td align='right'>Amt of Donations:</td><td>".$amt_period_pts."</td></tr>";
  327. echo "<tr><td align='right'>Top Donation:</td><td>".$top_period_pts."</td></tr>";
  328. echo "<tr><td align='right'>Price per AGS:</td><td>".$ags_period_pts."</td></tr>";
  329. echo "<tr><td align='right'>Wtd Price per AGS:</td><td>".$wt_ags_period_pts."</td></tr>";
  330. echo "<tr class='highlight'><td align='right'>Wtd USD per AGS:</td><td class='bold'>$".number_format(($wt_ags_period_pts*$pts_btc['last']*$btc_usd['last']), 2, '.', ',')."**</td></tr>";
  331. echo "</table>";
  332.  
  333.  
  334.  
  335. echo "</div>";
  336. echo "</div>";
  337.  
  338.  
  339.  
  340.  
  341. echo "<div id='left'>";
  342. echo "<div id='infobox'>";
  343.  
  344. if (isset($period_btc)){
  345. echo "<p class='header' align='center'>Overall BTC</p>";
  346. } else {
  347. echo "<p class='header' align='center'>BTC Data is parsing...</p>";
  348. }
  349. //echo "<p class='header' align='center'>Overall BTC</p>";
  350.  
  351. echo "<table class='table table-striped'>";
  352. echo "<tr><td align='right'>Sum of Donations:</td><td>".$sum_all_btc."</td></tr>";
  353. echo "<tr><td align='right'>Amt of Donations:</td><td>".$amt_all_btc."</td></tr>";
  354. echo "<tr><td align='right'>Top Donation:</td><td>".$top_all_btc."</td></tr>";
  355. echo "<tr><td align='right'>Price per AGS:</td><td>".$ags_all_btc."</td></tr>";
  356. echo "<tr><td align='right'>Wtd Price per AGS:</td><td>".$wt_ags_all_btc."</td></tr>";
  357. echo "<tr class='highlight'><td align='right'>Wtd USD per AGS:</td><td class='bold'>$".number_format(($wt_ags_all_btc*$btc_usd['last']), 2, '.', ',')."**</td></tr>";
  358. echo "</table>";
  359.  
  360.  
  361. echo "</div>";
  362. echo "</div>";
  363.  
  364.  
  365.  
  366. echo "<div id='right'>";
  367. echo "<div id='infobox'>";
  368. echo "<p class='header' align='center'>Overall PTS</p>";
  369. echo "<table class='table table-striped'>";
  370. echo "<tr><td align='right'>Sum of Donations:</td><td>".$sum_all_pts."</td></tr>";
  371. echo "<tr><td align='right'>Amt of Donations:</td><td>".$amt_all_pts."</td></tr>";
  372. echo "<tr><td align='right'>Top Donation:</td><td>".$top_all_pts."</td></tr>";
  373. echo "<tr><td align='right'>Price per AGS:</td><td>".$ags_all_pts."</td></tr>";
  374. echo "<tr><td align='right'>Wtd Price per AGS:</td><td>".$wt_ags_all_pts."</td></tr>";
  375. echo "<tr class='highlight'><td align='right'>Wtd USD per AGS:</td><td class='bold'>$".number_format(($wt_ags_all_pts*$pts_btc['last']*$btc_usd['last']), 2, '.', ',')."**</td></tr>";
  376. echo "</table>";
  377.  
  378. echo "</div>";
  379. echo "</div>";
  380.  
  381.  
  382.  
  383. $time = microtime();
  384. $time = explode(' ', $time);
  385. $time = $time[1] + $time[0];
  386. $finish = $time;
  387. $total_time = round(($finish - $start), 4);
  388.  
  389. ?>
  390.  
  391. </div>
  392. <?
  393.  
  394. echo "<div id='bottominfo' class='clear'>";
  395. echo "<p style='font-size: 14px;'>NOTE:  Weighted prices assume a linear increase of AGS from 0 to 5000 in current period.</p>";
  396. echo "<p style='font-size: 12px;'>Page generated in ".$total_time." seconds. / Blockchain data (v0.3) provided by <a href='https://bitsharestalk.org/index.php?topic=1853.0'>donschoe</a> / Tips: PYDhxRmdd8YQdYLD757s7robuvafFdMARi / <a href='http://pastebin.com/AWbHNvPr'>Source Code</a></p>";
  397.  
  398. echo "</div>";
  399.  
  400.  
  401. ?>
  402.  
  403. </body>
  404. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement