$averages[] = array($d, $m);
}
echo '],[';
$average = $averages[0][1];
foreach ($averages as $i => $n) {
    if ($i) {
        echo ',';
    }
    $average = ($average * (100 - $percent) + $n[1] * $percent) / 100;
    $m = round($average, 3);
    echo "[\"{$n[0]}\",{$m}]";
}
echo '],[';
for ($i = $t + $step, $j = 0; $i < time(); $i += $step) {
    if ($i != $t + $step) {
        echo ',';
    }
    $m = 0;
    if ($i + $step >= time()) {
        $m = round(yaamp_user_rate_bad($user->id, $algo) / 1000000, 3);
        //	debuglog("last $m");
    } else {
        if (isset($stats[$j]) && $i > $stats[$j]->time) {
            $m = round($stats[$j]->hashrate_bad / 1000000, 3);
            $j++;
        }
    }
    $d = date('Y-m-d H:i:s', $i);
    echo "[\"{$d}\",{$m}]";
}
echo ']]';
echo "<div class='main-left-title'>Miners: {$user->username}</div>";
echo "<div class='main-left-inner'>";
echo "<table  class='dataGrid2'>";
echo "<thead>";
echo "<tr>";
echo "<th align=left>Summary</th>";
echo "<th align=right>Miners</th>";
echo "<th align=right>Shares</th>";
echo "<th align=right width=80>Hashrate*</th>";
echo "<th align=right width=60>Reject*</th>";
echo "</tr>";
echo "</thead>";
foreach (yaamp_get_algos() as $algo) {
    //	debuglog($algo);
    $user_rate1 = yaamp_user_rate($user->id, $algo);
    $user_rate1_bad = yaamp_user_rate_bad($user->id, $algo);
    $percent_bad = $user_rate1 + $user_rate1_bad ? $user_rate1_bad * 100 / ($user_rate1 + $user_rate1_bad) : 0;
    $percent_bad = $percent_bad ? round($percent_bad, 1) . '%' : '';
    $user_rate1 = $user_rate1 ? Itoa2($user_rate1) . 'h/s' : '-';
    $minercount = getdbocount('db_workers', "userid={$user->id} and algo=:algo", array(':algo' => $algo));
    $user_shares = controller()->memcache->get_database_scalar("wallet_user_shares-{$user->id}-{$algo}", "select sum(difficulty) from shares where valid and algo=:algo and userid={$user->id}", array(':algo' => $algo));
    if (!$user_shares && !$minercount) {
        continue;
    }
    $total_shares = controller()->memcache->get_database_scalar("wallet_total_shares-{$algo}", "select sum(difficulty) from shares where valid and algo=:algo", array(':algo' => $algo));
    if (!$total_shares) {
        continue;
    }
    $percent_shares = round($user_shares * 100 / $total_shares, 4);
    echo "<tr class='ssrow'>";
    echo "<td><b>{$algo}</b></td>";
Example #3
0
function BackendStatsUpdate2()
{
    //	debuglog('----------------------------------');
    //	debuglog(__FUNCTION__);
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    $step = 15;
    $t = floor(time() / $step / 60) * $step * 60;
    $list = dbolist("select userid, algo from shares where time>{$t} group by userid, algo");
    foreach ($list as $item) {
        $stats = getdbosql('db_hashuser', "time={$t} and algo=:algo and userid=:userid", array(':algo' => $item['algo'], ':userid' => $item['userid']));
        if (!$stats) {
            $stats = new db_hashuser();
            $stats->userid = $item['userid'];
            $stats->time = $t;
            $stats->hashrate = dboscalar("select hashrate from hashuser where algo=:algo and userid=:userid order by time desc limit 1", array(':algo' => $item['algo'], ':userid' => $item['userid']));
            $stats->hashrate_bad = 0;
            $stats->algo = $item['algo'];
        }
        $percent = 20;
        $user_rate = yaamp_user_rate($item['userid'], $item['algo']);
        $stats->hashrate = round(($stats->hashrate * (100 - $percent) + $user_rate * $percent) / 100);
        if ($stats->hashrate < 1000) {
            $stats->hashrate = 0;
        }
        $user_rate_bad = yaamp_user_rate_bad($item['userid'], $item['algo']);
        $stats->hashrate_bad = round(($stats->hashrate_bad * (100 - $percent) + $user_rate_bad * $percent) / 100);
        if ($stats->hashrate_bad < 1000) {
            $stats->hashrate_bad = 0;
        }
        $stats->save();
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    $step = 15;
    $t = floor(time() / $step / 60) * $step * 60;
    $list = dbolist("select distinct jobid from jobsubmits where time>{$t}");
    foreach ($list as $item) {
        $jobid = $item['jobid'];
        $stats = getdbosql('db_hashrenter', "time={$t} and jobid={$jobid}");
        if (!$stats) {
            $stats = new db_hashrenter();
            //	$stats->renterid = ;
            $stats->jobid = $item['jobid'];
            $stats->time = $t;
            $stats->hashrate = dboscalar("select hashrate from hashrenter where jobid=:jobid order by time desc limit 1", array(':jobid' => $jobid));
            $stats->hashrate_bad = 0;
            //dboscalar("select hashrate_bad from hashrenter where jobid=$jobid order by time desc limit 1");
        }
        $percent = 20;
        $job_rate = yaamp_job_rate($jobid);
        $stats->hashrate = round(($stats->hashrate * (100 - $percent) + $job_rate * $percent) / 100);
        if ($stats->hashrate < 1000) {
            $stats->hashrate = 0;
        }
        $job_rate_bad = yaamp_job_rate_bad($jobid);
        $stats->hashrate_bad = round(($stats->hashrate_bad * (100 - $percent) + $job_rate_bad * $percent) / 100);
        if ($stats->hashrate_bad < 1000) {
            $stats->hashrate_bad = 0;
        }
        $stats->save();
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    $t = floor(time() / $step / 60) * $step * 60;
    $d = time() - 24 * 60 * 60;
    $list = getdbolist('db_accounts', "balance>0 or last_login>{$d}");
    foreach ($list as $user) {
        $stats = getdbosql('db_balanceuser', "time={$t} and userid={$user->id}");
        if (!$stats) {
            $stats = new db_balanceuser();
            $stats->userid = $user->id;
            $stats->time = $t;
        }
        // 		$refcoin = getdbo('db_coins', $user->coinid);
        // 		if(!$refcoin) $refcoin = getdbosql('db_coins', "symbol='BTC'");
        // 		if(!$refcoin->price || !$refcoin->price2) continue;
        // 		$pending1 = dboscalar("select sum(amount*price) from earnings where coinid=$refcoin->id and status!=2 and userid=$user->id");
        // 		$pending2 = dboscalar("select sum(amount*price) from earnings where coinid!=$refcoin->id and status!=2 and userid=$user->id");
        $stats->pending = yaamp_convert_earnings_user($user, "status!=2");
        $stats->pending = bitcoinvaluetoa($stats->pending);
        $stats->balance = $user->balance;
        $stats->save();
        $id = dboscalar("select id from earnings where userid={$user->id} order by id desc limit 100, 1");
        if ($id) {
            dborun("delete from earnings where status=2 and userid={$user->id} and id<{$id}");
        }
    }
}
    $averages[] = array($d, $m);
}
echo '],[';
$average = $averages[0][1];
foreach ($averages as $i => $n) {
    if ($i) {
        echo ',';
    }
    $average = ($average * (100 - $percent) + $n[1] * $percent) / 100;
    $m = round($average, 3);
    echo "[\"{$n[0]}\",{$m}]";
}
echo '],[';
for ($i = $t + $step, $j = 0; $i < time(); $i += $step) {
    if ($i != $t + $step) {
        echo ',';
    }
    $m = 0;
    if ($i + $step >= time()) {
        $m = round(yaamp_user_rate_bad($jobid) / 1000000, 3);
        //	debuglog("last $m");
    } else {
        if (isset($stats[$j]) && $i > $stats[$j]->time) {
            $m = round($stats[$j]->hashrate_bad / 1000000, 3);
            $j++;
        }
    }
    $d = date('Y-m-d H:i:s', $i);
    echo "[\"{$d}\",{$m}]";
}
echo ']]';