2 # -*- coding: utf-8 -*-
3 """Returns a dict of SQL statements used in fpdb.
5 # Copyright 2008-2011, Ray E. Barker
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # NOTES: The sql statements use the placeholder %s for bind variables
22 # which is then replaced by ? for sqlite. Comments can be included
23 # within sql statements using C style /* ... */ comments, BUT
24 # THE COMMENTS MUST NOT INCLUDE %s OR ?.
26 ########################################################################
28 # Standard Library modules
33 # FreePokerTools modules
37 def __init__(self
, game
= 'holdem', db_server
= 'mysql'):
39 ###############################################################################3
40 # Support for the Free Poker DataBase = fpdb http://fpdb.sourceforge.net/
43 ################################
45 ################################
46 if db_server
== 'mysql':
47 self
.query
['list_tables'] = """SHOW TABLES"""
48 elif db_server
== 'postgresql':
49 self
.query
['list_tables'] = """SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"""
50 elif db_server
== 'sqlite':
51 self
.query
['list_tables'] = """SELECT name FROM sqlite_master
55 ################################
57 ################################
58 if db_server
== 'mysql':
59 self
.query
['list_indexes'] = """SHOW INDEXES"""
60 elif db_server
== 'postgresql':
61 self
.query
['list_indexes'] = """SELECT tablename, indexname FROM PG_INDEXES"""
62 elif db_server
== 'sqlite':
63 self
.query
['list_indexes'] = """SELECT name FROM sqlite_master
67 ##################################################################
68 # Drop Tables - MySQL, PostgreSQL and SQLite all share same syntax
69 ##################################################################
71 self
.query
['drop_table'] = """DROP TABLE IF EXISTS """
74 ##################################################################
75 # Set transaction isolation level
76 ##################################################################
78 if db_server
== 'mysql' or db_server
== 'postgresql':
79 self
.query
['set tx level'] = """SET SESSION TRANSACTION
80 ISOLATION LEVEL READ COMMITTED"""
81 elif db_server
== 'sqlite':
82 self
.query
['set tx level'] = """ """
85 ################################
87 ################################
89 self
.query
['getSiteId'] = """SELECT id from Sites where name = %s"""
91 self
.query
['getGames'] = """SELECT DISTINCT category from Gametypes"""
93 self
.query
['getCurrencies'] = """SELECT DISTINCT currency from Gametypes ORDER BY currency"""
95 self
.query
['getLimits'] = """SELECT DISTINCT bigBlind from Gametypes ORDER by bigBlind DESC"""
97 self
.query
['getTourneyTypesIds'] = "SELECT id FROM TourneyTypes"
99 ################################
101 ################################
102 if db_server
== 'mysql':
103 self
.query
['createSettingsTable'] = """CREATE TABLE Settings (
104 version SMALLINT NOT NULL)
106 elif db_server
== 'postgresql':
107 self
.query
['createSettingsTable'] = """CREATE TABLE Settings (version SMALLINT NOT NULL)"""
109 elif db_server
== 'sqlite':
110 self
.query
['createSettingsTable'] = """CREATE TABLE Settings
111 (version INTEGER NOT NULL) """
113 ################################
115 ################################
116 if db_server
== 'mysql':
117 self
.query
['createLockTable'] = """CREATE TABLE InsertLock (
118 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
119 locked BOOLEAN NOT NULL DEFAULT FALSE)
122 ################################
123 # Create RawHands (this table is all but identical with RawTourneys)
124 ################################
125 if db_server
== 'mysql':
126 self
.query
['createRawHands'] = """CREATE TABLE RawHands (
127 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
128 handId BIGINT NOT NULL,
129 rawHand TEXT NOT NULL,
130 complain BOOLEAN NOT NULL DEFAULT FALSE)
132 elif db_server
== 'postgresql':
133 self
.query
['createRawHands'] = """CREATE TABLE RawHands (
134 id BIGSERIAL, PRIMARY KEY (id),
135 handId BIGINT NOT NULL,
136 rawHand TEXT NOT NULL,
137 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
138 elif db_server
== 'sqlite':
139 self
.query
['createRawHands'] = """CREATE TABLE RawHands (
140 id INTEGER PRIMARY KEY,
141 handId BIGINT NOT NULL,
142 rawHand TEXT NOT NULL,
143 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
145 ################################
146 # Create RawTourneys (this table is all but identical with RawHands)
147 ################################
148 if db_server
== 'mysql':
149 self
.query
['createRawTourneys'] = """CREATE TABLE RawTourneys (
150 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
151 tourneyId BIGINT NOT NULL,
152 rawTourney TEXT NOT NULL,
153 complain BOOLEAN NOT NULL DEFAULT FALSE)
155 elif db_server
== 'postgresql':
156 self
.query
['createRawTourneys'] = """CREATE TABLE RawTourneys (
157 id BIGSERIAL, PRIMARY KEY (id),
158 tourneyId BIGINT NOT NULL,
159 rawTourney TEXT NOT NULL,
160 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
161 elif db_server
== 'sqlite':
162 self
.query
['createRawTourneys'] = """CREATE TABLE RawTourneys (
163 id INTEGER PRIMARY KEY,
164 tourneyId BIGINT NOT NULL,
165 rawTourney TEXT NOT NULL,
166 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
168 ################################
170 ################################
172 if db_server
== 'mysql':
173 self
.query
['createActionsTable'] = """CREATE TABLE Actions (
174 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
175 name varchar(32) NOT NULL,
176 code char(4) NOT NULL)
178 elif db_server
== 'postgresql':
179 self
.query
['createActionsTable'] = """CREATE TABLE Actions (
180 id SERIAL, PRIMARY KEY (id),
183 elif db_server
== 'sqlite':
184 self
.query
['createActionsTable'] = """CREATE TABLE Actions (
185 id INTEGER PRIMARY KEY,
187 code TEXT NOT NULL)"""
189 ################################
191 ################################
193 if db_server
== 'mysql':
194 self
.query
['createSitesTable'] = """CREATE TABLE Sites (
195 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
196 name varchar(32) NOT NULL,
197 code char(2) NOT NULL)
199 elif db_server
== 'postgresql':
200 self
.query
['createSitesTable'] = """CREATE TABLE Sites (
201 id SERIAL, PRIMARY KEY (id),
204 elif db_server
== 'sqlite':
205 self
.query
['createSitesTable'] = """CREATE TABLE Sites (
206 id INTEGER PRIMARY KEY,
208 code TEXT NOT NULL)"""
210 ################################
212 ################################
214 if db_server
== 'mysql':
215 self
.query
['createBackingsTable'] = """CREATE TABLE Backings (
216 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
217 tourneysPlayersId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
218 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
219 buyInPercentage FLOAT UNSIGNED NOT NULL,
220 payOffPercentage FLOAT UNSIGNED NOT NULL) ENGINE=INNODB"""
221 elif db_server
== 'postgresql':
222 self
.query
['createBackingsTable'] = """CREATE TABLE Backings (
223 id BIGSERIAL, PRIMARY KEY (id),
224 tourneysPlayersId INT NOT NULL, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
225 playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
226 buyInPercentage FLOAT NOT NULL,
227 payOffPercentage FLOAT NOT NULL)"""
228 elif db_server
== 'sqlite':
229 self
.query
['createBackingsTable'] = """CREATE TABLE Backings (
230 id INTEGER PRIMARY KEY,
231 tourneysPlayersId INT NOT NULL,
232 playerId INT NOT NULL,
233 buyInPercentage REAL UNSIGNED NOT NULL,
234 payOffPercentage REAL UNSIGNED NOT NULL)"""
236 ################################
238 ################################
240 if db_server
== 'mysql':
241 self
.query
['createGametypesTable'] = """CREATE TABLE Gametypes (
242 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
243 siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
244 currency varchar(4) NOT NULL,
245 type char(4) NOT NULL,
246 base char(4) NOT NULL,
247 category varchar(9) NOT NULL,
248 limitType char(2) NOT NULL,
249 hiLo char(1) NOT NULL,
250 mix varchar(9) NOT NULL,
253 smallBet int NOT NULL,
255 maxSeats TINYINT NOT NULL,
258 elif db_server
== 'postgresql':
259 self
.query
['createGametypesTable'] = """CREATE TABLE Gametypes (
260 id SERIAL NOT NULL, PRIMARY KEY (id),
261 siteId INTEGER NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
262 currency varchar(4) NOT NULL,
263 type char(4) NOT NULL,
264 base char(4) NOT NULL,
265 category varchar(9) NOT NULL,
266 limitType char(2) NOT NULL,
267 hiLo char(1) NOT NULL,
268 mix char(9) NOT NULL,
271 smallBet int NOT NULL,
273 maxSeats SMALLINT NOT NULL,
274 ante INT NOT NULL)"""
275 elif db_server
== 'sqlite':
276 self
.query
['createGametypesTable'] = """CREATE TABLE Gametypes (
277 id INTEGER PRIMARY KEY NOT NULL,
278 siteId INTEGER NOT NULL,
279 currency TEXT NOT NULL,
282 category TEXT NOT NULL,
283 limitType TEXT NOT NULL,
288 smallBet INTEGER NOT NULL,
289 bigBet INTEGER NOT NULL,
290 maxSeats INT NOT NULL,
292 FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
295 ################################
297 ################################
299 if db_server
== 'mysql':
300 self
.query
['createPlayersTable'] = """CREATE TABLE Players (
301 id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
302 name VARCHAR(32) NOT NULL,
303 siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
307 elif db_server
== 'postgresql':
308 self
.query
['createPlayersTable'] = """CREATE TABLE Players (
309 id SERIAL, PRIMARY KEY (id),
311 siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id),
313 commentTs timestamp without time zone)"""
314 elif db_server
== 'sqlite':
315 self
.query
['createPlayersTable'] = """CREATE TABLE Players (
316 id INTEGER PRIMARY KEY,
321 FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
324 ################################
326 ################################
328 if db_server
== 'mysql':
329 self
.query
['createAutoratesTable'] = """CREATE TABLE Autorates (
330 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
331 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
332 gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
333 description varchar(50) NOT NULL,
334 shortDesc char(8) NOT NULL,
335 ratingTime DATETIME NOT NULL,
336 handCount int NOT NULL)
338 elif db_server
== 'postgresql':
339 self
.query
['createAutoratesTable'] = """CREATE TABLE Autorates (
340 id BIGSERIAL, PRIMARY KEY (id),
341 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
342 gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
343 description varchar(50),
345 ratingTime timestamp without time zone,
347 elif db_server
== 'sqlite':
348 self
.query
['createAutoratesTable'] = """CREATE TABLE Autorates (
349 id INTEGER PRIMARY KEY,
358 ################################
360 ################################
362 if db_server
== 'mysql':
363 self
.query
['createHandsTable'] = """CREATE TABLE Hands (
364 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
365 tableName VARCHAR(50) NOT NULL,
366 siteHandNo BIGINT NOT NULL,
367 tourneyId INT UNSIGNED,
368 gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
369 sessionId INT UNSIGNED,
370 gameSessionId INT UNSIGNED,
371 fileId INT(10) UNSIGNED NOT NULL, FOREIGN KEY (fileId) REFERENCES Files(id),
372 startTime DATETIME NOT NULL,
373 importTime DATETIME NOT NULL,
374 seats TINYINT NOT NULL,
376 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
383 playersVpi SMALLINT NOT NULL, /* num of players vpi */
384 playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */
385 playersAtStreet2 SMALLINT NOT NULL,
386 playersAtStreet3 SMALLINT NOT NULL,
387 playersAtStreet4 SMALLINT NOT NULL,
388 playersAtShowdown SMALLINT NOT NULL,
389 street0Raises TINYINT NOT NULL, /* num small bets paid to see flop/street4, including blind */
390 street1Raises TINYINT NOT NULL, /* num small bets paid to see turn/street5 */
391 street2Raises TINYINT NOT NULL, /* num big bets paid to see river/street6 */
392 street3Raises TINYINT NOT NULL, /* num big bets paid to see sd/street7 */
393 street4Raises TINYINT NOT NULL, /* num big bets paid to see showdown */
394 street1Pot INT, /* pot size at flop/street4 */
395 street2Pot INT, /* pot size at turn/street5 */
396 street3Pot INT, /* pot size at river/street6 */
397 street4Pot INT, /* pot size at sd/street7 */
398 showdownPot INT, /* pot size at sd/street7 */
402 elif db_server
== 'postgresql':
403 self
.query
['createHandsTable'] = """CREATE TABLE Hands (
404 id BIGSERIAL, PRIMARY KEY (id),
405 tableName VARCHAR(50) NOT NULL,
406 siteHandNo BIGINT NOT NULL,
408 gametypeId INT NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
411 fileId BIGINT NOT NULL, FOREIGN KEY (fileId) REFERENCES Files(id),
412 startTime timestamp without time zone NOT NULL,
413 importTime timestamp without time zone NOT NULL,
414 seats SMALLINT NOT NULL,
416 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
423 playersVpi SMALLINT NOT NULL, /* num of players vpi */
424 playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */
425 playersAtStreet2 SMALLINT NOT NULL,
426 playersAtStreet3 SMALLINT NOT NULL,
427 playersAtStreet4 SMALLINT NOT NULL,
428 playersAtShowdown SMALLINT NOT NULL,
429 street0Raises SMALLINT NOT NULL, /* num small bets paid to see flop/street4, including blind */
430 street1Raises SMALLINT NOT NULL, /* num small bets paid to see turn/street5 */
431 street2Raises SMALLINT NOT NULL, /* num big bets paid to see river/street6 */
432 street3Raises SMALLINT NOT NULL, /* num big bets paid to see sd/street7 */
433 street4Raises SMALLINT NOT NULL, /* num big bets paid to see showdown */
434 street1Pot INT, /* pot size at flop/street4 */
435 street2Pot INT, /* pot size at turn/street5 */
436 street3Pot INT, /* pot size at river/street6 */
437 street4Pot INT, /* pot size at sd/street7 */
438 showdownPot INT, /* pot size at sd/street7 */
440 commentTs timestamp without time zone)"""
441 elif db_server
== 'sqlite':
442 self
.query
['createHandsTable'] = """CREATE TABLE Hands (
443 id INTEGER PRIMARY KEY,
444 tableName TEXT(50) NOT NULL,
445 siteHandNo INT NOT NULL,
447 gametypeId INT NOT NULL,
451 startTime REAL NOT NULL,
452 importTime REAL NOT NULL,
455 boardcard1 INT, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
462 playersVpi INT NOT NULL, /* num of players vpi */
463 playersAtStreet1 INT NOT NULL, /* num of players seeing flop/street4 */
464 playersAtStreet2 INT NOT NULL,
465 playersAtStreet3 INT NOT NULL,
466 playersAtStreet4 INT NOT NULL,
467 playersAtShowdown INT NOT NULL,
468 street0Raises INT NOT NULL, /* num small bets paid to see flop/street4, including blind */
469 street1Raises INT NOT NULL, /* num small bets paid to see turn/street5 */
470 street2Raises INT NOT NULL, /* num big bets paid to see river/street6 */
471 street3Raises INT NOT NULL, /* num big bets paid to see sd/street7 */
472 street4Raises INT NOT NULL, /* num big bets paid to see showdown */
473 street1Pot INT, /* pot size at flop/street4 */
474 street2Pot INT, /* pot size at turn/street5 */
475 street3Pot INT, /* pot size at river/street6 */
476 street4Pot INT, /* pot size at sd/street7 */
477 showdownPot INT, /* pot size at sd/street7 */
481 ################################
483 ################################
485 if db_server
== 'mysql':
486 self
.query
['createBoardsTable'] = """CREATE TABLE Boards (
487 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
488 handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
490 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
496 elif db_server
== 'postgresql':
497 self
.query
['createBoardsTable'] = """CREATE TABLE Boards (
498 id BIGSERIAL, PRIMARY KEY (id),
499 handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
501 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
505 boardcard5 smallint)"""
506 elif db_server
== 'sqlite':
507 self
.query
['createBoardsTable'] = """CREATE TABLE Boards (
508 id INTEGER PRIMARY KEY,
511 boardcard1 INT, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
518 ################################
519 # Create TourneyTypes
520 ################################
522 if db_server
== 'mysql':
523 self
.query
['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
524 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
525 siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
529 category varchar(9) NOT NULL,
530 limitType char(2) NOT NULL,
548 doubleOrNothing BOOLEAN,
551 addedCurrency VARCHAR(4))
553 elif db_server
== 'postgresql':
554 self
.query
['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
555 id SERIAL, PRIMARY KEY (id),
556 siteId INT NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
579 doubleOrNothing BOOLEAN,
582 addedCurrency VARCHAR(4))"""
583 elif db_server
== 'sqlite':
584 self
.query
['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
585 id INTEGER PRIMARY KEY,
609 doubleOrNothing BOOLEAN,
612 addedCurrency VARCHAR(4))"""
614 ################################
616 ################################
618 if db_server
== 'mysql':
619 self
.query
['createTourneysTable'] = """CREATE TABLE Tourneys (
620 id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
621 tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
622 siteTourneyNo BIGINT NOT NULL,
625 startTime DATETIME NOT NULL,
627 tourneyName varchar(40),
628 matrixIdProcessed TINYINT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
634 elif db_server
== 'postgresql':
635 self
.query
['createTourneysTable'] = """CREATE TABLE Tourneys (
636 id SERIAL, PRIMARY KEY (id),
637 tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
638 siteTourneyNo BIGINT,
641 startTime timestamp without time zone,
642 endTime timestamp without time zone,
643 tourneyName varchar(40),
644 matrixIdProcessed SMALLINT DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
648 commentTs timestamp without time zone)"""
649 elif db_server
== 'sqlite':
650 self
.query
['createTourneysTable'] = """CREATE TABLE Tourneys (
651 id INTEGER PRIMARY KEY,
659 matrixIdProcessed INT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
664 ################################
665 # Create HandsPlayers
666 ################################
668 if db_server
== 'mysql':
669 self
.query
['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
670 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
671 handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
672 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
673 startCash INT NOT NULL,
675 seatNo SMALLINT NOT NULL,
676 sitout BOOLEAN NOT NULL,
677 wentAllInOnStreet SMALLINT,
679 card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
680 card2 smallint NOT NULL,
686 card8 smallint, /* cards 8-20 for draw hands */
702 winnings int NOT NULL,
707 tourneysPlayersId BIGINT UNSIGNED, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
709 wonWhenSeenStreet1 FLOAT,
710 wonWhenSeenStreet2 FLOAT,
711 wonWhenSeenStreet3 FLOAT,
712 wonWhenSeenStreet4 FLOAT,
717 street0_3BChance BOOLEAN,
718 street0_3BDone BOOLEAN,
719 street0_4BChance BOOLEAN,
720 street0_C4BChance BOOLEAN,
721 street0_4BDone BOOLEAN,
722 street0_C4BDone BOOLEAN,
723 street0_FoldTo3BChance BOOLEAN,
724 street0_FoldTo3BDone BOOLEAN,
725 street0_FoldTo4BChance BOOLEAN,
726 street0_FoldTo4BDone BOOLEAN,
727 street0_SqueezeChance BOOLEAN,
728 street0_SqueezeDone BOOLEAN,
730 raiseToStealChance BOOLEAN,
731 raiseToStealDone BOOLEAN,
732 success_Steal BOOLEAN,
746 otherRaisedStreet0 BOOLEAN,
747 otherRaisedStreet1 BOOLEAN,
748 otherRaisedStreet2 BOOLEAN,
749 otherRaisedStreet3 BOOLEAN,
750 otherRaisedStreet4 BOOLEAN,
751 foldToOtherRaisedStreet0 BOOLEAN,
752 foldToOtherRaisedStreet1 BOOLEAN,
753 foldToOtherRaisedStreet2 BOOLEAN,
754 foldToOtherRaisedStreet3 BOOLEAN,
755 foldToOtherRaisedStreet4 BOOLEAN,
757 raiseFirstInChance BOOLEAN,
758 raisedFirstIn BOOLEAN,
759 foldBbToStealChance BOOLEAN,
760 foldedBbToSteal BOOLEAN,
761 foldSbToStealChance BOOLEAN,
762 foldedSbToSteal BOOLEAN,
764 street1CBChance BOOLEAN,
765 street1CBDone BOOLEAN,
766 street2CBChance BOOLEAN,
767 street2CBDone BOOLEAN,
768 street3CBChance BOOLEAN,
769 street3CBDone BOOLEAN,
770 street4CBChance BOOLEAN,
771 street4CBDone BOOLEAN,
773 foldToStreet1CBChance BOOLEAN,
774 foldToStreet1CBDone BOOLEAN,
775 foldToStreet2CBChance BOOLEAN,
776 foldToStreet2CBDone BOOLEAN,
777 foldToStreet3CBChance BOOLEAN,
778 foldToStreet3CBDone BOOLEAN,
779 foldToStreet4CBChance BOOLEAN,
780 foldToStreet4CBDone BOOLEAN,
782 street1CheckCallRaiseChance BOOLEAN,
783 street1CheckCallRaiseDone BOOLEAN,
784 street2CheckCallRaiseChance BOOLEAN,
785 street2CheckCallRaiseDone BOOLEAN,
786 street3CheckCallRaiseChance BOOLEAN,
787 street3CheckCallRaiseDone BOOLEAN,
788 street4CheckCallRaiseChance BOOLEAN,
789 street4CheckCallRaiseDone BOOLEAN,
791 street0Calls TINYINT,
792 street1Calls TINYINT,
793 street2Calls TINYINT,
794 street3Calls TINYINT,
795 street4Calls TINYINT,
801 street0Raises TINYINT,
802 street1Raises TINYINT,
803 street2Raises TINYINT,
804 street3Raises TINYINT,
805 street4Raises TINYINT,
807 actionString VARCHAR(15))
809 elif db_server
== 'postgresql':
810 self
.query
['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
811 id BIGSERIAL, PRIMARY KEY (id),
812 handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
813 playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
814 startCash INT NOT NULL,
816 seatNo SMALLINT NOT NULL,
817 sitout BOOLEAN NOT NULL,
818 wentAllInOnStreet SMALLINT,
820 card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
821 card2 smallint NOT NULL,
827 card8 smallint, /* cards 8-20 for draw hands */
843 winnings int NOT NULL,
847 commentTs timestamp without time zone,
848 tourneysPlayersId BIGINT, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
850 wonWhenSeenStreet1 FLOAT,
851 wonWhenSeenStreet2 FLOAT,
852 wonWhenSeenStreet3 FLOAT,
853 wonWhenSeenStreet4 FLOAT,
858 street0_3BChance BOOLEAN,
859 street0_3BDone BOOLEAN,
860 street0_4BChance BOOLEAN,
861 street0_4BDone BOOLEAN,
862 street0_C4BChance BOOLEAN,
863 street0_C4BDone BOOLEAN,
864 street0_FoldTo3BChance BOOLEAN,
865 street0_FoldTo3BDone BOOLEAN,
866 street0_FoldTo4BChance BOOLEAN,
867 street0_FoldTo4BDone BOOLEAN,
868 street0_SqueezeChance BOOLEAN,
869 street0_SqueezeDone BOOLEAN,
871 raiseToStealChance BOOLEAN,
872 raiseToStealDone BOOLEAN,
873 success_Steal BOOLEAN,
887 otherRaisedStreet0 BOOLEAN,
888 otherRaisedStreet1 BOOLEAN,
889 otherRaisedStreet2 BOOLEAN,
890 otherRaisedStreet3 BOOLEAN,
891 otherRaisedStreet4 BOOLEAN,
892 foldToOtherRaisedStreet0 BOOLEAN,
893 foldToOtherRaisedStreet1 BOOLEAN,
894 foldToOtherRaisedStreet2 BOOLEAN,
895 foldToOtherRaisedStreet3 BOOLEAN,
896 foldToOtherRaisedStreet4 BOOLEAN,
898 raiseFirstInChance BOOLEAN,
899 raisedFirstIn BOOLEAN,
900 foldBbToStealChance BOOLEAN,
901 foldedBbToSteal BOOLEAN,
902 foldSbToStealChance BOOLEAN,
903 foldedSbToSteal BOOLEAN,
905 street1CBChance BOOLEAN,
906 street1CBDone BOOLEAN,
907 street2CBChance BOOLEAN,
908 street2CBDone BOOLEAN,
909 street3CBChance BOOLEAN,
910 street3CBDone BOOLEAN,
911 street4CBChance BOOLEAN,
912 street4CBDone BOOLEAN,
914 foldToStreet1CBChance BOOLEAN,
915 foldToStreet1CBDone BOOLEAN,
916 foldToStreet2CBChance BOOLEAN,
917 foldToStreet2CBDone BOOLEAN,
918 foldToStreet3CBChance BOOLEAN,
919 foldToStreet3CBDone BOOLEAN,
920 foldToStreet4CBChance BOOLEAN,
921 foldToStreet4CBDone BOOLEAN,
923 street1CheckCallRaiseChance BOOLEAN,
924 street1CheckCallRaiseDone BOOLEAN,
925 street2CheckCallRaiseChance BOOLEAN,
926 street2CheckCallRaiseDone BOOLEAN,
927 street3CheckCallRaiseChance BOOLEAN,
928 street3CheckCallRaiseDone BOOLEAN,
929 street4CheckCallRaiseChance BOOLEAN,
930 street4CheckCallRaiseDone BOOLEAN,
932 street0Calls SMALLINT,
933 street1Calls SMALLINT,
934 street2Calls SMALLINT,
935 street3Calls SMALLINT,
936 street4Calls SMALLINT,
937 street0Bets SMALLINT,
938 street1Bets SMALLINT,
939 street2Bets SMALLINT,
940 street3Bets SMALLINT,
941 street4Bets SMALLINT,
942 street0Raises SMALLINT,
943 street1Raises SMALLINT,
944 street2Raises SMALLINT,
945 street3Raises SMALLINT,
946 street4Raises SMALLINT,
948 actionString VARCHAR(15))"""
949 elif db_server
== 'sqlite':
950 self
.query
['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
951 id INTEGER PRIMARY KEY,
953 playerId INT NOT NULL,
954 startCash INT NOT NULL,
957 sitout BOOLEAN NOT NULL,
958 wentAllInOnStreet INT,
960 card1 INT NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
967 card8 INT, /* cards 8-20 for draw hands */
983 winnings INT NOT NULL,
988 tourneysPlayersId INT,
990 wonWhenSeenStreet1 REAL,
991 wonWhenSeenStreet2 REAL,
992 wonWhenSeenStreet3 REAL,
993 wonWhenSeenStreet4 REAL,
998 street0_3BChance INT,
1000 street0_4BChance INT,
1002 street0_C4BChance INT,
1003 street0_C4BDone INT,
1004 street0_FoldTo3BChance INT,
1005 street0_FoldTo3BDone INT,
1006 street0_FoldTo4BChance INT,
1007 street0_FoldTo4BDone INT,
1008 street0_SqueezeChance INT,
1009 street0_SqueezeDone INT,
1011 raiseToStealChance INT,
1012 raiseToStealDone INT,
1027 otherRaisedStreet0 INT,
1028 otherRaisedStreet1 INT,
1029 otherRaisedStreet2 INT,
1030 otherRaisedStreet3 INT,
1031 otherRaisedStreet4 INT,
1032 foldToOtherRaisedStreet0 INT,
1033 foldToOtherRaisedStreet1 INT,
1034 foldToOtherRaisedStreet2 INT,
1035 foldToOtherRaisedStreet3 INT,
1036 foldToOtherRaisedStreet4 INT,
1038 raiseFirstInChance INT,
1040 foldBbToStealChance INT,
1041 foldedBbToSteal INT,
1042 foldSbToStealChance INT,
1043 foldedSbToSteal INT,
1045 street1CBChance INT,
1047 street2CBChance INT,
1049 street3CBChance INT,
1051 street4CBChance INT,
1054 foldToStreet1CBChance INT,
1055 foldToStreet1CBDone INT,
1056 foldToStreet2CBChance INT,
1057 foldToStreet2CBDone INT,
1058 foldToStreet3CBChance INT,
1059 foldToStreet3CBDone INT,
1060 foldToStreet4CBChance INT,
1061 foldToStreet4CBDone INT,
1063 street1CheckCallRaiseChance INT,
1064 street1CheckCallRaiseDone INT,
1065 street2CheckCallRaiseChance INT,
1066 street2CheckCallRaiseDone INT,
1067 street3CheckCallRaiseChance INT,
1068 street3CheckCallRaiseDone INT,
1069 street4CheckCallRaiseChance INT,
1070 street4CheckCallRaiseDone INT,
1087 actionString VARCHAR(15))
1091 ################################
1092 # Create TourneysPlayers
1093 ################################
1095 if db_server
== 'mysql':
1096 self
.query
['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
1097 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1098 tourneyId INT UNSIGNED NOT NULL, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
1099 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1102 winningsCurrency VARCHAR(4),
1109 elif db_server
== 'postgresql':
1110 self
.query
['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
1111 id BIGSERIAL, PRIMARY KEY (id),
1112 tourneyId INT, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
1113 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
1116 winningsCurrency VARCHAR(4),
1121 commentTs timestamp without time zone)"""
1122 elif db_server
== 'sqlite':
1123 self
.query
['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
1124 id INTEGER PRIMARY KEY,
1129 winningsCurrency VARCHAR(4),
1134 commentTs timestamp without time zone,
1135 FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
1136 FOREIGN KEY (playerId) REFERENCES Players(id)
1140 ################################
1141 # Create HandsActions
1142 ################################
1144 if db_server
== 'mysql':
1145 self
.query
['createHandsActionsTable'] = """CREATE TABLE HandsActions (
1146 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1147 handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
1148 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1149 street SMALLINT NOT NULL,
1150 actionNo SMALLINT NOT NULL,
1151 streetActionNo SMALLINT NOT NULL,
1152 actionId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (actionId) REFERENCES Actions(id),
1153 amount INT NOT NULL,
1154 raiseTo INT NOT NULL,
1155 amountCalled INT NOT NULL,
1156 numDiscarded SMALLINT NOT NULL,
1157 cardsDiscarded varchar(14),
1158 allIn BOOLEAN NOT NULL)
1160 elif db_server
== 'postgresql':
1161 self
.query
['createHandsActionsTable'] = """CREATE TABLE HandsActions (
1162 id BIGSERIAL, PRIMARY KEY (id),
1163 handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
1164 playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1167 streetActionNo SMALLINT,
1168 actionId SMALLINT, FOREIGN KEY (actionId) REFERENCES Actions(id),
1172 numDiscarded SMALLINT,
1173 cardsDiscarded varchar(14),
1175 elif db_server
== 'sqlite':
1176 self
.query
['createHandsActionsTable'] = """CREATE TABLE HandsActions (
1177 id INTEGER PRIMARY KEY,
1178 handId INT NOT NULL,
1179 playerId INT NOT NULL,
1182 streetActionNo SMALLINT,
1187 numDiscarded SMALLINT,
1188 cardsDiscarded TEXT,
1192 ################################
1194 ################################
1196 if db_server
== 'mysql':
1197 self
.query
['createFilesTable'] = """CREATE TABLE Files (
1198 id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1202 startTime DATETIME NOT NULL,
1203 lastUpdate DATETIME NOT NULL,
1213 elif db_server
== 'postgresql':
1214 self
.query
['createFilesTable'] = """CREATE TABLE Files (
1215 id BIGSERIAL, PRIMARY KEY (id),
1219 startTime timestamp without time zone NOT NULL,
1220 lastUpdate timestamp without time zone NOT NULL,
1221 endTime timestamp without time zone,
1228 finished BOOLEAN)"""
1229 elif db_server
== 'sqlite':
1230 self
.query
['createFilesTable'] = """CREATE TABLE Files (
1231 id INTEGER PRIMARY KEY,
1235 startTime timestamp NOT NULL,
1236 lastUpdate timestamp NOT NULL,
1247 ################################
1249 ################################
1251 if db_server
== 'mysql':
1252 self
.query
['createHudCacheTable'] = """CREATE TABLE HudCache (
1253 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1254 gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
1255 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1256 activeSeats SMALLINT NOT NULL,
1258 tourneyTypeId SMALLINT UNSIGNED, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
1259 styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1262 wonWhenSeenStreet1 FLOAT,
1263 wonWhenSeenStreet2 FLOAT,
1264 wonWhenSeenStreet3 FLOAT,
1265 wonWhenSeenStreet4 FLOAT,
1270 street0_3BChance INT,
1272 street0_4BChance INT,
1274 street0_C4BChance INT,
1275 street0_C4BDone INT,
1276 street0_FoldTo3BChance INT,
1277 street0_FoldTo3BDone INT,
1278 street0_FoldTo4BChance INT,
1279 street0_FoldTo4BDone INT,
1280 street0_SqueezeChance INT,
1281 street0_SqueezeDone INT,
1283 raiseToStealChance INT,
1284 raiseToStealDone INT,
1299 otherRaisedStreet0 INT,
1300 otherRaisedStreet1 INT,
1301 otherRaisedStreet2 INT,
1302 otherRaisedStreet3 INT,
1303 otherRaisedStreet4 INT,
1304 foldToOtherRaisedStreet0 INT,
1305 foldToOtherRaisedStreet1 INT,
1306 foldToOtherRaisedStreet2 INT,
1307 foldToOtherRaisedStreet3 INT,
1308 foldToOtherRaisedStreet4 INT,
1310 raiseFirstInChance INT,
1312 foldBbToStealChance INT,
1313 foldedBbToSteal INT,
1314 foldSbToStealChance INT,
1315 foldedSbToSteal INT,
1317 street1CBChance INT,
1319 street2CBChance INT,
1321 street3CBChance INT,
1323 street4CBChance INT,
1326 foldToStreet1CBChance INT,
1327 foldToStreet1CBDone INT,
1328 foldToStreet2CBChance INT,
1329 foldToStreet2CBDone INT,
1330 foldToStreet3CBChance INT,
1331 foldToStreet3CBDone INT,
1332 foldToStreet4CBChance INT,
1333 foldToStreet4CBDone INT,
1337 street1CheckCallRaiseChance INT,
1338 street1CheckCallRaiseDone INT,
1339 street2CheckCallRaiseChance INT,
1340 street2CheckCallRaiseDone INT,
1341 street3CheckCallRaiseChance INT,
1342 street3CheckCallRaiseDone INT,
1343 street4CheckCallRaiseChance INT,
1344 street4CheckCallRaiseDone INT,
1363 elif db_server
== 'postgresql':
1364 self
.query
['createHudCacheTable'] = """CREATE TABLE HudCache (
1365 id BIGSERIAL, PRIMARY KEY (id),
1366 gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
1367 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
1368 activeSeats SMALLINT,
1370 tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
1371 styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1374 wonWhenSeenStreet1 FLOAT,
1375 wonWhenSeenStreet2 FLOAT,
1376 wonWhenSeenStreet3 FLOAT,
1377 wonWhenSeenStreet4 FLOAT,
1382 street0_3BChance INT,
1384 street0_4BChance INT,
1386 street0_C4BChance INT,
1387 street0_C4BDone INT,
1388 street0_FoldTo3BChance INT,
1389 street0_FoldTo3BDone INT,
1390 street0_FoldTo4BChance INT,
1391 street0_FoldTo4BDone INT,
1392 street0_SqueezeChance INT,
1393 street0_SqueezeDone INT,
1395 raiseToStealChance INT,
1396 raiseToStealDone INT,
1409 otherRaisedStreet0 INT,
1410 otherRaisedStreet1 INT,
1411 otherRaisedStreet2 INT,
1412 otherRaisedStreet3 INT,
1413 otherRaisedStreet4 INT,
1414 foldToOtherRaisedStreet0 INT,
1415 foldToOtherRaisedStreet1 INT,
1416 foldToOtherRaisedStreet2 INT,
1417 foldToOtherRaisedStreet3 INT,
1418 foldToOtherRaisedStreet4 INT,
1420 raiseFirstInChance INT,
1422 foldBbToStealChance INT,
1423 foldedBbToSteal INT,
1424 foldSbToStealChance INT,
1425 foldedSbToSteal INT,
1427 street1CBChance INT,
1429 street2CBChance INT,
1431 street3CBChance INT,
1433 street4CBChance INT,
1436 foldToStreet1CBChance INT,
1437 foldToStreet1CBDone INT,
1438 foldToStreet2CBChance INT,
1439 foldToStreet2CBDone INT,
1440 foldToStreet3CBChance INT,
1441 foldToStreet3CBDone INT,
1442 foldToStreet4CBChance INT,
1443 foldToStreet4CBDone INT,
1447 street1CheckCallRaiseChance INT,
1448 street1CheckCallRaiseDone INT,
1449 street2CheckCallRaiseChance INT,
1450 street2CheckCallRaiseDone INT,
1451 street3CheckCallRaiseChance INT,
1452 street3CheckCallRaiseDone INT,
1453 street4CheckCallRaiseChance INT,
1454 street4CheckCallRaiseDone INT,
1472 elif db_server
== 'sqlite':
1473 self
.query
['createHudCacheTable'] = """CREATE TABLE HudCache (
1474 id INTEGER PRIMARY KEY,
1480 styleKey TEXT NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1483 wonWhenSeenStreet1 REAL,
1484 wonWhenSeenStreet2 REAL,
1485 wonWhenSeenStreet3 REAL,
1486 wonWhenSeenStreet4 REAL,
1491 street0_3BChance INT,
1493 street0_4BChance INT,
1495 street0_C4BChance INT,
1496 street0_C4BDone INT,
1497 street0_FoldTo3BChance INT,
1498 street0_FoldTo3BDone INT,
1499 street0_FoldTo4BChance INT,
1500 street0_FoldTo4BDone INT,
1501 street0_SqueezeChance INT,
1502 street0_SqueezeDone INT,
1504 raiseToStealChance INT,
1505 raiseToStealDone INT,
1518 otherRaisedStreet0 INT,
1519 otherRaisedStreet1 INT,
1520 otherRaisedStreet2 INT,
1521 otherRaisedStreet3 INT,
1522 otherRaisedStreet4 INT,
1523 foldToOtherRaisedStreet0 INT,
1524 foldToOtherRaisedStreet1 INT,
1525 foldToOtherRaisedStreet2 INT,
1526 foldToOtherRaisedStreet3 INT,
1527 foldToOtherRaisedStreet4 INT,
1529 raiseFirstInChance INT,
1531 foldBbToStealChance INT,
1532 foldedBbToSteal INT,
1533 foldSbToStealChance INT,
1534 foldedSbToSteal INT,
1536 street1CBChance INT,
1538 street2CBChance INT,
1540 street3CBChance INT,
1542 street4CBChance INT,
1545 foldToStreet1CBChance INT,
1546 foldToStreet1CBDone INT,
1547 foldToStreet2CBChance INT,
1548 foldToStreet2CBDone INT,
1549 foldToStreet3CBChance INT,
1550 foldToStreet3CBDone INT,
1551 foldToStreet4CBChance INT,
1552 foldToStreet4CBDone INT,
1556 street1CheckCallRaiseChance INT,
1557 street1CheckCallRaiseDone INT,
1558 street2CheckCallRaiseChance INT,
1559 street2CheckCallRaiseDone INT,
1560 street3CheckCallRaiseChance INT,
1561 street3CheckCallRaiseDone INT,
1562 street4CheckCallRaiseChance INT,
1563 street4CheckCallRaiseDone INT,
1582 ################################
1583 # Create SessionsCache
1584 ################################
1586 if db_server
== 'mysql':
1587 self
.query
['createSessionsCacheTable'] = """CREATE TABLE SessionsCache (
1588 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1589 sessionStart DATETIME NOT NULL,
1590 sessionEnd DATETIME NOT NULL,
1591 gameStart DATETIME NOT NULL,
1592 gameEnd DATETIME NOT NULL,
1594 date CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1595 type char(7) NOT NULL,
1596 gametypeId SMALLINT UNSIGNED, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
1597 tourneyTypeId SMALLINT UNSIGNED, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
1598 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1601 tourneys INT NOT NULL,
1606 elif db_server
== 'postgresql':
1607 self
.query
['createSessionsCacheTable'] = """CREATE TABLE SessionsCache (
1608 id BIGSERIAL, PRIMARY KEY (id),
1609 sessionStart timestamp without time zone NOT NULL,
1610 sessionEnd timestamp without time zone NOT NULL,
1611 gameStart timestamp without time zone NOT NULL,
1612 gameEnd timestamp without time zone NOT NULL,
1614 date CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1616 gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
1617 tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
1618 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
1625 elif db_server
== 'sqlite':
1626 self
.query
['createSessionsCacheTable'] = """CREATE TABLE SessionsCache (
1627 id INTEGER PRIMARY KEY,
1628 sessionStart timestamp NOT NULL,
1629 sessionEnd timestamp NOT NULL,
1630 gameStart timestamp NOT NULL,
1631 gameEnd timestamp NOT NULL,
1633 date TEXT NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1644 self
.query
['addSessionIdIndex'] = """CREATE INDEX index_SessionId ON SessionsCache (sessionId)"""
1646 self
.query
['addHandsSessionIdIndex'] = """CREATE INDEX index_handsSessionId ON Hands (sessionId)"""
1648 self
.query
['addHandsGameSessionIdIndex'] = """CREATE INDEX index_handsGameSessionId ON Hands (gameSessionId)"""
1650 if db_server
== 'mysql':
1651 self
.query
['addTourneyIndex'] = """ALTER TABLE Tourneys ADD UNIQUE INDEX siteTourneyNo(siteTourneyNo, tourneyTypeId)"""
1652 elif db_server
== 'postgresql':
1653 self
.query
['addTourneyIndex'] = """CREATE UNIQUE INDEX siteTourneyNo ON Tourneys (siteTourneyNo, tourneyTypeId)"""
1654 elif db_server
== 'sqlite':
1655 self
.query
['addTourneyIndex'] = """CREATE UNIQUE INDEX siteTourneyNo ON Tourneys (siteTourneyNo, tourneyTypeId)"""
1657 if db_server
== 'mysql':
1658 self
.query
['addHandsIndex'] = """ALTER TABLE Hands ADD UNIQUE INDEX siteHandNo(siteHandNo, gametypeId)"""
1659 elif db_server
== 'postgresql':
1660 self
.query
['addHandsIndex'] = """CREATE UNIQUE INDEX siteHandNo ON Hands (siteHandNo, gametypeId)"""
1661 elif db_server
== 'sqlite':
1662 self
.query
['addHandsIndex'] = """CREATE UNIQUE INDEX siteHandNo ON Hands (siteHandNo, gametypeId)"""
1664 if db_server
== 'mysql':
1665 self
.query
['addPlayersIndex'] = """ALTER TABLE Players ADD UNIQUE INDEX name(name, siteId)"""
1666 elif db_server
== 'postgresql':
1667 self
.query
['addPlayersIndex'] = """CREATE UNIQUE INDEX name ON Players (name, siteId)"""
1668 elif db_server
== 'sqlite':
1669 self
.query
['addPlayersIndex'] = """CREATE UNIQUE INDEX name ON Players (name, siteId)"""
1671 if db_server
== 'mysql':
1672 self
.query
['addTPlayersIndex'] = """ALTER TABLE TourneysPlayers ADD UNIQUE INDEX _tourneyId(tourneyId, playerId)"""
1673 elif db_server
== 'postgresql':
1674 self
.query
['addTPlayersIndex'] = """CREATE UNIQUE INDEX tourneyId ON TourneysPlayers (tourneyId, playerId)"""
1675 elif db_server
== 'sqlite':
1676 self
.query
['addTPlayersIndex'] = """CREATE UNIQUE INDEX tourneyId ON TourneysPlayers (tourneyId, playerId)"""
1678 if db_server
== 'mysql':
1679 self
.query
['addTTypesIndex'] = """ALTER TABLE TourneyTypes ADD UNIQUE INDEX tourneytypes_all(siteId, buyin, fee
1680 , maxSeats, knockout, rebuy, addOn, speed, shootout, matrix, sng)"""
1681 elif db_server
== 'postgresql':
1682 self
.query
['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (siteId, buyin, fee
1683 , maxSeats, knockout, rebuy, addOn, speed, shootout, matrix, sng)"""
1684 elif db_server
== 'sqlite':
1685 self
.query
['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (siteId, buyin, fee
1686 , maxSeats, knockout, rebuy, addOn, speed, shootout, matrix, sng)"""
1688 self
.query
['get_last_hand'] = "select max(id) from Hands"
1690 self
.query
['get_last_date'] = "SELECT MAX(startTime) FROM Hands"
1692 self
.query
['get_first_date'] = "SELECT MIN(startTime) FROM Hands"
1694 self
.query
['get_player_id'] = """
1695 select Players.id AS player_id
1697 where Players.name = %s
1699 and Players.siteId = Sites.id
1702 self
.query
['get_player_names'] = """
1705 where lower(p.name) like lower(%s)
1706 and (p.siteId = %s or %s = -1)
1709 self
.query
['get_gameinfo_from_hid'] = """
1717 round(g.smallBlind / 100.0,2),
1718 round(g.bigBlind / 100.0,2),
1719 round(g.smallBet / 100.0,2),
1720 round(g.bigBet / 100.0,2),
1730 and g.id = h.gametypeid
1731 and hp.handid = h.id
1732 and p.id = hp.playerid
1737 self
.query
['get_stats_from_hand'] = """
1738 SELECT hc.playerId AS player_id,
1740 p.name AS screen_name,
1742 sum(hc.street0VPI) AS vpip,
1743 sum(hc.street0Aggr) AS pfr,
1744 sum(hc.street0_3BChance) AS TB_opp_0,
1745 sum(hc.street0_3BDone) AS TB_0,
1746 sum(hc.street0_4BChance) AS FB_opp_0,
1747 sum(hc.street0_4BDone) AS FB_0,
1748 sum(hc.street0_C4BChance) AS CFB_opp_0,
1749 sum(hc.street0_C4BDone) AS CFB_0,
1750 sum(hc.street0_FoldTo3BChance) AS F3B_opp_0,
1751 sum(hc.street0_FoldTo3BDone) AS F3B_0,
1752 sum(hc.street0_FoldTo4BChance) AS F4B_opp_0,
1753 sum(hc.street0_FoldTo4BDone) AS F4B_0,
1754 sum(hc.street0_SqueezeChance) AS SQZ_opp_0,
1755 sum(hc.street0_SqueezeDone) AS SQZ_0,
1756 sum(hc.raiseToStealChance) AS RTS_opp,
1757 sum(hc.raiseToStealDone) AS RTS,
1758 sum(hc.success_Steal) AS SUC_ST,
1759 sum(hc.street1Seen) AS saw_f,
1760 sum(hc.street1Seen) AS saw_1,
1761 sum(hc.street2Seen) AS saw_2,
1762 sum(hc.street3Seen) AS saw_3,
1763 sum(hc.street4Seen) AS saw_4,
1764 sum(hc.sawShowdown) AS sd,
1765 sum(hc.street1Aggr) AS aggr_1,
1766 sum(hc.street2Aggr) AS aggr_2,
1767 sum(hc.street3Aggr) AS aggr_3,
1768 sum(hc.street4Aggr) AS aggr_4,
1769 sum(hc.otherRaisedStreet1) AS was_raised_1,
1770 sum(hc.otherRaisedStreet2) AS was_raised_2,
1771 sum(hc.otherRaisedStreet3) AS was_raised_3,
1772 sum(hc.otherRaisedStreet4) AS was_raised_4,
1773 sum(hc.foldToOtherRaisedStreet1) AS f_freq_1,
1774 sum(hc.foldToOtherRaisedStreet2) AS f_freq_2,
1775 sum(hc.foldToOtherRaisedStreet3) AS f_freq_3,
1776 sum(hc.foldToOtherRaisedStreet4) AS f_freq_4,
1777 sum(hc.wonWhenSeenStreet1) AS w_w_s_1,
1778 sum(hc.wonAtSD) AS wmsd,
1779 sum(case hc.position
1780 when 'S' then hc.raiseFirstInChance
1781 when '0' then hc.raiseFirstInChance
1782 when '1' then hc.raiseFirstInChance
1785 sum(case hc.position
1786 when 'S' then hc.raisedFirstIn
1787 when '0' then hc.raisedFirstIn
1788 when '1' then hc.raisedFirstIn
1791 sum(hc.foldSbToStealChance) AS SBstolen,
1792 sum(hc.foldedSbToSteal) AS SBnotDef,
1793 sum(hc.foldBbToStealChance) AS BBstolen,
1794 sum(hc.foldedBbToSteal) AS BBnotDef,
1795 sum(hc.street1CBChance) AS CB_opp_1,
1796 sum(hc.street1CBDone) AS CB_1,
1797 sum(hc.street2CBChance) AS CB_opp_2,
1798 sum(hc.street2CBDone) AS CB_2,
1799 sum(hc.street3CBChance) AS CB_opp_3,
1800 sum(hc.street3CBDone) AS CB_3,
1801 sum(hc.street4CBChance) AS CB_opp_4,
1802 sum(hc.street4CBDone) AS CB_4,
1803 sum(hc.foldToStreet1CBChance) AS f_cb_opp_1,
1804 sum(hc.foldToStreet1CBDone) AS f_cb_1,
1805 sum(hc.foldToStreet2CBChance) AS f_cb_opp_2,
1806 sum(hc.foldToStreet2CBDone) AS f_cb_2,
1807 sum(hc.foldToStreet3CBChance) AS f_cb_opp_3,
1808 sum(hc.foldToStreet3CBDone) AS f_cb_3,
1809 sum(hc.foldToStreet4CBChance) AS f_cb_opp_4,
1810 sum(hc.foldToStreet4CBDone) AS f_cb_4,
1811 sum(hc.totalProfit) AS net,
1812 sum(gt.bigblind) AS bigblind,
1813 sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1,
1814 sum(hc.street1CheckCallRaiseDone) AS ccr_1,
1815 sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2,
1816 sum(hc.street2CheckCallRaiseDone) AS ccr_2,
1817 sum(hc.street3CheckCallRaiseChance) AS ccr_opp_3,
1818 sum(hc.street3CheckCallRaiseDone) AS ccr_3,
1819 sum(hc.street4CheckCallRaiseChance) AS ccr_opp_4,
1820 sum(hc.street4CheckCallRaiseDone) AS ccr_4
1821 sum(hc.street0Calls) AS call_0,
1822 sum(hc.street1Calls) AS call_1,
1823 sum(hc.street2Calls) AS call_2,
1824 sum(hc.street3Calls) AS call_3,
1825 sum(hc.street4Calls) AS call_4,
1826 sum(hc.street0Bets) AS bet_0,
1827 sum(hc.street1Bets) AS bet_1,
1828 sum(hc.street2Bets) AS bet_2,
1829 sum(hc.street3Bets) AS bet_3,
1830 sum(hc.street4Bets) AS bet_4,
1831 sum(hc.street0Raises) AS raise_0,
1832 sum(hc.street1Raises) AS raise_1,
1833 sum(hc.street2Raises) AS raise_2,
1834 sum(hc.street3Raises) AS raise_3,
1835 sum(hc.street4Raises) AS raise_4
1837 INNER JOIN HandsPlayers hp ON (hp.handId = h.id)
1838 INNER JOIN HudCache hc ON ( hc.PlayerId = hp.PlayerId+0
1839 AND hc.gametypeId+0 = h.gametypeId+0)
1840 INNER JOIN Players p ON (p.id = hp.PlayerId+0)
1841 INNER JOIN Gametypes gt ON (gt.id = hc.gametypeId)
1843 AND hc.styleKey > %s
1844 /* styleKey is currently 'd' (for date) followed by a yyyymmdd
1845 date key. Set it to 0000000 or similar to get all records */
1846 /* also check activeseats here even if only 3 groups eg 2-3/4-6/7+
1847 e.g. could use a multiplier:
1848 AND h.seats > X / 1.25 and hp.seats < X * 1.25
1849 where X is the number of active players at the current table (and
1850 1.25 would be a config value so user could change it)
1852 GROUP BY hc.PlayerId, hp.seatNo, p.name
1853 ORDER BY hc.PlayerId, hp.seatNo, p.name
1856 # same as above except stats are aggregated for all blind/limit levels
1857 self
.query
['get_stats_from_hand_aggregated'] = """
1858 /* explain query plan */
1859 SELECT hc.playerId AS player_id,
1860 max(case when hc.gametypeId = h.gametypeId
1864 p.name AS screen_name,
1866 sum(hc.street0VPI) AS vpip,
1867 sum(hc.street0Aggr) AS pfr,
1868 sum(hc.street0_3BChance) AS TB_opp_0,
1869 sum(hc.street0_3BDone) AS TB_0,
1870 sum(hc.street0_4BChance) AS FB_opp_0,
1871 sum(hc.street0_4BDone) AS FB_0,
1872 sum(hc.street0_C4BChance) AS CFB_opp_0,
1873 sum(hc.street0_C4BDone) AS CFB_0,
1874 sum(hc.street0_FoldTo3BChance) AS F3B_opp_0,
1875 sum(hc.street0_FoldTo3BDone) AS F3B_0,
1876 sum(hc.street0_FoldTo4BChance) AS F4B_opp_0,
1877 sum(hc.street0_FoldTo4BDone) AS F4B_0,
1878 sum(hc.street0_SqueezeChance) AS SQZ_opp_0,
1879 sum(hc.street0_SqueezeDone) AS SQZ_0,
1880 sum(hc.raiseToStealChance) AS RTS_opp,
1881 sum(hc.raiseToStealDone) AS RTS,
1882 sum(hc.success_Steal) AS SUC_ST,
1883 sum(hc.street1Seen) AS saw_f,
1884 sum(hc.street1Seen) AS saw_1,
1885 sum(hc.street2Seen) AS saw_2,
1886 sum(hc.street3Seen) AS saw_3,
1887 sum(hc.street4Seen) AS saw_4,
1888 sum(hc.sawShowdown) AS sd,
1889 sum(hc.street1Aggr) AS aggr_1,
1890 sum(hc.street2Aggr) AS aggr_2,
1891 sum(hc.street3Aggr) AS aggr_3,
1892 sum(hc.street4Aggr) AS aggr_4,
1893 sum(hc.otherRaisedStreet1) AS was_raised_1,
1894 sum(hc.otherRaisedStreet2) AS was_raised_2,
1895 sum(hc.otherRaisedStreet3) AS was_raised_3,
1896 sum(hc.otherRaisedStreet4) AS was_raised_4,
1897 sum(hc.foldToOtherRaisedStreet1) AS f_freq_1,
1898 sum(hc.foldToOtherRaisedStreet2) AS f_freq_2,
1899 sum(hc.foldToOtherRaisedStreet3) AS f_freq_3,
1900 sum(hc.foldToOtherRaisedStreet4) AS f_freq_4,
1901 sum(hc.wonWhenSeenStreet1) AS w_w_s_1,
1902 sum(hc.wonAtSD) AS wmsd,
1903 sum(hc.raiseFirstInChance) AS steal_opp,
1904 sum(hc.raisedFirstIn) AS steal,
1905 sum(hc.foldSbToStealChance) AS SBstolen,
1906 sum(hc.foldedSbToSteal) AS SBnotDef,
1907 sum(hc.foldBbToStealChance) AS BBstolen,
1908 sum(hc.foldedBbToSteal) AS BBnotDef,
1909 sum(hc.street1CBChance) AS CB_opp_1,
1910 sum(hc.street1CBDone) AS CB_1,
1911 sum(hc.street2CBChance) AS CB_opp_2,
1912 sum(hc.street2CBDone) AS CB_2,
1913 sum(hc.street3CBChance) AS CB_opp_3,
1914 sum(hc.street3CBDone) AS CB_3,
1915 sum(hc.street4CBChance) AS CB_opp_4,
1916 sum(hc.street4CBDone) AS CB_4,
1917 sum(hc.foldToStreet1CBChance) AS f_cb_opp_1,
1918 sum(hc.foldToStreet1CBDone) AS f_cb_1,
1919 sum(hc.foldToStreet2CBChance) AS f_cb_opp_2,
1920 sum(hc.foldToStreet2CBDone) AS f_cb_2,
1921 sum(hc.foldToStreet3CBChance) AS f_cb_opp_3,
1922 sum(hc.foldToStreet3CBDone) AS f_cb_3,
1923 sum(hc.foldToStreet4CBChance) AS f_cb_opp_4,
1924 sum(hc.foldToStreet4CBDone) AS f_cb_4,
1925 sum(hc.totalProfit) AS net,
1926 sum(gt.bigblind) AS bigblind,
1927 sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1,
1928 sum(hc.street1CheckCallRaiseDone) AS ccr_1,
1929 sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2,
1930 sum(hc.street2CheckCallRaiseDone) AS ccr_2,
1931 sum(hc.street3CheckCallRaiseChance) AS ccr_opp_3,
1932 sum(hc.street3CheckCallRaiseDone) AS ccr_3,
1933 sum(hc.street4CheckCallRaiseChance) AS ccr_opp_4,
1934 sum(hc.street4CheckCallRaiseDone) AS ccr_4,
1935 sum(hc.street0Calls) AS call_0,
1936 sum(hc.street1Calls) AS call_1,
1937 sum(hc.street2Calls) AS call_2,
1938 sum(hc.street3Calls) AS call_3,
1939 sum(hc.street4Calls) AS call_4,
1940 sum(hc.street0Bets) AS bet_0,
1941 sum(hc.street1Bets) AS bet_1,
1942 sum(hc.street2Bets) AS bet_2,
1943 sum(hc.street3Bets) AS bet_3,
1944 sum(hc.street4Bets) AS bet_4,
1945 sum(hc.street0Raises) AS raise_0,
1946 sum(hc.street1Raises) AS raise_1,
1947 sum(hc.street2Raises) AS raise_2,
1948 sum(hc.street3Raises) AS raise_3,
1949 sum(hc.street4Raises) AS raise_4
1951 INNER JOIN HandsPlayers hp ON (hp.handId = h.id)
1952 INNER JOIN HudCache hc ON (hc.playerId = hp.playerId)
1953 INNER JOIN Players p ON (p.id = hc.playerId)
1954 INNER JOIN Gametypes gt ON (gt.id = hc.gametypeId)
1956 AND ( /* 2 separate parts for hero and opponents */
1958 AND hc.styleKey > %s
1959 AND hc.gametypeId+0 in
1960 (SELECT gt1.id from Gametypes gt1, Gametypes gt2
1961 WHERE gt1.siteid = gt2.siteid /* find gametypes where these match: */
1962 AND gt1.type = gt2.type /* ring/tourney */
1963 AND gt1.category = gt2.category /* holdem/stud*/
1964 AND gt1.limittype = gt2.limittype /* fl/nl */
1965 AND gt1.bigblind <= gt2.bigblind * %s /* bigblind similar size */
1966 AND gt1.bigblind >= gt2.bigblind / %s
1967 AND gt2.id = h.gametypeId)
1968 AND hc.activeSeats between %s and %s
1972 AND hc.styleKey > %s
1973 AND hc.gametypeId+0 in
1974 (SELECT gt1.id from Gametypes gt1, Gametypes gt2
1975 WHERE gt1.siteid = gt2.siteid /* find gametypes where these match: */
1976 AND gt1.type = gt2.type /* ring/tourney */
1977 AND gt1.category = gt2.category /* holdem/stud*/
1978 AND gt1.limittype = gt2.limittype /* fl/nl */
1979 AND gt1.bigblind <= gt2.bigblind * %s /* bigblind similar size */
1980 AND gt1.bigblind >= gt2.bigblind / %s
1981 AND gt2.id = h.gametypeId)
1982 AND hc.activeSeats between %s and %s
1985 GROUP BY hc.PlayerId, p.name
1986 ORDER BY hc.PlayerId, p.name
1988 # NOTES on above cursor:
1989 # - Do NOT include %s inside query in a comment - the db api thinks
1990 # they are actual arguments.
1991 # - styleKey is currently 'd' (for date) followed by a yyyymmdd
1992 # date key. Set it to 0000000 or similar to get all records
1993 # Could also check activeseats here even if only 3 groups eg 2-3/4-6/7+
1994 # e.g. could use a multiplier:
1995 # AND h.seats > %s / 1.25 and hp.seats < %s * 1.25
1996 # where %s is the number of active players at the current table (and
1997 # 1.25 would be a config value so user could change it)
1999 if db_server
== 'mysql':
2000 self
.query
['get_stats_from_hand_session'] = """
2001 SELECT hp.playerId AS player_id, /* playerId and seats must */
2002 h.seats AS seats, /* be first and second field */
2003 hp.handId AS hand_id,
2005 p.name AS screen_name,
2007 cast(hp2.street0VPI as <signed>integer) AS vpip,
2008 cast(hp2.street0Aggr as <signed>integer) AS pfr,
2009 cast(hp2.street0_3BChance as <signed>integer) AS TB_opp_0,
2010 cast(hp2.street0_3BDone as <signed>integer) AS TB_0,
2011 cast(hp2.street0_4BChance as <signed>integer) AS FB_opp_0,
2012 cast(hp2.street0_4BDone as <signed>integer) AS FB_0,
2013 cast(hp2.street0_C4BChance as <signed>integer) AS CFB_opp_0,
2014 cast(hp2.street0_C4BDone as <signed>integer) AS CFB_0,
2015 cast(hp2.street0_FoldTo3BChance as <signed>integer) AS F3B_opp_0,
2016 cast(hp2.street0_FoldTo3BDone as <signed>integer) AS F3B_0,
2017 cast(hp2.street0_FoldTo4BChance as <signed>integer) AS F4B_opp_0,
2018 cast(hp2.street0_FoldTo4BDone as <signed>integer) AS F4B_0,
2019 cast(hp2.street0_SqueezeChance as <signed>integer) AS SQZ_opp_0,
2020 cast(hp2.street0_SqueezeDone as <signed>integer) AS SQZ_0,
2021 cast(hp2.raiseToStealChance as <signed>integer) AS RTS_opp,
2022 cast(hp2.raiseToStealDone as <signed>integer) AS RTS,
2023 cast(hp2.success_Steal as <signed>integer) AS SUC_ST,
2024 cast(hp2.street1Seen as <signed>integer) AS saw_f,
2025 cast(hp2.street1Seen as <signed>integer) AS saw_1,
2026 cast(hp2.street2Seen as <signed>integer) AS saw_2,
2027 cast(hp2.street3Seen as <signed>integer) AS saw_3,
2028 cast(hp2.street4Seen as <signed>integer) AS saw_4,
2029 cast(hp2.sawShowdown as <signed>integer) AS sd,
2030 cast(hp2.street1Aggr as <signed>integer) AS aggr_1,
2031 cast(hp2.street2Aggr as <signed>integer) AS aggr_2,
2032 cast(hp2.street3Aggr as <signed>integer) AS aggr_3,
2033 cast(hp2.street4Aggr as <signed>integer) AS aggr_4,
2034 cast(hp2.otherRaisedStreet1 as <signed>integer) AS was_raised_1,
2035 cast(hp2.otherRaisedStreet2 as <signed>integer) AS was_raised_2,
2036 cast(hp2.otherRaisedStreet3 as <signed>integer) AS was_raised_3,
2037 cast(hp2.otherRaisedStreet4 as <signed>integer) AS was_raised_4,
2038 cast(hp2.foldToOtherRaisedStreet1 as <signed>integer) AS f_freq_1,
2039 cast(hp2.foldToOtherRaisedStreet2 as <signed>integer) AS f_freq_2,
2040 cast(hp2.foldToOtherRaisedStreet3 as <signed>integer) AS f_freq_3,
2041 cast(hp2.foldToOtherRaisedStreet4 as <signed>integer) AS f_freq_4,
2042 cast(hp2.wonWhenSeenStreet1 as <signed>integer) AS w_w_s_1,
2043 cast(hp2.wonAtSD as <signed>integer) AS wmsd,
2044 cast(hp2.raiseFirstInChance as <signed>integer) AS steal_opp,
2045 cast(hp2.raisedFirstIn as <signed>integer) AS steal,
2046 cast(hp2.foldSbToStealChance as <signed>integer) AS SBstolen,
2047 cast(hp2.foldedSbToSteal as <signed>integer) AS SBnotDef,
2048 cast(hp2.foldBbToStealChance as <signed>integer) AS BBstolen,
2049 cast(hp2.foldedBbToSteal as <signed>integer) AS BBnotDef,
2050 cast(hp2.street1CBChance as <signed>integer) AS CB_opp_1,
2051 cast(hp2.street1CBDone as <signed>integer) AS CB_1,
2052 cast(hp2.street2CBChance as <signed>integer) AS CB_opp_2,
2053 cast(hp2.street2CBDone as <signed>integer) AS CB_2,
2054 cast(hp2.street3CBChance as <signed>integer) AS CB_opp_3,
2055 cast(hp2.street3CBDone as <signed>integer) AS CB_3,
2056 cast(hp2.street4CBChance as <signed>integer) AS CB_opp_4,
2057 cast(hp2.street4CBDone as <signed>integer) AS CB_4,
2058 cast(hp2.foldToStreet1CBChance as <signed>integer) AS f_cb_opp_1,
2059 cast(hp2.foldToStreet1CBDone as <signed>integer) AS f_cb_1,
2060 cast(hp2.foldToStreet2CBChance as <signed>integer) AS f_cb_opp_2,
2061 cast(hp2.foldToStreet2CBDone as <signed>integer) AS f_cb_2,
2062 cast(hp2.foldToStreet3CBChance as <signed>integer) AS f_cb_opp_3,
2063 cast(hp2.foldToStreet3CBDone as <signed>integer) AS f_cb_3,
2064 cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
2065 cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
2066 cast(hp2.totalProfit as <signed>integer) AS net,
2067 cast(gt.bigblind as <signed>integer) AS bigblind,
2068 cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
2069 cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
2070 cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
2071 cast(hp2.street2CheckCallRaiseDone as <signed>integer) AS ccr_2,
2072 cast(hp2.street3CheckCallRaiseChance as <signed>integer) AS ccr_opp_3,
2073 cast(hp2.street3CheckCallRaiseDone as <signed>integer) AS ccr_3,
2074 cast(hp2.street4CheckCallRaiseChance as <signed>integer) AS ccr_opp_4,
2075 cast(hp2.street4CheckCallRaiseDone as <signed>integer) AS ccr_4,
2076 cast(hp2.street0Calls as <signed>integer) AS call_0,
2077 cast(hp2.street1Calls as <signed>integer) AS call_1,
2078 cast(hp2.street2Calls as <signed>integer) AS call_2,
2079 cast(hp2.street3Calls as <signed>integer) AS call_3,
2080 cast(hp2.street4Calls as <signed>integer) AS call_4,
2081 cast(hp2.street0Bets as <signed>integer) AS bet_0,
2082 cast(hp2.street1Bets as <signed>integer) AS bet_1,
2083 cast(hp2.street2Bets as <signed>integer) AS bet_2,
2084 cast(hp2.street3Bets as <signed>integer) AS bet_3,
2085 cast(hp2.street4Bets as <signed>integer) AS bet_4,
2086 cast(hp2.street0Raises as <signed>integer) AS raise_0,
2087 cast(hp2.street1Raises as <signed>integer) AS raise_1,
2088 cast(hp2.street2Raises as <signed>integer) AS raise_2,
2089 cast(hp2.street3Raises as <signed>integer) AS raise_3,
2090 cast(hp2.street4Raises as <signed>integer) AS raise_4
2093 INNER JOIN Hands h2 ON (h2.id >= %s AND h2.tableName = h.tableName)
2094 INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */
2095 INNER JOIN HandsPlayers hp2 ON (hp2.playerId+0 = hp.playerId+0 AND (hp2.handId = h2.id+0)) /* other hands by these players */
2096 INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
2097 INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
2098 WHERE hp.handId = %s
2099 /* check activeseats once this data returned (don't want to do that here as it might
2100 assume a session ended just because the number of seats dipped for a few hands)
2102 AND ( /* 2 separate parts for hero and opponents */
2103 ( hp2.playerId != %s
2104 AND h2.seats between %s and %s
2108 AND h2.seats between %s and %s
2111 ORDER BY h.startTime desc, hp2.PlayerId
2112 /* order rows by handstart descending so that we can stop reading rows when
2113 there's a gap over X minutes between hands (ie. when we get back to start of
2116 elif db_server
== 'postgresql':
2117 self
.query
['get_stats_from_hand_session'] = """
2118 SELECT hp.playerId AS player_id,
2119 hp.handId AS hand_id,
2121 p.name AS screen_name,
2124 cast(hp2.street0VPI as <signed>integer) AS vpip,
2125 cast(hp2.street0Aggr as <signed>integer) AS pfr,
2126 cast(hp2.street0_3BChance as <signed>integer) AS TB_opp_0,
2127 cast(hp2.street0_3BDone as <signed>integer) AS TB_0,
2128 cast(hp2.street0_4BChance as <signed>integer) AS FB_opp_0,
2129 cast(hp2.street0_4BDone as <signed>integer) AS FB_0,
2130 cast(hp2.street0_C4BChance as <signed>integer) AS CFB_opp_0,
2131 cast(hp2.street0_C4BDone as <signed>integer) AS CFB_0,
2132 cast(hp2.street0_FoldTo3BChance as <signed>integer) AS F3B_opp_0,
2133 cast(hp2.street0_FoldTo3BDone as <signed>integer) AS F3B_0,
2134 cast(hp2.street0_FoldTo4BChance as <signed>integer) AS F4B_opp_0,
2135 cast(hp2.street0_FoldTo4BDone as <signed>integer) AS F4B_0,
2136 cast(hp2.street0_SqueezeChance as <signed>integer) AS SQZ_opp_0,
2137 cast(hp2.street0_SqueezeDone as <signed>integer) AS SQZ_0,
2138 cast(hp2.raiseToStealChance as <signed>integer) AS RTS_opp,
2139 cast(hp2.raiseToStealDone as <signed>integer) AS RTS,
2140 cast(hp2.success_Steal as <signed>integer) AS SUC_ST,
2141 cast(hp2.street1Seen as <signed>integer) AS saw_f,
2142 cast(hp2.street1Seen as <signed>integer) AS saw_1,
2143 cast(hp2.street2Seen as <signed>integer) AS saw_2,
2144 cast(hp2.street3Seen as <signed>integer) AS saw_3,
2145 cast(hp2.street4Seen as <signed>integer) AS saw_4,
2146 cast(hp2.sawShowdown as <signed>integer) AS sd,
2147 cast(hp2.street1Aggr as <signed>integer) AS aggr_1,
2148 cast(hp2.street2Aggr as <signed>integer) AS aggr_2,
2149 cast(hp2.street3Aggr as <signed>integer) AS aggr_3,
2150 cast(hp2.street4Aggr as <signed>integer) AS aggr_4,
2151 cast(hp2.otherRaisedStreet1 as <signed>integer) AS was_raised_1,
2152 cast(hp2.otherRaisedStreet2 as <signed>integer) AS was_raised_2,
2153 cast(hp2.otherRaisedStreet3 as <signed>integer) AS was_raised_3,
2154 cast(hp2.otherRaisedStreet4 as <signed>integer) AS was_raised_4,
2155 cast(hp2.foldToOtherRaisedStreet1 as <signed>integer) AS f_freq_1,
2156 cast(hp2.foldToOtherRaisedStreet2 as <signed>integer) AS f_freq_2,
2157 cast(hp2.foldToOtherRaisedStreet3 as <signed>integer) AS f_freq_3,
2158 cast(hp2.foldToOtherRaisedStreet4 as <signed>integer) AS f_freq_4,
2159 cast(hp2.wonWhenSeenStreet1 as <signed>integer) AS w_w_s_1,
2160 cast(hp2.wonAtSD as <signed>integer) AS wmsd,
2161 cast(hp2.raiseFirstInChance as <signed>integer) AS steal_opp,
2162 cast(hp2.raisedFirstIn as <signed>integer) AS steal,
2163 cast(hp2.foldSbToStealChance as <signed>integer) AS SBstolen,
2164 cast(hp2.foldedSbToSteal as <signed>integer) AS SBnotDef,
2165 cast(hp2.foldBbToStealChance as <signed>integer) AS BBstolen,
2166 cast(hp2.foldedBbToSteal as <signed>integer) AS BBnotDef,
2167 cast(hp2.street1CBChance as <signed>integer) AS CB_opp_1,
2168 cast(hp2.street1CBDone as <signed>integer) AS CB_1,
2169 cast(hp2.street2CBChance as <signed>integer) AS CB_opp_2,
2170 cast(hp2.street2CBDone as <signed>integer) AS CB_2,
2171 cast(hp2.street3CBChance as <signed>integer) AS CB_opp_3,
2172 cast(hp2.street3CBDone as <signed>integer) AS CB_3,
2173 cast(hp2.street4CBChance as <signed>integer) AS CB_opp_4,
2174 cast(hp2.street4CBDone as <signed>integer) AS CB_4,
2175 cast(hp2.foldToStreet1CBChance as <signed>integer) AS f_cb_opp_1,
2176 cast(hp2.foldToStreet1CBDone as <signed>integer) AS f_cb_1,
2177 cast(hp2.foldToStreet2CBChance as <signed>integer) AS f_cb_opp_2,
2178 cast(hp2.foldToStreet2CBDone as <signed>integer) AS f_cb_2,
2179 cast(hp2.foldToStreet3CBChance as <signed>integer) AS f_cb_opp_3,
2180 cast(hp2.foldToStreet3CBDone as <signed>integer) AS f_cb_3,
2181 cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
2182 cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
2183 cast(hp2.totalProfit as <signed>integer) AS net,
2184 cast(gt.bigblind as <signed>integer) AS bigblind,
2185 cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
2186 cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
2187 cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
2188 cast(hp2.street2CheckCallRaiseDone as <signed>integer) AS ccr_2,
2189 cast(hp2.street3CheckCallRaiseChance as <signed>integer) AS ccr_opp_3,
2190 cast(hp2.street3CheckCallRaiseDone as <signed>integer) AS ccr_3,
2191 cast(hp2.street4CheckCallRaiseChance as <signed>integer) AS ccr_opp_4,
2192 cast(hp2.street4CheckCallRaiseDone as <signed>integer) AS ccr_4,
2193 cast(hp2.street0Calls as <signed>integer) AS call_0,
2194 cast(hp2.street1Calls as <signed>integer) AS call_1,
2195 cast(hp2.street2Calls as <signed>integer) AS call_2,
2196 cast(hp2.street3Calls as <signed>integer) AS call_3,
2197 cast(hp2.street4Calls as <signed>integer) AS call_4,
2198 cast(hp2.street0Bets as <signed>integer) AS bet_0,
2199 cast(hp2.street1Bets as <signed>integer) AS bet_1,
2200 cast(hp2.street2Bets as <signed>integer) AS bet_2,
2201 cast(hp2.street3Bets as <signed>integer) AS bet_3,
2202 cast(hp2.street4Bets as <signed>integer) AS bet_4,
2203 cast(hp2.street0Raises as <signed>integer) AS raise_0,
2204 cast(hp2.street1Raises as <signed>integer) AS raise_1,
2205 cast(hp2.street2Raises as <signed>integer) AS raise_2,
2206 cast(hp2.street3Raises as <signed>integer) AS raise_3,
2207 cast(hp2.street4Raises as <signed>integer) AS raise_4
2208 FROM Hands h /* this hand */
2209 INNER JOIN Hands h2 ON ( h2.id >= %s /* other hands */
2210 AND h2.tableName = h.tableName)
2211 INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */
2212 INNER JOIN HandsPlayers hp2 ON ( hp2.playerId+0 = hp.playerId+0
2213 AND hp2.handId = h2.id) /* other hands by these players */
2214 INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
2215 INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
2217 /* check activeseats once this data returned (don't want to do that here as it might
2218 assume a session ended just because the number of seats dipped for a few hands)
2220 AND ( /* 2 separate parts for hero and opponents */
2221 ( hp2.playerId != %s
2222 AND h2.seats between %s and %s
2226 AND h2.seats between %s and %s
2229 ORDER BY h.startTime desc, hp2.PlayerId
2230 /* order rows by handstart descending so that we can stop reading rows when
2231 there's a gap over X minutes between hands (ie. when we get back to start of
2234 elif db_server
== 'sqlite':
2235 self
.query
['get_stats_from_hand_session'] = """
2236 SELECT hp.playerId AS player_id,
2237 hp.handId AS hand_id,
2239 p.name AS screen_name,
2242 cast(hp2.street0VPI as <signed>integer) AS vpip,
2243 cast(hp2.street0Aggr as <signed>integer) AS pfr,
2244 cast(hp2.street0_3BChance as <signed>integer) AS TB_opp_0,
2245 cast(hp2.street0_3BDone as <signed>integer) AS TB_0,
2246 cast(hp2.street0_4BChance as <signed>integer) AS FB_opp_0,
2247 cast(hp2.street0_4BDone as <signed>integer) AS FB_0,
2248 cast(hp2.street0_C4BChance as <signed>integer) AS CFB_opp_0,
2249 cast(hp2.street0_C4BDone as <signed>integer) AS CFB_0,
2250 cast(hp2.street0_FoldTo3BChance as <signed>integer) AS F3B_opp_0,
2251 cast(hp2.street0_FoldTo3BDone as <signed>integer) AS F3B_0,
2252 cast(hp2.street0_FoldTo4BChance as <signed>integer) AS F4B_opp_0,
2253 cast(hp2.street0_FoldTo4BDone as <signed>integer) AS F4B_0,
2254 cast(hp2.street0_SqueezeChance as <signed>integer) AS SQZ_opp_0,
2255 cast(hp2.street0_SqueezeDone as <signed>integer) AS SQZ_0,
2256 cast(hp2.raiseToStealChance as <signed>integer) AS RTS_opp,
2257 cast(hp2.raiseToStealDone as <signed>integer) AS RTS,
2258 cast(hp2.success_Steal as <signed>integer) AS SUC_ST,
2259 cast(hp2.street1Seen as <signed>integer) AS saw_f,
2260 cast(hp2.street1Seen as <signed>integer) AS saw_1,
2261 cast(hp2.street2Seen as <signed>integer) AS saw_2,
2262 cast(hp2.street3Seen as <signed>integer) AS saw_3,
2263 cast(hp2.street4Seen as <signed>integer) AS saw_4,
2264 cast(hp2.sawShowdown as <signed>integer) AS sd,
2265 cast(hp2.street1Aggr as <signed>integer) AS aggr_1,
2266 cast(hp2.street2Aggr as <signed>integer) AS aggr_2,
2267 cast(hp2.street3Aggr as <signed>integer) AS aggr_3,
2268 cast(hp2.street4Aggr as <signed>integer) AS aggr_4,
2269 cast(hp2.otherRaisedStreet1 as <signed>integer) AS was_raised_1,
2270 cast(hp2.otherRaisedStreet2 as <signed>integer) AS was_raised_2,
2271 cast(hp2.otherRaisedStreet3 as <signed>integer) AS was_raised_3,
2272 cast(hp2.otherRaisedStreet4 as <signed>integer) AS was_raised_4,
2273 cast(hp2.foldToOtherRaisedStreet1 as <signed>integer) AS f_freq_1,
2274 cast(hp2.foldToOtherRaisedStreet2 as <signed>integer) AS f_freq_2,
2275 cast(hp2.foldToOtherRaisedStreet3 as <signed>integer) AS f_freq_3,
2276 cast(hp2.foldToOtherRaisedStreet4 as <signed>integer) AS f_freq_4,
2277 cast(hp2.wonWhenSeenStreet1 as <signed>integer) AS w_w_s_1,
2278 cast(hp2.wonAtSD as <signed>integer) AS wmsd,
2279 cast(hp2.raiseFirstInChance as <signed>integer) AS steal_opp,
2280 cast(hp2.raisedFirstIn as <signed>integer) AS steal,
2281 cast(hp2.foldSbToStealChance as <signed>integer) AS SBstolen,
2282 cast(hp2.foldedSbToSteal as <signed>integer) AS SBnotDef,
2283 cast(hp2.foldBbToStealChance as <signed>integer) AS BBstolen,
2284 cast(hp2.foldedBbToSteal as <signed>integer) AS BBnotDef,
2285 cast(hp2.street1CBChance as <signed>integer) AS CB_opp_1,
2286 cast(hp2.street1CBDone as <signed>integer) AS CB_1,
2287 cast(hp2.street2CBChance as <signed>integer) AS CB_opp_2,
2288 cast(hp2.street2CBDone as <signed>integer) AS CB_2,
2289 cast(hp2.street3CBChance as <signed>integer) AS CB_opp_3,
2290 cast(hp2.street3CBDone as <signed>integer) AS CB_3,
2291 cast(hp2.street4CBChance as <signed>integer) AS CB_opp_4,
2292 cast(hp2.street4CBDone as <signed>integer) AS CB_4,
2293 cast(hp2.foldToStreet1CBChance as <signed>integer) AS f_cb_opp_1,
2294 cast(hp2.foldToStreet1CBDone as <signed>integer) AS f_cb_1,
2295 cast(hp2.foldToStreet2CBChance as <signed>integer) AS f_cb_opp_2,
2296 cast(hp2.foldToStreet2CBDone as <signed>integer) AS f_cb_2,
2297 cast(hp2.foldToStreet3CBChance as <signed>integer) AS f_cb_opp_3,
2298 cast(hp2.foldToStreet3CBDone as <signed>integer) AS f_cb_3,
2299 cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
2300 cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
2301 cast(hp2.totalProfit as <signed>integer) AS net,
2302 cast(gt.bigblind as <signed>integer) AS bigblind,
2303 cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
2304 cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
2305 cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
2306 cast(hp2.street2CheckCallRaiseDone as <signed>integer) AS ccr_2,
2307 cast(hp2.street3CheckCallRaiseChance as <signed>integer) AS ccr_opp_3,
2308 cast(hp2.street3CheckCallRaiseDone as <signed>integer) AS ccr_3,
2309 cast(hp2.street4CheckCallRaiseChance as <signed>integer) AS ccr_opp_4,
2310 cast(hp2.street4CheckCallRaiseDone as <signed>integer) AS ccr_4,
2311 cast(hp2.street0Calls as <signed>integer) AS call_0,
2312 cast(hp2.street1Calls as <signed>integer) AS call_1,
2313 cast(hp2.street2Calls as <signed>integer) AS call_2,
2314 cast(hp2.street3Calls as <signed>integer) AS call_3,
2315 cast(hp2.street4Calls as <signed>integer) AS call_4,
2316 cast(hp2.street0Bets as <signed>integer) AS bet_0,
2317 cast(hp2.street1Bets as <signed>integer) AS bet_1,
2318 cast(hp2.street2Bets as <signed>integer) AS bet_2,
2319 cast(hp2.street3Bets as <signed>integer) AS bet_3,
2320 cast(hp2.street4Bets as <signed>integer) AS bet_4,
2321 cast(hp2.street0Raises as <signed>integer) AS raise_0,
2322 cast(hp2.street1Raises as <signed>integer) AS raise_1,
2323 cast(hp2.street2Raises as <signed>integer) AS raise_2,
2324 cast(hp2.street3Raises as <signed>integer) AS raise_3,
2325 cast(hp2.street4Raises as <signed>integer) AS raise_4
2326 FROM Hands h /* this hand */
2327 INNER JOIN Hands h2 ON ( h2.id >= %s /* other hands */
2328 AND h2.tableName = h.tableName)
2329 INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */
2330 INNER JOIN HandsPlayers hp2 ON ( hp2.playerId+0 = hp.playerId+0
2331 AND hp2.handId = h2.id) /* other hands by these players */
2332 INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
2333 INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
2335 /* check activeseats once this data returned (don't want to do that here as it might
2336 assume a session ended just because the number of seats dipped for a few hands)
2338 AND ( /* 2 separate parts for hero and opponents */
2339 ( hp2.playerId != %s
2340 AND h2.seats between %s and %s
2344 AND h2.seats between %s and %s
2347 ORDER BY h.startTime desc, hp2.PlayerId
2348 /* order rows by handstart descending so that we can stop reading rows when
2349 there's a gap over X minutes between hands (ie. when we get back to start of
2353 self
.query
['get_players_from_hand'] = """
2354 SELECT HandsPlayers.playerId, seatNo, name
2355 FROM HandsPlayers INNER JOIN Players ON (HandsPlayers.playerId = Players.id)
2358 # WHERE handId = %s AND Players.id LIKE %s
2360 self
.query
['get_winners_from_hand'] = """
2361 SELECT name, winnings
2362 FROM HandsPlayers, Players
2364 AND Players.id = HandsPlayers.playerId
2368 self
.query
['get_table_name'] = """
2369 SELECT h.tableName, gt.maxSeats, gt.category, gt.type, s.id, s.name
2370 , count(1) as numseats
2371 FROM Hands h, Gametypes gt, Sites s, HandsPlayers hp
2373 AND gt.id = h.gametypeId
2374 AND s.id = gt.siteID
2375 AND hp.handId = h.id
2376 GROUP BY h.tableName, gt.maxSeats, gt.category, gt.type, s.id, s.name
2379 self
.query
['get_actual_seat'] = """
2382 where HandsPlayers.handId = %s
2383 and HandsPlayers.playerId = (select Players.id from Players
2384 where Players.name = %s)
2387 self
.query
['get_cards'] = """
2389 seatNo AS seat_number,
2390 card1, /*card1Value, card1Suit, */
2391 card2, /*card2Value, card2Suit, */
2392 card3, /*card3Value, card3Suit, */
2393 card4, /*card4Value, card4Suit, */
2394 card5, /*card5Value, card5Suit, */
2395 card6, /*card6Value, card6Suit, */
2396 card7 /*card7Value, card7Suit */
2397 from HandsPlayers, Players
2398 where handID = %s and HandsPlayers.playerId = Players.id
2402 self
.query
['get_common_cards'] = """
2413 if db_server
== 'mysql':
2414 self
.query
['get_hand_1day_ago'] = """
2415 select coalesce(max(id),0)
2417 where startTime < date_sub(utc_timestamp(), interval '1' day)"""
2418 elif db_server
== 'postgresql':
2419 self
.query
['get_hand_1day_ago'] = """
2420 select coalesce(max(id),0)
2422 where startTime < now() at time zone 'UTC' - interval '1 day'"""
2423 elif db_server
== 'sqlite':
2424 self
.query
['get_hand_1day_ago'] = """
2425 select coalesce(max(id),0)
2427 where startTime < datetime(strftime('%J', 'now') - 1)"""
2430 # gets a date, would need to use handsplayers (not hudcache) to get exact hand Id
2431 if db_server
== 'mysql':
2432 self
.query
['get_date_nhands_ago'] = """
2433 select concat( 'd', date_format(max(h.startTime), '%Y%m%d') )
2434 from (select hp.playerId
2435 ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
2436 from HandsPlayers hp
2437 where hp.playerId = %s
2438 group by hp.playerId) hp2
2439 inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx
2440 and hp3.playerId = hp2.playerId)
2441 inner join Hands h on (h.id = hp3.handId)
2443 elif db_server
== 'postgresql':
2444 self
.query
['get_date_nhands_ago'] = """
2445 select 'd' || to_char(max(h3.startTime), 'YYMMDD')
2446 from (select hp.playerId
2447 ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
2448 from HandsPlayers hp
2449 where hp.playerId = %s
2450 group by hp.playerId) hp2
2451 inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx
2452 and hp3.playerId = hp2.playerId)
2453 inner join Hands h on (h.id = hp3.handId)
2455 elif db_server
== 'sqlite': # untested guess at query:
2456 self
.query
['get_date_nhands_ago'] = """
2457 select 'd' || strftime(max(h3.startTime), 'YYMMDD')
2458 from (select hp.playerId
2459 ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
2460 from HandsPlayers hp
2461 where hp.playerId = %s
2462 group by hp.playerId) hp2
2463 inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx
2464 and hp3.playerId = hp2.playerId)
2465 inner join Hands h on (h.id = hp3.handId)
2469 #self.query['getLimits'] = already defined further up
2470 self
.query
['getLimits2'] = """SELECT DISTINCT type, limitType, bigBlind
2472 ORDER by type, limitType DESC, bigBlind DESC"""
2473 self
.query
['getLimits3'] = """select DISTINCT type
2476 when 'ring' then bigBlind
2478 - end as bb_or_buyin
2480 cross join TourneyTypes tt
2481 order by type, gt.limitType DESC, bb_or_buyin DESC"""
2482 self
.query
['getCashLimits'] = """select DISTINCT type
2484 , bigBlind as bb_or_buyin
2487 order by type, limitType DESC, bb_or_buyin DESC"""
2488 #FIXME: Some stats not added to DetailedStats (miss raise to steal)
2489 if db_server
== 'mysql':
2490 self
.query
['playerDetailedStats'] = """
2491 select <hgametypeId> AS hgametypeid
2492 ,<playerName> AS pname
2495 ,upper(gt.limitType) AS limittype
2497 ,min(gt.bigBlind) AS minbigblind
2498 ,max(gt.bigBlind) AS maxbigblind
2499 /*,<hcgametypeId> AS gtid*/
2500 ,<position> AS plposition
2502 ,100.0*sum(cast(hp.street0VPI as <signed>integer))/count(1) AS vpip
2503 ,100.0*sum(cast(hp.street0Aggr as <signed>integer))/count(1) AS pfr
2504 ,case when sum(cast(hp.street0_3Bchance as <signed>integer)) = 0 then -999
2505 else 100.0*sum(cast(hp.street0_3Bdone as <signed>integer))/sum(cast(hp.street0_3Bchance as <signed>integer))
2507 ,case when sum(cast(hp.street0_4Bchance as <signed>integer)) = 0 then -999
2508 else 100.0*sum(cast(hp.street0_4Bdone as <signed>integer))/sum(cast(hp.street0_4Bchance as <signed>integer))
2510 ,case when sum(cast(hp.street0_FoldTo3Bchance as <signed>integer)) = 0 then -999
2511 else 100.0*sum(cast(hp.street0_FoldTo3Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo3Bchance as <signed>integer))
2513 ,case when sum(cast(hp.street0_FoldTo4Bchance as <signed>integer)) = 0 then -999
2514 else 100.0*sum(cast(hp.street0_FoldTo4Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo4Bchance as <signed>integer))
2517 ,case when sum(cast(hp.raiseFirstInChance as <signed>integer)) = 0 then -999
2518 else 100.0 * sum(cast(hp.raisedFirstIn as <signed>integer)) /
2519 sum(cast(hp.raiseFirstInChance as <signed>integer))
2521 ,case when sum(case hp.position
2522 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2523 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2524 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2529 sum(case hp.position
2530 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2531 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2532 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2536 sum(case hp.position
2537 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2538 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2539 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2544 ,case when sum(cast(hp.success_Steal as <signed>integer)) = 0 then -999
2546 sum(cast(hp.success_Steal as <signed>integer))
2548 sum(case hp.position
2549 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2550 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2551 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2556 ,100.0*sum(cast(hp.street1Seen as <signed>integer))/count(1) AS saw_f
2557 ,100.0*sum(cast(hp.sawShowdown as <signed>integer))/count(1) AS sawsd
2558 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2559 else 100.0*sum(cast(hp.sawShowdown as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2561 ,case when sum(cast(hp.sawShowdown as <signed>integer)) = 0 then -999
2562 else 100.0*sum(cast(hp.wonAtSD as <signed>integer))/sum(cast(hp.sawShowdown as <signed>integer))
2564 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2565 else 100.0*sum(cast(hp.street1Aggr as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2567 ,case when sum(cast(hp.street2Seen as <signed>integer)) = 0 then -999
2568 else 100.0*sum(cast(hp.street2Aggr as <signed>integer))/sum(cast(hp.street2Seen as <signed>integer))
2570 ,case when sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
2571 else 100.0*sum(cast(hp.street3Aggr as <signed>integer))/sum(cast(hp.street3Seen as <signed>integer))
2573 ,case when sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
2574 else 100.0*(sum(cast(hp.street1Aggr as <signed>integer))+sum(cast(hp.street2Aggr as <signed>integer))+sum(cast(hp.street3Aggr as <signed>integer)))
2575 /(sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)))
2577 ,case when sum(cast(hp.street1Calls as <signed>integer))+ sum(cast(hp.street2Calls as <signed>integer))+ sum(cast(hp.street3Calls as <signed>integer))+ sum(cast(hp.street4Calls as <signed>integer)) = 0 then -999
2578 else (sum(cast(hp.street1Aggr as <signed>integer)) + sum(cast(hp.street2Aggr as <signed>integer)) + sum(cast(hp.street3Aggr as <signed>integer)) + sum(cast(hp.street4Aggr as <signed>integer)))
2579 /(0.0+sum(cast(hp.street1Calls as <signed>integer))+ sum(cast(hp.street2Calls as <signed>integer))+ sum(cast(hp.street3Calls as <signed>integer))+ sum(cast(hp.street4Calls as <signed>integer)))
2581 ,100.0*(sum(cast(hp.street1Aggr as <signed>integer)) + sum(cast(hp.street2Aggr as <signed>integer)) + sum(cast(hp.street3Aggr as <signed>integer)) + sum(cast(hp.street4Aggr as <signed>integer)))
2582 / ((sum(cast(hp.foldToOtherRaisedStreet1 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet2 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet3 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet4 as <signed>integer))) +
2583 (sum(cast(hp.street1Calls as <signed>integer))+ sum(cast(hp.street2Calls as <signed>integer))+ sum(cast(hp.street3Calls as <signed>integer))+ sum(cast(hp.street4Calls as <signed>integer))) +
2584 (sum(cast(hp.street1Aggr as <signed>integer)) + sum(cast(hp.street2Aggr as <signed>integer)) + sum(cast(hp.street3Aggr as <signed>integer)) + sum(cast(hp.street4Aggr as <signed>integer))) )
2586 ,100.0*(sum(cast(hp.street1CBDone as <signed>integer)) + sum(cast(hp.street2CBDone as <signed>integer)) + sum(cast(hp.street3CBDone as <signed>integer)) + sum(cast(hp.street4CBDone as <signed>integer)))
2587 / (sum(cast(hp.street1CBChance as <signed>integer))+ sum(cast(hp.street2CBChance as <signed>integer))+ sum(cast(hp.street3CBChance as <signed>integer))+ sum(cast(hp.street4CBChance as <signed>integer)))
2589 ,sum(hp.totalProfit)/100.0 AS net
2590 ,sum(hp.rake)/100.0 AS rake
2591 ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100
2592 ,avg(hp.totalProfit)/100.0 AS profitperhand
2593 ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr
2594 ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr
2595 ,avg(h.seats+0.0) AS avgseats
2596 ,variance(hp.totalProfit/100.0) AS variance
2597 from HandsPlayers hp
2598 inner join Hands h on (h.id = hp.handId)
2599 inner join Gametypes gt on (gt.Id = h.gametypeId)
2600 inner join Sites s on (s.Id = gt.siteId)
2601 inner join Players p on (p.Id = hp.playerId)
2602 where hp.playerId in <player_test>
2605 /*and hp.tourneysPlayersId IS NULL*/
2606 and h.seats <seats_test>
2610 and date_format(h.startTime, '%Y-%m-%d %T') <datestest>
2611 group by hgametypeId
2617 ,upper(gt.limitType)
2619 having 1 = 1 <havingclause>
2624 ,case <position> when 'B' then 'B'
2626 else concat('Z', <position>)
2628 <orderbyhgametypeId>
2629 ,upper(gt.limitType) desc
2633 elif db_server
== 'postgresql':
2634 self
.query
['playerDetailedStats'] = """
2635 select <hgametypeId> AS hgametypeid
2636 ,<playerName> AS pname
2639 ,upper(gt.limitType) AS limittype
2641 ,min(gt.bigBlind) AS minbigblind
2642 ,max(gt.bigBlind) AS maxbigblind
2643 /*,<hcgametypeId> AS gtid*/
2644 ,<position> AS plposition
2646 ,100.0*sum(cast(hp.street0VPI as <signed>integer))/count(1) AS vpip
2647 ,100.0*sum(cast(hp.street0Aggr as <signed>integer))/count(1) AS pfr
2648 ,case when sum(cast(hp.street0_3Bchance as <signed>integer)) = 0 then -999
2649 else 100.0*sum(cast(hp.street0_3Bdone as <signed>integer))/sum(cast(hp.street0_3Bchance as <signed>integer))
2651 ,case when sum(cast(hp.street0_4Bchance as <signed>integer)) = 0 then -999
2652 else 100.0*sum(cast(hp.street0_4Bdone as <signed>integer))/sum(cast(hp.street0_4Bchance as <signed>integer))
2654 ,case when sum(cast(hp.street0_FoldTo3Bchance as <signed>integer)) = 0 then -999
2655 else 100.0*sum(cast(hp.street0_FoldTo3Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo3Bchance as <signed>integer))
2657 ,case when sum(cast(hp.street0_FoldTo4Bchance as <signed>integer)) = 0 then -999
2658 else 100.0*sum(cast(hp.street0_FoldTo4Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo4Bchance as <signed>integer))
2660 ,case when sum(cast(hp.raiseFirstInChance as <signed>integer)) = 0 then -999
2661 else 100.0 * sum(cast(hp.raisedFirstIn as <signed>integer)) /
2662 sum(cast(hp.raiseFirstInChance as <signed>integer))
2664 ,case when sum(case hp.position
2665 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2666 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2667 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2672 sum(case hp.position
2673 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2674 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2675 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2679 sum(case hp.position
2680 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2681 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2682 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2687 ,case when sum(cast(hp.success_Steal as <signed>integer)) = 0 then -999
2689 sum(cast(hp.success_Steal as <signed>integer))
2691 sum(case hp.position
2692 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2693 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2694 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2699 ,100.0*sum(cast(hp.street1Seen as <signed>integer))/count(1) AS saw_f
2700 ,100.0*sum(cast(hp.sawShowdown as <signed>integer))/count(1) AS sawsd
2701 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2702 else 100.0*sum(cast(hp.sawShowdown as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2704 ,case when sum(cast(hp.sawShowdown as <signed>integer)) = 0 then -999
2705 else 100.0*sum(cast(hp.wonAtSD as <signed>integer))/sum(cast(hp.sawShowdown as <signed>integer))
2707 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2708 else 100.0*sum(cast(hp.street1Aggr as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2710 ,case when sum(cast(hp.street2Seen as <signed>integer)) = 0 then -999
2711 else 100.0*sum(cast(hp.street2Aggr as <signed>integer))/sum(cast(hp.street2Seen as <signed>integer))
2713 ,case when sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
2714 else 100.0*sum(cast(hp.street3Aggr as <signed>integer))/sum(cast(hp.street3Seen as <signed>integer))
2716 ,case when sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
2717 else 100.0*(sum(cast(hp.street1Aggr as <signed>integer))+sum(cast(hp.street2Aggr as <signed>integer))+sum(cast(hp.street3Aggr as <signed>integer)))
2718 /(sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)))
2720 ,case when sum(cast(hp.street1Calls as <signed>integer))+ sum(cast(hp.street2Calls as <signed>integer))+ sum(cast(hp.street3Calls as <signed>integer))+ sum(cast(hp.street4Calls as <signed>integer)) = 0 then -999
2721 else (sum(cast(hp.street1Aggr as <signed>integer)) + sum(cast(hp.street2Aggr as <signed>integer)) + sum(cast(hp.street3Aggr as <signed>integer)) + sum(cast(hp.street4Aggr as <signed>integer)))
2722 /(0.0+sum(cast(hp.street1Calls as <signed>integer))+ sum(cast(hp.street2Calls as <signed>integer))+ sum(cast(hp.street3Calls as <signed>integer))+ sum(cast(hp.street4Calls as <signed>integer)))
2725 sum(cast(hp.foldToOtherRaisedStreet1 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet2 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet3 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet4 as <signed>integer))+
2726 sum(cast(hp.street1Calls as <signed>integer))+ sum(cast(hp.street2Calls as <signed>integer))+ sum(cast(hp.street3Calls as <signed>integer))+ sum(cast(hp.street4Calls as <signed>integer))+
2727 sum(cast(hp.street1Aggr as <signed>integer))+ sum(cast(hp.street2Aggr as <signed>integer))+ sum(cast(hp.street3Aggr as <signed>integer))+ sum(cast(hp.street4Aggr as <signed>integer))
2730 100.0*(sum(cast(hp.street1Aggr as <signed>integer)) + sum(cast(hp.street2Aggr as <signed>integer)) + sum(cast(hp.street3Aggr as <signed>integer)) + sum(cast(hp.street4Aggr as <signed>integer)))
2731 / ((sum(cast(hp.foldToOtherRaisedStreet1 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet2 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet3 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet4 as <signed>integer))) +
2732 (sum(cast(hp.street1Calls as <signed>integer))+ sum(cast(hp.street2Calls as <signed>integer))+ sum(cast(hp.street3Calls as <signed>integer))+ sum(cast(hp.street4Calls as <signed>integer))) +
2733 (sum(cast(hp.street1Aggr as <signed>integer)) + sum(cast(hp.street2Aggr as <signed>integer)) + sum(cast(hp.street3Aggr as <signed>integer)) + sum(cast(hp.street4Aggr as <signed>integer))) )
2736 sum(cast(hp.street1CBChance as <signed>integer))+
2737 sum(cast(hp.street2CBChance as <signed>integer))+
2738 sum(cast(hp.street3CBChance as <signed>integer))+
2739 sum(cast(hp.street4CBChance as <signed>integer)) = 0 then -999
2741 100.0*(sum(cast(hp.street1CBDone as <signed>integer)) + sum(cast(hp.street2CBDone as <signed>integer)) + sum(cast(hp.street3CBDone as <signed>integer)) + sum(cast(hp.street4CBDone as <signed>integer)))
2742 / (sum(cast(hp.street1CBChance as <signed>integer))+ sum(cast(hp.street2CBChance as <signed>integer))+ sum(cast(hp.street3CBChance as <signed>integer))+ sum(cast(hp.street4CBChance as <signed>integer)))
2744 ,sum(hp.totalProfit)/100.0 AS net
2745 ,sum(hp.rake)/100.0 AS rake
2746 ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100
2747 ,avg(hp.totalProfit)/100.0 AS profitperhand
2748 ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr
2749 ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr
2750 ,avg(h.seats+0.0) AS avgseats
2751 ,variance(hp.totalProfit/100.0) AS variance
2752 from HandsPlayers hp
2753 inner join Hands h on (h.id = hp.handId)
2754 inner join Gametypes gt on (gt.Id = h.gametypeId)
2755 inner join Sites s on (s.Id = gt.siteId)
2756 inner join Players p on (p.Id = hp.playerId)
2757 where hp.playerId in <player_test>
2760 /*and hp.tourneysPlayersId IS NULL*/
2761 and h.seats <seats_test>
2765 and to_char(h.startTime, 'YYYY-MM-DD HH24:MI:SS') <datestest>
2766 group by hgametypeId
2772 ,upper(gt.limitType)
2774 having 1 = 1 <havingclause>
2779 ,case <position> when 'B' then 'B'
2782 else 'Z'||<position>
2784 <orderbyhgametypeId>
2785 ,upper(gt.limitType) desc
2789 elif db_server
== 'sqlite':
2790 self
.query
['playerDetailedStats'] = """
2791 select <hgametypeId> AS hgametypeid
2792 ,<playerName> AS pname
2794 ,gt.category AS category
2795 ,upper(gt.limitType) AS limittype
2797 ,min(gt.bigBlind) AS minbigblind
2798 ,max(gt.bigBlind) AS maxbigblind
2799 /*,<hcgametypeId> AS gtid*/
2800 ,<position> AS plposition
2802 ,100.0*sum(cast(hp.street0VPI as <signed>integer))/count(1) AS vpip
2803 ,100.0*sum(cast(hp.street0Aggr as <signed>integer))/count(1) AS pfr
2804 ,case when sum(cast(hp.street0_3Bchance as <signed>integer)) = 0 then -999
2805 else 100.0*sum(cast(hp.street0_3Bdone as <signed>integer))/sum(cast(hp.street0_3Bchance as <signed>integer))
2807 ,case when sum(cast(hp.street0_4Bchance as <signed>integer)) = 0 then -999
2808 else 100.0*sum(cast(hp.street0_4Bdone as <signed>integer))/sum(cast(hp.street0_4Bchance as <signed>integer))
2810 ,case when sum(cast(hp.street0_FoldTo3Bchance as <signed>integer)) = 0 then -999
2811 else 100.0*sum(cast(hp.street0_FoldTo3Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo3Bchance as <signed>integer))
2813 ,case when sum(cast(hp.street0_FoldTo4Bchance as <signed>integer)) = 0 then -999
2814 else 100.0*sum(cast(hp.street0_FoldTo4Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo4Bchance as <signed>integer))
2816 ,case when sum(cast(hp.raiseFirstInChance as <signed>integer)) = 0 then -999
2817 else 100.0 * sum(cast(hp.raisedFirstIn as <signed>integer)) /
2818 sum(cast(hp.raiseFirstInChance as <signed>integer))
2820 ,case when sum(case hp.position
2821 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2822 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2823 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2828 sum(case hp.position
2829 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2830 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2831 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2835 sum(case hp.position
2836 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2837 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2838 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2843 ,case when sum(cast(hp.success_Steal as <signed>integer)) = 0 then -999
2845 sum(cast(hp.success_Steal as <signed>integer))
2847 sum(case hp.position
2848 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2849 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2850 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2855 ,100.0*sum(cast(hp.street1Seen as <signed>integer))/count(1) AS saw_f
2856 ,100.0*sum(cast(hp.sawShowdown as <signed>integer))/count(1) AS sawsd
2857 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2858 else 100.0*sum(cast(hp.sawShowdown as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2860 ,case when sum(cast(hp.sawShowdown as <signed>integer)) = 0 then -999
2861 else 100.0*sum(cast(hp.wonAtSD as <signed>integer))/sum(cast(hp.sawShowdown as <signed>integer))
2863 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2864 else 100.0*sum(cast(hp.street1Aggr as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2866 ,case when sum(cast(hp.street2Seen as <signed>integer)) = 0 then -999
2867 else 100.0*sum(cast(hp.street2Aggr as <signed>integer))/sum(cast(hp.street2Seen as <signed>integer))
2869 ,case when sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
2870 else 100.0*sum(cast(hp.street3Aggr as <signed>integer))/sum(cast(hp.street3Seen as <signed>integer))
2872 ,case when sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
2873 else 100.0*(sum(cast(hp.street1Aggr as <signed>integer))+sum(cast(hp.street2Aggr as <signed>integer))+sum(cast(hp.street3Aggr as <signed>integer)))
2874 /(sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)))
2876 ,case when sum(cast(hp.street1Calls as <signed>integer))+ sum(cast(hp.street2Calls as <signed>integer))+ sum(cast(hp.street3Calls as <signed>integer))+ sum(cast(hp.street4Calls as <signed>integer)) = 0 then -999
2877 else (sum(cast(hp.street1Aggr as <signed>integer)) + sum(cast(hp.street2Aggr as <signed>integer)) + sum(cast(hp.street3Aggr as <signed>integer)) + sum(cast(hp.street4Aggr as <signed>integer)))
2878 /(0.0+sum(cast(hp.street1Calls as <signed>integer))+ sum(cast(hp.street2Calls as <signed>integer))+ sum(cast(hp.street3Calls as <signed>integer))+ sum(cast(hp.street4Calls as <signed>integer)))
2880 ,100.0*(sum(cast(hp.street1Aggr as <signed>integer)) + sum(cast(hp.street2Aggr as <signed>integer)) + sum(cast(hp.street3Aggr as <signed>integer)) + sum(cast(hp.street4Aggr as <signed>integer)))
2881 / ((sum(cast(hp.foldToOtherRaisedStreet1 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet2 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet3 as <signed>integer))+ sum(cast(hp.foldToOtherRaisedStreet4 as <signed>integer))) +
2882 (sum(cast(hp.street1Calls as <signed>integer))+ sum(cast(hp.street2Calls as <signed>integer))+ sum(cast(hp.street3Calls as <signed>integer))+ sum(cast(hp.street4Calls as <signed>integer))) +
2883 (sum(cast(hp.street1Aggr as <signed>integer)) + sum(cast(hp.street2Aggr as <signed>integer)) + sum(cast(hp.street3Aggr as <signed>integer)) + sum(cast(hp.street4Aggr as <signed>integer))) )
2885 ,100.0*(sum(cast(hp.street1CBDone as <signed>integer)) + sum(cast(hp.street2CBDone as <signed>integer)) + sum(cast(hp.street3CBDone as <signed>integer)) + sum(cast(hp.street4CBDone as <signed>integer)))
2886 / (sum(cast(hp.street1CBChance as <signed>integer))+ sum(cast(hp.street2CBChance as <signed>integer))+ sum(cast(hp.street3CBChance as <signed>integer))+ sum(cast(hp.street4CBChance as <signed>integer)))
2888 ,sum(hp.totalProfit)/100.0 AS net
2889 ,sum(hp.rake)/100.0 AS rake
2890 ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100
2891 ,avg(hp.totalProfit)/100.0 AS profitperhand
2892 ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr
2893 ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr
2894 ,avg(h.seats+0.0) AS avgseats
2895 ,variance(hp.totalProfit/100.0) AS variance
2896 from HandsPlayers hp
2897 inner join Hands h on (h.id = hp.handId)
2898 inner join Gametypes gt on (gt.Id = h.gametypeId)
2899 inner join Sites s on (s.Id = gt.siteId)
2900 inner join Players p on (p.Id = hp.playerId)
2901 where hp.playerId in <player_test>
2904 /*and hp.tourneysPlayersId IS NULL*/
2905 and h.seats <seats_test>
2909 and datetime(h.startTime) <datestest>
2910 group by hgametypeId
2916 ,upper(gt.limitType)
2918 having 1 = 1 <havingclause>
2919 order by hp.playerId
2923 ,case <position> when 'B' then 'B'
2926 else 'Z'||<position>
2928 <orderbyhgametypeId>
2929 ,upper(gt.limitType) desc
2930 ,max(gt.bigBlind) desc
2934 #FIXME: 3/4bet and foldTo don't added four tournaments yet
2935 if db_server
== 'mysql':
2936 self
.query
['tourneyPlayerDetailedStats'] = """
2937 select s.name AS siteName
2938 ,t.tourneyTypeId AS tourneyTypeId
2939 ,tt.currency AS currency
2941 WHEN tt.currency = 'USD' THEN tt.buyIn/100.0
2942 WHEN tt.currency = 'EUR' THEN tt.buyIn/100.0
2945 ,tt.fee/100.0 AS fee
2946 ,tt.category AS category
2947 ,tt.limitType AS limitType
2948 ,p.name AS playerName
2949 ,COUNT(1) AS tourneyCount
2950 ,SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END) AS unknownRank
2951 ,SUM(CASE WHEN winnings > 0 THEN 1 ELSE 0 END)/(COUNT(1) - SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END)) AS itm
2952 ,SUM(CASE WHEN rank = 1 THEN 1 ELSE 0 END) AS _1st
2953 ,SUM(CASE WHEN rank = 2 THEN 1 ELSE 0 END) AS _2nd
2954 ,SUM(CASE WHEN rank = 3 THEN 1 ELSE 0 END) AS _3rd
2955 ,SUM(tp.winnings)/100.0 AS won
2956 ,SUM(CASE WHEN tt.currency = 'USD' THEN (tt.buyIn+tt.fee)/100.0 WHEN tt.currency = 'EUR' THEN (tt.buyIn+tt.fee)/100.0 ELSE tt.buyIn END) AS spent
2957 ,SUM(tp.winnings)/SUM(tt.buyin+tt.fee)*100.0-100 AS roi
2958 ,SUM(tp.winnings-(tt.buyin+tt.fee))/100.0/(COUNT(1)-SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END)) AS profitPerTourney
2959 from TourneysPlayers tp
2960 inner join Tourneys t on (t.id = tp.tourneyId)
2961 inner join TourneyTypes tt on (tt.Id = t.tourneyTypeId)
2962 inner join Sites s on (s.Id = tt.siteId)
2963 inner join Players p on (p.Id = tp.playerId)
2964 where tp.playerId in <nametest> <sitetest>
2965 and date_format(t.startTime, '%Y-%m-%d %T') <datestest>
2966 group by tourneyTypeId, playerName
2967 order by tourneyTypeId
2970 elif db_server
== 'postgresql':
2971 # sc: itm and profitPerTourney changed to "ELSE 0" to avoid divide by zero error as temp fix
2972 # proper fix should use coalesce() or case ... when ... to work in all circumstances
2973 self
.query
['tourneyPlayerDetailedStats'] = """
2974 select s.name AS "siteName"
2975 ,t.tourneyTypeId AS "tourneyTypeId"
2976 ,tt.currency AS "currency"
2978 WHEN tt.currency = 'USD' THEN tt.buyIn/100.0
2979 WHEN tt.currency = 'EUR' THEN tt.buyIn/100.0
2982 ,tt.fee/100.0 AS "fee"
2983 ,tt.category AS "category"
2984 ,tt.limitType AS "limitType"
2985 ,p.name AS "playerName"
2986 ,COUNT(1) AS "tourneyCount"
2987 ,SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END) AS "unknownRank"
2988 ,SUM(CASE WHEN winnings > 0 THEN 1 ELSE 0 END)
2989 /(COUNT(1) - SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 0 END)) AS "itm"
2990 ,SUM(CASE WHEN rank = 1 THEN 1 ELSE 0 END) AS "_1st"
2991 ,SUM(CASE WHEN rank = 2 THEN 1 ELSE 0 END) AS "_2nd"
2992 ,SUM(CASE WHEN rank = 3 THEN 1 ELSE 0 END) AS "_3rd"
2993 ,SUM(tp.winnings)/100.0 AS "won"
2994 ,SUM(CASE WHEN tt.currency = 'USD' THEN (tt.buyIn+tt.fee)/100.0 ELSE tt.buyIn END) AS "spent"
2995 ,SUM(tp.winnings)/SUM(tt.buyin+tt.fee)*100.0-100 AS "roi"
2996 ,SUM(tp.winnings-(tt.buyin+tt.fee))/100.0
2997 /(COUNT(1)-SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 0 END)) AS "profitPerTourney"
2998 from TourneysPlayers tp
2999 inner join Tourneys t on (t.id = tp.tourneyId)
3000 inner join TourneyTypes tt on (tt.Id = t.tourneyTypeId)
3001 inner join Sites s on (s.Id = tt.siteId)
3002 inner join Players p on (p.Id = tp.playerId)
3003 where tp.playerId in <nametest> <sitetest>
3004 and to_char(t.startTime, 'YYYY-MM-DD HH24:MI:SS') <datestest>
3005 group by t.tourneyTypeId, s.name, p.name, tt.currency, tt.buyin, tt.fee
3006 , tt.category, tt.limitType
3007 order by t.tourneyTypeId
3010 elif db_server
== 'sqlite':
3011 self
.query
['tourneyPlayerDetailedStats'] = """
3012 select s.name AS siteName
3013 ,t.tourneyTypeId AS tourneyTypeId
3014 ,tt.currency AS currency
3016 WHEN tt.currency = 'USD' THEN tt.buyIn/100.0
3017 WHEN tt.currency = 'EUR' THEN tt.buyIn/100.0
3020 ,tt.fee/100.0 AS fee
3021 ,tt.category AS category
3022 ,tt.limitType AS limitType
3023 ,p.name AS playerName
3024 ,COUNT(1) AS tourneyCount
3025 ,SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END) AS unknownRank
3026 ,SUM(CASE WHEN winnings > 0 THEN 1 ELSE 0 END)/(COUNT(1) - SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END)) AS itm
3027 ,SUM(CASE WHEN rank = 1 THEN 1 ELSE 0 END) AS _1st
3028 ,SUM(CASE WHEN rank = 2 THEN 1 ELSE 0 END) AS _2nd
3029 ,SUM(CASE WHEN rank = 3 THEN 1 ELSE 0 END) AS _3rd
3030 ,SUM(tp.winnings)/100.0 AS won
3031 ,SUM(CASE WHEN tt.currency = 'USD' THEN (tt.buyIn+tt.fee)/100.0 ELSE tt.buyIn END) AS spent
3032 ,SUM(tp.winnings)/SUM(tt.buyin+tt.fee)*100.0-100 AS roi
3033 ,SUM(tp.winnings-(tt.buyin+tt.fee))/100.0/(COUNT(1)-SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END)) AS profitPerTourney
3034 from TourneysPlayers tp
3035 inner join Tourneys t on (t.id = tp.tourneyId)
3036 inner join TourneyTypes tt on (tt.Id = t.tourneyTypeId)
3037 inner join Sites s on (s.Id = tt.siteId)
3038 inner join Players p on (p.Id = tp.playerId)
3039 where tp.playerId in <nametest> <sitetest>
3040 and datetime(t.startTime) <datestest>
3041 group by tourneyTypeId, playerName
3042 order by tourneyTypeId
3046 if db_server
== 'mysql':
3047 self
.query
['playerStats'] = """
3049 concat(upper(stats.limitType), ' '
3050 ,concat(upper(substring(stats.category,1,1)),substring(stats.category,2) ), ' '
3052 ,cast(stats.bigBlindDesc as char)
3072 ,stats.Profitperhand
3073 ,case when hprof2.variance = -999 then '-'
3074 else format(hprof2.variance, 2)
3078 (select /* stats from hudcache */
3081 ,upper(gt.limitType) as limitType
3083 ,<selectgt.bigBlind> AS bigBlindDesc
3084 ,<hcgametypeId> AS gtId
3086 ,format(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
3087 ,format(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
3088 ,case when sum(street0_3Bchance) = 0 then '0'
3089 else format(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
3091 ,case when sum(street0_4Bchance) = 0 then '0'
3092 else format(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
3094 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
3095 else format(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
3097 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
3098 else format(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
3100 ,case when sum(raiseFirstInChance) = 0 then '-'
3101 else format(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
3103 ,format(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
3104 ,format(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
3105 ,case when sum(street1Seen) = 0 then '-'
3106 else format(100.0*sum(sawShowdown)/sum(street1Seen),1)
3108 ,case when sum(sawShowdown) = 0 then '-'
3109 else format(100.0*sum(wonAtSD)/sum(sawShowdown),1)
3111 ,case when sum(street1Seen) = 0 then '-'
3112 else format(100.0*sum(street1Aggr)/sum(street1Seen),1)
3114 ,case when sum(street2Seen) = 0 then '-'
3115 else format(100.0*sum(street2Aggr)/sum(street2Seen),1)
3117 ,case when sum(street3Seen) = 0 then '-'
3118 else format(100.0*sum(street3Aggr)/sum(street3Seen),1)
3120 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3121 else format(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3122 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
3124 ,format(sum(totalProfit)/100.0,2) AS Net
3125 ,format((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
3127 ,format( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
3128 ,format( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
3130 inner join Sites s on s.Id = gt.siteId
3131 inner join HudCache hc on hc.gametypeId = gt.Id
3132 where hc.playerId in <player_test>
3133 and <gtbigBlind_test>
3134 and hc.activeSeats <seats_test>
3135 and concat( '20', substring(hc.styleKey,2,2), '-', substring(hc.styleKey,4,2), '-'
3136 , substring(hc.styleKey,6,2) ) <datestest>
3139 ,upper(gt.limitType)
3141 <groupbygt.bigBlind>
3145 ( select # profit from handsplayers/handsactions
3146 hprof.gtId, sum(hprof.profit) sum_profit,
3147 avg(hprof.profit/100.0) profitperhand,
3148 case when hprof.gtId = -1 then -999
3149 else variance(hprof.profit/100.0)
3152 (select hp.handId, <hgametypeId> as gtId, hp.totalProfit as profit
3153 from HandsPlayers hp
3154 inner join Hands h ON h.id = hp.handId
3155 where hp.playerId in <player_test>
3156 and hp.tourneysPlayersId IS NULL
3157 and date_format(h.startTime, '%Y-%m-%d') <datestest>
3158 group by hp.handId, gtId, hp.totalProfit
3162 on hprof2.gtId = stats.gtId
3163 order by stats.category, stats.limittype, stats.bigBlindDesc desc <orderbyseats>"""
3164 elif db_server
== 'sqlite':
3165 self
.query
['playerStats'] = """
3167 upper(substr(stats.category,1,1)) || substr(stats.category,2) || ' ' ||
3168 stats.name || ' ' ||
3169 cast(stats.bigBlindDesc as char) || ' ' || stats.maxSeats || ' seat' AS Game
3170 ,stats.n,stats.vpip,stats.pfr,stats.pf3,stats.pf4,stats.pff3,stats.pff4
3171 ,stats.steals,stats.saw_f,stats.sawsd,stats.wtsdwsf,stats.wmsd,stats.FlAFq
3172 ,stats.TuAFq,stats.RvAFq,stats.PoFAFq,stats.Net,stats.BBper100,stats.Profitperhand
3173 ,case when hprof2.variance = -999 then '-' else round(hprof2.variance, 2)
3177 (select /* stats from hudcache */
3179 ,gt.category,maxSeats,gt.bigBlind,gt.currency
3180 ,upper(gt.limitType) AS limitType
3182 ,<selectgt.bigBlind> AS bigBlindDesc
3183 ,<hcgametypeId> AS gtId
3185 ,round(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
3186 ,round(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
3187 ,case when sum(street0_3Bchance) = 0 then '0'
3188 else round(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
3190 ,case when sum(street0_4Bchance) = 0 then '0'
3191 else round(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
3193 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
3194 else round(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
3196 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
3197 else round(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
3199 ,case when sum(raiseFirstInChance) = 0 then '-'
3200 else round(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
3202 ,round(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
3203 ,round(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
3204 ,case when sum(street1Seen) = 0 then '-'
3205 else round(100.0*sum(sawShowdown)/sum(street1Seen),1)
3207 ,case when sum(sawShowdown) = 0 then '-'
3208 else round(100.0*sum(wonAtSD)/sum(sawShowdown),1)
3210 ,case when sum(street1Seen) = 0 then '-'
3211 else round(100.0*sum(street1Aggr)/sum(street1Seen),1)
3213 ,case when sum(street2Seen) = 0 then '-'
3214 else round(100.0*sum(street2Aggr)/sum(street2Seen),1)
3216 ,case when sum(street3Seen) = 0 then '-'
3217 else round(100.0*sum(street3Aggr)/sum(street3Seen),1)
3219 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3220 else round(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3221 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
3223 ,round(sum(totalProfit)/100.0,2) AS Net
3224 ,round((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
3226 ,round( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
3227 ,round( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
3229 inner join Sites s on s.Id = gt.siteId
3230 inner join HudCache hc on hc.gametypeId = gt.Id
3231 where hc.playerId in <player_test>
3232 and <gtbigBlind_test>
3233 and hc.activeSeats <seats_test>
3234 and '20' || substr(hc.styleKey,2,2) || '-' || substr(hc.styleKey,4,2) || '-' ||
3235 substr(hc.styleKey,6,2) <datestest>
3236 group by gt.base,gt.category,upper(gt.limitType),s.name <groupbygt.bigBlind>,gtId
3239 ( select /* profit from handsplayers/handsactions */
3240 hprof.gtId, sum(hprof.profit) sum_profit,
3241 avg(hprof.profit/100.0) profitperhand,
3242 case when hprof.gtId = -1 then -999
3243 else variance(hprof.profit/100.0)
3246 (select hp.handId, <hgametypeId> as gtId, hp.totalProfit as profit
3247 from HandsPlayers hp
3248 inner join Hands h ON h.id = hp.handId
3249 where hp.playerId in <player_test>
3250 and hp.tourneysPlayersId IS NULL
3251 and datetime(h.startTime) <datestest>
3252 group by hp.handId, gtId, hp.totalProfit
3256 on hprof2.gtId = stats.gtId
3257 order by stats.category, stats.bigBlind, stats.limittype, stats.currency, stats.maxSeats <orderbyseats>"""
3258 else: # assume postgres
3259 self
.query
['playerStats'] = """
3260 SELECT upper(stats.limitType) || ' '
3261 || initcap(stats.category) || ' '
3262 || stats.name || ' '
3263 || stats.bigBlindDesc AS Game
3282 ,stats.Profitperhand
3283 ,case when hprof2.variance = -999 then '-'
3284 else to_char(hprof2.variance, '0D00')
3290 ,upper(gt.limitType) AS limitType
3292 ,<selectgt.bigBlind> AS bigBlindDesc
3293 ,<hcgametypeId> AS gtId
3295 ,to_char(100.0*sum(street0VPI)/sum(HDs),'990D0') AS vpip
3296 ,to_char(100.0*sum(street0Aggr)/sum(HDs),'90D0') AS pfr
3297 ,case when sum(street0_3Bchance) = 0 then '0'
3298 else to_char(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),'90D0')
3300 ,case when sum(raiseFirstInChance) = 0 then '-'
3301 else to_char(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),'90D0')
3303 ,to_char(100.0*sum(street1Seen)/sum(HDs),'90D0') AS saw_f
3304 ,to_char(100.0*sum(sawShowdown)/sum(HDs),'90D0') AS sawsd
3305 ,case when sum(street1Seen) = 0 then '-'
3306 else to_char(100.0*sum(sawShowdown)/sum(street1Seen),'90D0')
3308 ,case when sum(sawShowdown) = 0 then '-'
3309 else to_char(100.0*sum(wonAtSD)/sum(sawShowdown),'90D0')
3311 ,case when sum(street1Seen) = 0 then '-'
3312 else to_char(100.0*sum(street1Aggr)/sum(street1Seen),'90D0')
3314 ,case when sum(street2Seen) = 0 then '-'
3315 else to_char(100.0*sum(street2Aggr)/sum(street2Seen),'90D0')
3317 ,case when sum(street3Seen) = 0 then '-'
3318 else to_char(100.0*sum(street3Aggr)/sum(street3Seen),'90D0')
3320 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3321 else to_char(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3322 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),'90D0')
3324 ,round(sum(totalProfit)/100.0,2) AS Net
3325 ,to_char((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0), '990D00')
3327 ,to_char(sum(totalProfit/100.0) / (sum(HDs)+0.0), '990D0000') AS Profitperhand
3328 ,to_char(sum(activeSeats*HDs)/(sum(HDs)+0.0),'90D00') AS AvgSeats
3330 inner join Sites s on s.Id = gt.siteId
3331 inner join HudCache hc on hc.gametypeId = gt.Id
3332 where hc.playerId in <player_test>
3333 and <gtbigBlind_test>
3334 and hc.activeSeats <seats_test>
3335 and '20' || SUBSTR(hc.styleKey,2,2) || '-' || SUBSTR(hc.styleKey,4,2) || '-'
3336 || SUBSTR(hc.styleKey,6,2) <datestest>
3339 ,upper(gt.limitType)
3341 <groupbygt.bigBlind>
3346 hprof.gtId, sum(hprof.profit) AS sum_profit,
3347 avg(hprof.profit/100.0) AS profitperhand,
3348 case when hprof.gtId = -1 then -999
3349 else variance(hprof.profit/100.0)
3352 (select hp.handId, <hgametypeId> as gtId, hp.totalProfit as profit
3353 from HandsPlayers hp
3354 inner join Hands h ON (h.id = hp.handId)
3355 where hp.playerId in <player_test>
3356 and hp.tourneysPlayersId IS NULL
3357 and to_char(h.startTime, 'YYYY-MM-DD') <datestest>
3358 group by hp.handId, gtId, hp.totalProfit
3362 on hprof2.gtId = stats.gtId
3363 order by stats.base, stats.limittype, stats.bigBlindDesc desc <orderbyseats>"""
3365 if db_server
== 'mysql':
3366 self
.query
['playerStatsByPosition'] = """
3368 concat(upper(stats.limitType), ' '
3369 ,concat(upper(substring(stats.category,1,1)),substring(stats.category,2) ), ' '
3371 ,cast(stats.bigBlindDesc as char)
3373 ,case when stats.PlPosition = -2 then 'BB'
3374 when stats.PlPosition = -1 then 'SB'
3375 when stats.PlPosition = 0 then 'Btn'
3376 when stats.PlPosition = 1 then 'CO'
3377 when stats.PlPosition = 2 then 'MP'
3378 when stats.PlPosition = 5 then 'EP'
3399 ,stats.Profitperhand
3400 ,case when hprof2.variance = -999 then '-'
3401 else format(hprof2.variance, 2)
3405 (select /* stats from hudcache */
3408 ,upper(gt.limitType) AS limitType
3410 ,<selectgt.bigBlind> AS bigBlindDesc
3411 ,<hcgametypeId> AS gtId
3412 ,case when hc.position = 'B' then -2
3413 when hc.position = 'S' then -1
3414 when hc.position = 'D' then 0
3415 when hc.position = 'C' then 1
3416 when hc.position = 'M' then 2
3417 when hc.position = 'E' then 5
3421 ,format(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
3422 ,format(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
3423 ,case when sum(street0_3Bchance) = 0 then '0'
3424 else format(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
3426 ,case when sum(street0_4Bchance) = 0 then '0'
3427 else format(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
3429 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
3430 else format(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
3432 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
3433 else format(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
3435 ,case when sum(raiseFirstInChance) = 0 then '-'
3436 else format(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
3438 ,format(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
3439 ,format(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
3440 ,case when sum(street1Seen) = 0 then '-'
3441 else format(100.0*sum(sawShowdown)/sum(street1Seen),1)
3443 ,case when sum(sawShowdown) = 0 then '-'
3444 else format(100.0*sum(wonAtSD)/sum(sawShowdown),1)
3446 ,case when sum(street1Seen) = 0 then '-'
3447 else format(100.0*sum(street1Aggr)/sum(street1Seen),1)
3449 ,case when sum(street2Seen) = 0 then '-'
3450 else format(100.0*sum(street2Aggr)/sum(street2Seen),1)
3452 ,case when sum(street3Seen) = 0 then '-'
3453 else format(100.0*sum(street3Aggr)/sum(street3Seen),1)
3455 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3456 else format(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3457 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
3459 ,format(sum(totalProfit)/100.0,2) AS Net
3460 ,format((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
3462 ,format( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
3463 ,format( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
3465 inner join Sites s on s.Id = gt.siteId
3466 inner join HudCache hc on hc.gametypeId = gt.Id
3467 where hc.playerId in <player_test>
3468 and <gtbigBlind_test>
3469 and hc.activeSeats <seats_test>
3470 and concat( '20', substring(hc.styleKey,2,2), '-', substring(hc.styleKey,4,2), '-'
3471 , substring(hc.styleKey,6,2) ) <datestest>
3474 ,upper(gt.limitType)
3476 <groupbygt.bigBlind>
3482 ( select # profit from handsplayers/handsactions
3484 case when hprof.position = 'B' then -2
3485 when hprof.position = 'S' then -1
3486 when hprof.position in ('3','4') then 2
3487 when hprof.position in ('6','7') then 5
3490 sum(hprof.profit) as sum_profit,
3491 avg(hprof.profit/100.0) as profitperhand,
3492 case when hprof.gtId = -1 then -999
3493 else variance(hprof.profit/100.0)
3496 (select hp.handId, <hgametypeId> as gtId, hp.position
3497 , hp.totalProfit as profit
3498 from HandsPlayers hp
3499 inner join Hands h ON (h.id = hp.handId)
3500 where hp.playerId in <player_test>
3501 and hp.tourneysPlayersId IS NULL
3502 and date_format(h.startTime, '%Y-%m-%d') <datestest>
3503 group by hp.handId, gtId, hp.position, hp.totalProfit
3505 group by hprof.gtId, PlPosition
3507 on ( hprof2.gtId = stats.gtId
3508 and hprof2.PlPosition = stats.PlPosition)
3509 order by stats.category, stats.limitType, stats.bigBlindDesc desc
3510 <orderbyseats>, cast(stats.PlPosition as signed)
3512 elif db_server
== 'sqlite':
3513 self
.query
['playerStatsByPosition'] = """
3515 upper(substr(stats.category,1,1)) || substr(stats.category,2) || ' ' ||
3516 stats.name || ' ' ||
3517 cast(stats.bigBlindDesc as char) || ' ' || stats.maxSeats || ' seat' AS Game
3518 ,case when stats.PlPosition = -2 then 'BB'
3519 when stats.PlPosition = -1 then 'SB'
3520 when stats.PlPosition = 0 then 'Btn'
3521 when stats.PlPosition = 1 then 'CO'
3522 when stats.PlPosition = 2 then 'MP'
3523 when stats.PlPosition = 5 then 'EP'
3526 ,stats.n,stats.vpip,stats.pfr,stats.pf3,stats.pf4,stats.pff3,stats.pff4
3527 ,stats.steals,stats.saw_f,stats.sawsd,stats.wtsdwsf,stats.wmsd,stats.FlAFq
3528 ,stats.TuAFq,stats.RvAFq,stats.PoFAFq,stats.Net,stats.BBper100,stats.Profitperhand
3529 ,case when hprof2.variance = -999 then '-'
3530 else round(hprof2.variance, 2)
3534 (select /* stats from hudcache */
3536 ,gt.category,maxSeats,gt.bigBlind,gt.currency
3537 ,upper(gt.limitType) AS limitType
3539 ,<selectgt.bigBlind> AS bigBlindDesc
3540 ,<hcgametypeId> AS gtId
3541 ,case when hc.position = 'B' then -2
3542 when hc.position = 'S' then -1
3543 when hc.position = 'D' then 0
3544 when hc.position = 'C' then 1
3545 when hc.position = 'M' then 2
3546 when hc.position = 'E' then 5
3550 ,round(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
3551 ,round(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
3552 ,case when sum(street0_3Bchance) = 0 then '0'
3553 else round(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
3555 ,case when sum(street0_4Bchance) = 0 then '0'
3556 else round(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
3558 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
3559 else round(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
3561 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
3562 else round(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
3564 ,case when sum(raiseFirstInChance) = 0 then '-'
3565 else round(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
3567 ,round(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
3568 ,round(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
3569 ,case when sum(street1Seen) = 0 then '-'
3570 else round(100.0*sum(sawShowdown)/sum(street1Seen),1)
3572 ,case when sum(sawShowdown) = 0 then '-'
3573 else round(100.0*sum(wonAtSD)/sum(sawShowdown),1)
3575 ,case when sum(street1Seen) = 0 then '-'
3576 else round(100.0*sum(street1Aggr)/sum(street1Seen),1)
3578 ,case when sum(street2Seen) = 0 then '-'
3579 else round(100.0*sum(street2Aggr)/sum(street2Seen),1)
3581 ,case when sum(street3Seen) = 0 then '-'
3582 else round(100.0*sum(street3Aggr)/sum(street3Seen),1)
3584 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3585 else round(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3586 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
3588 ,round(sum(totalProfit)/100.0,2) AS Net
3589 ,round((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
3591 ,round( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
3592 ,round( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
3594 inner join Sites s on s.Id = gt.siteId
3595 inner join HudCache hc on hc.gametypeId = gt.Id
3596 where hc.playerId in <player_test>
3597 and <gtbigBlind_test>
3598 and hc.activeSeats <seats_test>
3599 and '20' || substr(hc.styleKey,2,2) || '-' || substr(hc.styleKey,4,2) || '-' ||
3600 substr(hc.styleKey,6,2) <datestest>
3601 group by gt.base,gt.category,upper(gt.limitType),s.name
3602 <groupbygt.bigBlind>,gtId<groupbyseats>,PlPosition
3605 ( select /* profit from handsplayers/handsactions */
3607 cast(case when hprof.position = 'B' then -2
3608 when hprof.position = 'S' then -1
3609 when hprof.position in ('3','4') then 2
3610 when hprof.position in ('6','7') then 5
3612 end as signed) as PlPosition,
3613 sum(hprof.profit) as sum_profit,
3614 avg(hprof.profit/100.0) as profitperhand,
3615 case when hprof.gtId = -1 then -999
3616 else variance(hprof.profit/100.0)
3619 (select hp.handId, <hgametypeId> as gtId, hp.position
3620 , hp.totalProfit as profit
3621 from HandsPlayers hp
3622 inner join Hands h ON (h.id = hp.handId)
3623 where hp.playerId in <player_test>
3624 and hp.tourneysPlayersId IS NULL
3625 and datetime(h.startTime) <datestest>
3626 group by hp.handId, gtId, hp.position, hp.totalProfit
3628 group by hprof.gtId, PlPosition
3630 on ( hprof2.gtId = stats.gtId
3631 and hprof2.PlPosition = stats.PlPosition)
3632 order by stats.category, stats.bigBlind, stats.limitType, stats.currency, stats.maxSeats <orderbyseats>
3633 ,cast(stats.PlPosition as signed)
3635 else: # assume postgresql
3636 self
.query
['playerStatsByPosition'] = """
3637 select /* stats from hudcache */
3638 upper(stats.limitType) || ' '
3639 || upper(substr(stats.category,1,1)) || substr(stats.category,2) || ' '
3640 || stats.name || ' '
3641 || stats.bigBlindDesc AS Game
3642 ,case when stats.PlPosition = -2 then 'BB'
3643 when stats.PlPosition = -1 then 'SB'
3644 when stats.PlPosition = 0 then 'Btn'
3645 when stats.PlPosition = 1 then 'CO'
3646 when stats.PlPosition = 2 then 'MP'
3647 when stats.PlPosition = 5 then 'EP'
3668 ,stats.Profitperhand
3669 ,case when hprof2.variance = -999 then '-'
3670 else to_char(hprof2.variance, '0D00')
3674 (select /* stats from hudcache */
3677 ,upper(gt.limitType) AS limitType
3679 ,<selectgt.bigBlind> AS bigBlindDesc
3680 ,<hcgametypeId> AS gtId
3681 ,case when hc.position = 'B' then -2
3682 when hc.position = 'S' then -1
3683 when hc.position = 'D' then 0
3684 when hc.position = 'C' then 1
3685 when hc.position = 'M' then 2
3686 when hc.position = 'E' then 5
3690 ,to_char(round(100.0*sum(street0VPI)/sum(HDs)),'990D0') AS vpip
3691 ,to_char(round(100.0*sum(street0Aggr)/sum(HDs)),'90D0') AS pfr
3692 ,case when sum(street0_3Bchance) = 0 then '0'
3693 else to_char(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),'90D0')
3695 ,case when sum(street0_4Bchance) = 0 then '0'
3696 else to_char(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),'90D0')
3698 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
3699 else to_char(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),'90D0')
3701 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
3702 else to_char(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),'90D0')
3704 ,case when sum(raiseFirstInChance) = 0 then '-'
3705 else to_char(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),'90D0')
3707 ,to_char(round(100.0*sum(street1Seen)/sum(HDs)),'90D0') AS saw_f
3708 ,to_char(round(100.0*sum(sawShowdown)/sum(HDs)),'90D0') AS sawsd
3709 ,case when sum(street1Seen) = 0 then '-'
3710 else to_char(round(100.0*sum(sawShowdown)/sum(street1Seen)),'90D0')
3712 ,case when sum(sawShowdown) = 0 then '-'
3713 else to_char(round(100.0*sum(wonAtSD)/sum(sawShowdown)),'90D0')
3715 ,case when sum(street1Seen) = 0 then '-'
3716 else to_char(round(100.0*sum(street1Aggr)/sum(street1Seen)),'90D0')
3718 ,case when sum(street2Seen) = 0 then '-'
3719 else to_char(round(100.0*sum(street2Aggr)/sum(street2Seen)),'90D0')
3721 ,case when sum(street3Seen) = 0 then '-'
3722 else to_char(round(100.0*sum(street3Aggr)/sum(street3Seen)),'90D0')
3724 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3725 else to_char(round(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3726 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen))),'90D0')
3728 ,to_char(sum(totalProfit)/100.0,'9G999G990D00') AS Net
3729 ,case when sum(HDs) = 0 then '0'
3730 else to_char(sum(totalProfit/(gt.bigBlind+0.0)) / (sum(HDs)/100.0), '990D00')
3732 ,case when sum(HDs) = 0 then '0'
3733 else to_char( (sum(totalProfit)/100.0) / sum(HDs), '90D0000')
3734 end AS Profitperhand
3735 ,to_char(sum(activeSeats*HDs)/(sum(HDs)+0.0),'90D00') AS AvgSeats
3737 inner join Sites s on (s.Id = gt.siteId)
3738 inner join HudCache hc on (hc.gametypeId = gt.Id)
3739 where hc.playerId in <player_test>
3740 and <gtbigBlind_test>
3741 and hc.activeSeats <seats_test>
3742 and '20' || SUBSTR(hc.styleKey,2,2) || '-' || SUBSTR(hc.styleKey,4,2) || '-'
3743 || SUBSTR(hc.styleKey,6,2) <datestest>
3746 ,upper(gt.limitType)
3748 <groupbygt.bigBlind>
3754 ( select /* profit from handsplayers/handsactions */
3756 case when hprof.position = 'B' then -2
3757 when hprof.position = 'S' then -1
3758 when hprof.position in ('3','4') then 2
3759 when hprof.position in ('6','7') then 5
3760 else cast(hprof.position as smallint)
3762 sum(hprof.profit) as sum_profit,
3763 avg(hprof.profit/100.0) as profitperhand,
3764 case when hprof.gtId = -1 then -999
3765 else variance(hprof.profit/100.0)
3768 (select hp.handId, <hgametypeId> as gtId, hp.position
3769 , hp.totalProfit as profit
3770 from HandsPlayers hp
3771 inner join Hands h ON (h.id = hp.handId)
3772 where hp.playerId in <player_test>
3773 and hp.tourneysPlayersId IS NULL
3774 and to_char(h.startTime, 'YYYY-MM-DD') <datestest>
3775 group by hp.handId, gametypeId, hp.position, hp.totalProfit
3777 group by hprof.gtId, PlPosition
3779 on ( hprof2.gtId = stats.gtId
3780 and hprof2.PlPosition = stats.PlPosition)
3781 order by stats.category, stats.limitType, stats.bigBlindDesc desc
3782 <orderbyseats>, cast(stats.PlPosition as smallint)
3785 ####################################
3786 # Cash Game Graph query
3787 ####################################
3788 self
.query
['getRingProfitAllHandsPlayerIdSite'] = """
3789 SELECT hp.handId, hp.totalProfit, hp.sawShowdown
3790 FROM HandsPlayers hp
3791 INNER JOIN Players pl ON (pl.id = hp.playerId)
3792 INNER JOIN Hands h ON (h.id = hp.handId)
3793 INNER JOIN Gametypes gt ON (gt.id = h.gametypeId)
3794 WHERE pl.id in <player_test>
3795 AND pl.siteId in <site_test>
3796 AND h.startTime > '<startdate_test>'
3797 AND h.startTime < '<enddate_test>'
3800 AND gt.type = 'ring'
3801 GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit
3802 ORDER BY h.startTime"""
3804 self
.query
['getRingProfitAllHandsPlayerIdSiteInBB'] = """
3805 SELECT hp.handId, ( hp.totalProfit / ( gt.bigBlind * 2.0 ) ) * 100 , hp.sawShowdown
3806 FROM HandsPlayers hp
3807 INNER JOIN Players pl ON (pl.id = hp.playerId)
3808 INNER JOIN Hands h ON (h.id = hp.handId)
3809 INNER JOIN Gametypes gt ON (gt.id = h.gametypeId)
3810 WHERE pl.id in <player_test>
3811 AND pl.siteId in <site_test>
3812 AND h.startTime > '<startdate_test>'
3813 AND h.startTime < '<enddate_test>'
3817 AND hp.tourneysPlayersId IS NULL
3818 GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit
3819 ORDER BY h.startTime"""
3821 self
.query
['getRingProfitAllHandsPlayerIdSiteInDollars'] = """
3822 SELECT hp.handId, hp.totalProfit, hp.sawShowdown
3823 FROM HandsPlayers hp
3824 INNER JOIN Players pl ON (pl.id = hp.playerId)
3825 INNER JOIN Hands h ON (h.id = hp.handId)
3826 INNER JOIN Gametypes gt ON (gt.id = h.gametypeId)
3827 WHERE pl.id in <player_test>
3828 AND pl.siteId in <site_test>
3829 AND h.startTime > '<startdate_test>'
3830 AND h.startTime < '<enddate_test>'
3834 AND hp.tourneysPlayersId IS NULL
3835 GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit
3836 ORDER BY h.startTime"""
3840 ####################################
3841 # Tourney Results query
3842 ####################################
3843 self
.query
['tourneyResults'] = """
3844 SELECT tp.tourneyId, (coalesce(tp.winnings,0) - coalesce(tt.buyIn,0) - coalesce(tt.fee,0)) as profit, tp.koCount, tp.rebuyCount, tp.addOnCount, tt.buyIn, tt.fee, t.siteTourneyNo
3845 FROM TourneysPlayers tp
3846 INNER JOIN Players pl ON (pl.id = tp.playerId)
3847 INNER JOIN Tourneys t ON (t.id = tp.tourneyId)
3848 INNER JOIN TourneyTypes tt ON (tt.id = t.tourneyTypeId)
3849 WHERE pl.id in <player_test>
3850 AND pl.siteId in <site_test>
3851 AND t.startTime > '<startdate_test>'
3852 AND t.startTime < '<enddate_test>'
3853 GROUP BY t.startTime, tp.tourneyId, tp.winningsCurrency,
3854 tp.winnings, tp.koCount,
3855 tp.rebuyCount, tp.addOnCount,
3857 ORDER BY t.startTime"""
3859 #AND gt.type = 'ring'
3863 ####################################
3864 # Session stats query
3865 ####################################
3866 if db_server
== 'mysql':
3867 self
.query
['sessionStats'] = """
3868 SELECT UNIX_TIMESTAMP(h.startTime) as time, hp.totalProfit
3869 FROM HandsPlayers hp
3870 INNER JOIN Hands h on (h.id = hp.handId)
3871 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
3872 INNER JOIN Sites s on (s.Id = gt.siteId)
3873 INNER JOIN Players p on (p.Id = hp.playerId)
3874 WHERE hp.playerId in <player_test>
3875 AND date_format(h.startTime, '%Y-%m-%d') <datestest>
3876 AND gt.type LIKE 'ring'
3882 elif db_server
== 'postgresql':
3883 self
.query
['sessionStats'] = """
3884 SELECT EXTRACT(epoch from h.startTime) as time, hp.totalProfit
3885 FROM HandsPlayers hp
3886 INNER JOIN Hands h on (h.id = hp.handId)
3887 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
3888 INNER JOIN Sites s on (s.Id = gt.siteId)
3889 INNER JOIN Players p on (p.Id = hp.playerId)
3890 WHERE hp.playerId in <player_test>
3891 AND h.startTime <datestest>
3892 AND gt.type LIKE 'ring'
3898 elif db_server
== 'sqlite':
3899 self
.query
['sessionStats'] = """
3900 SELECT STRFTIME('<ampersand_s>', h.startTime) as time, hp.totalProfit
3901 FROM HandsPlayers hp
3902 INNER JOIN Hands h on (h.id = hp.handId)
3903 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
3904 INNER JOIN Sites s on (s.Id = gt.siteId)
3905 INNER JOIN Players p on (p.Id = hp.playerId)
3906 WHERE hp.playerId in <player_test>
3907 AND h.startTime <datestest>
3908 AND gt.type is 'ring'
3916 ####################################
3917 # Queries to rebuild/modify hudcache
3918 ####################################
3920 self
.query
['clearHudCache'] = """DELETE FROM HudCache"""
3922 if db_server
== 'mysql':
3923 self
.query
['rebuildHudCache'] = """
3924 INSERT INTO HudCache
3929 <tourney_insert_clause>
3945 ,street0_FoldTo3BChance
3946 ,street0_FoldTo3BDone
3947 ,street0_FoldTo4BChance
3948 ,street0_FoldTo4BDone
3949 ,street0_SqueezeChance
3950 ,street0_SqueezeDone
3968 ,foldToOtherRaisedStreet0
3969 ,foldToOtherRaisedStreet1
3970 ,foldToOtherRaisedStreet2
3971 ,foldToOtherRaisedStreet3
3972 ,foldToOtherRaisedStreet4
3975 ,foldBbToStealChance
3977 ,foldSbToStealChance
3987 ,foldToStreet1CBChance
3988 ,foldToStreet1CBDone
3989 ,foldToStreet2CBChance
3990 ,foldToStreet2CBDone
3991 ,foldToStreet3CBChance
3992 ,foldToStreet3CBDone
3993 ,foldToStreet4CBChance
3994 ,foldToStreet4CBDone
3996 ,street1CheckCallRaiseChance
3997 ,street1CheckCallRaiseDone
3998 ,street2CheckCallRaiseChance
3999 ,street2CheckCallRaiseDone
4000 ,street3CheckCallRaiseChance
4001 ,street3CheckCallRaiseDone
4002 ,street4CheckCallRaiseChance
4003 ,street4CheckCallRaiseDone
4023 ,case when hp.position = 'B' then 'B'
4024 when hp.position = 'S' then 'S'
4025 when hp.position = '0' then 'D'
4026 when hp.position = '1' then 'C'
4027 when hp.position = '2' then 'M'
4028 when hp.position = '3' then 'M'
4029 when hp.position = '4' then 'M'
4030 when hp.position = '5' then 'E'
4031 when hp.position = '6' then 'E'
4032 when hp.position = '7' then 'E'
4033 when hp.position = '8' then 'E'
4034 when hp.position = '9' then 'E'
4037 <tourney_select_clause>
4038 ,date_format(h.startTime, 'd%y%m%d')
4040 ,sum(wonWhenSeenStreet1)
4041 ,sum(wonWhenSeenStreet2)
4042 ,sum(wonWhenSeenStreet3)
4043 ,sum(wonWhenSeenStreet4)
4047 ,sum(street0_3BChance)
4048 ,sum(street0_3BDone)
4049 ,sum(street0_4BChance)
4050 ,sum(street0_4BDone)
4051 ,sum(street0_C4BChance)
4052 ,sum(street0_C4BDone)
4053 ,sum(street0_FoldTo3BChance)
4054 ,sum(street0_FoldTo3BDone)
4055 ,sum(street0_FoldTo4BChance)
4056 ,sum(street0_FoldTo4BDone)
4057 ,sum(street0_SqueezeChance)
4058 ,sum(street0_SqueezeDone)
4059 ,sum(raiseToStealChance)
4060 ,sum(raiseToStealDone)
4071 ,sum(otherRaisedStreet0)
4072 ,sum(otherRaisedStreet1)
4073 ,sum(otherRaisedStreet2)
4074 ,sum(otherRaisedStreet3)
4075 ,sum(otherRaisedStreet4)
4076 ,sum(foldToOtherRaisedStreet0)
4077 ,sum(foldToOtherRaisedStreet1)
4078 ,sum(foldToOtherRaisedStreet2)
4079 ,sum(foldToOtherRaisedStreet3)
4080 ,sum(foldToOtherRaisedStreet4)
4081 ,sum(raiseFirstInChance)
4083 ,sum(foldBbToStealChance)
4084 ,sum(foldedBbToSteal)
4085 ,sum(foldSbToStealChance)
4086 ,sum(foldedSbToSteal)
4087 ,sum(street1CBChance)
4089 ,sum(street2CBChance)
4091 ,sum(street3CBChance)
4093 ,sum(street4CBChance)
4095 ,sum(foldToStreet1CBChance)
4096 ,sum(foldToStreet1CBDone)
4097 ,sum(foldToStreet2CBChance)
4098 ,sum(foldToStreet2CBDone)
4099 ,sum(foldToStreet3CBChance)
4100 ,sum(foldToStreet3CBDone)
4101 ,sum(foldToStreet4CBChance)
4102 ,sum(foldToStreet4CBDone)
4104 ,sum(street1CheckCallRaiseChance)
4105 ,sum(street1CheckCallRaiseDone)
4106 ,sum(street2CheckCallRaiseChance)
4107 ,sum(street2CheckCallRaiseDone)
4108 ,sum(street3CheckCallRaiseChance)
4109 ,sum(street3CheckCallRaiseDone)
4110 ,sum(street4CheckCallRaiseChance)
4111 ,sum(street4CheckCallRaiseDone)
4122 ,sum(hp.street0Raises)
4123 ,sum(hp.street1Raises)
4124 ,sum(hp.street2Raises)
4125 ,sum(hp.street3Raises)
4126 ,sum(hp.street4Raises)
4127 FROM HandsPlayers hp
4128 INNER JOIN Hands h ON (h.id = hp.handId)
4129 <tourney_join_clause>
4131 GROUP BY h.gametypeId
4135 <tourney_group_clause>
4136 ,date_format(h.startTime, 'd%y%m%d')
4138 elif db_server
== 'postgresql':
4139 self
.query
['rebuildHudCache'] = """
4140 INSERT INTO HudCache
4145 <tourney_insert_clause>
4161 ,street0_FoldTo3BChance
4162 ,street0_FoldTo3BDone
4163 ,street0_FoldTo4BChance
4164 ,street0_FoldTo4BDone
4165 ,street0_SqueezeChance
4166 ,street0_SqueezeDone
4184 ,foldToOtherRaisedStreet0
4185 ,foldToOtherRaisedStreet1
4186 ,foldToOtherRaisedStreet2
4187 ,foldToOtherRaisedStreet3
4188 ,foldToOtherRaisedStreet4
4191 ,foldBbToStealChance
4193 ,foldSbToStealChance
4203 ,foldToStreet1CBChance
4204 ,foldToStreet1CBDone
4205 ,foldToStreet2CBChance
4206 ,foldToStreet2CBDone
4207 ,foldToStreet3CBChance
4208 ,foldToStreet3CBDone
4209 ,foldToStreet4CBChance
4210 ,foldToStreet4CBDone
4212 ,street1CheckCallRaiseChance
4213 ,street1CheckCallRaiseDone
4214 ,street2CheckCallRaiseChance
4215 ,street2CheckCallRaiseDone
4216 ,street3CheckCallRaiseChance
4217 ,street3CheckCallRaiseDone
4218 ,street4CheckCallRaiseChance
4219 ,street4CheckCallRaiseDone
4239 ,case when hp.position = 'B' then 'B'
4240 when hp.position = 'S' then 'S'
4241 when hp.position = '0' then 'D'
4242 when hp.position = '1' then 'C'
4243 when hp.position = '2' then 'M'
4244 when hp.position = '3' then 'M'
4245 when hp.position = '4' then 'M'
4246 when hp.position = '5' then 'E'
4247 when hp.position = '6' then 'E'
4248 when hp.position = '7' then 'E'
4249 when hp.position = '8' then 'E'
4250 when hp.position = '9' then 'E'
4253 <tourney_select_clause>
4254 ,'d' || to_char(h.startTime, 'YYMMDD')
4256 ,sum(wonWhenSeenStreet1)
4257 ,sum(wonWhenSeenStreet2)
4258 ,sum(wonWhenSeenStreet3)
4259 ,sum(wonWhenSeenStreet4)
4261 ,sum(CAST(street0VPI as integer))
4262 ,sum(CAST(street0Aggr as integer))
4263 ,sum(CAST(street0_3BChance as integer))
4264 ,sum(CAST(street0_3BDone as integer))
4265 ,sum(CAST(street0_4BChance as integer))
4266 ,sum(CAST(street0_4BDone as integer))
4267 ,sum(CAST(street0_C4BChance as integer))
4268 ,sum(CAST(street0_C4BDone as integer))
4269 ,sum(CAST(street0_FoldTo3BChance as integer))
4270 ,sum(CAST(street0_FoldTo3BDone as integer))
4271 ,sum(CAST(street0_FoldTo4BChance as integer))
4272 ,sum(CAST(street0_FoldTo4BDone as integer))
4273 ,sum(CAST(street0_SqueezeChance as integer))
4274 ,sum(CAST(street0_SqueezeDone as integer))
4275 ,sum(CAST(raiseToStealChance as integer))
4276 ,sum(CAST(raiseToStealDone as integer))
4277 ,sum(CAST(success_Steal as integer))
4278 ,sum(CAST(street1Seen as integer))
4279 ,sum(CAST(street2Seen as integer))
4280 ,sum(CAST(street3Seen as integer))
4281 ,sum(CAST(street4Seen as integer))
4282 ,sum(CAST(sawShowdown as integer))
4283 ,sum(CAST(street1Aggr as integer))
4284 ,sum(CAST(street2Aggr as integer))
4285 ,sum(CAST(street3Aggr as integer))
4286 ,sum(CAST(street4Aggr as integer))
4287 ,sum(CAST(otherRaisedStreet0 as integer))
4288 ,sum(CAST(otherRaisedStreet1 as integer))
4289 ,sum(CAST(otherRaisedStreet2 as integer))
4290 ,sum(CAST(otherRaisedStreet3 as integer))
4291 ,sum(CAST(otherRaisedStreet4 as integer))
4292 ,sum(CAST(foldToOtherRaisedStreet0 as integer))
4293 ,sum(CAST(foldToOtherRaisedStreet1 as integer))
4294 ,sum(CAST(foldToOtherRaisedStreet2 as integer))
4295 ,sum(CAST(foldToOtherRaisedStreet3 as integer))
4296 ,sum(CAST(foldToOtherRaisedStreet4 as integer))
4297 ,sum(CAST(raiseFirstInChance as integer))
4298 ,sum(CAST(raisedFirstIn as integer))
4299 ,sum(CAST(foldBbToStealChance as integer))
4300 ,sum(CAST(foldedBbToSteal as integer))
4301 ,sum(CAST(foldSbToStealChance as integer))
4302 ,sum(CAST(foldedSbToSteal as integer))
4303 ,sum(CAST(street1CBChance as integer))
4304 ,sum(CAST(street1CBDone as integer))
4305 ,sum(CAST(street2CBChance as integer))
4306 ,sum(CAST(street2CBDone as integer))
4307 ,sum(CAST(street3CBChance as integer))
4308 ,sum(CAST(street3CBDone as integer))
4309 ,sum(CAST(street4CBChance as integer))
4310 ,sum(CAST(street4CBDone as integer))
4311 ,sum(CAST(foldToStreet1CBChance as integer))
4312 ,sum(CAST(foldToStreet1CBDone as integer))
4313 ,sum(CAST(foldToStreet2CBChance as integer))
4314 ,sum(CAST(foldToStreet2CBDone as integer))
4315 ,sum(CAST(foldToStreet3CBChance as integer))
4316 ,sum(CAST(foldToStreet3CBDone as integer))
4317 ,sum(CAST(foldToStreet4CBChance as integer))
4318 ,sum(CAST(foldToStreet4CBDone as integer))
4319 ,sum(CAST(totalProfit as integer))
4320 ,sum(CAST(street1CheckCallRaiseChance as integer))
4321 ,sum(CAST(street1CheckCallRaiseDone as integer))
4322 ,sum(CAST(street2CheckCallRaiseChance as integer))
4323 ,sum(CAST(street2CheckCallRaiseDone as integer))
4324 ,sum(CAST(street3CheckCallRaiseChance as integer))
4325 ,sum(CAST(street3CheckCallRaiseDone as integer))
4326 ,sum(CAST(street4CheckCallRaiseChance as integer))
4327 ,sum(CAST(street4CheckCallRaiseDone as integer))
4328 ,sum(CAST(street0Calls as integer))
4329 ,sum(CAST(street1Calls as integer))
4330 ,sum(CAST(street2Calls as integer))
4331 ,sum(CAST(street3Calls as integer))
4332 ,sum(CAST(street4Calls as integer))
4333 ,sum(CAST(street0Bets as integer))
4334 ,sum(CAST(street1Bets as integer))
4335 ,sum(CAST(street2Bets as integer))
4336 ,sum(CAST(street3Bets as integer))
4337 ,sum(CAST(street4Bets as integer))
4338 ,sum(CAST(hp.street0Raises as integer))
4339 ,sum(CAST(hp.street1Raises as integer))
4340 ,sum(CAST(hp.street2Raises as integer))
4341 ,sum(CAST(hp.street3Raises as integer))
4342 ,sum(CAST(hp.street4Raises as integer))
4343 FROM HandsPlayers hp
4344 INNER JOIN Hands h ON (h.id = hp.handId)
4345 <tourney_join_clause>
4347 GROUP BY h.gametypeId
4351 <tourney_group_clause>
4352 ,to_char(h.startTime, 'YYMMDD')
4354 else: # assume sqlite
4355 self
.query
['rebuildHudCache'] = """
4356 INSERT INTO HudCache
4361 <tourney_insert_clause>
4377 ,street0_FoldTo3BChance
4378 ,street0_FoldTo3BDone
4379 ,street0_FoldTo4BChance
4380 ,street0_FoldTo4BDone
4381 ,street0_SqueezeChance
4382 ,street0_SqueezeDone
4400 ,foldToOtherRaisedStreet0
4401 ,foldToOtherRaisedStreet1
4402 ,foldToOtherRaisedStreet2
4403 ,foldToOtherRaisedStreet3
4404 ,foldToOtherRaisedStreet4
4407 ,foldBbToStealChance
4409 ,foldSbToStealChance
4419 ,foldToStreet1CBChance
4420 ,foldToStreet1CBDone
4421 ,foldToStreet2CBChance
4422 ,foldToStreet2CBDone
4423 ,foldToStreet3CBChance
4424 ,foldToStreet3CBDone
4425 ,foldToStreet4CBChance
4426 ,foldToStreet4CBDone
4428 ,street1CheckCallRaiseChance
4429 ,street1CheckCallRaiseDone
4430 ,street2CheckCallRaiseChance
4431 ,street2CheckCallRaiseDone
4432 ,street3CheckCallRaiseChance
4433 ,street3CheckCallRaiseDone
4434 ,street4CheckCallRaiseChance
4435 ,street4CheckCallRaiseDone
4455 ,case when hp.position = 'B' then 'B'
4456 when hp.position = 'S' then 'S'
4457 when hp.position = '0' then 'D'
4458 when hp.position = '1' then 'C'
4459 when hp.position = '2' then 'M'
4460 when hp.position = '3' then 'M'
4461 when hp.position = '4' then 'M'
4462 when hp.position = '5' then 'E'
4463 when hp.position = '6' then 'E'
4464 when hp.position = '7' then 'E'
4465 when hp.position = '8' then 'E'
4466 when hp.position = '9' then 'E'
4469 <tourney_select_clause>
4470 ,'d' || substr(strftime('%Y%m%d', h.startTime),3,7)
4472 ,sum(wonWhenSeenStreet1)
4473 ,sum(wonWhenSeenStreet2)
4474 ,sum(wonWhenSeenStreet3)
4475 ,sum(wonWhenSeenStreet4)
4477 ,sum(CAST(street0VPI as integer))
4478 ,sum(CAST(street0Aggr as integer))
4479 ,sum(CAST(street0_3BChance as integer))
4480 ,sum(CAST(street0_3BDone as integer))
4481 ,sum(CAST(street0_4BChance as integer))
4482 ,sum(CAST(street0_4BDone as integer))
4483 ,sum(CAST(street0_C4BChance as integer))
4484 ,sum(CAST(street0_C4BDone as integer))
4485 ,sum(CAST(street0_FoldTo3BChance as integer))
4486 ,sum(CAST(street0_FoldTo3BDone as integer))
4487 ,sum(CAST(street0_FoldTo4BChance as integer))
4488 ,sum(CAST(street0_FoldTo4BDone as integer))
4489 ,sum(CAST(street0_SqueezeChance as integer))
4490 ,sum(CAST(street0_SqueezeDone as integer))
4491 ,sum(CAST(raiseToStealChance as integer))
4492 ,sum(CAST(raiseToStealDone as integer))
4493 ,sum(CAST(success_Steal as integer))
4494 ,sum(CAST(street1Seen as integer))
4495 ,sum(CAST(street2Seen as integer))
4496 ,sum(CAST(street3Seen as integer))
4497 ,sum(CAST(street4Seen as integer))
4498 ,sum(CAST(sawShowdown as integer))
4499 ,sum(CAST(street1Aggr as integer))
4500 ,sum(CAST(street2Aggr as integer))
4501 ,sum(CAST(street3Aggr as integer))
4502 ,sum(CAST(street4Aggr as integer))
4503 ,sum(CAST(otherRaisedStreet0 as integer))
4504 ,sum(CAST(otherRaisedStreet1 as integer))
4505 ,sum(CAST(otherRaisedStreet2 as integer))
4506 ,sum(CAST(otherRaisedStreet3 as integer))
4507 ,sum(CAST(otherRaisedStreet4 as integer))
4508 ,sum(CAST(foldToOtherRaisedStreet0 as integer))
4509 ,sum(CAST(foldToOtherRaisedStreet1 as integer))
4510 ,sum(CAST(foldToOtherRaisedStreet2 as integer))
4511 ,sum(CAST(foldToOtherRaisedStreet3 as integer))
4512 ,sum(CAST(foldToOtherRaisedStreet4 as integer))
4513 ,sum(CAST(raiseFirstInChance as integer))
4514 ,sum(CAST(raisedFirstIn as integer))
4515 ,sum(CAST(foldBbToStealChance as integer))
4516 ,sum(CAST(foldedBbToSteal as integer))
4517 ,sum(CAST(foldSbToStealChance as integer))
4518 ,sum(CAST(foldedSbToSteal as integer))
4519 ,sum(CAST(street1CBChance as integer))
4520 ,sum(CAST(street1CBDone as integer))
4521 ,sum(CAST(street2CBChance as integer))
4522 ,sum(CAST(street2CBDone as integer))
4523 ,sum(CAST(street3CBChance as integer))
4524 ,sum(CAST(street3CBDone as integer))
4525 ,sum(CAST(street4CBChance as integer))
4526 ,sum(CAST(street4CBDone as integer))
4527 ,sum(CAST(foldToStreet1CBChance as integer))
4528 ,sum(CAST(foldToStreet1CBDone as integer))
4529 ,sum(CAST(foldToStreet2CBChance as integer))
4530 ,sum(CAST(foldToStreet2CBDone as integer))
4531 ,sum(CAST(foldToStreet3CBChance as integer))
4532 ,sum(CAST(foldToStreet3CBDone as integer))
4533 ,sum(CAST(foldToStreet4CBChance as integer))
4534 ,sum(CAST(foldToStreet4CBDone as integer))
4535 ,sum(CAST(totalProfit as integer))
4536 ,sum(CAST(street1CheckCallRaiseChance as integer))
4537 ,sum(CAST(street1CheckCallRaiseDone as integer))
4538 ,sum(CAST(street2CheckCallRaiseChance as integer))
4539 ,sum(CAST(street2CheckCallRaiseDone as integer))
4540 ,sum(CAST(street3CheckCallRaiseChance as integer))
4541 ,sum(CAST(street3CheckCallRaiseDone as integer))
4542 ,sum(CAST(street4CheckCallRaiseChance as integer))
4543 ,sum(CAST(street4CheckCallRaiseDone as integer))
4544 ,sum(CAST(street0Calls as integer))
4545 ,sum(CAST(street1Calls as integer))
4546 ,sum(CAST(street2Calls as integer))
4547 ,sum(CAST(street3Calls as integer))
4548 ,sum(CAST(street4Calls as integer))
4549 ,sum(CAST(street0Bets as integer))
4550 ,sum(CAST(street1Bets as integer))
4551 ,sum(CAST(street2Bets as integer))
4552 ,sum(CAST(street3Bets as integer))
4553 ,sum(CAST(street4Bets as integer))
4554 ,sum(CAST(hp.street0Raises as integer))
4555 ,sum(CAST(hp.street1Raises as integer))
4556 ,sum(CAST(hp.street2Raises as integer))
4557 ,sum(CAST(hp.street3Raises as integer))
4558 ,sum(CAST(hp.street4Raises as integer))
4559 FROM HandsPlayers hp
4560 INNER JOIN Hands h ON (h.id = hp.handId)
4561 <tourney_join_clause>
4563 GROUP BY h.gametypeId
4567 <tourney_group_clause>
4568 ,'d' || substr(strftime('%Y%m%d', h.startTime),3,7)
4571 self
.query
['insert_hudcache'] = """
4572 insert into HudCache (
4588 street0_FoldTo3BChance,
4589 street0_FoldTo3BDone,
4590 street0_FoldTo4BChance,
4591 street0_FoldTo4BDone,
4592 street0_SqueezeChance,
4593 street0_SqueezeDone,
4611 foldToOtherRaisedStreet0,
4612 foldToOtherRaisedStreet1,
4613 foldToOtherRaisedStreet2,
4614 foldToOtherRaisedStreet3,
4615 foldToOtherRaisedStreet4,
4623 foldBbToStealChance,
4625 foldSbToStealChance,
4635 foldToStreet1CBChance,
4636 foldToStreet1CBDone,
4637 foldToStreet2CBChance,
4638 foldToStreet2CBDone,
4639 foldToStreet3CBChance,
4640 foldToStreet3CBDone,
4641 foldToStreet4CBChance,
4642 foldToStreet4CBDone,
4644 street1CheckCallRaiseChance,
4645 street1CheckCallRaiseDone,
4646 street2CheckCallRaiseChance,
4647 street2CheckCallRaiseDone,
4648 street3CheckCallRaiseChance,
4649 street3CheckCallRaiseDone,
4650 street4CheckCallRaiseChance,
4651 street4CheckCallRaiseDone,
4667 values (%s, %s, %s, %s, %s,
4687 self
.query
['update_hudcache'] = """
4690 street0VPI=street0VPI+%s,
4691 street0Aggr=street0Aggr+%s,
4692 street0_3BChance=street0_3BChance+%s,
4693 street0_3BDone=street0_3BDone+%s,
4694 street0_4BChance=street0_4BChance+%s,
4695 street0_4BDone=street0_4BDone+%s,
4696 street0_C4BChance=street0_C4BChance+%s,
4697 street0_C4BDone=street0_C4BDone+%s,
4698 street0_FoldTo3BChance=street0_FoldTo3BChance+%s,
4699 street0_FoldTo3BDone=street0_FoldTo3BDone+%s,
4700 street0_FoldTo4BChance=street0_FoldTo4BChance+%s,
4701 street0_FoldTo4BDone=street0_FoldTo4BDone+%s,
4702 street0_SqueezeChance=street0_SqueezeChance+%s,
4703 street0_SqueezeDone=street0_SqueezeDone+%s,
4704 raiseToStealChance=raiseToStealChance+%s,
4705 raiseToStealDone=raiseToStealDone+%s,
4706 success_Steal=success_Steal+%s,
4707 street1Seen=street1Seen+%s,
4708 street2Seen=street2Seen+%s,
4709 street3Seen=street3Seen+%s,
4710 street4Seen=street4Seen+%s,
4711 sawShowdown=sawShowdown+%s,
4712 street1Aggr=street1Aggr+%s,
4713 street2Aggr=street2Aggr+%s,
4714 street3Aggr=street3Aggr+%s,
4715 street4Aggr=street4Aggr+%s,
4716 otherRaisedStreet0=otherRaisedStreet0+%s,
4717 otherRaisedStreet1=otherRaisedStreet1+%s,
4718 otherRaisedStreet2=otherRaisedStreet2+%s,
4719 otherRaisedStreet3=otherRaisedStreet3+%s,
4720 otherRaisedStreet4=otherRaisedStreet4+%s,
4721 foldToOtherRaisedStreet0=foldToOtherRaisedStreet0+%s,
4722 foldToOtherRaisedStreet1=foldToOtherRaisedStreet1+%s,
4723 foldToOtherRaisedStreet2=foldToOtherRaisedStreet2+%s,
4724 foldToOtherRaisedStreet3=foldToOtherRaisedStreet3+%s,
4725 foldToOtherRaisedStreet4=foldToOtherRaisedStreet4+%s,
4726 wonWhenSeenStreet1=wonWhenSeenStreet1+%s,
4727 wonWhenSeenStreet2=wonWhenSeenStreet2+%s,
4728 wonWhenSeenStreet3=wonWhenSeenStreet3+%s,
4729 wonWhenSeenStreet4=wonWhenSeenStreet4+%s,
4731 raiseFirstInChance=raiseFirstInChance+%s,
4732 raisedFirstIn=raisedFirstIn+%s,
4733 foldBbToStealChance=foldBbToStealChance+%s,
4734 foldedBbToSteal=foldedBbToSteal+%s,
4735 foldSbToStealChance=foldSbToStealChance+%s,
4736 foldedSbToSteal=foldedSbToSteal+%s,
4737 street1CBChance=street1CBChance+%s,
4738 street1CBDone=street1CBDone+%s,
4739 street2CBChance=street2CBChance+%s,
4740 street2CBDone=street2CBDone+%s,
4741 street3CBChance=street3CBChance+%s,
4742 street3CBDone=street3CBDone+%s,
4743 street4CBChance=street4CBChance+%s,
4744 street4CBDone=street4CBDone+%s,
4745 foldToStreet1CBChance=foldToStreet1CBChance+%s,
4746 foldToStreet1CBDone=foldToStreet1CBDone+%s,
4747 foldToStreet2CBChance=foldToStreet2CBChance+%s,
4748 foldToStreet2CBDone=foldToStreet2CBDone+%s,
4749 foldToStreet3CBChance=foldToStreet3CBChance+%s,
4750 foldToStreet3CBDone=foldToStreet3CBDone+%s,
4751 foldToStreet4CBChance=foldToStreet4CBChance+%s,
4752 foldToStreet4CBDone=foldToStreet4CBDone+%s,
4753 totalProfit=totalProfit+%s,
4754 street1CheckCallRaiseChance=street1CheckCallRaiseChance+%s,
4755 street1CheckCallRaiseDone=street1CheckCallRaiseDone+%s,
4756 street2CheckCallRaiseChance=street2CheckCallRaiseChance+%s,
4757 street2CheckCallRaiseDone=street2CheckCallRaiseDone+%s,
4758 street3CheckCallRaiseChance=street3CheckCallRaiseChance+%s,
4759 street3CheckCallRaiseDone=street3CheckCallRaiseDone+%s,
4760 street4CheckCallRaiseChance=street4CheckCallRaiseChance+%s,
4761 street4CheckCallRaiseDone=street4CheckCallRaiseDone+%s,
4762 street0Calls=street0Calls+%s,
4763 street1Calls=street1Calls+%s,
4764 street2Calls=street2Calls+%s,
4765 street3Calls=street3Calls+%s,
4766 street4Calls=street4Calls+%s,
4767 street0Bets=street0Bets+%s,
4768 street1Bets=street1Bets+%s,
4769 street2Bets=street2Bets+%s,
4770 street3Bets=street3Bets+%s,
4771 street4Bets=street4Bets+%s,
4772 street0Raises=street0Raises+%s,
4773 street1Raises=street1Raises+%s,
4774 street2Raises=street2Raises+%s,
4775 street3Raises=street3Raises+%s,
4776 street4Raises=street4Raises+%s
4777 WHERE gametypeId+0=%s
4781 AND (case when tourneyTypeId is NULL then 1 else
4782 (case when tourneyTypeId+0=%s then 1 else 0 end) end)=1
4785 self
.query
['get_hero_hudcache_start'] = """select min(hc.styleKey)
4787 where hc.playerId in <playerid_list>
4788 and hc.styleKey like 'd%'"""
4790 ####################################
4791 # Queries to rebuild/modify sessionscache
4792 ####################################
4794 self
.query
['clearSessionsCache'] = """DELETE FROM SessionsCache"""
4796 self
.query
['rebuildSessionsCache'] = """
4797 SELECT Hands.id as id,
4798 Hands.startTime as startTime,
4799 HandsPlayers.playerId as playerId,
4800 Hands.gametypeId as gametypeId,
4801 Gametypes.type as game,
4802 HandsPlayers.totalProfit as totalProfit,
4803 Tourneys.tourneyTypeId as tourneyTypeId,
4804 HandsPlayers.street0VPI as street0VPI,
4805 HandsPlayers.street1Seen as street1Seen
4806 FROM Gametypes, HandsPlayers, Hands
4807 LEFT JOIN Tourneys ON Hands.tourneyId = Tourneys.tourneyTypeId
4808 WHERE HandsPlayers.handId = Hands.id
4809 AND Hands.gametypeId = Gametypes.id
4810 AND (case when HandsPlayers.playerId = <where_clause> then 1 else 0 end) = 1
4811 ORDER BY Hands.startTime ASC"""
4813 self
.query
['rebuildSessionsCacheSum'] = """
4814 SELECT Tourneys.id as id,
4815 Tourneys.startTime as startTime,
4816 TourneysPlayers.playerId,
4817 TourneyTypes.id as tourneyTypeId,
4818 TourneysPlayers.winnings as winnings,
4819 TourneysPlayers.winningsCurrency as winningsCurrency,
4820 TourneyTypes.currency as buyinCurrency,
4821 TourneyTypes.buyIn as buyIn,
4822 TourneyTypes.fee as fee,
4823 case when TourneyTypes.rebuy then TourneyTypes.rebuyCost else 0 end as rebuyCost,
4824 case when TourneyTypes.rebuy then TourneyTypes.rebuyFee else 0 end as rebuyFee,
4825 case when TourneyTypes.addOn then TourneyTypes.addOnCost else 0 end as addOnCost,
4826 case when TourneyTypes.addOn then TourneyTypes.addOnFee else 0 end as addOnFee,
4827 case when TourneyTypes.knockout then TourneyTypes.koBounty else 0 end as koBounty
4828 FROM Tourneys, TourneyTypes, TourneysPlayers
4829 WHERE Tourneys.tourneyTypeId = TourneyTypes.id
4830 AND Tourneys.id = TourneysPlayers.tourneyId
4831 AND (case when TourneysPlayers.playerId = <where_clause> then 1 else 0 end) = 1
4832 ORDER BY Tourneys.startTime ASC"""
4834 self
.query
['select_prepSC'] = """
4835 SELECT sessionId as id,
4838 count(sessionId) as count
4840 WHERE sessionEnd>=%s
4841 AND sessionStart<=%s
4842 GROUP BY sessionId, sessionStart, sessionEnd"""
4844 self
.query
['update_prepSC'] = """
4845 UPDATE SessionsCache SET
4848 WHERE sessionId=%s"""
4850 self
.query
['update_SC'] = """
4851 UPDATE SessionsCache SET
4857 tourneys=tourneys+%s,
4858 totalProfit=totalProfit+%s
4861 self
.query
['select_SC'] = """
4882 AND (case when gametypeId is NULL then 1 else
4883 (case when gametypeId=%s then 1 else 0 end) end)=1
4884 AND (case when tourneyTypeId is NULL then 1 else
4885 (case when tourneyTypeId=%s then 1 else 0 end) end)=1
4889 self
.query
['insert_SC'] = """
4890 insert into SessionsCache (
4905 values (%s, %s, %s, %s, %s, %s, %s,
4906 %s, %s, %s, %s, %s, %s, %s)"""
4908 self
.query
['update_Hands_gsid'] = """
4911 WHERE gameSessionId=%s"""
4913 self
.query
['update_Hands_sid'] = """
4916 WHERE sessionId=%s"""
4918 self
.query
['update_SC_sid'] = """
4919 UPDATE SessionsCache SET
4923 WHERE sessionId=%s"""
4925 self
.query
['delete_SC'] = """
4926 DELETE FROM SessionsCache
4929 ####################################
4930 # Database management queries
4931 ####################################
4933 if db_server
== 'mysql':
4934 self
.query
['analyze'] = """
4935 analyze table Autorates, GameTypes, Hands, HandsPlayers, HudCache, Players
4936 , Settings, Sites, Tourneys, TourneysPlayers, TourneyTypes
4938 elif db_server
== 'postgresql':
4939 self
.query
['analyze'] = "analyze"
4940 elif db_server
== 'sqlite':
4941 self
.query
['analyze'] = "analyze"
4943 if db_server
== 'mysql':
4944 self
.query
['selectLock'] = """
4948 LOCK IN SHARE MODE"""
4950 if db_server
== 'mysql':
4951 self
.query
['switchLock'] = """
4952 UPDATE InsertLock SET
4956 if db_server
== 'mysql':
4957 self
.query
['missedLock'] = """
4958 UPDATE InsertLock SET
4962 if db_server
== 'mysql':
4963 self
.query
['lockForInsert'] = """
4964 lock tables Hands write, HandsPlayers write, HandsActions write, Players write
4965 , HudCache write, GameTypes write, Sites write, Tourneys write
4966 , TourneysPlayers write, TourneyTypes write, Autorates write
4968 elif db_server
== 'postgresql':
4969 self
.query
['lockForInsert'] = ""
4970 elif db_server
== 'sqlite':
4971 self
.query
['lockForInsert'] = ""
4973 if db_server
== 'mysql':
4974 self
.query
['vacuum'] = """optimize table Hands, HandsPlayers, HandsActions, Players
4975 , HudCache, GameTypes, Sites, Tourneys
4976 , TourneysPlayers, TourneyTypes, Autorates
4978 elif db_server
== 'postgresql':
4979 self
.query
['vacuum'] = """ vacuum """
4980 elif db_server
== 'sqlite':
4981 self
.query
['vacuum'] = """ vacuum """
4983 self
.query
['getGametypeFL'] = """SELECT id
4993 """ #TODO: seems odd to have limitType variable in this query
4995 self
.query
['getGametypeNL'] = """SELECT id
5007 """ #TODO: seems odd to have limitType variable in this query
5009 self
.query
['insertGameTypes'] = """INSERT INTO Gametypes
5010 (siteId, currency, type, base, category, limitType
5011 ,hiLo, mix, smallBlind, bigBlind, smallBet, bigBet, maxSeats, ante)
5012 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
5014 self
.query
['isAlreadyInDB'] = """SELECT id FROM Hands
5015 WHERE gametypeId=%s AND siteHandNo=%s
5018 self
.query
['getTourneyTypeIdByTourneyNo'] = """SELECT tt.id,
5028 FROM TourneyTypes tt
5029 INNER JOIN Tourneys t ON (t.tourneyTypeId = tt.id)
5030 WHERE t.siteTourneyNo=%s AND tt.siteId=%s
5033 self
.query
['getTourneyTypeId'] = """SELECT id
5050 self
.query
['insertTourneyType'] = """INSERT INTO TourneyTypes
5051 (siteId, currency, buyin, fee, category, limitType, maxSeats, buyInChips, knockout, koBounty, rebuy,
5052 addOn ,speed, shootout, matrix, added, addedCurrency)
5053 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
5056 self
.query
['getTourneyByTourneyNo'] = """SELECT t.*
5058 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5059 WHERE tt.siteId=%s AND t.siteTourneyNo=%s
5062 self
.query
['getTourneyInfo'] = """SELECT tt.*, t.*
5064 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5065 INNER JOIN Sites s ON (tt.siteId = s.id)
5066 WHERE s.name=%s AND t.siteTourneyNo=%s
5069 self
.query
['getSiteTourneyNos'] = """SELECT t.siteTourneyNo
5071 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5072 INNER JOIN Sites s ON (tt.siteId = s.id)
5076 self
.query
['getTourneyPlayerInfo'] = """SELECT tp.*
5078 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5079 INNER JOIN Sites s ON (tt.siteId = s.id)
5080 INNER JOIN TourneysPlayers tp ON (tp.tourneyId = t.id)
5081 INNER JOIN Players p ON (p.id = tp.playerId)
5082 WHERE s.name=%s AND t.siteTourneyNo=%s AND p.name=%s
5085 self
.query
['insertTourney'] = """INSERT INTO Tourneys
5086 (tourneyTypeId, siteTourneyNo, entries, prizepool,
5087 startTime, endTime, tourneyName, matrixIdProcessed,
5088 totalRebuyCount, totalAddOnCount)
5089 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
5092 self
.query
['updateTourney'] = """UPDATE Tourneys
5098 matrixIdProcessed = %s,
5099 totalRebuyCount = %s,
5100 totalAddOnCount = %s,
5106 self
.query
['getTourneysPlayersByIds'] = """SELECT *
5107 FROM TourneysPlayers
5108 WHERE tourneyId=%s AND playerId+0=%s
5111 self
.query
['updateTourneysPlayer'] = """UPDATE TourneysPlayers
5114 winningsCurrency = %s,
5121 self
.query
['insertTourneysPlayer'] = """insert into TourneysPlayers
5122 (tourneyId, playerId, rank, winnings, winningsCurrency, rebuyCount, addOnCount, koCount)
5123 values (%s, %s, %s, %s, %s, %s, %s, %s)
5126 self
.query
['selectHandsPlayersWithWrongTTypeId'] = """SELECT id
5128 WHERE tourneyTypeId <> %s AND (TourneysPlayersId+0=%s)
5131 # self.query['updateHandsPlayersForTTypeId2'] = """UPDATE HandsPlayers
5132 # SET tourneyTypeId= %s
5133 # WHERE (TourneysPlayersId+0=%s)
5136 self
.query
['updateHandsPlayersForTTypeId'] = """UPDATE HandsPlayers
5137 SET tourneyTypeId= %s
5142 self
.query
['handsPlayersTTypeId_joiner'] = " OR TourneysPlayersId+0="
5143 self
.query
['handsPlayersTTypeId_joiner_id'] = " OR id="
5145 self
.query
['store_hand'] = """insert into Hands (
5181 (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
5182 %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
5183 %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
5186 self
.query
['store_hands_players'] = """insert into HandsPlayers (
5259 street0_FoldTo3BChance,
5260 street0_FoldTo3BDone,
5261 street0_FoldTo4BChance,
5262 street0_FoldTo4BDone,
5263 street0_SqueezeChance,
5264 street0_SqueezeDone,
5273 foldToOtherRaisedStreet0,
5274 foldToOtherRaisedStreet1,
5275 foldToOtherRaisedStreet2,
5276 foldToOtherRaisedStreet3,
5277 foldToOtherRaisedStreet4,
5280 foldBbToStealChance,
5282 foldSbToStealChance,
5284 foldToStreet1CBChance,
5285 foldToStreet1CBDone,
5286 foldToStreet2CBChance,
5287 foldToStreet2CBDone,
5288 foldToStreet3CBChance,
5289 foldToStreet3CBDone,
5290 foldToStreet4CBChance,
5291 foldToStreet4CBDone,
5292 street1CheckCallRaiseChance,
5293 street1CheckCallRaiseDone,
5294 street2CheckCallRaiseChance,
5295 street2CheckCallRaiseDone,
5296 street3CheckCallRaiseChance,
5297 street3CheckCallRaiseDone,
5298 street4CheckCallRaiseChance,
5299 street4CheckCallRaiseDone,
5333 self
.query
['store_hands_actions'] = """insert into HandsActions (
5353 self
.query
['store_boards'] = """insert into Boards (
5367 ################################
5368 # queries for Files Table
5369 ################################
5371 self
.query
['store_file'] = """ insert into Files (
5389 self
.query
['update_file'] = """
5399 ttime100=ttime100+%s,
5403 ################################
5404 # Counts for DB stats window
5405 ################################
5406 self
.query
['getHandCount'] = "SELECT COUNT(*) FROM Hands"
5407 self
.query
['getTourneyCount'] = "SELECT COUNT(*) FROM Tourneys"
5408 self
.query
['getTourneyTypeCount'] = "SELECT COUNT(*) FROM TourneyTypes"
5410 ################################
5411 # queries for dumpDatabase
5412 ################################
5413 for table
in (u
'Autorates', u
'Backings', u
'Gametypes', u
'Hands', u
'HandsActions', u
'HandsPlayers', u
'HudCache', u
'Players', u
'RawHands', u
'RawTourneys', u
'Settings', u
'Sites', u
'TourneyTypes', u
'Tourneys', u
'TourneysPlayers'):
5414 self
.query
['get'+table
] = u
"SELECT * FROM "+table
5416 ################################
5417 # placeholders and substitution stuff
5418 ################################
5419 if db_server
== 'mysql':
5420 self
.query
['placeholder'] = u
'%s'
5421 elif db_server
== 'postgresql':
5422 self
.query
['placeholder'] = u
'%s'
5423 elif db_server
== 'sqlite':
5424 self
.query
['placeholder'] = u
'?'
5427 # If using sqlite, use the ? placeholder instead of %s
5428 if db_server
== 'sqlite':
5429 for k
,q
in self
.query
.iteritems():
5430 self
.query
[k
] = re
.sub('%s','?',q
)
5432 if __name__
== "__main__":
5433 # just print the default queries and exit
5436 print "For query " + key
+ ", sql ="