Esempio n. 1
0
/**
*	purpose:	calculate new SSI based on GAME results between vdate1 -> vdate2
* 				stores new SSI in stat-table
* 	params:		date,date
*	returns:	output as ECHO statements
*/
function generateStaticSSIStatisticEntries($vdate1, $vdate2)
{
    # //
    # // v01 BH 12.7.2003 initial version - works
    # // run game query -> store pid,points in array (PID=index)
    # // run loop on every player - add points from array ... or from last SSI
    # // v02 BH for every player get the gamecount for this period and set the STATUS flag
    # // v03 added Rule 1 and rule 2
    # // v04 re-worked for ls_statsadmin
    global $dbi, $user, $redpic, $greenpic, $minSSIVal, $goback;
    if (!isset($vdate1)) {
        die("Error: no START date" . $goback);
    }
    if (!isset($vdate2)) {
        die("Error: no END date" . $goback);
    }
    $srecords = sql_query("select pid,pfname,plname,rid,rgid,rpid,rresult,rdate,rdesc,statval" . " from tplayer,tresult,tblstat" . " where pid=rpid and pid=statpid and statcode=2 and statdate = '{$vdate1}' and rdate>'{$vdate1}' and rdate<'{$vdate2}'" . " order by rdate,rgid asc,rresult desc", $dbi);
    $i = 0;
    $lastgame = 0;
    $arr = array();
    while (list($pid, $pfname, $plname, $rid, $rgid, $rpid, $rresult, $rdate, $rdesc, $sippoints) = sql_fetch_row($srecords, $dbi)) {
        #
        # es gibt immer 2 entries pro Spiel -> darstellung in einer Reihe
        # SORTORDER = WINNER A / Loser B -> Sieger immer in Record 1 Loser in Record 2
        # momentan entpricht der valAwin immer dem -valBWin (also reziprok wert ...)
        # der dynamic faktor liegt fr alle spieler bei 50 =(200/4)=3:1
        #
        $i = $i + 1;
        if ($rgid != $lastgame) {
            $sipA = $sippoints;
            $pidA = $pid;
        } else {
            $sipB = $sippoints;
            $pidB = $pid;
            # // calculate PLAYER A WINNER //////////
            $valAwin = ReturnSSIChangePlayer($sipA, $sipB, 1);
            # // calculate PLAYER B Loser /////////
            $valBLost = ReturnSSIChangePlayer($sipB, $sipA, 0);
            #debug("A PID=$pidA Value Arr=$arr[$pidA] adding $valAwin");
            #debug("B PID=$pidB Value Arr=$arr[$pidB] adding ".(-$valBLost));
            $arr[$pidA] = $arr[$pidA] + $valAwin;
            $arr[$pidB] = $arr[$pidB] + -$valBLost;
            $gamecount[$pidA] = $gamecount[$pidA] + 1;
            $gamecount[$pidB] = $gamecount[$pidB] + 1;
        }
        $lastgame = $rgid;
    }
    echo "<h3>Abrechnung der Spielresultate Periode {$vdate1} / {$vdate2}</h3><p>Zwecks &Uuml;berpr&uuml;fung oder einer manuellen Buchhaltung k&ouml;nnen die angezeigten Daten mit copy-paste &uuml;bernommen und z.B. anderweitig gesichert werden.<br>SSI Base Value={$minSSIVal}</p>";
    #foreach ($arr as $key => $valwin){
    #	echo "Valarray $key = $valwin<br>";
    #}
    # // now get the playerslist cycle with an INSERT into tblstat on $vdate2
    $pqry = sql_query("select pid,pfname,plname,statval from tplayer,tblstat where pid=statpid and statdate='{$vdate1}' and statcode=2 order by pid", $dbi);
    while (list($pid, $pfname, $plname, $sippoints) = sql_fetch_row($pqry, $dbi)) {
        if ($arr[$pid] != 0) {
            # // Rule 1 any player can not gain or loose more than 200 points
            if ($arr[$pid] > 200) {
                $arr[$pid] = 200;
            }
            if ($arr[$pid] < -200) {
                $arr[$pid] = -200;
            }
            # // get new value from $arr array and add to existing value from last period
            # // Rule 2 SSI can not get lower than 600 !!! //
            $newval = $sippoints + $arr[$pid];
            if ($newval < $minSSIVal) {
                $newval = $minSSIVal;
            }
            echo "{$greenpic}<b> NEW SSI for {$pfname} {$plname}: adding " . number_format($arr[$pid], 2, '.', '') . " pt to {$sippoints} for {$vdate1}/{$vdate2} = {$newval}</b></br>";
            #//echo "insert into tblstat values(0,'$vdate2',".($sippoints+$arr[$pid]).",$pid)<br>";
            $qry = "insert into tblstat(statid,statdate,statcode,statval,statpid) values(0,'{$vdate2}',2,{$newval},{$pid})";
            $res = sql_query($qry, $dbi);
            dsolog(2, $user, "<b>SSI UPDATE</b> {$pfname} {$plname} = {$newval}");
        } else {
            echo "{$redpic}<i>NO SSI update for {$pfname} {$plname} Points: " . number_format($arr[$pid], 2, '.', '') . "</i></br>";
            #//echo "insert into tblstat values(0,'$vdate2',".$sippoints.",$pid)<br>";
            $qry = "insert into tblstat(statid,statdate,statcode,statval,statpid) values(0,'{$vdate2}',2,{$sippoints},{$pid})";
            $res = sql_query($qry, $dbi);
            dsolog(1, $user, "<b>NO SSI UPDATE</b> {$pfname} {$plname} = {$sippoints}");
        }
        # // TOGGLE the SSI status field for this player case 0, -6, +6
        # // this is used to know how actual the current SSI value is
        switch ($gamecount[$pid]) {
            case 0:
                $res = sql_query("update tplayer set psipstatus=0 where pid={$pid}", $dbi);
                break;
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                $res = sql_query("update tplayer set psipstatus=1 where pid={$pid}", $dbi);
                break;
            default:
                $res = sql_query("update tplayer set psipstatus=2 where pid={$pid}", $dbi);
                break;
        }
        # // end switch status toggle
    }
}
Esempio n. 2
0
function showpersonal($vpid)
{
    # displays dialog + personal chances against other SSI players
    # displays only registered players with more than $mingames (4)
    global $dbi, $user, $sipgoback, $lastdate, $predpic, $pgreenpic, $porangepic, $minsip;
    $trecords = sql_query("select pid,pfname,plname,psipstatus,statval,sipcount from tplayer,tblstat" . " where pid=statpid and sipcount>{$minsip} and statdate = '{$lastdate}' and statcode=2 order by plname asc", $dbi);
    $optionstring = "";
    while (list($pid, $pfname, $plname, $psipstatus, $sippoints, $sipcount) = sql_fetch_row($trecords, $dbi)) {
        if ($vpid == $pid) {
            $strplayer = $plname . ' ' . $pfname . ' (' . number_format($sippoints, 2, '.', '') . ')';
            $sipplayer = $sippoints;
            $optionstring = $optionstring . '<option selected value=' . $pid . '>' . $plname . ' ' . $pfname . '</option>';
        } else {
            $optionstring = $optionstring . '<option value=' . $pid . '>' . $plname . ' ' . $pfname . '</option>';
        }
    }
    #OpenTable();
    echo '<h3>Pers&ouml;nliche SSI +/- Tabelle</h1>' . "<p>Gew&uuml;nschten Spieler aussuchen. F&uuml;r diesen Spieler werden die SSI +/- gegen alle anderen Spieler berechnet, die bereits einen g&uuml;ltige SSI Wert besitzen. Die SSI Zahl ist vom Stichtag {$lastdate}.</p>";
    echo "<form action=\"?func=personal\" method=\"post\"><table><tr>" . '<td><select name=vpid>' . $optionstring . '</select></td>' . '<td>' . _button('SSI +/- Werte berechnen') . '</td>' . '</tr></table></form>';
    #CloseTable();
    if (strlen($strplayer) > 0) {
        echo "<h3>SSI Tabelle f&uuml;r {$strplayer}</h3>";
    } else {
        die("<i>Einen Spieler aussuchen und auf Berechnen klicken.</i>");
    }
    # // execute this block only if a player has been selected ..
    mysql_data_seek($trecords, 0);
    #// move record pointer
    $aTH = array('Status', 'Gegner', 'Wert', 'Verlieren', 'Gewinnen', 'Gewinnwahrscheinlichkeit');
    OpenTable();
    echo ArrayToTableHead($aTH);
    while (list($pid, $pfname, $plname, $psipstatus, $sippoints, $sipcount) = sql_fetch_row($trecords, $dbi)) {
        echo '<tr><td>';
        switch ($psipstatus) {
            case "0":
                echo $predpic;
                break;
            case "1":
                echo $porangepic;
                break;
            case "2":
                echo $pgreenpic;
                break;
        }
        echo '</td><td>' . $pfname . ' ' . $plname . '</td><td>' . number_format($sippoints, 2, '.', '') . '</td>';
        # calculate Player Loses //////////
        $valLost = ReturnSSIChangePlayer($sipplayer, $sippoints, 0);
        echo '<td><font color="red">-' . number_format($valLost, 2, '.', '') . '</font></td>';
        # calculate PLAYER Winner /////////
        $valWin = ReturnSSIChangePlayer($sipplayer, $sippoints, 1);
        $expWin = ReturnWinExpectancy($sipplayer, $sippoints);
        echo '<td>+' . number_format($valWin, 2, '.', '') . '</td><td>' . number_format($expWin, 2, '.', '') . '%</td></tr>';
    }
    echo '</table>';
    CloseTable();
}