management of old games in stat-day.php, statadm.php and minor bugfixes
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Tue, 8 Oct 2013 16:25:54 +0000 (18:25 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Wed, 9 Oct 2013 05:38:11 +0000 (07:38 +0200)
web/briskin5/Obj/briskin5.phh
web/briskin5/Obj/placing.phh
web/briskin5/explain.php
web/briskin5/stat-day.php
web/briskin5/statadm.php

index 4bf9f70..068ea16 100644 (file)
@@ -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));
     }
index 71cbca1..fd932b4 100644 (file)
@@ -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) 
index e1852ab..dd09f68 100644 (file)
@@ -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";
 }
 ?>
 <html>
index ff991e2..4bd60ce 100644 (file)
@@ -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, "<br>");
                 $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, "<th>mazzo</th><th>descrizione</th></tr>\n");
 
+                if ($tmt_obj->minus_one_is_old != -1) {
+                    fprintf($fpexp, "<th>mazzo</th><th>descrizione</th></tr>\n");
+                }
                 // LISTA DELLE VARIE PARTITE
                 for ($g = 0 ; $g < $num_games ; $g++) {
                     $gam_obj = pg_fetch_object($gam_pg, $g);
                     fprintf($fpexp, "<tr>");
                     for ($u = 0 ; $u < BIN5_PLAYERS_N ; $u++) {
                         $pts_obj = pg_fetch_object($pts_pg[$u], $g);
-                        fprintf($fpexp, "<th>%d</th>", $pts_obj->pts);
+                        fprintf($fpexp, "<%s>%d</%s>",
+                                ($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, "<td>%s</td><td>%s</td>", $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, "<td>%s</td><td>%s</td>", $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, "</tr>\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, "<th>%d</th>", $tot_obj->pts);
                 }
-                fprintf($fpexp, "<th colspan='2'>%s</th></tr>\n", $mlang_stat_day['info_total'][$G_lang]);
+                if ($tmt_obj->minus_one_is_old != -1) {
+                    fprintf($fpexp, "<th colspan='2'>%s</th></tr>\n", $mlang_stat_day['info_total'][$G_lang]);
+                }
                 fprintf($fpexp, "</table>\n");
             }
             if ($m < $tmt_n)
index db3cf9b..f6d40b3 100644 (file)
@@ -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]");