users: rework table and bad shares count

This commit is contained in:
Tanguy Pruvot 2016-03-21 06:21:26 +01:00
parent 4ec4f92619
commit 0f34e167cf
5 changed files with 167 additions and 114 deletions

View file

@ -267,13 +267,13 @@ function yaamp_convert_earnings_user($user, $status)
if (YAAMP_ALLOW_EXCHANGE) {
if(!$refcoin) $refcoin = getdbosql('db_coins', "symbol='BTC'");
if(!$refcoin || $refcoin->price2 <= 0) return 0;
$value = dboscalar("select sum(amount*price) from earnings where $status and userid={$user->id}");
$value = dboscalar("SELECT sum(amount*price) FROM earnings WHERE $status AND userid={$user->id}");
$value = $value / $refcoin->price2;
} else if ($refcoin && $refcoin->price2 > 0.) {
$value = dboscalar("select sum(amount*price) from earnings where $status and userid={$user->id}");
$value = dboscalar("SELECT sum(amount*price) FROM earnings WHERE $status AND userid={$user->id}");
$value = $value / $refcoin->price2;
} else if ($user->coinid) {
$value = dboscalar("select sum(amount) from earnings where $status and userid={$user->id} and coinid={$user->coinid}");
$value = dboscalar("SELECT sum(amount) FROM earnings WHERE $status AND userid={$user->id} AND coinid=".$user->coinid);
}
return $value;
}
@ -289,7 +289,7 @@ function yaamp_pool_rate($algo=null)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_pool_rate-$algo",
"select sum(difficulty) * $target / $interval / 1000 from shares where valid and time>$delay and algo=:algo", array(':algo'=>$algo));
"SELECT (sum(difficulty) * $target / $interval / 1000) FROM shares WHERE valid AND time>$delay AND algo=:algo", array(':algo'=>$algo));
return $rate;
}
@ -303,7 +303,7 @@ function yaamp_pool_rate_bad($algo=null)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_pool_rate_bad-$algo",
"select sum(difficulty) * $target / $interval / 1000 from shares where not valid and time>$delay and algo=:algo", array(':algo'=>$algo));
"SELECT (sum(difficulty) * $target / $interval / 1000) FROM shares WHERE not valid AND time>$delay AND algo=:algo", array(':algo'=>$algo));
return $rate;
}
@ -317,7 +317,7 @@ function yaamp_pool_rate_rentable($algo=null)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_pool_rate_rentable-$algo",
"select sum(difficulty) * $target / $interval / 1000 from shares where valid and extranonce1 and time>$delay and algo=:algo", array(':algo'=>$algo));
"SELECT (sum(difficulty) * $target / $interval / 1000) FROM shares WHERE valid AND extranonce1 AND time>$delay AND algo=:algo", array(':algo'=>$algo));
return $rate;
}
@ -331,7 +331,7 @@ function yaamp_user_rate($userid, $algo=null)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_user_rate-$userid-$algo",
"select sum(difficulty) * $target / $interval / 1000 from shares where valid and time>$delay and userid=$userid and algo=:algo", array(':algo'=>$algo));
"SELECT (sum(difficulty) * $target / $interval / 1000) FROM shares WHERE valid AND time>$delay AND userid=$userid AND algo=:algo", array(':algo'=>$algo));
return $rate;
}
@ -345,7 +345,7 @@ function yaamp_user_rate_bad($userid, $algo=null)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_user_rate_bad-$userid-$algo",
"select sum(difficulty) * $target / $interval / 1000 from shares where not valid and time>$delay and userid=$userid and algo=:algo", array(':algo'=>$algo));
"SELECT (count(id) * $target / $interval / 1000) FROM shares WHERE valid!=1 AND time>$delay AND userid=$userid AND algo=:algo", array(':algo'=>$algo));
return $rate;
}
@ -359,7 +359,7 @@ function yaamp_worker_rate($workerid, $algo=null)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_worker_rate-$workerid-$algo",
"select sum(difficulty) * $target / $interval / 1000 from shares where valid and time>$delay and workerid=$workerid");
"SELECT (sum(difficulty) * $target / $interval / 1000) FROM shares WHERE valid AND time>$delay AND workerid=".$workerid);
return $rate;
}
@ -373,7 +373,7 @@ function yaamp_worker_rate_bad($workerid, $algo=null)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_worker_rate_bad-$workerid-$algo",
"select sum(difficulty) * $target / $interval / 1000 from shares where not valid and time>$delay and workerid=$workerid");
"SELECT (count(id) * $target / $interval / 1000) FROM shares WHERE valid!=1 AND time>$delay AND workerid=".$workerid);
return empty($rate)? 0: $rate;
}
@ -388,7 +388,7 @@ function yaamp_coin_rate($coinid)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_coin_rate-$coinid",
"select sum(difficulty) * $target / $interval / 1000 from shares where valid and time>$delay and coinid=$coinid");
"SELECT (sum(difficulty) * $target / $interval / 1000) FROM shares WHERE valid AND time>$delay AND coinid=$coinid");
return $rate;
}
@ -402,7 +402,7 @@ function yaamp_rented_rate($algo=null)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_rented_rate-$algo",
"select sum(difficulty) * $target / $interval / 1000 from shares where time>$delay and algo=:algo and jobid!=0 and valid", array(':algo'=>$algo));
"SELECT (sum(difficulty) * $target / $interval / 1000) FROM shares WHERE time>$delay AND algo=:algo AND jobid!=0 AND valid", array(':algo'=>$algo));
return $rate;
}
@ -417,7 +417,7 @@ function yaamp_job_rate($jobid)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_job_rate-$jobid",
"select sum(difficulty) * $target / $interval / 1000 from jobsubmits where valid and time>$delay and jobid=$jobid");
"SELECT (sum(difficulty) * $target / $interval / 1000) FROM jobsubmits WHERE valid AND time>$delay AND jobid=".$jobid);
return $rate;
}
@ -431,7 +431,7 @@ function yaamp_job_rate_bad($jobid)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_job_rate_bad-$jobid",
"select sum(difficulty) * $target / $interval / 1000 from jobsubmits where not valid and time>$delay and jobid=$jobid");
"SELECT (count(id) * $target / $interval / 1000) FROM jobsubmits WHERE valid!=1 AND time>$delay AND jobid=".$jobid);
return $rate;
}
@ -447,9 +447,9 @@ function yaamp_pool_rate_pow($algo=null)
$delay = time()-$interval;
$rate = controller()->memcache->get_database_scalar("yaamp_pool_rate_pow-$algo",
"select sum(shares.difficulty) * $target / $interval / 1000 from shares, coins
where shares.valid and shares.time>$delay and shares.algo=:algo and
shares.coinid=coins.id and coins.rpcencoding='POW'", array(':algo'=>$algo));
"SELECT sum(shares.difficulty) * $target / $interval / 1000 FROM shares, coins
WHERE shares.valid AND shares.time>$delay AND shares.algo=:algo AND
shares.coinid=coins.id AND coins.rpcencoding='POW'", array(':algo'=>$algo));
return $rate;
}

View file

@ -609,15 +609,30 @@ class SiteController extends CommonController
//////////////////////////////////////////////////////////////////////////////////////////////////
public function actionBanUser()
{
if(!$this->admin) return;
$user = getdbo('db_accounts', getiparam('id'));
if($user) {
$user->is_locked = true;
$user->balance = 0;
$user->save();
}
$this->goback();
}
public function actionBlockuser()
{
if(!$this->admin) return;
$wallet = getparam('wallet');
$user = getuserparam($wallet);
$user->is_locked = true;
$user->save();
if($user) {
$user->is_locked = true;
$user->save();
}
$this->goback();
}
@ -628,13 +643,29 @@ class SiteController extends CommonController
$wallet = getparam('wallet');
$user = getuserparam($wallet);
$user->is_locked = false;
$user->save();
if($user) {
$user->is_locked = false;
$user->save();
}
$this->goback();
}
public function actionLoguser()
{
if(!$this->admin) return;
$user = getdbo('db_accounts', getiparam('id'));
if($user) {
$user->logtraffic = getiparam('en');
$user->save();
}
$this->goback();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// called from the wallet
public function actionPayuserscoin()
{
@ -786,21 +817,6 @@ class SiteController extends CommonController
$this->redirect("/site/admin");
}
public function actionBanUser()
{
if(!$this->admin) return;
$user = getdbo('db_accounts', getiparam('id'));
if($user)
{
$user->is_locked = true;;
$user->balance = 0;
$user->save();
}
$this->goback();
}
public function actionOptimize()
{
BackendOptimizeTables();

View file

@ -1,23 +1,28 @@
<?php
JavascriptFile("/yaamp/ui/js/jquery.metadata.js");
JavascriptFile("/yaamp/ui/js/jquery.tablesorter.widgets.js");
echo getAdminSideBarLinks();
$symbol = getparam('symbol');
$coins = "<option value='all'>-all-</option>";
$list = getdbolist('db_coins', "enable AND id IN (select distinct coinid from accounts where balance>0.0001)");
$list = getdbolist('db_coins', "enable AND (".
"id IN (SELECT DISTINCT coinid FROM accounts WHERE balance>0.0001) ".
"OR id IN (SELECT DISTINCT coinid from earnings) ) ORDER BY symbol");
foreach($list as $coin)
{
if($coin->symbol == $symbol)
$coins .= "<option value='$coin->symbol' selected>$coin->symbol</option>";
$coins .= '<option value="'.$coin->symbol.'" selected>'.$coin->symbol.'</option>';
else
$coins .= "<option value='$coin->symbol'>$coin->symbol</option>";
$coins .= '<option value="'.$coin->symbol.'">'.$coin->symbol.'</option>';
}
echo <<<end
<div align="right" style="margin-top: -14px; margin-bottom: 6px;">
<div align="right" style="margin-top: -14px; margin-bottom: -6px; margin-right: 140px;">
Select coin: <select id='coin_select'>$coins</select>&nbsp;
</div>
@ -67,5 +72,3 @@ function main_refresh()
</script>
end;
echo "Note: this table show users with a non-zero balance.";

View file

@ -6,38 +6,61 @@ $symbol = getparam('symbol');
$coin = null;
if($symbol == 'all')
$users = getdbolist('db_accounts', "balance>.001 order by balance desc");
$users = getdbolist('db_accounts', "balance>.001 OR id IN (SELECT DISTINCT userid FROM workers) ORDER BY balance DESC");
else
{
$coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$symbol));
if(!$coin) return;
$users = getdbolist('db_accounts', "balance>.001 and coinid=$coin->id order by balance desc");
$users = getdbolist('db_accounts', "coinid={$coin->id} AND (balance>.001 OR id IN (SELECT DISTINCT userid FROM workers)) ORDER BY balance DESC");
}
//echo "<br><table class='dataGrid'>";
echo <<<end
<div align="right" style="margin-top: -20px; margin-bottom: 6px;">
<input class="search" type="search" data-column="all" style="width: 140px;" placeholder="Search..." />
</div>
<style type="text/css">
.red { color: darkred; }
tr.ssrow.filtered { display: none; }
</style>
end;
showTableSorter('maintable', "{
tableClass: 'dataGrid'
tableClass: 'dataGrid',
textExtraction: {
4: function(node, table, cellIndex) { return $(node).attr('data'); },
6: function(node, table, cellIndex) { return $(node).attr('data'); },
},
widgets: ['zebra','filter','Storage','saveSort'],
widgetOptions: {
saveSort: true,
filter_saveFilters: false,
filter_external: '.search',
filter_columnFilters: false,
filter_childRows : true,
filter_ignoreCase: true
}
}");
echo "<thead>";
echo "<tr>";
echo "<th>UID</th>";
echo "<th></th>";
echo "<th>Coin</th>";
echo "<th>Address</th>";
echo "<th>Last</th>";
echo "<th align=right>Miners</th>";
echo "<th align=right>Hashrate</th>";
echo "<th align=right>Bad</th>";
echo "<th></th>";
echo "<th align=right>Blocks</th>";
echo "<th align=right>Diff/Paid</th>";
echo "<th align=right>Balance</th>";
echo "<th align=right>Total Paid</th>";
echo "<th></th>";
echo "</tr>";
echo "</thead><tbody>";
echo <<<end
<thead>
<tr>
<th data-sorter="numeric">UID</th>
<th data-sorter="false">&nbsp;</th>
<th data-sorter="text">Coin</th>
<th data-sorter="text">Address</th>
<th data-sorter="numeric">Last</th>
<th data-sorter="numeric" align="right">Miners</th>
<th data-sorter="numeric" align="right">Hashrate</th>
<th data-sorter="numeric" align="right">Bad</th>
<th data-sorter="numeric" align="right">Blocks</th>
<th data-sorter="numeric" align="right">Diff/Paid</th>
<th data-sorter="currency" align="right">Balance</th>
<th data-sorter="currency" align="right">Total Paid</th>
<th data-sorter="false" align="right" class="actions" width="150">Actions</th>
</tr>
</thead><tbody>
end;
$total_balance = 0;
$total_paid = 0;
@ -46,24 +69,23 @@ $total_unsold = 0;
foreach($users as $user)
{
$target = yaamp_hashrate_constant();
$interval = yaamp_hashrate_step();
$interval = yaamp_hashrate_step(); // 300 seconds
$delay = time()-$interval;
$user_rate = dboscalar("select sum(difficulty) * $target / $interval / 1000 from shares where valid and time>$delay and userid=$user->id");
$user_bad = dboscalar("select sum(difficulty) * $target / $interval / 1000 from shares where not valid and time>$delay and userid=$user->id");
$percent = $user_rate? round($user_bad*100/$user_rate, 3): 0;
$user_rate = dboscalar("SELECT (sum(difficulty) * $target / $interval / 1000) FROM shares WHERE valid AND time>$delay AND userid=".$user->id);
$user_bad = yaamp_user_rate_bad($user->id);// dboscalar("SELECT (count(id) * $target / $interval / 1000) FROM shares WHERE valid=0 AND time>$delay AND userid=".$user->id);
$pct_bad = $user_rate? round($user_bad*100/$user_rate, 3): 0;
$balance = bitcoinvaluetoa($user->balance);
$paid = dboscalar("select sum(amount) from payouts where account_id=$user->id");
$paid = dboscalar("SELECT sum(amount) FROM payouts WHERE account_id=".$user->id);
$d = datetoa2($user->last_login);
$miner_count = getdbocount('db_workers', "userid=$user->id");
$block_count = getdbocount('db_blocks', "userid=$user->id");
$block_diff = $paid? round(dboscalar("select sum(difficulty) from blocks where userid=$user->id")/$paid, 3): '?';
$miner_count = getdbocount('db_workers', "userid=".$user->id);
$block_count = getdbocount('db_blocks', "userid=".$user->id);
$block_diff = ($paid && $block_count) ? round(dboscalar("SELECT sum(difficulty) FROM blocks WHERE userid=".$user->id)/$paid, 3): '?';
$paid = bitcoinvaluetoa($paid);
$user_rate = Itoa2($user_rate);
$user_bad = Itoa2($user_bad);
$coinimg = ''; $coinlink = '';
@ -79,29 +101,41 @@ foreach($users as $user)
}
}
echo "<tr class='ssrow'>";
echo "<td width=24>$user->id</td>";
echo "<td width=16>$coinimg</td>";
echo "<td width=48><b>$coinlink</b></td>";
echo '<tr class="ssrow">';
echo '<td width="24">'.$user->id.'</td>';
echo '<td width="16">'.$coinimg.'</td>';
echo '<td width="48"><b>'.$coinlink.'</b></td>';
echo '<td><a href="/?address='.$user->username.'"><b>'.$user->username.'</b></a></td>';
echo "<td>$d</td>";
echo "<td align=right>$miner_count</td>";
echo '<td data="'.$user->last_login.'">'.$d.'</td>';
echo '<td align=right>'.$miner_count.'</td>';
echo "<td width=32 align=right>$user_rate</td>";
echo "<td width=32 align=right>$user_bad</td>";
echo '<td width="32" data="'.(0+$user_rate).'" align="right">'.($user_rate ? Itoa2($user_rate) : '').'</td>';
echo '<td width="32" align="right">';
if ($pct_bad) echo round($pct_bad,1)."&nbsp;%";
echo '</td>';
if($percent > 50)
echo "<td width=32><b>{$percent}%</b></td>";
echo '<td align="right">'.$block_count.'</td>';
echo '<td align="right">'.($user_rate ? $block_diff : '').'</td>';
echo '<td align="right">'.$balance.'</td>';
echo '<td align="right">'.$paid.'</td>';
echo '<td class="actions" align="right">';
if ($user->logtraffic)
echo '<a href="/site/loguser?id='.$user->id.'&en=0">unwatch</a> ';
else
echo "<td width=32>{$percent}%</td>";
echo '<a href="/site/loguser?id='.$user->id.'&en=1">watch</a> ';
echo "<td align=right>$block_count</td>";
echo "<td align=right>$block_diff</td>";
echo "<td align=right>$balance</td>";
echo "<td align=right>$paid</td>";
if ($user->is_locked)
echo '<a href="/site/unblockuser?wallet='.$user->username.'">unblock</a> ';
else
echo '<a href="/site/blockuser?wallet='.$user->username.'">block</a> ';
echo "<td align=right><a href='/site/banuser?id=$user->id'><b>BAN</b></a></td>";
echo "</tr>";
echo '<a href="/site/banuser?id='.$user->id.'"><span class="red">BAN</span></a>';
echo '</td>';
echo '</tr>';
$total_balance += $user->balance;
$total_paid += $paid;
@ -110,38 +144,38 @@ foreach($users as $user)
echo "</tbody>";
// totals colspan
$colspan = 8;
$colspan = 7;
$total_balance = bitcoinvaluetoa($total_balance);
$total_paid = bitcoinvaluetoa($total_paid);
$user_count = count($users);
echo "<tr class='ssrow' style='border-top: 2px solid #eee;'>";
echo "<td colspan=3><b>Users Total ($user_count)</b></a></td>";
echo "<td colspan=$colspan></td>";
echo "<td align=right><b>$total_balance</b></td>";
echo "<td align=right><b>$total_paid</b></td>";
echo "<td></td>";
echo "</tr>";
echo '<tr class="ssfoot" style="border-top: 2px solid #eee;">';
echo '<th colspan=3><b>Users Total ('.$user_count.')</b></a></th>';
for ($c=0; $c<$colspan; $c++) echo '<th></th>';
echo '<th align="right"><b>'.$total_balance.'</b></th>';
echo '<th align="right"><b>'.$total_paid.'</b></th>';
echo '<th></th>';
echo '</tr>';
if($coin)
{
$balance = bitcoinvaluetoa($coin->balance);
$profit = bitcoinvaluetoa($balance - $total_balance);
echo "<tr class='ssrow' style='border-top: 2px solid #eee;'>";
echo "<td colspan=3><b>Wallet Balance</b></a></td>";
echo "<td colspan=$colspan></td>";
echo "<td align=right><b>$balance</b></td>";
echo "<td colspan=2></td>";
echo "</tr>";
echo '<tr class="ssfoot" style="border-top: 2px solid #eee;"">';
echo '<th colspan="3"><b>Wallet Balance</b></a></th>';
for ($c=0; $c<$colspan; $c++) echo '<th></th>';
echo '<th align="right"><b>'.$balance.'</b></th>';
echo '<th colspan="2"></th>';
echo '</tr>';
echo "<tr class='ssrow' style='border-top: 2px solid #eee;'>";
echo "<td colspan=3><b>Wallet Profit</b></a></td>";
echo "<td colspan=$colspan></td>";
echo "<td align=right><b>$profit</b></td>";
echo "<td colspan=2></td>";
echo "</tr>";
echo '<tr class="ssfoot" style="border-top: 2px solid #eee;">';
echo '<th colspan="3"><b>Wallet Profit</b></a></th>';
for ($c=0; $c<$colspan; $c++) echo '<th></th>';
echo '<th align="right"><b>'.$profit.'</b></th>';
echo '<th colspan="2"></th>';
echo '</tr>';
}
echo "</table>";

View file

@ -74,8 +74,8 @@ foreach($workers as $worker)
));
echo "<td>$shares</td>";
echo "<td>". ($user_bad ? Itoa2($user_bad).'h/s' : '-');
if ($user_bad) {
echo "<td>";
if ($user_bad > 0) {
if ($pct_bad > 50)
echo "<b> {$pct_bad}%</b>";
else