Browse Source

php - add a luck graph

master
kanoi 9 years ago
parent
commit
0c6984afdd
  1. 5
      pool/inc.php
  2. 201
      pool/page_luck.php
  3. 3
      pool/prime.php

5
pool/inc.php

@ -5,6 +5,7 @@ function GBaseJS()
$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;i<l;i++){var e=ar[i].indexOf('=');ans[ar[i].substr(0,e)]=ar[i].substr(e+1)}return ans}
function dfmt(c,e){var d=new Date(e*1000);var DD,HH,MM;if(c['utc']){DD=d.getUTCDate();HH=d.getUTCHours();MM=d.getUTCMinutes()}else{DD=d.getDate();HH=d.getHours();MM=d.getMinutes()}var ans=''+DD+'/';if(HH<10){ans += '0'}ans += ''+HH+':';if(MM<10){ans += '0'}ans += ''+MM;return ans}
function dfmtm(c,e){var d=new Date(e*1000);var M,DD,HH;var MMM=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];if(c['utc']){M=MMM[d.getUTCMonth()];DD=d.getUTCDate();HH=d.getUTCHours()}else{M=MMM[d.getMonth()];DD=d.getDate();HH=d.getHours()}var ans=''+M+'-';if(DD<10){ans += '0'}ans += ''+DD+'/';if(HH<10){ans += '0'}ans += ''+HH;return ans}
function ccb(c,n){var e=document.getElementById(n);c[n]=(e&&e.checked)}
function ccbd(c,n,d){var e=document.getElementById(n);if(e){c[n]=e.checked}else{c[n]=d}}
function gch(z,zm){if(z<0.5){return 0.5}if(z>(zm-0.5)){return(zm-0.5)}return z}
@ -28,13 +29,13 @@ 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,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);glw(c,0.2);var hi=c['ctx'].measureText('M').width, wi=c['ctx'].measureText('0').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);for(var i=0;i<xn;i++){var n=ar[nx+i];var x=ar[vx+i];var xo=(x-x0)/(x1-x0);if(c['skey'] && (i<(xn-1)) && (i%m) == 0){gbe(c,xo,0);gln(c,xo,-0.01);gst(c);gfz(c,xo,0,0,-hi*1.5,n,'#00a050','center')}if(c['slines']){gbe(c,xo,0);gln(c,xo,1);gst(c)}}var xhr=3600+x1-(x1%3600);gss(c,'brown');if(c['tkey'] || c['tlines']){var hlv=c['hln'][c['hl']];hrs=c['hrs'][c['hr']]*3600/hlv;var l=0;tpos=2.7;if(c['over']){tpos=1.5}for(var i=xhr;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);if(c['smooth']){for(var j=1;j<w.length;j++){if(c['lin'+j]){var f=1;gss(c,cols[j-1]);var xa=0,ya=0,xb=0,yb=0;for(var i=0;i<xn;i++){var x=ar[vx+i];var y=ar[w[j]+vy+i];var xo=(x-x0)/(x1-x0);var yo=(y-y0)/(y1-y0);if(f==1){gbe(c,xo,yo);f=0;xb=xo;yb=yo}else{gct(c,(xa+xb)/2,(ya+yb)/2,xb,yb,(xb+xo)/2,(yb+yo)/2)}xa=xb;ya=yb;xb=xo;yb=yo}gct(c,(xa+xb)/2,(ya+yb)/2,xo,yo,xo,yo);gst(c)}}}else{for(var j=1;j<w.length;j++){if(c['lin'+j]){var f=1;gss(c,cols[j-1]);for(var i=0;i<xn;i++){var x=ar[vx+i];var y=ar[w[j]+vy+i];var xo=(x-x0)/(x1-x0);var yo=(y-y0)/(y1-y0);if(f==1){gbe(c,xo,yo);f=0}else{gln(c,xo,yo)}}gst(c)}}}glw(c,1);for(var j=1;j<w.length;j++){if(av[j-1]>0 && c['lin'+j]){gss(c,'red');var y=(av[j-1]-y0)/(y1-y0);gbe(c,0,y);gln(c,1,y);gst(c);var t=''+av[j-1].toFixed(2)+'av';gfz(c,1,y,1,0,t,cols[j-1],'left')}}if(c['tkey']){var col,hrl=c['hrs'].length;for(var i=0;i<hrl;i++){if(c['hr']==i){col='red'}else{col='black'}gfz(c,1,0,c['xo']-c['pxe'],hi*(i+1)*2,''+c['hrs'][i],col,'end')}for(var i=0;i<c['hln'].length;i++){if(c['hl']==i){col='red'}else{col='black'}gfz(c,1,0,c['xo']-c['pxe'],hi*(i+2+hrl)*2,''+c['hrs'][i],col,'end')}}}
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);glw(c,0.2);var hi=c['ctx'].measureText('M').width, wi=c['ctx'].measureText('0').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);for(var i=0;i<xn;i++){var n=ar[nx+i];var x=ar[vx+i];var xo=(x-x0)/(x1-x0);if(c['skey'] && (i<(xn-1)) && (i%m) == 0){gbe(c,xo,0);gln(c,xo,-0.01);gst(c);gfz(c,xo,0,0,-hi*1.5,n,'#00a050','center')}if(c['slines']){gbe(c,xo,0);gln(c,xo,1);gst(c)}}var xhr=3600+x1-(x1%3600);gss(c,'brown');if(c['tkey'] || c['tlines']){var hlv=c['hln'][c['hl']];hrs=c['hrs'][c['hr']]*3600/hlv;var n,l=0;tpos=2.7;if(c['over']){tpos=1.5}for(var i=xhr;i>=x0;i-=hrs){var xo=(i-x0)/(x1-x0);if(c['hrs'][c['hr']]<=48){n=dfmt(c,i)}else{n=dfmtm(c,i)}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);if(c['smooth']){for(var j=1;j<w.length;j++){if(c['lin'+j]){var f=1;gss(c,cols[j-1]);var xa=0,ya=0,xb=0,yb=0;for(var i=0;i<xn;i++){var x=ar[vx+i];var y=ar[w[j]+vy+i];var xo=(x-x0)/(x1-x0);var yo=(y-y0)/(y1-y0);if(f==1){gbe(c,xo,yo);f=0;xb=xo;yb=yo}else{gct(c,(xa+xb)/2,(ya+yb)/2,xb,yb,(xb+xo)/2,(yb+yo)/2)}xa=xb;ya=yb;xb=xo;yb=yo}gct(c,(xa+xb)/2,(ya+yb)/2,xo,yo,xo,yo);gst(c)}}}else{for(var j=1;j<w.length;j++){if(c['lin'+j]){var f=1;gss(c,cols[j-1]);for(var i=0;i<xn;i++){var x=ar[vx+i];var y=ar[w[j]+vy+i];var xo=(x-x0)/(x1-x0);var yo=(y-y0)/(y1-y0);if(f==1){gbe(c,xo,yo);f=0}else{gln(c,xo,yo)}}gst(c)}}}glw(c,1);for(var j=1;j<w.length;j++){if(av[j-1]>0 && c['lin'+j]){gss(c,'red');var y=(av[j-1]-y0)/(y1-y0);gbe(c,0,y);gln(c,1,y);gst(c);var t=''+av[j-1].toFixed(2)+'av';gfz(c,1,y,1,0,t,cols[j-1],'left')}}if(c['tkey']){var i,dsp;i=c['hrs'][c['hr']];if(i < 24){dsp=''+i}else{dsp=''+(i/24)+'d'}gfz(c,1,0,c['xo']-c['pxe'],hi,dsp,'red','end');i=c['hln'][c['hl']];gfz(c,1,0,c['xo']-c['pxe'],hi*3,''+i,'red','end')}}
function sn(i,shi){if(shi.indexOf(' Shift ')<0){return ''+(i%10)}else{return shi.replace(/.* ([a-z])[a-z]*$/,'$1')}}
function gc2(c){var div=document.getElementById('can0');while (div.firstChild){div.removeChild(div.firstChild)}c['can']=document.createElement('canvas');c['can'].id='can';c['xo']=0.0;c['yo']=0.0;c['ctx']=c['can'].getContext('2d');c['ctx'].canvas.width=c['xm']+1;c['ctx'].canvas.height=c['ym']+1;div.appendChild(c['can']);c['pxe']=Math.max(Math.round(c['xm']/250),1)}
function gc(c){c['wx']=window.innerWidth;c['wy']=window.innerHeight;c['xm']=Math.max(Math.round(c['wx']*0.9+0.5),400);c['ym']=Math.max(Math.round(c['wy']*0.8+0.5),400);if(c['ym']>c['xm']){c['ym']=c['xm']}gc2(c)}
function gcxy(c,xm,ym){c['wx']=window.innerWidth;c['wy']=window.innerHeight;c['xm']=Math.min(Math.round(c['wx']*0.95),xm);c['ym']=Math.min(Math.round(c['wy']*0.95),ym);gc2(c)}
function opts(t,i){var e=document.getElementById(i);if(t.checked){e.style.visibility='visible'}else{e.style.visibility='hidden'}}
function ghrs(c){c['hrs']=[1,2,3,4,6,8,12,24,48];c['hln']=[1,2,3,4,6]}
function ghrs(c){c['hrs']=[1,2,3,4,6,8,12,24,48,168,336,672,1344,2688];c['hln']=[1,2,3,4,6]}
function ghg(c,dx){var tl=dx/(gchx(c,1)/50)/3600;for(var j=c['hrs'].length-1;j>=0;j--){if(tl<c['hrs'][j]){c['hr']=j}else{break}}if(tl<0.5){var tb=1/tl;for(var k=0;k<c['hln'].length;k++){if(c['hln'][k]<tb){c['hl']=k}else{break}}}else{c['hl']=1}}
function gopt(c,cbx){for(var i=0;i<cbx.length;i++){ccb(c,cbx[i])}}
function gsh(c,w){for(var i=1;i<w.length;i++){ccbd(c,'lin'+i,true)}}

201
pool/page_luck.php

@ -0,0 +1,201 @@
<?php
#
function lckg($nc, $av)
{
$g = "function gdrw(c,d,cbx){gc(c);ghrs(c);gopt(c,cbx);
gfs(c,'white');gss(c,'#0000c0');glw(c,2);gbd(c);
var rows=d['rows'],ymin=0,ymax=0,xmin=-1,xmax=0,tlk=[];
var w=d['arp'].split(',');var cols=d['cols'].split(',');
gsh(c,w);
for(var j=1;j<w.length;j++){tlk[j-1]=$av}
for(var i=0;i<rows;i++){var s=parseFloat(d['firstcreatedate:'+i]);d['vx:'+i]=s;if(xmin==-1||xmin>s){xmin=s}if(xmax<s){xmax=s}
for(var j=1;j<w.length;j++){var pre=w[j];var lk=0,nam=pre+'luck:'+i;if(d[nam]){lk=parseFloat(d[nam])}if(lk>ymax)ymax=lk}
}
if(ymax>500){ymax=500}
ghg(c,xmax-xmin);
ggr(c,0.90,0.90,'Luck%',rows,xmin,xmax,ymin,ymax,d,'seq:','vx:','luck:',tlk,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)}";
return $g;
}
#
function doluck($data, $user)
{
global $fld_sep, $val_sep;
if ($user === null)
$ans = getBlocks('Anon');
else
$ans = getBlocks($user);
$iCrap = strpos($_SERVER['HTTP_USER_AGENT'],'iP');
if ($iCrap)
$vlines = false;
else
$vlines = true;
$pg = '<h1>Pool Avg Block Luck History</h1><br>';
if ($ans['STATUS'] == 'ok' and isset($ans['rows']) and $ans['rows'] > 0)
{
$count = $ans['s_rows'] - 1;
$av = number_format(100 * $ans['s_luck:'.$count], 3);
for ($i = 0; $i < $count; $i++)
// This also defines how many lines there are
$cols = array('#0000c0', '#00dd00', '#e06020', '#b020e0');
$nams = array(1, 5, 15, 25);
$nc = count($cols);
addGBase();
$cbx = array('skey' => 'block key', 'slines' => 'block lines',
'tkey' => 'time key', 'tlines' => 'time lines',
'over' => 'key overlap', 'smooth' => 'smooth',
'utc' => 'utc');
$xon = array('skey' => 1, 'utc' => 1);
if ($vlines === true)
$xon['slines'] = 1;
$pg .= '<div>';
foreach ($cbx as $nam => $txt)
{
$pg .= ' <span class=nb>';
$pg .= "<input type=checkbox id=$nam onclick='gact(this)'>";
$pg .= "$txt&nbsp;</span>";
}
$pg .= '</div><div>';
$i = 1;
$datacols = '';
foreach ($cols as $col)
{
if ($i != 1)
$pg .= '&nbsp;&nbsp;';
if ($i == 2 || $i == 4)
$chk = ' checked';
else
$chk = '';
$pg .= "<span class=nb><font color=$col>";
$pg .= "<input type=checkbox id=lin$i$chk onclick='godrw(0)'>: ";
$pg .= $nams[$i-1].' Block Luck Avg</font></span>';
if ($i > 1)
$datacols .= ',';
$datacols .= $col;
$i++;
}
$pg .= '</div>';
$pg .= '<div id=can0><canvas id=can width=1 height=1>';
$pg .= 'A graph will show here if your browser supports html5/canvas';
$pg .= "</canvas></div>\n";
$count = $ans['rows'];
# add the orphan/reject ratios to the subsequent blocks
$dr = 0;
for ($i = $count-1; $i >= 0; $i--)
{
$conf = $ans["confirmed:$i"];
if ($conf == '1' or $conf == 'F')
{
$ans["diffratio:$i"] += $dr;
$dr = 0;
}
else
$dr += $ans["diffratio:$i"];
}
# $ans blocks are 0->rows-1 highest->lowest
# build an array of valid block offsets (reversed lowest->highest)
$off = array();
for ($i = $count-1; $i >= 0; $i--)
{
$conf = $ans["confirmed:$i"];
if ($conf == '1' or $conf == 'F')
$off[] = $i;
}
$data = '';
$count = count($off);
$avg = 0;
# each valid block offset number (lowest->highest)
for ($j = 0; $j < $count; $j++)
{
$i = $off[$j];
$data .= $fld_sep . "height:$j$val_sep";
$data .= $ans["height:$i"];
$data .= $fld_sep . "seq:$j$val_sep";
$data .= $ans["seq:$i"];
$data .= $fld_sep . "firstcreatedate:$j$val_sep";
$data .= $ans["firstcreatedate:$i"];
$data .= $fld_sep . "0_luck:$j$val_sep";
$data .= number_format(100 * $ans['luck:'.$i], 3);
$avg += $ans["diffratio:$i"];
$l5c = $l15c = $l25c = 1;
$l5 = $l15 = $l25 = $ans['diffratio:'.$i];
# +/- offset from j (12 is the max for 25)
for ($k = 1; $k <= 12; $k++)
{
# we want the (n-1)/2 on each side of the offset number
foreach (array(-1, 1) as $s)
{
$o = $j + ($s * $k);
if (0 <= $o && $o < $count)
{
$dr = $ans['diffratio:'.$off[$o]];
if ($k <= 2) # (5-1)/2
{
$l5 += $dr;
$l5c++;
}
if ($k < 7) # (15-1)/2
{
$l15 += $dr;
$l15c++;
}
$l25 += $dr;
$l25c++;
}
}
}
# luck is 1/(mean diffratio)
$data .= $fld_sep . "1_luck:$j$val_sep";
$data .= number_format(100 * $l5c / $l5, 3);
$data .= $fld_sep . "2_luck:$j$val_sep";
$data .= number_format(100 * $l15c / $l15, 3);
$data .= $fld_sep . "3_luck:$j$val_sep";
$data .= number_format(100 * $l25c / $l25, 3);
}
$data .= $fld_sep . 'rows' . $val_sep . $count;
$data .= $fld_sep . 'arp' . $val_sep . ',0_,1_,2_,3_';
$data .= $fld_sep . 'cols' . $val_sep . $datacols;
$pg .= "<script type='text/javascript'>\n";
$pg .= lckg($nc, 100*$count/$avg);
$pg .= "\nfunction godrw(f){var cbx=[";
$comma = '';
foreach ($cbx as $nam => $txt)
{
$pg .= "$comma'$nam'";
$comma = ',';
}
$pg .= '];if(f){var xon={};';
foreach ($xon as $nam => $val)
$pg .= "xon['$nam']=1;";
$pg .= "doinit(cbx,xon)}dodrw('$data',cbx)};godrw(1);</script>\n";
}
return $pg;
}
#
function show_luck($info, $page, $menu, $name, $user)
{
gopage($info, NULL, 'doluck', $page, $menu, $name, $user);
}
#
?>

3
pool/prime.php

@ -86,7 +86,8 @@ function check()
'Stats' => 'stats',
'Blocks' => 'blocks',
'Graph' => 'psperf',
'Acclaim' => 'userinfo'
'Acclaim' => 'userinfo',
'Luck' => 'luck'
),
'Admin' => NULL,
'gap' => array( # options not shown

Loading…
Cancel
Save