--- /dev/null
+== rende la view dei punteggi ==
+select m.ttok, m.tidx, g.code, g.tstamp, p.pts, u.login from bsk_bin5_points as p, bsk_bin5_games as g, bsk_bin5_matches as m, bsk_users as u where p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND g.tstamp > '2010-10-01 00:00:00' ORDER BY g.tstamp;
+
+
+== rende somma punteggi da una certa data ==
+select sum(p.pts), u.login from bsk_bin5_points as p, bsk_bin5_games as g, bsk_bin5_matches as m, bsk_users as u where p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND g.tstamp > '2010-10-01 00:00:00' GROUP BY (u.login) ORDER BY sum(p.pts);
+
+== vicini al conteggio ==
+select (sum(p.pts) * 100 ) / count(p.pts), u.login from bsk_bin5_points as p, bsk_bin5_games as g, bsk_bin5_matches as m, bsk_users as u where p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND g.tstamp > '2010-12-01 00:00:00' GROUP BY (u.login) ORDER BY (sum(p.pts) * 100 ) / count(p.pts);
+
+
+== conteggio esatto ==
+select (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts)), u.login from bsk_bin5_points as p, bsk_bin5_games as g, bsk_bin5_matches as m, bsk_users as u where p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND g.tstamp > '2010-10-01 00:00:00' GROUP BY (u.login) ORDER BY (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts));
+
+== conteggio ancora piĆ¹ esatto ==
+select (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts)), count(p.pts), u.login from bsk_bin5_points as p, bsk_bin5_games as g, bsk_bin5_matches as m, bsk_users as u where p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND g.tstamp > '2010-10-01 00:00:00' GROUP BY (u.login) ORDER BY (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts)) DESC, count(p.pts) DESC
+++ /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_SUSPEND, 0x00400000); // done
--- define(USER_FLAG_TY_DISABLE, 0x00800000); // done
-
-INSERT INTO #PFX#users VALUES (1, 'uno', md5('one'), 'uno@pluto.com', CAST (X'00020000' as integer));
-INSERT INTO #PFX#users VALUES (2, 'due', md5('two'), 'due@pluto.com', CAST (X'00010000' as integer));
-INSERT INTO #PFX#users VALUES (3, 'tre', md5('thr'), 'tre@pluto.com', CAST (X'00010000' as integer));
-INSERT INTO #PFX#users VALUES (4, 'qua', md5('for'), 'qua@pluto.com', CAST (X'00010000' as integer));
-INSERT INTO #PFX#users VALUES (5, 'cin', md5('fiv'), 'cin@pluto.com', CAST (X'00010000' as integer));
-
--- /dev/null
+--
+-- briskin5 (bin5) related tables
+--
+
+DROP TABLE #PFX#bin5_matches;
+CREATE TABLE #PFX#bin5_matches (
+ code SERIAL PRIMARY KEY,
+ ttok text UNIQUE, -- token associated to the match
+ tidx integer -- table index
+ );
+
+DROP TABLE #PFX#bin5_games;
+CREATE TABLE #PFX#bin5_games (
+ code SERIAL PRIMARY KEY,
+ mcode integer REFERENCES #PFX#bin5_matches (code) ON DELETE cascade ON UPDATE cascade,
+ tstamp timestamp -- end game time
+ );
+
+DROP TABLE #PFX#bin5_points;
+CREATE TABLE #PFX#bin5_points (
+ gcode integer REFERENCES #PFX#bin5_games (code) ON DELETE cascade ON UPDATE cascade,
+ ucode integer REFERENCES #PFX#users (code) ON DELETE cascade ON UPDATE cascade,
+ pts integer -- points
+ );
+
--- /dev/null
+--
+-- try to start with a single table for all placings
+--
+-- tri = 0 lo = 0
+-- mon = 2 hi = 1
+-- wee = 4
+--
+
+DROP TABLE #PFX#bin5_places_mtime;
+CREATE TABLE #PFX#bin5_places_mtime (
+ code int,
+ mtime timestamp
+);
+INSERT INTO #PFX#bin5_places_mtime (code, mtime) VALUES (0, now());
+
+DROP TABLE #PFX#bin5_places;
+CREATE TABLE #PFX#bin5_places (
+ type integer,
+ rank integer,
+ ucode integer REFERENCES #PFX#users (code) ON DELETE cascade ON UPDATE cascade,
+ login text,
+ pts integer,
+ games integer,
+ score float
+);
--- /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_SUSPEND, 0x00400000); // done
+-- define(USER_FLAG_TY_DISABLE, 0x00800000); // done
+
+INSERT INTO #PFX#users VALUES (1, 'uno', md5('one'), 'uno@pluto.com', CAST (X'00020000' as integer));
+INSERT INTO #PFX#users VALUES (2, 'due', md5('two'), 'due@pluto.com', CAST (X'00010000' as integer));
+INSERT INTO #PFX#users VALUES (3, 'tre', md5('thr'), 'tre@pluto.com', CAST (X'00010000' as integer));
+INSERT INTO #PFX#users VALUES (4, 'qua', md5('for'), 'qua@pluto.com', CAST (X'00010000' as integer));
+INSERT INTO #PFX#users VALUES (5, 'cin', md5('fiv'), 'cin@pluto.com', CAST (X'00010000' as integer));
+