Browse Source

php - block information

master
kanoi 8 years ago
parent
commit
8b3f5d3225
  1. 325
      pool/page_blocks.php

325
pool/page_blocks.php

@ -69,6 +69,182 @@ function pctcolour($pct)
return array($fg, $bg);
}
#
function statstable($poolfee, $ans, $data)
{
if ($ans['STATUS'] != 'ok' or !isset($ans['s_rows']) or $ans['s_rows'] < 1)
return '';
$pg = '<h1>Block Statistics</h1>';
$pg .= "<table cellpadding=0 cellspacing=0 border=0>\n";
$pg .= "<thead><tr class=title>";
$pg .= "<td class=dl>Description</td>";
$pg .= "<td class=dr>Time</td>";
$pg .= "<td class=dr>MeanTx%</td>";
$pg .= "<td class=dr>Diff%</td>";
$pg .= "<td class=dr>Mean%</td>";
$pg .= "<td class=dr>CDF[Erl]</td>";
$pg .= "<td class=dr>Luck%</td>";
$tt = "<span class=q onclick='tip(\"ppst\",6000)'>";
$tt .= '?</span><span class=tip0>';
$tt .= "<span class=notip id=ppst>";
$tt .= "Pool PPS%: MeanTx% * Luck% minus the pool fee</span></span>";
$pg .= "<td class=dr>${tt}PPS%</td>";
$pg .= "</tr></thead><tbody>\n";
$since = $data['info']['lastblock'];
$count = $ans['s_rows'];
for ($i = 0; $i < $count; $i++)
{
if (($i % 2) == 0)
$row = 'even';
else
$row = 'odd';
$desc = $ans['s_desc:'.$i];
$age = daysago($since - $ans['s_prevcreatedate:'.$i]);
$diff = number_format(100 * $ans['s_diffratio:'.$i], 2);
$mean = number_format(100 * $ans['s_diffmean:'.$i], 2);
$cdferl = $ans['s_cdferl:'.$i];
list($fg, $bg) = erlcolour($cdferl);
$cdferldsp = "<font color=$fg>".number_format($cdferl, 4).'</font>';
$bg = " bgcolor=$bg";
$luck = number_format(100 * $ans['s_luck:'.$i], 2);
$txm = number_format(100 * $ans['s_txmean:'.$i], 1);
$o = number_format((100 - $poolfee) * $ans['s_txmean:'.$i] / $ans['s_diffmean:'.$i], 2);
$pg .= "<tr class=$row>";
$pg .= "<td class=dl>$desc Blocks</td>";
$pg .= "<td class=dr>$age</td>";
$pg .= "<td class=dr>$txm%</td>";
$pg .= "<td class=dr>$diff%</td>";
$pg .= "<td class=dr>$mean%</td>";
$pg .= "<td class=dr$bg>$cdferldsp</td>";
$pg .= "<td class=dr>$luck%</td>";
$pg .= "<td class=dr>$o%</td>";
$pg .= "</tr>\n";
}
$pg .= "</tbody></table>\n";
return $pg;
}
#
function monthtable($poolfee, $ans, $limit)
{
if ($ans['STATUS'] != 'ok' or !isset($ans['rows']) or $ans['rows'] < 1)
return '';
$nowmon = intval(gmdate('n', $ans['STAMP']));
$nowyyyy = intval(gmdate('Y', $ans['STAMP']));
$pg = '<h1>Monthly Statistics</h1>';
$pg .= "<table cellpadding=0 cellspacing=0 border=0>\n";
$pg .= "<thead><tr class=title>";
$pg .= "<td class=dl>UTC Month</td>";
$pg .= "<td class=dr>Pool Avg</td>";
$pg .= "<td class=dr>Blocks</td>";
$pg .= "<td class=dr>Expected</td>";
$pg .= "<td class=dr>Mean Diff%</td>";
$pg .= "<td class=dr>MeanTx%</td>";
$pg .= "<td class=dr>Luck%</td>";
$pg .= "<td class=dr>PPS%</td>";
$pg .= "</tr></thead>\n";
$pg .= '<tbody>';
$count = $ans['rows'];
$rout = $bcount = $bcd = $bmon = $byyyy = $bdiffacc = $bdiffratio = $btxn = 0;
$skipped = false;
for ($i = 0; $i < $count; $i++)
{
$conf = $ans['confirmed:'.$i];
// Skip leading orphans
if (!$skipped && ($conf == 'O' || $conf == 'R'))
continue;
$skipped = true;
// If anything is missing, skip this table
$diffratio = $ans['diffratio:'.$i];
if ($diffratio == '?')
break;
$cd = $ans['firstcreatedate:'.$i];
$mon = intval(gmdate('n', $cd));
$yyyy = intval(gmdate('Y', $cd));
// all orphans after a block must be included with that block
if (($conf != 'O' && $conf != 'R')
&& ($mon != $bmon || $yyyy != $byyyy))
{
if ($bcount != 0)
{
if (($rout % 2) == 0)
$row = 'even';
else
$row = 'odd';
if ($bmon == $nowmon && $byyyy == $nowyyyy)
$dots = '&hellip;';
else
$dots = '';
$elap = $bcd - $cd;
$phr = ($bdiffacc / $elap) * pow(2, 32);
$phrdsp = siprefmt($phr);
$name = gmdate('Y M', $bcd);
$exc = number_format($bdiffratio, 2);
if ($bdiffratio > $bcount)
$bcol = 'darkred';
else
$bcol = 'darkgreen';
$md = number_format(100 * $bdiffratio / $bcount, 2);
$mr = number_format(100 * $btxn / $bcount, 2);
$ml = number_format(100 * $bcount / $bdiffratio, 2);
$oa = (100 - $poolfee) * ($bcount / $bdiffratio) * ($btxn / $bcount);
$odsp = number_format($oa, 2);
$pg .= "<tr class=$row>";
$pg .= "<td class=dl>$name$dots</td>";
$pg .= "<td class=dr>${phrdsp}Hs</td>";
$pg .= "<td class=dr><b><font color=$bcol>$bcount</font></b></td>";
$pg .= "<td class=dr>$exc</td>";
$pg .= "<td class=dr>$md%</td>";
$pg .= "<td class=dr>$mr%</td>";
$pg .= "<td class=dr>$ml%</td>";
$pg .= "<td class=dr>$odsp%</td>";
$pg .= "</tr>\n";
$rout++;
}
if ($rout > $limit)
break;
$bcd = $cd;
$bmon = $mon;
$byyyy = $yyyy;
$bcount = $bdiffacc = $bdiffratio = $btxn = 0;
}
$bdiffratio += floatval($ans['diffratio:'.$i]);
$bdiffacc += floatval($ans['diffacc:'.$i]);
if ($conf != 'O' and $conf != 'R')
{
$height = $ans['height:'.$i];
$reward = floatval($ans['reward:'.$i]);
$re = 5000000000.0 * pow(0.5, floor($height / 210000.0));
$btxn += $reward / $re;
$bcount++;
}
}
$pg .= '</tbody></table>';
return $pg;
}
#
function doblocks($data, $user)
{
$blink = '<a href=https://www.blocktrail.com/BTC/block/';
@ -88,154 +264,9 @@ function doblocks($data, $user)
if ($wantcsv === false)
{
if ($ans['STATUS'] == 'ok' and isset($ans['s_rows']) and $ans['s_rows'] > 0)
{
$pg .= '<h1>Block Statistics</h1>';
$pg .= "<table cellpadding=0 cellspacing=0 border=0>\n";
$pg .= "<thead><tr class=title>";
$pg .= "<td class=dl>Description</td>";
$pg .= "<td class=dr>Time</td>";
$pg .= "<td class=dr>MeanTx%</td>";
$pg .= "<td class=dr>Diff%</td>";
$pg .= "<td class=dr>Mean%</td>";
$pg .= "<td class=dr>CDF[Erl]</td>";
$pg .= "<td class=dr>Luck%</td>";
$tt = "<span class=q onclick='tip(\"ppst\",6000)'>";
$tt .= '?</span><span class=tip0>';
$tt .= "<span class=notip id=ppst>";
$tt .= "Pool PPS%: MeanTx% * Luck% minus the pool fee</span></span>";
$pg .= "<td class=dr>${tt}PPS%</td>";
$pg .= "</tr></thead><tbody>\n";
$since = $data['info']['lastblock'];
$count = $ans['s_rows'];
for ($i = 0; $i < $count; $i++)
{
if (($i % 2) == 0)
$row = 'even';
else
$row = 'odd';
$desc = $ans['s_desc:'.$i];
$age = daysago($since - $ans['s_prevcreatedate:'.$i]);
$diff = number_format(100 * $ans['s_diffratio:'.$i], 2);
$mean = number_format(100 * $ans['s_diffmean:'.$i], 2);
$cdferl = $ans['s_cdferl:'.$i];
list($fg, $bg) = erlcolour($cdferl);
$cdferldsp = "<font color=$fg>".number_format($cdferl, 4).'</font>';
$bg = " bgcolor=$bg";
$luck = number_format(100 * $ans['s_luck:'.$i], 2);
$txm = number_format(100 * $ans['s_txmean:'.$i], 1);
$o = number_format((100 - $poolfee) * $ans['s_txmean:'.$i] / $ans['s_diffmean:'.$i], 2);
$pg .= "<tr class=$row>";
$pg .= "<td class=dl>$desc Blocks</td>";
$pg .= "<td class=dr>$age</td>";
$pg .= "<td class=dr>$txm%</td>";
$pg .= "<td class=dr>$diff%</td>";
$pg .= "<td class=dr>$mean%</td>";
$pg .= "<td class=dr$bg>$cdferldsp</td>";
$pg .= "<td class=dr>$luck%</td>";
$pg .= "<td class=dr>$o%</td>";
$pg .= "</tr>\n";
}
$pg .= "</tbody></table>\n";
}
if ($ans['STATUS'] == 'ok' and isset($ans['rows']) and $ans['rows'] > 0)
{
$pg .= '<br><h1>Monthly Statistics</h1>';
$pg .= "<table cellpadding=0 cellspacing=0 border=0>\n";
$pg .= "<thead><tr class=title>";
$pg .= "<td class=dl>UTC Month</td>";
$pg .= "<td class=dr>Blocks</td>";
$pg .= "<td class=dr>Expected</td>";
$pg .= "<td class=dr>Mean Diff%</td>";
$pg .= "<td class=dr>MeanTx%</td>";
$pg .= "<td class=dr>Luck%</td>";
$pg .= "<td class=dr>PPS%</td>";
$pg .= "</tr></thead>\n";
$pg .= '<tbody>';
$count = $ans['rows'];
$rout = $bcount = $bcd = $bmon = $byyyy = $bdiffratio = $btxn = 0;
$skipped = false;
for ($i = 0; $i < $count; $i++)
{
$conf = $ans['confirmed:'.$i];
// Skip leading orphans
if (!$skipped && ($conf == 'O' || $conf == 'R'))
continue;
$skipped = true;
// If anything is missing, skip this table
$diffratio = $ans['diffratio:'.$i];
if ($diffratio == '?')
break;
$cd = $ans['firstcreatedate:'.$i];
$mon = intval(gmdate('n', $cd));
$yyyy = intval(gmdate('Y', $cd));
// all orphans after a block must be included with that block
if (($conf != 'O' && $conf != 'R')
&& ($mon != $bmon || $yyyy != $byyyy))
{
if ($bcount != 0)
{
if (($rout % 2) == 0)
$row = 'even';
else
$row = 'odd';
$name = gmdate('Y M', $bcd);
$exc = number_format($bdiffratio, 2);
$md = number_format(100 * $bdiffratio / $bcount, 2);
$mr = number_format(100 * $btxn / $bcount, 2);
$ml = number_format(100 * $bcount / $bdiffratio, 2);
$o = number_format((100 - $poolfee) * ($bcount / $bdiffratio) * ($btxn / $bcount), 2);
$pg .= "<tr class=$row>";
$pg .= "<td class=dl>$name</td>";
$pg .= "<td class=dr>$bcount</td>";
$pg .= "<td class=dr>$exc</td>";
$pg .= "<td class=dr>$md%</td>";
$pg .= "<td class=dr>$mr%</td>";
$pg .= "<td class=dr>$ml%</td>";
$pg .= "<td class=dr>$o%</td>";
$pg .= "</tr>\n";
$rout++;
}
if ($rout > 7)
break;
$bcd = $cd;
$bmon = $mon;
$byyyy = $yyyy;
$bcount = 0;
$bdiffratio = 0;
$btxn = 0;
}
$bdiffratio += floatval($ans['diffratio:'.$i]);
$pg .= statstable($poolfee, $ans, $data);
if ($conf != 'O' and $conf != 'R')
{
$height = $ans['height:'.$i];
$reward = floatval($ans['reward:'.$i]);
$re = 5000000000.0 * pow(0.5, floor($height / 210000.0));
$btxn += $reward / $re;
$bcount++;
}
}
$pg .= '</tbody></table>';
}
$pg .= monthtable($poolfee, $ans, 7);
if ($ans['STATUS'] == 'ok')
{

Loading…
Cancel
Save