FEATURES |
----------+
+ - PLACEMENT-NORMALIZATION
+ DONE . Normalize previous points
+ DONE . Denormalize "Info" view
+ DONE . Denormalize explained matches
+ DONE . Check placement
+ DONE . Distinguish between inherited mult and local mult
+
- AUTO-MAINTENANCE
DONE . Terms Of Service acceptance
DONE . print date of hard switch
==== brisk/table/user relationships ====
+=== points management ===
+
+read from db:
+ * continue a match
+ * calculate placings
+ * calculate explain
+
+write to db:
+ * finish a game
+
=== in the room ===
// when standup
#
MATCH_DROP='^DROP.*([^-]...|.[^-]..|..[^M].|...[^F])$|^ALTER TABLE.* DROP .*([^-]...|.[^-]..|..[^M].|...[^F])$|^DELETE .*([^-]...|.[^-]..|..[^M].|...[^F])$|--MB$'
+DATECUR="$(date +%s)"
# functions
usage () {
echo " USAGE"
- echo " ./builder <command> [-d|--dryrun] [-a|--allfiles] [-s|--short] ..."
+ echo " ./builder <command> [-d|--dryrun] [-a|-p|--allfiles|--devfiles] [-s|--short] ..."
echo " ./builder <-h|--help|help>"
echo " commands are:"
echo " create"
sht=$1
if [ "$SHORT" = "y" ]; then
- sed "s/#PFX#/$PFX/g" | psql -a $pg_args 2>&1 | egrep 'ERROR|^-- MESG'
+ sed "s/#PFX#/$PFX/g;s/#NOW#/$DATECUR/g" | psql -a $pg_args 2>&1 | egrep 'ERROR|^-- MESG|^-- FILE '
else
- sed "s/#PFX#/$PFX/g" | psql -a $pg_args
+ sed "s/#PFX#/$PFX/g;s/#NOW#/$DATECUR/g" | psql -a $pg_args
fi
return 0
}
one_or_all() {
- if [ "$ALL_FILES" = "y" ]; then
- sfx_files='*'
- else
- sfx_files='*.sql'
- fi
-
- if [ "$1" = "" ]; then
- cat sql.d/$sfx_files
- else
- cat "$1"
- fi
+ local old_ifs
+
+ old_ifs="$IFS"
+ IFS=" "
+ for fil in $(
+ if [ "$1" ]; then
+ echo "$1"
+ elif [ "$TYPE_FILES" = "a" ]; then
+ echo sql.d/[0-9]*
+ elif [ "$TYPE_FILES" = "d" ]; then
+ echo sql.d/[0-9]*.{sql,devel}
+ else
+ echo sql.d/[0-9]*.sql
+ fi); do
+ echo "-- FILE BEG: $fil"
+ cat "$fil"
+ echo "-- FILE END: $fil"
+ done
+ IFS="$old_ifs"
}
#
}
;;
-a|--allfiles)
- ALL_FILES=y
+ TYPE_FILES=a
+ ;;
+ -p|--devfiles)
+ TYPE_FILES=d
;;
-s|--short)
SHORT=y
su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
;;
"clean")
- ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; ) | sqlexe
+ ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: clean end" ; ) | sqlexe
;;
"build")
( echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) | sqlexe
;;
"rebuild")
- ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; \
+ ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: clean end" ; \
echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) \
| sqlexe
;;
( echo "-- MESG: add start" ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: add end" ; ) | sqlexe
;;
"del")
- ( echo "-- MESG: del start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; echo "-- MESG: del end" ; ) | sqlexe
+ ( echo "-- MESG: del start" ; cat "$@" | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: del end" ; ) | sqlexe
;;
"res")
- ( echo "-- MESG: res start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: del end" ; ) | sqlexe
+ ( echo "-- MESG: res start" ; cat "$@" | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: del end" ; ) | sqlexe
;;
"help"|"-h"|"--help")
usage 0
--- /dev/null
+DELETE FROM #PFX#bin5_matches WHERE code = 100 OR code = 101;
+
+INSERT INTO #PFX#bin5_matches (code, ttok, tidx, mazzo_next, mult_next) VALUES (100, 'normalize_points', 2, 1, 1) RETURNING *;
+INSERT INTO #PFX#bin5_table_orders (mcode, ucode, pos) VALUES (100, 10101, 0);
+INSERT INTO #PFX#bin5_table_orders (mcode, ucode, pos) VALUES (100, 10102, 1);
+INSERT INTO #PFX#bin5_table_orders (mcode, ucode, pos) VALUES (100, 10103, 2);
+INSERT INTO #PFX#bin5_games (code, mcode, tstamp, act, asta_pnt, pnt, asta_win, friend, mazzo, mult)
+ VALUES (200, 100, to_timestamp(#NOW# - 1000), 2, 60, 0, -1, -1, 0, 0) RETURNING *;
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (200, 10101, 0);
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (200, 10102, 0);
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (200, 10103, 0);
+UPDATE #PFX#bin5_matches SET (mazzo_next, mult_next) = (2, 0) WHERE code = 100;
+INSERT INTO #PFX#bin5_games (code, mcode, tstamp, act, asta_pnt, pnt, asta_win, friend, mazzo, mult)
+ VALUES (201, 100, to_timestamp(#NOW# - 900), 0, 61, 37, 2, 1, 1, 1) RETURNING *;
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (201, 10101, 2);
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (201, 10102, -2);
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (201, 10103, -4);
+
+
+INSERT INTO #PFX#bin5_matches (code, ttok, tidx, mazzo_next, mult_next) VALUES (101, 'normalize_points2', 2, 1, 0) RETURNING *;
+INSERT INTO #PFX#bin5_table_orders (mcode, ucode, pos) VALUES (101, 10101, 0);
+INSERT INTO #PFX#bin5_table_orders (mcode, ucode, pos) VALUES (101, 10102, 1);
+INSERT INTO #PFX#bin5_table_orders (mcode, ucode, pos) VALUES (101, 10103, 2);
+INSERT INTO #PFX#bin5_games (code, mcode, tstamp, act, asta_pnt, pnt, asta_win, friend, mazzo, mult)
+ VALUES (202, 101, to_timestamp(#NOW# - 800), 2, 60, 0, -1, -1, 0, 0) RETURNING *;
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (202, 10101, 0);
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (202, 10102, 0);
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (202, 10103, 0);
+UPDATE #PFX#bin5_matches SET (mazzo_next, mult_next) = (2, 0) WHERE code = 100;
+INSERT INTO #PFX#bin5_games (code, mcode, tstamp, act, asta_pnt, pnt, asta_win, friend, mazzo, mult)
+ VALUES (203, 101, to_timestamp(#NOW# - 700), 0, 81, 37, 2, 1, 1, 1) RETURNING *;
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (203, 10101, 6);
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (203, 10102, -6);
+INSERT INTO #PFX#bin5_points (gcode, ucode, pts) VALUES (203, 10103, -12);
+
+
+
--- /dev/null
+--
+-- points normalization to be able to calculate placing
+--
+UPDATE #PFX#bin5_points AS p SET pts = pts / (2 ^ g.mult) FROM #PFX#bin5_games AS g WHERE g.code = p.gcode; --MF
+UPDATE #PFX#bin5_points AS p SET pts = pts * (2 ^ g.mult) FROM #PFX#bin5_games AS g WHERE g.code = p.gcode; --MB
--- /dev/null
+--
+-- Populate users db.
+--
+
+-- macro for user_flag bit-field
+-- define(USER_FLAG_TY_ALL, 0x000f0000); // done
+-- define(USER_FLAG_TY_NORM, 0x00010000); // done
+-- define(USER_FLAG_TY_SUPER, 0x00020000); // done
+-- define(USER_FLAG_TY_FIRONLY, 0x00200000); // done
+-- define(USER_FLAG_TY_SUSPEND, 0x00400000); // done
+-- define(USER_FLAG_TY_DISABLE, 0x00800000); // done
+
+DELETE FROM #PFX#users WHERE code = 10101;
+INSERT INTO #PFX#users (code, login, pass, email, type, guar_code) VALUES (10101, 'uno', md5('one'), 'uno@pluto.com', CAST (X'00020000' as integer), 10101);
+DELETE FROM #PFX#users WHERE code = 10102;
+INSERT INTO #PFX#users (code, login, pass, email, type, guar_code) VALUES (10102, 'due', md5('two'), 'due@pluto.com', CAST (X'00010000' as integer), 10101);
+DELETE FROM #PFX#users WHERE code = 10103;
+INSERT INTO #PFX#users (code, login, pass, email, type, guar_code) VALUES (10103, 'tre', md5('thr'), 'tre@pluto.com', CAST (X'00010000' as integer), 10102);
+DELETE FROM #PFX#users WHERE code = 10104;
+INSERT INTO #PFX#users (code, login, pass, email, type, guar_code) VALUES (10104, 'qua', md5('for'), 'qua@pluto.com', CAST (X'00010000' as integer), 10102);
+DELETE FROM #PFX#users WHERE code = 10105;
+INSERT INTO #PFX#users (code, login, pass, email, type, guar_code) VALUES (10105, 'cin', md5('fiv'), 'cin@pluto.com', CAST (X'00010000' as integer), 10103);
+DELETE FROM #PFX#users WHERE code = 10106;
+INSERT INTO #PFX#users (code, login, pass, email, type, guar_code) VALUES (10106, 'sei', md5('six'), 'sei@pluto.com', CAST (X'00210000' as integer), 10103);
+ALTER SEQUENCE #PFX#users_code_seq RESTART WITH 10107;
+++ /dev/null
---
--- Populate users db.
---
-
--- macro for user_flag bit-field
--- define(USER_FLAG_TY_ALL, 0x000f0000); // done
--- define(USER_FLAG_TY_NORM, 0x00010000); // done
--- define(USER_FLAG_TY_SUPER, 0x00020000); // done
--- define(USER_FLAG_TY_FIRONLY, 0x00200000); // done
--- define(USER_FLAG_TY_SUSPEND, 0x00400000); // done
--- define(USER_FLAG_TY_DISABLE, 0x00800000); // done
-
-DELETE FROM #PFX#users WHERE code = 10101;
-INSERT INTO #PFX#users (code, login, pass, email, type) VALUES (10101, 'uno', md5('one'), 'uno@pluto.com', CAST (X'00020000' as integer));
-DELETE FROM #PFX#users WHERE code = 10102;
-INSERT INTO #PFX#users (code, login, pass, email, type) VALUES (10102, 'due', md5('two'), 'due@pluto.com', CAST (X'00010000' as integer));
-DELETE FROM #PFX#users WHERE code = 10103;
-INSERT INTO #PFX#users (code, login, pass, email, type) VALUES (10103, 'tre', md5('thr'), 'tre@pluto.com', CAST (X'00010000' as integer));
-DELETE FROM #PFX#users WHERE code = 10104;
-INSERT INTO #PFX#users (code, login, pass, email, type) VALUES (10104, 'qua', md5('for'), 'qua@pluto.com', CAST (X'00010000' as integer));
-DELETE FROM #PFX#users WHERE code = 10105;
-INSERT INTO #PFX#users (code, login, pass, email, type) VALUES (10105, 'cin', md5('fiv'), 'cin@pluto.com', CAST (X'00010000' as integer));
-DELETE FROM #PFX#users WHERE code = 10106;
-INSERT INTO #PFX#users (code, login, pass, email, type) VALUES (10106, 'sei', md5('six'), 'sei@pluto.com', CAST (X'00210000' as integer));
-ALTER SEQUENCE #PFX#users_code_seq RESTART WITH 10107;
$G_lng = langtolng($G_lang);
$G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
-$G_brisk_version = "4.12.4";
+$G_brisk_version = "4.13.0";
/* MLANG: ALL THE INFO STRINGS IN brisk.phh */
-$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: potenziato il sistema di debug.',
+$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: nuovo sistema per calcolare le classifiche, corretto bug nel comando cont',
'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
- 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: empowered logging system.',
+ 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: new placements calculation system, cont command fixed.',
'If you want to subscribe our <a target="_blank" href="ml-briscola+subscribe@milug.org">Mailing List</a>, click it!' ) );
$G_room_help = array( 'it' => '
function match_continue($match_code, $table, $tidx)
{
GLOBAL $G_dbpfx;
+ $sql_ttok = escsql($table->table_token);
if (($users = $this->users_get($match_code, FALSE /*without minmaxidx*/, TRUE /*new game*/)) == FALSE) {
log_crit(sprintf("%s::%s: retrieve users fails", __CLASS__, __FUNCTION__));
$num_obj = pg_fetch_object($num_pg, 0);
$table->points_n = $num_obj->points_n;
- $tot_sql = sprintf("SELECT sum(p.pts) AS pts
+ // TAG: POINTS_MANAGEMENT
+ $tot_sql = sprintf("SELECT sum(p.pts * (2^g.mult)) AS pts
FROM %sbin5_games AS g, %sbin5_points AS p, %susers AS u,
%sbin5_table_orders AS o
WHERE g.mcode = %d AND g.code = p.gcode AND p.ucode = u.code
$u = 0;
foreach ($users as $user) {
- $pts_sql = sprintf("SELECT p.pts AS pts
+ // TAG: POINTS_MANAGEMENT
+ $pts_sql = sprintf("SELECT p.pts AS pts, g.mult AS mult
FROM %sbin5_points as p, %sbin5_games as g
WHERE p.gcode = g.code AND g.mcode = %d AND p.ucode = %d
- ORDER BY g.code ASC
+ ORDER BY g.tstamp ASC
LIMIT %d OFFSET %d;",
$G_dbpfx, $G_dbpfx, $match_code, $user['code'],
MAX_POINTS,
log_crit(sprintf("%s::%s: number of points great than number of games", __CLASS__, __FUNCTION__));
return (FALSE);
}
+ // TAG: POINTS_MANAGEMENT
for ($i = 0 , $ct = $table->points_n - $pts_n; $ct < $table->points_n ; $ct++, $i++) {
$pts_obj = pg_fetch_object($pts_pg, $i);
- $table->points[$ct % MAX_POINTS][$u] = $pts_obj->pts;
+ $table->points[$ct % MAX_POINTS][$u] = $pts_obj->pts * pow(2, $pts_obj->mult);
}
$tot_obj = pg_fetch_object($tot_pg, $u);
$table->total[$u] = $tot_obj->pts;
$u++;
}
- $gam_sql = sprintf("SELECT * FROM %sbin5_games WHERE mcode = %d ORDER BY code DESC LIMIT 1;", $G_dbpfx, $match_code);
+ $gam_sql = sprintf("SELECT * FROM %sbin5_games WHERE mcode = %d ORDER BY tstamp DESC LIMIT 1;", $G_dbpfx, $match_code);
if (($gam_pg = $this->query($gam_sql)) == FALSE || pg_numrows($gam_pg) != 1) {
log_crit(sprintf("%s::%s: get last game fails", __CLASS__, __FUNCTION__));
return (FALSE);
$users[$gam_obj->friend]['login'] : ""),
$gam_obj->pnt, $gam_obj->asta_pnt);
+ // update matches with new ttok and table idx
+ $mtc_sql = sprintf("UPDATE %sbin5_matches SET (ttok, tidx) = ('%s', %d) WHERE code = %d RETURNING *;",
+ $G_dbpfx, $sql_ttok, $tidx, $match_code);
+ if (($mtc_pg = $this->query($mtc_sql)) == FALSE || pg_numrows($mtc_pg) != 1) {
+ log_crit(sprintf("%s::%s: update matches table failed", __CLASS__, __FUNCTION__));
+ return (FALSE);
+ }
+
return (TRUE);
}
function multer($is_new)
{
if ($is_new) {
- // return (pow(2, $this->mult) * $this->asta2mult($this->asta_pnt));
return (static::s_multer($this->mult, $this->asta_pnt));
}
else {
- // return (pow(2, $this->old_mult) * $this->asta2mult($this->old_asta_pnt));
return (static::s_multer($this->old_mult, $this->old_asta_pnt));
}
}
return (pow(2, $mult) * static::asta2mult($pnt));
}
+ static function s_point_calc($pnt_done, $mult, $pnt_req, $is_allpoints)
+ {
+ return ($pnt_done * static::s_multer($mult, $pnt_req) * ($is_allpoints ? 2 : 1));
+ }
+
// function bunch_create_old() function AND
// {
// $ret = array();
{
GLOBAL $G_all_points, $G_dbasetype;
- $pts = array();
+ $pnts_sav = array();
$this->old_act = $action;
if ($action == BIN5_RULES_ALLPASS) { // return TRUE if all correct
$this->old_pnt = 0;
$this->mult_inc(1);
for ($i = 0 ; $i < PLAYERS_N ; $i++) {
- $pts[$i] = 0;
+ $pnts_sav[$i] = 0;
}
$game_delta = 1;
$this->mult_inc(1);
for ($i = 0 ; $i < PLAYERS_N ; $i++) {
- $pts[$i] = 0;
+ $pnts_sav[$i] = 0;
}
// Non si cambia mazzo se si abbandona la partita
$this->points[$this->points_n % MAX_POINTS] = array();
for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
$this->points[$this->points_n % MAX_POINTS][$i] = 0;
- $pts[$i] = 0;
+ $pnts_sav[$i] = 0;
}
$this->points_n++;
$this->old_pnt = $pro;
$this->mult_inc(1);
- // return($pts);
break;
}
else
$sig = -1;
+ // TAG: POINTS_MANAGEMENT
$this->points[$this->points_n % MAX_POINTS] = array();
for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
if ($i == $this->asta_win)
- $pt = ($i == $this->friend ? 4 : 2);
+ $pnt = ($i == $this->friend ? 4 : 2);
else if ($i == $this->friend)
- $pt = 1;
+ $pnt = 1;
else
- $pt = -1;
+ $pnt = -1;
- log_wr(sprintf("PRO: pt[%d][%d] = %d", $this->points_n % MAX_POINTS, $i, $pt));
+ log_wr(sprintf("PRO: pt[%d][%d] = %d", $this->points_n % MAX_POINTS, $i, $pnt));
- $pt = $pt * $sig * $this->multer(TRUE) * ($pro == 120 ? 2 : 1);
+ $pnt_sav = static::s_point_calc($pnt * $sig, 0, $this->asta_pnt, ($pro == 120));
+ $pnt_tab = static::s_point_calc($pnt * $sig, $this->mult, $this->asta_pnt, ($pro == 120));
- log_wr(sprintf("PRO:[%d][%d][%d]", $sig, $this->multer(TRUE), ($pro == 120 ? 2 : 1)));
-
- $this->points[$this->points_n % MAX_POINTS][$i] = $pt;
- $this->total[$i] += $pt;
- $pts[$i] = $pt;
+ $this->points[$this->points_n % MAX_POINTS][$i] = $pnt_tab;
+ $this->total[$i] += $pnt_tab;
+ $pnts_sav[$i] = $pnt_sav;
}
$this->points_n++;
$this->old_pnt = $pro;
$this->old_asta_win = $this->asta_win;
$this->mult_set(0);
-
- // return($pts);
} while (0);
$game_delta = 1;
}
$ucodes[$i] = $user_cur->code_get();
/* pro log */
- $plist .= '|'.xcapelt($user_cur->name).'|'.$pts[$i];
+ $plist .= '|'.xcapelt($user_cur->name).'|'.$pnts_sav[$i];
$codes .= '|'.xcapelt($user_cur->code_get());
}
$plist .= $codes;
require_once("../Obj/dbase_".$G_dbasetype.".phh");
if (($bdb = BriskDB::create()) != FALSE) {
- $bdb->bin5_points_save($curtime, $this, $user->table_orig, $action, $ucodes, $pts);
+ $bdb->bin5_points_save($curtime, $this, $user->table_orig, $action, $ucodes, $pnts_sav);
unset($bdb);
}
else {
$ret = "";
$user = $bri->user[$table->player[$table_pos]];
+ // TAG: POINTS_MANAGEMENT
$pnt_min = $table->points_n - MAX_POINTS < 0 ? 0 : $table->points_n - MAX_POINTS;
$noty = sprintf('<table class=\"points\"><tr><th></th>');
define('TOP_NUM', 10);
define('TRI_LIMIT', (90 * 24 * 60 * 60));
-define('TRI_MIN_GAMES', 70);
+if (BIN5_PLAYERS_N != 5)
+ define('TRI_MIN_GAMES', 0);
+else
+ define('TRI_MIN_GAMES', 70);
define('TRI_MAX_GAMES', 140);
define('MON_LIMIT', (30 * 24 * 60 * 60));
-define('MON_MIN_GAMES', 35);
+if (BIN5_PLAYERS_N != 5)
+ define('MON_MIN_GAMES', 0);
+else
+ define('MON_MIN_GAMES', 35);
define('MON_MAX_GAMES', 70);
define('WEE_LIMIT', (7 * 24 * 60 * 60));
-define('WEE_MIN_GAMES', 10);
+if (BIN5_PLAYERS_N != 5)
+ define('WEE_MIN_GAMES', 0);
+else
+ define('WEE_MIN_GAMES', 10);
define('WEE_MAX_GAMES', 35);
$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, 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;",
+ $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 ...
printf("[Tournament [%s]], number of matches: %d\n", $mlang_stat_day[$trn_obj->name][$G_lang], $tmt_n);
fprintf($fpexp, "<h3>%s</h3>", $mlang_stat_day[$trn_obj->name][$G_lang]);
+ // loop on matches
for ($m = 0 ; $m < $tmt_n ; $m++) {
// log_crit("stat-day: LOOP m");
fprintf($fpexp, "<br>");
$tmt_obj = pg_fetch_object($tmt_pg, $m);
+ // get users for the match m
if (($users = $bdb->users_get($tmt_obj->code, TRUE, ($tmt_obj->minus_one_is_old > -1))) == FALSE) {
log_crit(sprintf("stat_day: users_get failed %d", $tmt_obj->code));
break;
}
- $gam_sql = sprintf("SELECT g.* FROM %sbin5_tournaments as t, %sbin5_matches AS m, %sbin5_games AS g WHERE t.code = m.tcode AND m.code = g.mcode AND m.code = %d ORDER BY g.tstamp;",
+ $gam_sql = sprintf("
+SELECT g.* FROM %sbin5_tournaments AS t, %sbin5_matches AS m, %sbin5_games AS g
+ WHERE t.code = m.tcode AND m.code = g.mcode AND m.code = %d
+ ORDER BY g.tstamp;",
$G_dbpfx, $G_dbpfx, $G_dbpfx, $tmt_obj->code);
if (($gam_pg = pg_query($bdb->dbconn->db(), $gam_sql)) == FALSE ) {
log_crit("stat-day: gam_sql failed");
break;
}
+ // loop on users of the match m
for ($u = 0 ; $u < count($users) ; $u++) {
// log_crit("stat-day: LOOP u");
if ($u == 0) {
}
fprintf($fpexp, "<th>%s</th>", $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.code",
+ $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']);
fprintf($fpexp, "<%s class='%s'>%d</%s>",
($tmt_obj->minus_one_is_old == -1 ? "td" : "th"),
- $cla_nam, $pts,
+ $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) {
// LISTA DEI TOTALI
fprintf($fpexp, "<tr>");
for ($u = 0 ; $u < BIN5_PLAYERS_N ; $u++) {
+ // NOTE: this part must be revisited when we move to multiple game rules
+ // probably removing the sum and adding another nested iteration on games.
$tot_sql = sprintf("
-SELECT SUM(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 ( (u.type & (CAST (X'00ff0000' as integer))) <> (CAST (X'00800000' as integer)) ) AND m.code = %d AND u.code = %d", $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx,
+SELECT sum(p.pts * (2^g.mult)) 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 ( (u.type & (CAST (X'00ff0000' as integer))) <> (CAST (X'00800000' as integer)) )
+ AND m.code = %d AND u.code = %d",
+ $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx,
$tmt_obj->code, $users[$u]['code']);
if (($tot_pg = pg_query($bdb->dbconn->db(), $tot_sql)) == FALSE ) {
break;
return ($ret);
}
-// echo "QUIr\n";
-// exit(123);
function main()
{
GLOBAL $G_lang, $G_dbasetype, $G_alarm_passwd, $pazz, $from, $to;
$old_score = array( 1000000000, 1000000000);
$old_gam = array( -1, -1);
$rank = array( 0, 0);
-
+
+ // 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
WHERE 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
+ 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,
count(p.pts) DESC",
$ctime = time();
- $curtime = ((int)($ctime / (24 * 3600))) * 24 * 3600 - (((int)substr(date("O", $ctime), 0, -2)) * 3600);
+ if (BIN5_PLAYERS_N != 5)
+ $curtime = $ctime;
+ else
+ $curtime = ((int)($ctime / (24 * 3600))) * 24 * 3600 - (((int)substr(date("O", $ctime), 0, -2)) * 3600);
if ($ret = $fun_name($curtime))
echo "Success.<br>\n";
else