X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fbriskin5%2Fstat-day.php;h=0359bfe3d800292ef8a4145f97ad244258cbe72a;hb=7f9618888f9963c4a7daebeb9e3d14ef0a56b968;hp=ff991e2219d07b539a9a0cb12d90c0105871b85b;hpb=c33375c2aaad1aefb69e269be1a95d3f737027d6;p=brisk.git diff --git a/web/briskin5/stat-day.php b/web/briskin5/stat-day.php index ff991e2..0359bfe 100644 --- a/web/briskin5/stat-day.php +++ b/web/briskin5/stat-day.php @@ -238,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"); @@ -266,10 +267,18 @@ 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 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 ... @@ -293,40 +302,48 @@ function main_pgsql($from, $to) 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) { @@ -334,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_obj[$u] = pg_fetch_object($pts_pg[$u], $g); + + if ($pt_min > $pts_obj[$u]->pts) { + $pt_min = $pts_obj[$u]->pts; + $pt_min_n = 1; + } + else if ($pt_min == $pts_obj[$u]->pts) { + $pt_min_n++; + } + + if ($pt_max < $pts_obj[$u]->pts) { + $pt_max = $pts_obj[$u]->pts; + $pt_max_n = 1; + } + else if ($pt_max == $pts_obj[$u]->pts) { + $pt_max_n++; + } + } + if ($pt_min_n > 1) { + $pt_min = 1000; + } + if ($pt_max_n > 1) { + $pt_max = -1000; + } + + /* cases: + pts = 0 -> white + pts == pt_min -> red + pts == pt_max -> green + pts < 0 -> light red + pts > 0 -> light green + */ + for ($u = 0 ; $u < BIN5_PLAYERS_N ; $u++) { + $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 | %s | \n", $mlang_stat_day['info_total'][$G_lang]); + } fprintf($fpexp, "