From: Matteo Nastasi (mop) Date: Tue, 8 Oct 2013 16:25:54 +0000 (+0200) Subject: management of old games in stat-day.php, statadm.php and minor bugfixes X-Git-Tag: v4.10.0^2~15 X-Git-Url: http://mop.ddnsfree.com/gitweb/?p=brisk.git;a=commitdiff_plain;h=66eaf1176bb114a40111960b5467201efef2b247 management of old games in stat-day.php, statadm.php and minor bugfixes --- diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index 4bf9f70..068ea16 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -30,9 +30,10 @@ define('BIN5_SHM_MAX', (BIN5_SHM_MIN + 1048576)); define('BIN5_SHM_DLT', 32768); define('BIN5_PROXY_PATH', PROXY_PATH."/bin5"); -define('BIN5_RULES_FINISH', 0); -define('BIN5_RULES_ABANDON', 1); -define('BIN5_RULES_ALLPASS', 2); +define('BIN5_RULES_OLDSCHEMA', -1); +define('BIN5_RULES_FINISH', 0); +define('BIN5_RULES_ABANDON', 1); +define('BIN5_RULES_ALLPASS', 2); $mlang_bin5_bin5 = array( // br, hr, b, /b, win, fri @@ -1900,7 +1901,10 @@ function game_description($act, $form, $old_mult, $win = -1, $win_name = "?1?", $tg_bc = ""; } - if ($act == BIN5_RULES_ALLPASS) { + if ($act == BIN5_RULES_OLDSCHEMA) { + return (""); + } + else if ($act == BIN5_RULES_ALLPASS) { return (sprintf($mlang_bin5_bin5['info_alpa'][$G_lang], $tg_br, $tg_hr, $tg_bo, $tg_bc)); } diff --git a/web/briskin5/Obj/placing.phh b/web/briskin5/Obj/placing.phh index 71cbca1..fd932b4 100644 --- a/web/briskin5/Obj/placing.phh +++ b/web/briskin5/Obj/placing.phh @@ -96,13 +96,13 @@ function ptsgam_cmp($a, $b) } /* types of placing based on delta time */ -define(TY_DTIME_TRI, 0); -define(TY_DTIME_MON, 1); -define(TY_DTIME_WEE, 2); +define('TY_DTIME_TRI', 0); +define('TY_DTIME_MON', 1); +define('TY_DTIME_WEE', 2); /* subtypes of placing based on number of played games */ -define(SUBTY_FREQ_LO, 0); -define(SUBTY_FREQ_HI, 1); +define('SUBTY_FREQ_LO', 0); +define('SUBTY_FREQ_HI', 1); function placings_show($user) diff --git a/web/briskin5/explain.php b/web/briskin5/explain.php index e1852ab..dd09f68 100644 --- a/web/briskin5/explain.php +++ b/web/briskin5/explain.php @@ -40,11 +40,11 @@ require_once("Obj/briskin5.phh"); require_once("Obj/placing.phh"); function main() { - - if (file_exists(LEGAL_PATH."/explain.log")) { - $ret .= file_get_contents(LEGAL_PATH."/explain.log"); - } - echo "$ret"; + $ret = ""; + if (file_exists(LEGAL_PATH."/explain.log")) { + $ret .= file_get_contents(LEGAL_PATH."/explain.log"); + } + echo "$ret"; } ?> diff --git a/web/briskin5/stat-day.php b/web/briskin5/stat-day.php index ff991e2..4bd60ce 100644 --- a/web/briskin5/stat-day.php +++ b/web/briskin5/stat-day.php @@ -269,7 +269,7 @@ function main_pgsql($from, $to) for ($t = 0 ; $t < $trn_n ; $t++) { $trn_obj = pg_fetch_object($trn_pg, $t); - $tmt_sql = sprintf("SELECT m.code AS code FROM %sbin5_matches AS m, %sbin5_games AS g, %sbin5_tournaments as t WHERE t.code = m.tcode AND m.code = g.mcode AND t.code = %d AND g.tstamp >= '%s' AND g.tstamp < '%s' GROUP BY m.code;", + $tmt_sql = sprintf("SELECT m.code AS code, m.mazzo_next as minus_one_is_old FROM %sbin5_matches AS m, %sbin5_games AS g, %sbin5_tournaments as t WHERE t.code = m.tcode AND m.code = g.mcode AND t.code = %d AND g.tstamp >= '%s' AND g.tstamp < '%s' GROUP BY m.code, minus_one_is_old ORDER BY m.code, minus_one_is_old DESC;", $G_dbpfx, $G_dbpfx, $G_dbpfx, $trn_obj->code, $from, $to); // if deletable old matches exists then ... @@ -297,14 +297,22 @@ function main_pgsql($from, $to) fprintf($fpexp, "
"); $tmt_obj = pg_fetch_object($tmt_pg, $m); - $usr_sql = sprintf(" + if ($tmt_obj->minus_one_is_old > -1) { // is new + $usr_sql = sprintf(" SELECT u.code AS code, u.login AS login, min(g.tstamp) AS first, max(g.tstamp) AS last, m.tidx AS tidx FROM %sbin5_matches AS m, %sbin5_games AS g, %sbin5_points AS p, %susers AS u, %sbin5_table_orders AS o WHERE m.code = g.mcode AND g.code = p.gcode AND u.code = p.ucode AND m.code = %d AND m.code = o.mcode AND u.code = o.ucode GROUP BY u.code, u.login, m.tidx, o.pos ORDER BY o.pos;", $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx, $tmt_obj->code); + } + else { // is old + $usr_sql = sprintf(" +SELECT u.code AS code, u.login AS login, min(g.tstamp) AS first, max(g.tstamp) AS last, m.tidx AS tidx FROM %sbin5_matches AS m, %sbin5_games AS g, %sbin5_points AS p, %susers AS u WHERE m.code = g.mcode AND g.code = p.gcode AND u.code = p.ucode AND m.code = %d GROUP BY u.code, u.login, m.tidx;", $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx, $tmt_obj->code); + } if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE ) { + log_crit("stat-day: pg_query usr_sql failed"); break; } $usr_n = pg_numrows($usr_pg); if ($usr_n != BIN5_PLAYERS_N) { + log_crit("stat-day: wrong number of players"); break; } @@ -341,22 +349,29 @@ SELECT u.code AS code, u.login AS login, min(g.tstamp) AS first, max(g.tstamp) A if ($u != BIN5_PLAYERS_N) { break; } - fprintf($fpexp, "mazzodescrizione\n"); + if ($tmt_obj->minus_one_is_old != -1) { + fprintf($fpexp, "mazzodescrizione\n"); + } // LISTA DELLE VARIE PARTITE for ($g = 0 ; $g < $num_games ; $g++) { $gam_obj = pg_fetch_object($gam_pg, $g); fprintf($fpexp, ""); for ($u = 0 ; $u < BIN5_PLAYERS_N ; $u++) { $pts_obj = pg_fetch_object($pts_pg[$u], $g); - fprintf($fpexp, "%d", $pts_obj->pts); + fprintf($fpexp, "<%s>%d", + ($tmt_obj->minus_one_is_old == -1 ? "td" : "th"), + $pts_obj->pts, + ($tmt_obj->minus_one_is_old == -1 ? "td" : "th")); + } + if ($tmt_obj->minus_one_is_old != -1) { + fprintf($fpexp, "%s%s", $usr_obj[$gam_obj->mazzo]->login, + xcape( game_description($gam_obj->act, 'plain', $gam_obj->mult, + $gam_obj->asta_win, $usr_obj[$gam_obj->asta_win]->login, + $gam_obj->friend, $usr_obj[$gam_obj->friend]->login, + $gam_obj->pnt, $gam_obj->asta_pnt) ) + ); } - fprintf($fpexp, "%s%s", $usr_obj[$gam_obj->mazzo]->login, - xcape( game_description($gam_obj->act, 'plain', $gam_obj->mult, - $gam_obj->asta_win, $usr_obj[$gam_obj->asta_win]->login, - $gam_obj->friend, $usr_obj[$gam_obj->friend]->login, - $gam_obj->pnt, $gam_obj->asta_pnt) ) - ); fprintf($fpexp, "\n"); } @@ -372,7 +387,9 @@ SELECT SUM(p.pts) AS pts FROM %sbin5_matches AS m, %sbin5_games AS g, %sbin5_poi $tot_obj = pg_fetch_object($tot_pg, 0); fprintf($fpexp, "%d", $tot_obj->pts); } - fprintf($fpexp, "%s\n", $mlang_stat_day['info_total'][$G_lang]); + if ($tmt_obj->minus_one_is_old != -1) { + fprintf($fpexp, "%s\n", $mlang_stat_day['info_total'][$G_lang]); + } fprintf($fpexp, "\n"); } if ($m < $tmt_n) diff --git a/web/briskin5/statadm.php b/web/briskin5/statadm.php index db3cf9b..f6d40b3 100644 --- a/web/briskin5/statadm.php +++ b/web/briskin5/statadm.php @@ -30,6 +30,8 @@ $G_base = "../"; +define('BIN5_TOURNAMENT_NORMAL', 1); + ini_set("max_execution_time", "240"); require_once("../Obj/brisk.phh"); @@ -232,8 +234,8 @@ function main_pgsql($curtime) $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 g.mcode = m.code GROUP BY m.code, m.ttok", - $G_dbpfx, $G_dbpfx, $G_dbpfx); + WHERE m.tcode = %d AND m.code = g.mcode GROUP BY m.code, m.ttok", + $G_dbpfx, $G_dbpfx, $G_dbpfx, BIN5_TOURNAMENT_NORMAL); if (pg_query($bdb->dbconn->db(), $mtc_sql) == FALSE) { log_crit("statadm: temporary matches table creation [$mtc_sql] failed"); break; @@ -336,12 +338,14 @@ function main_pgsql($curtime) $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 - WHERE p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND - g.tstamp > to_timestamp(%d) AND g.tstamp <= to_timestamp(%d) + WHERE m.tcode = %d AND m.code = g.mcode AND + g.tstamp > to_timestamp(%d) AND g.tstamp <= to_timestamp(%d) AND + p.ucode = u.code AND p.gcode = g.code GROUP BY u.code, u.login 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, $curtime - $limi[$dtime], $curtime); + $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx, BIN5_TOURNAMENT_NORMAL, + $curtime - $limi[$dtime], $curtime); // log_crit("statadm: INFO: [$pla_sql]");