Adding some more information for PPS to sidebar

* Added user share rate to sidebar for PPS
* Added estimated 24h LTC payout based on PPS value and share rate

Addresses #160
This commit is contained in:
Sebastian Grewe 2013-06-14 15:20:30 +02:00
parent 68d874b15a
commit 3f0c3884aa
3 changed files with 34 additions and 2 deletions

View File

@ -199,7 +199,7 @@ class Statistics {
a.username AS username,
a.donate_percent AS donate_percent,
a.email AS email,
COUNT(s.id) AS shares
COUNT(s.id) AS shares
FROM " . $this->user->getTableName() . " AS a
LEFT JOIN " . $this->share->getTableName() . " AS s
ON a.username = SUBSTRING_INDEX( s.username, '.', 1 )
@ -219,6 +219,7 @@ class Statistics {
* @return data integer Current Hashrate in khash/s
**/
public function getUserHashrate($account_id) {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
$stmt = $this->mysqli->prepare("
SELECT ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ")/600/1000) AS hashrate
@ -234,6 +235,28 @@ class Statistics {
return false;
}
/**
* Same as getUserHashrate for Sharerate
* @param account_id integer User ID
* @return data integer Current Sharerate in shares/s
**/
public function getUserSharerate($account_id) {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
$stmt = $this->mysqli->prepare("
SELECT COUNT(s.id)/600 AS sharerate
FROM " . $this->share->getTableName() . " AS s,
" . $this->user->getTableName() . " AS u
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
AND s.time > DATE_SUB(now(), INTERVAL 10 MINUTE)
AND u.id = ?");
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result() )
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate);
// Catchall
$this->debug->append("Failed to fetch sharerate: " . $this->mysqli->error);
return false;
}
/**
* Get hashrate for a specific worker
* @param worker_id int Worker ID to fetch hashrate for

View File

@ -59,6 +59,7 @@ if (@$_SESSION['USERDATA']['id']) {
// Other userdata that we can cache savely
$aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']);
$aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']);
$aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['id']);
// Some estimations
$aGlobal['userdata']['est_block'] = round(( (int)$aGlobal['userdata']['shares']['valid'] / (int)$aRoundShares['valid'] ) * (int)$config['reward'], 3);

View File

@ -14,9 +14,17 @@
<td class="right">{$GLOBAL.userdata.hashrate|number_format} KH/s</td>
</tr>
{if $GLOBAL.config.payout_system == 'pps'}
<tr>
<td><b>Share Rate</b></td>
<td class="right">{$GLOBAL.userdata.sharerate|number_format:"2"} S/s</td>
</tr>
<tr>
<td><b>PPS Value</b></td>
<td>{$GLOBAL.ppsvalue}</td>
<td class="right">{$GLOBAL.ppsvalue}</td>
</tr>
<tr>
<td><b>{$GLOBAL.config.currency} in 24h</b></td>
<td class="right">{($GLOBAL.userdata.sharerate * 24 * 60 * 60 * $GLOBAL.ppsvalue)|number_format:"8"}</td>
</tr>
{/if}
{if $GLOBAL.config.payout_system != 'pps'}