Browse Source

Semi-Merge commit '35d18e8' into cg_merges_20121215

Conflicts:
	miner.php
Luke Dashjr 13 years ago
parent
commit
e045c656eb
1 changed files with 248 additions and 6 deletions
  1. 248 6
      miner.php

+ 248 - 6
miner.php

@@ -824,6 +824,28 @@ function fmt($section, $name, $value, $when, $alldata)
 	case 'BUTTON.GPU':
 		$ret = $value;
 		break;
+	case 'SUMMARY.Difficulty Accepted':
+	case 'GPU.Difficulty Accepted':
+	case 'PGA.Difficulty Accepted':
+	case 'DEVS.Difficulty Accepted':
+	case 'POOL.Difficulty Accepted':
+	case 'total.Difficulty Accepted':
+	case 'SUMMARY.Difficulty Rejected':
+	case 'GPU.Difficulty Rejected':
+	case 'PGA.Difficulty Rejected':
+	case 'DEVS.Difficulty Rejected':
+	case 'POOL.Difficulty Rejected':
+	case 'total.Difficulty Rejected':
+	case 'SUMMARY.Difficulty Stale':
+	case 'POOL.Difficulty Stale':
+	case 'total.Difficulty Stale':
+	case 'GPU.Last Share Difficulty':
+	case 'PGA.Last Share Difficulty':
+	case 'DEVS.Last Share Difficulty':
+	case 'POOL.Last Share Difficulty':
+		if ($value != '')
+			$ret = number_format((float)$value, 2);
+		break;
 	}
 
  if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
@@ -1222,7 +1244,12 @@ function rigbutton($rig, $rigname, $when, $row)
 {
  list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
 
- return "<td align=middle$class>".riginput($rig, $rigname).'</td>';
+ if ($rig === '')
+	$ri = '&nbsp;';
+ else
+	$ri = riginput($rig, $rigname);
+
+ return "<td align=middle$class>$ri</td>";
 }
 #
 function showrigs($anss, $headname, $rigname)
@@ -1882,7 +1909,213 @@ function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total
  return $total;
 }
 #
-function processcustompage($pagename, $sections, $sum, $namemap)
+function docalc($func, $data)
+{
+ switch ($func)
+ {
+ case 'sum':
+	$tot = 0;
+	foreach ($data as $val)
+		$tot += $val;
+	return $tot;
+ case 'avg':
+	$tot = 0;
+	foreach ($data as $val)
+		$tot += $val;
+	return ($tot / count($data));
+ case 'min':
+	$ans = null;
+	foreach ($data as $val)
+		if ($ans === null)
+			$ans = $val;
+		else
+			if ($val < $ans)
+				$ans = $val;
+	return $ans;
+ case 'max':
+	$ans = null;
+	foreach ($data as $val)
+		if ($ans === null)
+			$ans = $val;
+		else
+			if ($val > $ans)
+				$ans = $val;
+	return $ans;
+ case 'lo':
+	$ans = null;
+	foreach ($data as $val)
+		if ($ans === null)
+			$ans = $val;
+		else
+			if (strcasecmp($val, $ans) < 0)
+				$ans = $val;
+	return $ans;
+ case 'hi':
+	$ans = null;
+	foreach ($data as $val)
+		if ($ans === null)
+			$ans = $val;
+		else
+			if (strcasecmp($val, $ans) > 0)
+				$ans = $val;
+	return $ans;
+ case 'any':
+ default:
+	return $data[0];
+ }
+}
+#
+function docompare($row, $test)
+{
+ // invalid $test data means true
+ if (count($test) < 2)
+	return true;
+
+ if (isset($row[$test[0]]))
+	$val = $row[$test[0]];
+ else
+	$val = null;
+
+ if ($test[1] == 'set')
+	return ($val !== null);
+
+ if ($val === null || count($test) < 3)
+	return true;
+
+ switch($test[1])
+ {
+ case '=':
+	return ($val == $test[2]);
+ case '<':
+	return ($val < $test[2]);
+ case '<=':
+	return ($val <= $test[2]);
+ case '>':
+	return ($val > $test[2]);
+ case '>=':
+	return ($val >= $test[2]);
+ case 'eq':
+	return (strcasecmp($val, $test[2]) == 0);
+ case 'lt':
+	return (strcasecmp($val, $test[2]) < 0);
+ case 'le':
+	return (strcasecmp($val, $test[2]) <= 0);
+ case 'gt':
+	return (strcasecmp($val, $test[2]) > 0);
+ case 'ge':
+	return (strcasecmp($val, $test[2]) >= 0);
+ default:
+	return true;
+ }
+}
+#
+function processcompare($which, $ext, $section, $res)
+{
+ if (isset($ext[$section][$which]))
+ {
+	$proc = $ext[$section][$which];
+	if ($proc !== null)
+	{
+		$res2 = array();
+		foreach ($res as $rig => $result)
+			foreach ($result as $sec => $row)
+			{
+				$secname = preg_replace('/\d/', '', $sec);
+				if (!secmatch($section, $secname))
+					$res2[$rig][$sec] = $row;
+				else
+				{
+					$keep = true;
+					foreach ($proc as $test)
+						if (!docompare($row, $test))
+						{
+							$keep = false;
+							break;
+						}
+					if ($keep)
+						$res2[$rig][$sec] = $row;
+				}
+			}
+
+		$res = $res2;
+	}
+ }
+ return $res;
+}
+#
+function processext($ext, $section, $res)
+{
+ $res = processcompare('where', $ext, $section, $res);
+
+ if (isset($ext[$section]['group']))
+ {
+	$grp = $ext[$section]['group'];
+	$calc = $ext[$section]['calc'];
+	if ($grp !== null)
+	{
+		$interim = array();
+		$res2 = array();
+		$cou = 0;
+		foreach ($res as $rig => $result)
+			foreach ($result as $sec => $row)
+			{
+				$secname = preg_replace('/\d/', '', $sec);
+				if (!secmatch($section, $secname))
+				{
+					// STATUS may be problematic ...
+					if (!isset($res2[$sec]))
+						$res2[$sec] = $row;
+				}
+				else
+				{
+					$grpkey = '';
+					$newrow = array();
+					foreach ($grp as $field)
+					{
+						if (isset($row[$field]))
+						{
+							$grpkey .= $row[$field].'.';
+							$newrow[$field] = $row[$field];
+						}
+						else
+							$grpkey .= '.';
+					}
+
+					if (!isset($interim[$grpkey]))
+					{
+						$interim[$grpkey]['grp'] = $newrow;
+						$interim[$grpkey]['sec'] = $secname.$cou;
+						$cou++;
+					}
+
+					if ($calc !== null)
+						foreach ($calc as $field => $func)
+						{
+							if (!isset($interim[$grpkey]['cal'][$field]))
+								$interim[$grpkey]['cal'][$field] = array();
+							$interim[$grpkey]['cal'][$field][] = $row[$field];
+						}
+				}
+			}
+
+		// Build the rest of $res2 from $interim
+		foreach ($interim as $rowkey => $row)
+		{
+			$key = $row['sec'];
+			foreach ($row['grp'] as $field => $value)
+				$res2[$key][$field] = $value;
+			foreach ($row['cal'] as $field => $data)
+				$res2[$key][$field] = docalc($calc[$field], $data);
+		}
+
+		$res = array('' => $res2);
+	}
+ }
+
+ return processcompare('having', $ext, $section, $res);
+}
+#
+function processcustompage($pagename, $sections, $sum, $ext, $namemap)
 {
  global $sectionmap;
  global $miner, $port;
@@ -1973,7 +2206,7 @@ function processcustompage($pagename, $sections, $sum, $namemap)
 
 		if (isset($results[$sectionmap[$section]]))
 		{
-			$rigresults = $results[$sectionmap[$section]];
+			$rigresults = processext($ext, $section, $results[$sectionmap[$section]]);
 			$showfields = array();
 			$showhead = array();
 			foreach ($fields as $field)
@@ -2013,7 +2246,11 @@ function processcustompage($pagename, $sections, $sum, $namemap)
 					otherrow('<td>&nbsp;</td>');
 
 				newtable();
-				showhead('', array('Rig'=>1)+$showhead, true);
+				if (count($rigresults) == 1 && isset($rigresults['']))
+					$ri = array('' => 1) + $showhead;
+				else
+					$ri = array('Rig' => 1) + $showhead;
+				showhead('', $ri, true);
 
 				$total = array();
 				$add = array('total' => array());
@@ -2059,7 +2296,8 @@ function showcustompage($pagename)
 	return;
  }
 
- if (count($customsummarypages[$pagename]) != 2)
+ $c = count($customsummarypages[$pagename]);
+ if ($c < 2 || $c > 3)
  {
 	$rw = "<td colspan=100>Invalid custom summary page '$pagename' (";
 	$rw .= count($customsummarypages[$pagename]).')</td>';
@@ -2087,6 +2325,10 @@ function showcustompage($pagename)
 		}
  }
 
+ $ext = null;
+ if (isset($customsummarypages[$pagename][2]))
+	$ext = $customsummarypages[$pagename][2];
+
  $sum = $customsummarypages[$pagename][1];
  if ($sum === null)
 	$sum = array();
@@ -2106,7 +2348,7 @@ function showcustompage($pagename)
 	return;
  }
 
- processcustompage($pagename, $page, $sum, $namemap);
+ processcustompage($pagename, $page, $sum, $ext, $namemap);
 
  if ($placebuttons == 'bot' || $placebuttons == 'both')
 	pagebuttons(null, $pagename);