X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;ds=inline;f=web%2Fbriskin5%2Fstat-day.php;h=0359bfe3d800292ef8a4145f97ad244258cbe72a;hb=refs%2Ftags%2Fv4.15.0;hp=04c106c20353decd4256e46a5d1eb75e20dcac2f;hpb=5edb498623d6c7becaf01a2eb8a8dd485c08eed5;p=brisk.git diff --git a/web/briskin5/stat-day.php b/web/briskin5/stat-day.php index 04c106c..0359bfe 100644 --- a/web/briskin5/stat-day.php +++ b/web/briskin5/stat-day.php @@ -43,7 +43,10 @@ $G_base = "../"; $mlang_stat_day = array( 'normal match'=> array( 'it' => 'Partite normali', 'en' => 'Normal matches' ), 'special match' => array( 'it' => 'Partite speciali', - 'en' => 'Special matches') + 'en' => 'Special matches'), + + 'info_total'=> array( 'it' => 'totali', + 'en' => 'En totali') ); @@ -235,6 +238,7 @@ function main_pgsql($from, $to) $ret = FALSE; $fpexp = FALSE; + // log_crit("stat-day: BEGIN"); do { if (($fpexp = @fopen(LEGAL_PATH."/explain.log", 'w')) == FALSE) { log_crit("stat-day: open explain failed"); @@ -261,12 +265,21 @@ function main_pgsql($from, $to) } $trn_n = pg_numrows($trn_pg); + printf("Number of tournaments: %d\n", $trn_n); + // loop on tournaments for ($t = 0 ; $t < $trn_n ; $t++) { + // log_crit("stat-day: LOOP 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 g.tstamp >= '%s' AND g.tstamp < '%s' GROUP BY m.code;", - $G_dbpfx, $G_dbpfx, $G_dbpfx, $from, $to); + $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 ... if (($tmt_pg = pg_query($bdb->dbconn->db(), $tmt_sql)) == FALSE) { @@ -286,42 +299,51 @@ function main_pgsql($from, $to) log_crit("stat-day: tournament name not found in array"); break; } + printf("[Tournament [%s]], number of matches: %d\n", $mlang_stat_day[$trn_obj->name][$G_lang], $tmt_n); fprintf($fpexp, "
%s | ", $usr_obj[$u]->login); - $pts_sql = sprintf("SELECT p.pts as pts 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 AND u.code = %d ORDER BY g.code", $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx, - $tmt_obj->code, $usr_obj[$u]->code); + fprintf($fpexp, "%s | ", $users[$u]['login']); + // note: we are looping on users, order on them not needed + $pts_sql = sprintf(" +SELECT p.pts AS pts + FROM %sbin5_games AS g, %sbin5_points AS p + WHERE g.code = p.gcode AND g.mcode = %d AND p.ucode = %d + ORDER BY g.tstamp", + $G_dbpfx, $G_dbpfx, + $tmt_obj->code, $users[$u]['code']); // points of the match for each user - if (($pts_pg[$u] = pg_query($bdb->dbconn->db(), $pts_sql)) == FALSE) { + if (($pts_pg[$u] = pg_query($bdb->dbconn->db(), $pts_sql)) == FALSE) { + log_crit("stat-day: pts_sql failed"); break; } if ($u == 0) { @@ -329,52 +351,128 @@ SELECT u.code AS code, u.login AS login, min(g.tstamp) AS first, max(g.tstamp) A } else { if ($num_games != pg_numrows($pts_pg[$u])) { + log_crit("stat-day: num_games != pg_numrows"); break; } } } if ($u != BIN5_PLAYERS_N) { + log_crit("stat-day: u != BIN5_PLAYERS_N"); break; } - fprintf($fpexp, "mazzo | descrizione | mazzo | descrizione | \n"); + } // LISTA DELLE VARIE PARTITE + $pts_obj = array(); for ($g = 0 ; $g < $num_games ; $g++) { $gam_obj = pg_fetch_object($gam_pg, $g); fprintf($fpexp, "
---|---|---|---|---|
%d | ", $pts_obj->pts); + $pts = $pts_obj[$u]->pts; + + if ($pts == 0) + $cla_nam = 'bg_white'; + else if ($pts == $pt_min) + $cla_nam = 'bg_red'; + else if ($pts == $pt_max) + $cla_nam = 'bg_green'; + else if ($pts < 0) + $cla_nam = 'bg_lired'; + else if ($pts > 0) + $cla_nam = 'bg_ligre'; + + fprintf($fpexp, "<%s class='%s'>%d%s>", + ($tmt_obj->minus_one_is_old == -1 ? "td" : "th"), + $cla_nam, pow(2,$gam_obj->mult) * $pts, + ($tmt_obj->minus_one_is_old == -1 ? "td" : "th")); + } + if ($tmt_obj->minus_one_is_old != -1) { + fprintf($fpexp, "%s | %s | ", $users[$gam_obj->mazzo]['login'], + xcape( game_description($gam_obj->act, 'plain', $gam_obj->mult, + $gam_obj->asta_win, + ($gam_obj->asta_win != -1 ? + $users[$gam_obj->asta_win]['login'] : ""), + $gam_obj->friend, + ($gam_obj->friend != -1 ? + $users[$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, "
%d | ", $tot_obj->pts); } - fprintf($fpexp, "%s | \n", $mlang_stat_day['info_total'][$G_lang]); + } fprintf($fpexp, "