mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37:25 +00:00
cli: enhance graphes holes maintenance task
This commit is contained in:
parent
ca50beefe6
commit
b7a9174a20
1 changed files with 66 additions and 6 deletions
|
@ -24,16 +24,32 @@ class GraphesCommand extends CConsoleCommand
|
|||
if (!isset($args[0]) || $args[0] == 'help') {
|
||||
|
||||
echo "Yiimp graphes command\n";
|
||||
echo "Usage: yiimp graphes hashrate [algo] - find holes in hashrate graphes\n";
|
||||
echo "Usage: yiimp graphes poolrate [algo] - find holes in hashrate graphes\n";
|
||||
echo " yiimp graphes hashrate [algo] - find holes in user hashrate graphes\n";
|
||||
echo " yiimp graphes balances [coin] - find holes in user balances graphes\n";
|
||||
|
||||
} else if ($args[0] == 'hashrate') {
|
||||
} else if ($args[0] == 'poolrate') {
|
||||
$algos = yaamp_get_algos();
|
||||
foreach ($algos as $algo) {
|
||||
$algo = arraySafeVal($args,1,$algo);
|
||||
$added = $this->checkAndFillPoolHashrateHoles($algo);
|
||||
while ($added > 0) $added = $this->checkAndFillPoolHashrateHoles($algo);
|
||||
}
|
||||
} else if ($args[0] == 'hashrate') {
|
||||
$algos = yaamp_get_algos();
|
||||
foreach ($algos as $algo) {
|
||||
$algo = arraySafeVal($args,1,$algo);
|
||||
$added = $this->checkAndFillUserHashrateHoles($algo);
|
||||
while ($added > 0) $added = $this->checkAndFillUserHashrateHoles($algo);
|
||||
}
|
||||
} else if ($args[0] == 'balances' && arraySafeVal($args,1,'') == '') {
|
||||
$coins = dbolist('SELECT symbol FROM coins WHERE enable AND visible ORDER by symbol');
|
||||
foreach ($coins as $row) {
|
||||
$symbol = $row['symbol'];
|
||||
echo("checking for $symbol holes\n");
|
||||
$added = $this->checkAndFillUserBalanceHoles($symbol);
|
||||
while ($added > 0) $added = $this->checkAndFillUserBalanceHoles($symbol);
|
||||
}
|
||||
} else if ($args[0] == 'balances') {
|
||||
$symbol = arraySafeVal($args,1,'DCR');
|
||||
$added = $this->checkAndFillUserBalanceHoles($symbol);
|
||||
|
@ -69,11 +85,14 @@ class GraphesCommand extends CConsoleCommand
|
|||
$h = strftime('%H:%M', $t);
|
||||
if ($d && $d != 900) {
|
||||
$h0 = strftime('%H:%M', $t2);
|
||||
echo "hole detected between $h0 and $h ($t)\n";
|
||||
echo "hole detected between $h0 and $h ($d sec, $t)\n";
|
||||
$fill = new db_hashrate;
|
||||
$fill->isNewRecord = true;
|
||||
$fill->time = $t2 + 900;
|
||||
$fill->hashrate = ($last_row->hashrate + $row->hashrate) / 2;
|
||||
if ($d > 3600)
|
||||
$fill->hashrate = 0;
|
||||
else
|
||||
$fill->hashrate = ($last_row->hashrate + $row->hashrate) / 2;
|
||||
$fill->price = ($last_row->price + $row->price) / 2;
|
||||
$fill->rent = ($last_row->rent + $row->rent) / 2;
|
||||
$fill->difficulty = ($last_row->difficulty + $row->difficulty) / 2;
|
||||
|
@ -88,6 +107,46 @@ class GraphesCommand extends CConsoleCommand
|
|||
return $added;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill empty data in db_hashuser
|
||||
*/
|
||||
public function checkAndFillUserHashrateHoles($algo)
|
||||
{
|
||||
$stats = new db_hashuser;
|
||||
|
||||
if (!$stats instanceof CActiveRecord)
|
||||
return;
|
||||
|
||||
$t2 = 0; $added = 0; $last_row = array();
|
||||
$since = time() - 24 * 3600;
|
||||
|
||||
$data = $stats->findAll(array('condition'=>"time>=$since AND algo=:algo", 'order'=>'userid, time', 'params'=>array(':algo'=>$algo)));
|
||||
foreach ($data as $row) {
|
||||
$t = (int) $row->time;
|
||||
$d = $t - $t2;
|
||||
if (!$t2 || arraySafeVal($last_row,'userid') != $row->userid) $d = 0;
|
||||
if ($d && $d != 900 && $row->hashrate > 0) {
|
||||
$h = strftime('%H:%M', $t);
|
||||
$h0 = strftime('%H:%M', $t2);
|
||||
echo "uid {$row->userid}: hole detected between $h0 and $h ($d sec, ts $t)\n";
|
||||
$fill = new db_hashuser;
|
||||
$fill->isNewRecord = true;
|
||||
$fill->time = $t2 + 900;
|
||||
$fill->userid = $row->userid;
|
||||
if ($d > 3600)
|
||||
$fill->hashrate = 0;
|
||||
else
|
||||
$fill->hashrate = ($last_row['hashrate'] + $row->hashrate) / 2;
|
||||
$fill->algo = $algo;
|
||||
$added += $fill->save();
|
||||
}
|
||||
$t2 = $t;
|
||||
$last_row = $row->getAttributes();
|
||||
}
|
||||
echo count($data)." records for $algo ($added added)\n";
|
||||
return $added;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill empty data in db_balanceuser
|
||||
*/
|
||||
|
@ -107,10 +166,11 @@ class GraphesCommand extends CConsoleCommand
|
|||
$t = (int) $row['time'];
|
||||
$d = $t - $t2;
|
||||
if (!$t2 || $last_row['userid'] != $row['userid']) $d = 0;
|
||||
$h = strftime('%H:%M', $t);
|
||||
if ($d && $d != 900 && ($row['pending'] + $row['balance']) > 0) {
|
||||
if ($d > 3600) continue;
|
||||
$h = strftime('%H:%M', $t);
|
||||
$h0 = strftime('%H:%M', $t2);
|
||||
echo $row['username'].": hole detected between $h0 and $h ($t)\n";
|
||||
echo $row['username'].": hole detected between $h0 and $h ($d sec, $t)\n";
|
||||
$fill = new db_balanceuser;
|
||||
$fill->isNewRecord = true;
|
||||
$fill->time = $t2 + 900;
|
||||
|
|
Loading…
Add table
Reference in a new issue