Merge pull request #19 from TheSerapher/next

Next
This commit is contained in:
Sebastian Grewe 2013-05-14 07:34:21 -07:00
commit 64801cfca1
5 changed files with 37 additions and 6 deletions

View File

@ -7,6 +7,7 @@ if (!defined('SECURITY'))
class Share {
private $sError = '';
private $table = 'shares';
private $tableArchive = 'shares_archive';
private $oUpstream;
private $iLastUpstreamId;
// This defines each share
@ -26,6 +27,9 @@ class Share {
return $this->sError;
}
public function getArchiveTableName() {
return $this->tableArchive;
}
public function getTableName() {
return $this->table;
}
@ -93,8 +97,8 @@ class Share {
}
public function moveArchive($previous_upstream=0, $current_upstream,$block_id) {
$archive_stmt = $this->mysqli->prepare("INSERT INTO shares_archive (share_id, username, our_result, upstream_result, block_id)
SELECT id, username, our_result, upstream_result, ?
$archive_stmt = $this->mysqli->prepare("INSERT INTO $this->tableArchive (share_id, username, our_result, upstream_result, block_id, time)
SELECT id, username, our_result, upstream_result, ?, time
FROM $this->table
WHERE id BETWEEN ? AND ?");
$delete_stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE id BETWEEN ? AND ?");

View File

@ -38,10 +38,33 @@ class Statistics {
}
public function getCurrentHashrate() {
$stmt = $this->mysqli->prepare("SELECT ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)");
$stmt = $this->mysqli->prepare("
SELECT SUM(hashrate) AS hashrate FROM
(
SELECT ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
UNION
SELECT ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
) AS sum
");
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) {
return $result->fetch_object()->hashrate;
}
return false;
}
public function getCurrentShareRate() {
$stmt = $this->mysqli->prepare("
SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM
(
SELECT COUNT(id) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
UNION ALL
SELECT COUNT(id) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
) AS sum
");
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) {
return $result->fetch_object()->sharerate;
}
return false;
}
private function checkStmt($bState) {

View File

@ -31,6 +31,7 @@ $aGlobal = array(
'websitename' => $settings->getValue('websitename'),
'ltc_usd' => $settings->getValue('btcesell'),
'hashrate' => $iCurrentPoolHashrate,
'sharerate' => $statistics->getCurrentShareRate(),
'workers' => $iCurrentActiveWorkers,
'roundshares' => $aRoundShares,
'statstime' => $settings->getValue('statstime'),

View File

@ -6,6 +6,7 @@
<tr>
<td><li>Ł/usd: {$GLOBAL.ltc_usd}&nbsp;&nbsp;&nbsp;&nbsp;</li></td>
<td><li>Pool Hashrate: {$GLOBAL.hashrate / 1000} MH/s&nbsp;&nbsp;&nbsp;&nbsp;</li></td>
<td><li>Pool Sharerate: {$GLOBAL.sharerate} Shares/m&nbsp;&nbsp;&nbsp;&nbsp;</li></td>
<td><li>Pool Workers: {$GLOBAL.workers}&nbsp;&nbsp;&nbsp;&nbsp;</li></td>
</tr>
</table>

View File

@ -3,7 +3,7 @@
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Erstellungszeit: 13. Mai 2013 um 16:03
-- Erstellungszeit: 14. Mai 2013 um 16:12
-- Server Version: 5.5.31-0ubuntu0.13.04.1
-- PHP-Version: 5.4.9-4ubuntu2
@ -17,7 +17,7 @@ SET time_zone = "+00:00";
/*!40101 SET NAMES utf8 */;
--
-- Datenbank: `mmcfe_ng`
-- Datenbank: `mmcfe_ng_db`
--
-- --------------------------------------------------------
@ -111,8 +111,10 @@ CREATE TABLE IF NOT EXISTS `shares_archive` (
`our_result` enum('Y','N') DEFAULT NULL,
`upstream_result` enum('Y','N') DEFAULT NULL,
`block_id` int(10) unsigned NOT NULL,
`time` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `share_id` (`share_id`)
UNIQUE KEY `share_id` (`share_id`),
KEY `time` (`time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Archive shares for potential later debugging purposes';
-- --------------------------------------------------------