From dac5d33e09fd86bee7358cc7b0c6933242a415fb Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 27 Mar 2016 11:47:46 +0200 Subject: [PATCH] profit: move sha256 GH/s factor in a function todo: handle blake algos like sha --- web/yaamp/core/backend/renting.php | 3 ++- web/yaamp/core/functions/yaamp.php | 16 ++++++++++++++-- web/yaamp/modules/api/ApiController.php | 7 ++----- web/yaamp/modules/site/common_results.php | 6 ++---- .../modules/site/results/current_results.php | 7 ++----- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/web/yaamp/core/backend/renting.php b/web/yaamp/core/backend/renting.php index fbb089c..8403b2a 100644 --- a/web/yaamp/core/backend/renting.php +++ b/web/yaamp/core/backend/renting.php @@ -24,7 +24,8 @@ function BackendRentingUpdate() $rent = dboscalar("select rent from hashrate where algo=:algo order by time desc limit 1", array(':algo'=>$submit->algo)); $amount = $rent * $submit->difficulty / 20116.56761169; - if($submit->algo == 'sha256') $amount /= 1000; + $factor = yaamp_algo_mBTC_factor($submit->algo); // 1000 for sha256 + $amount /= $factor; $submit->amount = $amount - $amount*YAAMP_FEES_RENTING/100; $submit->status = 1; diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index d2a6f4a..34eb304 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -40,6 +40,18 @@ function yaamp_get_algos() ); } +// Used for graphs and 24h profit +// GH/s for fast algos like sha256 +function yaamp_algo_mBTC_factor($algo) +{ + switch($algo) { + case 'sha256': + return 1000; + default: + return 1; + } +} + // mBTC coef per algo function yaamp_get_algo_norm($algo) { @@ -240,8 +252,8 @@ function yaamp_profitability($coin) } } - if($coin->algo == 'sha256') $btcmhd *= 1000; - return $btcmhd; + $algo_unit_factor = yaamp_algo_mBTC_factor($coin->algo); + return $btcmhd * $algo_unit_factor; } function yaamp_convert_amount_user($coin, $amount, $user) diff --git a/web/yaamp/modules/api/ApiController.php b/web/yaamp/modules/api/ApiController.php index 14b0884..79edd88 100644 --- a/web/yaamp/modules/api/ApiController.php +++ b/web/yaamp/modules/api/ApiController.php @@ -64,11 +64,8 @@ class ApiController extends CommonController $hashrate1 = controller()->memcache->get_database_scalar("api_status_avghashrate-$algo", "select avg(hashrate) from hashrate where time>$t and algo=:algo", array(':algo'=>$algo)); -// $btcmhday1 = $hashrate1 != 0? bitcoinvaluetoa($total1 / $hashrate1 * 1000000): '0.00000000'; - if($algo == 'sha256') - $btcmhday1 = $hashrate1 != 0? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000000): '0'; - else - $btcmhday1 = $hashrate1 != 0? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000): '0'; + $algo_unit_factor = yaamp_algo_mBTC_factor($algo); + $btcmhday1 = $hashrate1 != 0? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000 * $algo_unit_factor): ''; $fees = yaamp_fee($algo); $port = getAlgoPort($algo); diff --git a/web/yaamp/modules/site/common_results.php b/web/yaamp/modules/site/common_results.php index e202efd..ae6844e 100644 --- a/web/yaamp/modules/site/common_results.php +++ b/web/yaamp/modules/site/common_results.php @@ -96,10 +96,8 @@ foreach($algos as $item) $total1 = dboscalar("select sum(amount*price) from blocks where category!='orphan' and time>$t1 and algo=:algo", array(':algo'=>$algo)); $hashrate1 = dboscalar("select avg(hashrate) from hashrate where time>$t1 and algo=:algo", array(':algo'=>$algo)); - if($algo == 'sha256') - $btcmhday1 = $hashrate1 != 0? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000000): ''; - else - $btcmhday1 = $hashrate1 != 0? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000): ''; + $algo_unit_factor = yaamp_algo_mBTC_factor($algo); + $btcmhday1 = $hashrate1 != 0? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000 * $algo_unit_factor): ''; $fees = yaamp_fee($algo); diff --git a/web/yaamp/modules/site/results/current_results.php b/web/yaamp/modules/site/results/current_results.php index 7ee70a9..388bf56 100644 --- a/web/yaamp/modules/site/results/current_results.php +++ b/web/yaamp/modules/site/results/current_results.php @@ -101,11 +101,8 @@ foreach($algos as $item) $hashrate1 = controller()->memcache->get_database_scalar("current_hashrate1-$algo", "select avg(hashrate) from hashrate where time>$t and algo=:algo", array(':algo'=>$algo)); -// $btcmhday1 = $hashrate1 != 0? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000): '-'; - if($algo == 'sha256') - $btcmhday1 = $hashrate1 != 0? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000000): ''; - else - $btcmhday1 = $hashrate1 != 0? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000): ''; + $algo_unit_factor = yaamp_algo_mBTC_factor($algo); + $btcmhday1 = $hashrate1 != 0? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000 * $algo_unit_factor): ''; $fees = yaamp_fee($algo); $port = getAlgoPort($algo);