From: Matteo Nastasi (mop) Date: Wed, 26 Feb 2014 16:56:12 +0000 (+0100) Subject: Merge branch 'master' into auto-maintenance X-Git-Tag: v4.14.0~21 X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=970b78cd7eaef333d5b7e250ebed183440c9453e;hp=43b825479e2c58fe49b714e8d09fbbf472b8e662;p=brisk.git Merge branch 'master' into auto-maintenance --- diff --git a/TODO.txt b/TODO.txt index 107969d..3d779e3 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,6 +3,13 @@ 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 diff --git a/doc/ARCHITECTURE.txt b/doc/ARCHITECTURE.txt index d074067..da2fc8f 100644 --- a/doc/ARCHITECTURE.txt +++ b/doc/ARCHITECTURE.txt @@ -2,6 +2,16 @@ Sparse documentation about Brisk. ==== 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 diff --git a/sql/builder.sh b/sql/builder.sh index da05960..4e144b9 100755 --- a/sql/builder.sh +++ b/sql/builder.sh @@ -3,11 +3,12 @@ # MATCH_DROP='^DROP.*([^-]...|.[^-]..|..[^M].|...[^F])$|^ALTER TABLE.* DROP .*([^-]...|.[^-]..|..[^M].|...[^F])$|^DELETE .*([^-]...|.[^-]..|..[^M].|...[^F])$|--MB$' +DATECUR="$(date +%s)" # functions usage () { echo " USAGE" - echo " ./builder [-d|--dryrun] [-a|--allfiles] [-s|--short] ..." + echo " ./builder [-d|--dryrun] [-a|-p|--allfiles|--devfiles] [-s|--short] ..." echo " ./builder <-h|--help|help>" echo " commands are:" echo " create" @@ -37,26 +38,34 @@ sqlexe () { 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" } # @@ -76,7 +85,10 @@ while [ $# -gt 0 ]; do } ;; -a|--allfiles) - ALL_FILES=y + TYPE_FILES=a + ;; + -p|--devfiles) + TYPE_FILES=d ;; -s|--short) SHORT=y @@ -123,13 +135,13 @@ case $CMD in 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 ;; @@ -158,10 +170,10 @@ case $CMD in ( 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 diff --git a/sql/sql.d/066-insert-unnorm-games.sql.test b/sql/sql.d/066-insert-unnorm-games.sql.test new file mode 100644 index 0000000..930815e --- /dev/null +++ b/sql/sql.d/066-insert-unnorm-games.sql.test @@ -0,0 +1,37 @@ +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); + + + diff --git a/sql/sql.d/068-points-normalization.sql b/sql/sql.d/068-points-normalization.sql new file mode 100644 index 0000000..18b4385 --- /dev/null +++ b/sql/sql.d/068-points-normalization.sql @@ -0,0 +1,5 @@ +-- +-- 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 diff --git a/sql/sql.d/100-anagr.sql.devel b/sql/sql.d/100-anagr.sql.devel new file mode 100644 index 0000000..6b3796a --- /dev/null +++ b/sql/sql.d/100-anagr.sql.devel @@ -0,0 +1,25 @@ +-- +-- 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; diff --git a/sql/sql.d/100-anagr.sql.noinsert b/sql/sql.d/100-anagr.sql.noinsert deleted file mode 100644 index f14a21e..0000000 --- a/sql/sql.d/100-anagr.sql.noinsert +++ /dev/null @@ -1,25 +0,0 @@ --- --- 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; diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index 1fbfa0a..e19b659 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -150,12 +150,12 @@ $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi', $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.'), NOVITA\': potenziato il sistema di debug.', +$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': nuovo sistema per calcolare le classifiche, corretto bug nel comando cont', 'Se vuoi iscriverti alla Mailing List, cliccala!' ), - 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NEWS: empowered logging system.', + 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NEWS: new placements calculation system, cont command fixed.', 'If you want to subscribe our Mailing List, click it!' ) ); $G_room_help = array( 'it' => ' diff --git a/web/Obj/dbase_pgsql.phh b/web/Obj/dbase_pgsql.phh index d5b2770..5f0511e 100644 --- a/web/Obj/dbase_pgsql.phh +++ b/web/Obj/dbase_pgsql.phh @@ -399,6 +399,7 @@ class BriskDB 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__)); @@ -413,7 +414,8 @@ class BriskDB $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 @@ -429,10 +431,11 @@ class BriskDB $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, @@ -449,9 +452,10 @@ class BriskDB 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; @@ -459,7 +463,7 @@ class BriskDB $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); @@ -473,6 +477,14 @@ class BriskDB $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); } diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index f51b303..eaa3096 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -339,11 +339,9 @@ class Bin5_table extends Table { 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)); } } @@ -353,6 +351,11 @@ class Bin5_table extends Table { 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(); @@ -509,7 +512,7 @@ class Bin5_table extends Table { { 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 @@ -517,7 +520,7 @@ class Bin5_table extends Table { $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; @@ -531,7 +534,7 @@ class Bin5_table extends Table { $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 @@ -563,13 +566,12 @@ class Bin5_table extends Table { $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; } @@ -578,31 +580,29 @@ class Bin5_table extends Table { 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; } @@ -621,7 +621,7 @@ class Bin5_table extends Table { $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; @@ -646,7 +646,7 @@ class Bin5_table extends Table { 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 { @@ -1841,6 +1841,7 @@ function show_table_info(&$bri, &$table, $table_pos) $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(''); diff --git a/web/briskin5/Obj/placing.phh b/web/briskin5/Obj/placing.phh index fd932b4..ad69d50 100644 --- a/web/briskin5/Obj/placing.phh +++ b/web/briskin5/Obj/placing.phh @@ -25,15 +25,24 @@ 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); diff --git a/web/briskin5/stat-day.php b/web/briskin5/stat-day.php index c8af36d..0359bfe 100644 --- a/web/briskin5/stat-day.php +++ b/web/briskin5/stat-day.php @@ -267,11 +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, 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 ... @@ -295,23 +302,29 @@ 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

", $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, "
"); $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) { @@ -320,7 +333,11 @@ function main_pgsql($from, $to) } fprintf($fpexp, "", $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']); @@ -405,7 +422,7 @@ function main_pgsql($from, $to) fprintf($fpexp, "<%s class='%s'>%d", ($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) { @@ -426,9 +443,15 @@ function main_pgsql($from, $to) // LISTA DEI TOTALI fprintf($fpexp, ""); 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; @@ -463,8 +486,6 @@ WHERE m.code = g.mcode AND g.code = p.gcode AND u.code = p.ucode AND ( (u.type & return ($ret); } -// echo "QUIr\n"; -// exit(123); function main() { GLOBAL $G_lang, $G_dbasetype, $G_alarm_passwd, $pazz, $from, $to; diff --git a/web/briskin5/statadm.php b/web/briskin5/statadm.php index f1c7bfc..652a11d 100644 --- a/web/briskin5/statadm.php +++ b/web/briskin5/statadm.php @@ -335,13 +335,15 @@ function main_pgsql($curtime) $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", @@ -427,7 +429,10 @@ function main() $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.
\n"; else
%s