Merge pull request #367 from kanoi/minerphp miner.php prev/next rig buttons, custom page joins for STATS
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
diff --git a/miner.php b/miner.php
index f6250f0..ecabbdb 100644
--- a/miner.php
+++ b/miner.php
@@ -892,7 +892,7 @@ $singlerigsum = array(
'Hardware Errors' => 1, 'Utility' => 1, 'Total MH' => 1),
'pools' => array('Getworks' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Discarded' => 1,
'Stale' => 1, 'Get Failures' => 1, 'Remote Failures' => 1,
- 'Diff1 Shares' => 1),
+ 'Diff1 Shares' => 1, 'Difficulty Accepted' => 1),
'notify' => array('*' => 1));
#
function showtotal($total, $when, $oldvalues)
@@ -1207,7 +1207,7 @@ function process($cmds, $rig)
}
}
#
-function rigbutton($rig, $rigname, $when, $row)
+function rigname($rig, $rigname)
{
global $rigs;
@@ -1218,12 +1218,21 @@ function rigbutton($rig, $rigname, $when, $row)
$rigname = $parts[2];
}
- list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
+ return $rigname;
+}
+#
+function riginput($rig, $rigname)
+{
+ $rigname = rigname($rig, $rigname);
- $button = "<td align=middle$class><input type=button value='$rigname'";
- $button .= " onclick='pr(\"&rig=$rig\",null)'></td>";
+ return "<input type=button value='$rigname' onclick='pr(\"&rig=$rig\",null)'>";
+}
+#
+function rigbutton($rig, $rigname, $when, $row)
+{
+ list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
- return $button;
+ return "<td align=middle$class>".riginput($rig, $rigname).'</td>';
}
#
function showrigs($anss, $headname, $rigname)
@@ -1445,16 +1454,43 @@ function pagebuttons($rig, $pg)
if ($rig === null)
{
+ $prev = null;
+ $next = null;
+
if ($pg === null)
$refresh = '';
else
$refresh = "&pg=$pg";
}
else
+ {
+ switch (count($rigs))
+ {
+ case 0:
+ case 1:
+ $prev = null;
+ $next = null;
+ break;
+ case 2:
+ $prev = null;
+ $next = ($rig + 1) % count($rigs);
+ break;
+ default:
+ $prev = ($rig - 1) % count($rigs);
+ $next = ($rig + 1) % count($rigs);
+ break;
+ }
+
$refresh = "&rig=$rig";
+ }
echo '<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td nowrap>';
+ if ($prev !== null)
+ echo riginput($prev, 'Prev').' ';
echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'> ";
+ if ($next !== null)
+ echo riginput($next, 'Next').' ';
+ echo ' ';
if (count($rigs) > 1)
echo "<input type=button value='Summary' onclick='pr(\"\",null)'> ";
@@ -1522,7 +1558,8 @@ $sectionmap = array(
'DEVDETAILS' => 'devdetails',
'STATS' => 'stats',
'CONFIG' => 'config',
- 'COIN' => 'coin');
+ 'COIN' => 'coin',
+ 'USBSTATS' => 'usbstats');
#
function joinfields($section1, $section2, $join, $results)
{
@@ -1584,6 +1621,79 @@ function joinfields($section1, $section2, $join, $results)
return $newres;
}
#
+function joinlr($section1, $section2, $join, $results)
+{
+ global $sectionmap;
+
+ $name1 = $sectionmap[$section1];
+ $name2 = $sectionmap[$section2];
+ $newres = array();
+
+ // foreach rig in section1
+ foreach ($results[$name1] as $rig => $result)
+ {
+ $status = null;
+
+ // foreach answer section in the rig api call
+ foreach ($result as $name1b => $fields1b)
+ {
+ if ($name1b == 'STATUS')
+ {
+ // remember the STATUS from section1
+ $status = $result[$name1b];
+ continue;
+ }
+
+ // Build L string to be matched
+ // : means a string constant otherwise it's a field name
+ $Lval = '';
+ foreach ($join['L'] as $field)
+ {
+ if (substr($field, 0, 1) == ':')
+ $Lval .= substr($field, 1);
+ else
+ $Lval .= $fields1b[$field];
+ }
+
+ // foreach answer section in the rig api call (for the other api command)
+ foreach ($results[$name2][$rig] as $name2b => $fields2b)
+ {
+ if ($name2b == 'STATUS')
+ continue;
+
+ // Build R string and compare
+ // : means a string constant otherwise it's a field name
+ $Rval = '';
+ foreach ($join['R'] as $field)
+ {
+ if (substr($field, 0, 1) == ':')
+ $Rval .= substr($field, 1);
+ else
+ $Rval .= $fields2b[$field];
+ }
+
+ if ($Lval === $Rval)
+ {
+ if ($status != null)
+ {
+ $newres[$rig]['STATUS'] = $status;
+ $status = null;
+ }
+
+ $subsection = $section1.'+'.$section2;
+ $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
+
+ foreach ($fields1b as $nam => $val)
+ $newres[$rig][$subsection]["$section1.$nam"] = $val;
+ foreach ($fields2b as $nam => $val)
+ $newres[$rig][$subsection]["$section2.$nam"] = $val;
+ }
+ }
+ }
+ }
+ return $newres;
+}
+#
function joinall($section1, $section2, $results)
{
global $sectionmap;
@@ -1628,8 +1738,6 @@ function joinsections($sections, $results, $errors)
{
global $sectionmap;
-#echo "results['pools']=".print_r($results['pools'],true)."<br>";
-
// GPU's don't have Name,ID fields - so create them
foreach ($results as $section => $res)
foreach ($res as $rig => $result)
@@ -1667,14 +1775,33 @@ function joinsections($sections, $results, $errors)
}
break;
case 'DEVS':
- $join = array('Name', 'ID');
switch($both[1])
{
case 'NOTIFY':
case 'DEVDETAILS':
+ case 'USBSTATS':
+ $join = array('Name', 'ID');
$sectionmap[$section] = $section;
$results[$section] = joinfields($both[0], $both[1], $join, $results);
break;
+ case 'STATS':
+ $join = array('L' => array('Name','ID'), 'R' => array('ID'));
+ $sectionmap[$section] = $section;
+ $results[$section] = joinlr($both[0], $both[1], $join, $results);
+ break;
+ default:
+ $errors[] = "Error: Invalid section '$section'";
+ break;
+ }
+ break;
+ case 'POOL':
+ switch($both[1])
+ {
+ case 'STATS':
+ $join = array('L' => array(':POOL','POOL'), 'R' => array('ID'));
+ $sectionmap[$section] = $section;
+ $results[$section] = joinlr($both[0], $both[1], $join, $results);
+ break;
default:
$errors[] = "Error: Invalid section '$section'";
break;
@@ -2099,7 +2226,7 @@ function display()
newtable();
doforeach('version', 'rig summary', array(), array(), true);
- $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH', 'Work Utility', 'Diff1 Shares', 'Diff1 Work');
+ $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH', 'Work Utility', 'Diff1 Shares', 'Diff1 Work', 'Difficulty Accepted', 'Difficulty Rejected', 'Difficulty Stale');
doforeach('summary', 'summary information', $sum, array(), false);
endtable();
otherrow('<td><br><br></td>');