miner.php highlighting correctly handling difficulty
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/miner.php b/miner.php
index 268e05b..2c28f6f 100644
--- a/miner.php
+++ b/miner.php
@@ -523,7 +523,15 @@ function classlastshare($when, $alldata, $warnclass, $errorclass)
if (!isset($alldata['Last Share Time']))
return '';
+ if (!isset($alldata['Last Share Difficulty']))
+ return '';
+
$expected = pow(2, 32) / ($alldata['MHS av'] * pow(10, 6));
+
+ // If the share difficulty changes while waiting on a share,
+ // this calculation will of course be incorrect
+ $expected *= $alldata['Last Share Difficulty'];
+
$howlong = $when - $alldata['Last Share Time'];
if ($howlong < 1)
$howlong = 1;
@@ -658,11 +666,20 @@ function fmt($section, $name, $value, $when, $alldata)
if ($value == 0)
$class = $errorclass;
else
- if (isset($alldata['MHS av']))
+ if (isset($alldata['Difficulty Accepted'])
+ && isset($alldata['Accepted'])
+ && isset($alldata['MHS av'])
+ && ($alldata['Difficulty Accepted'] > 0)
+ && ($alldata['Accepted'] > 0))
{
$expected = 60 * $alldata['MHS av'] * (pow(10, 6) / pow(2, 32));
if ($expected == 0)
$expected = 0.000001; // 1 H/s
+
+ $da = $alldata['Difficulty Accepted'];
+ $a = $alldata['Accepted'];
+ $expected /= ($da / $a);
+
$ratio = $value / $expected;
if ($ratio < 0.9)
$class = $loclass;
@@ -730,16 +747,26 @@ function fmt($section, $name, $value, $when, $alldata)
$dec = '';
else
$dec = '.'.$parts[1];
- $ret = number_format($parts[0]).$dec;
+ $ret = number_format((float)$parts[0]).$dec;
if ($value == 0)
$class = $errorclass;
else
- if (isset($alldata['Utility']))
+ if (isset($alldata['Difficulty Accepted'])
+ && isset($alldata['Accepted'])
+ && isset($alldata['Utility'])
+ && ($alldata['Difficulty Accepted'] > 0)
+ && ($alldata['Accepted'] > 0))
{
$expected = 60 * $value * (pow(10, 6) / pow(2, 32));
- $utility = $alldata['Utility'];
- $ratio = $utility / $expected;
+ if ($expected == 0)
+ $expected = 0.000001; // 1 H/s
+
+ $da = $alldata['Difficulty Accepted'];
+ $a = $alldata['Accepted'];
+ $expected /= ($da / $a);
+
+ $ratio = $alldata['Utility'] / $expected;
if ($ratio < 0.9)
$class = $hiclass;
else
@@ -783,7 +810,7 @@ function fmt($section, $name, $value, $when, $alldata)
$dec = '';
else
$dec = '.'.$parts[1];
- $ret = number_format($parts[0]).$dec;
+ $ret = number_format((float)$parts[0]).$dec;
break;
case 'GPU.Status':
case 'PGA.Status':