From 8b3f5d32254e4e6f690c62ddd2b15c16a2d126e6 Mon Sep 17 00:00:00 2001 From: kanoi Date: Tue, 18 Oct 2016 16:09:23 +1100 Subject: [PATCH] php - block information --- pool/page_blocks.php | 325 ++++++++++++++++++++++++------------------- 1 file changed, 178 insertions(+), 147 deletions(-) diff --git a/pool/page_blocks.php b/pool/page_blocks.php index bc71d2b2..cff64aa6 100644 --- a/pool/page_blocks.php +++ b/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 = '

Block Statistics

'; + $pg .= "\n"; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + + $tt = ""; + $tt .= '?'; + $tt .= ""; + $tt .= "Pool PPS%: MeanTx% * Luck% minus the pool fee"; + + $pg .= ""; + $pg .= "\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 = "".number_format($cdferl, 4).''; + $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 .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= "\n"; + } + $pg .= "
DescriptionTimeMeanTx%Diff%Mean%CDF[Erl]Luck%${tt}PPS%
$desc Blocks$age$txm%$diff%$mean%$cdferldsp$luck%$o%
\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 = '

Monthly Statistics

'; + $pg .= "\n"; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= "\n"; + + $pg .= ''; + $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 = '…'; + 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 .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= ""; + $pg .= "\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 .= '
UTC MonthPool AvgBlocksExpectedMean Diff%MeanTx%Luck%PPS%
$name$dots${phrdsp}Hs$bcount$exc$md%$mr%$ml%$odsp%
'; + + return $pg; +} +# function doblocks($data, $user) { $blink = ' 0) - { - $pg .= '

Block Statistics

'; - $pg .= "\n"; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - - $tt = ""; - $tt .= '?'; - $tt .= ""; - $tt .= "Pool PPS%: MeanTx% * Luck% minus the pool fee"; - - $pg .= ""; - $pg .= "\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 = "".number_format($cdferl, 4).''; - $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 .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= "\n"; - } - $pg .= "
DescriptionTimeMeanTx%Diff%Mean%CDF[Erl]Luck%${tt}PPS%
$desc Blocks$age$txm%$diff%$mean%$cdferldsp$luck%$o%
\n"; - } - - if ($ans['STATUS'] == 'ok' and isset($ans['rows']) and $ans['rows'] > 0) - { - $pg .= '

Monthly Statistics

'; - $pg .= "\n"; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= "\n"; - - $pg .= ''; - $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 .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= ""; - $pg .= "\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 .= '
UTC MonthBlocksExpectedMean Diff%MeanTx%Luck%PPS%
$name$bcount$exc$md%$mr%$ml%$o%
'; - } + $pg .= monthtable($poolfee, $ans, 7); if ($ans['STATUS'] == 'ok') {