From 3fcb7779c853e374a06591ab19c50dacd9195b56 Mon Sep 17 00:00:00 2001 From: kanoi Date: Sat, 4 Apr 2015 12:56:44 +1100 Subject: [PATCH] ckdb/php - add mult-worker select to usperf and ? tips --- pool/db.php | 8 +++-- pool/page.php | 76 ++++++++++++++++++++++++++++++++------------ pool/page_shifts.php | 2 +- pool/page_usperf.php | 68 ++++++++++++++++++++++++++++++++++----- src/ckdb.h | 2 +- src/ckdb_cmd.c | 4 +-- 6 files changed, 126 insertions(+), 34 deletions(-) diff --git a/pool/db.php b/pool/db.php index 908c020b..33865c2c 100644 --- a/pool/db.php +++ b/pool/db.php @@ -309,11 +309,13 @@ function getMPayouts($user) return repDecode($rep); } # -function getShifts($user) +function getShifts($user, $workers = null) { if ($user == false) showIndex(); $flds = array('username' => $user); + if ($workers !== null) + $flds['select'] = $workers; $msg = msgEncode('shifts', 'shift', $flds, $user); $rep = sendsockreply('getShifts', $msg); if (!$rep) @@ -321,11 +323,13 @@ function getShifts($user) return repDecode($rep); } # -function getShiftData($user) +function getShiftData($user, $workers = null) { if ($user == false) showIndex(); $flds = array('username' => $user); + if ($workers !== null) + $flds['select'] = $workers; $msg = msgEncode('shifts', 'shift', $flds, $user); $rep = sendsockreply('getShifts', $msg); if (!$rep) diff --git a/pool/page.php b/pool/page.php index 93332a94..e05b1b3b 100644 --- a/pool/page.php +++ b/pool/page.php @@ -3,10 +3,12 @@ global $site_title; global $page_title; global $page_scripts; +global $page_css; # $site_title = 'CKPool'; $page_title = $site_title; $page_scripts = ''; +$page_css = ''; # global $dont_trm; $dont_trm = false; @@ -40,13 +42,20 @@ function addScript($script) } } # +function addCSS($css) +{ + global $page_css; + + $page_css .= $css; +} +# function addGBase() { $g = "function hasCan(){var c0=document.getElementById('can0');c=document.getElementById('can');return !!(c0&&c&&c.getContext&&c.getContext('2d'));} function sep(d){ans={};var ar=d.split('\\t');var l=ar.length;for(var i=0;i0){ans=c[0].substr(e+1)}}}return ans} -function scnv(n,v){var d = new Date();d.setTime(d.getTime()+(864*Math.pow(10,8)));document.cookie=n+'='+v+'; expires='+d.toUTCString()+'; path=/'} +function scnv(n,v){var d=new Date();d.setTime(d.getTime()+(864*Math.pow(10,8)));document.cookie=n+'='+v+'; expires='+d.toUTCString()+'; path=/'} function ccb(c,n){var e=document.getElementById(n);c[n]=(e&&e.checked)} function gch(z,zm){if(z<0.5){return 0.5}if(z>(zm-0.5)){return(zm-0.5)}return z} function gchx(c,x){return gch(x*c['xm']+c['xo'],c['ctx'].canvas.width)} @@ -69,7 +78,7 @@ function gfl(c){c['ctx'].fill()} function gst(c){c['ctx'].stroke()} function gfi(c){gle(c);gst(c)} function gbd(c){gbe(c,0,0);gln(c,1,0);gln(c,1,1);gln(c,0,1);gle(c);gfl(c);gst(c)} -function ggr(c,xs,ys,yt,xn,x0,x1,y0,y1,ar,nx,vx,vy,av){ +function ggr(c,xs,ys,yt,xn,x0,x1,y0,y1,ar,nx,vx,vy,av,w,cols){ gtso(c,xs,ys); gss(c,'black');glw(c,1.5); gbe(c,0,1);gln(c,0,0);gln(c,1,0);gst(c); @@ -78,7 +87,6 @@ var hi=c['ctx'].measureText('M').width, wi=c['ctx'].measureText('1').width; for(var i=0;i<11;i++){var y=i/10.0;gbe(c,-0.01,y);gln(c,1,y);gst(c);var t=''+(((y1-y0)*i/10+y0).toFixed(2));gfz(c,0,y,-wi,0,t,'black','end')} gfz(c,gx0(c),0.55,wi,0,yt,'#0080ff','left'); var m=Math.round(0.5+xn/20.0); -var f=1; for(var i=0;i=x0;i-=hrs){var n=dfmt(c,i);var xo=(i-x0)/(x1-x0);if(xo<=1&&c['tkey']&&((l%hlv)==0)){gbe(c,xo,0);gln(c,xo,-0.02);gst(c);gfz(c,xo,0,0,-hi*tpos,n,'brown','center')}if(xo<=1&&c['tlines']){gbe(c,xo,0);gln(c,xo,1);gst(c)}l++}} glw(c,1); -gss(c,'#0000c0'); -if(c['smooth']){var xa=0,ya=0,xb=0,yb=0; -for(var i=0;i0){gss(c,'red');var y=(av-y0)/(y1-y0); gbe(c,0,y);gln(c,1,y);gst(c); -var t=''+av.toFixed(2)+'av';gfz(c,1,y,1,0,t,'red','left') +var t=''+av.toFixed(2)+'av';gfz(c,1,y,1,0,t,'red','left')} if(c['tkey']){var col,hrl=c['hrs'].length;for(var i=0;i'.$pg; for ($i = 0; $i < $count; $i++) diff --git a/pool/page_usperf.php b/pool/page_usperf.php index 5edd947c..325d6305 100644 --- a/pool/page_usperf.php +++ b/pool/page_usperf.php @@ -1,25 +1,52 @@ ths){ymin=ths}if(ths>ymax)ymax=ths;d['nx:'+i]=sn(i,d['shift:'+i]);if(xmin==-1||xmin>s){xmin=s}if(xmaxs){xmin=s}if(xmaxths){ymin=ths}if(ths>ymax)ymax=ths;document.getElementById('worker'+j).value=d[pre+'worker']} +} var tav=(tda/(xmax-xmin))*Math.pow(2,32)/Math.pow(10,12); var p5=(ymax-ymin)*0.05;ymax+=p5;ymin-=p5;if(ymin<0){ymin=0} if(c['zerob']){ymin=0} ghg(c,xmax-xmin); -ggr(c,0.9,0.9,'TH/s',rows,xmin,xmax,ymin,ymax,d,'nx:','vx:','ths:',tav)} +ggr(c,0.9,0.9,'TH/s',rows,xmin,xmax,ymin,ymax,d,'nx:','vx:','ths:',tav,w,cols)} c={}; function dodrw(data,cbx){if(hasCan()){gdrw(c,sep(data),cbx)}} -function gact(t){if(t.checked){scnv(t.id,1)}else{scnv(t.id,0)}godrw(0)}"; +function gact(t){if(t.checked){scnv(t.id,1)}else{scnv(t.id,0)}godrw(0)} +function wch(){var w='';for(var i=1;i<=$nc;i++){var e=document.getElementById('worker'+i);if(e&&e.value&&e.value.trim()){if(i>1){w+=','}w+=e.value.trim()}}if(w){scnv('workers',w)}}"; return $g; } # function dousperf($data, $user) { - $ans = getShiftData($user); + global $fld_sep, $val_sep; + + // This also defines how many worker fields there are + $cols = array('#0000c0', '#00dd00', '#e06020', '#b020e0'); + $nc = count($cols); + + $workers = 'all'; + if (isset($_COOKIE['workers'])) + { + $w = substr(trim($_COOKIE['workers']), 0, 1024); + if ($w !== false) + { + $wa = explode(',', $w, $nc+1); + if (count($wa) > $nc) + { + $w = ''; + for ($i = 0; $i < $nc; $i++) + $w .= (($i == 0) ? '' : ',').$wa[$i]; + } + $workers = $w; + } + } + + $ans = getShiftData($user, $workers); $iCrap = strpos($_SERVER['HTTP_USER_AGENT'],'iP'); if ($iCrap) @@ -28,9 +55,11 @@ function dousperf($data, $user) $vlines = true; $pg = '

User Shift Reward Performance


'; + if ($ans['STATUS'] == 'ok' and $ans['DATA'] != '') { addGBase(); + addTips(); $cbx = array('skey' => 'shift key', 'slines' => 'shift lines', 'tkey' => 'time key', 'tlines' => 'time lines', 'over' => 'key overlap', 'smooth' => 'smooth', @@ -39,7 +68,29 @@ function dousperf($data, $user) if ($vlines === true) $xon['slines'] = 1; - $pg .= '
'; + $pg .= '
'; + + $tt = "
  • all = all workers
  • noname = worker with no workername
  • "; + $tt .= "
  • or full workername without the username i.e. .worker or _worker
"; + $pg .= "?"; + $pg .= "$tt"; + + $i = 0; + $datacols = ''; + $onch = " onchange='wch()'"; + foreach ($cols as $col) + { + $i++; + $pg .= " Worker$i:"; + $pg .= " "; + + if ($i > 1) + $datacols .= ','; + $datacols .= $col; + } + + $oncl = "wch();location.href=\"".makeURL('usperf')."\""; + $pg .= "
"; foreach ($cbx as $nam => $txt) { $pg .= ' '; @@ -52,8 +103,9 @@ function dousperf($data, $user) $pg .= 'A graph will show here if your browser supports html5/canvas'; $pg .= "
\n"; $data = str_replace(array("\\","'"), array("\\\\","\\'"), $ans['DATA']); + $data .= $fld_sep . 'cols' . $val_sep . $datacols; $pg .= "