/** # this calculates the ranking points of all players who belong # to a specific LEAGUE-Group $fedagroup FEDA (MIXED or DAMEN) # a) retrieve all legs belonging to this listnumber form all events for the specified period # b) check on legacy table and include data # v2.6 incl current league in report * v3 changed to fit into ls_statsadmin - produce minimal output ... * v4 changed and removed the team - event strings ... * includes all events of this statgroup not only active events * v5 extended by the API_RS model * v5 reM: works only on 501 legs !! **/ function generateStaticFEDAStatisticEntries($feda_stat_group, $indexdate, $writeToDB = 'no') { global $user, $dbi; $fromdate = fnc_date_calc($indexdate, -365); /* * Rangliste berechnet aus allen Spielen von $fromdate bis $indexdate * we query after all players from all events belonging to this statgroup ... * this returns really ALL players who have ever played in this group (active + non-active events ..) * No sense to include the teams+events here, since there could be multiple ... * this returns multiple records for each player .... */ $RS = DB_listEventStatGroupPlayers($dbi, $feda_stat_group); $aTH = array("Vorname", "Nachname", "Scorezahl", "Checkzahl", "Gesamtzahl", "Legs", "Spiele"); debug("Calculating actual stat values for " . count($RS) . " Players"); OpenTable(); echo ArrayToTableHead($aTH); foreach ($RS as $p) { # # get legs per player - calc - and sum up, att. here we can have multiple player entries # the recordset is sorted by PID ... # $sumScore = 0; $sumCheck = 0; $CountScore = 0; $CountCheck = 0; $scoreindex = 0; $checkindex = 0; ####################### # LEGACY data from pre system times ####################### $legqry = "select lxid,lxdate,lxrscore,lxrest,lxrcheck from tbllegx where lxpid={$p['0']} and lxevlist={$feda_stat_group} and lxdate<'{$indexdate}' and lxdate>'{$fromdate}' and lxrscore>0 order by lxdate asc"; $Lrecord = sql_query($legqry, $dbi); while (list($lxid, $lxdate, $lxrscore, $lxrest, $lxrcheck) = sql_fetch_row($Lrecord, $dbi)) { $idx = ""; $idx = retFEDAIndexZahlperLeg(501, $lxrscore, $lxrest, $lxrcheck, $iTEST); list($a, $b, $c) = split(":", $idx); # values of -1 indicate failure if ($a > -1) { $sumScore = $sumScore + $a; $CountScore = $CountScore + 1; } if ($b > -1) { $sumCheck = $sumCheck + $b; $CountCheck = $CountCheck + 1; } } ####################### # structured data from League-System ####################### $LEGS = DB_listLegsFromPeriod($dbi, 0, 0, $feda_stat_group, $fromdate, $indexdate, $p[0]); #debug(count($LEGS)); # lid,lroundscore,lscore,lroundcheck,gid,mid,mround,mdate ## $gamecount = 0; $lastgid = 0; foreach ($LEGS as $L) { if ($lastgid != $L[4]) { $gamecount = $gamecount + 1; } $idx = ""; $idx = retFEDAIndexZahlperLeg(501, $L[1], 501 - $L[2], $L[3]); list($a, $b, $c) = split(":", $idx); # values of -1 indicate failure if ($a > -1) { $sumScore = $sumScore + $a; $CountScore = $CountScore + 1; } if ($b > -1) { $sumCheck = $sumCheck + $b; $CountCheck = $CountCheck + 1; } $lastgid = $L[4]; } /* * calculate index by division with countvalues */ if ($CountScore > 0) { $scoreindex = $sumScore / $CountScore; } if ($CountCheck > 0) { $checkindex = $sumCheck / $CountCheck; } /* * Finally Output into TABLEROW or OUTVAR */ /* * V3.1 change, since we have ALL players here we have a lot of cases where no actual statval is compiled in this case its zero and * we cont store anything .. */ if ($gamecount > 0) { echo "<tr><td>{$p['1']}</td><td>{$p['2']}</td><td>" . number_format($scoreindex, 2, '.', '') . "</td><td>" . number_format($checkindex, 2, '.', '') . "</td><td>" . number_format($scoreindex + $checkindex, 2, '.', '') . "</td><td>{$CountScore}</td><td>{$gamecount}</td></tr>"; if ($writeToDB == 'yes') { $qry = "insert into tblstat(statid,statdate,statcode,statval,statpid,statgames,statlegs) values(0,'{$indexdate}',{$feda_stat_group}," . number_format($scoreindex + $checkindex, 2, '.', '') . ",{$p['0']},{$gamecount},{$CountScore})"; $res = sql_query($qry, $dbi); } } else { echo "<tr style=\"color:#ff0000;\"><td>{$p['1']}</td><td>{$p['2']}</td><td>NO DATA</td><td>NO DATA</td><td>NO DATA</td><td></td><td></td></tr>"; } } #// END FOR EACH PLAYER CloseTable(); }
$start_date = strip_tags($_GET['startdate']); } if (isset($_GET['enddate'])) { $end_date = strip_tags($_GET['enddate']); } if (!is_numeric($p_id)) { return 0; } if (!is_numeric($event_code)) { return 0; } if (!is_numeric($stat_code)) { return 0; } if (!is_numeric($event_group)) { return 0; } if (strlen($start_date) > 12) { return 0; } if (strlen($end_date) > 12) { return 0; } $dbi = sql_connect($dbhost, $dbuname, $dbpass, $dbname); #echo $event_code.":".$event_group.":".$stat_code.":".$start_date.":".$end_date.":".$p_id; $RS = DB_listLegsFromPeriod($dbi, $event_code, $event_group, $stat_code, $start_date, $end_date, $p_id); #$fields=array(7,6,4,0,1,2,3); #$ROWS=RecordsetToDataTable($RS,$fields); $ROWS = RecordsetToCSV($RS); header('Content-Type: application/text; charset=ISO-8859-1'); echo $ROWS;