Browse Source

ckdb/php - add all pool hash rates to pool stats

master
kanoi 10 years ago
parent
commit
2f501e9d9e
  1. 16
      pool/base.php
  2. 38
      pool/page.php
  3. 26
      pool/page_reg.php
  4. 56
      pool/page_stats.php
  5. 22
      pool/page_workers.php
  6. 2
      src/ckdb.h
  7. 21
      src/ckdb_cmd.c
  8. 1
      src/ckdb_dbio.c

16
pool/base.php

@ -87,6 +87,22 @@ function siprefmt($amt)
return number_format($amt, $dot).$sipre[$pref]; return number_format($amt, $dot).$sipre[$pref];
} }
# #
function dsprate($hr)
{
$hr /= 10000000;
if ($hr < 100000)
{
if ($hr < 0.01)
$hr = '0GHs';
else
$hr = number_format(round($hr)/100, 2).'GHs';
}
else
$hr = number_format(round($hr/1000)/100, 2).'THs';
return $hr;
}
#
function difffmt($amt) function difffmt($amt)
{ {
return siprefmt($amt); return siprefmt($amt);

38
pool/page.php

@ -145,11 +145,10 @@ h1 {margin-top: 20px; float:middle; font-size: 20px;}
return $head; return $head;
} }
# #
function pgtop($dotop, $user, $douser) function pgtop($info, $dotop, $user, $douser)
{ {
global $site_title; global $site_title;
$info = homeInfo($user);
$phr = '?THs'; $phr = '?THs';
$plb = '?'; $plb = '?';
$nlb = '?'; $nlb = '?';
@ -172,13 +171,7 @@ function pgtop($dotop, $user, $douser)
if ($phr == '?') if ($phr == '?')
$phr = '?THs'; $phr = '?THs';
else else
{ $phr = dsprate($phr);
$phr /= 10000000;
if ($phr < 100000)
$phr = (round($phr)/100).'GHs';
else
$phr = (round($phr/1000)/100).'THs';
}
if (isset($info['lastblock'])) if (isset($info['lastblock']))
{ {
@ -254,13 +247,7 @@ function pgtop($dotop, $user, $douser)
if ($uhr == '?') if ($uhr == '?')
$uhr = '?GHs'; $uhr = '?GHs';
else else
{ $uhr = dsprate($uhr);
$uhr /= 10000000;
if ($uhr < 100000)
$uhr = (round($uhr)/100).'GHs';
else
$uhr = (round($uhr/1000)/100).'THs';
}
} }
if (isset($info['u_hashrate1hr']) if (isset($info['u_hashrate1hr'])
@ -272,11 +259,7 @@ function pgtop($dotop, $user, $douser)
$u1hr = ''; $u1hr = '';
else else
{ {
$u1hr /= 10000000; $u1hr = dsprate($u1hr);
if ($u1hr < 100000)
$u1hr = '/'.(round($u1hr)/100).'GHs';
else
$u1hr = '/'.(round($u1hr/1000)/100).'THs';
if (substr($u1hr, -3) == substr($uhr, -3)) if (substr($u1hr, -3) == substr($uhr, -3))
$uhr = substr($uhr, 0, -3); $uhr = substr($uhr, 0, -3);
@ -395,7 +378,7 @@ function pgmenu($menus)
return $ret; return $ret;
} }
# #
function pgbody($page, $menu, $dotop, $user, $douser) function pgbody($info, $page, $menu, $dotop, $user, $douser)
{ {
$body = '<body onload="jst()"'; $body = '<body onload="jst()"';
if ($page == 'index') if ($page == 'index')
@ -407,7 +390,7 @@ function pgbody($page, $menu, $dotop, $user, $douser)
$body .= '<table border=0 cellpadding=0 cellspacing=0 width=94%>'; $body .= '<table border=0 cellpadding=0 cellspacing=0 width=94%>';
$body .= '<tr><td>'; $body .= '<tr><td>';
$body .= pgtop($dotop, $user, $douser); $body .= pgtop($info, $dotop, $user, $douser);
$body .= '</td></tr>'; $body .= '</td></tr>';
$body .= '<tr><td>'; $body .= '<tr><td>';
@ -449,8 +432,13 @@ function gopage($data, $pagefun, $page, $menu, $name, $user, $ispage = true, $do
else else
$pg = ''; $pg = '';
$info = homeInfo($user);
if ($ispage == true) if ($ispage == true)
$pg .= $pagefun($data, $user); {
$both = array('info' => $info, 'data' => $data);
$pg .= $pagefun($both, $user);
}
else else
$pg .= $pagefun; $pg .= $pagefun;
@ -458,7 +446,7 @@ function gopage($data, $pagefun, $page, $menu, $name, $user, $ispage = true, $do
// unset($_SESSION['logkey']); // unset($_SESSION['logkey']);
$head = pghead($script_marker, $name); $head = pghead($script_marker, $name);
$body = pgbody($page, $menu, $dotop, $user, $douser); $body = pgbody($info, $page, $menu, $dotop, $user, $douser);
$foot = pgfoot(); $foot = pgfoot();
if ($dbg === true) if ($dbg === true)

26
pool/page_reg.php

@ -5,21 +5,21 @@ include_once('email.php');
# #
function doregres($data, $u) function doregres($data, $u)
{ {
if (isset($data['user'])) if (isset($data['data']['user']))
$user = htmlspecialchars($data['user']); $user = htmlspecialchars($data['data']['user']);
else else
$user = ''; $user = '';
if (isset($data['mail'])) if (isset($data['data']['mail']))
$mail = htmlspecialchars($data['mail']); $mail = htmlspecialchars($data['data']['mail']);
else else
$mail = ''; $mail = '';
$pg = '<br><br><table cellpadding=5 cellspacing=0 border=1><tr><td class=dc>'; $pg = '<br><br><table cellpadding=5 cellspacing=0 border=1><tr><td class=dc>';
$pg .= '<h1>Register</h1>'; $pg .= '<h1>Register</h1>';
if (isset($data['error'])) if (isset($data['data']['error']))
$pg .= "<br><b>".$data['error']." - please try again</b><br><br>"; $pg .= "<br><b>".$data['data']['error']." - please try again</b><br><br>";
$pg .= makeForm(''); $pg .= makeForm('');
$pg .= " $pg .= "
<table> <table>
@ -65,8 +65,8 @@ An Email will be sent to you, to let you reset your password</font></td></tr>
# #
function doreg2($data) function doreg2($data)
{ {
if (isset($data['user'])) if (isset($data['data']['user']))
$user = htmlspecialchars($data['user']); $user = htmlspecialchars($data['data']['user']);
else else
$user = ''; $user = '';
@ -74,8 +74,8 @@ function doreg2($data)
// $pg .= '<br>You will receive an email shortly to verify your account'; // $pg .= '<br>You will receive an email shortly to verify your account';
$pg .= '<br>Your account is registered and ready to mine.'; $pg .= '<br>Your account is registered and ready to mine.';
$pg .= '<br>Choose your own worker names in cgminer.'; $pg .= '<br>Choose your own worker names in cgminer.';
$pg .= '<br>Worker names must start with your username like'; $pg .= '<br>Worker names must start with your username and a dot or an underscore';
$pg .= ": <span class=hil>${user}_</span> or <span class=hil>${user}.</span>"; $pg .= "<br>e.g. <span class=hil>${user}_worker1</span> or <span class=hil>${user}.worker7</span>";
return $pg; return $pg;
} }
# #
@ -138,8 +138,8 @@ function try_reg($page, $menu, $name, $u)
# #
function doreset2($data) function doreset2($data)
{ {
$user = $data['user']; $user = $data['data']['user'];
$email = $data['email']; $email = $data['data']['email'];
$emailinfo = getOpts($user, emailOptList()); $emailinfo = getOpts($user, emailOptList());
if ($emailinfo['STATUS'] != 'ok') if ($emailinfo['STATUS'] != 'ok')
@ -154,7 +154,7 @@ function doreset2($data)
{ {
// This line $code = isn't an attempt at security - // This line $code = isn't an attempt at security -
// it's simply to ensure the username is readable when we get it back // it's simply to ensure the username is readable when we get it back
$code = bin2hex($data['user']). '_'; $code = bin2hex($data['data']['user']). '_';
// A code that's large enough to not be worth guessing // A code that's large enough to not be worth guessing
$ran = $ans['STAMP'].$user.$email.rand(100000000,999999999); $ran = $ans['STAMP'].$user.$email.rand(100000000,999999999);

56
pool/page_stats.php

@ -12,6 +12,50 @@ function dostats($data, $user)
{ {
$pg = '<h1>Pool Stats</h1>'; $pg = '<h1>Pool Stats</h1>';
if (isset($data['info']) && $data['info'] !== false)
{
$info = $data['info'];
$dsp = '?THs';
$dsp5m = '?THs';
$dsp1hr = '?THs';
$dsp24hr = '?THs';
if (isset($info['p_hashrate']))
{
$hr = $info['p_hashrate'];
if ($hr != '?')
$dsp = dsprate($hr);
}
if (isset($info['p_hashrate5m']))
{
$hr = $info['p_hashrate5m'];
if ($hr != '?')
$dsp5m = dsprate($hr);
}
if (isset($info['p_hashrate1hr']))
{
$hr = $info['p_hashrate1hr'];
if ($hr != '?')
$dsp1hr = dsprate($hr);
}
if (isset($info['p_hashrate24hr']))
{
$hr = $info['p_hashrate24hr'];
if ($hr != '?')
$dsp24hr = dsprate($hr);
}
$pg .= '<table cellpadding=8 cellspacing=0 border=0><tr>';
$pg .= "<td>Pool Hashrate: $dsp</td>";
$pg .= "<td>5m: $dsp5m</td>";
$pg .= "<td>1hr: $dsp1hr</td>";
$pg .= "<td>24hr: $dsp24hr</td>";
$pg .= '</tr></table><br>';
}
$ans = getAllUsers($user); $ans = getAllUsers($user);
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n"; $pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
@ -45,17 +89,7 @@ function dostats($data, $user)
if ($uhr == '?') if ($uhr == '?')
$dsp = '?GHs'; $dsp = '?GHs';
else else
{ $dsp = dsprate($uhr);
$uhr /= 10000000;
if ($uhr < 100000)
$rate = 'G';
else
{
$rate = 'T';
$uhr /= 1000;
}
$dsp = number_format($uhr/100, 2).$rate.'Hs';
}
$pg .= "<td class=dr>$dsp</td>"; $pg .= "<td class=dr>$dsp</td>";
$pg .= "</tr>\n"; $pg .= "</tr>\n";
} }

22
pool/page_workers.php

@ -82,16 +82,7 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
else else
{ {
$totrate += $uhr; $totrate += $uhr;
$uhr /= 10000000; $uhr = dsprate($uhr);
if ($uhr < 0.01)
$uhr = '0GHs';
else
{
if ($uhr < 100000)
$uhr = number_format(round($uhr)/100,2).'GHs';
else
$uhr = number_format(round($uhr/1000)/100,2).'THs';
}
} }
$pg .= "<td class=dr>$uhr</td>"; $pg .= "<td class=dr>$uhr</td>";
@ -106,16 +97,7 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
function worktotal($offset, $totshare, $totdiff, $totinvalid, $totrate, $blockacc, $blockreward) function worktotal($offset, $totshare, $totdiff, $totinvalid, $totrate, $blockacc, $blockreward)
{ {
$pg = ''; $pg = '';
$totrate /= 10000000; $totrate = dsprate($totrate);
if ($totrate < 0.01)
$totrate = '0GHs';
else
{
if ($totrate < 100000)
$totrate = number_format(round($totrate)/100,2).'GHs';
else
$totrate = number_format(round($totrate/1000)/100,2).'THs';
}
if (($offset % 2) == 0) if (($offset % 2) == 0)
$row = 'even'; $row = 'even';
else else

2
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "0.9.2" #define DB_VERSION "0.9.2"
#define CKDB_VERSION DB_VERSION"-0.402" #define CKDB_VERSION DB_VERSION"-0.403"
#define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #define WHERE_FFL_HERE __FILE__, __func__, __LINE__

21
src/ckdb_cmd.c

@ -2006,6 +2006,10 @@ static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id,
snprintf(tmp, sizeof(tmp), "workers=%s%c", reply, FLDSEP); snprintf(tmp, sizeof(tmp), "workers=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
double_to_buf(poolstats->hashrate, reply, siz);
snprintf(tmp, sizeof(tmp), "p_hashrate=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
double_to_buf(poolstats->hashrate5m, reply, siz); double_to_buf(poolstats->hashrate5m, reply, siz);
snprintf(tmp, sizeof(tmp), "p_hashrate5m=%s%c", reply, FLDSEP); snprintf(tmp, sizeof(tmp), "p_hashrate5m=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
@ -2014,13 +2018,24 @@ static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id,
snprintf(tmp, sizeof(tmp), "p_hashrate1hr=%s%c", reply, FLDSEP); snprintf(tmp, sizeof(tmp), "p_hashrate1hr=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
double_to_buf(poolstats->hashrate24hr, reply, siz);
snprintf(tmp, sizeof(tmp), "p_hashrate24hr=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
bigint_to_buf(poolstats->elapsed, reply, siz); bigint_to_buf(poolstats->elapsed, reply, siz);
snprintf(tmp, sizeof(tmp), "p_elapsed=%s%c", reply, FLDSEP); snprintf(tmp, sizeof(tmp), "p_elapsed=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
tvs_to_buf(&(poolstats->createdate), reply, siz);
snprintf(tmp, sizeof(tmp), "p_statsdate=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
} else { } else {
snprintf(tmp, sizeof(tmp), "users=?%cworkers=?%cp_hashrate5m=?%c" snprintf(tmp, sizeof(tmp), "users=?%cworkers=?%cp_hashrate=?%c"
"p_hashrate1hr=?%cp_elapsed=?%c", "p_hashrate5m=?%cp_hashrate1hr=?%c"
FLDSEP, FLDSEP, FLDSEP, FLDSEP, FLDSEP); "p_hashrate24hr=?%cp_elapsed=?%c"
"p_statsdate=?%c",
FLDSEP, FLDSEP, FLDSEP, FLDSEP,
FLDSEP, FLDSEP, FLDSEP, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
} }

1
src/ckdb_dbio.c

@ -4456,6 +4456,7 @@ unparam:
return ok; return ok;
} }
// This is to RAM. The summariser calls the DB I/O functions for userstats
bool userstats_add(char *poolinstance, char *elapsed, char *username, bool userstats_add(char *poolinstance, char *elapsed, char *username,
char *workername, char *hashrate, char *hashrate5m, char *workername, char *hashrate, char *hashrate5m,
char *hashrate1hr, char *hashrate24hr, bool idle, char *hashrate1hr, char *hashrate24hr, bool idle,

Loading…
Cancel
Save