From e355d93bedf6e32ea86ef6aaa330f4e05e5e66b1 Mon Sep 17 00:00:00 2001 From: kanoi Date: Tue, 17 Mar 2015 01:53:35 +1100 Subject: [PATCH] php - add a simple shift perfomance graph --- html/can.js | 54 +++++++++++++++++++++++++++++++++++++++++++ pool/db.php | 55 ++++++++++++++++++++++++++++++++++++++++++-- pool/page_blocks.php | 12 ++++++---- pool/page_usperf.php | 26 +++++++++++++++++++++ pool/prime.php | 5 ++-- 5 files changed, 144 insertions(+), 8 deletions(-) create mode 100644 html/can.js create mode 100644 pool/page_usperf.php diff --git a/html/can.js b/html/can.js new file mode 100644 index 00000000..06882e01 --- /dev/null +++ b/html/can.js @@ -0,0 +1,54 @@ +function hasCan(){var c=document.getElementById('can');return !!(c.getContext&&c.getContext('2d'));} +function sep(d){ans={};var ar=d.split("\t");var l=ar.length;for(var i=0;i(zm-1)){return(zm-1)}return z} +function gchx(c,x){return gch(x*c['xm']+c['xo'],c['ctx'].canvas.width)} +function gchy(c,y){return gch((1-y)*c['ym']+c['yo'],c['ctx'].canvas.height)} +function gx0(c){return -c['xo']/c['xm']}; +function gy0(c){return -c['yo']/c['ym']}; +function gto(c,xo,yo){c['xo']+=xo;c['yo']+=yo} +function gts(c,xs,ys){c['xm']*=xs;c['ym']*=ys} +function gtso(c,xs,ys){gto(c,c['xm']*(1.0-xs)/2.0,c['ym']*(1.0-ys)/2.0);gts(c,xs,ys)} +function gfs(c,bg){c['ctx'].fillStyle=bg} +function gss(c,fg){c['ctx'].strokeStyle=fg} +function glw(c,pct){c['ctx'].lineWidth=pct*c['ym']/100.0} +function glwr(c,rat){c['ctx'].lineWidth*=rat} +function gfz(c,x,y,ox,oy,t,co,a){gfs(c,co);c['ctx'].textAlign=a;c['ctx'].fillText(t,gchx(c,x)+ox,gchy(c,y)-oy)} +function gbe(c,x,y){c['ctx'].beginPath();c['ctx'].moveTo(gchx(c,x),gchy(c,y))} +function gln(c,x,y){c['ctx'].lineTo(gchx(c,x),gchy(c,y))} +function glm(c,x,y){c['ctx'].moveTo(gchx(c,x),gchy(c,y))} +function gle(c){c['ctx'].closePath()} +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){ +gtso(c,xs,ys); +gss(c,'black');glw(c,0.25); +gbe(c,0,1);gln(c,0,0);gln(c,1,0);gst(c); +glwr(c,0.1); +var hi=c['ctx'].measureText('M').width; +var 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;ic['xm']){c['ym']=c['xm']}c['xo']=0.0;c['yo']=0.0;c['ctx'].canvas.width=c['xm'];c['ctx'].canvas.height=c['ym']} +function gdrw(d){var c={};gc(c); +gfs(c,'white');gss(c,'black');glw(c,1);gbd(c); +var rows=d['rows'];var ymin=-1;var ymax=0;var xmin=-1;var xmax=0; +var tda=0; +for(var i=0;iths){ymin=ths}if(ths>ymax)ymax=ths;d['nx:'+i]=sn(i,d['shift:'+i]);if(xmin==-1||xmin>s){xmin=s}if(xmax $user); + $msg = msgEncode('shifts', 'shift', $flds, $user); + $rep = sendsockreply('getShifts', $msg); + if (!$rep) + dbdown(); + return repData($rep); +} +# function getBlocks($user) { if ($user == false) diff --git a/pool/page_blocks.php b/pool/page_blocks.php index ba07472f..c294ba4c 100644 --- a/pool/page_blocks.php +++ b/pool/page_blocks.php @@ -182,11 +182,15 @@ function doblocks($data, $user) if ($stat == 'Orphan') $stara = '*'; - $statsconf = $ans['statsconf:'.$i]; - if ($statsconf == 'Y') - $approx = ''; + if (isset($ans['statsconf:'.$i])) + { + if ($ans['statsconf:'.$i] == 'Y') + $approx = ''; + else + $approx = '~'; + } else - $approx = '~'; + $approx = ''; $diffacc = $ans['diffacc:'.$i]; $acc = number_format($diffacc, 0); diff --git a/pool/page_usperf.php b/pool/page_usperf.php new file mode 100644 index 00000000..12e31e39 --- /dev/null +++ b/pool/page_usperf.php @@ -0,0 +1,26 @@ +User Shift Performance
'; + if ($ans['STATUS'] == 'ok' and $ans['DATA'] != '') + { + $pg .= ""; + $pg .= "A graph will show here if your browser supports html5/canvas"; + $pg .= "\n"; + $data = str_replace(array("\\","'"), array("\\\\","\\'"), $ans['DATA']); + $pg .= "\n"; + $pg .= "\n"; + } + + return $pg; +} +# +function show_usperf($info, $page, $menu, $name, $user) +{ + gopage($info, NULL, 'dousperf', $page, $menu, $name, $user); +} +# +?> diff --git a/pool/prime.php b/pool/prime.php index 6ee31cfb..9c0d2706 100644 --- a/pool/prime.php +++ b/pool/prime.php @@ -76,8 +76,9 @@ function check() 'User Settings' => 'userset' ), 'Workers' => array( - 'Shifts ' => 'shifts', - 'Workers ' => 'workers', + 'Shifts' => 'shifts', + 'Shift Graph' => 'usperf', + 'Workers' => 'workers', 'Management' => 'workmgt', ), 'Pool' => array(