miner.php custom formatting and row counter '#'
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 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
diff --git a/API-README b/API-README
index 5643e80..a39d24f 100644
--- a/API-README
+++ b/API-README
@@ -1470,20 +1470,25 @@ $autorefresh = default value, 0 means dont auto-refresh
---------
Default:
- $placebuttons = 'top';
-
-Where to place the Refresh, Summary, Custom Pages, Quit, etc. buttons
+ $miner_font_family = 'verdana,arial,sans';
+ $miner_font_size = '13pt';
-Valid values are: 'top' 'bot' 'both'
- anything else means don't show them - case sensitive
+Change these to set the font and font size used on the web page
---------
Default:
- $miner_font_family = 'verdana,arial,sans';
- $miner_font_size = '13pt';
+ $add_css_names = array();
-Change these to set the font and font size used on the web page
+List of CSS names to add to the CSS style object
+ e.g. array('td.cool' => false);
+true/false to not include the default $miner_font
+The CSS name/value pairs must be defined in $colouroverride below
+
+This allows you to create multiple complete CSS styles, optionally
+using a different font to the default used/specified for all other
+styles, and then when using the class name in a custom formatting
+function (fmt) in a customsummarypage, it can use this style
---------
@@ -1504,6 +1509,20 @@ you could do the following:
'td.h background' => 'blue'
);
+You can also add your own CSS styles to be used by a customsummarypage
+custom format function, if you specify the class name in $add_css_names
+and put the class styles in $colouroverride
+
+---------
+
+Default:
+ $placebuttons = 'top';
+
+Where to place the Refresh, Summary, Custom Pages, Quit, etc. buttons
+
+Valid values are: 'top' 'bot' 'both'
+ anything else means don't show them - case sensitive
+
---------
Default:
@@ -1522,16 +1541,22 @@ The section defines what data you want in the summary table and the Fields
define what data you want shown from that section
Standard sections are:
- SUMMARY, POOL, PGA, GPU, NOTIFY, CONFIG, DEVDETAILS, DEVS, STATS, COIN
+ SUMMARY, POOL, PGA, GPU, NOTIFY, CONFIG, DEVDETAILS, DEVS, EDEVS, STATS,
+ ESTATS, COIN
Fields are the names as shown on the headers on the normal pages
+There is a special field name '#' that will total to the number of rows
+displayed in the custom summary page
+In the actual row output it is a row counter per rig
+
Fields can be 'name=new name' to display 'name' with a different heading
'new name'
There are also now joined sections:
- SUMMARY+POOL, SUMMARY+DEVS, SUMMARY+CONFIG, DEVS+NOTIFY, DEVS+DEVDETAILS
- SUMMARY+COIN
+ SUMMARY+POOL, SUMMARY+DEVS, SUMMARY+EDEVS, DEVS+STATS, EDEVS+ESTATS,
+ POOL+STATS plus many more
+See the miner.php function joinsections() for the full list
These sections are an SQL join of the two sections and the fields in them
are named section.field where section. is the section the field comes from
@@ -1648,10 +1673,10 @@ The example given:
With cgminer 2.10.2 and later, miner.php includes an extension to
the custom pages that allows you to apply SQL style commands to
the data: where, group, and having
-cgminer 3.4.2 also includes another option 'gen'
+cgminer 3.4.2 and later also includes another option 'gen'
+cgminer 4.1.1 and later also includes another option 'fmt'
-As an example, miner.php includes a more complex custom page called 'Pools'
-this includes the extension:
+An example of an 'ext' section in a more complex custom summary page:
$poolsext = array(
'POOL+STATS' => array(
@@ -1665,8 +1690,30 @@ $poolsext = array(
'STATS.Times Recv' => 'sum',
'STATS.Bytes Recv' => 'sum'),
'gen' => array('AvShr', 'POOL.Difficulty Accepted/max(POOL.Accepted,1)),
- 'having' => array(array('STATS.Bytes Recv', '>', 0)))
-);
+ 'having' => array(array('STATS.Bytes Recv', '>', 0)),
+ 'fmt' => 'myfmtfunc'));
+
+function myfmtfunc($section, $name, $value, $when, $alldata,
+ $warnclass, $errorclass, $hiclass, $loclass, $totclass);
+{
+ $ret = '';
+ $class = '';
+ switch ($section.'.'.$name)
+ {
+ case 'GEN.AvShr':
+ $ret = number_format((float)$value, 2);
+ if ($value == 0)
+ $class = $errorclass;
+ break;
+ // Nonsence example :) since total would show the sum of the averages
+ case 'total.AvShr':
+ $ret = $value;
+ if ($value == 0)
+ $class = $warnclass;
+ break;
+ }
+ return array($ret, $class);
+}
This allows you to group records together from one or more rigs
In the example, you'll get each Pool (with the same URL+Stratum+GBT settings)
@@ -1717,6 +1764,34 @@ The first 4 are as expected - the numerical sum, average, minimum or maximum
'any' is effectively random: the field value in the 1st row of the grouped data
An unrecognised 'function' uses 'any'
+
+A 'fmt' allows you to specify a function to be called by miner.php to format
+data to be displayed in the output html
+If the function doesn't exist in miner.php or myminer.php, then it will be
+ignored
+If the function returns a $ret value (see the example 'myfmtfunc' above) then
+that will be displayed, however if $ret is empty, then the normal formatting
+code will process the data to be displayed
+Thus, if there is no formatting code in miner.php for the field value, then it
+will be displayed as it was received from the API
+i.e. this allows you to either supply some php code to format field values
+that are not formatted by miner.php, or you can also override the formatting
+done by miner.php itself for your chosen list of field data
+You can return an ' ' if you wish to force it to display as blank
+Use the example 'myfmtfunc' above as a template to write your own
+Note that your provided function will be called for all data being displayed,
+so you should use the 'case' layout as in the example to select the data fields
+you wish to format, but return '' for fields you don't wish to change the way
+they are formatted
+The 2nd return field is the name of a CSS class in $colourtable or created in
+your own $add_css_names and $colouroverride
+The value you return can stay in effect even if you return an empty $ret, if
+the default formatting function for the field doesn't set the $class variable
+The fields passed to your function by miner.php:
+ $warnclass, $errorclass, $hiclass, $loclass, $totclass
+contain the default class names used for formatting
+
+
A 'gen' allows you to generate new fields from any php valid function of any
of the other fields
e.g. 'gen' => array('AvShr', 'POOL.Difficulty Accepted/max(POOL.Accepted,1)),
diff --git a/miner.php b/miner.php
index 3d9fe78..beda63f 100644
--- a/miner.php
+++ b/miner.php
@@ -11,7 +11,7 @@ global $checklastshare, $poolinputs, $hidefields;
global $ignorerefresh, $changerefresh, $autorefresh;
global $allowcustompages, $customsummarypages;
global $miner_font_family, $miner_font_size;
-global $bad_font_family, $bad_font_size;
+global $bad_font_family, $bad_font_size, $add_css_names;
global $colouroverride, $placebuttons, $userlist;
#
$doctype = "<!DOCTYPE html>\n";
@@ -208,6 +208,12 @@ $miner_font_size = '13pt';
$bad_font_family = '"Times New Roman", Times, serif';
$bad_font_size = '18pt';
#
+# List of css names to add to the css style object
+# e.g. array('td.cool' => false);
+# true/false to not include the default $miner_font
+# The css name/value pairs must be defined in $colouroverride below
+$add_css_names = array();
+#
# Edit this or redefine it in myminer.php to change the colour scheme
# See $colourtable below for the list of names
$colouroverride = array();
@@ -314,7 +320,7 @@ function php_pr($cmd)
function htmlhead($mcerr, $checkapi, $rig, $pg = null, $noscript = false)
{
global $doctype, $title, $miner_font_family, $miner_font_size;
- global $bad_font_family, $bad_font_size;
+ global $bad_font_family, $bad_font_size, $add_css_names;
global $error, $readonly, $poolinputs, $here;
global $ignorerefresh, $autorefresh;
@@ -358,8 +364,16 @@ td.sta { $miner_font ".getcss('td.sta')."}
td.tot { $miner_font ".getcss('td.tot')."}
td.lst { $miner_font ".getcss('td.lst')."}
td.hi { $miner_font ".getcss('td.hi')."}
-td.lo { $miner_font ".getcss('td.lo')."}
-</style>
+td.lo { $miner_font ".getcss('td.lo')."}\n";
+ if (isset($add_css_names))
+ foreach ($add_css_names as $css_name => $no_miner_font)
+ {
+ echo "$css_name { ";
+ if ($no_miner_font !== true)
+ echo "$miner_font ";
+ echo getcss("$css_name")."}\n";
+ }
+ echo "</style>
</head><body".getdom('body').">\n";
if ($noscript === false)
{
@@ -796,32 +810,46 @@ function endzero($num)
return $rep;
}
#
-function fmt($section, $name, $value, $when, $alldata)
+function fmt($section, $name, $value, $when, $alldata, $cf = NULL)
{
global $dfmt, $rownum;
if ($alldata == null)
$alldata = array();
- $errorclass = ' class=err';
- $warnclass = ' class=warn';
- $lstclass = ' class=lst';
- $hiclass = ' class=hi';
- $loclass = ' class=lo';
- $c2class = ' class=two';
- $totclass = ' class=tot';
+ $errorclass = 'err';
+ $warnclass = 'warn';
+ $lstclass = 'lst';
+ $hiclass = 'hi';
+ $loclass = 'lo';
+ $c2class = 'two';
+ $totclass = 'tot';
$b = ' ';
- $ret = $value;
$class = '';
$nams = explode('.', $name);
if (count($nams) > 1)
$name = $nams[count($nams)-1];
+ $done = false;
if ($value === null)
+ {
$ret = $b;
+ $done = true;
+ }
else
+ if ($cf != NULL and function_exists($cf))
+ {
+ list($ret, $class) = $cf($section, $name, $value, $when, $alldata,
+ $warnclass, $errorclass, $hiclass, $loclass, $totclass);
+ if ($ret !== '')
+ $done = true;
+ }
+
+ if ($done === false)
+ {
+ $ret = $value;
switch ($section.'.'.$name)
{
case 'GPU.Last Share Time':
@@ -1229,6 +1257,7 @@ function fmt($section, $name, $value, $when, $alldata)
$ret = number_format((float)$value);
break;
}
+ }
if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
$class = $errorclass;
@@ -1245,6 +1274,9 @@ function fmt($section, $name, $value, $when, $alldata)
if ($ret === '')
$ret = $b;
+ if ($class !== '')
+ $class = " class=$class";
+
return array($ret, $class);
}
#
@@ -2291,10 +2323,11 @@ function secmatch($section, $field)
return false;
}
#
-function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
+function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total, $cf = NULL)
{
global $rigbuttons;
+ $rn = 0;
foreach ($result as $sec => $row)
{
$secname = preg_replace('/\d/', '', $sec);
@@ -2314,13 +2347,22 @@ function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total
echo rigbutton($rig, $rig, $when, $row, $rigbuttons);
else
{
- list($ignore, $class) = fmt('total', '', '', $when, $row);
+ list($ignore, $class) = fmt('total', '', '', $when, $row, $cf);
echo "<td align=middle$class>$rig</td>";
}
foreach ($showfields as $name => $one)
{
- if (isset($row[$name]))
+ if ($name === '#' and $sec != 'total')
+ {
+ $rn++;
+ $value = $rn;
+ if (isset($total[$name]))
+ $total[$name]++;
+ else
+ $total[$name] = 1;
+ }
+ elseif (isset($row[$name]))
{
$value = $row[$name];
@@ -2341,11 +2383,14 @@ function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total
}
if (strpos($secname, '+') === false)
- list($showvalue, $class) = fmt($secname, $name, $value, $when, $row);
+ list($showvalue, $class) = fmt($secname, $name, $value, $when, $row, $cf);
else
{
- $parts = explode('.', $name, 2);
- list($showvalue, $class) = fmt($parts[0], $parts[1], $value, $when, $row);
+ if ($name != '#')
+ $parts = explode('.', $name, 2);
+ else
+ $parts[0] = $parts[1] = '#';
+ list($showvalue, $class) = fmt($parts[0], $parts[1], $value, $when, $row, $cf);
}
echo "<td$class align=right>$showvalue</td>";
@@ -2710,6 +2755,11 @@ function processcustompage($pagename, $sections, $sum, $ext, $namemap)
if (isset($results[$sectionmap[$section]]))
{
+ if (isset($ext[$section]['fmt']))
+ $cf = $ext[$section]['fmt'];
+ else
+ $cf = NULL;
+
$rigresults = processext($ext, $section, $results[$sectionmap[$section]], $fields);
$showfields = array();
@@ -2733,6 +2783,11 @@ function processcustompage($pagename, $sections, $sum, $ext, $namemap)
$showhead[$f] = 1;
}
}
+ elseif ($field === '#')
+ {
+ $showfields[$field] = 1;
+ $showhead[$field] = 1;
+ }
elseif (isset($row[$field]))
{
$showfields[$field] = 1;
@@ -2761,10 +2816,10 @@ function processcustompage($pagename, $sections, $sum, $ext, $namemap)
$add = array('total' => array());
foreach ($rigresults as $num => $result)
- $total = customset($showfields, $sum, $section, $num, true, $result, $total);
+ $total = customset($showfields, $sum, $section, $num, true, $result, $total, $cf);
if (count($total) > 0)
- customset($showfields, $sum, $section, 'Σ', false, $add, $total);
+ customset($showfields, $sum, $section, 'Σ', false, $add, $total, $cf);
$first = false;