From 63eb163e329d00f3e9c8f88287298b0f18ffedb0 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 13 Nov 2014 23:06:17 +0100 Subject: [PATCH] api: update sample rig ui totals, readable uptime, autorefresh --- api/index.php | 65 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/api/index.php b/api/index.php index 8ae6518..e49a006 100644 --- a/api/index.php +++ b/api/index.php @@ -27,11 +27,11 @@ function translateField($key) $intl['VER'] = 'Version'; $intl['ALGO'] = 'Algorithm'; - $intl['KHS'] = 'Hashrate (kH/s)'; + $intl['KHS'] = 'Hash rate (kH/s)'; $intl['ACC'] = 'Accepted shares'; $intl['ACCMN'] = 'Accepted / mn'; $intl['REJ'] = 'Rejected'; - $intl['UPTIME'] = 'Miner uptime'; + $intl['UPTIME'] = 'Miner up time'; $intl['TEMP'] = 'T°c'; $intl['FAN'] = 'Fan %'; @@ -42,27 +42,50 @@ function translateField($key) return $key; } +function translateValue($key,$val) +{ + if ($key == 'UPTIME') { + $min = floor(intval($val) / 60); + $sec = intval($val) % 60; + $val = "${min}mn ${sec}s"; + } + return $val; +} + function displayData($data) { $htm = ''; + $totals = array(); foreach ($data as $name => $stats) { $htm .= ''."\n"; $htm .= '\n"; - foreach ($stats['summary'] as $key=>$val) { - if (!empty($val)) - $htm .= ''. - '\n"; - } - foreach ($stats['stats'] as $g=>$gpu) { - $htm .= '\n"; - foreach ($gpu as $key=>$val) { + if (!empty($stats)) { + $summary = $stats['summary']; + foreach ($summary as $key=>$val) { if (!empty($val)) - $htm .= ''. - '\n"; + $htm .= ''. + '\n"; + } + $totals[$summary['ALGO']] += floatval($summary['KHS']); + foreach ($stats['stats'] as $g=>$gpu) { + $htm .= '\n"; + foreach ($gpu as $key=>$val) { + if (!empty($val)) + $htm .= ''. + '\n"; + } } } $htm .= "
'.$name."
'.translateField($key).''.$val."
'.$g."
'.translateField($key).''.$val."
'.translateField($key).''.translateValue($key, $val)."
'.$g."
'.translateField($key).''.translateValue($key, $val)."
\n"; } + // totals + if (!empty($totals)) { + $htm .= '

Total Hash rate

'."\n"; + foreach ($totals as $algo => $hashrate) { + $htm .= '
  • '.$algo.":$hashrate kH/s
  • \n"; + } + $htm .= '
    '; + } return $htm; } @@ -71,12 +94,18 @@ $data = getdataFromPears(); ?> -ccminer rig api sample + ccminer rig api sample + + @@ -127,4 +160,4 @@ td.val { width: 70px; max-width: 180px; color: white; } - + \ No newline at end of file