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>
2606 /*and hp.tourneysPlayersId IS NULL*/
2607 and h.seats <seats_test>
2611 and date_format(h.startTime, '%Y-%m-%d %T') <datestest>
2612 group by hgametypeId
2618 ,upper(gt.limitType)
2620 having 1 = 1 <havingclause>
2625 ,case <position> when 'B' then 'B'
2627 else concat('Z', <position>)
2629 <orderbyhgametypeId>
2630 ,upper(gt.limitType) desc
2634 elif db_server
== 'postgresql':
2635 self
.query
['playerDetailedStats'] = """
2636 select <hgametypeId> AS hgametypeid
2637 ,<playerName> AS pname
2640 ,upper(gt.limitType) AS limittype
2642 ,min(gt.bigBlind) AS minbigblind
2643 ,max(gt.bigBlind) AS maxbigblind
2644 /*,<hcgametypeId> AS gtid*/
2645 ,<position> AS plposition
2647 ,100.0*sum(cast(hp.street0VPI as <signed>integer))/count(1) AS vpip
2648 ,100.0*sum(cast(hp.street0Aggr as <signed>integer))/count(1) AS pfr
2649 ,case when sum(cast(hp.street0_3Bchance as <signed>integer)) = 0 then -999
2650 else 100.0*sum(cast(hp.street0_3Bdone as <signed>integer))/sum(cast(hp.street0_3Bchance as <signed>integer))
2652 ,case when sum(cast(hp.street0_4Bchance as <signed>integer)) = 0 then -999
2653 else 100.0*sum(cast(hp.street0_4Bdone as <signed>integer))/sum(cast(hp.street0_4Bchance as <signed>integer))
2655 ,case when sum(cast(hp.street0_FoldTo3Bchance as <signed>integer)) = 0 then -999
2656 else 100.0*sum(cast(hp.street0_FoldTo3Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo3Bchance as <signed>integer))
2658 ,case when sum(cast(hp.street0_FoldTo4Bchance as <signed>integer)) = 0 then -999
2659 else 100.0*sum(cast(hp.street0_FoldTo4Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo4Bchance as <signed>integer))
2661 ,case when sum(cast(hp.raiseFirstInChance as <signed>integer)) = 0 then -999
2662 else 100.0 * sum(cast(hp.raisedFirstIn as <signed>integer)) /
2663 sum(cast(hp.raiseFirstInChance as <signed>integer))
2665 ,case when sum(case hp.position
2666 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2667 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2668 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2673 sum(case hp.position
2674 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2675 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2676 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2680 sum(case hp.position
2681 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2682 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2683 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2688 ,case when sum(cast(hp.success_Steal as <signed>integer)) = 0 then -999
2690 sum(cast(hp.success_Steal as <signed>integer))
2692 sum(case hp.position
2693 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2694 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2695 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2700 ,100.0*sum(cast(hp.street1Seen as <signed>integer))/count(1) AS saw_f
2701 ,100.0*sum(cast(hp.sawShowdown as <signed>integer))/count(1) AS sawsd
2702 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2703 else 100.0*sum(cast(hp.sawShowdown as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2705 ,case when sum(cast(hp.sawShowdown as <signed>integer)) = 0 then -999
2706 else 100.0*sum(cast(hp.wonAtSD as <signed>integer))/sum(cast(hp.sawShowdown as <signed>integer))
2708 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2709 else 100.0*sum(cast(hp.street1Aggr as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2711 ,case when sum(cast(hp.street2Seen as <signed>integer)) = 0 then -999
2712 else 100.0*sum(cast(hp.street2Aggr as <signed>integer))/sum(cast(hp.street2Seen as <signed>integer))
2714 ,case when sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
2715 else 100.0*sum(cast(hp.street3Aggr as <signed>integer))/sum(cast(hp.street3Seen as <signed>integer))
2717 ,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
2718 else 100.0*(sum(cast(hp.street1Aggr as <signed>integer))+sum(cast(hp.street2Aggr as <signed>integer))+sum(cast(hp.street3Aggr as <signed>integer)))
2719 /(sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)))
2721 ,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
2722 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)))
2723 /(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)))
2726 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))+
2727 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))+
2728 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 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)))
2732 / ((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))) +
2733 (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))) +
2734 (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))) )
2737 sum(cast(hp.street1CBChance as <signed>integer))+
2738 sum(cast(hp.street2CBChance as <signed>integer))+
2739 sum(cast(hp.street3CBChance as <signed>integer))+
2740 sum(cast(hp.street4CBChance as <signed>integer)) = 0 then -999
2742 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)))
2743 / (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)))
2745 ,sum(hp.totalProfit)/100.0 AS net
2746 ,sum(hp.rake)/100.0 AS rake
2747 ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100
2748 ,avg(hp.totalProfit)/100.0 AS profitperhand
2749 ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr
2750 ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr
2751 ,avg(h.seats+0.0) AS avgseats
2752 ,variance(hp.totalProfit/100.0) AS variance
2753 from HandsPlayers hp
2754 inner join Hands h on (h.id = hp.handId)
2755 inner join Gametypes gt on (gt.Id = h.gametypeId)
2756 inner join Sites s on (s.Id = gt.siteId)
2757 inner join Players p on (p.Id = hp.playerId)
2758 where hp.playerId in <player_test>
2762 /*and hp.tourneysPlayersId IS NULL*/
2763 and h.seats <seats_test>
2767 and to_char(h.startTime, 'YYYY-MM-DD HH24:MI:SS') <datestest>
2768 group by hgametypeId
2774 ,upper(gt.limitType)
2776 having 1 = 1 <havingclause>
2781 ,case <position> when 'B' then 'B'
2784 else 'Z'||<position>
2786 <orderbyhgametypeId>
2787 ,upper(gt.limitType) desc
2791 elif db_server
== 'sqlite':
2792 self
.query
['playerDetailedStats'] = """
2793 select <hgametypeId> AS hgametypeid
2794 ,<playerName> AS pname
2796 ,gt.category AS category
2797 ,upper(gt.limitType) AS limittype
2799 ,min(gt.bigBlind) AS minbigblind
2800 ,max(gt.bigBlind) AS maxbigblind
2801 /*,<hcgametypeId> AS gtid*/
2802 ,<position> AS plposition
2804 ,100.0*sum(cast(hp.street0VPI as <signed>integer))/count(1) AS vpip
2805 ,100.0*sum(cast(hp.street0Aggr as <signed>integer))/count(1) AS pfr
2806 ,case when sum(cast(hp.street0_3Bchance as <signed>integer)) = 0 then -999
2807 else 100.0*sum(cast(hp.street0_3Bdone as <signed>integer))/sum(cast(hp.street0_3Bchance as <signed>integer))
2809 ,case when sum(cast(hp.street0_4Bchance as <signed>integer)) = 0 then -999
2810 else 100.0*sum(cast(hp.street0_4Bdone as <signed>integer))/sum(cast(hp.street0_4Bchance as <signed>integer))
2812 ,case when sum(cast(hp.street0_FoldTo3Bchance as <signed>integer)) = 0 then -999
2813 else 100.0*sum(cast(hp.street0_FoldTo3Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo3Bchance as <signed>integer))
2815 ,case when sum(cast(hp.street0_FoldTo4Bchance as <signed>integer)) = 0 then -999
2816 else 100.0*sum(cast(hp.street0_FoldTo4Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo4Bchance as <signed>integer))
2818 ,case when sum(cast(hp.raiseFirstInChance as <signed>integer)) = 0 then -999
2819 else 100.0 * sum(cast(hp.raisedFirstIn as <signed>integer)) /
2820 sum(cast(hp.raiseFirstInChance as <signed>integer))
2822 ,case when sum(case hp.position
2823 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2824 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2825 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2830 sum(case hp.position
2831 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2832 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2833 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2837 sum(case hp.position
2838 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2839 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2840 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2845 ,case when sum(cast(hp.success_Steal as <signed>integer)) = 0 then -999
2847 sum(cast(hp.success_Steal as <signed>integer))
2849 sum(case hp.position
2850 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2851 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2852 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2857 ,100.0*sum(cast(hp.street1Seen as <signed>integer))/count(1) AS saw_f
2858 ,100.0*sum(cast(hp.sawShowdown as <signed>integer))/count(1) AS sawsd
2859 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2860 else 100.0*sum(cast(hp.sawShowdown as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2862 ,case when sum(cast(hp.sawShowdown as <signed>integer)) = 0 then -999
2863 else 100.0*sum(cast(hp.wonAtSD as <signed>integer))/sum(cast(hp.sawShowdown as <signed>integer))
2865 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2866 else 100.0*sum(cast(hp.street1Aggr as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2868 ,case when sum(cast(hp.street2Seen as <signed>integer)) = 0 then -999
2869 else 100.0*sum(cast(hp.street2Aggr as <signed>integer))/sum(cast(hp.street2Seen as <signed>integer))
2871 ,case when sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
2872 else 100.0*sum(cast(hp.street3Aggr as <signed>integer))/sum(cast(hp.street3Seen as <signed>integer))
2874 ,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
2875 else 100.0*(sum(cast(hp.street1Aggr as <signed>integer))+sum(cast(hp.street2Aggr as <signed>integer))+sum(cast(hp.street3Aggr as <signed>integer)))
2876 /(sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)))
2878 ,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
2879 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)))
2880 /(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)))
2882 ,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)))
2883 / ((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))) +
2884 (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))) +
2885 (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))) )
2887 ,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)))
2888 / (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)))
2890 ,sum(hp.totalProfit)/100.0 AS net
2891 ,sum(hp.rake)/100.0 AS rake
2892 ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100
2893 ,avg(hp.totalProfit)/100.0 AS profitperhand
2894 ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr
2895 ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr
2896 ,avg(h.seats+0.0) AS avgseats
2897 ,variance(hp.totalProfit/100.0) AS variance
2898 from HandsPlayers hp
2899 inner join Hands h on (h.id = hp.handId)
2900 inner join Gametypes gt on (gt.Id = h.gametypeId)
2901 inner join Sites s on (s.Id = gt.siteId)
2902 inner join Players p on (p.Id = hp.playerId)
2903 where hp.playerId in <player_test>
2907 /*and hp.tourneysPlayersId IS NULL*/
2908 and h.seats <seats_test>
2912 and datetime(h.startTime) <datestest>
2913 group by hgametypeId
2919 ,upper(gt.limitType)
2921 having 1 = 1 <havingclause>
2922 order by hp.playerId
2926 ,case <position> when 'B' then 'B'
2929 else 'Z'||<position>
2931 <orderbyhgametypeId>
2932 ,upper(gt.limitType) desc
2933 ,max(gt.bigBlind) desc
2937 #FIXME: 3/4bet and foldTo don't added four tournaments yet
2938 if db_server
== 'mysql':
2939 self
.query
['tourneyPlayerDetailedStats'] = """
2940 select s.name AS siteName
2941 ,t.tourneyTypeId AS tourneyTypeId
2942 ,tt.currency AS currency
2944 WHEN tt.currency = 'USD' THEN tt.buyIn/100.0
2945 WHEN tt.currency = 'EUR' THEN tt.buyIn/100.0
2948 ,tt.fee/100.0 AS fee
2949 ,tt.category AS category
2950 ,tt.limitType AS limitType
2951 ,p.name AS playerName
2952 ,COUNT(1) AS tourneyCount
2953 ,SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END) AS unknownRank
2954 ,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
2955 ,SUM(CASE WHEN rank = 1 THEN 1 ELSE 0 END) AS _1st
2956 ,SUM(CASE WHEN rank = 2 THEN 1 ELSE 0 END) AS _2nd
2957 ,SUM(CASE WHEN rank = 3 THEN 1 ELSE 0 END) AS _3rd
2958 ,SUM(tp.winnings)/100.0 AS won
2959 ,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
2960 ,SUM(tp.winnings)/SUM(tt.buyin+tt.fee)*100.0-100 AS roi
2961 ,SUM(tp.winnings-(tt.buyin+tt.fee))/100.0/(COUNT(1)-SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END)) AS profitPerTourney
2962 from TourneysPlayers tp
2963 inner join Tourneys t on (t.id = tp.tourneyId)
2964 inner join TourneyTypes tt on (tt.Id = t.tourneyTypeId)
2965 inner join Sites s on (s.Id = tt.siteId)
2966 inner join Players p on (p.Id = tp.playerId)
2967 where tp.playerId in <nametest> <sitetest>
2968 and date_format(t.startTime, '%Y-%m-%d %T') <datestest>
2969 group by tourneyTypeId, playerName
2970 order by tourneyTypeId
2973 elif db_server
== 'postgresql':
2974 # sc: itm and profitPerTourney changed to "ELSE 0" to avoid divide by zero error as temp fix
2975 # proper fix should use coalesce() or case ... when ... to work in all circumstances
2976 self
.query
['tourneyPlayerDetailedStats'] = """
2977 select s.name AS "siteName"
2978 ,t.tourneyTypeId AS "tourneyTypeId"
2979 ,tt.currency AS "currency"
2981 WHEN tt.currency = 'USD' THEN tt.buyIn/100.0
2982 WHEN tt.currency = 'EUR' THEN tt.buyIn/100.0
2985 ,tt.fee/100.0 AS "fee"
2986 ,tt.category AS "category"
2987 ,tt.limitType AS "limitType"
2988 ,p.name AS "playerName"
2989 ,COUNT(1) AS "tourneyCount"
2990 ,SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END) AS "unknownRank"
2991 ,SUM(CASE WHEN winnings > 0 THEN 1 ELSE 0 END)
2992 /(COUNT(1) - SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 0 END)) AS "itm"
2993 ,SUM(CASE WHEN rank = 1 THEN 1 ELSE 0 END) AS "_1st"
2994 ,SUM(CASE WHEN rank = 2 THEN 1 ELSE 0 END) AS "_2nd"
2995 ,SUM(CASE WHEN rank = 3 THEN 1 ELSE 0 END) AS "_3rd"
2996 ,SUM(tp.winnings)/100.0 AS "won"
2997 ,SUM(CASE WHEN tt.currency = 'USD' THEN (tt.buyIn+tt.fee)/100.0 ELSE tt.buyIn END) AS "spent"
2998 ,SUM(tp.winnings)/SUM(tt.buyin+tt.fee)*100.0-100 AS "roi"
2999 ,SUM(tp.winnings-(tt.buyin+tt.fee))/100.0
3000 /(COUNT(1)-SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 0 END)) AS "profitPerTourney"
3001 from TourneysPlayers tp
3002 inner join Tourneys t on (t.id = tp.tourneyId)
3003 inner join TourneyTypes tt on (tt.Id = t.tourneyTypeId)
3004 inner join Sites s on (s.Id = tt.siteId)
3005 inner join Players p on (p.Id = tp.playerId)
3006 where tp.playerId in <nametest> <sitetest>
3007 and to_char(t.startTime, 'YYYY-MM-DD HH24:MI:SS') <datestest>
3008 group by t.tourneyTypeId, s.name, p.name, tt.currency, tt.buyin, tt.fee
3009 , tt.category, tt.limitType
3010 order by t.tourneyTypeId
3013 elif db_server
== 'sqlite':
3014 self
.query
['tourneyPlayerDetailedStats'] = """
3015 select s.name AS siteName
3016 ,t.tourneyTypeId AS tourneyTypeId
3017 ,tt.currency AS currency
3019 WHEN tt.currency = 'USD' THEN tt.buyIn/100.0
3020 WHEN tt.currency = 'EUR' THEN tt.buyIn/100.0
3023 ,tt.fee/100.0 AS fee
3024 ,tt.category AS category
3025 ,tt.limitType AS limitType
3026 ,p.name AS playerName
3027 ,COUNT(1) AS tourneyCount
3028 ,SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END) AS unknownRank
3029 ,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
3030 ,SUM(CASE WHEN rank = 1 THEN 1 ELSE 0 END) AS _1st
3031 ,SUM(CASE WHEN rank = 2 THEN 1 ELSE 0 END) AS _2nd
3032 ,SUM(CASE WHEN rank = 3 THEN 1 ELSE 0 END) AS _3rd
3033 ,SUM(tp.winnings)/100.0 AS won
3034 ,SUM(CASE WHEN tt.currency = 'USD' THEN (tt.buyIn+tt.fee)/100.0 ELSE tt.buyIn END) AS spent
3035 ,SUM(tp.winnings)/SUM(tt.buyin+tt.fee)*100.0-100 AS roi
3036 ,SUM(tp.winnings-(tt.buyin+tt.fee))/100.0/(COUNT(1)-SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END)) AS profitPerTourney
3037 from TourneysPlayers tp
3038 inner join Tourneys t on (t.id = tp.tourneyId)
3039 inner join TourneyTypes tt on (tt.Id = t.tourneyTypeId)
3040 inner join Sites s on (s.Id = tt.siteId)
3041 inner join Players p on (p.Id = tp.playerId)
3042 where tp.playerId in <nametest> <sitetest>
3043 and datetime(t.startTime) <datestest>
3044 group by tourneyTypeId, playerName
3045 order by tourneyTypeId
3049 if db_server
== 'mysql':
3050 self
.query
['playerStats'] = """
3052 concat(upper(stats.limitType), ' '
3053 ,concat(upper(substring(stats.category,1,1)),substring(stats.category,2) ), ' '
3055 ,cast(stats.bigBlindDesc as char)
3075 ,stats.Profitperhand
3076 ,case when hprof2.variance = -999 then '-'
3077 else format(hprof2.variance, 2)
3081 (select /* stats from hudcache */
3084 ,upper(gt.limitType) as limitType
3086 ,<selectgt.bigBlind> AS bigBlindDesc
3087 ,<hcgametypeId> AS gtId
3089 ,format(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
3090 ,format(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
3091 ,case when sum(street0_3Bchance) = 0 then '0'
3092 else format(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
3094 ,case when sum(street0_4Bchance) = 0 then '0'
3095 else format(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
3097 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
3098 else format(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
3100 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
3101 else format(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
3103 ,case when sum(raiseFirstInChance) = 0 then '-'
3104 else format(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
3106 ,format(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
3107 ,format(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
3108 ,case when sum(street1Seen) = 0 then '-'
3109 else format(100.0*sum(sawShowdown)/sum(street1Seen),1)
3111 ,case when sum(sawShowdown) = 0 then '-'
3112 else format(100.0*sum(wonAtSD)/sum(sawShowdown),1)
3114 ,case when sum(street1Seen) = 0 then '-'
3115 else format(100.0*sum(street1Aggr)/sum(street1Seen),1)
3117 ,case when sum(street2Seen) = 0 then '-'
3118 else format(100.0*sum(street2Aggr)/sum(street2Seen),1)
3120 ,case when sum(street3Seen) = 0 then '-'
3121 else format(100.0*sum(street3Aggr)/sum(street3Seen),1)
3123 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3124 else format(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3125 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
3127 ,format(sum(totalProfit)/100.0,2) AS Net
3128 ,format((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
3130 ,format( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
3131 ,format( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
3133 inner join Sites s on s.Id = gt.siteId
3134 inner join HudCache hc on hc.gametypeId = gt.Id
3135 where hc.playerId in <player_test>
3136 and <gtbigBlind_test>
3137 and hc.activeSeats <seats_test>
3138 and concat( '20', substring(hc.styleKey,2,2), '-', substring(hc.styleKey,4,2), '-'
3139 , substring(hc.styleKey,6,2) ) <datestest>
3142 ,upper(gt.limitType)
3144 <groupbygt.bigBlind>
3148 ( select # profit from handsplayers/handsactions
3149 hprof.gtId, sum(hprof.profit) sum_profit,
3150 avg(hprof.profit/100.0) profitperhand,
3151 case when hprof.gtId = -1 then -999
3152 else variance(hprof.profit/100.0)
3155 (select hp.handId, <hgametypeId> as gtId, hp.totalProfit as profit
3156 from HandsPlayers hp
3157 inner join Hands h ON h.id = hp.handId
3158 where hp.playerId in <player_test>
3159 and hp.tourneysPlayersId IS NULL
3160 and date_format(h.startTime, '%Y-%m-%d') <datestest>
3161 group by hp.handId, gtId, hp.totalProfit
3165 on hprof2.gtId = stats.gtId
3166 order by stats.category, stats.limittype, stats.bigBlindDesc desc <orderbyseats>"""
3167 elif db_server
== 'sqlite':
3168 self
.query
['playerStats'] = """
3170 upper(substr(stats.category,1,1)) || substr(stats.category,2) || ' ' ||
3171 stats.name || ' ' ||
3172 cast(stats.bigBlindDesc as char) || ' ' || stats.maxSeats || ' seat' AS Game
3173 ,stats.n,stats.vpip,stats.pfr,stats.pf3,stats.pf4,stats.pff3,stats.pff4
3174 ,stats.steals,stats.saw_f,stats.sawsd,stats.wtsdwsf,stats.wmsd,stats.FlAFq
3175 ,stats.TuAFq,stats.RvAFq,stats.PoFAFq,stats.Net,stats.BBper100,stats.Profitperhand
3176 ,case when hprof2.variance = -999 then '-' else round(hprof2.variance, 2)
3180 (select /* stats from hudcache */
3182 ,gt.category,maxSeats,gt.bigBlind,gt.currency
3183 ,upper(gt.limitType) AS limitType
3185 ,<selectgt.bigBlind> AS bigBlindDesc
3186 ,<hcgametypeId> AS gtId
3188 ,round(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
3189 ,round(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
3190 ,case when sum(street0_3Bchance) = 0 then '0'
3191 else round(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
3193 ,case when sum(street0_4Bchance) = 0 then '0'
3194 else round(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
3196 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
3197 else round(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
3199 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
3200 else round(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
3202 ,case when sum(raiseFirstInChance) = 0 then '-'
3203 else round(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
3205 ,round(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
3206 ,round(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
3207 ,case when sum(street1Seen) = 0 then '-'
3208 else round(100.0*sum(sawShowdown)/sum(street1Seen),1)
3210 ,case when sum(sawShowdown) = 0 then '-'
3211 else round(100.0*sum(wonAtSD)/sum(sawShowdown),1)
3213 ,case when sum(street1Seen) = 0 then '-'
3214 else round(100.0*sum(street1Aggr)/sum(street1Seen),1)
3216 ,case when sum(street2Seen) = 0 then '-'
3217 else round(100.0*sum(street2Aggr)/sum(street2Seen),1)
3219 ,case when sum(street3Seen) = 0 then '-'
3220 else round(100.0*sum(street3Aggr)/sum(street3Seen),1)
3222 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3223 else round(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3224 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
3226 ,round(sum(totalProfit)/100.0,2) AS Net
3227 ,round((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
3229 ,round( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
3230 ,round( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
3232 inner join Sites s on s.Id = gt.siteId
3233 inner join HudCache hc on hc.gametypeId = gt.Id
3234 where hc.playerId in <player_test>
3235 and <gtbigBlind_test>
3236 and hc.activeSeats <seats_test>
3237 and '20' || substr(hc.styleKey,2,2) || '-' || substr(hc.styleKey,4,2) || '-' ||
3238 substr(hc.styleKey,6,2) <datestest>
3239 group by gt.base,gt.category,upper(gt.limitType),s.name <groupbygt.bigBlind>,gtId
3242 ( select /* profit from handsplayers/handsactions */
3243 hprof.gtId, sum(hprof.profit) sum_profit,
3244 avg(hprof.profit/100.0) profitperhand,
3245 case when hprof.gtId = -1 then -999
3246 else variance(hprof.profit/100.0)
3249 (select hp.handId, <hgametypeId> as gtId, hp.totalProfit as profit
3250 from HandsPlayers hp
3251 inner join Hands h ON h.id = hp.handId
3252 where hp.playerId in <player_test>
3253 and hp.tourneysPlayersId IS NULL
3254 and datetime(h.startTime) <datestest>
3255 group by hp.handId, gtId, hp.totalProfit
3259 on hprof2.gtId = stats.gtId
3260 order by stats.category, stats.bigBlind, stats.limittype, stats.currency, stats.maxSeats <orderbyseats>"""
3261 else: # assume postgres
3262 self
.query
['playerStats'] = """
3263 SELECT upper(stats.limitType) || ' '
3264 || initcap(stats.category) || ' '
3265 || stats.name || ' '
3266 || stats.bigBlindDesc AS Game
3285 ,stats.Profitperhand
3286 ,case when hprof2.variance = -999 then '-'
3287 else to_char(hprof2.variance, '0D00')
3293 ,upper(gt.limitType) AS limitType
3295 ,<selectgt.bigBlind> AS bigBlindDesc
3296 ,<hcgametypeId> AS gtId
3298 ,to_char(100.0*sum(street0VPI)/sum(HDs),'990D0') AS vpip
3299 ,to_char(100.0*sum(street0Aggr)/sum(HDs),'90D0') AS pfr
3300 ,case when sum(street0_3Bchance) = 0 then '0'
3301 else to_char(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),'90D0')
3303 ,case when sum(raiseFirstInChance) = 0 then '-'
3304 else to_char(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),'90D0')
3306 ,to_char(100.0*sum(street1Seen)/sum(HDs),'90D0') AS saw_f
3307 ,to_char(100.0*sum(sawShowdown)/sum(HDs),'90D0') AS sawsd
3308 ,case when sum(street1Seen) = 0 then '-'
3309 else to_char(100.0*sum(sawShowdown)/sum(street1Seen),'90D0')
3311 ,case when sum(sawShowdown) = 0 then '-'
3312 else to_char(100.0*sum(wonAtSD)/sum(sawShowdown),'90D0')
3314 ,case when sum(street1Seen) = 0 then '-'
3315 else to_char(100.0*sum(street1Aggr)/sum(street1Seen),'90D0')
3317 ,case when sum(street2Seen) = 0 then '-'
3318 else to_char(100.0*sum(street2Aggr)/sum(street2Seen),'90D0')
3320 ,case when sum(street3Seen) = 0 then '-'
3321 else to_char(100.0*sum(street3Aggr)/sum(street3Seen),'90D0')
3323 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3324 else to_char(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3325 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),'90D0')
3327 ,round(sum(totalProfit)/100.0,2) AS Net
3328 ,to_char((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0), '990D00')
3330 ,to_char(sum(totalProfit/100.0) / (sum(HDs)+0.0), '990D0000') AS Profitperhand
3331 ,to_char(sum(activeSeats*HDs)/(sum(HDs)+0.0),'90D00') AS AvgSeats
3333 inner join Sites s on s.Id = gt.siteId
3334 inner join HudCache hc on hc.gametypeId = gt.Id
3335 where hc.playerId in <player_test>
3336 and <gtbigBlind_test>
3337 and hc.activeSeats <seats_test>
3338 and '20' || SUBSTR(hc.styleKey,2,2) || '-' || SUBSTR(hc.styleKey,4,2) || '-'
3339 || SUBSTR(hc.styleKey,6,2) <datestest>
3342 ,upper(gt.limitType)
3344 <groupbygt.bigBlind>
3349 hprof.gtId, sum(hprof.profit) AS sum_profit,
3350 avg(hprof.profit/100.0) AS profitperhand,
3351 case when hprof.gtId = -1 then -999
3352 else variance(hprof.profit/100.0)
3355 (select hp.handId, <hgametypeId> as gtId, hp.totalProfit as profit
3356 from HandsPlayers hp
3357 inner join Hands h ON (h.id = hp.handId)
3358 where hp.playerId in <player_test>
3359 and hp.tourneysPlayersId IS NULL
3360 and to_char(h.startTime, 'YYYY-MM-DD') <datestest>
3361 group by hp.handId, gtId, hp.totalProfit
3365 on hprof2.gtId = stats.gtId
3366 order by stats.base, stats.limittype, stats.bigBlindDesc desc <orderbyseats>"""
3368 if db_server
== 'mysql':
3369 self
.query
['playerStatsByPosition'] = """
3371 concat(upper(stats.limitType), ' '
3372 ,concat(upper(substring(stats.category,1,1)),substring(stats.category,2) ), ' '
3374 ,cast(stats.bigBlindDesc as char)
3376 ,case when stats.PlPosition = -2 then 'BB'
3377 when stats.PlPosition = -1 then 'SB'
3378 when stats.PlPosition = 0 then 'Btn'
3379 when stats.PlPosition = 1 then 'CO'
3380 when stats.PlPosition = 2 then 'MP'
3381 when stats.PlPosition = 5 then 'EP'
3402 ,stats.Profitperhand
3403 ,case when hprof2.variance = -999 then '-'
3404 else format(hprof2.variance, 2)
3408 (select /* stats from hudcache */
3411 ,upper(gt.limitType) AS limitType
3413 ,<selectgt.bigBlind> AS bigBlindDesc
3414 ,<hcgametypeId> AS gtId
3415 ,case when hc.position = 'B' then -2
3416 when hc.position = 'S' then -1
3417 when hc.position = 'D' then 0
3418 when hc.position = 'C' then 1
3419 when hc.position = 'M' then 2
3420 when hc.position = 'E' then 5
3424 ,format(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
3425 ,format(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
3426 ,case when sum(street0_3Bchance) = 0 then '0'
3427 else format(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
3429 ,case when sum(street0_4Bchance) = 0 then '0'
3430 else format(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
3432 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
3433 else format(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
3435 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
3436 else format(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
3438 ,case when sum(raiseFirstInChance) = 0 then '-'
3439 else format(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
3441 ,format(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
3442 ,format(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
3443 ,case when sum(street1Seen) = 0 then '-'
3444 else format(100.0*sum(sawShowdown)/sum(street1Seen),1)
3446 ,case when sum(sawShowdown) = 0 then '-'
3447 else format(100.0*sum(wonAtSD)/sum(sawShowdown),1)
3449 ,case when sum(street1Seen) = 0 then '-'
3450 else format(100.0*sum(street1Aggr)/sum(street1Seen),1)
3452 ,case when sum(street2Seen) = 0 then '-'
3453 else format(100.0*sum(street2Aggr)/sum(street2Seen),1)
3455 ,case when sum(street3Seen) = 0 then '-'
3456 else format(100.0*sum(street3Aggr)/sum(street3Seen),1)
3458 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3459 else format(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3460 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
3462 ,format(sum(totalProfit)/100.0,2) AS Net
3463 ,format((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
3465 ,format( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
3466 ,format( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
3468 inner join Sites s on s.Id = gt.siteId
3469 inner join HudCache hc on hc.gametypeId = gt.Id
3470 where hc.playerId in <player_test>
3471 and <gtbigBlind_test>
3472 and hc.activeSeats <seats_test>
3473 and concat( '20', substring(hc.styleKey,2,2), '-', substring(hc.styleKey,4,2), '-'
3474 , substring(hc.styleKey,6,2) ) <datestest>
3477 ,upper(gt.limitType)
3479 <groupbygt.bigBlind>
3485 ( select # profit from handsplayers/handsactions
3487 case when hprof.position = 'B' then -2
3488 when hprof.position = 'S' then -1
3489 when hprof.position in ('3','4') then 2
3490 when hprof.position in ('6','7') then 5
3493 sum(hprof.profit) as sum_profit,
3494 avg(hprof.profit/100.0) as profitperhand,
3495 case when hprof.gtId = -1 then -999
3496 else variance(hprof.profit/100.0)
3499 (select hp.handId, <hgametypeId> as gtId, hp.position
3500 , hp.totalProfit as profit
3501 from HandsPlayers hp
3502 inner join Hands h ON (h.id = hp.handId)
3503 where hp.playerId in <player_test>
3504 and hp.tourneysPlayersId IS NULL
3505 and date_format(h.startTime, '%Y-%m-%d') <datestest>
3506 group by hp.handId, gtId, hp.position, hp.totalProfit
3508 group by hprof.gtId, PlPosition
3510 on ( hprof2.gtId = stats.gtId
3511 and hprof2.PlPosition = stats.PlPosition)
3512 order by stats.category, stats.limitType, stats.bigBlindDesc desc
3513 <orderbyseats>, cast(stats.PlPosition as signed)
3515 elif db_server
== 'sqlite':
3516 self
.query
['playerStatsByPosition'] = """
3518 upper(substr(stats.category,1,1)) || substr(stats.category,2) || ' ' ||
3519 stats.name || ' ' ||
3520 cast(stats.bigBlindDesc as char) || ' ' || stats.maxSeats || ' seat' AS Game
3521 ,case when stats.PlPosition = -2 then 'BB'
3522 when stats.PlPosition = -1 then 'SB'
3523 when stats.PlPosition = 0 then 'Btn'
3524 when stats.PlPosition = 1 then 'CO'
3525 when stats.PlPosition = 2 then 'MP'
3526 when stats.PlPosition = 5 then 'EP'
3529 ,stats.n,stats.vpip,stats.pfr,stats.pf3,stats.pf4,stats.pff3,stats.pff4
3530 ,stats.steals,stats.saw_f,stats.sawsd,stats.wtsdwsf,stats.wmsd,stats.FlAFq
3531 ,stats.TuAFq,stats.RvAFq,stats.PoFAFq,stats.Net,stats.BBper100,stats.Profitperhand
3532 ,case when hprof2.variance = -999 then '-'
3533 else round(hprof2.variance, 2)
3537 (select /* stats from hudcache */
3539 ,gt.category,maxSeats,gt.bigBlind,gt.currency
3540 ,upper(gt.limitType) AS limitType
3542 ,<selectgt.bigBlind> AS bigBlindDesc
3543 ,<hcgametypeId> AS gtId
3544 ,case when hc.position = 'B' then -2
3545 when hc.position = 'S' then -1
3546 when hc.position = 'D' then 0
3547 when hc.position = 'C' then 1
3548 when hc.position = 'M' then 2
3549 when hc.position = 'E' then 5
3553 ,round(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
3554 ,round(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
3555 ,case when sum(street0_3Bchance) = 0 then '0'
3556 else round(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
3558 ,case when sum(street0_4Bchance) = 0 then '0'
3559 else round(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
3561 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
3562 else round(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
3564 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
3565 else round(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
3567 ,case when sum(raiseFirstInChance) = 0 then '-'
3568 else round(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
3570 ,round(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
3571 ,round(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
3572 ,case when sum(street1Seen) = 0 then '-'
3573 else round(100.0*sum(sawShowdown)/sum(street1Seen),1)
3575 ,case when sum(sawShowdown) = 0 then '-'
3576 else round(100.0*sum(wonAtSD)/sum(sawShowdown),1)
3578 ,case when sum(street1Seen) = 0 then '-'
3579 else round(100.0*sum(street1Aggr)/sum(street1Seen),1)
3581 ,case when sum(street2Seen) = 0 then '-'
3582 else round(100.0*sum(street2Aggr)/sum(street2Seen),1)
3584 ,case when sum(street3Seen) = 0 then '-'
3585 else round(100.0*sum(street3Aggr)/sum(street3Seen),1)
3587 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3588 else round(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3589 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
3591 ,round(sum(totalProfit)/100.0,2) AS Net
3592 ,round((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
3594 ,round( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
3595 ,round( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
3597 inner join Sites s on s.Id = gt.siteId
3598 inner join HudCache hc on hc.gametypeId = gt.Id
3599 where hc.playerId in <player_test>
3600 and <gtbigBlind_test>
3601 and hc.activeSeats <seats_test>
3602 and '20' || substr(hc.styleKey,2,2) || '-' || substr(hc.styleKey,4,2) || '-' ||
3603 substr(hc.styleKey,6,2) <datestest>
3604 group by gt.base,gt.category,upper(gt.limitType),s.name
3605 <groupbygt.bigBlind>,gtId<groupbyseats>,PlPosition
3608 ( select /* profit from handsplayers/handsactions */
3610 cast(case when hprof.position = 'B' then -2
3611 when hprof.position = 'S' then -1
3612 when hprof.position in ('3','4') then 2
3613 when hprof.position in ('6','7') then 5
3615 end as signed) as PlPosition,
3616 sum(hprof.profit) as sum_profit,
3617 avg(hprof.profit/100.0) as profitperhand,
3618 case when hprof.gtId = -1 then -999
3619 else variance(hprof.profit/100.0)
3622 (select hp.handId, <hgametypeId> as gtId, hp.position
3623 , hp.totalProfit as profit
3624 from HandsPlayers hp
3625 inner join Hands h ON (h.id = hp.handId)
3626 where hp.playerId in <player_test>
3627 and hp.tourneysPlayersId IS NULL
3628 and datetime(h.startTime) <datestest>
3629 group by hp.handId, gtId, hp.position, hp.totalProfit
3631 group by hprof.gtId, PlPosition
3633 on ( hprof2.gtId = stats.gtId
3634 and hprof2.PlPosition = stats.PlPosition)
3635 order by stats.category, stats.bigBlind, stats.limitType, stats.currency, stats.maxSeats <orderbyseats>
3636 ,cast(stats.PlPosition as signed)
3638 else: # assume postgresql
3639 self
.query
['playerStatsByPosition'] = """
3640 select /* stats from hudcache */
3641 upper(stats.limitType) || ' '
3642 || upper(substr(stats.category,1,1)) || substr(stats.category,2) || ' '
3643 || stats.name || ' '
3644 || stats.bigBlindDesc AS Game
3645 ,case when stats.PlPosition = -2 then 'BB'
3646 when stats.PlPosition = -1 then 'SB'
3647 when stats.PlPosition = 0 then 'Btn'
3648 when stats.PlPosition = 1 then 'CO'
3649 when stats.PlPosition = 2 then 'MP'
3650 when stats.PlPosition = 5 then 'EP'
3671 ,stats.Profitperhand
3672 ,case when hprof2.variance = -999 then '-'
3673 else to_char(hprof2.variance, '0D00')
3677 (select /* stats from hudcache */
3680 ,upper(gt.limitType) AS limitType
3682 ,<selectgt.bigBlind> AS bigBlindDesc
3683 ,<hcgametypeId> AS gtId
3684 ,case when hc.position = 'B' then -2
3685 when hc.position = 'S' then -1
3686 when hc.position = 'D' then 0
3687 when hc.position = 'C' then 1
3688 when hc.position = 'M' then 2
3689 when hc.position = 'E' then 5
3693 ,to_char(round(100.0*sum(street0VPI)/sum(HDs)),'990D0') AS vpip
3694 ,to_char(round(100.0*sum(street0Aggr)/sum(HDs)),'90D0') AS pfr
3695 ,case when sum(street0_3Bchance) = 0 then '0'
3696 else to_char(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),'90D0')
3698 ,case when sum(street0_4Bchance) = 0 then '0'
3699 else to_char(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),'90D0')
3701 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
3702 else to_char(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),'90D0')
3704 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
3705 else to_char(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),'90D0')
3707 ,case when sum(raiseFirstInChance) = 0 then '-'
3708 else to_char(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),'90D0')
3710 ,to_char(round(100.0*sum(street1Seen)/sum(HDs)),'90D0') AS saw_f
3711 ,to_char(round(100.0*sum(sawShowdown)/sum(HDs)),'90D0') AS sawsd
3712 ,case when sum(street1Seen) = 0 then '-'
3713 else to_char(round(100.0*sum(sawShowdown)/sum(street1Seen)),'90D0')
3715 ,case when sum(sawShowdown) = 0 then '-'
3716 else to_char(round(100.0*sum(wonAtSD)/sum(sawShowdown)),'90D0')
3718 ,case when sum(street1Seen) = 0 then '-'
3719 else to_char(round(100.0*sum(street1Aggr)/sum(street1Seen)),'90D0')
3721 ,case when sum(street2Seen) = 0 then '-'
3722 else to_char(round(100.0*sum(street2Aggr)/sum(street2Seen)),'90D0')
3724 ,case when sum(street3Seen) = 0 then '-'
3725 else to_char(round(100.0*sum(street3Aggr)/sum(street3Seen)),'90D0')
3727 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3728 else to_char(round(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3729 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen))),'90D0')
3731 ,to_char(sum(totalProfit)/100.0,'9G999G990D00') AS Net
3732 ,case when sum(HDs) = 0 then '0'
3733 else to_char(sum(totalProfit/(gt.bigBlind+0.0)) / (sum(HDs)/100.0), '990D00')
3735 ,case when sum(HDs) = 0 then '0'
3736 else to_char( (sum(totalProfit)/100.0) / sum(HDs), '90D0000')
3737 end AS Profitperhand
3738 ,to_char(sum(activeSeats*HDs)/(sum(HDs)+0.0),'90D00') AS AvgSeats
3740 inner join Sites s on (s.Id = gt.siteId)
3741 inner join HudCache hc on (hc.gametypeId = gt.Id)
3742 where hc.playerId in <player_test>
3743 and <gtbigBlind_test>
3744 and hc.activeSeats <seats_test>
3745 and '20' || SUBSTR(hc.styleKey,2,2) || '-' || SUBSTR(hc.styleKey,4,2) || '-'
3746 || SUBSTR(hc.styleKey,6,2) <datestest>
3749 ,upper(gt.limitType)
3751 <groupbygt.bigBlind>
3757 ( select /* profit from handsplayers/handsactions */
3759 case when hprof.position = 'B' then -2
3760 when hprof.position = 'S' then -1
3761 when hprof.position in ('3','4') then 2
3762 when hprof.position in ('6','7') then 5
3763 else cast(hprof.position as smallint)
3765 sum(hprof.profit) as sum_profit,
3766 avg(hprof.profit/100.0) as profitperhand,
3767 case when hprof.gtId = -1 then -999
3768 else variance(hprof.profit/100.0)
3771 (select hp.handId, <hgametypeId> as gtId, hp.position
3772 , hp.totalProfit as profit
3773 from HandsPlayers hp
3774 inner join Hands h ON (h.id = hp.handId)
3775 where hp.playerId in <player_test>
3776 and hp.tourneysPlayersId IS NULL
3777 and to_char(h.startTime, 'YYYY-MM-DD') <datestest>
3778 group by hp.handId, gametypeId, hp.position, hp.totalProfit
3780 group by hprof.gtId, PlPosition
3782 on ( hprof2.gtId = stats.gtId
3783 and hprof2.PlPosition = stats.PlPosition)
3784 order by stats.category, stats.limitType, stats.bigBlindDesc desc
3785 <orderbyseats>, cast(stats.PlPosition as smallint)
3788 ####################################
3789 # Cash Game Graph query
3790 ####################################
3791 self
.query
['getRingProfitAllHandsPlayerIdSite'] = """
3792 SELECT hp.handId, hp.totalProfit, hp.sawShowdown
3793 FROM HandsPlayers hp
3794 INNER JOIN Players pl ON (pl.id = hp.playerId)
3795 INNER JOIN Hands h ON (h.id = hp.handId)
3796 INNER JOIN Gametypes gt ON (gt.id = h.gametypeId)
3797 WHERE pl.id in <player_test>
3798 AND pl.siteId in <site_test>
3799 AND h.startTime > '<startdate_test>'
3800 AND h.startTime < '<enddate_test>'
3803 AND gt.type = 'ring'
3804 GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit
3805 ORDER BY h.startTime"""
3807 self
.query
['getRingProfitAllHandsPlayerIdSiteInBB'] = """
3808 SELECT hp.handId, ( hp.totalProfit / ( gt.bigBlind * 2.0 ) ) * 100 , hp.sawShowdown
3809 FROM HandsPlayers hp
3810 INNER JOIN Players pl ON (pl.id = hp.playerId)
3811 INNER JOIN Hands h ON (h.id = hp.handId)
3812 INNER JOIN Gametypes gt ON (gt.id = h.gametypeId)
3813 WHERE pl.id in <player_test>
3814 AND pl.siteId in <site_test>
3815 AND h.startTime > '<startdate_test>'
3816 AND h.startTime < '<enddate_test>'
3820 AND hp.tourneysPlayersId IS NULL
3821 GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit
3822 ORDER BY h.startTime"""
3824 self
.query
['getRingProfitAllHandsPlayerIdSiteInDollars'] = """
3825 SELECT hp.handId, hp.totalProfit, hp.sawShowdown
3826 FROM HandsPlayers hp
3827 INNER JOIN Players pl ON (pl.id = hp.playerId)
3828 INNER JOIN Hands h ON (h.id = hp.handId)
3829 INNER JOIN Gametypes gt ON (gt.id = h.gametypeId)
3830 WHERE pl.id in <player_test>
3831 AND pl.siteId in <site_test>
3832 AND h.startTime > '<startdate_test>'
3833 AND h.startTime < '<enddate_test>'
3837 AND hp.tourneysPlayersId IS NULL
3838 GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit
3839 ORDER BY h.startTime"""
3843 ####################################
3844 # Tourney Results query
3845 ####################################
3846 self
.query
['tourneyResults'] = """
3847 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
3848 FROM TourneysPlayers tp
3849 INNER JOIN Players pl ON (pl.id = tp.playerId)
3850 INNER JOIN Tourneys t ON (t.id = tp.tourneyId)
3851 INNER JOIN TourneyTypes tt ON (tt.id = t.tourneyTypeId)
3852 WHERE pl.id in <player_test>
3853 AND pl.siteId in <site_test>
3854 AND t.startTime > '<startdate_test>'
3855 AND t.startTime < '<enddate_test>'
3856 GROUP BY t.startTime, tp.tourneyId, tp.winningsCurrency,
3857 tp.winnings, tp.koCount,
3858 tp.rebuyCount, tp.addOnCount,
3860 ORDER BY t.startTime"""
3862 #AND gt.type = 'ring'
3866 ####################################
3867 # Session stats query
3868 ####################################
3869 if db_server
== 'mysql':
3870 self
.query
['sessionStats'] = """
3871 SELECT UNIX_TIMESTAMP(h.startTime) as time, hp.totalProfit
3872 FROM HandsPlayers hp
3873 INNER JOIN Hands h on (h.id = hp.handId)
3874 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
3875 INNER JOIN Sites s on (s.Id = gt.siteId)
3876 INNER JOIN Players p on (p.Id = hp.playerId)
3877 WHERE hp.playerId in <player_test>
3878 AND date_format(h.startTime, '%Y-%m-%d') <datestest>
3879 AND gt.type LIKE 'ring'
3885 elif db_server
== 'postgresql':
3886 self
.query
['sessionStats'] = """
3887 SELECT EXTRACT(epoch from h.startTime) as time, hp.totalProfit
3888 FROM HandsPlayers hp
3889 INNER JOIN Hands h on (h.id = hp.handId)
3890 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
3891 INNER JOIN Sites s on (s.Id = gt.siteId)
3892 INNER JOIN Players p on (p.Id = hp.playerId)
3893 WHERE hp.playerId in <player_test>
3894 AND h.startTime <datestest>
3895 AND gt.type LIKE 'ring'
3901 elif db_server
== 'sqlite':
3902 self
.query
['sessionStats'] = """
3903 SELECT STRFTIME('<ampersand_s>', h.startTime) as time, hp.totalProfit
3904 FROM HandsPlayers hp
3905 INNER JOIN Hands h on (h.id = hp.handId)
3906 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
3907 INNER JOIN Sites s on (s.Id = gt.siteId)
3908 INNER JOIN Players p on (p.Id = hp.playerId)
3909 WHERE hp.playerId in <player_test>
3910 AND h.startTime <datestest>
3911 AND gt.type is 'ring'
3919 ####################################
3920 # Queries to rebuild/modify hudcache
3921 ####################################
3923 self
.query
['clearHudCache'] = """DELETE FROM HudCache"""
3925 if db_server
== 'mysql':
3926 self
.query
['rebuildHudCache'] = """
3927 INSERT INTO HudCache
3932 <tourney_insert_clause>
3948 ,street0_FoldTo3BChance
3949 ,street0_FoldTo3BDone
3950 ,street0_FoldTo4BChance
3951 ,street0_FoldTo4BDone
3952 ,street0_SqueezeChance
3953 ,street0_SqueezeDone
3971 ,foldToOtherRaisedStreet0
3972 ,foldToOtherRaisedStreet1
3973 ,foldToOtherRaisedStreet2
3974 ,foldToOtherRaisedStreet3
3975 ,foldToOtherRaisedStreet4
3978 ,foldBbToStealChance
3980 ,foldSbToStealChance
3990 ,foldToStreet1CBChance
3991 ,foldToStreet1CBDone
3992 ,foldToStreet2CBChance
3993 ,foldToStreet2CBDone
3994 ,foldToStreet3CBChance
3995 ,foldToStreet3CBDone
3996 ,foldToStreet4CBChance
3997 ,foldToStreet4CBDone
3999 ,street1CheckCallRaiseChance
4000 ,street1CheckCallRaiseDone
4001 ,street2CheckCallRaiseChance
4002 ,street2CheckCallRaiseDone
4003 ,street3CheckCallRaiseChance
4004 ,street3CheckCallRaiseDone
4005 ,street4CheckCallRaiseChance
4006 ,street4CheckCallRaiseDone
4026 ,case when hp.position = 'B' then 'B'
4027 when hp.position = 'S' then 'S'
4028 when hp.position = '0' then 'D'
4029 when hp.position = '1' then 'C'
4030 when hp.position = '2' then 'M'
4031 when hp.position = '3' then 'M'
4032 when hp.position = '4' then 'M'
4033 when hp.position = '5' then 'E'
4034 when hp.position = '6' then 'E'
4035 when hp.position = '7' then 'E'
4036 when hp.position = '8' then 'E'
4037 when hp.position = '9' then 'E'
4040 <tourney_select_clause>
4041 ,date_format(h.startTime, 'd%y%m%d')
4043 ,sum(wonWhenSeenStreet1)
4044 ,sum(wonWhenSeenStreet2)
4045 ,sum(wonWhenSeenStreet3)
4046 ,sum(wonWhenSeenStreet4)
4050 ,sum(street0_3BChance)
4051 ,sum(street0_3BDone)
4052 ,sum(street0_4BChance)
4053 ,sum(street0_4BDone)
4054 ,sum(street0_C4BChance)
4055 ,sum(street0_C4BDone)
4056 ,sum(street0_FoldTo3BChance)
4057 ,sum(street0_FoldTo3BDone)
4058 ,sum(street0_FoldTo4BChance)
4059 ,sum(street0_FoldTo4BDone)
4060 ,sum(street0_SqueezeChance)
4061 ,sum(street0_SqueezeDone)
4062 ,sum(raiseToStealChance)
4063 ,sum(raiseToStealDone)
4074 ,sum(otherRaisedStreet0)
4075 ,sum(otherRaisedStreet1)
4076 ,sum(otherRaisedStreet2)
4077 ,sum(otherRaisedStreet3)
4078 ,sum(otherRaisedStreet4)
4079 ,sum(foldToOtherRaisedStreet0)
4080 ,sum(foldToOtherRaisedStreet1)
4081 ,sum(foldToOtherRaisedStreet2)
4082 ,sum(foldToOtherRaisedStreet3)
4083 ,sum(foldToOtherRaisedStreet4)
4084 ,sum(raiseFirstInChance)
4086 ,sum(foldBbToStealChance)
4087 ,sum(foldedBbToSteal)
4088 ,sum(foldSbToStealChance)
4089 ,sum(foldedSbToSteal)
4090 ,sum(street1CBChance)
4092 ,sum(street2CBChance)
4094 ,sum(street3CBChance)
4096 ,sum(street4CBChance)
4098 ,sum(foldToStreet1CBChance)
4099 ,sum(foldToStreet1CBDone)
4100 ,sum(foldToStreet2CBChance)
4101 ,sum(foldToStreet2CBDone)
4102 ,sum(foldToStreet3CBChance)
4103 ,sum(foldToStreet3CBDone)
4104 ,sum(foldToStreet4CBChance)
4105 ,sum(foldToStreet4CBDone)
4107 ,sum(street1CheckCallRaiseChance)
4108 ,sum(street1CheckCallRaiseDone)
4109 ,sum(street2CheckCallRaiseChance)
4110 ,sum(street2CheckCallRaiseDone)
4111 ,sum(street3CheckCallRaiseChance)
4112 ,sum(street3CheckCallRaiseDone)
4113 ,sum(street4CheckCallRaiseChance)
4114 ,sum(street4CheckCallRaiseDone)
4125 ,sum(hp.street0Raises)
4126 ,sum(hp.street1Raises)
4127 ,sum(hp.street2Raises)
4128 ,sum(hp.street3Raises)
4129 ,sum(hp.street4Raises)
4130 FROM HandsPlayers hp
4131 INNER JOIN Hands h ON (h.id = hp.handId)
4132 <tourney_join_clause>
4134 GROUP BY h.gametypeId
4138 <tourney_group_clause>
4139 ,date_format(h.startTime, 'd%y%m%d')
4141 elif db_server
== 'postgresql':
4142 self
.query
['rebuildHudCache'] = """
4143 INSERT INTO HudCache
4148 <tourney_insert_clause>
4164 ,street0_FoldTo3BChance
4165 ,street0_FoldTo3BDone
4166 ,street0_FoldTo4BChance
4167 ,street0_FoldTo4BDone
4168 ,street0_SqueezeChance
4169 ,street0_SqueezeDone
4187 ,foldToOtherRaisedStreet0
4188 ,foldToOtherRaisedStreet1
4189 ,foldToOtherRaisedStreet2
4190 ,foldToOtherRaisedStreet3
4191 ,foldToOtherRaisedStreet4
4194 ,foldBbToStealChance
4196 ,foldSbToStealChance
4206 ,foldToStreet1CBChance
4207 ,foldToStreet1CBDone
4208 ,foldToStreet2CBChance
4209 ,foldToStreet2CBDone
4210 ,foldToStreet3CBChance
4211 ,foldToStreet3CBDone
4212 ,foldToStreet4CBChance
4213 ,foldToStreet4CBDone
4215 ,street1CheckCallRaiseChance
4216 ,street1CheckCallRaiseDone
4217 ,street2CheckCallRaiseChance
4218 ,street2CheckCallRaiseDone
4219 ,street3CheckCallRaiseChance
4220 ,street3CheckCallRaiseDone
4221 ,street4CheckCallRaiseChance
4222 ,street4CheckCallRaiseDone
4242 ,case when hp.position = 'B' then 'B'
4243 when hp.position = 'S' then 'S'
4244 when hp.position = '0' then 'D'
4245 when hp.position = '1' then 'C'
4246 when hp.position = '2' then 'M'
4247 when hp.position = '3' then 'M'
4248 when hp.position = '4' then 'M'
4249 when hp.position = '5' then 'E'
4250 when hp.position = '6' then 'E'
4251 when hp.position = '7' then 'E'
4252 when hp.position = '8' then 'E'
4253 when hp.position = '9' then 'E'
4256 <tourney_select_clause>
4257 ,'d' || to_char(h.startTime, 'YYMMDD')
4259 ,sum(wonWhenSeenStreet1)
4260 ,sum(wonWhenSeenStreet2)
4261 ,sum(wonWhenSeenStreet3)
4262 ,sum(wonWhenSeenStreet4)
4264 ,sum(CAST(street0VPI as integer))
4265 ,sum(CAST(street0Aggr as integer))
4266 ,sum(CAST(street0_3BChance as integer))
4267 ,sum(CAST(street0_3BDone as integer))
4268 ,sum(CAST(street0_4BChance as integer))
4269 ,sum(CAST(street0_4BDone as integer))
4270 ,sum(CAST(street0_C4BChance as integer))
4271 ,sum(CAST(street0_C4BDone as integer))
4272 ,sum(CAST(street0_FoldTo3BChance as integer))
4273 ,sum(CAST(street0_FoldTo3BDone as integer))
4274 ,sum(CAST(street0_FoldTo4BChance as integer))
4275 ,sum(CAST(street0_FoldTo4BDone as integer))
4276 ,sum(CAST(street0_SqueezeChance as integer))
4277 ,sum(CAST(street0_SqueezeDone as integer))
4278 ,sum(CAST(raiseToStealChance as integer))
4279 ,sum(CAST(raiseToStealDone as integer))
4280 ,sum(CAST(success_Steal as integer))
4281 ,sum(CAST(street1Seen as integer))
4282 ,sum(CAST(street2Seen as integer))
4283 ,sum(CAST(street3Seen as integer))
4284 ,sum(CAST(street4Seen as integer))
4285 ,sum(CAST(sawShowdown as integer))
4286 ,sum(CAST(street1Aggr as integer))
4287 ,sum(CAST(street2Aggr as integer))
4288 ,sum(CAST(street3Aggr as integer))
4289 ,sum(CAST(street4Aggr as integer))
4290 ,sum(CAST(otherRaisedStreet0 as integer))
4291 ,sum(CAST(otherRaisedStreet1 as integer))
4292 ,sum(CAST(otherRaisedStreet2 as integer))
4293 ,sum(CAST(otherRaisedStreet3 as integer))
4294 ,sum(CAST(otherRaisedStreet4 as integer))
4295 ,sum(CAST(foldToOtherRaisedStreet0 as integer))
4296 ,sum(CAST(foldToOtherRaisedStreet1 as integer))
4297 ,sum(CAST(foldToOtherRaisedStreet2 as integer))
4298 ,sum(CAST(foldToOtherRaisedStreet3 as integer))
4299 ,sum(CAST(foldToOtherRaisedStreet4 as integer))
4300 ,sum(CAST(raiseFirstInChance as integer))
4301 ,sum(CAST(raisedFirstIn as integer))
4302 ,sum(CAST(foldBbToStealChance as integer))
4303 ,sum(CAST(foldedBbToSteal as integer))
4304 ,sum(CAST(foldSbToStealChance as integer))
4305 ,sum(CAST(foldedSbToSteal as integer))
4306 ,sum(CAST(street1CBChance as integer))
4307 ,sum(CAST(street1CBDone as integer))
4308 ,sum(CAST(street2CBChance as integer))
4309 ,sum(CAST(street2CBDone as integer))
4310 ,sum(CAST(street3CBChance as integer))
4311 ,sum(CAST(street3CBDone as integer))
4312 ,sum(CAST(street4CBChance as integer))
4313 ,sum(CAST(street4CBDone as integer))
4314 ,sum(CAST(foldToStreet1CBChance as integer))
4315 ,sum(CAST(foldToStreet1CBDone as integer))
4316 ,sum(CAST(foldToStreet2CBChance as integer))
4317 ,sum(CAST(foldToStreet2CBDone as integer))
4318 ,sum(CAST(foldToStreet3CBChance as integer))
4319 ,sum(CAST(foldToStreet3CBDone as integer))
4320 ,sum(CAST(foldToStreet4CBChance as integer))
4321 ,sum(CAST(foldToStreet4CBDone as integer))
4322 ,sum(CAST(totalProfit as integer))
4323 ,sum(CAST(street1CheckCallRaiseChance as integer))
4324 ,sum(CAST(street1CheckCallRaiseDone as integer))
4325 ,sum(CAST(street2CheckCallRaiseChance as integer))
4326 ,sum(CAST(street2CheckCallRaiseDone as integer))
4327 ,sum(CAST(street3CheckCallRaiseChance as integer))
4328 ,sum(CAST(street3CheckCallRaiseDone as integer))
4329 ,sum(CAST(street4CheckCallRaiseChance as integer))
4330 ,sum(CAST(street4CheckCallRaiseDone as integer))
4331 ,sum(CAST(street0Calls as integer))
4332 ,sum(CAST(street1Calls as integer))
4333 ,sum(CAST(street2Calls as integer))
4334 ,sum(CAST(street3Calls as integer))
4335 ,sum(CAST(street4Calls as integer))
4336 ,sum(CAST(street0Bets as integer))
4337 ,sum(CAST(street1Bets as integer))
4338 ,sum(CAST(street2Bets as integer))
4339 ,sum(CAST(street3Bets as integer))
4340 ,sum(CAST(street4Bets as integer))
4341 ,sum(CAST(hp.street0Raises as integer))
4342 ,sum(CAST(hp.street1Raises as integer))
4343 ,sum(CAST(hp.street2Raises as integer))
4344 ,sum(CAST(hp.street3Raises as integer))
4345 ,sum(CAST(hp.street4Raises as integer))
4346 FROM HandsPlayers hp
4347 INNER JOIN Hands h ON (h.id = hp.handId)
4348 <tourney_join_clause>
4350 GROUP BY h.gametypeId
4354 <tourney_group_clause>
4355 ,to_char(h.startTime, 'YYMMDD')
4357 else: # assume sqlite
4358 self
.query
['rebuildHudCache'] = """
4359 INSERT INTO HudCache
4364 <tourney_insert_clause>
4380 ,street0_FoldTo3BChance
4381 ,street0_FoldTo3BDone
4382 ,street0_FoldTo4BChance
4383 ,street0_FoldTo4BDone
4384 ,street0_SqueezeChance
4385 ,street0_SqueezeDone
4403 ,foldToOtherRaisedStreet0
4404 ,foldToOtherRaisedStreet1
4405 ,foldToOtherRaisedStreet2
4406 ,foldToOtherRaisedStreet3
4407 ,foldToOtherRaisedStreet4
4410 ,foldBbToStealChance
4412 ,foldSbToStealChance
4422 ,foldToStreet1CBChance
4423 ,foldToStreet1CBDone
4424 ,foldToStreet2CBChance
4425 ,foldToStreet2CBDone
4426 ,foldToStreet3CBChance
4427 ,foldToStreet3CBDone
4428 ,foldToStreet4CBChance
4429 ,foldToStreet4CBDone
4431 ,street1CheckCallRaiseChance
4432 ,street1CheckCallRaiseDone
4433 ,street2CheckCallRaiseChance
4434 ,street2CheckCallRaiseDone
4435 ,street3CheckCallRaiseChance
4436 ,street3CheckCallRaiseDone
4437 ,street4CheckCallRaiseChance
4438 ,street4CheckCallRaiseDone
4458 ,case when hp.position = 'B' then 'B'
4459 when hp.position = 'S' then 'S'
4460 when hp.position = '0' then 'D'
4461 when hp.position = '1' then 'C'
4462 when hp.position = '2' then 'M'
4463 when hp.position = '3' then 'M'
4464 when hp.position = '4' then 'M'
4465 when hp.position = '5' then 'E'
4466 when hp.position = '6' then 'E'
4467 when hp.position = '7' then 'E'
4468 when hp.position = '8' then 'E'
4469 when hp.position = '9' then 'E'
4472 <tourney_select_clause>
4473 ,'d' || substr(strftime('%Y%m%d', h.startTime),3,7)
4475 ,sum(wonWhenSeenStreet1)
4476 ,sum(wonWhenSeenStreet2)
4477 ,sum(wonWhenSeenStreet3)
4478 ,sum(wonWhenSeenStreet4)
4480 ,sum(CAST(street0VPI as integer))
4481 ,sum(CAST(street0Aggr as integer))
4482 ,sum(CAST(street0_3BChance as integer))
4483 ,sum(CAST(street0_3BDone as integer))
4484 ,sum(CAST(street0_4BChance as integer))
4485 ,sum(CAST(street0_4BDone as integer))
4486 ,sum(CAST(street0_C4BChance as integer))
4487 ,sum(CAST(street0_C4BDone as integer))
4488 ,sum(CAST(street0_FoldTo3BChance as integer))
4489 ,sum(CAST(street0_FoldTo3BDone as integer))
4490 ,sum(CAST(street0_FoldTo4BChance as integer))
4491 ,sum(CAST(street0_FoldTo4BDone as integer))
4492 ,sum(CAST(street0_SqueezeChance as integer))
4493 ,sum(CAST(street0_SqueezeDone as integer))
4494 ,sum(CAST(raiseToStealChance as integer))
4495 ,sum(CAST(raiseToStealDone as integer))
4496 ,sum(CAST(success_Steal as integer))
4497 ,sum(CAST(street1Seen as integer))
4498 ,sum(CAST(street2Seen as integer))
4499 ,sum(CAST(street3Seen as integer))
4500 ,sum(CAST(street4Seen as integer))
4501 ,sum(CAST(sawShowdown as integer))
4502 ,sum(CAST(street1Aggr as integer))
4503 ,sum(CAST(street2Aggr as integer))
4504 ,sum(CAST(street3Aggr as integer))
4505 ,sum(CAST(street4Aggr as integer))
4506 ,sum(CAST(otherRaisedStreet0 as integer))
4507 ,sum(CAST(otherRaisedStreet1 as integer))
4508 ,sum(CAST(otherRaisedStreet2 as integer))
4509 ,sum(CAST(otherRaisedStreet3 as integer))
4510 ,sum(CAST(otherRaisedStreet4 as integer))
4511 ,sum(CAST(foldToOtherRaisedStreet0 as integer))
4512 ,sum(CAST(foldToOtherRaisedStreet1 as integer))
4513 ,sum(CAST(foldToOtherRaisedStreet2 as integer))
4514 ,sum(CAST(foldToOtherRaisedStreet3 as integer))
4515 ,sum(CAST(foldToOtherRaisedStreet4 as integer))
4516 ,sum(CAST(raiseFirstInChance as integer))
4517 ,sum(CAST(raisedFirstIn as integer))
4518 ,sum(CAST(foldBbToStealChance as integer))
4519 ,sum(CAST(foldedBbToSteal as integer))
4520 ,sum(CAST(foldSbToStealChance as integer))
4521 ,sum(CAST(foldedSbToSteal as integer))
4522 ,sum(CAST(street1CBChance as integer))
4523 ,sum(CAST(street1CBDone as integer))
4524 ,sum(CAST(street2CBChance as integer))
4525 ,sum(CAST(street2CBDone as integer))
4526 ,sum(CAST(street3CBChance as integer))
4527 ,sum(CAST(street3CBDone as integer))
4528 ,sum(CAST(street4CBChance as integer))
4529 ,sum(CAST(street4CBDone as integer))
4530 ,sum(CAST(foldToStreet1CBChance as integer))
4531 ,sum(CAST(foldToStreet1CBDone as integer))
4532 ,sum(CAST(foldToStreet2CBChance as integer))
4533 ,sum(CAST(foldToStreet2CBDone as integer))
4534 ,sum(CAST(foldToStreet3CBChance as integer))
4535 ,sum(CAST(foldToStreet3CBDone as integer))
4536 ,sum(CAST(foldToStreet4CBChance as integer))
4537 ,sum(CAST(foldToStreet4CBDone as integer))
4538 ,sum(CAST(totalProfit as integer))
4539 ,sum(CAST(street1CheckCallRaiseChance as integer))
4540 ,sum(CAST(street1CheckCallRaiseDone as integer))
4541 ,sum(CAST(street2CheckCallRaiseChance as integer))
4542 ,sum(CAST(street2CheckCallRaiseDone as integer))
4543 ,sum(CAST(street3CheckCallRaiseChance as integer))
4544 ,sum(CAST(street3CheckCallRaiseDone as integer))
4545 ,sum(CAST(street4CheckCallRaiseChance as integer))
4546 ,sum(CAST(street4CheckCallRaiseDone as integer))
4547 ,sum(CAST(street0Calls as integer))
4548 ,sum(CAST(street1Calls as integer))
4549 ,sum(CAST(street2Calls as integer))
4550 ,sum(CAST(street3Calls as integer))
4551 ,sum(CAST(street4Calls as integer))
4552 ,sum(CAST(street0Bets as integer))
4553 ,sum(CAST(street1Bets as integer))
4554 ,sum(CAST(street2Bets as integer))
4555 ,sum(CAST(street3Bets as integer))
4556 ,sum(CAST(street4Bets as integer))
4557 ,sum(CAST(hp.street0Raises as integer))
4558 ,sum(CAST(hp.street1Raises as integer))
4559 ,sum(CAST(hp.street2Raises as integer))
4560 ,sum(CAST(hp.street3Raises as integer))
4561 ,sum(CAST(hp.street4Raises as integer))
4562 FROM HandsPlayers hp
4563 INNER JOIN Hands h ON (h.id = hp.handId)
4564 <tourney_join_clause>
4566 GROUP BY h.gametypeId
4570 <tourney_group_clause>
4571 ,'d' || substr(strftime('%Y%m%d', h.startTime),3,7)
4574 self
.query
['insert_hudcache'] = """
4575 insert into HudCache (
4591 street0_FoldTo3BChance,
4592 street0_FoldTo3BDone,
4593 street0_FoldTo4BChance,
4594 street0_FoldTo4BDone,
4595 street0_SqueezeChance,
4596 street0_SqueezeDone,
4614 foldToOtherRaisedStreet0,
4615 foldToOtherRaisedStreet1,
4616 foldToOtherRaisedStreet2,
4617 foldToOtherRaisedStreet3,
4618 foldToOtherRaisedStreet4,
4626 foldBbToStealChance,
4628 foldSbToStealChance,
4638 foldToStreet1CBChance,
4639 foldToStreet1CBDone,
4640 foldToStreet2CBChance,
4641 foldToStreet2CBDone,
4642 foldToStreet3CBChance,
4643 foldToStreet3CBDone,
4644 foldToStreet4CBChance,
4645 foldToStreet4CBDone,
4647 street1CheckCallRaiseChance,
4648 street1CheckCallRaiseDone,
4649 street2CheckCallRaiseChance,
4650 street2CheckCallRaiseDone,
4651 street3CheckCallRaiseChance,
4652 street3CheckCallRaiseDone,
4653 street4CheckCallRaiseChance,
4654 street4CheckCallRaiseDone,
4670 values (%s, %s, %s, %s, %s,
4690 self
.query
['update_hudcache'] = """
4693 street0VPI=street0VPI+%s,
4694 street0Aggr=street0Aggr+%s,
4695 street0_3BChance=street0_3BChance+%s,
4696 street0_3BDone=street0_3BDone+%s,
4697 street0_4BChance=street0_4BChance+%s,
4698 street0_4BDone=street0_4BDone+%s,
4699 street0_C4BChance=street0_C4BChance+%s,
4700 street0_C4BDone=street0_C4BDone+%s,
4701 street0_FoldTo3BChance=street0_FoldTo3BChance+%s,
4702 street0_FoldTo3BDone=street0_FoldTo3BDone+%s,
4703 street0_FoldTo4BChance=street0_FoldTo4BChance+%s,
4704 street0_FoldTo4BDone=street0_FoldTo4BDone+%s,
4705 street0_SqueezeChance=street0_SqueezeChance+%s,
4706 street0_SqueezeDone=street0_SqueezeDone+%s,
4707 raiseToStealChance=raiseToStealChance+%s,
4708 raiseToStealDone=raiseToStealDone+%s,
4709 success_Steal=success_Steal+%s,
4710 street1Seen=street1Seen+%s,
4711 street2Seen=street2Seen+%s,
4712 street3Seen=street3Seen+%s,
4713 street4Seen=street4Seen+%s,
4714 sawShowdown=sawShowdown+%s,
4715 street1Aggr=street1Aggr+%s,
4716 street2Aggr=street2Aggr+%s,
4717 street3Aggr=street3Aggr+%s,
4718 street4Aggr=street4Aggr+%s,
4719 otherRaisedStreet0=otherRaisedStreet0+%s,
4720 otherRaisedStreet1=otherRaisedStreet1+%s,
4721 otherRaisedStreet2=otherRaisedStreet2+%s,
4722 otherRaisedStreet3=otherRaisedStreet3+%s,
4723 otherRaisedStreet4=otherRaisedStreet4+%s,
4724 foldToOtherRaisedStreet0=foldToOtherRaisedStreet0+%s,
4725 foldToOtherRaisedStreet1=foldToOtherRaisedStreet1+%s,
4726 foldToOtherRaisedStreet2=foldToOtherRaisedStreet2+%s,
4727 foldToOtherRaisedStreet3=foldToOtherRaisedStreet3+%s,
4728 foldToOtherRaisedStreet4=foldToOtherRaisedStreet4+%s,
4729 wonWhenSeenStreet1=wonWhenSeenStreet1+%s,
4730 wonWhenSeenStreet2=wonWhenSeenStreet2+%s,
4731 wonWhenSeenStreet3=wonWhenSeenStreet3+%s,
4732 wonWhenSeenStreet4=wonWhenSeenStreet4+%s,
4734 raiseFirstInChance=raiseFirstInChance+%s,
4735 raisedFirstIn=raisedFirstIn+%s,
4736 foldBbToStealChance=foldBbToStealChance+%s,
4737 foldedBbToSteal=foldedBbToSteal+%s,
4738 foldSbToStealChance=foldSbToStealChance+%s,
4739 foldedSbToSteal=foldedSbToSteal+%s,
4740 street1CBChance=street1CBChance+%s,
4741 street1CBDone=street1CBDone+%s,
4742 street2CBChance=street2CBChance+%s,
4743 street2CBDone=street2CBDone+%s,
4744 street3CBChance=street3CBChance+%s,
4745 street3CBDone=street3CBDone+%s,
4746 street4CBChance=street4CBChance+%s,
4747 street4CBDone=street4CBDone+%s,
4748 foldToStreet1CBChance=foldToStreet1CBChance+%s,
4749 foldToStreet1CBDone=foldToStreet1CBDone+%s,
4750 foldToStreet2CBChance=foldToStreet2CBChance+%s,
4751 foldToStreet2CBDone=foldToStreet2CBDone+%s,
4752 foldToStreet3CBChance=foldToStreet3CBChance+%s,
4753 foldToStreet3CBDone=foldToStreet3CBDone+%s,
4754 foldToStreet4CBChance=foldToStreet4CBChance+%s,
4755 foldToStreet4CBDone=foldToStreet4CBDone+%s,
4756 totalProfit=totalProfit+%s,
4757 street1CheckCallRaiseChance=street1CheckCallRaiseChance+%s,
4758 street1CheckCallRaiseDone=street1CheckCallRaiseDone+%s,
4759 street2CheckCallRaiseChance=street2CheckCallRaiseChance+%s,
4760 street2CheckCallRaiseDone=street2CheckCallRaiseDone+%s,
4761 street3CheckCallRaiseChance=street3CheckCallRaiseChance+%s,
4762 street3CheckCallRaiseDone=street3CheckCallRaiseDone+%s,
4763 street4CheckCallRaiseChance=street4CheckCallRaiseChance+%s,
4764 street4CheckCallRaiseDone=street4CheckCallRaiseDone+%s,
4765 street0Calls=street0Calls+%s,
4766 street1Calls=street1Calls+%s,
4767 street2Calls=street2Calls+%s,
4768 street3Calls=street3Calls+%s,
4769 street4Calls=street4Calls+%s,
4770 street0Bets=street0Bets+%s,
4771 street1Bets=street1Bets+%s,
4772 street2Bets=street2Bets+%s,
4773 street3Bets=street3Bets+%s,
4774 street4Bets=street4Bets+%s,
4775 street0Raises=street0Raises+%s,
4776 street1Raises=street1Raises+%s,
4777 street2Raises=street2Raises+%s,
4778 street3Raises=street3Raises+%s,
4779 street4Raises=street4Raises+%s
4780 WHERE gametypeId+0=%s
4784 AND (case when tourneyTypeId is NULL then 1 else
4785 (case when tourneyTypeId+0=%s then 1 else 0 end) end)=1
4788 self
.query
['get_hero_hudcache_start'] = """select min(hc.styleKey)
4790 where hc.playerId in <playerid_list>
4791 and hc.styleKey like 'd%'"""
4793 ####################################
4794 # Queries to rebuild/modify sessionscache
4795 ####################################
4797 self
.query
['clearSessionsCache'] = """DELETE FROM SessionsCache"""
4799 self
.query
['rebuildSessionsCache'] = """
4800 SELECT Hands.id as id,
4801 Hands.startTime as startTime,
4802 HandsPlayers.playerId as playerId,
4803 Hands.gametypeId as gametypeId,
4804 Gametypes.type as game,
4805 HandsPlayers.totalProfit as totalProfit,
4806 Tourneys.tourneyTypeId as tourneyTypeId,
4807 HandsPlayers.street0VPI as street0VPI,
4808 HandsPlayers.street1Seen as street1Seen
4809 FROM Gametypes, HandsPlayers, Hands
4810 LEFT JOIN Tourneys ON Hands.tourneyId = Tourneys.tourneyTypeId
4811 WHERE HandsPlayers.handId = Hands.id
4812 AND Hands.gametypeId = Gametypes.id
4813 AND (case when HandsPlayers.playerId = <where_clause> then 1 else 0 end) = 1
4814 ORDER BY Hands.startTime ASC"""
4816 self
.query
['rebuildSessionsCacheSum'] = """
4817 SELECT Tourneys.id as id,
4818 Tourneys.startTime as startTime,
4819 TourneysPlayers.playerId,
4820 TourneyTypes.id as tourneyTypeId,
4821 TourneysPlayers.winnings as winnings,
4822 TourneysPlayers.winningsCurrency as winningsCurrency,
4823 TourneyTypes.currency as buyinCurrency,
4824 TourneyTypes.buyIn as buyIn,
4825 TourneyTypes.fee as fee,
4826 case when TourneyTypes.rebuy then TourneyTypes.rebuyCost else 0 end as rebuyCost,
4827 case when TourneyTypes.rebuy then TourneyTypes.rebuyFee else 0 end as rebuyFee,
4828 case when TourneyTypes.addOn then TourneyTypes.addOnCost else 0 end as addOnCost,
4829 case when TourneyTypes.addOn then TourneyTypes.addOnFee else 0 end as addOnFee,
4830 case when TourneyTypes.knockout then TourneyTypes.koBounty else 0 end as koBounty
4831 FROM Tourneys, TourneyTypes, TourneysPlayers
4832 WHERE Tourneys.tourneyTypeId = TourneyTypes.id
4833 AND Tourneys.id = TourneysPlayers.tourneyId
4834 AND (case when TourneysPlayers.playerId = <where_clause> then 1 else 0 end) = 1
4835 ORDER BY Tourneys.startTime ASC"""
4837 self
.query
['select_prepSC'] = """
4838 SELECT sessionId as id,
4841 count(sessionId) as count
4843 WHERE sessionEnd>=%s
4844 AND sessionStart<=%s
4845 GROUP BY sessionId, sessionStart, sessionEnd"""
4847 self
.query
['update_prepSC'] = """
4848 UPDATE SessionsCache SET
4851 WHERE sessionId=%s"""
4853 self
.query
['update_SC'] = """
4854 UPDATE SessionsCache SET
4860 tourneys=tourneys+%s,
4861 totalProfit=totalProfit+%s
4864 self
.query
['select_SC'] = """
4885 AND (case when gametypeId is NULL then 1 else
4886 (case when gametypeId=%s then 1 else 0 end) end)=1
4887 AND (case when tourneyTypeId is NULL then 1 else
4888 (case when tourneyTypeId=%s then 1 else 0 end) end)=1
4892 self
.query
['insert_SC'] = """
4893 insert into SessionsCache (
4908 values (%s, %s, %s, %s, %s, %s, %s,
4909 %s, %s, %s, %s, %s, %s, %s)"""
4911 self
.query
['update_Hands_gsid'] = """
4914 WHERE gameSessionId=%s"""
4916 self
.query
['update_Hands_sid'] = """
4919 WHERE sessionId=%s"""
4921 self
.query
['update_SC_sid'] = """
4922 UPDATE SessionsCache SET
4926 WHERE sessionId=%s"""
4928 self
.query
['delete_SC'] = """
4929 DELETE FROM SessionsCache
4932 ####################################
4933 # Database management queries
4934 ####################################
4936 if db_server
== 'mysql':
4937 self
.query
['analyze'] = """
4938 analyze table Autorates, GameTypes, Hands, HandsPlayers, HudCache, Players
4939 , Settings, Sites, Tourneys, TourneysPlayers, TourneyTypes
4941 elif db_server
== 'postgresql':
4942 self
.query
['analyze'] = "analyze"
4943 elif db_server
== 'sqlite':
4944 self
.query
['analyze'] = "analyze"
4946 if db_server
== 'mysql':
4947 self
.query
['selectLock'] = """
4951 LOCK IN SHARE MODE"""
4953 if db_server
== 'mysql':
4954 self
.query
['switchLock'] = """
4955 UPDATE InsertLock SET
4959 if db_server
== 'mysql':
4960 self
.query
['missedLock'] = """
4961 UPDATE InsertLock SET
4965 if db_server
== 'mysql':
4966 self
.query
['lockForInsert'] = """
4967 lock tables Hands write, HandsPlayers write, HandsActions write, Players write
4968 , HudCache write, GameTypes write, Sites write, Tourneys write
4969 , TourneysPlayers write, TourneyTypes write, Autorates write
4971 elif db_server
== 'postgresql':
4972 self
.query
['lockForInsert'] = ""
4973 elif db_server
== 'sqlite':
4974 self
.query
['lockForInsert'] = ""
4976 if db_server
== 'mysql':
4977 self
.query
['vacuum'] = """optimize table Hands, HandsPlayers, HandsActions, Players
4978 , HudCache, GameTypes, Sites, Tourneys
4979 , TourneysPlayers, TourneyTypes, Autorates
4981 elif db_server
== 'postgresql':
4982 self
.query
['vacuum'] = """ vacuum """
4983 elif db_server
== 'sqlite':
4984 self
.query
['vacuum'] = """ vacuum """
4986 self
.query
['getGametypeFL'] = """SELECT id
4996 """ #TODO: seems odd to have limitType variable in this query
4998 self
.query
['getGametypeNL'] = """SELECT id
5010 """ #TODO: seems odd to have limitType variable in this query
5012 self
.query
['insertGameTypes'] = """INSERT INTO Gametypes
5013 (siteId, currency, type, base, category, limitType
5014 ,hiLo, mix, smallBlind, bigBlind, smallBet, bigBet, maxSeats, ante)
5015 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
5017 self
.query
['isAlreadyInDB'] = """SELECT id FROM Hands
5018 WHERE gametypeId=%s AND siteHandNo=%s
5021 self
.query
['getTourneyTypeIdByTourneyNo'] = """SELECT tt.id,
5031 FROM TourneyTypes tt
5032 INNER JOIN Tourneys t ON (t.tourneyTypeId = tt.id)
5033 WHERE t.siteTourneyNo=%s AND tt.siteId=%s
5036 self
.query
['getTourneyTypeId'] = """SELECT id
5053 self
.query
['insertTourneyType'] = """INSERT INTO TourneyTypes
5054 (siteId, currency, buyin, fee, category, limitType, maxSeats, buyInChips, knockout, koBounty, rebuy,
5055 addOn ,speed, shootout, matrix, added, addedCurrency)
5056 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
5059 self
.query
['getTourneyByTourneyNo'] = """SELECT t.*
5061 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5062 WHERE tt.siteId=%s AND t.siteTourneyNo=%s
5065 self
.query
['getTourneyInfo'] = """SELECT tt.*, t.*
5067 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5068 INNER JOIN Sites s ON (tt.siteId = s.id)
5069 WHERE s.name=%s AND t.siteTourneyNo=%s
5072 self
.query
['getSiteTourneyNos'] = """SELECT t.siteTourneyNo
5074 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5075 INNER JOIN Sites s ON (tt.siteId = s.id)
5079 self
.query
['getTourneyPlayerInfo'] = """SELECT tp.*
5081 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5082 INNER JOIN Sites s ON (tt.siteId = s.id)
5083 INNER JOIN TourneysPlayers tp ON (tp.tourneyId = t.id)
5084 INNER JOIN Players p ON (p.id = tp.playerId)
5085 WHERE s.name=%s AND t.siteTourneyNo=%s AND p.name=%s
5088 self
.query
['insertTourney'] = """INSERT INTO Tourneys
5089 (tourneyTypeId, siteTourneyNo, entries, prizepool,
5090 startTime, endTime, tourneyName, matrixIdProcessed,
5091 totalRebuyCount, totalAddOnCount)
5092 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
5095 self
.query
['updateTourney'] = """UPDATE Tourneys
5101 matrixIdProcessed = %s,
5102 totalRebuyCount = %s,
5103 totalAddOnCount = %s,
5109 self
.query
['getTourneysPlayersByIds'] = """SELECT *
5110 FROM TourneysPlayers
5111 WHERE tourneyId=%s AND playerId+0=%s
5114 self
.query
['updateTourneysPlayer'] = """UPDATE TourneysPlayers
5117 winningsCurrency = %s,
5124 self
.query
['insertTourneysPlayer'] = """insert into TourneysPlayers
5125 (tourneyId, playerId, rank, winnings, winningsCurrency, rebuyCount, addOnCount, koCount)
5126 values (%s, %s, %s, %s, %s, %s, %s, %s)
5129 self
.query
['selectHandsPlayersWithWrongTTypeId'] = """SELECT id
5131 WHERE tourneyTypeId <> %s AND (TourneysPlayersId+0=%s)
5134 # self.query['updateHandsPlayersForTTypeId2'] = """UPDATE HandsPlayers
5135 # SET tourneyTypeId= %s
5136 # WHERE (TourneysPlayersId+0=%s)
5139 self
.query
['updateHandsPlayersForTTypeId'] = """UPDATE HandsPlayers
5140 SET tourneyTypeId= %s
5145 self
.query
['handsPlayersTTypeId_joiner'] = " OR TourneysPlayersId+0="
5146 self
.query
['handsPlayersTTypeId_joiner_id'] = " OR id="
5148 self
.query
['store_hand'] = """insert into Hands (
5184 (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
5185 %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
5186 %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
5189 self
.query
['store_hands_players'] = """insert into HandsPlayers (
5262 street0_FoldTo3BChance,
5263 street0_FoldTo3BDone,
5264 street0_FoldTo4BChance,
5265 street0_FoldTo4BDone,
5266 street0_SqueezeChance,
5267 street0_SqueezeDone,
5276 foldToOtherRaisedStreet0,
5277 foldToOtherRaisedStreet1,
5278 foldToOtherRaisedStreet2,
5279 foldToOtherRaisedStreet3,
5280 foldToOtherRaisedStreet4,
5283 foldBbToStealChance,
5285 foldSbToStealChance,
5287 foldToStreet1CBChance,
5288 foldToStreet1CBDone,
5289 foldToStreet2CBChance,
5290 foldToStreet2CBDone,
5291 foldToStreet3CBChance,
5292 foldToStreet3CBDone,
5293 foldToStreet4CBChance,
5294 foldToStreet4CBDone,
5295 street1CheckCallRaiseChance,
5296 street1CheckCallRaiseDone,
5297 street2CheckCallRaiseChance,
5298 street2CheckCallRaiseDone,
5299 street3CheckCallRaiseChance,
5300 street3CheckCallRaiseDone,
5301 street4CheckCallRaiseChance,
5302 street4CheckCallRaiseDone,
5336 self
.query
['store_hands_actions'] = """insert into HandsActions (
5356 self
.query
['store_boards'] = """insert into Boards (
5370 ################################
5371 # queries for Files Table
5372 ################################
5374 self
.query
['store_file'] = """ insert into Files (
5392 self
.query
['update_file'] = """
5402 ttime100=ttime100+%s,
5406 ################################
5407 # Counts for DB stats window
5408 ################################
5409 self
.query
['getHandCount'] = "SELECT COUNT(*) FROM Hands"
5410 self
.query
['getTourneyCount'] = "SELECT COUNT(*) FROM Tourneys"
5411 self
.query
['getTourneyTypeCount'] = "SELECT COUNT(*) FROM TourneyTypes"
5413 ################################
5414 # queries for dumpDatabase
5415 ################################
5416 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'):
5417 self
.query
['get'+table
] = u
"SELECT * FROM "+table
5419 ################################
5420 # placeholders and substitution stuff
5421 ################################
5422 if db_server
== 'mysql':
5423 self
.query
['placeholder'] = u
'%s'
5424 elif db_server
== 'postgresql':
5425 self
.query
['placeholder'] = u
'%s'
5426 elif db_server
== 'sqlite':
5427 self
.query
['placeholder'] = u
'?'
5430 # If using sqlite, use the ? placeholder instead of %s
5431 if db_server
== 'sqlite':
5432 for k
,q
in self
.query
.iteritems():
5433 self
.query
[k
] = re
.sub('%s','?',q
)
5435 if __name__
== "__main__":
5436 # just print the default queries and exit
5439 print "For query " + key
+ ", sql ="