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
['getLimits'] = """SELECT DISTINCT bigBlind from Gametypes ORDER by bigBlind DESC"""
95 self
.query
['getTourneyTypesIds'] = "SELECT id FROM TourneyTypes"
97 ################################
99 ################################
100 if db_server
== 'mysql':
101 self
.query
['createSettingsTable'] = """CREATE TABLE Settings (
102 version SMALLINT NOT NULL)
104 elif db_server
== 'postgresql':
105 self
.query
['createSettingsTable'] = """CREATE TABLE Settings (version SMALLINT NOT NULL)"""
107 elif db_server
== 'sqlite':
108 self
.query
['createSettingsTable'] = """CREATE TABLE Settings
109 (version INTEGER NOT NULL) """
111 ################################
113 ################################
114 if db_server
== 'mysql':
115 self
.query
['createLockTable'] = """CREATE TABLE InsertLock (
116 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
117 locked BOOLEAN NOT NULL DEFAULT FALSE)
120 ################################
121 # Create RawHands (this table is all but identical with RawTourneys)
122 ################################
123 if db_server
== 'mysql':
124 self
.query
['createRawHands'] = """CREATE TABLE RawHands (
125 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
126 handId BIGINT NOT NULL,
127 rawHand TEXT NOT NULL,
128 complain BOOLEAN NOT NULL DEFAULT FALSE)
130 elif db_server
== 'postgresql':
131 self
.query
['createRawHands'] = """CREATE TABLE RawHands (
132 id BIGSERIAL, PRIMARY KEY (id),
133 handId BIGINT NOT NULL,
134 rawHand TEXT NOT NULL,
135 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
136 elif db_server
== 'sqlite':
137 self
.query
['createRawHands'] = """CREATE TABLE RawHands (
138 id INTEGER PRIMARY KEY,
139 handId BIGINT NOT NULL,
140 rawHand TEXT NOT NULL,
141 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
143 ################################
144 # Create RawTourneys (this table is all but identical with RawHands)
145 ################################
146 if db_server
== 'mysql':
147 self
.query
['createRawTourneys'] = """CREATE TABLE RawTourneys (
148 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
149 tourneyId BIGINT NOT NULL,
150 rawTourney TEXT NOT NULL,
151 complain BOOLEAN NOT NULL DEFAULT FALSE)
153 elif db_server
== 'postgresql':
154 self
.query
['createRawTourneys'] = """CREATE TABLE RawTourneys (
155 id BIGSERIAL, PRIMARY KEY (id),
156 tourneyId BIGINT NOT NULL,
157 rawTourney TEXT NOT NULL,
158 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
159 elif db_server
== 'sqlite':
160 self
.query
['createRawTourneys'] = """CREATE TABLE RawTourneys (
161 id INTEGER PRIMARY KEY,
162 tourneyId BIGINT NOT NULL,
163 rawTourney TEXT NOT NULL,
164 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
166 ################################
168 ################################
170 if db_server
== 'mysql':
171 self
.query
['createActionsTable'] = """CREATE TABLE Actions (
172 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
173 name varchar(32) NOT NULL,
174 code char(4) NOT NULL)
176 elif db_server
== 'postgresql':
177 self
.query
['createActionsTable'] = """CREATE TABLE Actions (
178 id SERIAL, PRIMARY KEY (id),
181 elif db_server
== 'sqlite':
182 self
.query
['createActionsTable'] = """CREATE TABLE Actions (
183 id INTEGER PRIMARY KEY,
185 code TEXT NOT NULL)"""
187 ################################
189 ################################
191 if db_server
== 'mysql':
192 self
.query
['createSitesTable'] = """CREATE TABLE Sites (
193 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
194 name varchar(32) NOT NULL,
195 code char(2) NOT NULL)
197 elif db_server
== 'postgresql':
198 self
.query
['createSitesTable'] = """CREATE TABLE Sites (
199 id SERIAL, PRIMARY KEY (id),
202 elif db_server
== 'sqlite':
203 self
.query
['createSitesTable'] = """CREATE TABLE Sites (
204 id INTEGER PRIMARY KEY,
206 code TEXT NOT NULL)"""
208 ################################
210 ################################
212 if db_server
== 'mysql':
213 self
.query
['createBackingsTable'] = """CREATE TABLE Backings (
214 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
215 tourneysPlayersId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
216 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
217 buyInPercentage FLOAT UNSIGNED NOT NULL,
218 payOffPercentage FLOAT UNSIGNED NOT NULL) ENGINE=INNODB"""
219 elif db_server
== 'postgresql':
220 self
.query
['createBackingsTable'] = """CREATE TABLE Backings (
221 id BIGSERIAL, PRIMARY KEY (id),
222 tourneysPlayersId INT NOT NULL, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
223 playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
224 buyInPercentage FLOAT NOT NULL,
225 payOffPercentage FLOAT NOT NULL)"""
226 elif db_server
== 'sqlite':
227 self
.query
['createBackingsTable'] = """CREATE TABLE Backings (
228 id INTEGER PRIMARY KEY,
229 tourneysPlayersId INT NOT NULL,
230 playerId INT NOT NULL,
231 buyInPercentage REAL UNSIGNED NOT NULL,
232 payOffPercentage REAL UNSIGNED NOT NULL)"""
234 ################################
236 ################################
238 if db_server
== 'mysql':
239 self
.query
['createGametypesTable'] = """CREATE TABLE Gametypes (
240 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
241 siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
242 currency varchar(4) NOT NULL,
243 type char(4) NOT NULL,
244 base char(4) NOT NULL,
245 category varchar(9) NOT NULL,
246 limitType char(2) NOT NULL,
247 hiLo char(1) NOT NULL,
248 mix varchar(9) NOT NULL,
251 smallBet int NOT NULL,
253 maxSeats TINYINT NOT NULL,
256 elif db_server
== 'postgresql':
257 self
.query
['createGametypesTable'] = """CREATE TABLE Gametypes (
258 id SERIAL NOT NULL, PRIMARY KEY (id),
259 siteId INTEGER NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
260 currency varchar(4) NOT NULL,
261 type char(4) NOT NULL,
262 base char(4) NOT NULL,
263 category varchar(9) NOT NULL,
264 limitType char(2) NOT NULL,
265 hiLo char(1) NOT NULL,
266 mix char(9) NOT NULL,
269 smallBet int NOT NULL,
271 maxSeats SMALLINT NOT NULL,
272 ante INT NOT NULL)"""
273 elif db_server
== 'sqlite':
274 self
.query
['createGametypesTable'] = """CREATE TABLE Gametypes (
275 id INTEGER PRIMARY KEY NOT NULL,
276 siteId INTEGER NOT NULL,
277 currency TEXT NOT NULL,
280 category TEXT NOT NULL,
281 limitType TEXT NOT NULL,
286 smallBet INTEGER NOT NULL,
287 bigBet INTEGER NOT NULL,
288 maxSeats INT NOT NULL,
290 FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
293 ################################
295 ################################
297 if db_server
== 'mysql':
298 self
.query
['createPlayersTable'] = """CREATE TABLE Players (
299 id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
300 name VARCHAR(32) NOT NULL,
301 siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
305 elif db_server
== 'postgresql':
306 self
.query
['createPlayersTable'] = """CREATE TABLE Players (
307 id SERIAL, PRIMARY KEY (id),
309 siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id),
311 commentTs timestamp without time zone)"""
312 elif db_server
== 'sqlite':
313 self
.query
['createPlayersTable'] = """CREATE TABLE Players (
314 id INTEGER PRIMARY KEY,
319 FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
322 ################################
324 ################################
326 if db_server
== 'mysql':
327 self
.query
['createAutoratesTable'] = """CREATE TABLE Autorates (
328 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
329 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
330 gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
331 description varchar(50) NOT NULL,
332 shortDesc char(8) NOT NULL,
333 ratingTime DATETIME NOT NULL,
334 handCount int NOT NULL)
336 elif db_server
== 'postgresql':
337 self
.query
['createAutoratesTable'] = """CREATE TABLE Autorates (
338 id BIGSERIAL, PRIMARY KEY (id),
339 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
340 gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
341 description varchar(50),
343 ratingTime timestamp without time zone,
345 elif db_server
== 'sqlite':
346 self
.query
['createAutoratesTable'] = """CREATE TABLE Autorates (
347 id INTEGER PRIMARY KEY,
356 ################################
358 ################################
360 if db_server
== 'mysql':
361 self
.query
['createHandsTable'] = """CREATE TABLE Hands (
362 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
363 tableName VARCHAR(50) NOT NULL,
364 siteHandNo BIGINT NOT NULL,
365 tourneyId INT UNSIGNED,
366 gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
367 sessionId INT UNSIGNED,
368 gameSessionId INT UNSIGNED,
369 fileId INT(10) UNSIGNED NOT NULL, FOREIGN KEY (fileId) REFERENCES Files(id),
370 startTime DATETIME NOT NULL,
371 importTime DATETIME NOT NULL,
372 seats TINYINT NOT NULL,
374 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
381 playersVpi SMALLINT NOT NULL, /* num of players vpi */
382 playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */
383 playersAtStreet2 SMALLINT NOT NULL,
384 playersAtStreet3 SMALLINT NOT NULL,
385 playersAtStreet4 SMALLINT NOT NULL,
386 playersAtShowdown SMALLINT NOT NULL,
387 street0Raises TINYINT NOT NULL, /* num small bets paid to see flop/street4, including blind */
388 street1Raises TINYINT NOT NULL, /* num small bets paid to see turn/street5 */
389 street2Raises TINYINT NOT NULL, /* num big bets paid to see river/street6 */
390 street3Raises TINYINT NOT NULL, /* num big bets paid to see sd/street7 */
391 street4Raises TINYINT NOT NULL, /* num big bets paid to see showdown */
392 street1Pot INT, /* pot size at flop/street4 */
393 street2Pot INT, /* pot size at turn/street5 */
394 street3Pot INT, /* pot size at river/street6 */
395 street4Pot INT, /* pot size at sd/street7 */
396 showdownPot INT, /* pot size at sd/street7 */
400 elif db_server
== 'postgresql':
401 self
.query
['createHandsTable'] = """CREATE TABLE Hands (
402 id BIGSERIAL, PRIMARY KEY (id),
403 tableName VARCHAR(50) NOT NULL,
404 siteHandNo BIGINT NOT NULL,
406 gametypeId INT NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
409 fileId BIGINT NOT NULL, FOREIGN KEY (fileId) REFERENCES Files(id),
410 startTime timestamp without time zone NOT NULL,
411 importTime timestamp without time zone NOT NULL,
412 seats SMALLINT NOT NULL,
414 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
421 playersVpi SMALLINT NOT NULL, /* num of players vpi */
422 playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */
423 playersAtStreet2 SMALLINT NOT NULL,
424 playersAtStreet3 SMALLINT NOT NULL,
425 playersAtStreet4 SMALLINT NOT NULL,
426 playersAtShowdown SMALLINT NOT NULL,
427 street0Raises SMALLINT NOT NULL, /* num small bets paid to see flop/street4, including blind */
428 street1Raises SMALLINT NOT NULL, /* num small bets paid to see turn/street5 */
429 street2Raises SMALLINT NOT NULL, /* num big bets paid to see river/street6 */
430 street3Raises SMALLINT NOT NULL, /* num big bets paid to see sd/street7 */
431 street4Raises SMALLINT NOT NULL, /* num big bets paid to see showdown */
432 street1Pot INT, /* pot size at flop/street4 */
433 street2Pot INT, /* pot size at turn/street5 */
434 street3Pot INT, /* pot size at river/street6 */
435 street4Pot INT, /* pot size at sd/street7 */
436 showdownPot INT, /* pot size at sd/street7 */
438 commentTs timestamp without time zone)"""
439 elif db_server
== 'sqlite':
440 self
.query
['createHandsTable'] = """CREATE TABLE Hands (
441 id INTEGER PRIMARY KEY,
442 tableName TEXT(50) NOT NULL,
443 siteHandNo INT NOT NULL,
445 gametypeId INT NOT NULL,
449 startTime REAL NOT NULL,
450 importTime REAL NOT NULL,
453 boardcard1 INT, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
460 playersVpi INT NOT NULL, /* num of players vpi */
461 playersAtStreet1 INT NOT NULL, /* num of players seeing flop/street4 */
462 playersAtStreet2 INT NOT NULL,
463 playersAtStreet3 INT NOT NULL,
464 playersAtStreet4 INT NOT NULL,
465 playersAtShowdown INT NOT NULL,
466 street0Raises INT NOT NULL, /* num small bets paid to see flop/street4, including blind */
467 street1Raises INT NOT NULL, /* num small bets paid to see turn/street5 */
468 street2Raises INT NOT NULL, /* num big bets paid to see river/street6 */
469 street3Raises INT NOT NULL, /* num big bets paid to see sd/street7 */
470 street4Raises INT NOT NULL, /* num big bets paid to see showdown */
471 street1Pot INT, /* pot size at flop/street4 */
472 street2Pot INT, /* pot size at turn/street5 */
473 street3Pot INT, /* pot size at river/street6 */
474 street4Pot INT, /* pot size at sd/street7 */
475 showdownPot INT, /* pot size at sd/street7 */
479 ################################
481 ################################
483 if db_server
== 'mysql':
484 self
.query
['createBoardsTable'] = """CREATE TABLE Boards (
485 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
486 handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
488 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
494 elif db_server
== 'postgresql':
495 self
.query
['createBoardsTable'] = """CREATE TABLE Boards (
496 id BIGSERIAL, PRIMARY KEY (id),
497 handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
499 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
503 boardcard5 smallint)"""
504 elif db_server
== 'sqlite':
505 self
.query
['createBoardsTable'] = """CREATE TABLE Boards (
506 id INTEGER PRIMARY KEY,
509 boardcard1 INT, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
516 ################################
517 # Create TourneyTypes
518 ################################
520 if db_server
== 'mysql':
521 self
.query
['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
522 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
523 siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
527 category varchar(9) NOT NULL,
528 limitType char(2) NOT NULL,
546 doubleOrNothing BOOLEAN,
549 addedCurrency VARCHAR(4))
551 elif db_server
== 'postgresql':
552 self
.query
['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
553 id SERIAL, PRIMARY KEY (id),
554 siteId INT NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
577 doubleOrNothing BOOLEAN,
580 addedCurrency VARCHAR(4))"""
581 elif db_server
== 'sqlite':
582 self
.query
['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
583 id INTEGER PRIMARY KEY,
607 doubleOrNothing BOOLEAN,
610 addedCurrency VARCHAR(4))"""
612 ################################
614 ################################
616 if db_server
== 'mysql':
617 self
.query
['createTourneysTable'] = """CREATE TABLE Tourneys (
618 id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
619 tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
620 siteTourneyNo BIGINT NOT NULL,
623 startTime DATETIME NOT NULL,
625 tourneyName varchar(40),
626 matrixIdProcessed TINYINT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
632 elif db_server
== 'postgresql':
633 self
.query
['createTourneysTable'] = """CREATE TABLE Tourneys (
634 id SERIAL, PRIMARY KEY (id),
635 tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
636 siteTourneyNo BIGINT,
639 startTime timestamp without time zone,
640 endTime timestamp without time zone,
641 tourneyName varchar(40),
642 matrixIdProcessed SMALLINT DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
646 commentTs timestamp without time zone)"""
647 elif db_server
== 'sqlite':
648 self
.query
['createTourneysTable'] = """CREATE TABLE Tourneys (
649 id INTEGER PRIMARY KEY,
657 matrixIdProcessed INT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
662 ################################
663 # Create HandsPlayers
664 ################################
666 if db_server
== 'mysql':
667 self
.query
['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
668 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
669 handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
670 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
671 startCash INT NOT NULL,
673 seatNo SMALLINT NOT NULL,
674 sitout BOOLEAN NOT NULL,
675 wentAllInOnStreet SMALLINT,
677 card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
678 card2 smallint NOT NULL,
684 card8 smallint, /* cards 8-20 for draw hands */
700 winnings int NOT NULL,
705 tourneysPlayersId BIGINT UNSIGNED, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
707 wonWhenSeenStreet1 FLOAT,
708 wonWhenSeenStreet2 FLOAT,
709 wonWhenSeenStreet3 FLOAT,
710 wonWhenSeenStreet4 FLOAT,
715 street0_3BChance BOOLEAN,
716 street0_3BDone BOOLEAN,
717 street0_4BChance BOOLEAN,
718 street0_C4BChance BOOLEAN,
719 street0_4BDone BOOLEAN,
720 street0_C4BDone BOOLEAN,
721 street0_FoldTo3BChance BOOLEAN,
722 street0_FoldTo3BDone BOOLEAN,
723 street0_FoldTo4BChance BOOLEAN,
724 street0_FoldTo4BDone BOOLEAN,
725 street0_SqueezeChance BOOLEAN,
726 street0_SqueezeDone BOOLEAN,
728 raiseToStealChance BOOLEAN,
729 raiseToStealDone BOOLEAN,
730 success_Steal BOOLEAN,
744 otherRaisedStreet0 BOOLEAN,
745 otherRaisedStreet1 BOOLEAN,
746 otherRaisedStreet2 BOOLEAN,
747 otherRaisedStreet3 BOOLEAN,
748 otherRaisedStreet4 BOOLEAN,
749 foldToOtherRaisedStreet0 BOOLEAN,
750 foldToOtherRaisedStreet1 BOOLEAN,
751 foldToOtherRaisedStreet2 BOOLEAN,
752 foldToOtherRaisedStreet3 BOOLEAN,
753 foldToOtherRaisedStreet4 BOOLEAN,
755 raiseFirstInChance BOOLEAN,
756 raisedFirstIn BOOLEAN,
757 foldBbToStealChance BOOLEAN,
758 foldedBbToSteal BOOLEAN,
759 foldSbToStealChance BOOLEAN,
760 foldedSbToSteal BOOLEAN,
762 street1CBChance BOOLEAN,
763 street1CBDone BOOLEAN,
764 street2CBChance BOOLEAN,
765 street2CBDone BOOLEAN,
766 street3CBChance BOOLEAN,
767 street3CBDone BOOLEAN,
768 street4CBChance BOOLEAN,
769 street4CBDone BOOLEAN,
771 foldToStreet1CBChance BOOLEAN,
772 foldToStreet1CBDone BOOLEAN,
773 foldToStreet2CBChance BOOLEAN,
774 foldToStreet2CBDone BOOLEAN,
775 foldToStreet3CBChance BOOLEAN,
776 foldToStreet3CBDone BOOLEAN,
777 foldToStreet4CBChance BOOLEAN,
778 foldToStreet4CBDone BOOLEAN,
780 street1CheckCallRaiseChance BOOLEAN,
781 street1CheckCallRaiseDone BOOLEAN,
782 street2CheckCallRaiseChance BOOLEAN,
783 street2CheckCallRaiseDone BOOLEAN,
784 street3CheckCallRaiseChance BOOLEAN,
785 street3CheckCallRaiseDone BOOLEAN,
786 street4CheckCallRaiseChance BOOLEAN,
787 street4CheckCallRaiseDone BOOLEAN,
789 street0Calls TINYINT,
790 street1Calls TINYINT,
791 street2Calls TINYINT,
792 street3Calls TINYINT,
793 street4Calls TINYINT,
799 street0Raises TINYINT,
800 street1Raises TINYINT,
801 street2Raises TINYINT,
802 street3Raises TINYINT,
803 street4Raises TINYINT,
805 actionString VARCHAR(15))
807 elif db_server
== 'postgresql':
808 self
.query
['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
809 id BIGSERIAL, PRIMARY KEY (id),
810 handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
811 playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
812 startCash INT NOT NULL,
814 seatNo SMALLINT NOT NULL,
815 sitout BOOLEAN NOT NULL,
816 wentAllInOnStreet SMALLINT,
818 card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
819 card2 smallint NOT NULL,
825 card8 smallint, /* cards 8-20 for draw hands */
841 winnings int NOT NULL,
845 commentTs timestamp without time zone,
846 tourneysPlayersId BIGINT, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
848 wonWhenSeenStreet1 FLOAT,
849 wonWhenSeenStreet2 FLOAT,
850 wonWhenSeenStreet3 FLOAT,
851 wonWhenSeenStreet4 FLOAT,
856 street0_3BChance BOOLEAN,
857 street0_3BDone BOOLEAN,
858 street0_4BChance BOOLEAN,
859 street0_4BDone BOOLEAN,
860 street0_C4BChance BOOLEAN,
861 street0_C4BDone BOOLEAN,
862 street0_FoldTo3BChance BOOLEAN,
863 street0_FoldTo3BDone BOOLEAN,
864 street0_FoldTo4BChance BOOLEAN,
865 street0_FoldTo4BDone BOOLEAN,
866 street0_SqueezeChance BOOLEAN,
867 street0_SqueezeDone BOOLEAN,
869 raiseToStealChance BOOLEAN,
870 raiseToStealDone BOOLEAN,
871 success_Steal BOOLEAN,
885 otherRaisedStreet0 BOOLEAN,
886 otherRaisedStreet1 BOOLEAN,
887 otherRaisedStreet2 BOOLEAN,
888 otherRaisedStreet3 BOOLEAN,
889 otherRaisedStreet4 BOOLEAN,
890 foldToOtherRaisedStreet0 BOOLEAN,
891 foldToOtherRaisedStreet1 BOOLEAN,
892 foldToOtherRaisedStreet2 BOOLEAN,
893 foldToOtherRaisedStreet3 BOOLEAN,
894 foldToOtherRaisedStreet4 BOOLEAN,
896 raiseFirstInChance BOOLEAN,
897 raisedFirstIn BOOLEAN,
898 foldBbToStealChance BOOLEAN,
899 foldedBbToSteal BOOLEAN,
900 foldSbToStealChance BOOLEAN,
901 foldedSbToSteal BOOLEAN,
903 street1CBChance BOOLEAN,
904 street1CBDone BOOLEAN,
905 street2CBChance BOOLEAN,
906 street2CBDone BOOLEAN,
907 street3CBChance BOOLEAN,
908 street3CBDone BOOLEAN,
909 street4CBChance BOOLEAN,
910 street4CBDone BOOLEAN,
912 foldToStreet1CBChance BOOLEAN,
913 foldToStreet1CBDone BOOLEAN,
914 foldToStreet2CBChance BOOLEAN,
915 foldToStreet2CBDone BOOLEAN,
916 foldToStreet3CBChance BOOLEAN,
917 foldToStreet3CBDone BOOLEAN,
918 foldToStreet4CBChance BOOLEAN,
919 foldToStreet4CBDone BOOLEAN,
921 street1CheckCallRaiseChance BOOLEAN,
922 street1CheckCallRaiseDone BOOLEAN,
923 street2CheckCallRaiseChance BOOLEAN,
924 street2CheckCallRaiseDone BOOLEAN,
925 street3CheckCallRaiseChance BOOLEAN,
926 street3CheckCallRaiseDone BOOLEAN,
927 street4CheckCallRaiseChance BOOLEAN,
928 street4CheckCallRaiseDone BOOLEAN,
930 street0Calls SMALLINT,
931 street1Calls SMALLINT,
932 street2Calls SMALLINT,
933 street3Calls SMALLINT,
934 street4Calls SMALLINT,
935 street0Bets SMALLINT,
936 street1Bets SMALLINT,
937 street2Bets SMALLINT,
938 street3Bets SMALLINT,
939 street4Bets SMALLINT,
940 street0Raises SMALLINT,
941 street1Raises SMALLINT,
942 street2Raises SMALLINT,
943 street3Raises SMALLINT,
944 street4Raises SMALLINT,
946 actionString VARCHAR(15))"""
947 elif db_server
== 'sqlite':
948 self
.query
['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
949 id INTEGER PRIMARY KEY,
951 playerId INT NOT NULL,
952 startCash INT NOT NULL,
955 sitout BOOLEAN NOT NULL,
956 wentAllInOnStreet INT,
958 card1 INT NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
965 card8 INT, /* cards 8-20 for draw hands */
981 winnings INT NOT NULL,
986 tourneysPlayersId INT,
988 wonWhenSeenStreet1 REAL,
989 wonWhenSeenStreet2 REAL,
990 wonWhenSeenStreet3 REAL,
991 wonWhenSeenStreet4 REAL,
996 street0_3BChance INT,
998 street0_4BChance INT,
1000 street0_C4BChance INT,
1001 street0_C4BDone INT,
1002 street0_FoldTo3BChance INT,
1003 street0_FoldTo3BDone INT,
1004 street0_FoldTo4BChance INT,
1005 street0_FoldTo4BDone INT,
1006 street0_SqueezeChance INT,
1007 street0_SqueezeDone INT,
1009 raiseToStealChance INT,
1010 raiseToStealDone INT,
1025 otherRaisedStreet0 INT,
1026 otherRaisedStreet1 INT,
1027 otherRaisedStreet2 INT,
1028 otherRaisedStreet3 INT,
1029 otherRaisedStreet4 INT,
1030 foldToOtherRaisedStreet0 INT,
1031 foldToOtherRaisedStreet1 INT,
1032 foldToOtherRaisedStreet2 INT,
1033 foldToOtherRaisedStreet3 INT,
1034 foldToOtherRaisedStreet4 INT,
1036 raiseFirstInChance INT,
1038 foldBbToStealChance INT,
1039 foldedBbToSteal INT,
1040 foldSbToStealChance INT,
1041 foldedSbToSteal INT,
1043 street1CBChance INT,
1045 street2CBChance INT,
1047 street3CBChance INT,
1049 street4CBChance INT,
1052 foldToStreet1CBChance INT,
1053 foldToStreet1CBDone INT,
1054 foldToStreet2CBChance INT,
1055 foldToStreet2CBDone INT,
1056 foldToStreet3CBChance INT,
1057 foldToStreet3CBDone INT,
1058 foldToStreet4CBChance INT,
1059 foldToStreet4CBDone INT,
1061 street1CheckCallRaiseChance INT,
1062 street1CheckCallRaiseDone INT,
1063 street2CheckCallRaiseChance INT,
1064 street2CheckCallRaiseDone INT,
1065 street3CheckCallRaiseChance INT,
1066 street3CheckCallRaiseDone INT,
1067 street4CheckCallRaiseChance INT,
1068 street4CheckCallRaiseDone INT,
1085 actionString VARCHAR(15))
1089 ################################
1090 # Create TourneysPlayers
1091 ################################
1093 if db_server
== 'mysql':
1094 self
.query
['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
1095 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1096 tourneyId INT UNSIGNED NOT NULL, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
1097 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1100 winningsCurrency VARCHAR(4),
1107 elif db_server
== 'postgresql':
1108 self
.query
['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
1109 id BIGSERIAL, PRIMARY KEY (id),
1110 tourneyId INT, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
1111 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
1114 winningsCurrency VARCHAR(4),
1119 commentTs timestamp without time zone)"""
1120 elif db_server
== 'sqlite':
1121 self
.query
['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
1122 id INTEGER PRIMARY KEY,
1127 winningsCurrency VARCHAR(4),
1132 commentTs timestamp without time zone,
1133 FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
1134 FOREIGN KEY (playerId) REFERENCES Players(id)
1138 ################################
1139 # Create HandsActions
1140 ################################
1142 if db_server
== 'mysql':
1143 self
.query
['createHandsActionsTable'] = """CREATE TABLE HandsActions (
1144 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1145 handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
1146 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1147 street SMALLINT NOT NULL,
1148 actionNo SMALLINT NOT NULL,
1149 streetActionNo SMALLINT NOT NULL,
1150 actionId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (actionId) REFERENCES Actions(id),
1151 amount INT NOT NULL,
1152 raiseTo INT NOT NULL,
1153 amountCalled INT NOT NULL,
1154 numDiscarded SMALLINT NOT NULL,
1155 cardsDiscarded varchar(14),
1156 allIn BOOLEAN NOT NULL)
1158 elif db_server
== 'postgresql':
1159 self
.query
['createHandsActionsTable'] = """CREATE TABLE HandsActions (
1160 id BIGSERIAL, PRIMARY KEY (id),
1161 handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
1162 playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1165 streetActionNo SMALLINT,
1166 actionId SMALLINT, FOREIGN KEY (actionId) REFERENCES Actions(id),
1170 numDiscarded SMALLINT,
1171 cardsDiscarded varchar(14),
1173 elif db_server
== 'sqlite':
1174 self
.query
['createHandsActionsTable'] = """CREATE TABLE HandsActions (
1175 id INTEGER PRIMARY KEY,
1176 handId INT NOT NULL,
1177 playerId INT NOT NULL,
1180 streetActionNo SMALLINT,
1185 numDiscarded SMALLINT,
1186 cardsDiscarded TEXT,
1190 ################################
1192 ################################
1194 if db_server
== 'mysql':
1195 self
.query
['createFilesTable'] = """CREATE TABLE Files (
1196 id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1200 startTime DATETIME NOT NULL,
1201 lastUpdate DATETIME NOT NULL,
1211 elif db_server
== 'postgresql':
1212 self
.query
['createFilesTable'] = """CREATE TABLE Files (
1213 id BIGSERIAL, PRIMARY KEY (id),
1217 startTime timestamp without time zone NOT NULL,
1218 lastUpdate timestamp without time zone NOT NULL,
1219 endTime timestamp without time zone,
1226 finished BOOLEAN)"""
1227 elif db_server
== 'sqlite':
1228 self
.query
['createFilesTable'] = """CREATE TABLE Files (
1229 id INTEGER PRIMARY KEY,
1233 startTime timestamp NOT NULL,
1234 lastUpdate timestamp NOT NULL,
1245 ################################
1247 ################################
1249 if db_server
== 'mysql':
1250 self
.query
['createHudCacheTable'] = """CREATE TABLE HudCache (
1251 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1252 gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
1253 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1254 activeSeats SMALLINT NOT NULL,
1256 tourneyTypeId SMALLINT UNSIGNED, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
1257 styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1260 wonWhenSeenStreet1 FLOAT,
1261 wonWhenSeenStreet2 FLOAT,
1262 wonWhenSeenStreet3 FLOAT,
1263 wonWhenSeenStreet4 FLOAT,
1268 street0_3BChance INT,
1270 street0_4BChance INT,
1272 street0_C4BChance INT,
1273 street0_C4BDone INT,
1274 street0_FoldTo3BChance INT,
1275 street0_FoldTo3BDone INT,
1276 street0_FoldTo4BChance INT,
1277 street0_FoldTo4BDone INT,
1278 street0_SqueezeChance INT,
1279 street0_SqueezeDone INT,
1281 raiseToStealChance INT,
1282 raiseToStealDone INT,
1297 otherRaisedStreet0 INT,
1298 otherRaisedStreet1 INT,
1299 otherRaisedStreet2 INT,
1300 otherRaisedStreet3 INT,
1301 otherRaisedStreet4 INT,
1302 foldToOtherRaisedStreet0 INT,
1303 foldToOtherRaisedStreet1 INT,
1304 foldToOtherRaisedStreet2 INT,
1305 foldToOtherRaisedStreet3 INT,
1306 foldToOtherRaisedStreet4 INT,
1308 raiseFirstInChance INT,
1310 foldBbToStealChance INT,
1311 foldedBbToSteal INT,
1312 foldSbToStealChance INT,
1313 foldedSbToSteal INT,
1315 street1CBChance INT,
1317 street2CBChance INT,
1319 street3CBChance INT,
1321 street4CBChance INT,
1324 foldToStreet1CBChance INT,
1325 foldToStreet1CBDone INT,
1326 foldToStreet2CBChance INT,
1327 foldToStreet2CBDone INT,
1328 foldToStreet3CBChance INT,
1329 foldToStreet3CBDone INT,
1330 foldToStreet4CBChance INT,
1331 foldToStreet4CBDone INT,
1335 street1CheckCallRaiseChance INT,
1336 street1CheckCallRaiseDone INT,
1337 street2CheckCallRaiseChance INT,
1338 street2CheckCallRaiseDone INT,
1339 street3CheckCallRaiseChance INT,
1340 street3CheckCallRaiseDone INT,
1341 street4CheckCallRaiseChance INT,
1342 street4CheckCallRaiseDone INT,
1361 elif db_server
== 'postgresql':
1362 self
.query
['createHudCacheTable'] = """CREATE TABLE HudCache (
1363 id BIGSERIAL, PRIMARY KEY (id),
1364 gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
1365 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
1366 activeSeats SMALLINT,
1368 tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
1369 styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1372 wonWhenSeenStreet1 FLOAT,
1373 wonWhenSeenStreet2 FLOAT,
1374 wonWhenSeenStreet3 FLOAT,
1375 wonWhenSeenStreet4 FLOAT,
1380 street0_3BChance INT,
1382 street0_4BChance INT,
1384 street0_C4BChance INT,
1385 street0_C4BDone INT,
1386 street0_FoldTo3BChance INT,
1387 street0_FoldTo3BDone INT,
1388 street0_FoldTo4BChance INT,
1389 street0_FoldTo4BDone INT,
1390 street0_SqueezeChance INT,
1391 street0_SqueezeDone INT,
1393 raiseToStealChance INT,
1394 raiseToStealDone INT,
1407 otherRaisedStreet0 INT,
1408 otherRaisedStreet1 INT,
1409 otherRaisedStreet2 INT,
1410 otherRaisedStreet3 INT,
1411 otherRaisedStreet4 INT,
1412 foldToOtherRaisedStreet0 INT,
1413 foldToOtherRaisedStreet1 INT,
1414 foldToOtherRaisedStreet2 INT,
1415 foldToOtherRaisedStreet3 INT,
1416 foldToOtherRaisedStreet4 INT,
1418 raiseFirstInChance INT,
1420 foldBbToStealChance INT,
1421 foldedBbToSteal INT,
1422 foldSbToStealChance INT,
1423 foldedSbToSteal INT,
1425 street1CBChance INT,
1427 street2CBChance INT,
1429 street3CBChance INT,
1431 street4CBChance INT,
1434 foldToStreet1CBChance INT,
1435 foldToStreet1CBDone INT,
1436 foldToStreet2CBChance INT,
1437 foldToStreet2CBDone INT,
1438 foldToStreet3CBChance INT,
1439 foldToStreet3CBDone INT,
1440 foldToStreet4CBChance INT,
1441 foldToStreet4CBDone INT,
1445 street1CheckCallRaiseChance INT,
1446 street1CheckCallRaiseDone INT,
1447 street2CheckCallRaiseChance INT,
1448 street2CheckCallRaiseDone INT,
1449 street3CheckCallRaiseChance INT,
1450 street3CheckCallRaiseDone INT,
1451 street4CheckCallRaiseChance INT,
1452 street4CheckCallRaiseDone INT,
1470 elif db_server
== 'sqlite':
1471 self
.query
['createHudCacheTable'] = """CREATE TABLE HudCache (
1472 id INTEGER PRIMARY KEY,
1478 styleKey TEXT NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1481 wonWhenSeenStreet1 REAL,
1482 wonWhenSeenStreet2 REAL,
1483 wonWhenSeenStreet3 REAL,
1484 wonWhenSeenStreet4 REAL,
1489 street0_3BChance INT,
1491 street0_4BChance INT,
1493 street0_C4BChance INT,
1494 street0_C4BDone INT,
1495 street0_FoldTo3BChance INT,
1496 street0_FoldTo3BDone INT,
1497 street0_FoldTo4BChance INT,
1498 street0_FoldTo4BDone INT,
1499 street0_SqueezeChance INT,
1500 street0_SqueezeDone INT,
1502 raiseToStealChance INT,
1503 raiseToStealDone INT,
1516 otherRaisedStreet0 INT,
1517 otherRaisedStreet1 INT,
1518 otherRaisedStreet2 INT,
1519 otherRaisedStreet3 INT,
1520 otherRaisedStreet4 INT,
1521 foldToOtherRaisedStreet0 INT,
1522 foldToOtherRaisedStreet1 INT,
1523 foldToOtherRaisedStreet2 INT,
1524 foldToOtherRaisedStreet3 INT,
1525 foldToOtherRaisedStreet4 INT,
1527 raiseFirstInChance INT,
1529 foldBbToStealChance INT,
1530 foldedBbToSteal INT,
1531 foldSbToStealChance INT,
1532 foldedSbToSteal INT,
1534 street1CBChance INT,
1536 street2CBChance INT,
1538 street3CBChance INT,
1540 street4CBChance INT,
1543 foldToStreet1CBChance INT,
1544 foldToStreet1CBDone INT,
1545 foldToStreet2CBChance INT,
1546 foldToStreet2CBDone INT,
1547 foldToStreet3CBChance INT,
1548 foldToStreet3CBDone INT,
1549 foldToStreet4CBChance INT,
1550 foldToStreet4CBDone INT,
1554 street1CheckCallRaiseChance INT,
1555 street1CheckCallRaiseDone INT,
1556 street2CheckCallRaiseChance INT,
1557 street2CheckCallRaiseDone INT,
1558 street3CheckCallRaiseChance INT,
1559 street3CheckCallRaiseDone INT,
1560 street4CheckCallRaiseChance INT,
1561 street4CheckCallRaiseDone INT,
1580 ################################
1581 # Create SessionsCache
1582 ################################
1584 if db_server
== 'mysql':
1585 self
.query
['createSessionsCacheTable'] = """CREATE TABLE SessionsCache (
1586 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1587 sessionStart DATETIME NOT NULL,
1588 sessionEnd DATETIME NOT NULL,
1589 gameStart DATETIME NOT NULL,
1590 gameEnd DATETIME NOT NULL,
1592 date CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1593 type char(7) NOT NULL,
1594 gametypeId SMALLINT UNSIGNED, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
1595 tourneyTypeId SMALLINT UNSIGNED, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
1596 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1599 tourneys INT NOT NULL,
1604 elif db_server
== 'postgresql':
1605 self
.query
['createSessionsCacheTable'] = """CREATE TABLE SessionsCache (
1606 id BIGSERIAL, PRIMARY KEY (id),
1607 sessionStart timestamp without time zone NOT NULL,
1608 sessionEnd timestamp without time zone NOT NULL,
1609 gameStart timestamp without time zone NOT NULL,
1610 gameEnd timestamp without time zone NOT NULL,
1612 date CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1614 gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
1615 tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
1616 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
1623 elif db_server
== 'sqlite':
1624 self
.query
['createSessionsCacheTable'] = """CREATE TABLE SessionsCache (
1625 id INTEGER PRIMARY KEY,
1626 sessionStart timestamp NOT NULL,
1627 sessionEnd timestamp NOT NULL,
1628 gameStart timestamp NOT NULL,
1629 gameEnd timestamp NOT NULL,
1631 date TEXT NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1642 self
.query
['addSessionIdIndex'] = """CREATE INDEX index_SessionId ON SessionsCache (sessionId)"""
1644 self
.query
['addHandsSessionIdIndex'] = """CREATE INDEX index_handsSessionId ON Hands (sessionId)"""
1646 self
.query
['addHandsGameSessionIdIndex'] = """CREATE INDEX index_handsGameSessionId ON Hands (gameSessionId)"""
1648 if db_server
== 'mysql':
1649 self
.query
['addTourneyIndex'] = """ALTER TABLE Tourneys ADD UNIQUE INDEX siteTourneyNo(siteTourneyNo, tourneyTypeId)"""
1650 elif db_server
== 'postgresql':
1651 self
.query
['addTourneyIndex'] = """CREATE UNIQUE INDEX siteTourneyNo ON Tourneys (siteTourneyNo, tourneyTypeId)"""
1652 elif db_server
== 'sqlite':
1653 self
.query
['addTourneyIndex'] = """CREATE UNIQUE INDEX siteTourneyNo ON Tourneys (siteTourneyNo, tourneyTypeId)"""
1655 if db_server
== 'mysql':
1656 self
.query
['addHandsIndex'] = """ALTER TABLE Hands ADD UNIQUE INDEX siteHandNo(siteHandNo, gametypeId)"""
1657 elif db_server
== 'postgresql':
1658 self
.query
['addHandsIndex'] = """CREATE UNIQUE INDEX siteHandNo ON Hands (siteHandNo, gametypeId)"""
1659 elif db_server
== 'sqlite':
1660 self
.query
['addHandsIndex'] = """CREATE UNIQUE INDEX siteHandNo ON Hands (siteHandNo, gametypeId)"""
1662 if db_server
== 'mysql':
1663 self
.query
['addPlayersIndex'] = """ALTER TABLE Players ADD UNIQUE INDEX name(name, siteId)"""
1664 elif db_server
== 'postgresql':
1665 self
.query
['addPlayersIndex'] = """CREATE UNIQUE INDEX name ON Players (name, siteId)"""
1666 elif db_server
== 'sqlite':
1667 self
.query
['addPlayersIndex'] = """CREATE UNIQUE INDEX name ON Players (name, siteId)"""
1669 if db_server
== 'mysql':
1670 self
.query
['addTPlayersIndex'] = """ALTER TABLE TourneysPlayers ADD UNIQUE INDEX _tourneyId(tourneyId, playerId)"""
1671 elif db_server
== 'postgresql':
1672 self
.query
['addTPlayersIndex'] = """CREATE UNIQUE INDEX tourneyId ON TourneysPlayers (tourneyId, playerId)"""
1673 elif db_server
== 'sqlite':
1674 self
.query
['addTPlayersIndex'] = """CREATE UNIQUE INDEX tourneyId ON TourneysPlayers (tourneyId, playerId)"""
1676 if db_server
== 'mysql':
1677 self
.query
['addTTypesIndex'] = """ALTER TABLE TourneyTypes ADD UNIQUE INDEX tourneytypes_all(siteId, buyin, fee
1678 , maxSeats, knockout, rebuy, addOn, speed, shootout, matrix, sng)"""
1679 elif db_server
== 'postgresql':
1680 self
.query
['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (siteId, buyin, fee
1681 , maxSeats, knockout, rebuy, addOn, speed, shootout, matrix, sng)"""
1682 elif db_server
== 'sqlite':
1683 self
.query
['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (siteId, buyin, fee
1684 , maxSeats, knockout, rebuy, addOn, speed, shootout, matrix, sng)"""
1686 self
.query
['get_last_hand'] = "select max(id) from Hands"
1688 self
.query
['get_last_date'] = "SELECT MAX(startTime) FROM Hands"
1690 self
.query
['get_first_date'] = "SELECT MIN(startTime) FROM Hands"
1692 self
.query
['get_player_id'] = """
1693 select Players.id AS player_id
1695 where Players.name = %s
1697 and Players.siteId = Sites.id
1700 self
.query
['get_player_names'] = """
1703 where lower(p.name) like lower(%s)
1704 and (p.siteId = %s or %s = -1)
1707 self
.query
['get_gameinfo_from_hid'] = """
1715 round(g.smallBlind / 100.0,2),
1716 round(g.bigBlind / 100.0,2),
1717 round(g.smallBet / 100.0,2),
1718 round(g.bigBet / 100.0,2),
1728 and g.id = h.gametypeid
1729 and hp.handid = h.id
1730 and p.id = hp.playerid
1735 self
.query
['get_stats_from_hand'] = """
1736 SELECT hc.playerId AS player_id,
1738 p.name AS screen_name,
1740 sum(hc.street0VPI) AS vpip,
1741 sum(hc.street0Aggr) AS pfr,
1742 sum(hc.street0_3BChance) AS TB_opp_0,
1743 sum(hc.street0_3BDone) AS TB_0,
1744 sum(hc.street0_4BChance) AS FB_opp_0,
1745 sum(hc.street0_4BDone) AS FB_0,
1746 sum(hc.street0_C4BChance) AS CFB_opp_0,
1747 sum(hc.street0_C4BDone) AS CFB_0,
1748 sum(hc.street0_FoldTo3BChance) AS F3B_opp_0,
1749 sum(hc.street0_FoldTo3BDone) AS F3B_0,
1750 sum(hc.street0_FoldTo4BChance) AS F4B_opp_0,
1751 sum(hc.street0_FoldTo4BDone) AS F4B_0,
1752 sum(hc.street0_SqueezeChance) AS SQZ_opp_0,
1753 sum(hc.street0_SqueezeDone) AS SQZ_0,
1754 sum(hc.raiseToStealChance) AS RTS_opp,
1755 sum(hc.raiseToStealDone) AS RTS,
1756 sum(hc.success_Steal) AS SUC_ST,
1757 sum(hc.street1Seen) AS saw_f,
1758 sum(hc.street1Seen) AS saw_1,
1759 sum(hc.street2Seen) AS saw_2,
1760 sum(hc.street3Seen) AS saw_3,
1761 sum(hc.street4Seen) AS saw_4,
1762 sum(hc.sawShowdown) AS sd,
1763 sum(hc.street1Aggr) AS aggr_1,
1764 sum(hc.street2Aggr) AS aggr_2,
1765 sum(hc.street3Aggr) AS aggr_3,
1766 sum(hc.street4Aggr) AS aggr_4,
1767 sum(hc.otherRaisedStreet1) AS was_raised_1,
1768 sum(hc.otherRaisedStreet2) AS was_raised_2,
1769 sum(hc.otherRaisedStreet3) AS was_raised_3,
1770 sum(hc.otherRaisedStreet4) AS was_raised_4,
1771 sum(hc.foldToOtherRaisedStreet1) AS f_freq_1,
1772 sum(hc.foldToOtherRaisedStreet2) AS f_freq_2,
1773 sum(hc.foldToOtherRaisedStreet3) AS f_freq_3,
1774 sum(hc.foldToOtherRaisedStreet4) AS f_freq_4,
1775 sum(hc.wonWhenSeenStreet1) AS w_w_s_1,
1776 sum(hc.wonAtSD) AS wmsd,
1777 sum(case hc.position
1778 when 'S' then hc.raiseFirstInChance
1779 when '0' then hc.raiseFirstInChance
1780 when '1' then hc.raiseFirstInChance
1783 sum(case hc.position
1784 when 'S' then hc.raisedFirstIn
1785 when '0' then hc.raisedFirstIn
1786 when '1' then hc.raisedFirstIn
1789 sum(hc.foldSbToStealChance) AS SBstolen,
1790 sum(hc.foldedSbToSteal) AS SBnotDef,
1791 sum(hc.foldBbToStealChance) AS BBstolen,
1792 sum(hc.foldedBbToSteal) AS BBnotDef,
1793 sum(hc.street1CBChance) AS CB_opp_1,
1794 sum(hc.street1CBDone) AS CB_1,
1795 sum(hc.street2CBChance) AS CB_opp_2,
1796 sum(hc.street2CBDone) AS CB_2,
1797 sum(hc.street3CBChance) AS CB_opp_3,
1798 sum(hc.street3CBDone) AS CB_3,
1799 sum(hc.street4CBChance) AS CB_opp_4,
1800 sum(hc.street4CBDone) AS CB_4,
1801 sum(hc.foldToStreet1CBChance) AS f_cb_opp_1,
1802 sum(hc.foldToStreet1CBDone) AS f_cb_1,
1803 sum(hc.foldToStreet2CBChance) AS f_cb_opp_2,
1804 sum(hc.foldToStreet2CBDone) AS f_cb_2,
1805 sum(hc.foldToStreet3CBChance) AS f_cb_opp_3,
1806 sum(hc.foldToStreet3CBDone) AS f_cb_3,
1807 sum(hc.foldToStreet4CBChance) AS f_cb_opp_4,
1808 sum(hc.foldToStreet4CBDone) AS f_cb_4,
1809 sum(hc.totalProfit) AS net,
1810 sum(gt.bigblind) AS bigblind,
1811 sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1,
1812 sum(hc.street1CheckCallRaiseDone) AS ccr_1,
1813 sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2,
1814 sum(hc.street2CheckCallRaiseDone) AS ccr_2,
1815 sum(hc.street3CheckCallRaiseChance) AS ccr_opp_3,
1816 sum(hc.street3CheckCallRaiseDone) AS ccr_3,
1817 sum(hc.street4CheckCallRaiseChance) AS ccr_opp_4,
1818 sum(hc.street4CheckCallRaiseDone) AS ccr_4
1819 sum(hc.street0Calls) AS call_0,
1820 sum(hc.street1Calls) AS call_1,
1821 sum(hc.street2Calls) AS call_2,
1822 sum(hc.street3Calls) AS call_3,
1823 sum(hc.street4Calls) AS call_4,
1824 sum(hc.street0Bets) AS bet_0,
1825 sum(hc.street1Bets) AS bet_1,
1826 sum(hc.street2Bets) AS bet_2,
1827 sum(hc.street3Bets) AS bet_3,
1828 sum(hc.street4Bets) AS bet_4,
1829 sum(hc.street0Raises) AS raise_0,
1830 sum(hc.street1Raises) AS raise_1,
1831 sum(hc.street2Raises) AS raise_2,
1832 sum(hc.street3Raises) AS raise_3,
1833 sum(hc.street4Raises) AS raise_4
1835 INNER JOIN HandsPlayers hp ON (hp.handId = h.id)
1836 INNER JOIN HudCache hc ON ( hc.PlayerId = hp.PlayerId+0
1837 AND hc.gametypeId+0 = h.gametypeId+0)
1838 INNER JOIN Players p ON (p.id = hp.PlayerId+0)
1839 INNER JOIN Gametypes gt ON (gt.id = hc.gametypeId)
1841 AND hc.styleKey > %s
1842 /* styleKey is currently 'd' (for date) followed by a yyyymmdd
1843 date key. Set it to 0000000 or similar to get all records */
1844 /* also check activeseats here even if only 3 groups eg 2-3/4-6/7+
1845 e.g. could use a multiplier:
1846 AND h.seats > X / 1.25 and hp.seats < X * 1.25
1847 where X is the number of active players at the current table (and
1848 1.25 would be a config value so user could change it)
1850 GROUP BY hc.PlayerId, hp.seatNo, p.name
1851 ORDER BY hc.PlayerId, hp.seatNo, p.name
1854 # same as above except stats are aggregated for all blind/limit levels
1855 self
.query
['get_stats_from_hand_aggregated'] = """
1856 /* explain query plan */
1857 SELECT hc.playerId AS player_id,
1858 max(case when hc.gametypeId = h.gametypeId
1862 p.name AS screen_name,
1864 sum(hc.street0VPI) AS vpip,
1865 sum(hc.street0Aggr) AS pfr,
1866 sum(hc.street0_3BChance) AS TB_opp_0,
1867 sum(hc.street0_3BDone) AS TB_0,
1868 sum(hc.street0_4BChance) AS FB_opp_0,
1869 sum(hc.street0_4BDone) AS FB_0,
1870 sum(hc.street0_C4BChance) AS CFB_opp_0,
1871 sum(hc.street0_C4BDone) AS CFB_0,
1872 sum(hc.street0_FoldTo3BChance) AS F3B_opp_0,
1873 sum(hc.street0_FoldTo3BDone) AS F3B_0,
1874 sum(hc.street0_FoldTo4BChance) AS F4B_opp_0,
1875 sum(hc.street0_FoldTo4BDone) AS F4B_0,
1876 sum(hc.street0_SqueezeChance) AS SQZ_opp_0,
1877 sum(hc.street0_SqueezeDone) AS SQZ_0,
1878 sum(hc.raiseToStealChance) AS RTS_opp,
1879 sum(hc.raiseToStealDone) AS RTS,
1880 sum(hc.success_Steal) AS SUC_ST,
1881 sum(hc.street1Seen) AS saw_f,
1882 sum(hc.street1Seen) AS saw_1,
1883 sum(hc.street2Seen) AS saw_2,
1884 sum(hc.street3Seen) AS saw_3,
1885 sum(hc.street4Seen) AS saw_4,
1886 sum(hc.sawShowdown) AS sd,
1887 sum(hc.street1Aggr) AS aggr_1,
1888 sum(hc.street2Aggr) AS aggr_2,
1889 sum(hc.street3Aggr) AS aggr_3,
1890 sum(hc.street4Aggr) AS aggr_4,
1891 sum(hc.otherRaisedStreet1) AS was_raised_1,
1892 sum(hc.otherRaisedStreet2) AS was_raised_2,
1893 sum(hc.otherRaisedStreet3) AS was_raised_3,
1894 sum(hc.otherRaisedStreet4) AS was_raised_4,
1895 sum(hc.foldToOtherRaisedStreet1) AS f_freq_1,
1896 sum(hc.foldToOtherRaisedStreet2) AS f_freq_2,
1897 sum(hc.foldToOtherRaisedStreet3) AS f_freq_3,
1898 sum(hc.foldToOtherRaisedStreet4) AS f_freq_4,
1899 sum(hc.wonWhenSeenStreet1) AS w_w_s_1,
1900 sum(hc.wonAtSD) AS wmsd,
1901 sum(hc.raiseFirstInChance) AS steal_opp,
1902 sum(hc.raisedFirstIn) AS steal,
1903 sum(hc.foldSbToStealChance) AS SBstolen,
1904 sum(hc.foldedSbToSteal) AS SBnotDef,
1905 sum(hc.foldBbToStealChance) AS BBstolen,
1906 sum(hc.foldedBbToSteal) AS BBnotDef,
1907 sum(hc.street1CBChance) AS CB_opp_1,
1908 sum(hc.street1CBDone) AS CB_1,
1909 sum(hc.street2CBChance) AS CB_opp_2,
1910 sum(hc.street2CBDone) AS CB_2,
1911 sum(hc.street3CBChance) AS CB_opp_3,
1912 sum(hc.street3CBDone) AS CB_3,
1913 sum(hc.street4CBChance) AS CB_opp_4,
1914 sum(hc.street4CBDone) AS CB_4,
1915 sum(hc.foldToStreet1CBChance) AS f_cb_opp_1,
1916 sum(hc.foldToStreet1CBDone) AS f_cb_1,
1917 sum(hc.foldToStreet2CBChance) AS f_cb_opp_2,
1918 sum(hc.foldToStreet2CBDone) AS f_cb_2,
1919 sum(hc.foldToStreet3CBChance) AS f_cb_opp_3,
1920 sum(hc.foldToStreet3CBDone) AS f_cb_3,
1921 sum(hc.foldToStreet4CBChance) AS f_cb_opp_4,
1922 sum(hc.foldToStreet4CBDone) AS f_cb_4,
1923 sum(hc.totalProfit) AS net,
1924 sum(gt.bigblind) AS bigblind,
1925 sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1,
1926 sum(hc.street1CheckCallRaiseDone) AS ccr_1,
1927 sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2,
1928 sum(hc.street2CheckCallRaiseDone) AS ccr_2,
1929 sum(hc.street3CheckCallRaiseChance) AS ccr_opp_3,
1930 sum(hc.street3CheckCallRaiseDone) AS ccr_3,
1931 sum(hc.street4CheckCallRaiseChance) AS ccr_opp_4,
1932 sum(hc.street4CheckCallRaiseDone) AS ccr_4,
1933 sum(hc.street0Calls) AS call_0,
1934 sum(hc.street1Calls) AS call_1,
1935 sum(hc.street2Calls) AS call_2,
1936 sum(hc.street3Calls) AS call_3,
1937 sum(hc.street4Calls) AS call_4,
1938 sum(hc.street0Bets) AS bet_0,
1939 sum(hc.street1Bets) AS bet_1,
1940 sum(hc.street2Bets) AS bet_2,
1941 sum(hc.street3Bets) AS bet_3,
1942 sum(hc.street4Bets) AS bet_4,
1943 sum(hc.street0Raises) AS raise_0,
1944 sum(hc.street1Raises) AS raise_1,
1945 sum(hc.street2Raises) AS raise_2,
1946 sum(hc.street3Raises) AS raise_3,
1947 sum(hc.street4Raises) AS raise_4
1949 INNER JOIN HandsPlayers hp ON (hp.handId = h.id)
1950 INNER JOIN HudCache hc ON (hc.playerId = hp.playerId)
1951 INNER JOIN Players p ON (p.id = hc.playerId)
1952 INNER JOIN Gametypes gt ON (gt.id = hc.gametypeId)
1954 AND ( /* 2 separate parts for hero and opponents */
1956 AND hc.styleKey > %s
1957 AND hc.gametypeId+0 in
1958 (SELECT gt1.id from Gametypes gt1, Gametypes gt2
1959 WHERE gt1.siteid = gt2.siteid /* find gametypes where these match: */
1960 AND gt1.type = gt2.type /* ring/tourney */
1961 AND gt1.category = gt2.category /* holdem/stud*/
1962 AND gt1.limittype = gt2.limittype /* fl/nl */
1963 AND gt1.bigblind <= gt2.bigblind * %s /* bigblind similar size */
1964 AND gt1.bigblind >= gt2.bigblind / %s
1965 AND gt2.id = h.gametypeId)
1966 AND hc.activeSeats between %s and %s
1970 AND hc.styleKey > %s
1971 AND hc.gametypeId+0 in
1972 (SELECT gt1.id from Gametypes gt1, Gametypes gt2
1973 WHERE gt1.siteid = gt2.siteid /* find gametypes where these match: */
1974 AND gt1.type = gt2.type /* ring/tourney */
1975 AND gt1.category = gt2.category /* holdem/stud*/
1976 AND gt1.limittype = gt2.limittype /* fl/nl */
1977 AND gt1.bigblind <= gt2.bigblind * %s /* bigblind similar size */
1978 AND gt1.bigblind >= gt2.bigblind / %s
1979 AND gt2.id = h.gametypeId)
1980 AND hc.activeSeats between %s and %s
1983 GROUP BY hc.PlayerId, p.name
1984 ORDER BY hc.PlayerId, p.name
1986 # NOTES on above cursor:
1987 # - Do NOT include %s inside query in a comment - the db api thinks
1988 # they are actual arguments.
1989 # - styleKey is currently 'd' (for date) followed by a yyyymmdd
1990 # date key. Set it to 0000000 or similar to get all records
1991 # Could also check activeseats here even if only 3 groups eg 2-3/4-6/7+
1992 # e.g. could use a multiplier:
1993 # AND h.seats > %s / 1.25 and hp.seats < %s * 1.25
1994 # where %s is the number of active players at the current table (and
1995 # 1.25 would be a config value so user could change it)
1997 if db_server
== 'mysql':
1998 self
.query
['get_stats_from_hand_session'] = """
1999 SELECT hp.playerId AS player_id, /* playerId and seats must */
2000 h.seats AS seats, /* be first and second field */
2001 hp.handId AS hand_id,
2003 p.name AS screen_name,
2005 cast(hp2.street0VPI as <signed>integer) AS vpip,
2006 cast(hp2.street0Aggr as <signed>integer) AS pfr,
2007 cast(hp2.street0_3BChance as <signed>integer) AS TB_opp_0,
2008 cast(hp2.street0_3BDone as <signed>integer) AS TB_0,
2009 cast(hp2.street0_4BChance as <signed>integer) AS FB_opp_0,
2010 cast(hp2.street0_4BDone as <signed>integer) AS FB_0,
2011 cast(hp2.street0_C4BChance as <signed>integer) AS CFB_opp_0,
2012 cast(hp2.street0_C4BDone as <signed>integer) AS CFB_0,
2013 cast(hp2.street0_FoldTo3BChance as <signed>integer) AS F3B_opp_0,
2014 cast(hp2.street0_FoldTo3BDone as <signed>integer) AS F3B_0,
2015 cast(hp2.street0_FoldTo4BChance as <signed>integer) AS F4B_opp_0,
2016 cast(hp2.street0_FoldTo4BDone as <signed>integer) AS F4B_0,
2017 cast(hp2.street0_SqueezeChance as <signed>integer) AS SQZ_opp_0,
2018 cast(hp2.street0_SqueezeDone as <signed>integer) AS SQZ_0,
2019 cast(hp2.raiseToStealChance as <signed>integer) AS RTS_opp,
2020 cast(hp2.raiseToStealDone as <signed>integer) AS RTS,
2021 cast(hp2.success_Steal as <signed>integer) AS SUC_ST,
2022 cast(hp2.street1Seen as <signed>integer) AS saw_f,
2023 cast(hp2.street1Seen as <signed>integer) AS saw_1,
2024 cast(hp2.street2Seen as <signed>integer) AS saw_2,
2025 cast(hp2.street3Seen as <signed>integer) AS saw_3,
2026 cast(hp2.street4Seen as <signed>integer) AS saw_4,
2027 cast(hp2.sawShowdown as <signed>integer) AS sd,
2028 cast(hp2.street1Aggr as <signed>integer) AS aggr_1,
2029 cast(hp2.street2Aggr as <signed>integer) AS aggr_2,
2030 cast(hp2.street3Aggr as <signed>integer) AS aggr_3,
2031 cast(hp2.street4Aggr as <signed>integer) AS aggr_4,
2032 cast(hp2.otherRaisedStreet1 as <signed>integer) AS was_raised_1,
2033 cast(hp2.otherRaisedStreet2 as <signed>integer) AS was_raised_2,
2034 cast(hp2.otherRaisedStreet3 as <signed>integer) AS was_raised_3,
2035 cast(hp2.otherRaisedStreet4 as <signed>integer) AS was_raised_4,
2036 cast(hp2.foldToOtherRaisedStreet1 as <signed>integer) AS f_freq_1,
2037 cast(hp2.foldToOtherRaisedStreet2 as <signed>integer) AS f_freq_2,
2038 cast(hp2.foldToOtherRaisedStreet3 as <signed>integer) AS f_freq_3,
2039 cast(hp2.foldToOtherRaisedStreet4 as <signed>integer) AS f_freq_4,
2040 cast(hp2.wonWhenSeenStreet1 as <signed>integer) AS w_w_s_1,
2041 cast(hp2.wonAtSD as <signed>integer) AS wmsd,
2042 cast(hp2.raiseFirstInChance as <signed>integer) AS steal_opp,
2043 cast(hp2.raisedFirstIn as <signed>integer) AS steal,
2044 cast(hp2.foldSbToStealChance as <signed>integer) AS SBstolen,
2045 cast(hp2.foldedSbToSteal as <signed>integer) AS SBnotDef,
2046 cast(hp2.foldBbToStealChance as <signed>integer) AS BBstolen,
2047 cast(hp2.foldedBbToSteal as <signed>integer) AS BBnotDef,
2048 cast(hp2.street1CBChance as <signed>integer) AS CB_opp_1,
2049 cast(hp2.street1CBDone as <signed>integer) AS CB_1,
2050 cast(hp2.street2CBChance as <signed>integer) AS CB_opp_2,
2051 cast(hp2.street2CBDone as <signed>integer) AS CB_2,
2052 cast(hp2.street3CBChance as <signed>integer) AS CB_opp_3,
2053 cast(hp2.street3CBDone as <signed>integer) AS CB_3,
2054 cast(hp2.street4CBChance as <signed>integer) AS CB_opp_4,
2055 cast(hp2.street4CBDone as <signed>integer) AS CB_4,
2056 cast(hp2.foldToStreet1CBChance as <signed>integer) AS f_cb_opp_1,
2057 cast(hp2.foldToStreet1CBDone as <signed>integer) AS f_cb_1,
2058 cast(hp2.foldToStreet2CBChance as <signed>integer) AS f_cb_opp_2,
2059 cast(hp2.foldToStreet2CBDone as <signed>integer) AS f_cb_2,
2060 cast(hp2.foldToStreet3CBChance as <signed>integer) AS f_cb_opp_3,
2061 cast(hp2.foldToStreet3CBDone as <signed>integer) AS f_cb_3,
2062 cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
2063 cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
2064 cast(hp2.totalProfit as <signed>integer) AS net,
2065 cast(gt.bigblind as <signed>integer) AS bigblind,
2066 cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
2067 cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
2068 cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
2069 cast(hp2.street2CheckCallRaiseDone as <signed>integer) AS ccr_2,
2070 cast(hp2.street3CheckCallRaiseChance as <signed>integer) AS ccr_opp_3,
2071 cast(hp2.street3CheckCallRaiseDone as <signed>integer) AS ccr_3,
2072 cast(hp2.street4CheckCallRaiseChance as <signed>integer) AS ccr_opp_4,
2073 cast(hp2.street4CheckCallRaiseDone as <signed>integer) AS ccr_4,
2074 cast(hp2.street0Calls as <signed>integer) AS call_0,
2075 cast(hp2.street1Calls as <signed>integer) AS call_1,
2076 cast(hp2.street2Calls as <signed>integer) AS call_2,
2077 cast(hp2.street3Calls as <signed>integer) AS call_3,
2078 cast(hp2.street4Calls as <signed>integer) AS call_4,
2079 cast(hp2.street0Bets as <signed>integer) AS bet_0,
2080 cast(hp2.street1Bets as <signed>integer) AS bet_1,
2081 cast(hp2.street2Bets as <signed>integer) AS bet_2,
2082 cast(hp2.street3Bets as <signed>integer) AS bet_3,
2083 cast(hp2.street4Bets as <signed>integer) AS bet_4,
2084 cast(hp2.street0Raises as <signed>integer) AS raise_0,
2085 cast(hp2.street1Raises as <signed>integer) AS raise_1,
2086 cast(hp2.street2Raises as <signed>integer) AS raise_2,
2087 cast(hp2.street3Raises as <signed>integer) AS raise_3,
2088 cast(hp2.street4Raises as <signed>integer) AS raise_4
2091 INNER JOIN Hands h2 ON (h2.id >= %s AND h2.tableName = h.tableName)
2092 INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */
2093 INNER JOIN HandsPlayers hp2 ON (hp2.playerId+0 = hp.playerId+0 AND (hp2.handId = h2.id+0)) /* other hands by these players */
2094 INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
2095 INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
2096 WHERE hp.handId = %s
2097 /* check activeseats once this data returned (don't want to do that here as it might
2098 assume a session ended just because the number of seats dipped for a few hands)
2100 AND ( /* 2 separate parts for hero and opponents */
2101 ( hp2.playerId != %s
2102 AND h2.seats between %s and %s
2106 AND h2.seats between %s and %s
2109 ORDER BY h.startTime desc, hp2.PlayerId
2110 /* order rows by handstart descending so that we can stop reading rows when
2111 there's a gap over X minutes between hands (ie. when we get back to start of
2114 elif db_server
== 'postgresql':
2115 self
.query
['get_stats_from_hand_session'] = """
2116 SELECT hp.playerId AS player_id,
2117 hp.handId AS hand_id,
2119 p.name AS screen_name,
2122 cast(hp2.street0VPI as <signed>integer) AS vpip,
2123 cast(hp2.street0Aggr as <signed>integer) AS pfr,
2124 cast(hp2.street0_3BChance as <signed>integer) AS TB_opp_0,
2125 cast(hp2.street0_3BDone as <signed>integer) AS TB_0,
2126 cast(hp2.street0_4BChance as <signed>integer) AS FB_opp_0,
2127 cast(hp2.street0_4BDone as <signed>integer) AS FB_0,
2128 cast(hp2.street0_C4BChance as <signed>integer) AS CFB_opp_0,
2129 cast(hp2.street0_C4BDone as <signed>integer) AS CFB_0,
2130 cast(hp2.street0_FoldTo3BChance as <signed>integer) AS F3B_opp_0,
2131 cast(hp2.street0_FoldTo3BDone as <signed>integer) AS F3B_0,
2132 cast(hp2.street0_FoldTo4BChance as <signed>integer) AS F4B_opp_0,
2133 cast(hp2.street0_FoldTo4BDone as <signed>integer) AS F4B_0,
2134 cast(hp2.street0_SqueezeChance as <signed>integer) AS SQZ_opp_0,
2135 cast(hp2.street0_SqueezeDone as <signed>integer) AS SQZ_0,
2136 cast(hp2.raiseToStealChance as <signed>integer) AS RTS_opp,
2137 cast(hp2.raiseToStealDone as <signed>integer) AS RTS,
2138 cast(hp2.success_Steal as <signed>integer) AS SUC_ST,
2139 cast(hp2.street1Seen as <signed>integer) AS saw_f,
2140 cast(hp2.street1Seen as <signed>integer) AS saw_1,
2141 cast(hp2.street2Seen as <signed>integer) AS saw_2,
2142 cast(hp2.street3Seen as <signed>integer) AS saw_3,
2143 cast(hp2.street4Seen as <signed>integer) AS saw_4,
2144 cast(hp2.sawShowdown as <signed>integer) AS sd,
2145 cast(hp2.street1Aggr as <signed>integer) AS aggr_1,
2146 cast(hp2.street2Aggr as <signed>integer) AS aggr_2,
2147 cast(hp2.street3Aggr as <signed>integer) AS aggr_3,
2148 cast(hp2.street4Aggr as <signed>integer) AS aggr_4,
2149 cast(hp2.otherRaisedStreet1 as <signed>integer) AS was_raised_1,
2150 cast(hp2.otherRaisedStreet2 as <signed>integer) AS was_raised_2,
2151 cast(hp2.otherRaisedStreet3 as <signed>integer) AS was_raised_3,
2152 cast(hp2.otherRaisedStreet4 as <signed>integer) AS was_raised_4,
2153 cast(hp2.foldToOtherRaisedStreet1 as <signed>integer) AS f_freq_1,
2154 cast(hp2.foldToOtherRaisedStreet2 as <signed>integer) AS f_freq_2,
2155 cast(hp2.foldToOtherRaisedStreet3 as <signed>integer) AS f_freq_3,
2156 cast(hp2.foldToOtherRaisedStreet4 as <signed>integer) AS f_freq_4,
2157 cast(hp2.wonWhenSeenStreet1 as <signed>integer) AS w_w_s_1,
2158 cast(hp2.wonAtSD as <signed>integer) AS wmsd,
2159 cast(hp2.raiseFirstInChance as <signed>integer) AS steal_opp,
2160 cast(hp2.raisedFirstIn as <signed>integer) AS steal,
2161 cast(hp2.foldSbToStealChance as <signed>integer) AS SBstolen,
2162 cast(hp2.foldedSbToSteal as <signed>integer) AS SBnotDef,
2163 cast(hp2.foldBbToStealChance as <signed>integer) AS BBstolen,
2164 cast(hp2.foldedBbToSteal as <signed>integer) AS BBnotDef,
2165 cast(hp2.street1CBChance as <signed>integer) AS CB_opp_1,
2166 cast(hp2.street1CBDone as <signed>integer) AS CB_1,
2167 cast(hp2.street2CBChance as <signed>integer) AS CB_opp_2,
2168 cast(hp2.street2CBDone as <signed>integer) AS CB_2,
2169 cast(hp2.street3CBChance as <signed>integer) AS CB_opp_3,
2170 cast(hp2.street3CBDone as <signed>integer) AS CB_3,
2171 cast(hp2.street4CBChance as <signed>integer) AS CB_opp_4,
2172 cast(hp2.street4CBDone as <signed>integer) AS CB_4,
2173 cast(hp2.foldToStreet1CBChance as <signed>integer) AS f_cb_opp_1,
2174 cast(hp2.foldToStreet1CBDone as <signed>integer) AS f_cb_1,
2175 cast(hp2.foldToStreet2CBChance as <signed>integer) AS f_cb_opp_2,
2176 cast(hp2.foldToStreet2CBDone as <signed>integer) AS f_cb_2,
2177 cast(hp2.foldToStreet3CBChance as <signed>integer) AS f_cb_opp_3,
2178 cast(hp2.foldToStreet3CBDone as <signed>integer) AS f_cb_3,
2179 cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
2180 cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
2181 cast(hp2.totalProfit as <signed>integer) AS net,
2182 cast(gt.bigblind as <signed>integer) AS bigblind,
2183 cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
2184 cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
2185 cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
2186 cast(hp2.street2CheckCallRaiseDone as <signed>integer) AS ccr_2,
2187 cast(hp2.street3CheckCallRaiseChance as <signed>integer) AS ccr_opp_3,
2188 cast(hp2.street3CheckCallRaiseDone as <signed>integer) AS ccr_3,
2189 cast(hp2.street4CheckCallRaiseChance as <signed>integer) AS ccr_opp_4,
2190 cast(hp2.street4CheckCallRaiseDone as <signed>integer) AS ccr_4,
2191 cast(hp2.street0Calls as <signed>integer) AS call_0,
2192 cast(hp2.street1Calls as <signed>integer) AS call_1,
2193 cast(hp2.street2Calls as <signed>integer) AS call_2,
2194 cast(hp2.street3Calls as <signed>integer) AS call_3,
2195 cast(hp2.street4Calls as <signed>integer) AS call_4,
2196 cast(hp2.street0Bets as <signed>integer) AS bet_0,
2197 cast(hp2.street1Bets as <signed>integer) AS bet_1,
2198 cast(hp2.street2Bets as <signed>integer) AS bet_2,
2199 cast(hp2.street3Bets as <signed>integer) AS bet_3,
2200 cast(hp2.street4Bets as <signed>integer) AS bet_4,
2201 cast(hp2.street0Raises as <signed>integer) AS raise_0,
2202 cast(hp2.street1Raises as <signed>integer) AS raise_1,
2203 cast(hp2.street2Raises as <signed>integer) AS raise_2,
2204 cast(hp2.street3Raises as <signed>integer) AS raise_3,
2205 cast(hp2.street4Raises as <signed>integer) AS raise_4
2206 FROM Hands h /* this hand */
2207 INNER JOIN Hands h2 ON ( h2.id >= %s /* other hands */
2208 AND h2.tableName = h.tableName)
2209 INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */
2210 INNER JOIN HandsPlayers hp2 ON ( hp2.playerId+0 = hp.playerId+0
2211 AND hp2.handId = h2.id) /* other hands by these players */
2212 INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
2213 INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
2215 /* check activeseats once this data returned (don't want to do that here as it might
2216 assume a session ended just because the number of seats dipped for a few hands)
2218 AND ( /* 2 separate parts for hero and opponents */
2219 ( hp2.playerId != %s
2220 AND h2.seats between %s and %s
2224 AND h2.seats between %s and %s
2227 ORDER BY h.startTime desc, hp2.PlayerId
2228 /* order rows by handstart descending so that we can stop reading rows when
2229 there's a gap over X minutes between hands (ie. when we get back to start of
2232 elif db_server
== 'sqlite':
2233 self
.query
['get_stats_from_hand_session'] = """
2234 SELECT hp.playerId AS player_id,
2235 hp.handId AS hand_id,
2237 p.name AS screen_name,
2240 cast(hp2.street0VPI as <signed>integer) AS vpip,
2241 cast(hp2.street0Aggr as <signed>integer) AS pfr,
2242 cast(hp2.street0_3BChance as <signed>integer) AS TB_opp_0,
2243 cast(hp2.street0_3BDone as <signed>integer) AS TB_0,
2244 cast(hp2.street0_4BChance as <signed>integer) AS FB_opp_0,
2245 cast(hp2.street0_4BDone as <signed>integer) AS FB_0,
2246 cast(hp2.street0_C4BChance as <signed>integer) AS CFB_opp_0,
2247 cast(hp2.street0_C4BDone as <signed>integer) AS CFB_0,
2248 cast(hp2.street0_FoldTo3BChance as <signed>integer) AS F3B_opp_0,
2249 cast(hp2.street0_FoldTo3BDone as <signed>integer) AS F3B_0,
2250 cast(hp2.street0_FoldTo4BChance as <signed>integer) AS F4B_opp_0,
2251 cast(hp2.street0_FoldTo4BDone as <signed>integer) AS F4B_0,
2252 cast(hp2.street0_SqueezeChance as <signed>integer) AS SQZ_opp_0,
2253 cast(hp2.street0_SqueezeDone as <signed>integer) AS SQZ_0,
2254 cast(hp2.raiseToStealChance as <signed>integer) AS RTS_opp,
2255 cast(hp2.raiseToStealDone as <signed>integer) AS RTS,
2256 cast(hp2.success_Steal as <signed>integer) AS SUC_ST,
2257 cast(hp2.street1Seen as <signed>integer) AS saw_f,
2258 cast(hp2.street1Seen as <signed>integer) AS saw_1,
2259 cast(hp2.street2Seen as <signed>integer) AS saw_2,
2260 cast(hp2.street3Seen as <signed>integer) AS saw_3,
2261 cast(hp2.street4Seen as <signed>integer) AS saw_4,
2262 cast(hp2.sawShowdown as <signed>integer) AS sd,
2263 cast(hp2.street1Aggr as <signed>integer) AS aggr_1,
2264 cast(hp2.street2Aggr as <signed>integer) AS aggr_2,
2265 cast(hp2.street3Aggr as <signed>integer) AS aggr_3,
2266 cast(hp2.street4Aggr as <signed>integer) AS aggr_4,
2267 cast(hp2.otherRaisedStreet1 as <signed>integer) AS was_raised_1,
2268 cast(hp2.otherRaisedStreet2 as <signed>integer) AS was_raised_2,
2269 cast(hp2.otherRaisedStreet3 as <signed>integer) AS was_raised_3,
2270 cast(hp2.otherRaisedStreet4 as <signed>integer) AS was_raised_4,
2271 cast(hp2.foldToOtherRaisedStreet1 as <signed>integer) AS f_freq_1,
2272 cast(hp2.foldToOtherRaisedStreet2 as <signed>integer) AS f_freq_2,
2273 cast(hp2.foldToOtherRaisedStreet3 as <signed>integer) AS f_freq_3,
2274 cast(hp2.foldToOtherRaisedStreet4 as <signed>integer) AS f_freq_4,
2275 cast(hp2.wonWhenSeenStreet1 as <signed>integer) AS w_w_s_1,
2276 cast(hp2.wonAtSD as <signed>integer) AS wmsd,
2277 cast(hp2.raiseFirstInChance as <signed>integer) AS steal_opp,
2278 cast(hp2.raisedFirstIn as <signed>integer) AS steal,
2279 cast(hp2.foldSbToStealChance as <signed>integer) AS SBstolen,
2280 cast(hp2.foldedSbToSteal as <signed>integer) AS SBnotDef,
2281 cast(hp2.foldBbToStealChance as <signed>integer) AS BBstolen,
2282 cast(hp2.foldedBbToSteal as <signed>integer) AS BBnotDef,
2283 cast(hp2.street1CBChance as <signed>integer) AS CB_opp_1,
2284 cast(hp2.street1CBDone as <signed>integer) AS CB_1,
2285 cast(hp2.street2CBChance as <signed>integer) AS CB_opp_2,
2286 cast(hp2.street2CBDone as <signed>integer) AS CB_2,
2287 cast(hp2.street3CBChance as <signed>integer) AS CB_opp_3,
2288 cast(hp2.street3CBDone as <signed>integer) AS CB_3,
2289 cast(hp2.street4CBChance as <signed>integer) AS CB_opp_4,
2290 cast(hp2.street4CBDone as <signed>integer) AS CB_4,
2291 cast(hp2.foldToStreet1CBChance as <signed>integer) AS f_cb_opp_1,
2292 cast(hp2.foldToStreet1CBDone as <signed>integer) AS f_cb_1,
2293 cast(hp2.foldToStreet2CBChance as <signed>integer) AS f_cb_opp_2,
2294 cast(hp2.foldToStreet2CBDone as <signed>integer) AS f_cb_2,
2295 cast(hp2.foldToStreet3CBChance as <signed>integer) AS f_cb_opp_3,
2296 cast(hp2.foldToStreet3CBDone as <signed>integer) AS f_cb_3,
2297 cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
2298 cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
2299 cast(hp2.totalProfit as <signed>integer) AS net,
2300 cast(gt.bigblind as <signed>integer) AS bigblind,
2301 cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
2302 cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
2303 cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
2304 cast(hp2.street2CheckCallRaiseDone as <signed>integer) AS ccr_2,
2305 cast(hp2.street3CheckCallRaiseChance as <signed>integer) AS ccr_opp_3,
2306 cast(hp2.street3CheckCallRaiseDone as <signed>integer) AS ccr_3,
2307 cast(hp2.street4CheckCallRaiseChance as <signed>integer) AS ccr_opp_4,
2308 cast(hp2.street4CheckCallRaiseDone as <signed>integer) AS ccr_4,
2309 cast(hp2.street0Calls as <signed>integer) AS call_0,
2310 cast(hp2.street1Calls as <signed>integer) AS call_1,
2311 cast(hp2.street2Calls as <signed>integer) AS call_2,
2312 cast(hp2.street3Calls as <signed>integer) AS call_3,
2313 cast(hp2.street4Calls as <signed>integer) AS call_4,
2314 cast(hp2.street0Bets as <signed>integer) AS bet_0,
2315 cast(hp2.street1Bets as <signed>integer) AS bet_1,
2316 cast(hp2.street2Bets as <signed>integer) AS bet_2,
2317 cast(hp2.street3Bets as <signed>integer) AS bet_3,
2318 cast(hp2.street4Bets as <signed>integer) AS bet_4,
2319 cast(hp2.street0Raises as <signed>integer) AS raise_0,
2320 cast(hp2.street1Raises as <signed>integer) AS raise_1,
2321 cast(hp2.street2Raises as <signed>integer) AS raise_2,
2322 cast(hp2.street3Raises as <signed>integer) AS raise_3,
2323 cast(hp2.street4Raises as <signed>integer) AS raise_4
2324 FROM Hands h /* this hand */
2325 INNER JOIN Hands h2 ON ( h2.id >= %s /* other hands */
2326 AND h2.tableName = h.tableName)
2327 INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */
2328 INNER JOIN HandsPlayers hp2 ON ( hp2.playerId+0 = hp.playerId+0
2329 AND hp2.handId = h2.id) /* other hands by these players */
2330 INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
2331 INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
2333 /* check activeseats once this data returned (don't want to do that here as it might
2334 assume a session ended just because the number of seats dipped for a few hands)
2336 AND ( /* 2 separate parts for hero and opponents */
2337 ( hp2.playerId != %s
2338 AND h2.seats between %s and %s
2342 AND h2.seats between %s and %s
2345 ORDER BY h.startTime desc, hp2.PlayerId
2346 /* order rows by handstart descending so that we can stop reading rows when
2347 there's a gap over X minutes between hands (ie. when we get back to start of
2351 self
.query
['get_players_from_hand'] = """
2352 SELECT HandsPlayers.playerId, seatNo, name
2353 FROM HandsPlayers INNER JOIN Players ON (HandsPlayers.playerId = Players.id)
2356 # WHERE handId = %s AND Players.id LIKE %s
2358 self
.query
['get_winners_from_hand'] = """
2359 SELECT name, winnings
2360 FROM HandsPlayers, Players
2362 AND Players.id = HandsPlayers.playerId
2366 self
.query
['get_table_name'] = """
2367 SELECT h.tableName, gt.maxSeats, gt.category, gt.type, s.id, s.name
2368 , count(1) as numseats
2369 FROM Hands h, Gametypes gt, Sites s, HandsPlayers hp
2371 AND gt.id = h.gametypeId
2372 AND s.id = gt.siteID
2373 AND hp.handId = h.id
2374 GROUP BY h.tableName, gt.maxSeats, gt.category, gt.type, s.id, s.name
2377 self
.query
['get_actual_seat'] = """
2380 where HandsPlayers.handId = %s
2381 and HandsPlayers.playerId = (select Players.id from Players
2382 where Players.name = %s)
2385 self
.query
['get_cards'] = """
2387 seatNo AS seat_number,
2388 card1, /*card1Value, card1Suit, */
2389 card2, /*card2Value, card2Suit, */
2390 card3, /*card3Value, card3Suit, */
2391 card4, /*card4Value, card4Suit, */
2392 card5, /*card5Value, card5Suit, */
2393 card6, /*card6Value, card6Suit, */
2394 card7 /*card7Value, card7Suit */
2395 from HandsPlayers, Players
2396 where handID = %s and HandsPlayers.playerId = Players.id
2400 self
.query
['get_common_cards'] = """
2411 if db_server
== 'mysql':
2412 self
.query
['get_hand_1day_ago'] = """
2413 select coalesce(max(id),0)
2415 where startTime < date_sub(utc_timestamp(), interval '1' day)"""
2416 elif db_server
== 'postgresql':
2417 self
.query
['get_hand_1day_ago'] = """
2418 select coalesce(max(id),0)
2420 where startTime < now() at time zone 'UTC' - interval '1 day'"""
2421 elif db_server
== 'sqlite':
2422 self
.query
['get_hand_1day_ago'] = """
2423 select coalesce(max(id),0)
2425 where startTime < datetime(strftime('%J', 'now') - 1)"""
2428 # gets a date, would need to use handsplayers (not hudcache) to get exact hand Id
2429 if db_server
== 'mysql':
2430 self
.query
['get_date_nhands_ago'] = """
2431 select concat( 'd', date_format(max(h.startTime), '%Y%m%d') )
2432 from (select hp.playerId
2433 ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
2434 from HandsPlayers hp
2435 where hp.playerId = %s
2436 group by hp.playerId) hp2
2437 inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx
2438 and hp3.playerId = hp2.playerId)
2439 inner join Hands h on (h.id = hp3.handId)
2441 elif db_server
== 'postgresql':
2442 self
.query
['get_date_nhands_ago'] = """
2443 select 'd' || to_char(max(h3.startTime), 'YYMMDD')
2444 from (select hp.playerId
2445 ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
2446 from HandsPlayers hp
2447 where hp.playerId = %s
2448 group by hp.playerId) hp2
2449 inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx
2450 and hp3.playerId = hp2.playerId)
2451 inner join Hands h on (h.id = hp3.handId)
2453 elif db_server
== 'sqlite': # untested guess at query:
2454 self
.query
['get_date_nhands_ago'] = """
2455 select 'd' || strftime(max(h3.startTime), 'YYMMDD')
2456 from (select hp.playerId
2457 ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
2458 from HandsPlayers hp
2459 where hp.playerId = %s
2460 group by hp.playerId) hp2
2461 inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx
2462 and hp3.playerId = hp2.playerId)
2463 inner join Hands h on (h.id = hp3.handId)
2466 # used in Gui*PlayerStats:
2467 self
.query
['getPlayerId'] = """SELECT id from Players where name = %s"""
2469 self
.query
['getPlayerIdBySite'] = """SELECT id from Players where name = %s AND siteId = %s"""
2472 #self.query['getLimits'] = already defined further up
2473 self
.query
['getLimits2'] = """SELECT DISTINCT type, limitType, bigBlind
2475 ORDER by type, limitType DESC, bigBlind DESC"""
2476 self
.query
['getLimits3'] = """select DISTINCT type
2479 when 'ring' then bigBlind
2481 - end as bb_or_buyin
2483 cross join TourneyTypes tt
2484 order by type, gt.limitType DESC, bb_or_buyin DESC"""
2485 self
.query
['getCashLimits'] = """select DISTINCT type
2487 , bigBlind as bb_or_buyin
2490 order by type, limitType DESC, bb_or_buyin DESC"""
2491 #FIXME: Some stats not added to DetailedStats (miss raise to steal)
2492 if db_server
== 'mysql':
2493 self
.query
['playerDetailedStats'] = """
2494 select <hgametypeId> AS hgametypeid
2495 ,<playerName> AS pname
2498 ,upper(gt.limitType) AS limittype
2500 ,min(gt.bigBlind) AS minbigblind
2501 ,max(gt.bigBlind) AS maxbigblind
2502 /*,<hcgametypeId> AS gtid*/
2503 ,<position> AS plposition
2505 ,100.0*sum(cast(hp.street0VPI as <signed>integer))/count(1) AS vpip
2506 ,100.0*sum(cast(hp.street0Aggr as <signed>integer))/count(1) AS pfr
2507 ,case when sum(cast(hp.street0_3Bchance as <signed>integer)) = 0 then -999
2508 else 100.0*sum(cast(hp.street0_3Bdone as <signed>integer))/sum(cast(hp.street0_3Bchance as <signed>integer))
2510 ,case when sum(cast(hp.street0_4Bchance as <signed>integer)) = 0 then -999
2511 else 100.0*sum(cast(hp.street0_4Bdone as <signed>integer))/sum(cast(hp.street0_4Bchance as <signed>integer))
2513 ,case when sum(cast(hp.street0_FoldTo3Bchance as <signed>integer)) = 0 then -999
2514 else 100.0*sum(cast(hp.street0_FoldTo3Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo3Bchance as <signed>integer))
2516 ,case when sum(cast(hp.street0_FoldTo4Bchance as <signed>integer)) = 0 then -999
2517 else 100.0*sum(cast(hp.street0_FoldTo4Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo4Bchance as <signed>integer))
2520 ,case when sum(cast(hp.raiseFirstInChance as <signed>integer)) = 0 then -999
2521 else 100.0 * sum(cast(hp.raisedFirstIn as <signed>integer)) /
2522 sum(cast(hp.raiseFirstInChance as <signed>integer))
2524 ,case when sum(case hp.position
2525 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2526 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2527 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2532 sum(case hp.position
2533 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2534 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2535 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2539 sum(case hp.position
2540 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2541 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2542 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2547 ,case when sum(cast(hp.success_Steal as <signed>integer)) = 0 then -999
2549 sum(cast(hp.success_Steal as <signed>integer))
2551 sum(case hp.position
2552 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2553 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2554 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2559 ,100.0*sum(cast(hp.street1Seen as <signed>integer))/count(1) AS saw_f
2560 ,100.0*sum(cast(hp.sawShowdown as <signed>integer))/count(1) AS sawsd
2561 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2562 else 100.0*sum(cast(hp.sawShowdown as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2564 ,case when sum(cast(hp.sawShowdown as <signed>integer)) = 0 then -999
2565 else 100.0*sum(cast(hp.wonAtSD as <signed>integer))/sum(cast(hp.sawShowdown as <signed>integer))
2567 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2568 else 100.0*sum(cast(hp.street1Aggr as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2570 ,case when sum(cast(hp.street2Seen as <signed>integer)) = 0 then -999
2571 else 100.0*sum(cast(hp.street2Aggr as <signed>integer))/sum(cast(hp.street2Seen as <signed>integer))
2573 ,case when sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
2574 else 100.0*sum(cast(hp.street3Aggr as <signed>integer))/sum(cast(hp.street3Seen as <signed>integer))
2576 ,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
2577 else 100.0*(sum(cast(hp.street1Aggr as <signed>integer))+sum(cast(hp.street2Aggr as <signed>integer))+sum(cast(hp.street3Aggr as <signed>integer)))
2578 /(sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)))
2580 ,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
2581 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)))
2582 /(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)))
2584 ,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)))
2585 / ((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))) +
2586 (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))) +
2587 (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))) )
2589 ,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)))
2590 / (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)))
2592 ,sum(hp.totalProfit)/100.0 AS net
2593 ,sum(hp.rake)/100.0 AS rake
2594 ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100
2595 ,avg(hp.totalProfit)/100.0 AS profitperhand
2596 ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr
2597 ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr
2598 ,avg(h.seats+0.0) AS avgseats
2599 ,variance(hp.totalProfit/100.0) AS variance
2600 from HandsPlayers hp
2601 inner join Hands h on (h.id = hp.handId)
2602 inner join Gametypes gt on (gt.Id = h.gametypeId)
2603 inner join Sites s on (s.Id = gt.siteId)
2604 inner join Players p on (p.Id = hp.playerId)
2605 where hp.playerId in <player_test>
2608 /*and hp.tourneysPlayersId IS NULL*/
2609 and h.seats <seats_test>
2613 and date_format(h.startTime, '%Y-%m-%d %T') <datestest>
2614 group by hgametypeId
2620 ,upper(gt.limitType)
2622 having 1 = 1 <havingclause>
2627 ,case <position> when 'B' then 'B'
2629 else concat('Z', <position>)
2631 <orderbyhgametypeId>
2632 ,upper(gt.limitType) desc
2636 elif db_server
== 'postgresql':
2637 self
.query
['playerDetailedStats'] = """
2638 select <hgametypeId> AS hgametypeid
2639 ,<playerName> AS pname
2642 ,upper(gt.limitType) AS limittype
2644 ,min(gt.bigBlind) AS minbigblind
2645 ,max(gt.bigBlind) AS maxbigblind
2646 /*,<hcgametypeId> AS gtid*/
2647 ,<position> AS plposition
2649 ,100.0*sum(cast(hp.street0VPI as <signed>integer))/count(1) AS vpip
2650 ,100.0*sum(cast(hp.street0Aggr as <signed>integer))/count(1) AS pfr
2651 ,case when sum(cast(hp.street0_3Bchance as <signed>integer)) = 0 then -999
2652 else 100.0*sum(cast(hp.street0_3Bdone as <signed>integer))/sum(cast(hp.street0_3Bchance as <signed>integer))
2654 ,case when sum(cast(hp.street0_4Bchance as <signed>integer)) = 0 then -999
2655 else 100.0*sum(cast(hp.street0_4Bdone as <signed>integer))/sum(cast(hp.street0_4Bchance as <signed>integer))
2657 ,case when sum(cast(hp.street0_FoldTo3Bchance as <signed>integer)) = 0 then -999
2658 else 100.0*sum(cast(hp.street0_FoldTo3Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo3Bchance as <signed>integer))
2660 ,case when sum(cast(hp.street0_FoldTo4Bchance as <signed>integer)) = 0 then -999
2661 else 100.0*sum(cast(hp.street0_FoldTo4Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo4Bchance as <signed>integer))
2663 ,case when sum(cast(hp.raiseFirstInChance as <signed>integer)) = 0 then -999
2664 else 100.0 * sum(cast(hp.raisedFirstIn as <signed>integer)) /
2665 sum(cast(hp.raiseFirstInChance as <signed>integer))
2667 ,case when sum(case hp.position
2668 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2669 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2670 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2675 sum(case hp.position
2676 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2677 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2678 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2682 sum(case hp.position
2683 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2684 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2685 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2690 ,case when sum(cast(hp.success_Steal as <signed>integer)) = 0 then -999
2692 sum(cast(hp.success_Steal as <signed>integer))
2694 sum(case hp.position
2695 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2696 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2697 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2702 ,100.0*sum(cast(hp.street1Seen as <signed>integer))/count(1) AS saw_f
2703 ,100.0*sum(cast(hp.sawShowdown as <signed>integer))/count(1) AS sawsd
2704 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2705 else 100.0*sum(cast(hp.sawShowdown as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2707 ,case when sum(cast(hp.sawShowdown as <signed>integer)) = 0 then -999
2708 else 100.0*sum(cast(hp.wonAtSD as <signed>integer))/sum(cast(hp.sawShowdown as <signed>integer))
2710 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2711 else 100.0*sum(cast(hp.street1Aggr as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2713 ,case when sum(cast(hp.street2Seen as <signed>integer)) = 0 then -999
2714 else 100.0*sum(cast(hp.street2Aggr as <signed>integer))/sum(cast(hp.street2Seen as <signed>integer))
2716 ,case when sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
2717 else 100.0*sum(cast(hp.street3Aggr as <signed>integer))/sum(cast(hp.street3Seen as <signed>integer))
2719 ,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
2720 else 100.0*(sum(cast(hp.street1Aggr as <signed>integer))+sum(cast(hp.street2Aggr as <signed>integer))+sum(cast(hp.street3Aggr as <signed>integer)))
2721 /(sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)))
2723 ,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
2724 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)))
2725 /(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)))
2728 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))+
2729 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))+
2730 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))
2733 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)))
2734 / ((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))) +
2735 (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))) +
2736 (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))) )
2739 sum(cast(hp.street1CBChance as <signed>integer))+
2740 sum(cast(hp.street2CBChance as <signed>integer))+
2741 sum(cast(hp.street3CBChance as <signed>integer))+
2742 sum(cast(hp.street4CBChance as <signed>integer)) = 0 then -999
2744 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)))
2745 / (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)))
2747 ,sum(hp.totalProfit)/100.0 AS net
2748 ,sum(hp.rake)/100.0 AS rake
2749 ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100
2750 ,avg(hp.totalProfit)/100.0 AS profitperhand
2751 ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr
2752 ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr
2753 ,avg(h.seats+0.0) AS avgseats
2754 ,variance(hp.totalProfit/100.0) AS variance
2755 from HandsPlayers hp
2756 inner join Hands h on (h.id = hp.handId)
2757 inner join Gametypes gt on (gt.Id = h.gametypeId)
2758 inner join Sites s on (s.Id = gt.siteId)
2759 inner join Players p on (p.Id = hp.playerId)
2760 where hp.playerId in <player_test>
2763 /*and hp.tourneysPlayersId IS NULL*/
2764 and h.seats <seats_test>
2768 and to_char(h.startTime, 'YYYY-MM-DD HH24:MI:SS') <datestest>
2769 group by hgametypeId
2775 ,upper(gt.limitType)
2777 having 1 = 1 <havingclause>
2782 ,case <position> when 'B' then 'B'
2785 else 'Z'||<position>
2787 <orderbyhgametypeId>
2788 ,upper(gt.limitType) desc
2792 elif db_server
== 'sqlite':
2793 self
.query
['playerDetailedStats'] = """
2794 select <hgametypeId> AS hgametypeid
2795 ,<playerName> AS pname
2797 ,gt.category AS category
2798 ,upper(gt.limitType) AS limittype
2800 ,min(gt.bigBlind) AS minbigblind
2801 ,max(gt.bigBlind) AS maxbigblind
2802 /*,<hcgametypeId> AS gtid*/
2803 ,<position> AS plposition
2805 ,100.0*sum(cast(hp.street0VPI as <signed>integer))/count(1) AS vpip
2806 ,100.0*sum(cast(hp.street0Aggr as <signed>integer))/count(1) AS pfr
2807 ,case when sum(cast(hp.street0_3Bchance as <signed>integer)) = 0 then -999
2808 else 100.0*sum(cast(hp.street0_3Bdone as <signed>integer))/sum(cast(hp.street0_3Bchance as <signed>integer))
2810 ,case when sum(cast(hp.street0_4Bchance as <signed>integer)) = 0 then -999
2811 else 100.0*sum(cast(hp.street0_4Bdone as <signed>integer))/sum(cast(hp.street0_4Bchance as <signed>integer))
2813 ,case when sum(cast(hp.street0_FoldTo3Bchance as <signed>integer)) = 0 then -999
2814 else 100.0*sum(cast(hp.street0_FoldTo3Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo3Bchance as <signed>integer))
2816 ,case when sum(cast(hp.street0_FoldTo4Bchance as <signed>integer)) = 0 then -999
2817 else 100.0*sum(cast(hp.street0_FoldTo4Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo4Bchance as <signed>integer))
2819 ,case when sum(cast(hp.raiseFirstInChance as <signed>integer)) = 0 then -999
2820 else 100.0 * sum(cast(hp.raisedFirstIn as <signed>integer)) /
2821 sum(cast(hp.raiseFirstInChance as <signed>integer))
2823 ,case when sum(case hp.position
2824 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2825 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2826 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2831 sum(case hp.position
2832 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2833 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2834 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2838 sum(case hp.position
2839 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
2840 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
2841 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
2846 ,case when sum(cast(hp.success_Steal as <signed>integer)) = 0 then -999
2848 sum(cast(hp.success_Steal as <signed>integer))
2850 sum(case hp.position
2851 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
2852 when '0' then cast(hp.raisedFirstIn as <signed>integer)
2853 when '1' then cast(hp.raisedFirstIn as <signed>integer)
2858 ,100.0*sum(cast(hp.street1Seen as <signed>integer))/count(1) AS saw_f
2859 ,100.0*sum(cast(hp.sawShowdown as <signed>integer))/count(1) AS sawsd
2860 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2861 else 100.0*sum(cast(hp.sawShowdown as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2863 ,case when sum(cast(hp.sawShowdown as <signed>integer)) = 0 then -999
2864 else 100.0*sum(cast(hp.wonAtSD as <signed>integer))/sum(cast(hp.sawShowdown as <signed>integer))
2866 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
2867 else 100.0*sum(cast(hp.street1Aggr as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
2869 ,case when sum(cast(hp.street2Seen as <signed>integer)) = 0 then -999
2870 else 100.0*sum(cast(hp.street2Aggr as <signed>integer))/sum(cast(hp.street2Seen as <signed>integer))
2872 ,case when sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
2873 else 100.0*sum(cast(hp.street3Aggr as <signed>integer))/sum(cast(hp.street3Seen as <signed>integer))
2875 ,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
2876 else 100.0*(sum(cast(hp.street1Aggr as <signed>integer))+sum(cast(hp.street2Aggr as <signed>integer))+sum(cast(hp.street3Aggr as <signed>integer)))
2877 /(sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)))
2879 ,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
2880 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)))
2881 /(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)))
2883 ,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)))
2884 / ((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))) +
2885 (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))) +
2886 (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))) )
2888 ,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)))
2889 / (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)))
2891 ,sum(hp.totalProfit)/100.0 AS net
2892 ,sum(hp.rake)/100.0 AS rake
2893 ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100
2894 ,avg(hp.totalProfit)/100.0 AS profitperhand
2895 ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr
2896 ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr
2897 ,avg(h.seats+0.0) AS avgseats
2898 ,variance(hp.totalProfit/100.0) AS variance
2899 from HandsPlayers hp
2900 inner join Hands h on (h.id = hp.handId)
2901 inner join Gametypes gt on (gt.Id = h.gametypeId)
2902 inner join Sites s on (s.Id = gt.siteId)
2903 inner join Players p on (p.Id = hp.playerId)
2904 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>'
3819 AND hp.tourneysPlayersId IS NULL
3820 GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit
3821 ORDER BY h.startTime"""
3823 self
.query
['getRingProfitAllHandsPlayerIdSiteInDollars'] = """
3824 SELECT hp.handId, hp.totalProfit, hp.sawShowdown
3825 FROM HandsPlayers hp
3826 INNER JOIN Players pl ON (pl.id = hp.playerId)
3827 INNER JOIN Hands h ON (h.id = hp.handId)
3828 INNER JOIN Gametypes gt ON (gt.id = h.gametypeId)
3829 WHERE pl.id in <player_test>
3830 AND pl.siteId in <site_test>
3831 AND h.startTime > '<startdate_test>'
3832 AND h.startTime < '<enddate_test>'
3835 AND hp.tourneysPlayersId IS NULL
3836 GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit
3837 ORDER BY h.startTime"""
3841 ####################################
3842 # Tourney Results query
3843 ####################################
3844 self
.query
['tourneyResults'] = """
3845 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
3846 FROM TourneysPlayers tp
3847 INNER JOIN Players pl ON (pl.id = tp.playerId)
3848 INNER JOIN Tourneys t ON (t.id = tp.tourneyId)
3849 INNER JOIN TourneyTypes tt ON (tt.id = t.tourneyTypeId)
3850 WHERE pl.id in <player_test>
3851 AND pl.siteId in <site_test>
3852 AND t.startTime > '<startdate_test>'
3853 AND t.startTime < '<enddate_test>'
3854 GROUP BY t.startTime, tp.tourneyId, tp.winningsCurrency,
3855 tp.winnings, tp.koCount,
3856 tp.rebuyCount, tp.addOnCount,
3858 ORDER BY t.startTime"""
3860 #AND gt.type = 'ring'
3864 ####################################
3865 # Session stats query
3866 ####################################
3867 if db_server
== 'mysql':
3868 self
.query
['sessionStats'] = """
3869 SELECT UNIX_TIMESTAMP(h.startTime) as time, hp.handId, hp.startCash, hp.winnings, hp.totalProfit
3870 FROM HandsPlayers hp
3871 INNER JOIN Hands h on (h.id = hp.handId)
3872 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
3873 INNER JOIN Sites s on (s.Id = gt.siteId)
3874 INNER JOIN Players p on (p.Id = hp.playerId)
3875 WHERE hp.playerId in <player_test>
3876 AND date_format(h.startTime, '%Y-%m-%d') <datestest>
3877 AND gt.type LIKE 'ring'
3879 elif db_server
== 'postgresql':
3880 self
.query
['sessionStats'] = """
3881 SELECT EXTRACT(epoch from h.startTime) as time, hp.handId, hp.startCash, hp.winnings, hp.totalProfit
3882 FROM HandsPlayers hp
3883 INNER JOIN Hands h on (h.id = hp.handId)
3884 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
3885 INNER JOIN Sites s on (s.Id = gt.siteId)
3886 INNER JOIN Players p on (p.Id = hp.playerId)
3887 WHERE hp.playerId in <player_test>
3888 AND h.startTime <datestest>
3889 AND gt.type LIKE 'ring'
3891 elif db_server
== 'sqlite':
3892 self
.query
['sessionStats'] = """
3893 SELECT STRFTIME('<ampersand_s>', h.startTime) as time, hp.handId, hp.startCash, hp.winnings, hp.totalProfit
3894 FROM HandsPlayers hp
3895 INNER JOIN Hands h on (h.id = hp.handId)
3896 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
3897 INNER JOIN Sites s on (s.Id = gt.siteId)
3898 INNER JOIN Players p on (p.Id = hp.playerId)
3899 WHERE hp.playerId in <player_test>
3900 AND h.startTime <datestest>
3901 AND gt.type is 'ring'
3905 ####################################
3906 # Queries to rebuild/modify hudcache
3907 ####################################
3909 self
.query
['clearHudCache'] = """DELETE FROM HudCache"""
3911 if db_server
== 'mysql':
3912 self
.query
['rebuildHudCache'] = """
3913 INSERT INTO HudCache
3918 <tourney_insert_clause>
3934 ,street0_FoldTo3BChance
3935 ,street0_FoldTo3BDone
3936 ,street0_FoldTo4BChance
3937 ,street0_FoldTo4BDone
3938 ,street0_SqueezeChance
3939 ,street0_SqueezeDone
3957 ,foldToOtherRaisedStreet0
3958 ,foldToOtherRaisedStreet1
3959 ,foldToOtherRaisedStreet2
3960 ,foldToOtherRaisedStreet3
3961 ,foldToOtherRaisedStreet4
3964 ,foldBbToStealChance
3966 ,foldSbToStealChance
3976 ,foldToStreet1CBChance
3977 ,foldToStreet1CBDone
3978 ,foldToStreet2CBChance
3979 ,foldToStreet2CBDone
3980 ,foldToStreet3CBChance
3981 ,foldToStreet3CBDone
3982 ,foldToStreet4CBChance
3983 ,foldToStreet4CBDone
3985 ,street1CheckCallRaiseChance
3986 ,street1CheckCallRaiseDone
3987 ,street2CheckCallRaiseChance
3988 ,street2CheckCallRaiseDone
3989 ,street3CheckCallRaiseChance
3990 ,street3CheckCallRaiseDone
3991 ,street4CheckCallRaiseChance
3992 ,street4CheckCallRaiseDone
4012 ,case when hp.position = 'B' then 'B'
4013 when hp.position = 'S' then 'S'
4014 when hp.position = '0' then 'D'
4015 when hp.position = '1' then 'C'
4016 when hp.position = '2' then 'M'
4017 when hp.position = '3' then 'M'
4018 when hp.position = '4' then 'M'
4019 when hp.position = '5' then 'E'
4020 when hp.position = '6' then 'E'
4021 when hp.position = '7' then 'E'
4022 when hp.position = '8' then 'E'
4023 when hp.position = '9' then 'E'
4026 <tourney_select_clause>
4027 ,date_format(h.startTime, 'd%y%m%d')
4029 ,sum(wonWhenSeenStreet1)
4030 ,sum(wonWhenSeenStreet2)
4031 ,sum(wonWhenSeenStreet3)
4032 ,sum(wonWhenSeenStreet4)
4036 ,sum(street0_3BChance)
4037 ,sum(street0_3BDone)
4038 ,sum(street0_4BChance)
4039 ,sum(street0_4BDone)
4040 ,sum(street0_C4BChance)
4041 ,sum(street0_C4BDone)
4042 ,sum(street0_FoldTo3BChance)
4043 ,sum(street0_FoldTo3BDone)
4044 ,sum(street0_FoldTo4BChance)
4045 ,sum(street0_FoldTo4BDone)
4046 ,sum(street0_SqueezeChance)
4047 ,sum(street0_SqueezeDone)
4048 ,sum(raiseToStealChance)
4049 ,sum(raiseToStealDone)
4060 ,sum(otherRaisedStreet0)
4061 ,sum(otherRaisedStreet1)
4062 ,sum(otherRaisedStreet2)
4063 ,sum(otherRaisedStreet3)
4064 ,sum(otherRaisedStreet4)
4065 ,sum(foldToOtherRaisedStreet0)
4066 ,sum(foldToOtherRaisedStreet1)
4067 ,sum(foldToOtherRaisedStreet2)
4068 ,sum(foldToOtherRaisedStreet3)
4069 ,sum(foldToOtherRaisedStreet4)
4070 ,sum(raiseFirstInChance)
4072 ,sum(foldBbToStealChance)
4073 ,sum(foldedBbToSteal)
4074 ,sum(foldSbToStealChance)
4075 ,sum(foldedSbToSteal)
4076 ,sum(street1CBChance)
4078 ,sum(street2CBChance)
4080 ,sum(street3CBChance)
4082 ,sum(street4CBChance)
4084 ,sum(foldToStreet1CBChance)
4085 ,sum(foldToStreet1CBDone)
4086 ,sum(foldToStreet2CBChance)
4087 ,sum(foldToStreet2CBDone)
4088 ,sum(foldToStreet3CBChance)
4089 ,sum(foldToStreet3CBDone)
4090 ,sum(foldToStreet4CBChance)
4091 ,sum(foldToStreet4CBDone)
4093 ,sum(street1CheckCallRaiseChance)
4094 ,sum(street1CheckCallRaiseDone)
4095 ,sum(street2CheckCallRaiseChance)
4096 ,sum(street2CheckCallRaiseDone)
4097 ,sum(street3CheckCallRaiseChance)
4098 ,sum(street3CheckCallRaiseDone)
4099 ,sum(street4CheckCallRaiseChance)
4100 ,sum(street4CheckCallRaiseDone)
4111 ,sum(hp.street0Raises)
4112 ,sum(hp.street1Raises)
4113 ,sum(hp.street2Raises)
4114 ,sum(hp.street3Raises)
4115 ,sum(hp.street4Raises)
4116 FROM HandsPlayers hp
4117 INNER JOIN Hands h ON (h.id = hp.handId)
4118 <tourney_join_clause>
4120 GROUP BY h.gametypeId
4124 <tourney_group_clause>
4125 ,date_format(h.startTime, 'd%y%m%d')
4127 elif db_server
== 'postgresql':
4128 self
.query
['rebuildHudCache'] = """
4129 INSERT INTO HudCache
4134 <tourney_insert_clause>
4150 ,street0_FoldTo3BChance
4151 ,street0_FoldTo3BDone
4152 ,street0_FoldTo4BChance
4153 ,street0_FoldTo4BDone
4154 ,street0_SqueezeChance
4155 ,street0_SqueezeDone
4173 ,foldToOtherRaisedStreet0
4174 ,foldToOtherRaisedStreet1
4175 ,foldToOtherRaisedStreet2
4176 ,foldToOtherRaisedStreet3
4177 ,foldToOtherRaisedStreet4
4180 ,foldBbToStealChance
4182 ,foldSbToStealChance
4192 ,foldToStreet1CBChance
4193 ,foldToStreet1CBDone
4194 ,foldToStreet2CBChance
4195 ,foldToStreet2CBDone
4196 ,foldToStreet3CBChance
4197 ,foldToStreet3CBDone
4198 ,foldToStreet4CBChance
4199 ,foldToStreet4CBDone
4201 ,street1CheckCallRaiseChance
4202 ,street1CheckCallRaiseDone
4203 ,street2CheckCallRaiseChance
4204 ,street2CheckCallRaiseDone
4205 ,street3CheckCallRaiseChance
4206 ,street3CheckCallRaiseDone
4207 ,street4CheckCallRaiseChance
4208 ,street4CheckCallRaiseDone
4228 ,case when hp.position = 'B' then 'B'
4229 when hp.position = 'S' then 'S'
4230 when hp.position = '0' then 'D'
4231 when hp.position = '1' then 'C'
4232 when hp.position = '2' then 'M'
4233 when hp.position = '3' then 'M'
4234 when hp.position = '4' then 'M'
4235 when hp.position = '5' then 'E'
4236 when hp.position = '6' then 'E'
4237 when hp.position = '7' then 'E'
4238 when hp.position = '8' then 'E'
4239 when hp.position = '9' then 'E'
4242 <tourney_select_clause>
4243 ,'d' || to_char(h.startTime, 'YYMMDD')
4245 ,sum(wonWhenSeenStreet1)
4246 ,sum(wonWhenSeenStreet2)
4247 ,sum(wonWhenSeenStreet3)
4248 ,sum(wonWhenSeenStreet4)
4250 ,sum(CAST(street0VPI as integer))
4251 ,sum(CAST(street0Aggr as integer))
4252 ,sum(CAST(street0_3BChance as integer))
4253 ,sum(CAST(street0_3BDone as integer))
4254 ,sum(CAST(street0_4BChance as integer))
4255 ,sum(CAST(street0_4BDone as integer))
4256 ,sum(CAST(street0_C4BChance as integer))
4257 ,sum(CAST(street0_C4BDone as integer))
4258 ,sum(CAST(street0_FoldTo3BChance as integer))
4259 ,sum(CAST(street0_FoldTo3BDone as integer))
4260 ,sum(CAST(street0_FoldTo4BChance as integer))
4261 ,sum(CAST(street0_FoldTo4BDone as integer))
4262 ,sum(CAST(street0_SqueezeChance as integer))
4263 ,sum(CAST(street0_SqueezeDone as integer))
4264 ,sum(CAST(raiseToStealChance as integer))
4265 ,sum(CAST(raiseToStealDone as integer))
4266 ,sum(CAST(success_Steal as integer))
4267 ,sum(CAST(street1Seen as integer))
4268 ,sum(CAST(street2Seen as integer))
4269 ,sum(CAST(street3Seen as integer))
4270 ,sum(CAST(street4Seen as integer))
4271 ,sum(CAST(sawShowdown as integer))
4272 ,sum(CAST(street1Aggr as integer))
4273 ,sum(CAST(street2Aggr as integer))
4274 ,sum(CAST(street3Aggr as integer))
4275 ,sum(CAST(street4Aggr as integer))
4276 ,sum(CAST(otherRaisedStreet0 as integer))
4277 ,sum(CAST(otherRaisedStreet1 as integer))
4278 ,sum(CAST(otherRaisedStreet2 as integer))
4279 ,sum(CAST(otherRaisedStreet3 as integer))
4280 ,sum(CAST(otherRaisedStreet4 as integer))
4281 ,sum(CAST(foldToOtherRaisedStreet0 as integer))
4282 ,sum(CAST(foldToOtherRaisedStreet1 as integer))
4283 ,sum(CAST(foldToOtherRaisedStreet2 as integer))
4284 ,sum(CAST(foldToOtherRaisedStreet3 as integer))
4285 ,sum(CAST(foldToOtherRaisedStreet4 as integer))
4286 ,sum(CAST(raiseFirstInChance as integer))
4287 ,sum(CAST(raisedFirstIn as integer))
4288 ,sum(CAST(foldBbToStealChance as integer))
4289 ,sum(CAST(foldedBbToSteal as integer))
4290 ,sum(CAST(foldSbToStealChance as integer))
4291 ,sum(CAST(foldedSbToSteal as integer))
4292 ,sum(CAST(street1CBChance as integer))
4293 ,sum(CAST(street1CBDone as integer))
4294 ,sum(CAST(street2CBChance as integer))
4295 ,sum(CAST(street2CBDone as integer))
4296 ,sum(CAST(street3CBChance as integer))
4297 ,sum(CAST(street3CBDone as integer))
4298 ,sum(CAST(street4CBChance as integer))
4299 ,sum(CAST(street4CBDone as integer))
4300 ,sum(CAST(foldToStreet1CBChance as integer))
4301 ,sum(CAST(foldToStreet1CBDone as integer))
4302 ,sum(CAST(foldToStreet2CBChance as integer))
4303 ,sum(CAST(foldToStreet2CBDone as integer))
4304 ,sum(CAST(foldToStreet3CBChance as integer))
4305 ,sum(CAST(foldToStreet3CBDone as integer))
4306 ,sum(CAST(foldToStreet4CBChance as integer))
4307 ,sum(CAST(foldToStreet4CBDone as integer))
4308 ,sum(CAST(totalProfit as integer))
4309 ,sum(CAST(street1CheckCallRaiseChance as integer))
4310 ,sum(CAST(street1CheckCallRaiseDone as integer))
4311 ,sum(CAST(street2CheckCallRaiseChance as integer))
4312 ,sum(CAST(street2CheckCallRaiseDone as integer))
4313 ,sum(CAST(street3CheckCallRaiseChance as integer))
4314 ,sum(CAST(street3CheckCallRaiseDone as integer))
4315 ,sum(CAST(street4CheckCallRaiseChance as integer))
4316 ,sum(CAST(street4CheckCallRaiseDone as integer))
4317 ,sum(CAST(street0Calls as integer))
4318 ,sum(CAST(street1Calls as integer))
4319 ,sum(CAST(street2Calls as integer))
4320 ,sum(CAST(street3Calls as integer))
4321 ,sum(CAST(street4Calls as integer))
4322 ,sum(CAST(street0Bets as integer))
4323 ,sum(CAST(street1Bets as integer))
4324 ,sum(CAST(street2Bets as integer))
4325 ,sum(CAST(street3Bets as integer))
4326 ,sum(CAST(street4Bets as integer))
4327 ,sum(CAST(hp.street0Raises as integer))
4328 ,sum(CAST(hp.street1Raises as integer))
4329 ,sum(CAST(hp.street2Raises as integer))
4330 ,sum(CAST(hp.street3Raises as integer))
4331 ,sum(CAST(hp.street4Raises as integer))
4332 FROM HandsPlayers hp
4333 INNER JOIN Hands h ON (h.id = hp.handId)
4334 <tourney_join_clause>
4336 GROUP BY h.gametypeId
4340 <tourney_group_clause>
4341 ,to_char(h.startTime, 'YYMMDD')
4343 else: # assume sqlite
4344 self
.query
['rebuildHudCache'] = """
4345 INSERT INTO HudCache
4350 <tourney_insert_clause>
4366 ,street0_FoldTo3BChance
4367 ,street0_FoldTo3BDone
4368 ,street0_FoldTo4BChance
4369 ,street0_FoldTo4BDone
4370 ,street0_SqueezeChance
4371 ,street0_SqueezeDone
4389 ,foldToOtherRaisedStreet0
4390 ,foldToOtherRaisedStreet1
4391 ,foldToOtherRaisedStreet2
4392 ,foldToOtherRaisedStreet3
4393 ,foldToOtherRaisedStreet4
4396 ,foldBbToStealChance
4398 ,foldSbToStealChance
4408 ,foldToStreet1CBChance
4409 ,foldToStreet1CBDone
4410 ,foldToStreet2CBChance
4411 ,foldToStreet2CBDone
4412 ,foldToStreet3CBChance
4413 ,foldToStreet3CBDone
4414 ,foldToStreet4CBChance
4415 ,foldToStreet4CBDone
4417 ,street1CheckCallRaiseChance
4418 ,street1CheckCallRaiseDone
4419 ,street2CheckCallRaiseChance
4420 ,street2CheckCallRaiseDone
4421 ,street3CheckCallRaiseChance
4422 ,street3CheckCallRaiseDone
4423 ,street4CheckCallRaiseChance
4424 ,street4CheckCallRaiseDone
4444 ,case when hp.position = 'B' then 'B'
4445 when hp.position = 'S' then 'S'
4446 when hp.position = '0' then 'D'
4447 when hp.position = '1' then 'C'
4448 when hp.position = '2' then 'M'
4449 when hp.position = '3' then 'M'
4450 when hp.position = '4' then 'M'
4451 when hp.position = '5' then 'E'
4452 when hp.position = '6' then 'E'
4453 when hp.position = '7' then 'E'
4454 when hp.position = '8' then 'E'
4455 when hp.position = '9' then 'E'
4458 <tourney_select_clause>
4459 ,'d' || substr(strftime('%Y%m%d', h.startTime),3,7)
4461 ,sum(wonWhenSeenStreet1)
4462 ,sum(wonWhenSeenStreet2)
4463 ,sum(wonWhenSeenStreet3)
4464 ,sum(wonWhenSeenStreet4)
4466 ,sum(CAST(street0VPI as integer))
4467 ,sum(CAST(street0Aggr as integer))
4468 ,sum(CAST(street0_3BChance as integer))
4469 ,sum(CAST(street0_3BDone as integer))
4470 ,sum(CAST(street0_4BChance as integer))
4471 ,sum(CAST(street0_4BDone as integer))
4472 ,sum(CAST(street0_C4BChance as integer))
4473 ,sum(CAST(street0_C4BDone as integer))
4474 ,sum(CAST(street0_FoldTo3BChance as integer))
4475 ,sum(CAST(street0_FoldTo3BDone as integer))
4476 ,sum(CAST(street0_FoldTo4BChance as integer))
4477 ,sum(CAST(street0_FoldTo4BDone as integer))
4478 ,sum(CAST(street0_SqueezeChance as integer))
4479 ,sum(CAST(street0_SqueezeDone as integer))
4480 ,sum(CAST(raiseToStealChance as integer))
4481 ,sum(CAST(raiseToStealDone as integer))
4482 ,sum(CAST(success_Steal as integer))
4483 ,sum(CAST(street1Seen as integer))
4484 ,sum(CAST(street2Seen as integer))
4485 ,sum(CAST(street3Seen as integer))
4486 ,sum(CAST(street4Seen as integer))
4487 ,sum(CAST(sawShowdown as integer))
4488 ,sum(CAST(street1Aggr as integer))
4489 ,sum(CAST(street2Aggr as integer))
4490 ,sum(CAST(street3Aggr as integer))
4491 ,sum(CAST(street4Aggr as integer))
4492 ,sum(CAST(otherRaisedStreet0 as integer))
4493 ,sum(CAST(otherRaisedStreet1 as integer))
4494 ,sum(CAST(otherRaisedStreet2 as integer))
4495 ,sum(CAST(otherRaisedStreet3 as integer))
4496 ,sum(CAST(otherRaisedStreet4 as integer))
4497 ,sum(CAST(foldToOtherRaisedStreet0 as integer))
4498 ,sum(CAST(foldToOtherRaisedStreet1 as integer))
4499 ,sum(CAST(foldToOtherRaisedStreet2 as integer))
4500 ,sum(CAST(foldToOtherRaisedStreet3 as integer))
4501 ,sum(CAST(foldToOtherRaisedStreet4 as integer))
4502 ,sum(CAST(raiseFirstInChance as integer))
4503 ,sum(CAST(raisedFirstIn as integer))
4504 ,sum(CAST(foldBbToStealChance as integer))
4505 ,sum(CAST(foldedBbToSteal as integer))
4506 ,sum(CAST(foldSbToStealChance as integer))
4507 ,sum(CAST(foldedSbToSteal as integer))
4508 ,sum(CAST(street1CBChance as integer))
4509 ,sum(CAST(street1CBDone as integer))
4510 ,sum(CAST(street2CBChance as integer))
4511 ,sum(CAST(street2CBDone as integer))
4512 ,sum(CAST(street3CBChance as integer))
4513 ,sum(CAST(street3CBDone as integer))
4514 ,sum(CAST(street4CBChance as integer))
4515 ,sum(CAST(street4CBDone as integer))
4516 ,sum(CAST(foldToStreet1CBChance as integer))
4517 ,sum(CAST(foldToStreet1CBDone as integer))
4518 ,sum(CAST(foldToStreet2CBChance as integer))
4519 ,sum(CAST(foldToStreet2CBDone as integer))
4520 ,sum(CAST(foldToStreet3CBChance as integer))
4521 ,sum(CAST(foldToStreet3CBDone as integer))
4522 ,sum(CAST(foldToStreet4CBChance as integer))
4523 ,sum(CAST(foldToStreet4CBDone as integer))
4524 ,sum(CAST(totalProfit as integer))
4525 ,sum(CAST(street1CheckCallRaiseChance as integer))
4526 ,sum(CAST(street1CheckCallRaiseDone as integer))
4527 ,sum(CAST(street2CheckCallRaiseChance as integer))
4528 ,sum(CAST(street2CheckCallRaiseDone as integer))
4529 ,sum(CAST(street3CheckCallRaiseChance as integer))
4530 ,sum(CAST(street3CheckCallRaiseDone as integer))
4531 ,sum(CAST(street4CheckCallRaiseChance as integer))
4532 ,sum(CAST(street4CheckCallRaiseDone as integer))
4533 ,sum(CAST(street0Calls as integer))
4534 ,sum(CAST(street1Calls as integer))
4535 ,sum(CAST(street2Calls as integer))
4536 ,sum(CAST(street3Calls as integer))
4537 ,sum(CAST(street4Calls as integer))
4538 ,sum(CAST(street0Bets as integer))
4539 ,sum(CAST(street1Bets as integer))
4540 ,sum(CAST(street2Bets as integer))
4541 ,sum(CAST(street3Bets as integer))
4542 ,sum(CAST(street4Bets as integer))
4543 ,sum(CAST(hp.street0Raises as integer))
4544 ,sum(CAST(hp.street1Raises as integer))
4545 ,sum(CAST(hp.street2Raises as integer))
4546 ,sum(CAST(hp.street3Raises as integer))
4547 ,sum(CAST(hp.street4Raises as integer))
4548 FROM HandsPlayers hp
4549 INNER JOIN Hands h ON (h.id = hp.handId)
4550 <tourney_join_clause>
4552 GROUP BY h.gametypeId
4556 <tourney_group_clause>
4557 ,'d' || substr(strftime('%Y%m%d', h.startTime),3,7)
4560 self
.query
['insert_hudcache'] = """
4561 insert into HudCache (
4577 street0_FoldTo3BChance,
4578 street0_FoldTo3BDone,
4579 street0_FoldTo4BChance,
4580 street0_FoldTo4BDone,
4581 street0_SqueezeChance,
4582 street0_SqueezeDone,
4600 foldToOtherRaisedStreet0,
4601 foldToOtherRaisedStreet1,
4602 foldToOtherRaisedStreet2,
4603 foldToOtherRaisedStreet3,
4604 foldToOtherRaisedStreet4,
4612 foldBbToStealChance,
4614 foldSbToStealChance,
4624 foldToStreet1CBChance,
4625 foldToStreet1CBDone,
4626 foldToStreet2CBChance,
4627 foldToStreet2CBDone,
4628 foldToStreet3CBChance,
4629 foldToStreet3CBDone,
4630 foldToStreet4CBChance,
4631 foldToStreet4CBDone,
4633 street1CheckCallRaiseChance,
4634 street1CheckCallRaiseDone,
4635 street2CheckCallRaiseChance,
4636 street2CheckCallRaiseDone,
4637 street3CheckCallRaiseChance,
4638 street3CheckCallRaiseDone,
4639 street4CheckCallRaiseChance,
4640 street4CheckCallRaiseDone,
4656 values (%s, %s, %s, %s, %s,
4676 self
.query
['update_hudcache'] = """
4679 street0VPI=street0VPI+%s,
4680 street0Aggr=street0Aggr+%s,
4681 street0_3BChance=street0_3BChance+%s,
4682 street0_3BDone=street0_3BDone+%s,
4683 street0_4BChance=street0_4BChance+%s,
4684 street0_4BDone=street0_4BDone+%s,
4685 street0_C4BChance=street0_C4BChance+%s,
4686 street0_C4BDone=street0_C4BDone+%s,
4687 street0_FoldTo3BChance=street0_FoldTo3BChance+%s,
4688 street0_FoldTo3BDone=street0_FoldTo3BDone+%s,
4689 street0_FoldTo4BChance=street0_FoldTo4BChance+%s,
4690 street0_FoldTo4BDone=street0_FoldTo4BDone+%s,
4691 street0_SqueezeChance=street0_SqueezeChance+%s,
4692 street0_SqueezeDone=street0_SqueezeDone+%s,
4693 raiseToStealChance=raiseToStealChance+%s,
4694 raiseToStealDone=raiseToStealDone+%s,
4695 success_Steal=success_Steal+%s,
4696 street1Seen=street1Seen+%s,
4697 street2Seen=street2Seen+%s,
4698 street3Seen=street3Seen+%s,
4699 street4Seen=street4Seen+%s,
4700 sawShowdown=sawShowdown+%s,
4701 street1Aggr=street1Aggr+%s,
4702 street2Aggr=street2Aggr+%s,
4703 street3Aggr=street3Aggr+%s,
4704 street4Aggr=street4Aggr+%s,
4705 otherRaisedStreet0=otherRaisedStreet0+%s,
4706 otherRaisedStreet1=otherRaisedStreet1+%s,
4707 otherRaisedStreet2=otherRaisedStreet2+%s,
4708 otherRaisedStreet3=otherRaisedStreet3+%s,
4709 otherRaisedStreet4=otherRaisedStreet4+%s,
4710 foldToOtherRaisedStreet0=foldToOtherRaisedStreet0+%s,
4711 foldToOtherRaisedStreet1=foldToOtherRaisedStreet1+%s,
4712 foldToOtherRaisedStreet2=foldToOtherRaisedStreet2+%s,
4713 foldToOtherRaisedStreet3=foldToOtherRaisedStreet3+%s,
4714 foldToOtherRaisedStreet4=foldToOtherRaisedStreet4+%s,
4715 wonWhenSeenStreet1=wonWhenSeenStreet1+%s,
4716 wonWhenSeenStreet2=wonWhenSeenStreet2+%s,
4717 wonWhenSeenStreet3=wonWhenSeenStreet3+%s,
4718 wonWhenSeenStreet4=wonWhenSeenStreet4+%s,
4720 raiseFirstInChance=raiseFirstInChance+%s,
4721 raisedFirstIn=raisedFirstIn+%s,
4722 foldBbToStealChance=foldBbToStealChance+%s,
4723 foldedBbToSteal=foldedBbToSteal+%s,
4724 foldSbToStealChance=foldSbToStealChance+%s,
4725 foldedSbToSteal=foldedSbToSteal+%s,
4726 street1CBChance=street1CBChance+%s,
4727 street1CBDone=street1CBDone+%s,
4728 street2CBChance=street2CBChance+%s,
4729 street2CBDone=street2CBDone+%s,
4730 street3CBChance=street3CBChance+%s,
4731 street3CBDone=street3CBDone+%s,
4732 street4CBChance=street4CBChance+%s,
4733 street4CBDone=street4CBDone+%s,
4734 foldToStreet1CBChance=foldToStreet1CBChance+%s,
4735 foldToStreet1CBDone=foldToStreet1CBDone+%s,
4736 foldToStreet2CBChance=foldToStreet2CBChance+%s,
4737 foldToStreet2CBDone=foldToStreet2CBDone+%s,
4738 foldToStreet3CBChance=foldToStreet3CBChance+%s,
4739 foldToStreet3CBDone=foldToStreet3CBDone+%s,
4740 foldToStreet4CBChance=foldToStreet4CBChance+%s,
4741 foldToStreet4CBDone=foldToStreet4CBDone+%s,
4742 totalProfit=totalProfit+%s,
4743 street1CheckCallRaiseChance=street1CheckCallRaiseChance+%s,
4744 street1CheckCallRaiseDone=street1CheckCallRaiseDone+%s,
4745 street2CheckCallRaiseChance=street2CheckCallRaiseChance+%s,
4746 street2CheckCallRaiseDone=street2CheckCallRaiseDone+%s,
4747 street3CheckCallRaiseChance=street3CheckCallRaiseChance+%s,
4748 street3CheckCallRaiseDone=street3CheckCallRaiseDone+%s,
4749 street4CheckCallRaiseChance=street4CheckCallRaiseChance+%s,
4750 street4CheckCallRaiseDone=street4CheckCallRaiseDone+%s,
4751 street0Calls=street0Calls+%s,
4752 street1Calls=street1Calls+%s,
4753 street2Calls=street2Calls+%s,
4754 street3Calls=street3Calls+%s,
4755 street4Calls=street4Calls+%s,
4756 street0Bets=street0Bets+%s,
4757 street1Bets=street1Bets+%s,
4758 street2Bets=street2Bets+%s,
4759 street3Bets=street3Bets+%s,
4760 street4Bets=street4Bets+%s,
4761 street0Raises=street0Raises+%s,
4762 street1Raises=street1Raises+%s,
4763 street2Raises=street2Raises+%s,
4764 street3Raises=street3Raises+%s,
4765 street4Raises=street4Raises+%s
4766 WHERE gametypeId+0=%s
4770 AND (case when tourneyTypeId is NULL then 1 else
4771 (case when tourneyTypeId+0=%s then 1 else 0 end) end)=1
4774 self
.query
['get_hero_hudcache_start'] = """select min(hc.styleKey)
4776 where hc.playerId in <playerid_list>
4777 and hc.styleKey like 'd%'"""
4779 ####################################
4780 # Queries to rebuild/modify sessionscache
4781 ####################################
4783 self
.query
['clearSessionsCache'] = """DELETE FROM SessionsCache"""
4785 self
.query
['rebuildSessionsCache'] = """
4786 SELECT Hands.id as id,
4787 Hands.startTime as startTime,
4788 HandsPlayers.playerId as playerId,
4789 Hands.gametypeId as gametypeId,
4790 Gametypes.type as game,
4791 HandsPlayers.totalProfit as totalProfit,
4792 Tourneys.tourneyTypeId as tourneyTypeId,
4793 HandsPlayers.street0VPI as street0VPI,
4794 HandsPlayers.street1Seen as street1Seen
4795 FROM Gametypes, HandsPlayers, Hands
4796 LEFT JOIN Tourneys ON Hands.tourneyId = Tourneys.tourneyTypeId
4797 WHERE HandsPlayers.handId = Hands.id
4798 AND Hands.gametypeId = Gametypes.id
4799 AND (case when HandsPlayers.playerId = <where_clause> then 1 else 0 end) = 1
4800 ORDER BY Hands.startTime ASC"""
4802 self
.query
['rebuildSessionsCacheSum'] = """
4803 SELECT Tourneys.id as id,
4804 Tourneys.startTime as startTime,
4805 TourneysPlayers.playerId,
4806 TourneyTypes.id as tourneyTypeId,
4807 TourneysPlayers.winnings as winnings,
4808 TourneysPlayers.winningsCurrency as winningsCurrency,
4809 TourneyTypes.currency as buyinCurrency,
4810 TourneyTypes.buyIn as buyIn,
4811 TourneyTypes.fee as fee,
4812 case when TourneyTypes.rebuy then TourneyTypes.rebuyCost else 0 end as rebuyCost,
4813 case when TourneyTypes.rebuy then TourneyTypes.rebuyFee else 0 end as rebuyFee,
4814 case when TourneyTypes.addOn then TourneyTypes.addOnCost else 0 end as addOnCost,
4815 case when TourneyTypes.addOn then TourneyTypes.addOnFee else 0 end as addOnFee,
4816 case when TourneyTypes.knockout then TourneyTypes.koBounty else 0 end as koBounty
4817 FROM Tourneys, TourneyTypes, TourneysPlayers
4818 WHERE Tourneys.tourneyTypeId = TourneyTypes.id
4819 AND Tourneys.id = TourneysPlayers.tourneyId
4820 AND (case when TourneysPlayers.playerId = <where_clause> then 1 else 0 end) = 1
4821 ORDER BY Tourneys.startTime ASC"""
4823 self
.query
['select_prepSC'] = """
4824 SELECT sessionId as id,
4827 count(sessionId) as count
4829 WHERE sessionEnd>=%s
4830 AND sessionStart<=%s
4831 GROUP BY sessionId, sessionStart, sessionEnd"""
4833 self
.query
['update_prepSC'] = """
4834 UPDATE SessionsCache SET
4837 WHERE sessionId=%s"""
4839 self
.query
['update_SC'] = """
4840 UPDATE SessionsCache SET
4846 tourneys=tourneys+%s,
4847 totalProfit=totalProfit+%s
4850 self
.query
['select_SC'] = """
4871 AND (case when gametypeId is NULL then 1 else
4872 (case when gametypeId=%s then 1 else 0 end) end)=1
4873 AND (case when tourneyTypeId is NULL then 1 else
4874 (case when tourneyTypeId=%s then 1 else 0 end) end)=1
4878 self
.query
['insert_SC'] = """
4879 insert into SessionsCache (
4894 values (%s, %s, %s, %s, %s, %s, %s,
4895 %s, %s, %s, %s, %s, %s, %s)"""
4897 self
.query
['update_Hands_gsid'] = """
4900 WHERE gameSessionId=%s"""
4902 self
.query
['update_Hands_sid'] = """
4905 WHERE sessionId=%s"""
4907 self
.query
['update_SC_sid'] = """
4908 UPDATE SessionsCache SET
4912 WHERE sessionId=%s"""
4914 self
.query
['delete_SC'] = """
4915 DELETE FROM SessionsCache
4918 ####################################
4919 # Database management queries
4920 ####################################
4922 if db_server
== 'mysql':
4923 self
.query
['analyze'] = """
4924 analyze table Autorates, GameTypes, Hands, HandsPlayers, HudCache, Players
4925 , Settings, Sites, Tourneys, TourneysPlayers, TourneyTypes
4927 elif db_server
== 'postgresql':
4928 self
.query
['analyze'] = "analyze"
4929 elif db_server
== 'sqlite':
4930 self
.query
['analyze'] = "analyze"
4932 if db_server
== 'mysql':
4933 self
.query
['selectLock'] = """
4937 LOCK IN SHARE MODE"""
4939 if db_server
== 'mysql':
4940 self
.query
['switchLock'] = """
4941 UPDATE InsertLock SET
4945 if db_server
== 'mysql':
4946 self
.query
['missedLock'] = """
4947 UPDATE InsertLock SET
4951 if db_server
== 'mysql':
4952 self
.query
['lockForInsert'] = """
4953 lock tables Hands write, HandsPlayers write, HandsActions write, Players write
4954 , HudCache write, GameTypes write, Sites write, Tourneys write
4955 , TourneysPlayers write, TourneyTypes write, Autorates write
4957 elif db_server
== 'postgresql':
4958 self
.query
['lockForInsert'] = ""
4959 elif db_server
== 'sqlite':
4960 self
.query
['lockForInsert'] = ""
4962 if db_server
== 'mysql':
4963 self
.query
['vacuum'] = """optimize table Hands, HandsPlayers, HandsActions, Players
4964 , HudCache, GameTypes, Sites, Tourneys
4965 , TourneysPlayers, TourneyTypes, Autorates
4967 elif db_server
== 'postgresql':
4968 self
.query
['vacuum'] = """ vacuum """
4969 elif db_server
== 'sqlite':
4970 self
.query
['vacuum'] = """ vacuum """
4972 self
.query
['getGametypeFL'] = """SELECT id
4982 """ #TODO: seems odd to have limitType variable in this query
4984 self
.query
['getGametypeNL'] = """SELECT id
4996 """ #TODO: seems odd to have limitType variable in this query
4998 self
.query
['insertGameTypes'] = """INSERT INTO Gametypes
4999 (siteId, currency, type, base, category, limitType
5000 ,hiLo, mix, smallBlind, bigBlind, smallBet, bigBet, maxSeats, ante)
5001 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
5003 self
.query
['isAlreadyInDB'] = """SELECT id FROM Hands
5004 WHERE gametypeId=%s AND siteHandNo=%s
5007 self
.query
['getTourneyTypeIdByTourneyNo'] = """SELECT tt.id,
5017 FROM TourneyTypes tt
5018 INNER JOIN Tourneys t ON (t.tourneyTypeId = tt.id)
5019 WHERE t.siteTourneyNo=%s AND tt.siteId=%s
5022 self
.query
['getTourneyTypeId'] = """SELECT id
5039 self
.query
['insertTourneyType'] = """INSERT INTO TourneyTypes
5040 (siteId, currency, buyin, fee, category, limitType, maxSeats, buyInChips, knockout, koBounty, rebuy,
5041 addOn ,speed, shootout, matrix, added, addedCurrency)
5042 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
5045 self
.query
['getTourneyByTourneyNo'] = """SELECT t.*
5047 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5048 WHERE tt.siteId=%s AND t.siteTourneyNo=%s
5051 self
.query
['getTourneyInfo'] = """SELECT tt.*, t.*
5053 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5054 INNER JOIN Sites s ON (tt.siteId = s.id)
5055 WHERE s.name=%s AND t.siteTourneyNo=%s
5058 self
.query
['getSiteTourneyNos'] = """SELECT t.siteTourneyNo
5060 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5061 INNER JOIN Sites s ON (tt.siteId = s.id)
5065 self
.query
['getTourneyPlayerInfo'] = """SELECT tp.*
5067 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
5068 INNER JOIN Sites s ON (tt.siteId = s.id)
5069 INNER JOIN TourneysPlayers tp ON (tp.tourneyId = t.id)
5070 INNER JOIN Players p ON (p.id = tp.playerId)
5071 WHERE s.name=%s AND t.siteTourneyNo=%s AND p.name=%s
5074 self
.query
['insertTourney'] = """INSERT INTO Tourneys
5075 (tourneyTypeId, siteTourneyNo, entries, prizepool,
5076 startTime, endTime, tourneyName, matrixIdProcessed,
5077 totalRebuyCount, totalAddOnCount)
5078 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
5081 self
.query
['updateTourney'] = """UPDATE Tourneys
5087 matrixIdProcessed = %s,
5088 totalRebuyCount = %s,
5089 totalAddOnCount = %s,
5095 self
.query
['getTourneysPlayersByIds'] = """SELECT *
5096 FROM TourneysPlayers
5097 WHERE tourneyId=%s AND playerId+0=%s
5100 self
.query
['updateTourneysPlayer'] = """UPDATE TourneysPlayers
5103 winningsCurrency = %s,
5110 self
.query
['insertTourneysPlayer'] = """insert into TourneysPlayers
5111 (tourneyId, playerId, rank, winnings, winningsCurrency, rebuyCount, addOnCount, koCount)
5112 values (%s, %s, %s, %s, %s, %s, %s, %s)
5115 self
.query
['selectHandsPlayersWithWrongTTypeId'] = """SELECT id
5117 WHERE tourneyTypeId <> %s AND (TourneysPlayersId+0=%s)
5120 # self.query['updateHandsPlayersForTTypeId2'] = """UPDATE HandsPlayers
5121 # SET tourneyTypeId= %s
5122 # WHERE (TourneysPlayersId+0=%s)
5125 self
.query
['updateHandsPlayersForTTypeId'] = """UPDATE HandsPlayers
5126 SET tourneyTypeId= %s
5131 self
.query
['handsPlayersTTypeId_joiner'] = " OR TourneysPlayersId+0="
5132 self
.query
['handsPlayersTTypeId_joiner_id'] = " OR id="
5134 self
.query
['store_hand'] = """insert into Hands (
5170 (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
5171 %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
5172 %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
5175 self
.query
['store_hands_players'] = """insert into HandsPlayers (
5248 street0_FoldTo3BChance,
5249 street0_FoldTo3BDone,
5250 street0_FoldTo4BChance,
5251 street0_FoldTo4BDone,
5252 street0_SqueezeChance,
5253 street0_SqueezeDone,
5262 foldToOtherRaisedStreet0,
5263 foldToOtherRaisedStreet1,
5264 foldToOtherRaisedStreet2,
5265 foldToOtherRaisedStreet3,
5266 foldToOtherRaisedStreet4,
5269 foldBbToStealChance,
5271 foldSbToStealChance,
5273 foldToStreet1CBChance,
5274 foldToStreet1CBDone,
5275 foldToStreet2CBChance,
5276 foldToStreet2CBDone,
5277 foldToStreet3CBChance,
5278 foldToStreet3CBDone,
5279 foldToStreet4CBChance,
5280 foldToStreet4CBDone,
5281 street1CheckCallRaiseChance,
5282 street1CheckCallRaiseDone,
5283 street2CheckCallRaiseChance,
5284 street2CheckCallRaiseDone,
5285 street3CheckCallRaiseChance,
5286 street3CheckCallRaiseDone,
5287 street4CheckCallRaiseChance,
5288 street4CheckCallRaiseDone,
5322 self
.query
['store_hands_actions'] = """insert into HandsActions (
5342 self
.query
['store_boards'] = """insert into Boards (
5356 ################################
5357 # queries for Files Table
5358 ################################
5360 self
.query
['store_file'] = """ insert into Files (
5378 self
.query
['update_file'] = """
5388 ttime100=ttime100+%s,
5392 ################################
5393 # Counts for DB stats window
5394 ################################
5395 self
.query
['getHandCount'] = "SELECT COUNT(*) FROM Hands"
5396 self
.query
['getTourneyCount'] = "SELECT COUNT(*) FROM Tourneys"
5397 self
.query
['getTourneyTypeCount'] = "SELECT COUNT(*) FROM TourneyTypes"
5399 ################################
5400 # queries for dumpDatabase
5401 ################################
5402 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'):
5403 self
.query
['get'+table
] = u
"SELECT * FROM "+table
5405 ################################
5406 # placeholders and substitution stuff
5407 ################################
5408 if db_server
== 'mysql':
5409 self
.query
['placeholder'] = u
'%s'
5410 elif db_server
== 'postgresql':
5411 self
.query
['placeholder'] = u
'%s'
5412 elif db_server
== 'sqlite':
5413 self
.query
['placeholder'] = u
'?'
5416 # If using sqlite, use the ? placeholder instead of %s
5417 if db_server
== 'sqlite':
5418 for k
,q
in self
.query
.iteritems():
5419 self
.query
[k
] = re
.sub('%s','?',q
)
5421 if __name__
== "__main__":
5422 # just print the default queries and exit
5425 print "For query " + key
+ ", sql ="