From 444ad2ca278a605aaba75ea9062e260937004c0a Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Thu, 23 Feb 2017 08:08:49 +0100 Subject: [PATCH] removed legacy '*_file' functions and trailed spaces --- web/briskin5/stat-day.php | 172 --------------------------- web/briskin5/statadm.php | 240 ++++++-------------------------------- 2 files changed, 34 insertions(+), 378 deletions(-) diff --git a/web/briskin5/stat-day.php b/web/briskin5/stat-day.php index 5f62596..8afb371 100644 --- a/web/briskin5/stat-day.php +++ b/web/briskin5/stat-day.php @@ -65,178 +65,6 @@ require_once("../Obj/dbase_${G_dbasetype}.phh"); require_once("Obj/briskin5.phh"); require_once("Obj/placing.phh"); -function main_file($curtime) -{ - GLOBAL $G_lang, $G_alarm_passwd; - $tri = array(); - $mon = array(); - $wee = array(); - - if (($fp = @fopen(LEGAL_PATH."/points.log", 'r')) == FALSE) { - echo "Open data file error"; - exit; - } - echo "prima
"; - - if (($fp_start = @fopen(LEGAL_PATH."/points.start", 'r')) != FALSE) { - $skip = intval(fgets($fp_start)); - if ($skip > 0) - fseek($fp, $skip, SEEK_SET); - fclose($fp_start); - } - - if (($bdb = BriskDB::create()) == FALSE) { - echo "database connection failed"; - exit; - } - - $bdb->users_load(); - - for ($i = 0 ; $i < $bdb->count() ; $i++) { - $login = $bdb->getlogin_byidx($i); - $tri[$i] = new Ptsgam($login); - $mon[$i] = new Ptsgam($login); - $wee[$i] = new Ptsgam($login); - } - - // recalculate all the placings - // 1246428948|492e4e9e856b0|N|tre|172.22.1.90|STAT:BRISKIN5:FINISH_GAME|4a4afd4983039|6|3|tre|1|due|2|uno|-1| - while (!feof($fp)) { - $p = 0; - $bf = fgets($fp, 4096); - $ar = csplitter($bf, '|'); - // if not auth table, continue - if (count($ar) < 15) - continue; - - // echo $p++."
"; - if ($ar[7] >= TABLES_AUTH_N) - continue; - // echo $p++." ".$ar[5]."
"; - // if not FINISH_GAME line, continue - if ($ar[5] != "STAT:BRISKIN5:FINISH_GAME") - continue; - // echo $p++."
"; - // if to much old points, continue - if ($ar[0] < $curtime - TRI_LIMIT) { - if (($fp_start = @fopen(LEGAL_PATH."/points.start", 'w')) != FALSE) { - $curpos = ftell($fp); - fwrite($fp_start, sprintf("%d\n", $curpos)); - fclose($fp_start); - } - - continue; - } - // echo $p++." ".BIN5_PLAYERS_N."
"; - - $found = FALSE; - $mult = 1; - for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) { - for ($e = $i + 1 ; $e < BIN5_PLAYERS_N ; $e++) { - if ($ar[10+($i*2)] == $ar[10+($e*2)]) { - $mult = abs($ar[10+($i*2)]); - $found = TRUE; - } - } - if ($found) - break; - } - - if ($mult == 0) - continue; - for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) { - // echo $p." i) ".$i."
"; - $username = $ar[9+($i*2)]; - if (($item = $bdb->getitem_bylogin($username, &$id)) == FALSE) { - echo "WARNING: the user [".$username."] NOT EXISTS!
"; - continue; - } - - // echo $item->login." id)".$id." ".$ar[10+($i*2)]." mult: ".$mult."
"; - $tri[$id]->add($ar[10+($i*2)] / $mult); - if ($ar[0] >= $curtime - MON_LIMIT) - $mon[$id]->add($ar[10+($i*2)] / $mult); - if ($ar[0] >= $curtime - WEE_LIMIT) - $wee[$id]->add($ar[10+($i*2)] / $mult); - } - // $p++; echo $p++."
"; - } - fclose($fp); - - usort($tri, ptsgam_cmp); - usort($mon, ptsgam_cmp); - usort($wee, ptsgam_cmp); - - echo "

TRI
\n"; - - if (($fplo = @fopen(LEGAL_PATH."/class_tri_lo.log", 'w')) == FALSE) { - echo "Open tri_lo failed
"; - exit; - } - if (($fphi = @fopen(LEGAL_PATH."/class_tri_hi.log", 'w')) == FALSE) { - echo "Open tri_hi failed
"; - exit; - } - - for ($i = 0 ; $i < count($tri) ; $i++) { - if ($tri[$i]->gam == 0.0) - continue; - printf("%s: %s (%d)
\n", $tri[$i]->username, $tri[$i]->snormpts(), $tri[$i]->gam); - if ($tri[$i]->gam >= TRI_MAX_GAMES) - fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($tri[$i]->username), $tri[$i]->pts, $tri[$i]->gam)); - else if ($tri[$i]->gam > TRI_MIN_GAMES) - fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($tri[$i]->username), $tri[$i]->pts, $tri[$i]->gam)); - } - fclose($fphi); - fclose($fplo); - - echo "

MON
\n"; - - if (($fplo = @fopen(LEGAL_PATH."/class_mon_lo.log", 'w')) == FALSE) { - echo "Open tri_lo failed
"; - exit; - } - if (($fphi = @fopen(LEGAL_PATH."/class_mon_hi.log", 'w')) == FALSE) { - echo "Open tri_hi failed
"; - exit; - } - - for ($i = 0 ; $i < count($mon) ; $i++) { - if ($mon[$i]->gam == 0.0) - continue; - printf("%s: %s (%d)
\n", $mon[$i]->username, $mon[$i]->snormpts(), $mon[$i]->gam); - if ($mon[$i]->gam >= MON_MAX_GAMES) - fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($mon[$i]->username), $mon[$i]->pts, $mon[$i]->gam)); - else if ($mon[$i]->gam > MON_MIN_GAMES) - fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($mon[$i]->username), $mon[$i]->pts, $mon[$i]->gam)); - } - fclose($fphi); - fclose($fplo); - - echo "

WEE
\n"; - if (($fplo = @fopen(LEGAL_PATH."/class_wee_lo.log", 'w')) == FALSE) { - echo "Open wee_lo failed
"; - exit; - } - if (($fphi = @fopen(LEGAL_PATH."/class_wee_hi.log", 'w')) == FALSE) { - echo "Open wee_hi failed
"; - exit; - } - - for ($i = 0 ; $i < count($wee) ; $i++) { - if ($wee[$i]->gam == 0.0) - continue; - printf("%s: %s (%d)
\n", $wee[$i]->username, $wee[$i]->snormpts(), $wee[$i]->gam); - if ($wee[$i]->gam >= WEE_MAX_GAMES) - fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($wee[$i]->username), $wee[$i]->pts, $wee[$i]->gam)); - else if ($wee[$i]->gam > WEE_MIN_GAMES) - fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($wee[$i]->username), $wee[$i]->pts, $wee[$i]->gam)); - } - fclose($fphi); - fclose($fplo); - -} - function main_pgsql($from, $to) { GLOBAL $G_lang, $G_dbpfx, $mlang_stat_day; diff --git a/web/briskin5/statadm.php b/web/briskin5/statadm.php index 2e702c7..71d2321 100644 --- a/web/briskin5/statadm.php +++ b/web/briskin5/statadm.php @@ -3,7 +3,7 @@ * brisk - statadm.php * * Copyright (C) 2009-2012 Matteo Nastasi - * mailto: nastasi@alternativeoutput.it + * mailto: nastasi@alternativeoutput.it * matteo.nastasi@milug.org * web: http://www.alternativeoutput.it * @@ -25,7 +25,7 @@ /* line example: 1246428948|492e4e9e856b0|N|tre|172.22.1.90|STAT:BRISKIN5:FINISH_GAME|4a4afd4983039|6|3|tre|1|due|2|uno|-1| - + */ $G_base = "../"; @@ -39,178 +39,6 @@ require_once("../Obj/dbase_${G_dbasetype}.phh"); require_once("Obj/briskin5.phh"); require_once("Obj/placing.phh"); -function main_file($curtime) -{ - GLOBAL $G_alarm_passwd; - $tri = array(); - $mon = array(); - $wee = array(); - - if (($fp = @fopen(LEGAL_PATH."/points.log", 'r')) == FALSE) { - echo "Open data file error"; - exit; - } - echo "prima
"; - - if (($fp_start = @fopen(LEGAL_PATH."/points.start", 'r')) != FALSE) { - $skip = intval(fgets($fp_start)); - if ($skip > 0) - fseek($fp, $skip, SEEK_SET); - fclose($fp_start); - } - - if (($bdb = BriskDB::create()) == FALSE) { - echo "database connection failed"; - exit; - } - - $bdb->users_load(); - - for ($i = 0 ; $i < $bdb->count() ; $i++) { - $login = $bdb->getlogin_byidx($i); - $tri[$i] = new Ptsgam($login); - $mon[$i] = new Ptsgam($login); - $wee[$i] = new Ptsgam($login); - } - - // recalculate all the placings - // 1246428948|492e4e9e856b0|N|tre|172.22.1.90|STAT:BRISKIN5:FINISH_GAME|4a4afd4983039|6|3|tre|1|due|2|uno|-1| - while (!feof($fp)) { - $p = 0; - $bf = fgets($fp, 4096); - $ar = csplitter($bf, '|'); - // if not auth table, continue - if (count($ar) < 15) - continue; - - // echo $p++."
"; - if ($ar[7] >= TABLES_AUTH_N) - continue; - // echo $p++." ".$ar[5]."
"; - // if not FINISH_GAME line, continue - if ($ar[5] != "STAT:BRISKIN5:FINISH_GAME") - continue; - // echo $p++."
"; - // if to much old points, continue - if ($ar[0] < $curtime - TRI_LIMIT) { - if (($fp_start = @fopen(LEGAL_PATH."/points.start", 'w')) != FALSE) { - $curpos = ftell($fp); - fwrite($fp_start, sprintf("%d\n", $curpos)); - fclose($fp_start); - } - - continue; - } - // echo $p++." ".BIN5_PLAYERS_N."
"; - - $found = FALSE; - $mult = 1; - for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) { - for ($e = $i + 1 ; $e < BIN5_PLAYERS_N ; $e++) { - if ($ar[10+($i*2)] == $ar[10+($e*2)]) { - $mult = abs($ar[10+($i*2)]); - $found = TRUE; - } - } - if ($found) - break; - } - - if ($mult == 0) - continue; - for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) { - // echo $p." i) ".$i."
"; - $username = $ar[9+($i*2)]; - if (($item = $bdb->getitem_bylogin($username, &$id)) == FALSE) { - echo "WARNING: the user [".$username."] NOT EXISTS!
"; - continue; - } - - // echo $item->login." id)".$id." ".$ar[10+($i*2)]." mult: ".$mult."
"; - $tri[$id]->add($ar[10+($i*2)] / $mult); - if ($ar[0] >= $curtime - MON_LIMIT) - $mon[$id]->add($ar[10+($i*2)] / $mult); - if ($ar[0] >= $curtime - WEE_LIMIT) - $wee[$id]->add($ar[10+($i*2)] / $mult); - } - // $p++; echo $p++."
"; - } - fclose($fp); - - usort($tri, ptsgam_cmp); - usort($mon, ptsgam_cmp); - usort($wee, ptsgam_cmp); - - echo "

TRI
\n"; - - if (($fplo = @fopen(LEGAL_PATH."/class_tri_lo.log", 'w')) == FALSE) { - echo "Open tri_lo failed
"; - exit; - } - if (($fphi = @fopen(LEGAL_PATH."/class_tri_hi.log", 'w')) == FALSE) { - echo "Open tri_hi failed
"; - exit; - } - - for ($i = 0 ; $i < count($tri) ; $i++) { - if ($tri[$i]->gam == 0.0) - continue; - printf("%s: %s (%d)
\n", $tri[$i]->username, $tri[$i]->snormpts(), $tri[$i]->gam); - if ($tri[$i]->gam >= TRI_MAX_GAMES) - fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($tri[$i]->username), $tri[$i]->pts, $tri[$i]->gam)); - else if ($tri[$i]->gam > TRI_MIN_GAMES) - fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($tri[$i]->username), $tri[$i]->pts, $tri[$i]->gam)); - } - fclose($fphi); - fclose($fplo); - - echo "

MON
\n"; - - if (($fplo = @fopen(LEGAL_PATH."/class_mon_lo.log", 'w')) == FALSE) { - echo "Open tri_lo failed
"; - exit; - } - if (($fphi = @fopen(LEGAL_PATH."/class_mon_hi.log", 'w')) == FALSE) { - echo "Open tri_hi failed
"; - exit; - } - - for ($i = 0 ; $i < count($mon) ; $i++) { - if ($mon[$i]->gam == 0.0) - continue; - printf("%s: %s (%d)
\n", $mon[$i]->username, $mon[$i]->snormpts(), $mon[$i]->gam); - if ($mon[$i]->gam >= MON_MAX_GAMES) - fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($mon[$i]->username), $mon[$i]->pts, $mon[$i]->gam)); - else if ($mon[$i]->gam > MON_MIN_GAMES) - fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($mon[$i]->username), $mon[$i]->pts, $mon[$i]->gam)); - } - fclose($fphi); - fclose($fplo); - - echo "

WEE
\n"; - if (($fplo = @fopen(LEGAL_PATH."/class_wee_lo.log", 'w')) == FALSE) { - echo "Open wee_lo failed
"; - exit; - } - if (($fphi = @fopen(LEGAL_PATH."/class_wee_hi.log", 'w')) == FALSE) { - echo "Open wee_hi failed
"; - exit; - } - - for ($i = 0 ; $i < count($wee) ; $i++) { - if ($wee[$i]->gam == 0.0) - continue; - printf("%s: %s (%d)
\n", $wee[$i]->username, $wee[$i]->snormpts(), $wee[$i]->gam); - if ($wee[$i]->gam >= WEE_MAX_GAMES) - fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($wee[$i]->username), $wee[$i]->pts, $wee[$i]->gam)); - else if ($wee[$i]->gam > WEE_MIN_GAMES) - fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($wee[$i]->username), $wee[$i]->pts, $wee[$i]->gam)); - } - fclose($fphi); - fclose($fplo); - -} - function main_pgsql($curtime) { GLOBAL $G_dbpfx; @@ -229,16 +57,16 @@ function main_pgsql($curtime) log_crit("statadm: begin failed"); break; } - - $mtc_sql = sprintf("CREATE TEMPORARY TABLE %sbin5_temp_matches ON COMMIT DROP AS SELECT m.code, max(g.tstamp) AS tstamp - FROM %sbin5_matches as m, %sbin5_games as g + + $mtc_sql = sprintf("CREATE TEMPORARY TABLE %sbin5_temp_matches ON COMMIT DROP AS SELECT m.code, max(g.tstamp) AS tstamp + FROM %sbin5_matches as m, %sbin5_games as g WHERE (m.tcode = %d OR m.tcode = %d) AND m.code = g.mcode GROUP BY m.code, m.ttok", $G_dbpfx, $G_dbpfx, $G_dbpfx, BIN5_TOURNAMENT_OLDRULES, BIN5_TOURNAMENT_NO_DRAW); if (pg_query($bdb->dbconn->db(), $mtc_sql) == FALSE) { log_crit("statadm: temporary matches table creation [$mtc_sql] failed"); break; } - + $tmt_sql = sprintf("SELECT * FROM %sbin5_temp_matches WHERE tstamp < to_timestamp(%d)", $G_dbpfx, $curtime - TRI_LIMIT); @@ -252,40 +80,40 @@ function main_pgsql($curtime) log_crit("statadm: log file [$fname] open failed"); break; } - + $tmt_n = pg_numrows($tmt_pg); // get matches for ($m = 0 ; $m < $tmt_n ; $m++) { $tmt_obj = pg_fetch_object($tmt_pg, $m); - + $mtc_sql = sprintf("SELECT * from %sbin5_matches WHERE code = %d", $G_dbpfx, $tmt_obj->code); - + if (($mtc_pg = pg_query($bdb->dbconn->db(), $mtc_sql)) == FALSE || pg_numrows($mtc_pg) != 1) { log_crit("statadm: matches row select failed"); break; } $mtc_obj = pg_fetch_object($mtc_pg, 0); - + if (fwrite($fp, sprintf("M|%d|%s|%d|%d|\n", $mtc_obj->code, xcapelt($mtc_obj->ttok), $mtc_obj->tidx, $mtc_obj->tcode)) == FALSE) { log_crit("statadm: log file [$fname] write match failed"); break; } - + // get games associated to each match - $gam_sql = sprintf("SELECT code, mcode, EXTRACT(epoch FROM tstamp) AS tstamp FROM %sbin5_games + $gam_sql = sprintf("SELECT code, mcode, EXTRACT(epoch FROM tstamp) AS tstamp FROM %sbin5_games WHERE mcode = %d ORDER BY tstamp", $G_dbpfx, $mtc_obj->code); if (($gam_pg = pg_query($bdb->dbconn->db(), $gam_sql)) == FALSE) { log_crit("statadm: games row select failed"); break; } - + $gam_n = pg_numrows($gam_pg); for ($g = 0 ; $g < $gam_n ; $g++) { $gam_obj = pg_fetch_object($gam_pg, $g); - + if (fwrite($fp, sprintf("G|%d|%d|%d|\n", $gam_obj->mcode, $gam_obj->code, $gam_obj->tstamp)) == FALSE) { log_crit("statadm: log file [$fname] write game failed"); break; @@ -298,7 +126,7 @@ function main_pgsql($curtime) $pts_n = pg_numrows($pts_pg); for ($p = 0 ; $p < $pts_n ; $p++) { $pts_obj = pg_fetch_object($pts_pg, $p); - + if (fwrite($fp, sprintf("P|%d|%d|%d|\n", $pts_obj->gcode, $pts_obj->ucode, $pts_obj->pts)) == FALSE) { log_crit("statadm: log file [$fname] write pts failed"); break; @@ -309,7 +137,7 @@ function main_pgsql($curtime) } if ($g < $gam_n) break; - + // delete match and all it's childs (games and points) $del_sql = sprintf("DELETE FROM %sbin5_matches WHERE code = %d", $G_dbpfx, $tmt_obj->code); @@ -317,7 +145,7 @@ function main_pgsql($curtime) log_crit("statadm: matches row deletion failed"); break; } - + } if ($m < $tmt_n) break; @@ -329,7 +157,7 @@ function main_pgsql($curtime) log_crit("statadm: truncate failed"); break; } - + for ($dtime = 0 ; $dtime < count($limi) ; $dtime++) { $old_score = array( 1000000000, 1000000000); $old_gam = array( -1, -1); @@ -337,14 +165,14 @@ function main_pgsql($curtime) // TAG: POINTS_MANAGEMENT $pla_sql = sprintf("SELECT (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts)) as score, sum(p.pts) as points, count(p.pts) as games, u.code as ucode, u.login as login - FROM %sbin5_points as p, %sbin5_games as g, %sbin5_matches as m, %susers as u + FROM %sbin5_points as p, %sbin5_games as g, %sbin5_matches as m, %susers as u WHERE (m.tcode = %d OR m.tcode = %d) AND m.code = g.mcode AND ( (u.type & (CAST (X'ff0000' as integer))) <> (CAST (X'800000' as integer)) ) AND g.tstamp > to_timestamp(%d) AND g.tstamp <= to_timestamp(%d) AND p.ucode = u.code AND p.gcode = g.code AND p.pts != 0 GROUP BY u.code, u.login - ORDER BY (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts)) DESC, + ORDER BY (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts)) DESC, count(p.pts) DESC", $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx, BIN5_TOURNAMENT_OLDRULES, BIN5_TOURNAMENT_NO_DRAW, @@ -357,7 +185,7 @@ function main_pgsql($curtime) log_crit("statadm: main placement select failed [$pla_sql]"); break; } - + for ($i = 0 ; $i < pg_numrows($pla_pg) ; $i++) { $pla_obj = pg_fetch_object($pla_pg,$i); if ($pla_obj->games < $ming[$dtime]) @@ -367,22 +195,22 @@ function main_pgsql($curtime) $subty = 0; else $subty = 1; - + $ty = ($dtime * 2) + $subty; - + if ($pla_obj->games != $old_gam[$subty] || $pla_obj->score != $old_score[$subty]) { $rank[$subty]++; } $new_sql = sprintf("INSERT INTO %sbin5_places (type, rank, ucode, login, pts, games, score) VALUES (%d, %d, %d, '%s', %d, %d, %f);", - $G_dbpfx, $ty, $rank[$subty], $pla_obj->ucode, escsql($pla_obj->login), + $G_dbpfx, $ty, $rank[$subty], $pla_obj->ucode, escsql($pla_obj->login), $pla_obj->points, $pla_obj->games, $pla_obj->score); - if ( ! (($new_pg = pg_query($bdb->dbconn->db(), $new_sql)) != FALSE && + if ( ! (($new_pg = pg_query($bdb->dbconn->db(), $new_sql)) != FALSE && pg_affected_rows($new_pg) == 1) ) { log_crit("statadm: new place insert failed: ".print_r($pla_obj, TRUE)); - break; + break; } - + $old_gam[$subty] = $pla_obj->games; $old_score[$subty] = $pla_obj->score; } // for ($i = 0 ; $i < pg_numrows($pla_pg) ; $i++) { @@ -396,12 +224,12 @@ function main_pgsql($curtime) $mti_sql = sprintf("UPDATE %sbin5_places_mtime SET mtime = (to_timestamp(%d)) WHERE code = 0;", $G_dbpfx, $curtime); - if ( ! (($mti_pg = pg_query($bdb->dbconn->db(), $mti_sql)) != FALSE && + if ( ! (($mti_pg = pg_query($bdb->dbconn->db(), $mti_sql)) != FALSE && pg_affected_rows($mti_pg) == 1) ) { log_crit("statadm: new mtime insert failed."); - break; + break; } - + if ($bdb->transaction("COMMIT") == FALSE) { break; } @@ -416,7 +244,7 @@ function main_pgsql($curtime) function main() { GLOBAL $G_dbasetype, $G_alarm_passwd, $pazz; - + echo "Inizio.
"; mop_flush(); if ($pazz != $G_alarm_passwd) { @@ -424,9 +252,9 @@ function main() mop_flush(); exit; } - + $fun_name = "main_${G_dbasetype}"; - + $ctime = time(); if (BIN5_PLAYERS_N != 5) @@ -437,7 +265,7 @@ function main() echo "Success.
\n"; else echo "Failed.
\n"; - + echo "Fine.\n"; mop_flush(); } -- 2.17.1