2 # -*- coding: utf-8 -*-
3 """Returns a dict of SQL statements used in fpdb.
5 # Copyright 2008-2011, Ray E. Barker
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # NOTES: The sql statements use the placeholder %s for bind variables
22 # which is then replaced by ? for sqlite. Comments can be included
23 # within sql statements using C style /* ... */ comments, BUT
24 # THE COMMENTS MUST NOT INCLUDE %s OR ?.
26 ########################################################################
28 # Standard Library modules
33 # FreePokerTools modules
37 def __init__(self
, game
= 'holdem', db_server
= 'mysql'):
39 ###############################################################################3
40 # Support for the Free Poker DataBase = fpdb http://fpdb.sourceforge.net/
43 ################################
45 ################################
46 if db_server
== 'mysql':
47 self
.query
['list_tables'] = """SHOW TABLES"""
48 elif db_server
== 'postgresql':
49 self
.query
['list_tables'] = """SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"""
50 elif db_server
== 'sqlite':
51 self
.query
['list_tables'] = """SELECT name FROM sqlite_master
55 ################################
57 ################################
58 if db_server
== 'mysql':
59 self
.query
['list_indexes'] = """SHOW INDEXES"""
60 elif db_server
== 'postgresql':
61 self
.query
['list_indexes'] = """SELECT tablename, indexname FROM PG_INDEXES"""
62 elif db_server
== 'sqlite':
63 self
.query
['list_indexes'] = """SELECT name FROM sqlite_master
67 ##################################################################
68 # Drop Tables - MySQL, PostgreSQL and SQLite all share same syntax
69 ##################################################################
71 self
.query
['drop_table'] = """DROP TABLE IF EXISTS """
74 ##################################################################
75 # Set transaction isolation level
76 ##################################################################
78 if db_server
== 'mysql' or db_server
== 'postgresql':
79 self
.query
['set tx level'] = """SET SESSION TRANSACTION
80 ISOLATION LEVEL READ COMMITTED"""
81 elif db_server
== 'sqlite':
82 self
.query
['set tx level'] = """ """
85 ################################
87 ################################
89 self
.query
['getSiteId'] = """SELECT id from Sites where name = %s"""
91 self
.query
['getGames'] = """SELECT DISTINCT category from Gametypes"""
93 self
.query
['getCurrencies'] = """SELECT DISTINCT currency from Gametypes ORDER BY currency"""
95 self
.query
['getLimits'] = """SELECT DISTINCT bigBlind from Gametypes ORDER by bigBlind DESC"""
97 self
.query
['getTourneyTypesIds'] = "SELECT id FROM TourneyTypes"
99 ################################
101 ################################
102 if db_server
== 'mysql':
103 self
.query
['createSettingsTable'] = """CREATE TABLE Settings (
104 version SMALLINT NOT NULL)
106 elif db_server
== 'postgresql':
107 self
.query
['createSettingsTable'] = """CREATE TABLE Settings (version SMALLINT NOT NULL)"""
109 elif db_server
== 'sqlite':
110 self
.query
['createSettingsTable'] = """CREATE TABLE Settings
111 (version INTEGER NOT NULL) """
113 ################################
115 ################################
116 if db_server
== 'mysql':
117 self
.query
['createLockTable'] = """CREATE TABLE InsertLock (
118 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
119 locked BOOLEAN NOT NULL DEFAULT FALSE)
122 ################################
123 # Create RawHands (this table is all but identical with RawTourneys)
124 ################################
125 if db_server
== 'mysql':
126 self
.query
['createRawHands'] = """CREATE TABLE RawHands (
127 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
128 handId BIGINT NOT NULL,
129 rawHand TEXT NOT NULL,
130 complain BOOLEAN NOT NULL DEFAULT FALSE)
132 elif db_server
== 'postgresql':
133 self
.query
['createRawHands'] = """CREATE TABLE RawHands (
134 id BIGSERIAL, PRIMARY KEY (id),
135 handId BIGINT NOT NULL,
136 rawHand TEXT NOT NULL,
137 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
138 elif db_server
== 'sqlite':
139 self
.query
['createRawHands'] = """CREATE TABLE RawHands (
140 id INTEGER PRIMARY KEY,
141 handId BIGINT NOT NULL,
142 rawHand TEXT NOT NULL,
143 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
145 ################################
146 # Create RawTourneys (this table is all but identical with RawHands)
147 ################################
148 if db_server
== 'mysql':
149 self
.query
['createRawTourneys'] = """CREATE TABLE RawTourneys (
150 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
151 tourneyId BIGINT NOT NULL,
152 rawTourney TEXT NOT NULL,
153 complain BOOLEAN NOT NULL DEFAULT FALSE)
155 elif db_server
== 'postgresql':
156 self
.query
['createRawTourneys'] = """CREATE TABLE RawTourneys (
157 id BIGSERIAL, PRIMARY KEY (id),
158 tourneyId BIGINT NOT NULL,
159 rawTourney TEXT NOT NULL,
160 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
161 elif db_server
== 'sqlite':
162 self
.query
['createRawTourneys'] = """CREATE TABLE RawTourneys (
163 id INTEGER PRIMARY KEY,
164 tourneyId BIGINT NOT NULL,
165 rawTourney TEXT NOT NULL,
166 complain BOOLEAN NOT NULL DEFAULT FALSE)"""
168 ################################
170 ################################
172 if db_server
== 'mysql':
173 self
.query
['createActionsTable'] = """CREATE TABLE Actions (
174 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
175 name varchar(32) NOT NULL,
176 code char(4) NOT NULL)
178 elif db_server
== 'postgresql':
179 self
.query
['createActionsTable'] = """CREATE TABLE Actions (
180 id SERIAL, PRIMARY KEY (id),
183 elif db_server
== 'sqlite':
184 self
.query
['createActionsTable'] = """CREATE TABLE Actions (
185 id INTEGER PRIMARY KEY,
187 code TEXT NOT NULL)"""
189 ################################
191 ################################
193 if db_server
== 'mysql':
194 self
.query
['createSitesTable'] = """CREATE TABLE Sites (
195 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
196 name varchar(32) NOT NULL,
197 code char(2) NOT NULL)
199 elif db_server
== 'postgresql':
200 self
.query
['createSitesTable'] = """CREATE TABLE Sites (
201 id SERIAL, PRIMARY KEY (id),
204 elif db_server
== 'sqlite':
205 self
.query
['createSitesTable'] = """CREATE TABLE Sites (
206 id INTEGER PRIMARY KEY,
208 code TEXT NOT NULL)"""
210 ################################
212 ################################
214 if db_server
== 'mysql':
215 self
.query
['createBackingsTable'] = """CREATE TABLE Backings (
216 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
217 tourneysPlayersId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
218 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
219 buyInPercentage FLOAT UNSIGNED NOT NULL,
220 payOffPercentage FLOAT UNSIGNED NOT NULL) ENGINE=INNODB"""
221 elif db_server
== 'postgresql':
222 self
.query
['createBackingsTable'] = """CREATE TABLE Backings (
223 id BIGSERIAL, PRIMARY KEY (id),
224 tourneysPlayersId INT NOT NULL, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
225 playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
226 buyInPercentage FLOAT NOT NULL,
227 payOffPercentage FLOAT NOT NULL)"""
228 elif db_server
== 'sqlite':
229 self
.query
['createBackingsTable'] = """CREATE TABLE Backings (
230 id INTEGER PRIMARY KEY,
231 tourneysPlayersId INT NOT NULL,
232 playerId INT NOT NULL,
233 buyInPercentage REAL UNSIGNED NOT NULL,
234 payOffPercentage REAL UNSIGNED NOT NULL)"""
236 ################################
238 ################################
240 if db_server
== 'mysql':
241 self
.query
['createGametypesTable'] = """CREATE TABLE Gametypes (
242 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
243 siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
244 currency varchar(4) NOT NULL,
245 type char(4) NOT NULL,
246 base char(4) NOT NULL,
247 category varchar(9) NOT NULL,
248 limitType char(2) NOT NULL,
249 hiLo char(1) NOT NULL,
250 mix varchar(9) NOT NULL,
253 smallBet int NOT NULL,
255 maxSeats TINYINT NOT NULL,
258 elif db_server
== 'postgresql':
259 self
.query
['createGametypesTable'] = """CREATE TABLE Gametypes (
260 id SERIAL NOT NULL, PRIMARY KEY (id),
261 siteId INTEGER NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
262 currency varchar(4) NOT NULL,
263 type char(4) NOT NULL,
264 base char(4) NOT NULL,
265 category varchar(9) NOT NULL,
266 limitType char(2) NOT NULL,
267 hiLo char(1) NOT NULL,
268 mix char(9) NOT NULL,
271 smallBet int NOT NULL,
273 maxSeats SMALLINT NOT NULL,
274 ante INT NOT NULL)"""
275 elif db_server
== 'sqlite':
276 self
.query
['createGametypesTable'] = """CREATE TABLE Gametypes (
277 id INTEGER PRIMARY KEY NOT NULL,
278 siteId INTEGER NOT NULL,
279 currency TEXT NOT NULL,
282 category TEXT NOT NULL,
283 limitType TEXT NOT NULL,
288 smallBet INTEGER NOT NULL,
289 bigBet INTEGER NOT NULL,
290 maxSeats INT NOT NULL,
292 FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
295 ################################
297 ################################
299 if db_server
== 'mysql':
300 self
.query
['createPlayersTable'] = """CREATE TABLE Players (
301 id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
302 name VARCHAR(32) NOT NULL,
303 siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
307 elif db_server
== 'postgresql':
308 self
.query
['createPlayersTable'] = """CREATE TABLE Players (
309 id SERIAL, PRIMARY KEY (id),
311 siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id),
313 commentTs timestamp without time zone)"""
314 elif db_server
== 'sqlite':
315 self
.query
['createPlayersTable'] = """CREATE TABLE Players (
316 id INTEGER PRIMARY KEY,
321 FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
324 ################################
326 ################################
328 if db_server
== 'mysql':
329 self
.query
['createAutoratesTable'] = """CREATE TABLE Autorates (
330 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
331 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
332 gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
333 description varchar(50) NOT NULL,
334 shortDesc char(8) NOT NULL,
335 ratingTime DATETIME NOT NULL,
336 handCount int NOT NULL)
338 elif db_server
== 'postgresql':
339 self
.query
['createAutoratesTable'] = """CREATE TABLE Autorates (
340 id BIGSERIAL, PRIMARY KEY (id),
341 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
342 gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
343 description varchar(50),
345 ratingTime timestamp without time zone,
347 elif db_server
== 'sqlite':
348 self
.query
['createAutoratesTable'] = """CREATE TABLE Autorates (
349 id INTEGER PRIMARY KEY,
358 ################################
360 ################################
362 if db_server
== 'mysql':
363 self
.query
['createHandsTable'] = """CREATE TABLE Hands (
364 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
365 tableName VARCHAR(50) NOT NULL,
366 siteHandNo BIGINT NOT NULL,
367 tourneyId INT UNSIGNED, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
368 gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
369 sessionId INT UNSIGNED, FOREIGN KEY (sessionId) REFERENCES SessionsCache(id),
370 gameId INT UNSIGNED, FOREIGN KEY (gameId) REFERENCES GamesCache(id),
371 fileId INT(10) UNSIGNED NOT NULL, FOREIGN KEY (fileId) REFERENCES Files(id),
372 startTime DATETIME NOT NULL,
373 importTime DATETIME NOT NULL,
374 seats TINYINT NOT NULL,
376 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
383 playersVpi SMALLINT NOT NULL, /* num of players vpi */
384 playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */
385 playersAtStreet2 SMALLINT NOT NULL,
386 playersAtStreet3 SMALLINT NOT NULL,
387 playersAtStreet4 SMALLINT NOT NULL,
388 playersAtShowdown SMALLINT NOT NULL,
389 street0Raises TINYINT NOT NULL, /* num small bets paid to see flop/street4, including blind */
390 street1Raises TINYINT NOT NULL, /* num small bets paid to see turn/street5 */
391 street2Raises TINYINT NOT NULL, /* num big bets paid to see river/street6 */
392 street3Raises TINYINT NOT NULL, /* num big bets paid to see sd/street7 */
393 street4Raises TINYINT NOT NULL, /* num big bets paid to see showdown */
394 street1Pot INT, /* pot size at flop/street4 */
395 street2Pot INT, /* pot size at turn/street5 */
396 street3Pot INT, /* pot size at river/street6 */
397 street4Pot INT, /* pot size at sd/street7 */
398 showdownPot INT, /* pot size at sd/street7 */
402 elif db_server
== 'postgresql':
403 self
.query
['createHandsTable'] = """CREATE TABLE Hands (
404 id BIGSERIAL, PRIMARY KEY (id),
405 tableName VARCHAR(50) NOT NULL,
406 siteHandNo BIGINT NOT NULL,
407 tourneyId INT, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
408 gametypeId INT NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
409 sessionId INT, FOREIGN KEY (sessionId) REFERENCES SessionsCache(id),
410 gameId INT, FOREIGN KEY (gameId) REFERENCES GamesCache(id),
411 fileId BIGINT NOT NULL, FOREIGN KEY (fileId) REFERENCES Files(id),
412 startTime timestamp without time zone NOT NULL,
413 importTime timestamp without time zone NOT NULL,
414 seats SMALLINT NOT NULL,
416 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
423 playersVpi SMALLINT NOT NULL, /* num of players vpi */
424 playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */
425 playersAtStreet2 SMALLINT NOT NULL,
426 playersAtStreet3 SMALLINT NOT NULL,
427 playersAtStreet4 SMALLINT NOT NULL,
428 playersAtShowdown SMALLINT NOT NULL,
429 street0Raises SMALLINT NOT NULL, /* num small bets paid to see flop/street4, including blind */
430 street1Raises SMALLINT NOT NULL, /* num small bets paid to see turn/street5 */
431 street2Raises SMALLINT NOT NULL, /* num big bets paid to see river/street6 */
432 street3Raises SMALLINT NOT NULL, /* num big bets paid to see sd/street7 */
433 street4Raises SMALLINT NOT NULL, /* num big bets paid to see showdown */
434 street1Pot INT, /* pot size at flop/street4 */
435 street2Pot INT, /* pot size at turn/street5 */
436 street3Pot INT, /* pot size at river/street6 */
437 street4Pot INT, /* pot size at sd/street7 */
438 showdownPot INT, /* pot size at sd/street7 */
440 commentTs timestamp without time zone)"""
441 elif db_server
== 'sqlite':
442 self
.query
['createHandsTable'] = """CREATE TABLE Hands (
443 id INTEGER PRIMARY KEY,
444 tableName TEXT(50) NOT NULL,
445 siteHandNo INT NOT NULL,
447 gametypeId INT NOT NULL,
451 startTime REAL NOT NULL,
452 importTime REAL NOT NULL,
455 boardcard1 INT, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
462 playersVpi INT NOT NULL, /* num of players vpi */
463 playersAtStreet1 INT NOT NULL, /* num of players seeing flop/street4 */
464 playersAtStreet2 INT NOT NULL,
465 playersAtStreet3 INT NOT NULL,
466 playersAtStreet4 INT NOT NULL,
467 playersAtShowdown INT NOT NULL,
468 street0Raises INT NOT NULL, /* num small bets paid to see flop/street4, including blind */
469 street1Raises INT NOT NULL, /* num small bets paid to see turn/street5 */
470 street2Raises INT NOT NULL, /* num big bets paid to see river/street6 */
471 street3Raises INT NOT NULL, /* num big bets paid to see sd/street7 */
472 street4Raises INT NOT NULL, /* num big bets paid to see showdown */
473 street1Pot INT, /* pot size at flop/street4 */
474 street2Pot INT, /* pot size at turn/street5 */
475 street3Pot INT, /* pot size at river/street6 */
476 street4Pot INT, /* pot size at sd/street7 */
477 showdownPot INT, /* pot size at sd/street7 */
481 ################################
483 ################################
485 if db_server
== 'mysql':
486 self
.query
['createBoardsTable'] = """CREATE TABLE Boards (
487 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
488 handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
490 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
496 elif db_server
== 'postgresql':
497 self
.query
['createBoardsTable'] = """CREATE TABLE Boards (
498 id BIGSERIAL, PRIMARY KEY (id),
499 handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
501 boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
505 boardcard5 smallint)"""
506 elif db_server
== 'sqlite':
507 self
.query
['createBoardsTable'] = """CREATE TABLE Boards (
508 id INTEGER PRIMARY KEY,
511 boardcard1 INT, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
518 ################################
519 # Create TourneyTypes
520 ################################
522 if db_server
== 'mysql':
523 self
.query
['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
524 id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
525 siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
529 category varchar(9) NOT NULL,
530 limitType char(2) NOT NULL,
548 doubleOrNothing BOOLEAN,
551 addedCurrency VARCHAR(4))
553 elif db_server
== 'postgresql':
554 self
.query
['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
555 id SERIAL, PRIMARY KEY (id),
556 siteId INT NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
579 doubleOrNothing BOOLEAN,
582 addedCurrency VARCHAR(4))"""
583 elif db_server
== 'sqlite':
584 self
.query
['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
585 id INTEGER PRIMARY KEY,
609 doubleOrNothing BOOLEAN,
612 addedCurrency VARCHAR(4))"""
614 ################################
616 ################################
618 if db_server
== 'mysql':
619 self
.query
['createTourneysTable'] = """CREATE TABLE Tourneys (
620 id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
621 tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
622 sessionId INT UNSIGNED, FOREIGN KEY (sessionId) REFERENCES SessionsCache(id),
623 siteTourneyNo BIGINT NOT NULL,
628 tourneyName varchar(40),
629 matrixIdProcessed TINYINT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
635 elif db_server
== 'postgresql':
636 self
.query
['createTourneysTable'] = """CREATE TABLE Tourneys (
637 id SERIAL, PRIMARY KEY (id),
638 tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
639 sessionId INT, FOREIGN KEY (sessionId) REFERENCES SessionsCache(id),
640 siteTourneyNo BIGINT,
643 startTime timestamp without time zone,
644 endTime timestamp without time zone,
645 tourneyName varchar(40),
646 matrixIdProcessed SMALLINT DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
650 commentTs timestamp without time zone)"""
651 elif db_server
== 'sqlite':
652 self
.query
['createTourneysTable'] = """CREATE TABLE Tourneys (
653 id INTEGER PRIMARY KEY,
662 matrixIdProcessed INT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */
668 ################################
669 # Create HandsPlayers
670 ################################
672 if db_server
== 'mysql':
673 self
.query
['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
674 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
675 handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
676 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
677 startCash INT NOT NULL,
679 seatNo SMALLINT NOT NULL,
680 sitout BOOLEAN NOT NULL,
681 wentAllInOnStreet SMALLINT,
683 card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
684 card2 smallint NOT NULL,
690 card8 smallint, /* cards 8-20 for draw hands */
706 winnings int NOT NULL,
712 tourneysPlayersId BIGINT UNSIGNED, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
714 wonWhenSeenStreet1 FLOAT,
715 wonWhenSeenStreet2 FLOAT,
716 wonWhenSeenStreet3 FLOAT,
717 wonWhenSeenStreet4 FLOAT,
722 street0CalledRaiseChance TINYINT,
723 street0CalledRaiseDone TINYINT,
724 street0_3BChance BOOLEAN,
725 street0_3BDone BOOLEAN,
726 street0_4BChance BOOLEAN,
727 street0_C4BChance BOOLEAN,
728 street0_4BDone BOOLEAN,
729 street0_C4BDone BOOLEAN,
730 street0_FoldTo3BChance BOOLEAN,
731 street0_FoldTo3BDone BOOLEAN,
732 street0_FoldTo4BChance BOOLEAN,
733 street0_FoldTo4BDone BOOLEAN,
734 street0_SqueezeChance BOOLEAN,
735 street0_SqueezeDone BOOLEAN,
737 raiseToStealChance BOOLEAN,
738 raiseToStealDone BOOLEAN,
739 success_Steal BOOLEAN,
753 otherRaisedStreet0 BOOLEAN,
754 otherRaisedStreet1 BOOLEAN,
755 otherRaisedStreet2 BOOLEAN,
756 otherRaisedStreet3 BOOLEAN,
757 otherRaisedStreet4 BOOLEAN,
758 foldToOtherRaisedStreet0 BOOLEAN,
759 foldToOtherRaisedStreet1 BOOLEAN,
760 foldToOtherRaisedStreet2 BOOLEAN,
761 foldToOtherRaisedStreet3 BOOLEAN,
762 foldToOtherRaisedStreet4 BOOLEAN,
764 raiseFirstInChance BOOLEAN,
765 raisedFirstIn BOOLEAN,
766 foldBbToStealChance BOOLEAN,
767 foldedBbToSteal BOOLEAN,
768 foldSbToStealChance BOOLEAN,
769 foldedSbToSteal BOOLEAN,
771 street1CBChance BOOLEAN,
772 street1CBDone BOOLEAN,
773 street2CBChance BOOLEAN,
774 street2CBDone BOOLEAN,
775 street3CBChance BOOLEAN,
776 street3CBDone BOOLEAN,
777 street4CBChance BOOLEAN,
778 street4CBDone BOOLEAN,
780 foldToStreet1CBChance BOOLEAN,
781 foldToStreet1CBDone BOOLEAN,
782 foldToStreet2CBChance BOOLEAN,
783 foldToStreet2CBDone BOOLEAN,
784 foldToStreet3CBChance BOOLEAN,
785 foldToStreet3CBDone BOOLEAN,
786 foldToStreet4CBChance BOOLEAN,
787 foldToStreet4CBDone BOOLEAN,
789 street1CheckCallRaiseChance BOOLEAN,
790 street1CheckCallRaiseDone BOOLEAN,
791 street2CheckCallRaiseChance BOOLEAN,
792 street2CheckCallRaiseDone BOOLEAN,
793 street3CheckCallRaiseChance BOOLEAN,
794 street3CheckCallRaiseDone BOOLEAN,
795 street4CheckCallRaiseChance BOOLEAN,
796 street4CheckCallRaiseDone BOOLEAN,
798 street0Calls TINYINT,
799 street1Calls TINYINT,
800 street2Calls TINYINT,
801 street3Calls TINYINT,
802 street4Calls TINYINT,
808 street0Raises TINYINT,
809 street1Raises TINYINT,
810 street2Raises TINYINT,
811 street3Raises TINYINT,
812 street4Raises TINYINT,
814 actionString VARCHAR(15))
816 elif db_server
== 'postgresql':
817 self
.query
['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
818 id BIGSERIAL, PRIMARY KEY (id),
819 handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
820 playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
821 startCash INT NOT NULL,
823 seatNo SMALLINT NOT NULL,
824 sitout BOOLEAN NOT NULL,
825 wentAllInOnStreet SMALLINT,
827 card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
828 card2 smallint NOT NULL,
834 card8 smallint, /* cards 8-20 for draw hands */
850 winnings int NOT NULL,
855 commentTs timestamp without time zone,
856 tourneysPlayersId BIGINT, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
858 wonWhenSeenStreet1 FLOAT,
859 wonWhenSeenStreet2 FLOAT,
860 wonWhenSeenStreet3 FLOAT,
861 wonWhenSeenStreet4 FLOAT,
866 street0CalledRaiseChance SMALLINT,
867 street0CalledRaiseDone SMALLINT,
868 street0_3BChance BOOLEAN,
869 street0_3BDone BOOLEAN,
870 street0_4BChance BOOLEAN,
871 street0_4BDone BOOLEAN,
872 street0_C4BChance BOOLEAN,
873 street0_C4BDone BOOLEAN,
874 street0_FoldTo3BChance BOOLEAN,
875 street0_FoldTo3BDone BOOLEAN,
876 street0_FoldTo4BChance BOOLEAN,
877 street0_FoldTo4BDone BOOLEAN,
878 street0_SqueezeChance BOOLEAN,
879 street0_SqueezeDone BOOLEAN,
881 raiseToStealChance BOOLEAN,
882 raiseToStealDone BOOLEAN,
883 success_Steal BOOLEAN,
897 otherRaisedStreet0 BOOLEAN,
898 otherRaisedStreet1 BOOLEAN,
899 otherRaisedStreet2 BOOLEAN,
900 otherRaisedStreet3 BOOLEAN,
901 otherRaisedStreet4 BOOLEAN,
902 foldToOtherRaisedStreet0 BOOLEAN,
903 foldToOtherRaisedStreet1 BOOLEAN,
904 foldToOtherRaisedStreet2 BOOLEAN,
905 foldToOtherRaisedStreet3 BOOLEAN,
906 foldToOtherRaisedStreet4 BOOLEAN,
908 raiseFirstInChance BOOLEAN,
909 raisedFirstIn BOOLEAN,
910 foldBbToStealChance BOOLEAN,
911 foldedBbToSteal BOOLEAN,
912 foldSbToStealChance BOOLEAN,
913 foldedSbToSteal BOOLEAN,
915 street1CBChance BOOLEAN,
916 street1CBDone BOOLEAN,
917 street2CBChance BOOLEAN,
918 street2CBDone BOOLEAN,
919 street3CBChance BOOLEAN,
920 street3CBDone BOOLEAN,
921 street4CBChance BOOLEAN,
922 street4CBDone BOOLEAN,
924 foldToStreet1CBChance BOOLEAN,
925 foldToStreet1CBDone BOOLEAN,
926 foldToStreet2CBChance BOOLEAN,
927 foldToStreet2CBDone BOOLEAN,
928 foldToStreet3CBChance BOOLEAN,
929 foldToStreet3CBDone BOOLEAN,
930 foldToStreet4CBChance BOOLEAN,
931 foldToStreet4CBDone BOOLEAN,
933 street1CheckCallRaiseChance BOOLEAN,
934 street1CheckCallRaiseDone BOOLEAN,
935 street2CheckCallRaiseChance BOOLEAN,
936 street2CheckCallRaiseDone BOOLEAN,
937 street3CheckCallRaiseChance BOOLEAN,
938 street3CheckCallRaiseDone BOOLEAN,
939 street4CheckCallRaiseChance BOOLEAN,
940 street4CheckCallRaiseDone BOOLEAN,
942 street0Calls SMALLINT,
943 street1Calls SMALLINT,
944 street2Calls SMALLINT,
945 street3Calls SMALLINT,
946 street4Calls SMALLINT,
947 street0Bets SMALLINT,
948 street1Bets SMALLINT,
949 street2Bets SMALLINT,
950 street3Bets SMALLINT,
951 street4Bets SMALLINT,
952 street0Raises SMALLINT,
953 street1Raises SMALLINT,
954 street2Raises SMALLINT,
955 street3Raises SMALLINT,
956 street4Raises SMALLINT,
958 actionString VARCHAR(15))"""
959 elif db_server
== 'sqlite':
960 self
.query
['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
961 id INTEGER PRIMARY KEY,
963 playerId INT NOT NULL,
964 startCash INT NOT NULL,
967 sitout BOOLEAN NOT NULL,
968 wentAllInOnStreet INT,
970 card1 INT NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
977 card8 INT, /* cards 8-20 for draw hands */
993 winnings INT NOT NULL,
999 tourneysPlayersId INT,
1001 wonWhenSeenStreet1 REAL,
1002 wonWhenSeenStreet2 REAL,
1003 wonWhenSeenStreet3 REAL,
1004 wonWhenSeenStreet4 REAL,
1009 street0CalledRaiseChance INT,
1010 street0CalledRaiseDone INT,
1011 street0_3BChance INT,
1013 street0_4BChance INT,
1015 street0_C4BChance INT,
1016 street0_C4BDone INT,
1017 street0_FoldTo3BChance INT,
1018 street0_FoldTo3BDone INT,
1019 street0_FoldTo4BChance INT,
1020 street0_FoldTo4BDone INT,
1021 street0_SqueezeChance INT,
1022 street0_SqueezeDone INT,
1024 raiseToStealChance INT,
1025 raiseToStealDone INT,
1040 otherRaisedStreet0 INT,
1041 otherRaisedStreet1 INT,
1042 otherRaisedStreet2 INT,
1043 otherRaisedStreet3 INT,
1044 otherRaisedStreet4 INT,
1045 foldToOtherRaisedStreet0 INT,
1046 foldToOtherRaisedStreet1 INT,
1047 foldToOtherRaisedStreet2 INT,
1048 foldToOtherRaisedStreet3 INT,
1049 foldToOtherRaisedStreet4 INT,
1051 raiseFirstInChance INT,
1053 foldBbToStealChance INT,
1054 foldedBbToSteal INT,
1055 foldSbToStealChance INT,
1056 foldedSbToSteal INT,
1058 street1CBChance INT,
1060 street2CBChance INT,
1062 street3CBChance INT,
1064 street4CBChance INT,
1067 foldToStreet1CBChance INT,
1068 foldToStreet1CBDone INT,
1069 foldToStreet2CBChance INT,
1070 foldToStreet2CBDone INT,
1071 foldToStreet3CBChance INT,
1072 foldToStreet3CBDone INT,
1073 foldToStreet4CBChance INT,
1074 foldToStreet4CBDone INT,
1076 street1CheckCallRaiseChance INT,
1077 street1CheckCallRaiseDone INT,
1078 street2CheckCallRaiseChance INT,
1079 street2CheckCallRaiseDone INT,
1080 street3CheckCallRaiseChance INT,
1081 street3CheckCallRaiseDone INT,
1082 street4CheckCallRaiseChance INT,
1083 street4CheckCallRaiseDone INT,
1100 actionString VARCHAR(15))
1104 ################################
1105 # Create TourneysPlayers
1106 ################################
1108 if db_server
== 'mysql':
1109 self
.query
['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
1110 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1111 tourneyId INT UNSIGNED NOT NULL, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
1112 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1117 winningsCurrency VARCHAR(4),
1126 elif db_server
== 'postgresql':
1127 self
.query
['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
1128 id BIGSERIAL, PRIMARY KEY (id),
1129 tourneyId INT, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
1130 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
1131 startTime timestamp without time zone,
1132 endTime timestamp without time zone,
1135 winningsCurrency VARCHAR(4),
1142 commentTs timestamp without time zone)"""
1143 elif db_server
== 'sqlite':
1144 self
.query
['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
1145 id INTEGER PRIMARY KEY,
1148 startTime timestamp,
1152 winningsCurrency VARCHAR(4),
1159 commentTs timestamp without time zone,
1160 FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
1161 FOREIGN KEY (playerId) REFERENCES Players(id)
1165 ################################
1166 # Create HandsActions
1167 ################################
1169 if db_server
== 'mysql':
1170 self
.query
['createHandsActionsTable'] = """CREATE TABLE HandsActions (
1171 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1172 handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
1173 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1174 street SMALLINT NOT NULL,
1175 actionNo SMALLINT NOT NULL,
1176 streetActionNo SMALLINT NOT NULL,
1177 actionId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (actionId) REFERENCES Actions(id),
1178 amount INT NOT NULL,
1179 raiseTo INT NOT NULL,
1180 amountCalled INT NOT NULL,
1181 numDiscarded SMALLINT NOT NULL,
1182 cardsDiscarded varchar(14),
1183 allIn BOOLEAN NOT NULL)
1185 elif db_server
== 'postgresql':
1186 self
.query
['createHandsActionsTable'] = """CREATE TABLE HandsActions (
1187 id BIGSERIAL, PRIMARY KEY (id),
1188 handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
1189 playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1192 streetActionNo SMALLINT,
1193 actionId SMALLINT, FOREIGN KEY (actionId) REFERENCES Actions(id),
1197 numDiscarded SMALLINT,
1198 cardsDiscarded varchar(14),
1200 elif db_server
== 'sqlite':
1201 self
.query
['createHandsActionsTable'] = """CREATE TABLE HandsActions (
1202 id INTEGER PRIMARY KEY,
1203 handId INT NOT NULL,
1204 playerId INT NOT NULL,
1207 streetActionNo SMALLINT,
1212 numDiscarded SMALLINT,
1213 cardsDiscarded TEXT,
1218 ################################
1220 ################################
1222 if db_server
== 'mysql':
1223 self
.query
['createHandsStoveTable'] = """CREATE TABLE HandsStove (
1224 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1225 handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
1226 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1233 elif db_server
== 'postgresql':
1234 self
.query
['createHandsStoveTable'] = """CREATE TABLE HandsStove (
1235 id BIGSERIAL, PRIMARY KEY (id),
1236 handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
1237 playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1243 elif db_server
== 'sqlite':
1244 self
.query
['createHandsStoveTable'] = """CREATE TABLE HandsStove (
1245 id INTEGER PRIMARY KEY,
1246 handId INT NOT NULL,
1247 playerId INT NOT NULL,
1256 ################################
1258 ################################
1260 if db_server
== 'mysql':
1261 self
.query
['createFilesTable'] = """CREATE TABLE Files (
1262 id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1266 startTime DATETIME NOT NULL,
1267 lastUpdate DATETIME NOT NULL,
1277 elif db_server
== 'postgresql':
1278 self
.query
['createFilesTable'] = """CREATE TABLE Files (
1279 id BIGSERIAL, PRIMARY KEY (id),
1283 startTime timestamp without time zone NOT NULL,
1284 lastUpdate timestamp without time zone NOT NULL,
1285 endTime timestamp without time zone,
1292 finished BOOLEAN)"""
1293 elif db_server
== 'sqlite':
1294 self
.query
['createFilesTable'] = """CREATE TABLE Files (
1295 id INTEGER PRIMARY KEY,
1299 startTime timestamp NOT NULL,
1300 lastUpdate timestamp NOT NULL,
1311 ################################
1313 ################################
1315 if db_server
== 'mysql':
1316 self
.query
['createHudCacheTable'] = """CREATE TABLE HudCache (
1317 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1318 gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
1319 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1320 activeSeats SMALLINT NOT NULL,
1322 tourneyTypeId SMALLINT UNSIGNED, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
1323 styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1326 wonWhenSeenStreet1 FLOAT,
1327 wonWhenSeenStreet2 FLOAT,
1328 wonWhenSeenStreet3 FLOAT,
1329 wonWhenSeenStreet4 FLOAT,
1334 street0CalledRaiseChance INT,
1335 street0CalledRaiseDone INT,
1336 street0_3BChance INT,
1338 street0_4BChance INT,
1340 street0_C4BChance INT,
1341 street0_C4BDone INT,
1342 street0_FoldTo3BChance INT,
1343 street0_FoldTo3BDone INT,
1344 street0_FoldTo4BChance INT,
1345 street0_FoldTo4BDone INT,
1346 street0_SqueezeChance INT,
1347 street0_SqueezeDone INT,
1349 raiseToStealChance INT,
1350 raiseToStealDone INT,
1365 otherRaisedStreet0 INT,
1366 otherRaisedStreet1 INT,
1367 otherRaisedStreet2 INT,
1368 otherRaisedStreet3 INT,
1369 otherRaisedStreet4 INT,
1370 foldToOtherRaisedStreet0 INT,
1371 foldToOtherRaisedStreet1 INT,
1372 foldToOtherRaisedStreet2 INT,
1373 foldToOtherRaisedStreet3 INT,
1374 foldToOtherRaisedStreet4 INT,
1376 raiseFirstInChance INT,
1378 foldBbToStealChance INT,
1379 foldedBbToSteal INT,
1380 foldSbToStealChance INT,
1381 foldedSbToSteal INT,
1383 street1CBChance INT,
1385 street2CBChance INT,
1387 street3CBChance INT,
1389 street4CBChance INT,
1392 foldToStreet1CBChance INT,
1393 foldToStreet1CBDone INT,
1394 foldToStreet2CBChance INT,
1395 foldToStreet2CBDone INT,
1396 foldToStreet3CBChance INT,
1397 foldToStreet3CBDone INT,
1398 foldToStreet4CBChance INT,
1399 foldToStreet4CBDone INT,
1404 street1CheckCallRaiseChance INT,
1405 street1CheckCallRaiseDone INT,
1406 street2CheckCallRaiseChance INT,
1407 street2CheckCallRaiseDone INT,
1408 street3CheckCallRaiseChance INT,
1409 street3CheckCallRaiseDone INT,
1410 street4CheckCallRaiseChance INT,
1411 street4CheckCallRaiseDone INT,
1430 elif db_server
== 'postgresql':
1431 self
.query
['createHudCacheTable'] = """CREATE TABLE HudCache (
1432 id BIGSERIAL, PRIMARY KEY (id),
1433 gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
1434 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
1435 activeSeats SMALLINT,
1437 tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
1438 styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1441 wonWhenSeenStreet1 FLOAT,
1442 wonWhenSeenStreet2 FLOAT,
1443 wonWhenSeenStreet3 FLOAT,
1444 wonWhenSeenStreet4 FLOAT,
1449 street0CalledRaiseChance INT,
1450 street0CalledRaiseDone INT,
1451 street0_3BChance INT,
1453 street0_4BChance INT,
1455 street0_C4BChance INT,
1456 street0_C4BDone INT,
1457 street0_FoldTo3BChance INT,
1458 street0_FoldTo3BDone INT,
1459 street0_FoldTo4BChance INT,
1460 street0_FoldTo4BDone INT,
1461 street0_SqueezeChance INT,
1462 street0_SqueezeDone INT,
1464 raiseToStealChance INT,
1465 raiseToStealDone INT,
1478 otherRaisedStreet0 INT,
1479 otherRaisedStreet1 INT,
1480 otherRaisedStreet2 INT,
1481 otherRaisedStreet3 INT,
1482 otherRaisedStreet4 INT,
1483 foldToOtherRaisedStreet0 INT,
1484 foldToOtherRaisedStreet1 INT,
1485 foldToOtherRaisedStreet2 INT,
1486 foldToOtherRaisedStreet3 INT,
1487 foldToOtherRaisedStreet4 INT,
1489 raiseFirstInChance INT,
1491 foldBbToStealChance INT,
1492 foldedBbToSteal INT,
1493 foldSbToStealChance INT,
1494 foldedSbToSteal INT,
1496 street1CBChance INT,
1498 street2CBChance INT,
1500 street3CBChance INT,
1502 street4CBChance INT,
1505 foldToStreet1CBChance INT,
1506 foldToStreet1CBDone INT,
1507 foldToStreet2CBChance INT,
1508 foldToStreet2CBDone INT,
1509 foldToStreet3CBChance INT,
1510 foldToStreet3CBDone INT,
1511 foldToStreet4CBChance INT,
1512 foldToStreet4CBDone INT,
1517 street1CheckCallRaiseChance INT,
1518 street1CheckCallRaiseDone INT,
1519 street2CheckCallRaiseChance INT,
1520 street2CheckCallRaiseDone INT,
1521 street3CheckCallRaiseChance INT,
1522 street3CheckCallRaiseDone INT,
1523 street4CheckCallRaiseChance INT,
1524 street4CheckCallRaiseDone INT,
1542 elif db_server
== 'sqlite':
1543 self
.query
['createHudCacheTable'] = """CREATE TABLE HudCache (
1544 id INTEGER PRIMARY KEY,
1550 styleKey TEXT NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
1553 wonWhenSeenStreet1 REAL,
1554 wonWhenSeenStreet2 REAL,
1555 wonWhenSeenStreet3 REAL,
1556 wonWhenSeenStreet4 REAL,
1561 street0CalledRaiseChance INT,
1562 street0CalledRaiseDone INT,
1563 street0_3BChance INT,
1565 street0_4BChance INT,
1567 street0_C4BChance INT,
1568 street0_C4BDone INT,
1569 street0_FoldTo3BChance INT,
1570 street0_FoldTo3BDone INT,
1571 street0_FoldTo4BChance INT,
1572 street0_FoldTo4BDone INT,
1573 street0_SqueezeChance INT,
1574 street0_SqueezeDone INT,
1576 raiseToStealChance INT,
1577 raiseToStealDone INT,
1590 otherRaisedStreet0 INT,
1591 otherRaisedStreet1 INT,
1592 otherRaisedStreet2 INT,
1593 otherRaisedStreet3 INT,
1594 otherRaisedStreet4 INT,
1595 foldToOtherRaisedStreet0 INT,
1596 foldToOtherRaisedStreet1 INT,
1597 foldToOtherRaisedStreet2 INT,
1598 foldToOtherRaisedStreet3 INT,
1599 foldToOtherRaisedStreet4 INT,
1601 raiseFirstInChance INT,
1603 foldBbToStealChance INT,
1604 foldedBbToSteal INT,
1605 foldSbToStealChance INT,
1606 foldedSbToSteal INT,
1608 street1CBChance INT,
1610 street2CBChance INT,
1612 street3CBChance INT,
1614 street4CBChance INT,
1617 foldToStreet1CBChance INT,
1618 foldToStreet1CBDone INT,
1619 foldToStreet2CBChance INT,
1620 foldToStreet2CBDone INT,
1621 foldToStreet3CBChance INT,
1622 foldToStreet3CBDone INT,
1623 foldToStreet4CBChance INT,
1624 foldToStreet4CBDone INT,
1629 street1CheckCallRaiseChance INT,
1630 street1CheckCallRaiseDone INT,
1631 street2CheckCallRaiseChance INT,
1632 street2CheckCallRaiseDone INT,
1633 street3CheckCallRaiseChance INT,
1634 street3CheckCallRaiseDone INT,
1635 street4CheckCallRaiseChance INT,
1636 street4CheckCallRaiseDone INT,
1655 ################################
1657 ################################
1659 if db_server
== 'mysql':
1660 self
.query
['createCardsCacheTable'] = """CREATE TABLE CardsCache (
1661 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
1662 type char(4) NOT NULL,
1663 category varchar(9) NOT NULL,
1664 currency char(4) NOT NULL,
1665 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
1666 startCards SMALLINT NOT NULL,
1669 wonWhenSeenStreet1 FLOAT,
1670 wonWhenSeenStreet2 FLOAT,
1671 wonWhenSeenStreet3 FLOAT,
1672 wonWhenSeenStreet4 FLOAT,
1677 street0CalledRaiseChance INT,
1678 street0CalledRaiseDone INT,
1679 street0_3BChance INT,
1681 street0_4BChance INT,
1683 street0_C4BChance INT,
1684 street0_C4BDone INT,
1685 street0_FoldTo3BChance INT,
1686 street0_FoldTo3BDone INT,
1687 street0_FoldTo4BChance INT,
1688 street0_FoldTo4BDone INT,
1689 street0_SqueezeChance INT,
1690 street0_SqueezeDone INT,
1692 raiseToStealChance INT,
1693 raiseToStealDone INT,
1708 otherRaisedStreet0 INT,
1709 otherRaisedStreet1 INT,
1710 otherRaisedStreet2 INT,
1711 otherRaisedStreet3 INT,
1712 otherRaisedStreet4 INT,
1713 foldToOtherRaisedStreet0 INT,
1714 foldToOtherRaisedStreet1 INT,
1715 foldToOtherRaisedStreet2 INT,
1716 foldToOtherRaisedStreet3 INT,
1717 foldToOtherRaisedStreet4 INT,
1719 raiseFirstInChance INT,
1721 foldBbToStealChance INT,
1722 foldedBbToSteal INT,
1723 foldSbToStealChance INT,
1724 foldedSbToSteal INT,
1726 street1CBChance INT,
1728 street2CBChance INT,
1730 street3CBChance INT,
1732 street4CBChance INT,
1735 foldToStreet1CBChance INT,
1736 foldToStreet1CBDone INT,
1737 foldToStreet2CBChance INT,
1738 foldToStreet2CBDone INT,
1739 foldToStreet3CBChance INT,
1740 foldToStreet3CBDone INT,
1741 foldToStreet4CBChance INT,
1742 foldToStreet4CBDone INT,
1747 street1CheckCallRaiseChance INT,
1748 street1CheckCallRaiseDone INT,
1749 street2CheckCallRaiseChance INT,
1750 street2CheckCallRaiseDone INT,
1751 street3CheckCallRaiseChance INT,
1752 street3CheckCallRaiseDone INT,
1753 street4CheckCallRaiseChance INT,
1754 street4CheckCallRaiseDone INT,
1773 elif db_server
== 'postgresql':
1774 self
.query
['createCardsCacheTable'] = """CREATE TABLE CardsCache (
1775 id BIGSERIAL, PRIMARY KEY (id),
1776 type char(4) NOT NULL,
1777 category varchar(9) NOT NULL,
1778 currency char(4) NOT NULL,
1779 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
1780 startCards SMALLINT,
1783 wonWhenSeenStreet1 FLOAT,
1784 wonWhenSeenStreet2 FLOAT,
1785 wonWhenSeenStreet3 FLOAT,
1786 wonWhenSeenStreet4 FLOAT,
1791 street0CalledRaiseChance INT,
1792 street0CalledRaiseDone INT,
1793 street0_3BChance INT,
1795 street0_4BChance INT,
1797 street0_C4BChance INT,
1798 street0_C4BDone INT,
1799 street0_FoldTo3BChance INT,
1800 street0_FoldTo3BDone INT,
1801 street0_FoldTo4BChance INT,
1802 street0_FoldTo4BDone INT,
1803 street0_SqueezeChance INT,
1804 street0_SqueezeDone INT,
1806 raiseToStealChance INT,
1807 raiseToStealDone INT,
1820 otherRaisedStreet0 INT,
1821 otherRaisedStreet1 INT,
1822 otherRaisedStreet2 INT,
1823 otherRaisedStreet3 INT,
1824 otherRaisedStreet4 INT,
1825 foldToOtherRaisedStreet0 INT,
1826 foldToOtherRaisedStreet1 INT,
1827 foldToOtherRaisedStreet2 INT,
1828 foldToOtherRaisedStreet3 INT,
1829 foldToOtherRaisedStreet4 INT,
1831 raiseFirstInChance INT,
1833 foldBbToStealChance INT,
1834 foldedBbToSteal INT,
1835 foldSbToStealChance INT,
1836 foldedSbToSteal INT,
1838 street1CBChance INT,
1840 street2CBChance INT,
1842 street3CBChance INT,
1844 street4CBChance INT,
1847 foldToStreet1CBChance INT,
1848 foldToStreet1CBDone INT,
1849 foldToStreet2CBChance INT,
1850 foldToStreet2CBDone INT,
1851 foldToStreet3CBChance INT,
1852 foldToStreet3CBDone INT,
1853 foldToStreet4CBChance INT,
1854 foldToStreet4CBDone INT,
1859 street1CheckCallRaiseChance INT,
1860 street1CheckCallRaiseDone INT,
1861 street2CheckCallRaiseChance INT,
1862 street2CheckCallRaiseDone INT,
1863 street3CheckCallRaiseChance INT,
1864 street3CheckCallRaiseDone INT,
1865 street4CheckCallRaiseChance INT,
1866 street4CheckCallRaiseDone INT,
1884 elif db_server
== 'sqlite':
1885 self
.query
['createCardsCacheTable'] = """CREATE TABLE CardsCache (
1886 id INTEGER PRIMARY KEY,
1888 category TEXT NOT NULL,
1889 currency TEXT NOT NULL,
1894 wonWhenSeenStreet1 REAL,
1895 wonWhenSeenStreet2 REAL,
1896 wonWhenSeenStreet3 REAL,
1897 wonWhenSeenStreet4 REAL,
1902 street0CalledRaiseChance INT,
1903 street0CalledRaiseDone INT,
1904 street0_3BChance INT,
1906 street0_4BChance INT,
1908 street0_C4BChance INT,
1909 street0_C4BDone INT,
1910 street0_FoldTo3BChance INT,
1911 street0_FoldTo3BDone INT,
1912 street0_FoldTo4BChance INT,
1913 street0_FoldTo4BDone INT,
1914 street0_SqueezeChance INT,
1915 street0_SqueezeDone INT,
1917 raiseToStealChance INT,
1918 raiseToStealDone INT,
1931 otherRaisedStreet0 INT,
1932 otherRaisedStreet1 INT,
1933 otherRaisedStreet2 INT,
1934 otherRaisedStreet3 INT,
1935 otherRaisedStreet4 INT,
1936 foldToOtherRaisedStreet0 INT,
1937 foldToOtherRaisedStreet1 INT,
1938 foldToOtherRaisedStreet2 INT,
1939 foldToOtherRaisedStreet3 INT,
1940 foldToOtherRaisedStreet4 INT,
1942 raiseFirstInChance INT,
1944 foldBbToStealChance INT,
1945 foldedBbToSteal INT,
1946 foldSbToStealChance INT,
1947 foldedSbToSteal INT,
1949 street1CBChance INT,
1951 street2CBChance INT,
1953 street3CBChance INT,
1955 street4CBChance INT,
1958 foldToStreet1CBChance INT,
1959 foldToStreet1CBDone INT,
1960 foldToStreet2CBChance INT,
1961 foldToStreet2CBDone INT,
1962 foldToStreet3CBChance INT,
1963 foldToStreet3CBDone INT,
1964 foldToStreet4CBChance INT,
1965 foldToStreet4CBDone INT,
1970 street1CheckCallRaiseChance INT,
1971 street1CheckCallRaiseDone INT,
1972 street2CheckCallRaiseChance INT,
1973 street2CheckCallRaiseDone INT,
1974 street3CheckCallRaiseChance INT,
1975 street3CheckCallRaiseDone INT,
1976 street4CheckCallRaiseChance INT,
1977 street4CheckCallRaiseDone INT,
1996 ################################
1997 # Create PositionsCache
1998 ################################
2000 if db_server
== 'mysql':
2001 self
.query
['createPositionsCacheTable'] = """CREATE TABLE PositionsCache (
2002 id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
2003 type char(4) NOT NULL,
2004 base char(4) NOT NULL,
2005 category varchar(9) NOT NULL,
2006 currency char(4) NOT NULL,
2007 maxSeats TINYINT NOT NULL,
2008 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
2009 activeSeats SMALLINT NOT NULL,
2013 wonWhenSeenStreet1 FLOAT,
2014 wonWhenSeenStreet2 FLOAT,
2015 wonWhenSeenStreet3 FLOAT,
2016 wonWhenSeenStreet4 FLOAT,
2021 street0CalledRaiseChance INT,
2022 street0CalledRaiseDone INT,
2023 street0_3BChance INT,
2025 street0_4BChance INT,
2027 street0_C4BChance INT,
2028 street0_C4BDone INT,
2029 street0_FoldTo3BChance INT,
2030 street0_FoldTo3BDone INT,
2031 street0_FoldTo4BChance INT,
2032 street0_FoldTo4BDone INT,
2033 street0_SqueezeChance INT,
2034 street0_SqueezeDone INT,
2036 raiseToStealChance INT,
2037 raiseToStealDone INT,
2052 otherRaisedStreet0 INT,
2053 otherRaisedStreet1 INT,
2054 otherRaisedStreet2 INT,
2055 otherRaisedStreet3 INT,
2056 otherRaisedStreet4 INT,
2057 foldToOtherRaisedStreet0 INT,
2058 foldToOtherRaisedStreet1 INT,
2059 foldToOtherRaisedStreet2 INT,
2060 foldToOtherRaisedStreet3 INT,
2061 foldToOtherRaisedStreet4 INT,
2063 raiseFirstInChance INT,
2065 foldBbToStealChance INT,
2066 foldedBbToSteal INT,
2067 foldSbToStealChance INT,
2068 foldedSbToSteal INT,
2070 street1CBChance INT,
2072 street2CBChance INT,
2074 street3CBChance INT,
2076 street4CBChance INT,
2079 foldToStreet1CBChance INT,
2080 foldToStreet1CBDone INT,
2081 foldToStreet2CBChance INT,
2082 foldToStreet2CBDone INT,
2083 foldToStreet3CBChance INT,
2084 foldToStreet3CBDone INT,
2085 foldToStreet4CBChance INT,
2086 foldToStreet4CBDone INT,
2091 street1CheckCallRaiseChance INT,
2092 street1CheckCallRaiseDone INT,
2093 street2CheckCallRaiseChance INT,
2094 street2CheckCallRaiseDone INT,
2095 street3CheckCallRaiseChance INT,
2096 street3CheckCallRaiseDone INT,
2097 street4CheckCallRaiseChance INT,
2098 street4CheckCallRaiseDone INT,
2117 elif db_server
== 'postgresql':
2118 self
.query
['createPositionsCacheTable'] = """CREATE TABLE PositionsCache (
2119 id BIGSERIAL, PRIMARY KEY (id),
2120 type char(4) NOT NULL,
2121 base char(4) NOT NULL,
2122 category varchar(9) NOT NULL,
2123 currency char(4) NOT NULL,
2124 maxSeats SMALLINT NOT NULL,
2125 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
2126 activeSeats SMALLINT,
2130 wonWhenSeenStreet1 FLOAT,
2131 wonWhenSeenStreet2 FLOAT,
2132 wonWhenSeenStreet3 FLOAT,
2133 wonWhenSeenStreet4 FLOAT,
2138 street0CalledRaiseChance INT,
2139 street0CalledRaiseDone INT,
2140 street0_3BChance INT,
2142 street0_4BChance INT,
2144 street0_C4BChance INT,
2145 street0_C4BDone INT,
2146 street0_FoldTo3BChance INT,
2147 street0_FoldTo3BDone INT,
2148 street0_FoldTo4BChance INT,
2149 street0_FoldTo4BDone INT,
2150 street0_SqueezeChance INT,
2151 street0_SqueezeDone INT,
2153 raiseToStealChance INT,
2154 raiseToStealDone INT,
2167 otherRaisedStreet0 INT,
2168 otherRaisedStreet1 INT,
2169 otherRaisedStreet2 INT,
2170 otherRaisedStreet3 INT,
2171 otherRaisedStreet4 INT,
2172 foldToOtherRaisedStreet0 INT,
2173 foldToOtherRaisedStreet1 INT,
2174 foldToOtherRaisedStreet2 INT,
2175 foldToOtherRaisedStreet3 INT,
2176 foldToOtherRaisedStreet4 INT,
2178 raiseFirstInChance INT,
2180 foldBbToStealChance INT,
2181 foldedBbToSteal INT,
2182 foldSbToStealChance INT,
2183 foldedSbToSteal INT,
2185 street1CBChance INT,
2187 street2CBChance INT,
2189 street3CBChance INT,
2191 street4CBChance INT,
2194 foldToStreet1CBChance INT,
2195 foldToStreet1CBDone INT,
2196 foldToStreet2CBChance INT,
2197 foldToStreet2CBDone INT,
2198 foldToStreet3CBChance INT,
2199 foldToStreet3CBDone INT,
2200 foldToStreet4CBChance INT,
2201 foldToStreet4CBDone INT,
2206 street1CheckCallRaiseChance INT,
2207 street1CheckCallRaiseDone INT,
2208 street2CheckCallRaiseChance INT,
2209 street2CheckCallRaiseDone INT,
2210 street3CheckCallRaiseChance INT,
2211 street3CheckCallRaiseDone INT,
2212 street4CheckCallRaiseChance INT,
2213 street4CheckCallRaiseDone INT,
2231 elif db_server
== 'sqlite':
2232 self
.query
['createPositionsCacheTable'] = """CREATE TABLE PositionsCache (
2233 id INTEGER PRIMARY KEY,
2236 category TEXT NOT NULL,
2237 currency TEXT NOT NULL,
2238 maxSeats INT NOT NULL,
2244 wonWhenSeenStreet1 REAL,
2245 wonWhenSeenStreet2 REAL,
2246 wonWhenSeenStreet3 REAL,
2247 wonWhenSeenStreet4 REAL,
2252 street0CalledRaiseChance INT,
2253 street0CalledRaiseDone INT,
2254 street0_3BChance INT,
2256 street0_4BChance INT,
2258 street0_C4BChance INT,
2259 street0_C4BDone INT,
2260 street0_FoldTo3BChance INT,
2261 street0_FoldTo3BDone INT,
2262 street0_FoldTo4BChance INT,
2263 street0_FoldTo4BDone INT,
2264 street0_SqueezeChance INT,
2265 street0_SqueezeDone INT,
2267 raiseToStealChance INT,
2268 raiseToStealDone INT,
2281 otherRaisedStreet0 INT,
2282 otherRaisedStreet1 INT,
2283 otherRaisedStreet2 INT,
2284 otherRaisedStreet3 INT,
2285 otherRaisedStreet4 INT,
2286 foldToOtherRaisedStreet0 INT,
2287 foldToOtherRaisedStreet1 INT,
2288 foldToOtherRaisedStreet2 INT,
2289 foldToOtherRaisedStreet3 INT,
2290 foldToOtherRaisedStreet4 INT,
2292 raiseFirstInChance INT,
2294 foldBbToStealChance INT,
2295 foldedBbToSteal INT,
2296 foldSbToStealChance INT,
2297 foldedSbToSteal INT,
2299 street1CBChance INT,
2301 street2CBChance INT,
2303 street3CBChance INT,
2305 street4CBChance INT,
2308 foldToStreet1CBChance INT,
2309 foldToStreet1CBDone INT,
2310 foldToStreet2CBChance INT,
2311 foldToStreet2CBDone INT,
2312 foldToStreet3CBChance INT,
2313 foldToStreet3CBDone INT,
2314 foldToStreet4CBChance INT,
2315 foldToStreet4CBDone INT,
2320 street1CheckCallRaiseChance INT,
2321 street1CheckCallRaiseDone INT,
2322 street2CheckCallRaiseChance INT,
2323 street2CheckCallRaiseDone INT,
2324 street3CheckCallRaiseChance INT,
2325 street3CheckCallRaiseDone INT,
2326 street4CheckCallRaiseChance INT,
2327 street4CheckCallRaiseDone INT,
2347 ################################
2348 # Create SessionsCache
2349 ################################
2351 if db_server
== 'mysql':
2352 self
.query
['createSessionsCacheTable'] = """CREATE TABLE SessionsCache (
2353 id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
2354 sessionStart DATETIME NOT NULL,
2355 sessionEnd DATETIME NOT NULL)
2359 elif db_server
== 'postgresql':
2360 self
.query
['createSessionsCacheTable'] = """CREATE TABLE SessionsCache (
2361 id SERIAL, PRIMARY KEY (id),
2362 sessionStart timestamp without time zone NOT NULL,
2363 sessionEnd timestamp without time zone NOT NULL)
2366 elif db_server
== 'sqlite':
2367 self
.query
['createSessionsCacheTable'] = """CREATE TABLE SessionsCache (
2368 id INTEGER PRIMARY KEY,
2369 sessionStart timestamp NOT NULL,
2370 sessionEnd timestamp NOT NULL)
2373 ################################
2375 ################################
2377 if db_server
== 'mysql':
2378 self
.query
['createGamesCacheTable'] = """CREATE TABLE GamesCache (
2379 id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
2380 sessionId INT UNSIGNED, FOREIGN KEY (sessionId) REFERENCES SessionsCache(id),
2381 gameStart DATETIME NOT NULL,
2382 gameEnd DATETIME NOT NULL,
2383 date CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
2384 gametypeId SMALLINT UNSIGNED, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
2385 playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
2386 played INT NOT NULL,
2390 showdownWinnings INT,
2391 nonShowdownWinnings INT,
2396 elif db_server
== 'postgresql':
2397 self
.query
['createGamesCacheTable'] = """CREATE TABLE GamesCache (
2398 id SERIAL, PRIMARY KEY (id),
2399 sessionId INT, FOREIGN KEY (sessionId) REFERENCES SessionsCache(id),
2400 gameStart timestamp without time zone NOT NULL,
2401 gameEnd timestamp without time zone NOT NULL,
2402 date CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
2403 gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
2404 playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
2409 showdownWinnings INT,
2410 nonShowdownWinnings INT,
2414 elif db_server
== 'sqlite':
2415 self
.query
['createGamesCacheTable'] = """CREATE TABLE GamesCache (
2416 id INTEGER PRIMARY KEY,
2418 gameStart timestamp NOT NULL,
2419 gameEnd timestamp NOT NULL,
2420 date TEXT NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
2428 showdownWinnings INT,
2429 nonShowdownWinnings INT,
2433 if db_server
== 'mysql':
2434 self
.query
['addTourneyIndex'] = """ALTER TABLE Tourneys ADD UNIQUE INDEX siteTourneyNo(siteTourneyNo, tourneyTypeId)"""
2435 elif db_server
== 'postgresql':
2436 self
.query
['addTourneyIndex'] = """CREATE UNIQUE INDEX siteTourneyNo ON Tourneys (siteTourneyNo, tourneyTypeId)"""
2437 elif db_server
== 'sqlite':
2438 self
.query
['addTourneyIndex'] = """CREATE UNIQUE INDEX siteTourneyNo ON Tourneys (siteTourneyNo, tourneyTypeId)"""
2440 if db_server
== 'mysql':
2441 self
.query
['addHandsIndex'] = """ALTER TABLE Hands ADD UNIQUE INDEX siteHandNo(siteHandNo, gametypeId)"""
2442 elif db_server
== 'postgresql':
2443 self
.query
['addHandsIndex'] = """CREATE UNIQUE INDEX siteHandNo ON Hands (siteHandNo, gametypeId)"""
2444 elif db_server
== 'sqlite':
2445 self
.query
['addHandsIndex'] = """CREATE UNIQUE INDEX siteHandNo ON Hands (siteHandNo, gametypeId)"""
2447 if db_server
== 'mysql':
2448 self
.query
['addPlayersIndex'] = """ALTER TABLE Players ADD UNIQUE INDEX name(name, siteId)"""
2449 elif db_server
== 'postgresql':
2450 self
.query
['addPlayersIndex'] = """CREATE UNIQUE INDEX name ON Players (name, siteId)"""
2451 elif db_server
== 'sqlite':
2452 self
.query
['addPlayersIndex'] = """CREATE UNIQUE INDEX name ON Players (name, siteId)"""
2454 if db_server
== 'mysql':
2455 self
.query
['addTPlayersIndex'] = """ALTER TABLE TourneysPlayers ADD UNIQUE INDEX _tourneyId(tourneyId, playerId)"""
2456 elif db_server
== 'postgresql':
2457 self
.query
['addTPlayersIndex'] = """CREATE UNIQUE INDEX tourneyId ON TourneysPlayers (tourneyId, playerId)"""
2458 elif db_server
== 'sqlite':
2459 self
.query
['addTPlayersIndex'] = """CREATE UNIQUE INDEX tourneyId ON TourneysPlayers (tourneyId, playerId)"""
2461 self
.query
['addHudCacheCompundIndex'] = """CREATE UNIQUE INDEX HudCache_Compound_idx ON HudCache(gametypeId, playerId, activeSeats, position, tourneyTypeId, styleKey)"""
2462 self
.query
['addCardsCacheCompundIndex'] = """CREATE UNIQUE INDEX CardsCache_Compound_idx ON CardsCache(type, category, currency, playerId, startCards)"""
2463 self
.query
['addPositionsCacheCompundIndex'] = """CREATE UNIQUE INDEX PositionsCache_Compound_idx ON PositionsCache(type, base, category, currency, maxSeats, playerId, activeSeats, position)"""
2465 self
.query
['get_last_hand'] = "select max(id) from Hands"
2467 self
.query
['get_last_date'] = "SELECT MAX(startTime) FROM Hands"
2469 self
.query
['get_first_date'] = "SELECT MIN(startTime) FROM Hands"
2471 self
.query
['get_player_id'] = """
2472 select Players.id AS player_id
2474 where Players.name = %s
2476 and Players.siteId = Sites.id
2479 self
.query
['get_player_names'] = """
2482 where lower(p.name) like lower(%s)
2483 and (p.siteId = %s or %s = -1)
2486 self
.query
['get_gameinfo_from_hid'] = """
2494 round(g.smallBlind / 100.0,2),
2495 round(g.bigBlind / 100.0,2),
2496 round(g.smallBet / 100.0,2),
2497 round(g.bigBet / 100.0,2),
2507 and g.id = h.gametypeid
2508 and hp.handid = h.id
2509 and p.id = hp.playerid
2514 self
.query
['get_stats_from_hand'] = """
2515 SELECT hc.playerId AS player_id,
2517 p.name AS screen_name,
2519 sum(hc.street0VPI) AS vpip,
2520 sum(hc.street0Aggr) AS pfr,
2521 sum(hc.street0CalledRaiseChance) AS CAR_opp_0,
2522 sum(hc.street0CalledRaiseDone) AS CAR_0,
2523 sum(hc.street0_3BChance) AS TB_opp_0,
2524 sum(hc.street0_3BDone) AS TB_0,
2525 sum(hc.street0_4BChance) AS FB_opp_0,
2526 sum(hc.street0_4BDone) AS FB_0,
2527 sum(hc.street0_C4BChance) AS CFB_opp_0,
2528 sum(hc.street0_C4BDone) AS CFB_0,
2529 sum(hc.street0_FoldTo3BChance) AS F3B_opp_0,
2530 sum(hc.street0_FoldTo3BDone) AS F3B_0,
2531 sum(hc.street0_FoldTo4BChance) AS F4B_opp_0,
2532 sum(hc.street0_FoldTo4BDone) AS F4B_0,
2533 sum(hc.street0_SqueezeChance) AS SQZ_opp_0,
2534 sum(hc.street0_SqueezeDone) AS SQZ_0,
2535 sum(hc.raiseToStealChance) AS RTS_opp,
2536 sum(hc.raiseToStealDone) AS RTS,
2537 sum(hc.success_Steal) AS SUC_ST,
2538 sum(hc.street1Seen) AS saw_f,
2539 sum(hc.street1Seen) AS saw_1,
2540 sum(hc.street2Seen) AS saw_2,
2541 sum(hc.street3Seen) AS saw_3,
2542 sum(hc.street4Seen) AS saw_4,
2543 sum(hc.sawShowdown) AS sd,
2544 sum(hc.street1Aggr) AS aggr_1,
2545 sum(hc.street2Aggr) AS aggr_2,
2546 sum(hc.street3Aggr) AS aggr_3,
2547 sum(hc.street4Aggr) AS aggr_4,
2548 sum(hc.otherRaisedStreet1) AS was_raised_1,
2549 sum(hc.otherRaisedStreet2) AS was_raised_2,
2550 sum(hc.otherRaisedStreet3) AS was_raised_3,
2551 sum(hc.otherRaisedStreet4) AS was_raised_4,
2552 sum(hc.foldToOtherRaisedStreet1) AS f_freq_1,
2553 sum(hc.foldToOtherRaisedStreet2) AS f_freq_2,
2554 sum(hc.foldToOtherRaisedStreet3) AS f_freq_3,
2555 sum(hc.foldToOtherRaisedStreet4) AS f_freq_4,
2556 sum(hc.wonWhenSeenStreet1) AS w_w_s_1,
2557 sum(hc.wonAtSD) AS wmsd,
2558 sum(case hc.position
2559 when 'S' then hc.raiseFirstInChance
2560 when '0' then hc.raiseFirstInChance
2561 when '1' then hc.raiseFirstInChance
2564 sum(case hc.position
2565 when 'S' then hc.raisedFirstIn
2566 when '0' then hc.raisedFirstIn
2567 when '1' then hc.raisedFirstIn
2570 sum(hc.foldSbToStealChance) AS SBstolen,
2571 sum(hc.foldedSbToSteal) AS SBnotDef,
2572 sum(hc.foldBbToStealChance) AS BBstolen,
2573 sum(hc.foldedBbToSteal) AS BBnotDef,
2574 sum(hc.street1CBChance) AS CB_opp_1,
2575 sum(hc.street1CBDone) AS CB_1,
2576 sum(hc.street2CBChance) AS CB_opp_2,
2577 sum(hc.street2CBDone) AS CB_2,
2578 sum(hc.street3CBChance) AS CB_opp_3,
2579 sum(hc.street3CBDone) AS CB_3,
2580 sum(hc.street4CBChance) AS CB_opp_4,
2581 sum(hc.street4CBDone) AS CB_4,
2582 sum(hc.foldToStreet1CBChance) AS f_cb_opp_1,
2583 sum(hc.foldToStreet1CBDone) AS f_cb_1,
2584 sum(hc.foldToStreet2CBChance) AS f_cb_opp_2,
2585 sum(hc.foldToStreet2CBDone) AS f_cb_2,
2586 sum(hc.foldToStreet3CBChance) AS f_cb_opp_3,
2587 sum(hc.foldToStreet3CBDone) AS f_cb_3,
2588 sum(hc.foldToStreet4CBChance) AS f_cb_opp_4,
2589 sum(hc.foldToStreet4CBDone) AS f_cb_4,
2590 sum(hc.totalProfit) AS net,
2591 sum(gt.bigblind) AS bigblind,
2592 sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1,
2593 sum(hc.street1CheckCallRaiseDone) AS ccr_1,
2594 sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2,
2595 sum(hc.street2CheckCallRaiseDone) AS ccr_2,
2596 sum(hc.street3CheckCallRaiseChance) AS ccr_opp_3,
2597 sum(hc.street3CheckCallRaiseDone) AS ccr_3,
2598 sum(hc.street4CheckCallRaiseChance) AS ccr_opp_4,
2599 sum(hc.street4CheckCallRaiseDone) AS ccr_4
2600 sum(hc.street0Calls) AS call_0,
2601 sum(hc.street1Calls) AS call_1,
2602 sum(hc.street2Calls) AS call_2,
2603 sum(hc.street3Calls) AS call_3,
2604 sum(hc.street4Calls) AS call_4,
2605 sum(hc.street0Bets) AS bet_0,
2606 sum(hc.street1Bets) AS bet_1,
2607 sum(hc.street2Bets) AS bet_2,
2608 sum(hc.street3Bets) AS bet_3,
2609 sum(hc.street4Bets) AS bet_4,
2610 sum(hc.street0Raises) AS raise_0,
2611 sum(hc.street1Raises) AS raise_1,
2612 sum(hc.street2Raises) AS raise_2,
2613 sum(hc.street3Raises) AS raise_3,
2614 sum(hc.street4Raises) AS raise_4
2616 INNER JOIN HandsPlayers hp ON (hp.handId = h.id)
2617 INNER JOIN HudCache hc ON ( hc.PlayerId = hp.PlayerId+0
2618 AND hc.gametypeId+0 = h.gametypeId+0)
2619 INNER JOIN Players p ON (p.id = hp.PlayerId+0)
2620 INNER JOIN Gametypes gt ON (gt.id = hc.gametypeId)
2622 AND hc.styleKey > %s
2623 /* styleKey is currently 'd' (for date) followed by a yyyymmdd
2624 date key. Set it to 0000000 or similar to get all records */
2625 /* also check activeseats here even if only 3 groups eg 2-3/4-6/7+
2626 e.g. could use a multiplier:
2627 AND h.seats > X / 1.25 and hp.seats < X * 1.25
2628 where X is the number of active players at the current table (and
2629 1.25 would be a config value so user could change it)
2631 GROUP BY hc.PlayerId, hp.seatNo, p.name
2632 ORDER BY hc.PlayerId, hp.seatNo, p.name
2635 # same as above except stats are aggregated for all blind/limit levels
2636 self
.query
['get_stats_from_hand_aggregated'] = """
2637 /* explain query plan */
2638 SELECT hc.playerId AS player_id,
2639 max(case when hc.gametypeId = h.gametypeId
2643 p.name AS screen_name,
2645 sum(hc.street0VPI) AS vpip,
2646 sum(hc.street0Aggr) AS pfr,
2647 sum(hc.street0CalledRaiseChance) AS CAR_opp_0,
2648 sum(hc.street0CalledRaiseDone) AS CAR_0,
2649 sum(hc.street0_3BChance) AS TB_opp_0,
2650 sum(hc.street0_3BDone) AS TB_0,
2651 sum(hc.street0_4BChance) AS FB_opp_0,
2652 sum(hc.street0_4BDone) AS FB_0,
2653 sum(hc.street0_C4BChance) AS CFB_opp_0,
2654 sum(hc.street0_C4BDone) AS CFB_0,
2655 sum(hc.street0_FoldTo3BChance) AS F3B_opp_0,
2656 sum(hc.street0_FoldTo3BDone) AS F3B_0,
2657 sum(hc.street0_FoldTo4BChance) AS F4B_opp_0,
2658 sum(hc.street0_FoldTo4BDone) AS F4B_0,
2659 sum(hc.street0_SqueezeChance) AS SQZ_opp_0,
2660 sum(hc.street0_SqueezeDone) AS SQZ_0,
2661 sum(hc.raiseToStealChance) AS RTS_opp,
2662 sum(hc.raiseToStealDone) AS RTS,
2663 sum(hc.success_Steal) AS SUC_ST,
2664 sum(hc.street1Seen) AS saw_f,
2665 sum(hc.street1Seen) AS saw_1,
2666 sum(hc.street2Seen) AS saw_2,
2667 sum(hc.street3Seen) AS saw_3,
2668 sum(hc.street4Seen) AS saw_4,
2669 sum(hc.sawShowdown) AS sd,
2670 sum(hc.street1Aggr) AS aggr_1,
2671 sum(hc.street2Aggr) AS aggr_2,
2672 sum(hc.street3Aggr) AS aggr_3,
2673 sum(hc.street4Aggr) AS aggr_4,
2674 sum(hc.otherRaisedStreet1) AS was_raised_1,
2675 sum(hc.otherRaisedStreet2) AS was_raised_2,
2676 sum(hc.otherRaisedStreet3) AS was_raised_3,
2677 sum(hc.otherRaisedStreet4) AS was_raised_4,
2678 sum(hc.foldToOtherRaisedStreet1) AS f_freq_1,
2679 sum(hc.foldToOtherRaisedStreet2) AS f_freq_2,
2680 sum(hc.foldToOtherRaisedStreet3) AS f_freq_3,
2681 sum(hc.foldToOtherRaisedStreet4) AS f_freq_4,
2682 sum(hc.wonWhenSeenStreet1) AS w_w_s_1,
2683 sum(hc.wonAtSD) AS wmsd,
2684 sum(hc.raiseFirstInChance) AS steal_opp,
2685 sum(hc.raisedFirstIn) AS steal,
2686 sum(hc.foldSbToStealChance) AS SBstolen,
2687 sum(hc.foldedSbToSteal) AS SBnotDef,
2688 sum(hc.foldBbToStealChance) AS BBstolen,
2689 sum(hc.foldedBbToSteal) AS BBnotDef,
2690 sum(hc.street1CBChance) AS CB_opp_1,
2691 sum(hc.street1CBDone) AS CB_1,
2692 sum(hc.street2CBChance) AS CB_opp_2,
2693 sum(hc.street2CBDone) AS CB_2,
2694 sum(hc.street3CBChance) AS CB_opp_3,
2695 sum(hc.street3CBDone) AS CB_3,
2696 sum(hc.street4CBChance) AS CB_opp_4,
2697 sum(hc.street4CBDone) AS CB_4,
2698 sum(hc.foldToStreet1CBChance) AS f_cb_opp_1,
2699 sum(hc.foldToStreet1CBDone) AS f_cb_1,
2700 sum(hc.foldToStreet2CBChance) AS f_cb_opp_2,
2701 sum(hc.foldToStreet2CBDone) AS f_cb_2,
2702 sum(hc.foldToStreet3CBChance) AS f_cb_opp_3,
2703 sum(hc.foldToStreet3CBDone) AS f_cb_3,
2704 sum(hc.foldToStreet4CBChance) AS f_cb_opp_4,
2705 sum(hc.foldToStreet4CBDone) AS f_cb_4,
2706 sum(hc.totalProfit) AS net,
2707 sum(gt.bigblind) AS bigblind,
2708 sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1,
2709 sum(hc.street1CheckCallRaiseDone) AS ccr_1,
2710 sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2,
2711 sum(hc.street2CheckCallRaiseDone) AS ccr_2,
2712 sum(hc.street3CheckCallRaiseChance) AS ccr_opp_3,
2713 sum(hc.street3CheckCallRaiseDone) AS ccr_3,
2714 sum(hc.street4CheckCallRaiseChance) AS ccr_opp_4,
2715 sum(hc.street4CheckCallRaiseDone) AS ccr_4,
2716 sum(hc.street0Calls) AS call_0,
2717 sum(hc.street1Calls) AS call_1,
2718 sum(hc.street2Calls) AS call_2,
2719 sum(hc.street3Calls) AS call_3,
2720 sum(hc.street4Calls) AS call_4,
2721 sum(hc.street0Bets) AS bet_0,
2722 sum(hc.street1Bets) AS bet_1,
2723 sum(hc.street2Bets) AS bet_2,
2724 sum(hc.street3Bets) AS bet_3,
2725 sum(hc.street4Bets) AS bet_4,
2726 sum(hc.street0Raises) AS raise_0,
2727 sum(hc.street1Raises) AS raise_1,
2728 sum(hc.street2Raises) AS raise_2,
2729 sum(hc.street3Raises) AS raise_3,
2730 sum(hc.street4Raises) AS raise_4
2732 INNER JOIN HandsPlayers hp ON (hp.handId = h.id)
2733 INNER JOIN HudCache hc ON (hc.playerId = hp.playerId)
2734 INNER JOIN Players p ON (p.id = hc.playerId)
2735 INNER JOIN Gametypes gt ON (gt.id = hc.gametypeId)
2737 AND ( /* 2 separate parts for hero and opponents */
2739 AND hc.styleKey > %s
2740 AND hc.gametypeId+0 in
2741 (SELECT gt1.id from Gametypes gt1, Gametypes gt2
2742 WHERE gt1.siteid = gt2.siteid /* find gametypes where these match: */
2743 AND gt1.type = gt2.type /* ring/tourney */
2744 AND gt1.category = gt2.category /* holdem/stud*/
2745 AND gt1.limittype = gt2.limittype /* fl/nl */
2746 AND gt1.bigblind <= gt2.bigblind * %s /* bigblind similar size */
2747 AND gt1.bigblind >= gt2.bigblind / %s
2748 AND gt2.id = h.gametypeId)
2749 AND hc.activeSeats between %s and %s
2753 AND hc.styleKey > %s
2754 AND hc.gametypeId+0 in
2755 (SELECT gt1.id from Gametypes gt1, Gametypes gt2
2756 WHERE gt1.siteid = gt2.siteid /* find gametypes where these match: */
2757 AND gt1.type = gt2.type /* ring/tourney */
2758 AND gt1.category = gt2.category /* holdem/stud*/
2759 AND gt1.limittype = gt2.limittype /* fl/nl */
2760 AND gt1.bigblind <= gt2.bigblind * %s /* bigblind similar size */
2761 AND gt1.bigblind >= gt2.bigblind / %s
2762 AND gt2.id = h.gametypeId)
2763 AND hc.activeSeats between %s and %s
2766 GROUP BY hc.PlayerId, p.name
2767 ORDER BY hc.PlayerId, p.name
2769 # NOTES on above cursor:
2770 # - Do NOT include %s inside query in a comment - the db api thinks
2771 # they are actual arguments.
2772 # - styleKey is currently 'd' (for date) followed by a yyyymmdd
2773 # date key. Set it to 0000000 or similar to get all records
2774 # Could also check activeseats here even if only 3 groups eg 2-3/4-6/7+
2775 # e.g. could use a multiplier:
2776 # AND h.seats > %s / 1.25 and hp.seats < %s * 1.25
2777 # where %s is the number of active players at the current table (and
2778 # 1.25 would be a config value so user could change it)
2780 if db_server
== 'mysql':
2781 self
.query
['get_stats_from_hand_session'] = """
2782 SELECT hp.playerId AS player_id, /* playerId and seats must */
2783 h.seats AS seats, /* be first and second field */
2784 hp.handId AS hand_id,
2786 p.name AS screen_name,
2788 cast(hp2.street0VPI as <signed>integer) AS vpip,
2789 cast(hp2.street0Aggr as <signed>integer) AS pfr,
2790 cast(hp2.street0CalledRaiseChance as <signed>integer) AS CAR_opp_0,
2791 cast(hp2.street0CalledRaiseDone as <signed>integer) AS CAR_0,
2792 cast(hp2.street0_3BChance as <signed>integer) AS TB_opp_0,
2793 cast(hp2.street0_3BDone as <signed>integer) AS TB_0,
2794 cast(hp2.street0_4BChance as <signed>integer) AS FB_opp_0,
2795 cast(hp2.street0_4BDone as <signed>integer) AS FB_0,
2796 cast(hp2.street0_C4BChance as <signed>integer) AS CFB_opp_0,
2797 cast(hp2.street0_C4BDone as <signed>integer) AS CFB_0,
2798 cast(hp2.street0_FoldTo3BChance as <signed>integer) AS F3B_opp_0,
2799 cast(hp2.street0_FoldTo3BDone as <signed>integer) AS F3B_0,
2800 cast(hp2.street0_FoldTo4BChance as <signed>integer) AS F4B_opp_0,
2801 cast(hp2.street0_FoldTo4BDone as <signed>integer) AS F4B_0,
2802 cast(hp2.street0_SqueezeChance as <signed>integer) AS SQZ_opp_0,
2803 cast(hp2.street0_SqueezeDone as <signed>integer) AS SQZ_0,
2804 cast(hp2.raiseToStealChance as <signed>integer) AS RTS_opp,
2805 cast(hp2.raiseToStealDone as <signed>integer) AS RTS,
2806 cast(hp2.success_Steal as <signed>integer) AS SUC_ST,
2807 cast(hp2.street1Seen as <signed>integer) AS saw_f,
2808 cast(hp2.street1Seen as <signed>integer) AS saw_1,
2809 cast(hp2.street2Seen as <signed>integer) AS saw_2,
2810 cast(hp2.street3Seen as <signed>integer) AS saw_3,
2811 cast(hp2.street4Seen as <signed>integer) AS saw_4,
2812 cast(hp2.sawShowdown as <signed>integer) AS sd,
2813 cast(hp2.street1Aggr as <signed>integer) AS aggr_1,
2814 cast(hp2.street2Aggr as <signed>integer) AS aggr_2,
2815 cast(hp2.street3Aggr as <signed>integer) AS aggr_3,
2816 cast(hp2.street4Aggr as <signed>integer) AS aggr_4,
2817 cast(hp2.otherRaisedStreet1 as <signed>integer) AS was_raised_1,
2818 cast(hp2.otherRaisedStreet2 as <signed>integer) AS was_raised_2,
2819 cast(hp2.otherRaisedStreet3 as <signed>integer) AS was_raised_3,
2820 cast(hp2.otherRaisedStreet4 as <signed>integer) AS was_raised_4,
2821 cast(hp2.foldToOtherRaisedStreet1 as <signed>integer) AS f_freq_1,
2822 cast(hp2.foldToOtherRaisedStreet2 as <signed>integer) AS f_freq_2,
2823 cast(hp2.foldToOtherRaisedStreet3 as <signed>integer) AS f_freq_3,
2824 cast(hp2.foldToOtherRaisedStreet4 as <signed>integer) AS f_freq_4,
2825 cast(hp2.wonWhenSeenStreet1 as <signed>integer) AS w_w_s_1,
2826 cast(hp2.wonAtSD as <signed>integer) AS wmsd,
2827 cast(hp2.raiseFirstInChance as <signed>integer) AS steal_opp,
2828 cast(hp2.raisedFirstIn as <signed>integer) AS steal,
2829 cast(hp2.foldSbToStealChance as <signed>integer) AS SBstolen,
2830 cast(hp2.foldedSbToSteal as <signed>integer) AS SBnotDef,
2831 cast(hp2.foldBbToStealChance as <signed>integer) AS BBstolen,
2832 cast(hp2.foldedBbToSteal as <signed>integer) AS BBnotDef,
2833 cast(hp2.street1CBChance as <signed>integer) AS CB_opp_1,
2834 cast(hp2.street1CBDone as <signed>integer) AS CB_1,
2835 cast(hp2.street2CBChance as <signed>integer) AS CB_opp_2,
2836 cast(hp2.street2CBDone as <signed>integer) AS CB_2,
2837 cast(hp2.street3CBChance as <signed>integer) AS CB_opp_3,
2838 cast(hp2.street3CBDone as <signed>integer) AS CB_3,
2839 cast(hp2.street4CBChance as <signed>integer) AS CB_opp_4,
2840 cast(hp2.street4CBDone as <signed>integer) AS CB_4,
2841 cast(hp2.foldToStreet1CBChance as <signed>integer) AS f_cb_opp_1,
2842 cast(hp2.foldToStreet1CBDone as <signed>integer) AS f_cb_1,
2843 cast(hp2.foldToStreet2CBChance as <signed>integer) AS f_cb_opp_2,
2844 cast(hp2.foldToStreet2CBDone as <signed>integer) AS f_cb_2,
2845 cast(hp2.foldToStreet3CBChance as <signed>integer) AS f_cb_opp_3,
2846 cast(hp2.foldToStreet3CBDone as <signed>integer) AS f_cb_3,
2847 cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
2848 cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
2849 cast(hp2.totalProfit as <signed>integer) AS net,
2850 cast(gt.bigblind as <signed>integer) AS bigblind,
2851 cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
2852 cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
2853 cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
2854 cast(hp2.street2CheckCallRaiseDone as <signed>integer) AS ccr_2,
2855 cast(hp2.street3CheckCallRaiseChance as <signed>integer) AS ccr_opp_3,
2856 cast(hp2.street3CheckCallRaiseDone as <signed>integer) AS ccr_3,
2857 cast(hp2.street4CheckCallRaiseChance as <signed>integer) AS ccr_opp_4,
2858 cast(hp2.street4CheckCallRaiseDone as <signed>integer) AS ccr_4,
2859 cast(hp2.street0Calls as <signed>integer) AS call_0,
2860 cast(hp2.street1Calls as <signed>integer) AS call_1,
2861 cast(hp2.street2Calls as <signed>integer) AS call_2,
2862 cast(hp2.street3Calls as <signed>integer) AS call_3,
2863 cast(hp2.street4Calls as <signed>integer) AS call_4,
2864 cast(hp2.street0Bets as <signed>integer) AS bet_0,
2865 cast(hp2.street1Bets as <signed>integer) AS bet_1,
2866 cast(hp2.street2Bets as <signed>integer) AS bet_2,
2867 cast(hp2.street3Bets as <signed>integer) AS bet_3,
2868 cast(hp2.street4Bets as <signed>integer) AS bet_4,
2869 cast(hp2.street0Raises as <signed>integer) AS raise_0,
2870 cast(hp2.street1Raises as <signed>integer) AS raise_1,
2871 cast(hp2.street2Raises as <signed>integer) AS raise_2,
2872 cast(hp2.street3Raises as <signed>integer) AS raise_3,
2873 cast(hp2.street4Raises as <signed>integer) AS raise_4
2876 INNER JOIN Hands h2 ON (h2.id >= %s AND h2.tableName = h.tableName)
2877 INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */
2878 INNER JOIN HandsPlayers hp2 ON (hp2.playerId+0 = hp.playerId+0 AND (hp2.handId = h2.id+0)) /* other hands by these players */
2879 INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
2880 INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
2881 WHERE hp.handId = %s
2882 /* check activeseats once this data returned (don't want to do that here as it might
2883 assume a session ended just because the number of seats dipped for a few hands)
2885 AND ( /* 2 separate parts for hero and opponents */
2886 ( hp2.playerId != %s
2887 AND h2.seats between %s and %s
2891 AND h2.seats between %s and %s
2894 ORDER BY h.startTime desc, hp2.PlayerId
2895 /* order rows by handstart descending so that we can stop reading rows when
2896 there's a gap over X minutes between hands (ie. when we get back to start of
2899 elif db_server
== 'postgresql':
2900 self
.query
['get_stats_from_hand_session'] = """
2901 SELECT hp.playerId AS player_id,
2902 hp.handId AS hand_id,
2904 p.name AS screen_name,
2907 cast(hp2.street0VPI as <signed>integer) AS vpip,
2908 cast(hp2.street0Aggr as <signed>integer) AS pfr,
2909 cast(hp2.street0CalledRaiseChance as <signed>integer) AS CAR_opp_0,
2910 cast(hp2.street0CalledRaiseDone as <signed>integer) AS CAR_0,
2911 cast(hp2.street0_3BChance as <signed>integer) AS TB_opp_0,
2912 cast(hp2.street0_3BDone as <signed>integer) AS TB_0,
2913 cast(hp2.street0_4BChance as <signed>integer) AS FB_opp_0,
2914 cast(hp2.street0_4BDone as <signed>integer) AS FB_0,
2915 cast(hp2.street0_C4BChance as <signed>integer) AS CFB_opp_0,
2916 cast(hp2.street0_C4BDone as <signed>integer) AS CFB_0,
2917 cast(hp2.street0_FoldTo3BChance as <signed>integer) AS F3B_opp_0,
2918 cast(hp2.street0_FoldTo3BDone as <signed>integer) AS F3B_0,
2919 cast(hp2.street0_FoldTo4BChance as <signed>integer) AS F4B_opp_0,
2920 cast(hp2.street0_FoldTo4BDone as <signed>integer) AS F4B_0,
2921 cast(hp2.street0_SqueezeChance as <signed>integer) AS SQZ_opp_0,
2922 cast(hp2.street0_SqueezeDone as <signed>integer) AS SQZ_0,
2923 cast(hp2.raiseToStealChance as <signed>integer) AS RTS_opp,
2924 cast(hp2.raiseToStealDone as <signed>integer) AS RTS,
2925 cast(hp2.success_Steal as <signed>integer) AS SUC_ST,
2926 cast(hp2.street1Seen as <signed>integer) AS saw_f,
2927 cast(hp2.street1Seen as <signed>integer) AS saw_1,
2928 cast(hp2.street2Seen as <signed>integer) AS saw_2,
2929 cast(hp2.street3Seen as <signed>integer) AS saw_3,
2930 cast(hp2.street4Seen as <signed>integer) AS saw_4,
2931 cast(hp2.sawShowdown as <signed>integer) AS sd,
2932 cast(hp2.street1Aggr as <signed>integer) AS aggr_1,
2933 cast(hp2.street2Aggr as <signed>integer) AS aggr_2,
2934 cast(hp2.street3Aggr as <signed>integer) AS aggr_3,
2935 cast(hp2.street4Aggr as <signed>integer) AS aggr_4,
2936 cast(hp2.otherRaisedStreet1 as <signed>integer) AS was_raised_1,
2937 cast(hp2.otherRaisedStreet2 as <signed>integer) AS was_raised_2,
2938 cast(hp2.otherRaisedStreet3 as <signed>integer) AS was_raised_3,
2939 cast(hp2.otherRaisedStreet4 as <signed>integer) AS was_raised_4,
2940 cast(hp2.foldToOtherRaisedStreet1 as <signed>integer) AS f_freq_1,
2941 cast(hp2.foldToOtherRaisedStreet2 as <signed>integer) AS f_freq_2,
2942 cast(hp2.foldToOtherRaisedStreet3 as <signed>integer) AS f_freq_3,
2943 cast(hp2.foldToOtherRaisedStreet4 as <signed>integer) AS f_freq_4,
2944 cast(hp2.wonWhenSeenStreet1 as <signed>integer) AS w_w_s_1,
2945 cast(hp2.wonAtSD as <signed>integer) AS wmsd,
2946 cast(hp2.raiseFirstInChance as <signed>integer) AS steal_opp,
2947 cast(hp2.raisedFirstIn as <signed>integer) AS steal,
2948 cast(hp2.foldSbToStealChance as <signed>integer) AS SBstolen,
2949 cast(hp2.foldedSbToSteal as <signed>integer) AS SBnotDef,
2950 cast(hp2.foldBbToStealChance as <signed>integer) AS BBstolen,
2951 cast(hp2.foldedBbToSteal as <signed>integer) AS BBnotDef,
2952 cast(hp2.street1CBChance as <signed>integer) AS CB_opp_1,
2953 cast(hp2.street1CBDone as <signed>integer) AS CB_1,
2954 cast(hp2.street2CBChance as <signed>integer) AS CB_opp_2,
2955 cast(hp2.street2CBDone as <signed>integer) AS CB_2,
2956 cast(hp2.street3CBChance as <signed>integer) AS CB_opp_3,
2957 cast(hp2.street3CBDone as <signed>integer) AS CB_3,
2958 cast(hp2.street4CBChance as <signed>integer) AS CB_opp_4,
2959 cast(hp2.street4CBDone as <signed>integer) AS CB_4,
2960 cast(hp2.foldToStreet1CBChance as <signed>integer) AS f_cb_opp_1,
2961 cast(hp2.foldToStreet1CBDone as <signed>integer) AS f_cb_1,
2962 cast(hp2.foldToStreet2CBChance as <signed>integer) AS f_cb_opp_2,
2963 cast(hp2.foldToStreet2CBDone as <signed>integer) AS f_cb_2,
2964 cast(hp2.foldToStreet3CBChance as <signed>integer) AS f_cb_opp_3,
2965 cast(hp2.foldToStreet3CBDone as <signed>integer) AS f_cb_3,
2966 cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
2967 cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
2968 cast(hp2.totalProfit as <signed>integer) AS net,
2969 cast(gt.bigblind as <signed>integer) AS bigblind,
2970 cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
2971 cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
2972 cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
2973 cast(hp2.street2CheckCallRaiseDone as <signed>integer) AS ccr_2,
2974 cast(hp2.street3CheckCallRaiseChance as <signed>integer) AS ccr_opp_3,
2975 cast(hp2.street3CheckCallRaiseDone as <signed>integer) AS ccr_3,
2976 cast(hp2.street4CheckCallRaiseChance as <signed>integer) AS ccr_opp_4,
2977 cast(hp2.street4CheckCallRaiseDone as <signed>integer) AS ccr_4,
2978 cast(hp2.street0Calls as <signed>integer) AS call_0,
2979 cast(hp2.street1Calls as <signed>integer) AS call_1,
2980 cast(hp2.street2Calls as <signed>integer) AS call_2,
2981 cast(hp2.street3Calls as <signed>integer) AS call_3,
2982 cast(hp2.street4Calls as <signed>integer) AS call_4,
2983 cast(hp2.street0Bets as <signed>integer) AS bet_0,
2984 cast(hp2.street1Bets as <signed>integer) AS bet_1,
2985 cast(hp2.street2Bets as <signed>integer) AS bet_2,
2986 cast(hp2.street3Bets as <signed>integer) AS bet_3,
2987 cast(hp2.street4Bets as <signed>integer) AS bet_4,
2988 cast(hp2.street0Raises as <signed>integer) AS raise_0,
2989 cast(hp2.street1Raises as <signed>integer) AS raise_1,
2990 cast(hp2.street2Raises as <signed>integer) AS raise_2,
2991 cast(hp2.street3Raises as <signed>integer) AS raise_3,
2992 cast(hp2.street4Raises as <signed>integer) AS raise_4
2993 FROM Hands h /* this hand */
2994 INNER JOIN Hands h2 ON ( h2.id >= %s /* other hands */
2995 AND h2.tableName = h.tableName)
2996 INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */
2997 INNER JOIN HandsPlayers hp2 ON ( hp2.playerId+0 = hp.playerId+0
2998 AND hp2.handId = h2.id) /* other hands by these players */
2999 INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
3000 INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
3002 /* check activeseats once this data returned (don't want to do that here as it might
3003 assume a session ended just because the number of seats dipped for a few hands)
3005 AND ( /* 2 separate parts for hero and opponents */
3006 ( hp2.playerId != %s
3007 AND h2.seats between %s and %s
3011 AND h2.seats between %s and %s
3014 ORDER BY h.startTime desc, hp2.PlayerId
3015 /* order rows by handstart descending so that we can stop reading rows when
3016 there's a gap over X minutes between hands (ie. when we get back to start of
3019 elif db_server
== 'sqlite':
3020 self
.query
['get_stats_from_hand_session'] = """
3021 SELECT hp.playerId AS player_id,
3022 hp.handId AS hand_id,
3024 p.name AS screen_name,
3027 cast(hp2.street0VPI as <signed>integer) AS vpip,
3028 cast(hp2.street0Aggr as <signed>integer) AS pfr,
3029 cast(hp2.street0CalledRaiseChance as <signed>integer) AS CAR_opp_0,
3030 cast(hp2.street0CalledRaiseDone as <signed>integer) AS CAR_0,
3031 cast(hp2.street0_3BChance as <signed>integer) AS TB_opp_0,
3032 cast(hp2.street0_3BDone as <signed>integer) AS TB_0,
3033 cast(hp2.street0_4BChance as <signed>integer) AS FB_opp_0,
3034 cast(hp2.street0_4BDone as <signed>integer) AS FB_0,
3035 cast(hp2.street0_C4BChance as <signed>integer) AS CFB_opp_0,
3036 cast(hp2.street0_C4BDone as <signed>integer) AS CFB_0,
3037 cast(hp2.street0_FoldTo3BChance as <signed>integer) AS F3B_opp_0,
3038 cast(hp2.street0_FoldTo3BDone as <signed>integer) AS F3B_0,
3039 cast(hp2.street0_FoldTo4BChance as <signed>integer) AS F4B_opp_0,
3040 cast(hp2.street0_FoldTo4BDone as <signed>integer) AS F4B_0,
3041 cast(hp2.street0_SqueezeChance as <signed>integer) AS SQZ_opp_0,
3042 cast(hp2.street0_SqueezeDone as <signed>integer) AS SQZ_0,
3043 cast(hp2.raiseToStealChance as <signed>integer) AS RTS_opp,
3044 cast(hp2.raiseToStealDone as <signed>integer) AS RTS,
3045 cast(hp2.success_Steal as <signed>integer) AS SUC_ST,
3046 cast(hp2.street1Seen as <signed>integer) AS saw_f,
3047 cast(hp2.street1Seen as <signed>integer) AS saw_1,
3048 cast(hp2.street2Seen as <signed>integer) AS saw_2,
3049 cast(hp2.street3Seen as <signed>integer) AS saw_3,
3050 cast(hp2.street4Seen as <signed>integer) AS saw_4,
3051 cast(hp2.sawShowdown as <signed>integer) AS sd,
3052 cast(hp2.street1Aggr as <signed>integer) AS aggr_1,
3053 cast(hp2.street2Aggr as <signed>integer) AS aggr_2,
3054 cast(hp2.street3Aggr as <signed>integer) AS aggr_3,
3055 cast(hp2.street4Aggr as <signed>integer) AS aggr_4,
3056 cast(hp2.otherRaisedStreet1 as <signed>integer) AS was_raised_1,
3057 cast(hp2.otherRaisedStreet2 as <signed>integer) AS was_raised_2,
3058 cast(hp2.otherRaisedStreet3 as <signed>integer) AS was_raised_3,
3059 cast(hp2.otherRaisedStreet4 as <signed>integer) AS was_raised_4,
3060 cast(hp2.foldToOtherRaisedStreet1 as <signed>integer) AS f_freq_1,
3061 cast(hp2.foldToOtherRaisedStreet2 as <signed>integer) AS f_freq_2,
3062 cast(hp2.foldToOtherRaisedStreet3 as <signed>integer) AS f_freq_3,
3063 cast(hp2.foldToOtherRaisedStreet4 as <signed>integer) AS f_freq_4,
3064 cast(hp2.wonWhenSeenStreet1 as <signed>integer) AS w_w_s_1,
3065 cast(hp2.wonAtSD as <signed>integer) AS wmsd,
3066 cast(hp2.raiseFirstInChance as <signed>integer) AS steal_opp,
3067 cast(hp2.raisedFirstIn as <signed>integer) AS steal,
3068 cast(hp2.foldSbToStealChance as <signed>integer) AS SBstolen,
3069 cast(hp2.foldedSbToSteal as <signed>integer) AS SBnotDef,
3070 cast(hp2.foldBbToStealChance as <signed>integer) AS BBstolen,
3071 cast(hp2.foldedBbToSteal as <signed>integer) AS BBnotDef,
3072 cast(hp2.street1CBChance as <signed>integer) AS CB_opp_1,
3073 cast(hp2.street1CBDone as <signed>integer) AS CB_1,
3074 cast(hp2.street2CBChance as <signed>integer) AS CB_opp_2,
3075 cast(hp2.street2CBDone as <signed>integer) AS CB_2,
3076 cast(hp2.street3CBChance as <signed>integer) AS CB_opp_3,
3077 cast(hp2.street3CBDone as <signed>integer) AS CB_3,
3078 cast(hp2.street4CBChance as <signed>integer) AS CB_opp_4,
3079 cast(hp2.street4CBDone as <signed>integer) AS CB_4,
3080 cast(hp2.foldToStreet1CBChance as <signed>integer) AS f_cb_opp_1,
3081 cast(hp2.foldToStreet1CBDone as <signed>integer) AS f_cb_1,
3082 cast(hp2.foldToStreet2CBChance as <signed>integer) AS f_cb_opp_2,
3083 cast(hp2.foldToStreet2CBDone as <signed>integer) AS f_cb_2,
3084 cast(hp2.foldToStreet3CBChance as <signed>integer) AS f_cb_opp_3,
3085 cast(hp2.foldToStreet3CBDone as <signed>integer) AS f_cb_3,
3086 cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
3087 cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
3088 cast(hp2.totalProfit as <signed>integer) AS net,
3089 cast(gt.bigblind as <signed>integer) AS bigblind,
3090 cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
3091 cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
3092 cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
3093 cast(hp2.street2CheckCallRaiseDone as <signed>integer) AS ccr_2,
3094 cast(hp2.street3CheckCallRaiseChance as <signed>integer) AS ccr_opp_3,
3095 cast(hp2.street3CheckCallRaiseDone as <signed>integer) AS ccr_3,
3096 cast(hp2.street4CheckCallRaiseChance as <signed>integer) AS ccr_opp_4,
3097 cast(hp2.street4CheckCallRaiseDone as <signed>integer) AS ccr_4,
3098 cast(hp2.street0Calls as <signed>integer) AS call_0,
3099 cast(hp2.street1Calls as <signed>integer) AS call_1,
3100 cast(hp2.street2Calls as <signed>integer) AS call_2,
3101 cast(hp2.street3Calls as <signed>integer) AS call_3,
3102 cast(hp2.street4Calls as <signed>integer) AS call_4,
3103 cast(hp2.street0Bets as <signed>integer) AS bet_0,
3104 cast(hp2.street1Bets as <signed>integer) AS bet_1,
3105 cast(hp2.street2Bets as <signed>integer) AS bet_2,
3106 cast(hp2.street3Bets as <signed>integer) AS bet_3,
3107 cast(hp2.street4Bets as <signed>integer) AS bet_4,
3108 cast(hp2.street0Raises as <signed>integer) AS raise_0,
3109 cast(hp2.street1Raises as <signed>integer) AS raise_1,
3110 cast(hp2.street2Raises as <signed>integer) AS raise_2,
3111 cast(hp2.street3Raises as <signed>integer) AS raise_3,
3112 cast(hp2.street4Raises as <signed>integer) AS raise_4
3113 FROM Hands h /* this hand */
3114 INNER JOIN Hands h2 ON ( h2.id >= %s /* other hands */
3115 AND h2.tableName = h.tableName)
3116 INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */
3117 INNER JOIN HandsPlayers hp2 ON ( hp2.playerId+0 = hp.playerId+0
3118 AND hp2.handId = h2.id) /* other hands by these players */
3119 INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
3120 INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
3122 /* check activeseats once this data returned (don't want to do that here as it might
3123 assume a session ended just because the number of seats dipped for a few hands)
3125 AND ( /* 2 separate parts for hero and opponents */
3126 ( hp2.playerId != %s
3127 AND h2.seats between %s and %s
3131 AND h2.seats between %s and %s
3134 ORDER BY h.startTime desc, hp2.PlayerId
3135 /* order rows by handstart descending so that we can stop reading rows when
3136 there's a gap over X minutes between hands (ie. when we get back to start of
3140 self
.query
['get_players_from_hand'] = """
3141 SELECT HandsPlayers.playerId, seatNo, name
3142 FROM HandsPlayers INNER JOIN Players ON (HandsPlayers.playerId = Players.id)
3145 # WHERE handId = %s AND Players.id LIKE %s
3147 self
.query
['get_winners_from_hand'] = """
3148 SELECT name, winnings
3149 FROM HandsPlayers, Players
3151 AND Players.id = HandsPlayers.playerId
3155 self
.query
['get_table_name'] = """
3156 SELECT h.tableName, gt.maxSeats, gt.category, gt.type, s.id, s.name
3157 , count(1) as numseats
3158 FROM Hands h, Gametypes gt, Sites s, HandsPlayers hp
3160 AND gt.id = h.gametypeId
3161 AND s.id = gt.siteID
3162 AND hp.handId = h.id
3163 GROUP BY h.tableName, gt.maxSeats, gt.category, gt.type, s.id, s.name
3166 self
.query
['get_actual_seat'] = """
3169 where HandsPlayers.handId = %s
3170 and HandsPlayers.playerId = (select Players.id from Players
3171 where Players.name = %s)
3174 self
.query
['get_cards'] = """
3176 changed to activate mucked card display in draw games
3177 in draw games, card6->card20 contain 3 sets of 5 cards at each draw
3179 CASE code searches from the highest card number (latest draw) and when
3180 it finds a non-zero card, it returns that set of data
3183 seatNo AS seat_number,
3185 when 'draw' then COALESCE(NULLIF(card16,0), NULLIF(card11,0), NULLIF(card6,0), card1)
3189 when 'draw' then COALESCE(NULLIF(card17,0), NULLIF(card12,0), NULLIF(card7,0), card2)
3193 when 'draw' then COALESCE(NULLIF(card18,0), NULLIF(card13,0), NULLIF(card8,0), card3)
3197 when 'draw' then COALESCE(NULLIF(card19,0), NULLIF(card14,0), NULLIF(card9,0), card4)
3201 when 'draw' then COALESCE(NULLIF(card20,0), NULLIF(card15,0), NULLIF(card10,0), card5)
3213 FROM HandsPlayers, Hands, Gametypes
3215 AND HandsPlayers.handId=Hands.id
3216 AND Hands.gametypeId = Gametypes.id
3220 self
.query
['get_common_cards'] = """
3231 if db_server
== 'mysql':
3232 self
.query
['get_hand_1day_ago'] = """
3233 select coalesce(max(id),0)
3235 where startTime < date_sub(utc_timestamp(), interval '1' day)"""
3236 elif db_server
== 'postgresql':
3237 self
.query
['get_hand_1day_ago'] = """
3238 select coalesce(max(id),0)
3240 where startTime < now() at time zone 'UTC' - interval '1 day'"""
3241 elif db_server
== 'sqlite':
3242 self
.query
['get_hand_1day_ago'] = """
3243 select coalesce(max(id),0)
3245 where startTime < datetime(strftime('%J', 'now') - 1)"""
3248 # gets a date, would need to use handsplayers (not hudcache) to get exact hand Id
3249 if db_server
== 'mysql':
3250 self
.query
['get_date_nhands_ago'] = """
3251 select concat( 'd', date_format(max(h.startTime), '%Y%m%d') )
3252 from (select hp.playerId
3253 ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
3254 from HandsPlayers hp
3255 where hp.playerId = %s
3256 group by hp.playerId) hp2
3257 inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx
3258 and hp3.playerId = hp2.playerId)
3259 inner join Hands h on (h.id = hp3.handId)
3261 elif db_server
== 'postgresql':
3262 self
.query
['get_date_nhands_ago'] = """
3263 select 'd' || to_char(max(h3.startTime), 'YYMMDD')
3264 from (select hp.playerId
3265 ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
3266 from HandsPlayers hp
3267 where hp.playerId = %s
3268 group by hp.playerId) hp2
3269 inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx
3270 and hp3.playerId = hp2.playerId)
3271 inner join Hands h on (h.id = hp3.handId)
3273 elif db_server
== 'sqlite': # untested guess at query:
3274 self
.query
['get_date_nhands_ago'] = """
3275 select 'd' || strftime(max(h3.startTime), 'YYMMDD')
3276 from (select hp.playerId
3277 ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
3278 from HandsPlayers hp
3279 where hp.playerId = %s
3280 group by hp.playerId) hp2
3281 inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx
3282 and hp3.playerId = hp2.playerId)
3283 inner join Hands h on (h.id = hp3.handId)
3287 #self.query['getLimits'] = already defined further up
3288 self
.query
['getLimits2'] = """SELECT DISTINCT type, limitType, bigBlind
3290 ORDER by type, limitType DESC, bigBlind DESC"""
3291 self
.query
['getLimits3'] = """select DISTINCT type
3294 when 'ring' then bigBlind
3296 - end as bb_or_buyin
3298 cross join TourneyTypes tt
3299 order by type, gt.limitType DESC, bb_or_buyin DESC"""
3300 self
.query
['getCashLimits'] = """select DISTINCT type
3302 , bigBlind as bb_or_buyin
3305 order by type, limitType DESC, bb_or_buyin DESC"""
3307 self
.query
['getPositions'] = """select distinct position
3308 from HandsPlayers gt
3309 order by position"""
3311 #FIXME: Some stats not added to DetailedStats (miss raise to steal)
3312 if db_server
== 'mysql':
3313 self
.query
['playerDetailedStats'] = """
3314 select <hgametypeId> AS hgametypeid
3315 ,<playerName> AS pname
3318 ,upper(gt.limitType) AS limittype
3320 ,min(gt.bigBlind) AS minbigblind
3321 ,max(gt.bigBlind) AS maxbigblind
3322 /*,<hcgametypeId> AS gtid*/
3323 ,<position> AS plposition
3325 ,100.0*sum(cast(hp.street0VPI as <signed>integer))/count(1) AS vpip
3326 ,100.0*sum(cast(hp.street0Aggr as <signed>integer))/count(1) AS pfr
3327 ,case when sum(cast(hp.street0CalledRaiseChance as <signed>integer)) = 0 then -999
3328 else 100.0*sum(cast(hp.street0CalledRaiseDone as <signed>integer))/sum(cast(hp.street0CalledRaiseChance as <signed>integer))
3330 ,case when sum(cast(hp.street0_3Bchance as <signed>integer)) = 0 then -999
3331 else 100.0*sum(cast(hp.street0_3Bdone as <signed>integer))/sum(cast(hp.street0_3Bchance as <signed>integer))
3333 ,case when sum(cast(hp.street0_4Bchance as <signed>integer)) = 0 then -999
3334 else 100.0*sum(cast(hp.street0_4Bdone as <signed>integer))/sum(cast(hp.street0_4Bchance as <signed>integer))
3336 ,case when sum(cast(hp.street0_FoldTo3Bchance as <signed>integer)) = 0 then -999
3337 else 100.0*sum(cast(hp.street0_FoldTo3Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo3Bchance as <signed>integer))
3339 ,case when sum(cast(hp.street0_FoldTo4Bchance as <signed>integer)) = 0 then -999
3340 else 100.0*sum(cast(hp.street0_FoldTo4Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo4Bchance as <signed>integer))
3343 ,case when sum(cast(hp.raiseFirstInChance as <signed>integer)) = 0 then -999
3344 else 100.0 * sum(cast(hp.raisedFirstIn as <signed>integer)) /
3345 sum(cast(hp.raiseFirstInChance as <signed>integer))
3347 ,case when sum(case hp.position
3348 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
3349 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
3350 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
3355 sum(case hp.position
3356 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
3357 when '0' then cast(hp.raisedFirstIn as <signed>integer)
3358 when '1' then cast(hp.raisedFirstIn as <signed>integer)
3362 sum(case hp.position
3363 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
3364 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
3365 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
3370 ,case when sum(cast(hp.success_Steal as <signed>integer)) = 0 then -999
3372 sum(cast(hp.success_Steal as <signed>integer))
3374 sum(case hp.position
3375 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
3376 when '0' then cast(hp.raisedFirstIn as <signed>integer)
3377 when '1' then cast(hp.raisedFirstIn as <signed>integer)
3382 ,100.0*sum(cast(hp.street1Seen as <signed>integer))/count(1) AS saw_f
3383 ,100.0*sum(cast(hp.sawShowdown as <signed>integer))/count(1) AS sawsd
3384 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
3385 else 100.0*sum(cast(hp.wonWhenSeenStreet1 as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
3387 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
3388 else 100.0*sum(cast(hp.sawShowdown as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
3390 ,case when sum(cast(hp.sawShowdown as <signed>integer)) = 0 then -999
3391 else 100.0*sum(cast(hp.wonAtSD as <signed>integer))/sum(cast(hp.sawShowdown as <signed>integer))
3393 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
3394 else 100.0*sum(cast(hp.street1Aggr as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
3396 ,case when sum(cast(hp.street2Seen as <signed>integer)) = 0 then -999
3397 else 100.0*sum(cast(hp.street2Aggr as <signed>integer))/sum(cast(hp.street2Seen as <signed>integer))
3399 ,case when sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
3400 else 100.0*sum(cast(hp.street3Aggr as <signed>integer))/sum(cast(hp.street3Seen as <signed>integer))
3402 ,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
3403 else 100.0*(sum(cast(hp.street1Aggr as <signed>integer))+sum(cast(hp.street2Aggr as <signed>integer))+sum(cast(hp.street3Aggr as <signed>integer)))
3404 /(sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)))
3406 ,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
3407 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)))
3408 /(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)))
3410 ,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)))
3411 / ((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))) +
3412 (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))) +
3413 (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))) )
3415 ,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)))
3416 / (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)))
3418 ,sum(hp.totalProfit)/100.0 AS net
3419 ,sum(hp.rake)/100.0 AS rake
3420 ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100
3421 ,avg(hp.totalProfit)/100.0 AS profitperhand
3422 ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr
3423 ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr
3424 ,avg(h.seats+0.0) AS avgseats
3425 ,variance(hp.totalProfit/100.0) AS variance
3426 ,sqrt(variance(hp.totalProfit/100.0)) AS stddev
3427 from HandsPlayers hp
3428 inner join Hands h on (h.id = hp.handId)
3429 inner join Gametypes gt on (gt.Id = h.gametypeId)
3430 inner join Sites s on (s.Id = gt.siteId)
3431 inner join Players p on (p.Id = hp.playerId)
3432 where hp.playerId in <player_test>
3436 /*and hp.tourneysPlayersId IS NULL*/
3437 and h.seats <seats_test>
3441 and date_format(h.startTime, '%Y-%m-%d %T') <datestest>
3442 group by hgametypeId
3448 ,upper(gt.limitType)
3450 having 1 = 1 <havingclause>
3455 ,case <position> when 'B' then 'B'
3457 else concat('Z', <position>)
3459 <orderbyhgametypeId>
3460 ,upper(gt.limitType) desc
3464 elif db_server
== 'postgresql':
3465 self
.query
['playerDetailedStats'] = """
3466 select <hgametypeId> AS hgametypeid
3467 ,<playerName> AS pname
3470 ,upper(gt.limitType) AS limittype
3472 ,min(gt.bigBlind) AS minbigblind
3473 ,max(gt.bigBlind) AS maxbigblind
3474 /*,<hcgametypeId> AS gtid*/
3475 ,<position> AS plposition
3477 ,100.0*sum(cast(hp.street0VPI as <signed>integer))/count(1) AS vpip
3478 ,100.0*sum(cast(hp.street0Aggr as <signed>integer))/count(1) AS pfr
3479 ,case when sum(cast(hp.street0CalledRaiseChance as <signed>integer)) = 0 then -999
3480 else 100.0*sum(cast(hp.street0CalledRaiseDone as <signed>integer))/sum(cast(hp.street0CalledRaiseChance as <signed>integer))
3482 ,case when sum(cast(hp.street0_3Bchance as <signed>integer)) = 0 then -999
3483 else 100.0*sum(cast(hp.street0_3Bdone as <signed>integer))/sum(cast(hp.street0_3Bchance as <signed>integer))
3485 ,case when sum(cast(hp.street0_4Bchance as <signed>integer)) = 0 then -999
3486 else 100.0*sum(cast(hp.street0_4Bdone as <signed>integer))/sum(cast(hp.street0_4Bchance as <signed>integer))
3488 ,case when sum(cast(hp.street0_FoldTo3Bchance as <signed>integer)) = 0 then -999
3489 else 100.0*sum(cast(hp.street0_FoldTo3Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo3Bchance as <signed>integer))
3491 ,case when sum(cast(hp.street0_FoldTo4Bchance as <signed>integer)) = 0 then -999
3492 else 100.0*sum(cast(hp.street0_FoldTo4Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo4Bchance as <signed>integer))
3494 ,case when sum(cast(hp.raiseFirstInChance as <signed>integer)) = 0 then -999
3495 else 100.0 * sum(cast(hp.raisedFirstIn as <signed>integer)) /
3496 sum(cast(hp.raiseFirstInChance as <signed>integer))
3498 ,case when sum(case hp.position
3499 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
3500 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
3501 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
3506 sum(case hp.position
3507 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
3508 when '0' then cast(hp.raisedFirstIn as <signed>integer)
3509 when '1' then cast(hp.raisedFirstIn as <signed>integer)
3513 sum(case hp.position
3514 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
3515 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
3516 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
3521 ,case when sum(cast(hp.success_Steal as <signed>integer)) = 0 then -999
3523 sum(cast(hp.success_Steal as <signed>integer))
3525 sum(case hp.position
3526 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
3527 when '0' then cast(hp.raisedFirstIn as <signed>integer)
3528 when '1' then cast(hp.raisedFirstIn as <signed>integer)
3533 ,100.0*sum(cast(hp.street1Seen as <signed>integer))/count(1) AS saw_f
3534 ,100.0*sum(cast(hp.sawShowdown as <signed>integer))/count(1) AS sawsd
3535 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
3536 else 100.0*sum(cast(hp.wonWhenSeenStreet1 as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
3538 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
3539 else 100.0*sum(cast(hp.sawShowdown as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
3541 ,case when sum(cast(hp.sawShowdown as <signed>integer)) = 0 then -999
3542 else 100.0*sum(cast(hp.wonAtSD as <signed>integer))/sum(cast(hp.sawShowdown as <signed>integer))
3544 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
3545 else 100.0*sum(cast(hp.street1Aggr as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
3547 ,case when sum(cast(hp.street2Seen as <signed>integer)) = 0 then -999
3548 else 100.0*sum(cast(hp.street2Aggr as <signed>integer))/sum(cast(hp.street2Seen as <signed>integer))
3550 ,case when sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
3551 else 100.0*sum(cast(hp.street3Aggr as <signed>integer))/sum(cast(hp.street3Seen as <signed>integer))
3553 ,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
3554 else 100.0*(sum(cast(hp.street1Aggr as <signed>integer))+sum(cast(hp.street2Aggr as <signed>integer))+sum(cast(hp.street3Aggr as <signed>integer)))
3555 /(sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)))
3557 ,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
3558 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)))
3559 /(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)))
3562 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))+
3563 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))+
3564 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))
3567 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)))
3568 / ((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))) +
3569 (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))) +
3570 (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))) )
3573 sum(cast(hp.street1CBChance as <signed>integer))+
3574 sum(cast(hp.street2CBChance as <signed>integer))+
3575 sum(cast(hp.street3CBChance as <signed>integer))+
3576 sum(cast(hp.street4CBChance as <signed>integer)) = 0 then -999
3578 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)))
3579 / (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)))
3581 ,sum(hp.totalProfit)/100.0 AS net
3582 ,sum(hp.rake)/100.0 AS rake
3583 ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100
3584 ,avg(hp.totalProfit)/100.0 AS profitperhand
3585 ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr
3586 ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr
3587 ,avg(h.seats+0.0) AS avgseats
3588 ,variance(hp.totalProfit/100.0) AS variance
3589 ,sqrt(variance(hp.totalProfit/100.0)) AS stddev
3590 from HandsPlayers hp
3591 inner join Hands h on (h.id = hp.handId)
3592 inner join Gametypes gt on (gt.Id = h.gametypeId)
3593 inner join Sites s on (s.Id = gt.siteId)
3594 inner join Players p on (p.Id = hp.playerId)
3595 where hp.playerId in <player_test>
3599 /*and hp.tourneysPlayersId IS NULL*/
3600 and h.seats <seats_test>
3604 and to_char(h.startTime, 'YYYY-MM-DD HH24:MI:SS') <datestest>
3605 group by hgametypeId
3611 ,upper(gt.limitType)
3613 having 1 = 1 <havingclause>
3618 ,case <position> when 'B' then 'B'
3621 else 'Z'||<position>
3623 <orderbyhgametypeId>
3624 ,upper(gt.limitType) desc
3628 elif db_server
== 'sqlite':
3629 self
.query
['playerDetailedStats'] = """
3630 select <hgametypeId> AS hgametypeid
3631 ,<playerName> AS pname
3633 ,gt.category AS category
3634 ,upper(gt.limitType) AS limittype
3636 ,min(gt.bigBlind) AS minbigblind
3637 ,max(gt.bigBlind) AS maxbigblind
3638 /*,<hcgametypeId> AS gtid*/
3639 ,<position> AS plposition
3641 ,100.0*sum(cast(hp.street0VPI as <signed>integer))/count(1) AS vpip
3642 ,100.0*sum(cast(hp.street0Aggr as <signed>integer))/count(1) AS pfr
3643 ,case when sum(cast(hp.street0CalledRaiseChance as <signed>integer)) = 0 then -999
3644 else 100.0*sum(cast(hp.street0CalledRaiseDone as <signed>integer))/sum(cast(hp.street0CalledRaiseChance as <signed>integer))
3646 ,case when sum(cast(hp.street0_3Bchance as <signed>integer)) = 0 then -999
3647 else 100.0*sum(cast(hp.street0_3Bdone as <signed>integer))/sum(cast(hp.street0_3Bchance as <signed>integer))
3649 ,case when sum(cast(hp.street0_4Bchance as <signed>integer)) = 0 then -999
3650 else 100.0*sum(cast(hp.street0_4Bdone as <signed>integer))/sum(cast(hp.street0_4Bchance as <signed>integer))
3652 ,case when sum(cast(hp.street0_FoldTo3Bchance as <signed>integer)) = 0 then -999
3653 else 100.0*sum(cast(hp.street0_FoldTo3Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo3Bchance as <signed>integer))
3655 ,case when sum(cast(hp.street0_FoldTo4Bchance as <signed>integer)) = 0 then -999
3656 else 100.0*sum(cast(hp.street0_FoldTo4Bdone as <signed>integer))/sum(cast(hp.street0_FoldTo4Bchance as <signed>integer))
3658 ,case when sum(cast(hp.raiseFirstInChance as <signed>integer)) = 0 then -999
3659 else 100.0 * sum(cast(hp.raisedFirstIn as <signed>integer)) /
3660 sum(cast(hp.raiseFirstInChance as <signed>integer))
3662 ,case when sum(case hp.position
3663 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
3664 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
3665 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
3670 sum(case hp.position
3671 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
3672 when '0' then cast(hp.raisedFirstIn as <signed>integer)
3673 when '1' then cast(hp.raisedFirstIn as <signed>integer)
3677 sum(case hp.position
3678 when 'S' then cast(hp.raiseFirstInChance as <signed>integer)
3679 when '0' then cast(hp.raiseFirstInChance as <signed>integer)
3680 when '1' then cast(hp.raiseFirstInChance as <signed>integer)
3685 ,case when sum(cast(hp.success_Steal as <signed>integer)) = 0 then -999
3687 sum(cast(hp.success_Steal as <signed>integer))
3689 sum(case hp.position
3690 when 'S' then cast(hp.raisedFirstIn as <signed>integer)
3691 when '0' then cast(hp.raisedFirstIn as <signed>integer)
3692 when '1' then cast(hp.raisedFirstIn as <signed>integer)
3697 ,100.0*sum(cast(hp.street1Seen as <signed>integer))/count(1) AS saw_f
3698 ,100.0*sum(cast(hp.sawShowdown as <signed>integer))/count(1) AS sawsd
3699 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
3700 else 100.0*sum(cast(hp.wonWhenSeenStreet1 as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
3702 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
3703 else 100.0*sum(cast(hp.sawShowdown as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
3705 ,case when sum(cast(hp.sawShowdown as <signed>integer)) = 0 then -999
3706 else 100.0*sum(cast(hp.wonAtSD as <signed>integer))/sum(cast(hp.sawShowdown as <signed>integer))
3708 ,case when sum(cast(hp.street1Seen as <signed>integer)) = 0 then -999
3709 else 100.0*sum(cast(hp.street1Aggr as <signed>integer))/sum(cast(hp.street1Seen as <signed>integer))
3711 ,case when sum(cast(hp.street2Seen as <signed>integer)) = 0 then -999
3712 else 100.0*sum(cast(hp.street2Aggr as <signed>integer))/sum(cast(hp.street2Seen as <signed>integer))
3714 ,case when sum(cast(hp.street3Seen as <signed>integer)) = 0 then -999
3715 else 100.0*sum(cast(hp.street3Aggr as <signed>integer))/sum(cast(hp.street3Seen as <signed>integer))
3717 ,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
3718 else 100.0*(sum(cast(hp.street1Aggr as <signed>integer))+sum(cast(hp.street2Aggr as <signed>integer))+sum(cast(hp.street3Aggr as <signed>integer)))
3719 /(sum(cast(hp.street1Seen as <signed>integer))+sum(cast(hp.street2Seen as <signed>integer))+sum(cast(hp.street3Seen as <signed>integer)))
3721 ,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
3722 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)))
3723 /(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)))
3725 ,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)))
3726 / ((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))) +
3727 (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))) +
3728 (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))) )
3730 ,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)))
3731 / (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)))
3733 ,sum(hp.totalProfit)/100.0 AS net
3734 ,sum(hp.rake)/100.0 AS rake
3735 ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100
3736 ,avg(hp.totalProfit)/100.0 AS profitperhand
3737 ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr
3738 ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr
3739 ,avg(h.seats+0.0) AS avgseats
3740 ,variance(hp.totalProfit/100.0) AS variance
3741 ,sqrt(variance(hp.totalProfit/100.0)) AS stddev
3742 from HandsPlayers hp
3743 inner join Hands h on (h.id = hp.handId)
3744 inner join Gametypes gt on (gt.Id = h.gametypeId)
3745 inner join Sites s on (s.Id = gt.siteId)
3746 inner join Players p on (p.Id = hp.playerId)
3747 where hp.playerId in <player_test>
3751 /*and hp.tourneysPlayersId IS NULL*/
3752 and h.seats <seats_test>
3756 and datetime(h.startTime) <datestest>
3757 group by hgametypeId
3763 ,upper(gt.limitType)
3765 having 1 = 1 <havingclause>
3766 order by hp.playerId
3770 ,case <position> when 'B' then 'B'
3773 else 'Z'||<position>
3775 <orderbyhgametypeId>
3776 ,upper(gt.limitType) desc
3777 ,max(gt.bigBlind) desc
3781 #FIXME: 3/4bet and foldTo don't added four tournaments yet
3782 if db_server
== 'mysql':
3783 self
.query
['tourneyPlayerDetailedStats'] = """
3784 select s.name AS siteName
3785 ,t.tourneyTypeId AS tourneyTypeId
3786 ,tt.currency AS currency
3788 WHEN tt.currency = 'play' THEN tt.buyIn
3791 ,tt.fee/100.0 AS fee
3792 ,tt.category AS category
3793 ,tt.limitType AS limitType
3794 ,p.name AS playerName
3795 ,COUNT(1) AS tourneyCount
3796 ,SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END) AS unknownRank
3797 ,(CAST(SUM(CASE WHEN winnings > 0 THEN 1 ELSE 0 END) AS REAL)/CAST(COUNT(1) AS REAL))*100 AS itm
3798 ,SUM(CASE WHEN rank = 1 THEN 1 ELSE 0 END) AS _1st
3799 ,SUM(CASE WHEN rank = 2 THEN 1 ELSE 0 END) AS _2nd
3800 ,SUM(CASE WHEN rank = 3 THEN 1 ELSE 0 END) AS _3rd
3801 ,SUM(tp.winnings)/100.0 AS won
3803 WHEN tt.currency = 'play' THEN tt.buyIn
3804 ELSE (tt.buyIn+tt.fee)/100.0
3807 (CAST(SUM(tp.winnings - tt.buyin - tt.fee) AS REAL)/
3808 CAST(SUM(tt.buyin+tt.fee) AS REAL))* 100.0
3810 ,SUM(tp.winnings-(tt.buyin+tt.fee))/100.0/(COUNT(1)-SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END)) AS profitPerTourney
3811 from TourneysPlayers tp
3812 inner join Tourneys t on (t.id = tp.tourneyId)
3813 inner join TourneyTypes tt on (tt.Id = t.tourneyTypeId)
3814 inner join Sites s on (s.Id = tt.siteId)
3815 inner join Players p on (p.Id = tp.playerId)
3816 where tp.playerId in <nametest> <sitetest>
3817 AND ((t.startTime > '<startdate_test>' AND t.startTime < '<enddate_test>')
3818 OR t.startTime is NULL)
3819 group by tourneyTypeId, playerName
3820 order by tourneyTypeId
3823 elif db_server
== 'postgresql':
3824 # sc: itm and profitPerTourney changed to "ELSE 0" to avoid divide by zero error as temp fix
3825 # proper fix should use coalesce() or case ... when ... to work in all circumstances
3826 self
.query
['tourneyPlayerDetailedStats'] = """
3827 select s.name AS "siteName"
3828 ,t.tourneyTypeId AS "tourneyTypeId"
3829 ,tt.currency AS "currency"
3831 WHEN tt.currency = 'play' THEN tt.buyIn
3834 ,tt.fee/100.0 AS "fee"
3835 ,tt.category AS "category"
3836 ,tt.limitType AS "limitType"
3837 ,p.name AS "playerName"
3838 ,COUNT(1) AS "tourneyCount"
3839 ,SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END) AS "unknownRank"
3840 ,(CAST(SUM(CASE WHEN winnings > 0 THEN 1 ELSE 0 END) AS REAL)/CAST(COUNT(1) AS REAL))*100 AS itm
3841 ,SUM(CASE WHEN rank = 1 THEN 1 ELSE 0 END) AS "_1st"
3842 ,SUM(CASE WHEN rank = 2 THEN 1 ELSE 0 END) AS "_2nd"
3843 ,SUM(CASE WHEN rank = 3 THEN 1 ELSE 0 END) AS "_3rd"
3844 ,SUM(tp.winnings)/100.0 AS "won"
3846 WHEN tt.currency = 'play' THEN tt.buyIn
3847 ELSE (tt.buyIn+tt.fee)/100.0
3850 (CAST(SUM(tp.winnings - tt.buyin - tt.fee) AS REAL)/
3851 CAST(SUM(tt.buyin+tt.fee) AS REAL))* 100.0
3853 ,SUM(tp.winnings-(tt.buyin+tt.fee))/100.0
3854 /(COUNT(1)-SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 0 END)) AS "profitPerTourney"
3855 from TourneysPlayers tp
3856 inner join Tourneys t on (t.id = tp.tourneyId)
3857 inner join TourneyTypes tt on (tt.Id = t.tourneyTypeId)
3858 inner join Sites s on (s.Id = tt.siteId)
3859 inner join Players p on (p.Id = tp.playerId)
3860 where tp.playerId in <nametest> <sitetest>
3861 AND ((t.startTime > '<startdate_test>' AND t.startTime < '<enddate_test>')
3862 OR t.startTime is NULL)
3863 group by t.tourneyTypeId, s.name, p.name, tt.currency, tt.buyin, tt.fee
3864 , tt.category, tt.limitType
3865 order by t.tourneyTypeId
3868 elif db_server
== 'sqlite':
3869 self
.query
['tourneyPlayerDetailedStats'] = """
3870 select s.name AS siteName
3871 ,t.tourneyTypeId AS tourneyTypeId
3872 ,tt.currency AS currency
3874 WHEN tt.currency = 'play' THEN tt.buyIn
3877 ,tt.fee/100.0 AS fee
3878 ,tt.category AS category
3879 ,tt.limitType AS limitType
3880 ,p.name AS playerName
3881 ,COUNT(1) AS tourneyCount
3882 ,SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END) AS unknownRank
3883 ,(CAST(SUM(CASE WHEN winnings > 0 THEN 1 ELSE 0 END) AS REAL)/CAST(COUNT(1) AS REAL))*100 AS itm
3884 ,SUM(CASE WHEN rank = 1 THEN 1 ELSE 0 END) AS _1st
3885 ,SUM(CASE WHEN rank = 2 THEN 1 ELSE 0 END) AS _2nd
3886 ,SUM(CASE WHEN rank = 3 THEN 1 ELSE 0 END) AS _3rd
3887 ,SUM(tp.winnings)/100.0 AS won
3889 WHEN tt.currency = 'play' THEN tt.buyIn
3890 ELSE (tt.buyIn+tt.fee)/100.0
3893 (CAST(SUM(tp.winnings - tt.buyin - tt.fee) AS REAL)/
3894 CAST(SUM(tt.buyin+tt.fee) AS REAL))* 100.0
3896 ,SUM(tp.winnings-(tt.buyin+tt.fee))/100.0/(COUNT(1)-SUM(CASE WHEN tp.rank > 0 THEN 0 ELSE 1 END)) AS profitPerTourney
3897 from TourneysPlayers tp
3898 inner join Tourneys t on (t.id = tp.tourneyId)
3899 inner join TourneyTypes tt on (tt.Id = t.tourneyTypeId)
3900 inner join Sites s on (s.Id = tt.siteId)
3901 inner join Players p on (p.Id = tp.playerId)
3902 where tp.playerId in <nametest> <sitetest>
3903 AND ((t.startTime > '<startdate_test>' AND t.startTime < '<enddate_test>')
3904 OR t.startTime is NULL)
3905 group by tourneyTypeId, playerName
3906 order by tourneyTypeId
3910 if db_server
== 'mysql':
3911 self
.query
['playerStats'] = """
3913 concat(upper(stats.limitType), ' '
3914 ,concat(upper(substring(stats.category,1,1)),substring(stats.category,2) ), ' '
3916 ,cast(stats.bigBlindDesc as char)
3936 ,stats.Profitperhand
3937 ,case when hprof2.variance = -999 then '-'
3938 else format(hprof2.variance, 2)
3940 ,case when hprof2.stddev = -999 then '-'
3941 else format(hprof2.stddev, 2)
3945 (select /* stats from hudcache */
3948 ,upper(gt.limitType) as limitType
3950 ,<selectgt.bigBlind> AS bigBlindDesc
3951 ,<hcgametypeId> AS gtId
3953 ,format(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
3954 ,format(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
3956 ,case when sum(street0CalledRaiseChance) = 0 then '0'
3957 else format(100.0*sum(street0CalledRaiseDone)/sum(street0CalledRaiseChance),1)
3959 ,case when sum(street0_3Bchance) = 0 then '0'
3960 else format(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
3962 ,case when sum(street0_4Bchance) = 0 then '0'
3963 else format(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
3965 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
3966 else format(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
3968 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
3969 else format(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
3971 ,case when sum(raiseFirstInChance) = 0 then '-'
3972 else format(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
3974 ,format(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
3975 ,format(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
3976 ,case when sum(street1Seen) = 0 then '-'
3977 else format(100.0*sum(sawShowdown)/sum(street1Seen),1)
3979 ,case when sum(sawShowdown) = 0 then '-'
3980 else format(100.0*sum(wonAtSD)/sum(sawShowdown),1)
3982 ,case when sum(street1Seen) = 0 then '-'
3983 else format(100.0*sum(street1Aggr)/sum(street1Seen),1)
3985 ,case when sum(street2Seen) = 0 then '-'
3986 else format(100.0*sum(street2Aggr)/sum(street2Seen),1)
3988 ,case when sum(street3Seen) = 0 then '-'
3989 else format(100.0*sum(street3Aggr)/sum(street3Seen),1)
3991 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
3992 else format(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
3993 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
3995 ,format(sum(totalProfit)/100.0,2) AS Net
3996 ,format((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
3998 ,format( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
3999 ,format( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
4001 inner join Sites s on s.Id = gt.siteId
4002 inner join HudCache hc on hc.gametypeId = gt.Id
4003 where hc.playerId in <player_test>
4005 and hc.activeSeats <seats_test>
4006 and concat( '20', substring(hc.styleKey,2,2), '-', substring(hc.styleKey,4,2), '-'
4007 , substring(hc.styleKey,6,2) ) <datestest>
4010 ,upper(gt.limitType)
4012 <groupbygt.bigBlind>
4016 ( select # profit from handsplayers/handsactions
4017 hprof.gtId, sum(hprof.profit) sum_profit,
4018 avg(hprof.profit/100.0) profitperhand,
4019 case when hprof.gtId = -1 then -999
4020 else variance(hprof.profit/100.0)
4022 ,sqrt(variance(hprof.profit/100.0)) AS stddev
4024 (select hp.handId, <hgametypeId> as gtId, hp.totalProfit as profit
4025 from HandsPlayers hp
4026 inner join Hands h ON h.id = hp.handId
4027 where hp.playerId in <player_test>
4028 and hp.tourneysPlayersId IS NULL
4029 and date_format(h.startTime, '%Y-%m-%d') <datestest>
4030 group by hp.handId, gtId, hp.totalProfit
4034 on hprof2.gtId = stats.gtId
4035 order by stats.category, stats.limittype, stats.bigBlindDesc desc <orderbyseats>"""
4036 elif db_server
== 'sqlite':
4037 self
.query
['playerStats'] = """
4039 upper(substr(stats.category,1,1)) || substr(stats.category,2) || ' ' ||
4040 stats.name || ' ' ||
4041 cast(stats.bigBlindDesc as char) || ' ' || stats.maxSeats || ' seat' AS Game
4042 ,stats.n,stats.vpip,stats.pfr,stats.pf3,stats.pf4,stats.pff3,stats.pff4
4043 ,stats.steals,stats.saw_f,stats.sawsd,stats.wtsdwsf,stats.wmsd,stats.FlAFq
4044 ,stats.TuAFq,stats.RvAFq,stats.PoFAFq,stats.Net,stats.BBper100,stats.Profitperhand
4045 ,case when hprof2.variance = -999 then '-' else round(hprof2.variance, 2)
4047 ,case when hprof2.stddev = -999 then '-' else round(hprof2.stddev, 2)
4051 (select /* stats from hudcache */
4053 ,gt.category,maxSeats,gt.bigBlind,gt.currency
4054 ,upper(gt.limitType) AS limitType
4056 ,<selectgt.bigBlind> AS bigBlindDesc
4057 ,<hcgametypeId> AS gtId
4059 ,round(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
4060 ,round(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
4061 ,case when sum(street0CalledRaiseChance) = 0 then '0'
4062 else round(100.0*sum(street0CalledRaiseDone)/sum(street0CalledRaiseChance),1)
4064 ,case when sum(street0_3Bchance) = 0 then '0'
4065 else round(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
4067 ,case when sum(street0_4Bchance) = 0 then '0'
4068 else round(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
4070 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
4071 else round(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
4073 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
4074 else round(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
4076 ,case when sum(raiseFirstInChance) = 0 then '-'
4077 else round(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
4079 ,round(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
4080 ,round(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
4081 ,case when sum(street1Seen) = 0 then '-'
4082 else round(100.0*sum(sawShowdown)/sum(street1Seen),1)
4084 ,case when sum(sawShowdown) = 0 then '-'
4085 else round(100.0*sum(wonAtSD)/sum(sawShowdown),1)
4087 ,case when sum(street1Seen) = 0 then '-'
4088 else round(100.0*sum(street1Aggr)/sum(street1Seen),1)
4090 ,case when sum(street2Seen) = 0 then '-'
4091 else round(100.0*sum(street2Aggr)/sum(street2Seen),1)
4093 ,case when sum(street3Seen) = 0 then '-'
4094 else round(100.0*sum(street3Aggr)/sum(street3Seen),1)
4096 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
4097 else round(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
4098 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
4100 ,round(sum(totalProfit)/100.0,2) AS Net
4101 ,round((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
4103 ,round( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
4104 ,round( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
4106 inner join Sites s on s.Id = gt.siteId
4107 inner join HudCache hc on hc.gametypeId = gt.Id
4108 where hc.playerId in <player_test>
4110 and hc.activeSeats <seats_test>
4111 and '20' || substr(hc.styleKey,2,2) || '-' || substr(hc.styleKey,4,2) || '-' ||
4112 substr(hc.styleKey,6,2) <datestest>
4113 group by gt.base,gt.category,upper(gt.limitType),s.name <groupbygt.bigBlind>,gtId
4116 ( select /* profit from handsplayers/handsactions */
4117 hprof.gtId, sum(hprof.profit) sum_profit,
4118 avg(hprof.profit/100.0) profitperhand,
4119 case when hprof.gtId = -1 then -999
4120 else variance(hprof.profit/100.0)
4122 ,case when hprof.gtId = -1 then -999
4123 else sqrt(variance(hprof.profit/100.0))
4126 (select hp.handId, <hgametypeId> as gtId, hp.totalProfit as profit
4127 from HandsPlayers hp
4128 inner join Hands h ON h.id = hp.handId
4129 where hp.playerId in <player_test>
4130 and hp.tourneysPlayersId IS NULL
4131 and datetime(h.startTime) <datestest>
4132 group by hp.handId, gtId, hp.totalProfit
4136 on hprof2.gtId = stats.gtId
4137 order by stats.category, stats.bigBlind, stats.limittype, stats.currency, stats.maxSeats <orderbyseats>"""
4138 else: # assume postgres
4139 self
.query
['playerStats'] = """
4140 SELECT upper(stats.limitType) || ' '
4141 || initcap(stats.category) || ' '
4142 || stats.name || ' '
4143 || stats.bigBlindDesc AS Game
4162 ,stats.Profitperhand
4163 ,case when hprof2.variance = -999 then '-'
4164 else to_char(hprof2.variance, '0D00')
4166 ,case when hprof2.stddev = -999 then '-'
4167 else to_char(hprof2.stddev, '0D00')
4173 ,upper(gt.limitType) AS limitType
4175 ,<selectgt.bigBlind> AS bigBlindDesc
4176 ,<hcgametypeId> AS gtId
4178 ,to_char(100.0*sum(street0VPI)/sum(HDs),'990D0') AS vpip
4179 ,to_char(100.0*sum(street0Aggr)/sum(HDs),'90D0') AS pfr
4180 ,case when sum(street0CalledRaiseChance) = 0 then '0'
4181 else to_char(100.0*sum(street0CalledRaiseDone)/sum(street0CalledRaiseChance),'90D0')
4183 ,case when sum(street0_3Bchance) = 0 then '0'
4184 else to_char(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),'90D0')
4186 ,case when sum(raiseFirstInChance) = 0 then '-'
4187 else to_char(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),'90D0')
4189 ,to_char(100.0*sum(street1Seen)/sum(HDs),'90D0') AS saw_f
4190 ,to_char(100.0*sum(sawShowdown)/sum(HDs),'90D0') AS sawsd
4191 ,case when sum(street1Seen) = 0 then '-'
4192 else to_char(100.0*sum(sawShowdown)/sum(street1Seen),'90D0')
4194 ,case when sum(sawShowdown) = 0 then '-'
4195 else to_char(100.0*sum(wonAtSD)/sum(sawShowdown),'90D0')
4197 ,case when sum(street1Seen) = 0 then '-'
4198 else to_char(100.0*sum(street1Aggr)/sum(street1Seen),'90D0')
4200 ,case when sum(street2Seen) = 0 then '-'
4201 else to_char(100.0*sum(street2Aggr)/sum(street2Seen),'90D0')
4203 ,case when sum(street3Seen) = 0 then '-'
4204 else to_char(100.0*sum(street3Aggr)/sum(street3Seen),'90D0')
4206 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
4207 else to_char(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
4208 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),'90D0')
4210 ,round(sum(totalProfit)/100.0,2) AS Net
4211 ,to_char((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0), '990D00')
4213 ,to_char(sum(totalProfit/100.0) / (sum(HDs)+0.0), '990D0000') AS Profitperhand
4214 ,to_char(sum(activeSeats*HDs)/(sum(HDs)+0.0),'90D00') AS AvgSeats
4216 inner join Sites s on s.Id = gt.siteId
4217 inner join HudCache hc on hc.gametypeId = gt.Id
4218 where hc.playerId in <player_test>
4220 and hc.activeSeats <seats_test>
4221 and '20' || SUBSTR(hc.styleKey,2,2) || '-' || SUBSTR(hc.styleKey,4,2) || '-'
4222 || SUBSTR(hc.styleKey,6,2) <datestest>
4225 ,upper(gt.limitType)
4227 <groupbygt.bigBlind>
4232 hprof.gtId, sum(hprof.profit) AS sum_profit,
4233 avg(hprof.profit/100.0) AS profitperhand,
4234 case when hprof.gtId = -1 then -999
4235 else variance(hprof.profit/100.0)
4237 ,case when hprof.gtId = -1 then -999
4238 else sqrt(variance(hprof.profit/100.0)
4241 (select hp.handId, <hgametypeId> as gtId, hp.totalProfit as profit
4242 from HandsPlayers hp
4243 inner join Hands h ON (h.id = hp.handId)
4244 where hp.playerId in <player_test>
4245 and hp.tourneysPlayersId IS NULL
4246 and to_char(h.startTime, 'YYYY-MM-DD') <datestest>
4247 group by hp.handId, gtId, hp.totalProfit
4251 on hprof2.gtId = stats.gtId
4252 order by stats.base, stats.limittype, stats.bigBlindDesc desc <orderbyseats>"""
4254 if db_server
== 'mysql':
4255 self
.query
['playerStatsByPosition'] = """
4257 concat(upper(stats.limitType), ' '
4258 ,concat(upper(substring(stats.category,1,1)),substring(stats.category,2) ), ' '
4260 ,cast(stats.bigBlindDesc as char)
4262 ,case when stats.PlPosition = -2 then 'BB'
4263 when stats.PlPosition = -1 then 'SB'
4264 when stats.PlPosition = 0 then 'Btn'
4265 when stats.PlPosition = 1 then 'CO'
4266 when stats.PlPosition = 2 then 'MP'
4267 when stats.PlPosition = 5 then 'EP'
4289 ,stats.Profitperhand
4290 ,case when hprof2.variance = -999 then '-'
4291 else format(hprof2.variance, 2)
4293 ,case when hprof2.stddev = -999 then '-'
4294 else format(hprof2.stddev, 2)
4298 (select /* stats from hudcache */
4301 ,upper(gt.limitType) AS limitType
4303 ,<selectgt.bigBlind> AS bigBlindDesc
4304 ,<hcgametypeId> AS gtId
4305 ,case when hc.position = 'B' then -2
4306 when hc.position = 'S' then -1
4307 when hc.position = 'D' then 0
4308 when hc.position = 'C' then 1
4309 when hc.position = 'M' then 2
4310 when hc.position = 'E' then 5
4314 ,format(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
4315 ,format(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
4316 ,case when sum(street0CalledRaiseChance) = 0 then '0'
4317 else format(100.0*sum(street0CalledRaiseDone)/sum(street0CalledRaiseChance),1)
4319 ,case when sum(street0_3Bchance) = 0 then '0'
4320 else format(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
4322 ,case when sum(street0_4Bchance) = 0 then '0'
4323 else format(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
4325 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
4326 else format(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
4328 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
4329 else format(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
4331 ,case when sum(raiseFirstInChance) = 0 then '-'
4332 else format(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
4334 ,format(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
4335 ,format(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
4336 ,case when sum(street1Seen) = 0 then '-'
4337 else format(100.0*sum(sawShowdown)/sum(street1Seen),1)
4339 ,case when sum(sawShowdown) = 0 then '-'
4340 else format(100.0*sum(wonAtSD)/sum(sawShowdown),1)
4342 ,case when sum(street1Seen) = 0 then '-'
4343 else format(100.0*sum(street1Aggr)/sum(street1Seen),1)
4345 ,case when sum(street2Seen) = 0 then '-'
4346 else format(100.0*sum(street2Aggr)/sum(street2Seen),1)
4348 ,case when sum(street3Seen) = 0 then '-'
4349 else format(100.0*sum(street3Aggr)/sum(street3Seen),1)
4351 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
4352 else format(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
4353 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
4355 ,format(sum(totalProfit)/100.0,2) AS Net
4356 ,format((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
4358 ,format( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
4359 ,format( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
4361 inner join Sites s on s.Id = gt.siteId
4362 inner join HudCache hc on hc.gametypeId = gt.Id
4363 where hc.playerId in <player_test>
4365 and hc.activeSeats <seats_test>
4366 and concat( '20', substring(hc.styleKey,2,2), '-', substring(hc.styleKey,4,2), '-'
4367 , substring(hc.styleKey,6,2) ) <datestest>
4370 ,upper(gt.limitType)
4372 <groupbygt.bigBlind>
4378 ( select # profit from handsplayers/handsactions
4380 case when hprof.position = 'B' then -2
4381 when hprof.position = 'S' then -1
4382 when hprof.position in ('3','4') then 2
4383 when hprof.position in ('6','7') then 5
4386 sum(hprof.profit) as sum_profit,
4387 avg(hprof.profit/100.0) as profitperhand,
4388 case when hprof.gtId = -1 then -999
4389 else variance(hprof.profit/100.0)
4391 ,case when hprof.gtId = -1 then -999
4392 else sqrt(variance(hprof.profit/100.0))
4395 (select hp.handId, <hgametypeId> as gtId, hp.position
4396 , hp.totalProfit as profit
4397 from HandsPlayers hp
4398 inner join Hands h ON (h.id = hp.handId)
4399 where hp.playerId in <player_test>
4400 and hp.tourneysPlayersId IS NULL
4401 and date_format(h.startTime, '%Y-%m-%d') <datestest>
4402 group by hp.handId, gtId, hp.position, hp.totalProfit
4404 group by hprof.gtId, PlPosition
4406 on ( hprof2.gtId = stats.gtId
4407 and hprof2.PlPosition = stats.PlPosition)
4408 order by stats.category, stats.limitType, stats.bigBlindDesc desc
4409 <orderbyseats>, cast(stats.PlPosition as signed)
4411 elif db_server
== 'sqlite':
4412 self
.query
['playerStatsByPosition'] = """
4414 upper(substr(stats.category,1,1)) || substr(stats.category,2) || ' ' ||
4415 stats.name || ' ' ||
4416 cast(stats.bigBlindDesc as char) || ' ' || stats.maxSeats || ' seat' AS Game
4417 ,case when stats.PlPosition = -2 then 'BB'
4418 when stats.PlPosition = -1 then 'SB'
4419 when stats.PlPosition = 0 then 'Btn'
4420 when stats.PlPosition = 1 then 'CO'
4421 when stats.PlPosition = 2 then 'MP'
4422 when stats.PlPosition = 5 then 'EP'
4425 ,stats.n,stats.vpip,stats.pfr,stats.pf3,stats.pf4,stats.pff3,stats.pff4
4426 ,stats.steals,stats.saw_f,stats.sawsd,stats.wtsdwsf,stats.wmsd,stats.FlAFq
4427 ,stats.TuAFq,stats.RvAFq,stats.PoFAFq,stats.Net,stats.BBper100,stats.Profitperhand
4428 ,case when hprof2.variance = -999 then '-'
4429 else round(hprof2.variance, 2)
4431 ,case when hprof2.variance = -999 then '-'
4432 else round(hprof2.stddev, 2)
4436 (select /* stats from hudcache */
4438 ,gt.category,maxSeats,gt.bigBlind,gt.currency
4439 ,upper(gt.limitType) AS limitType
4441 ,<selectgt.bigBlind> AS bigBlindDesc
4442 ,<hcgametypeId> AS gtId
4443 ,case when hc.position = 'B' then -2
4444 when hc.position = 'S' then -1
4445 when hc.position = 'D' then 0
4446 when hc.position = 'C' then 1
4447 when hc.position = 'M' then 2
4448 when hc.position = 'E' then 5
4452 ,round(100.0*sum(street0VPI)/sum(HDs),1) AS vpip
4453 ,round(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr
4454 ,case when sum(street0CalledRaiseChance) = 0 then '0'
4455 else round(100.0*sum(street0CalledRaiseDone)/sum(street0CalledRaiseChance),1)
4457 ,case when sum(street0_3Bchance) = 0 then '0'
4458 else round(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1)
4460 ,case when sum(street0_4Bchance) = 0 then '0'
4461 else round(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),1)
4463 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
4464 else round(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),1)
4466 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
4467 else round(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),1)
4469 ,case when sum(raiseFirstInChance) = 0 then '-'
4470 else round(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),1)
4472 ,round(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f
4473 ,round(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd
4474 ,case when sum(street1Seen) = 0 then '-'
4475 else round(100.0*sum(sawShowdown)/sum(street1Seen),1)
4477 ,case when sum(sawShowdown) = 0 then '-'
4478 else round(100.0*sum(wonAtSD)/sum(sawShowdown),1)
4480 ,case when sum(street1Seen) = 0 then '-'
4481 else round(100.0*sum(street1Aggr)/sum(street1Seen),1)
4483 ,case when sum(street2Seen) = 0 then '-'
4484 else round(100.0*sum(street2Aggr)/sum(street2Seen),1)
4486 ,case when sum(street3Seen) = 0 then '-'
4487 else round(100.0*sum(street3Aggr)/sum(street3Seen),1)
4489 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
4490 else round(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
4491 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1)
4493 ,round(sum(totalProfit)/100.0,2) AS Net
4494 ,round((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2)
4496 ,round( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand
4497 ,round( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats
4499 inner join Sites s on s.Id = gt.siteId
4500 inner join HudCache hc on hc.gametypeId = gt.Id
4501 where hc.playerId in <player_test>
4503 and hc.activeSeats <seats_test>
4504 and '20' || substr(hc.styleKey,2,2) || '-' || substr(hc.styleKey,4,2) || '-' ||
4505 substr(hc.styleKey,6,2) <datestest>
4506 group by gt.base,gt.category,upper(gt.limitType),s.name
4507 <groupbygt.bigBlind>,gtId<groupbyseats>,PlPosition
4510 ( select /* profit from handsplayers/handsactions */
4512 cast(case when hprof.position = 'B' then -2
4513 when hprof.position = 'S' then -1
4514 when hprof.position in ('3','4') then 2
4515 when hprof.position in ('6','7') then 5
4517 end as signed) as PlPosition,
4518 sum(hprof.profit) as sum_profit,
4519 avg(hprof.profit/100.0) as profitperhand,
4520 case when hprof.gtId = -1 then -999
4521 else variance(hprof.profit/100.0)
4523 ,case when hprof.gtId = -1 then -999
4524 else sqrt(variance(hprof.profit/100.0))
4527 (select hp.handId, <hgametypeId> as gtId, hp.position
4528 , hp.totalProfit as profit
4529 from HandsPlayers hp
4530 inner join Hands h ON (h.id = hp.handId)
4531 where hp.playerId in <player_test>
4532 and hp.tourneysPlayersId IS NULL
4533 and datetime(h.startTime) <datestest>
4534 group by hp.handId, gtId, hp.position, hp.totalProfit
4536 group by hprof.gtId, PlPosition
4538 on ( hprof2.gtId = stats.gtId
4539 and hprof2.PlPosition = stats.PlPosition)
4540 order by stats.category, stats.bigBlind, stats.limitType, stats.currency, stats.maxSeats <orderbyseats>
4541 ,cast(stats.PlPosition as signed)
4543 else: # assume postgresql
4544 self
.query
['playerStatsByPosition'] = """
4545 select /* stats from hudcache */
4546 upper(stats.limitType) || ' '
4547 || upper(substr(stats.category,1,1)) || substr(stats.category,2) || ' '
4548 || stats.name || ' '
4549 || stats.bigBlindDesc AS Game
4550 ,case when stats.PlPosition = -2 then 'BB'
4551 when stats.PlPosition = -1 then 'SB'
4552 when stats.PlPosition = 0 then 'Btn'
4553 when stats.PlPosition = 1 then 'CO'
4554 when stats.PlPosition = 2 then 'MP'
4555 when stats.PlPosition = 5 then 'EP'
4576 ,stats.Profitperhand
4577 ,case when hprof2.variance = -999 then '-'
4578 else to_char(hprof2.variance, '0D00')
4580 ,case when hprof2.stddev = -999 then '-'
4581 else to_char(hprof2.stddev, '0D00')
4585 (select /* stats from hudcache */
4588 ,upper(gt.limitType) AS limitType
4590 ,<selectgt.bigBlind> AS bigBlindDesc
4591 ,<hcgametypeId> AS gtId
4592 ,case when hc.position = 'B' then -2
4593 when hc.position = 'S' then -1
4594 when hc.position = 'D' then 0
4595 when hc.position = 'C' then 1
4596 when hc.position = 'M' then 2
4597 when hc.position = 'E' then 5
4601 ,to_char(round(100.0*sum(street0VPI)/sum(HDs)),'990D0') AS vpip
4602 ,to_char(round(100.0*sum(street0Aggr)/sum(HDs)),'90D0') AS pfr
4603 ,case when sum(street0CalledRaiseChance) = 0 then '0'
4604 else to_char(100.0*sum(street0CalledRaiseDone)/sum(street0CalledRaiseChance),'90D0')
4606 ,case when sum(street0_3Bchance) = 0 then '0'
4607 else to_char(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),'90D0')
4609 ,case when sum(street0_4Bchance) = 0 then '0'
4610 else to_char(100.0*sum(street0_4Bdone)/sum(street0_4Bchance),'90D0')
4612 ,case when sum(street0_FoldTo3Bchance) = 0 then '0'
4613 else to_char(100.0*sum(street0_FoldTo3Bdone)/sum(street0_FoldTo3Bchance),'90D0')
4615 ,case when sum(street0_FoldTo4Bchance) = 0 then '0'
4616 else to_char(100.0*sum(street0_FoldTo4Bdone)/sum(street0_FoldTo4Bchance),'90D0')
4618 ,case when sum(raiseFirstInChance) = 0 then '-'
4619 else to_char(100.0*sum(raisedFirstIn)/sum(raiseFirstInChance),'90D0')
4621 ,to_char(round(100.0*sum(street1Seen)/sum(HDs)),'90D0') AS saw_f
4622 ,to_char(round(100.0*sum(sawShowdown)/sum(HDs)),'90D0') AS sawsd
4623 ,case when sum(street1Seen) = 0 then '-'
4624 else to_char(round(100.0*sum(sawShowdown)/sum(street1Seen)),'90D0')
4626 ,case when sum(sawShowdown) = 0 then '-'
4627 else to_char(round(100.0*sum(wonAtSD)/sum(sawShowdown)),'90D0')
4629 ,case when sum(street1Seen) = 0 then '-'
4630 else to_char(round(100.0*sum(street1Aggr)/sum(street1Seen)),'90D0')
4632 ,case when sum(street2Seen) = 0 then '-'
4633 else to_char(round(100.0*sum(street2Aggr)/sum(street2Seen)),'90D0')
4635 ,case when sum(street3Seen) = 0 then '-'
4636 else to_char(round(100.0*sum(street3Aggr)/sum(street3Seen)),'90D0')
4638 ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-'
4639 else to_char(round(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
4640 /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen))),'90D0')
4642 ,to_char(sum(totalProfit)/100.0,'9G999G990D00') AS Net
4643 ,case when sum(HDs) = 0 then '0'
4644 else to_char(sum(totalProfit/(gt.bigBlind+0.0)) / (sum(HDs)/100.0), '990D00')
4646 ,case when sum(HDs) = 0 then '0'
4647 else to_char( (sum(totalProfit)/100.0) / sum(HDs), '90D0000')
4648 end AS Profitperhand
4649 ,to_char(sum(activeSeats*HDs)/(sum(HDs)+0.0),'90D00') AS AvgSeats
4651 inner join Sites s on (s.Id = gt.siteId)
4652 inner join HudCache hc on (hc.gametypeId = gt.Id)
4653 where hc.playerId in <player_test>
4655 and hc.activeSeats <seats_test>
4656 and '20' || SUBSTR(hc.styleKey,2,2) || '-' || SUBSTR(hc.styleKey,4,2) || '-'
4657 || SUBSTR(hc.styleKey,6,2) <datestest>
4660 ,upper(gt.limitType)
4662 <groupbygt.bigBlind>
4668 ( select /* profit from handsplayers/handsactions */
4670 case when hprof.position = 'B' then -2
4671 when hprof.position = 'S' then -1
4672 when hprof.position in ('3','4') then 2
4673 when hprof.position in ('6','7') then 5
4674 else cast(hprof.position as smallint)
4676 sum(hprof.profit) as sum_profit,
4677 avg(hprof.profit/100.0) as profitperhand,
4678 case when hprof.gtId = -1 then -999
4679 else variance(hprof.profit/100.0)
4681 ,case when hprof.gtId = -1 then -999
4682 else sqrt(variance(hprof.profit/100.0))
4685 (select hp.handId, <hgametypeId> as gtId, hp.position
4686 , hp.totalProfit as profit
4687 from HandsPlayers hp
4688 inner join Hands h ON (h.id = hp.handId)
4689 where hp.playerId in <player_test>
4690 and hp.tourneysPlayersId IS NULL
4691 and to_char(h.startTime, 'YYYY-MM-DD') <datestest>
4692 group by hp.handId, gametypeId, hp.position, hp.totalProfit
4694 group by hprof.gtId, PlPosition
4696 on ( hprof2.gtId = stats.gtId
4697 and hprof2.PlPosition = stats.PlPosition)
4698 order by stats.category, stats.limitType, stats.bigBlindDesc desc
4699 <orderbyseats>, cast(stats.PlPosition as smallint)
4702 ####################################
4703 # Cash Game Graph query
4704 ####################################
4705 self
.query
['getRingProfitAllHandsPlayerIdSite'] = """
4706 SELECT hp.handId, hp.totalProfit, hp.sawShowdown
4707 FROM HandsPlayers hp
4708 INNER JOIN Players pl ON (pl.id = hp.playerId)
4709 INNER JOIN Hands h ON (h.id = hp.handId)
4710 INNER JOIN Gametypes gt ON (gt.id = h.gametypeId)
4711 WHERE pl.id in <player_test>
4712 AND pl.siteId in <site_test>
4713 AND h.startTime > '<startdate_test>'
4714 AND h.startTime < '<enddate_test>'
4717 AND gt.type = 'ring'
4718 GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit
4719 ORDER BY h.startTime"""
4721 self
.query
['getRingProfitAllHandsPlayerIdSiteInBB'] = """
4722 SELECT hp.handId, ( hp.totalProfit / ( gt.bigBlind * 2.0 ) ) * 100 , hp.sawShowdown, ( hp.allInEV / ( gt.bigBlind * 2.0 ) ) * 100
4723 FROM HandsPlayers hp
4724 INNER JOIN Players pl ON (pl.id = hp.playerId)
4725 INNER JOIN Hands h ON (h.id = hp.handId)
4726 INNER JOIN Gametypes gt ON (gt.id = h.gametypeId)
4727 WHERE pl.id in <player_test>
4728 AND pl.siteId in <site_test>
4729 AND h.startTime > '<startdate_test>'
4730 AND h.startTime < '<enddate_test>'
4734 AND hp.tourneysPlayersId IS NULL
4735 GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit, hp.allInEV
4736 ORDER BY h.startTime"""
4738 self
.query
['getRingProfitAllHandsPlayerIdSiteInDollars'] = """
4739 SELECT hp.handId, hp.totalProfit, hp.sawShowdown, hp.allInEV
4740 FROM HandsPlayers hp
4741 INNER JOIN Players pl ON (pl.id = hp.playerId)
4742 INNER JOIN Hands h ON (h.id = hp.handId)
4743 INNER JOIN Gametypes gt ON (gt.id = h.gametypeId)
4744 WHERE pl.id in <player_test>
4745 AND pl.siteId in <site_test>
4746 AND h.startTime > '<startdate_test>'
4747 AND h.startTime < '<enddate_test>'
4751 AND hp.tourneysPlayersId IS NULL
4752 GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit, hp.allInEV
4753 ORDER BY h.startTime"""
4757 ####################################
4758 # Tourney Results query
4759 ####################################
4760 self
.query
['tourneyResults'] = """
4761 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
4762 FROM TourneysPlayers tp
4763 INNER JOIN Players pl ON (pl.id = tp.playerId)
4764 INNER JOIN Tourneys t ON (t.id = tp.tourneyId)
4765 INNER JOIN TourneyTypes tt ON (tt.id = t.tourneyTypeId)
4766 WHERE pl.id in <player_test>
4767 AND pl.siteId in <site_test>
4768 AND ((t.startTime > '<startdate_test>' AND t.startTime < '<enddate_test>')
4769 OR t.startTime is NULL)
4770 GROUP BY t.startTime, tp.tourneyId, tp.winningsCurrency,
4771 tp.winnings, tp.koCount,
4772 tp.rebuyCount, tp.addOnCount,
4774 ORDER BY t.startTime"""
4776 #AND gt.type = 'ring'
4780 ####################################
4781 # Session stats query
4782 ####################################
4783 if db_server
== 'mysql':
4784 self
.query
['sessionStats'] = """
4785 SELECT UNIX_TIMESTAMP(h.startTime) as time, hp.totalProfit
4786 FROM HandsPlayers hp
4787 INNER JOIN Hands h on (h.id = hp.handId)
4788 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
4789 INNER JOIN Sites s on (s.Id = gt.siteId)
4790 INNER JOIN Players p on (p.Id = hp.playerId)
4791 WHERE hp.playerId in <player_test>
4792 AND date_format(h.startTime, '%Y-%m-%d') <datestest>
4793 AND gt.type LIKE 'ring'
4799 elif db_server
== 'postgresql':
4800 self
.query
['sessionStats'] = """
4801 SELECT EXTRACT(epoch from h.startTime) as time, hp.totalProfit
4802 FROM HandsPlayers hp
4803 INNER JOIN Hands h on (h.id = hp.handId)
4804 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
4805 INNER JOIN Sites s on (s.Id = gt.siteId)
4806 INNER JOIN Players p on (p.Id = hp.playerId)
4807 WHERE hp.playerId in <player_test>
4808 AND h.startTime <datestest>
4809 AND gt.type LIKE 'ring'
4815 elif db_server
== 'sqlite':
4816 self
.query
['sessionStats'] = """
4817 SELECT STRFTIME('<ampersand_s>', h.startTime) as time, hp.totalProfit
4818 FROM HandsPlayers hp
4819 INNER JOIN Hands h on (h.id = hp.handId)
4820 INNER JOIN Gametypes gt on (gt.Id = h.gametypeId)
4821 INNER JOIN Sites s on (s.Id = gt.siteId)
4822 INNER JOIN Players p on (p.Id = hp.playerId)
4823 WHERE hp.playerId in <player_test>
4824 AND h.startTime <datestest>
4825 AND gt.type is 'ring'
4832 ####################################
4833 # Querry to get all hands in a date range
4834 ####################################
4835 self
.query
['handsInRange'] = """
4838 join HandsPlayers hp on h.id = hp.handId
4839 join Gametypes gt on gt.id = h.gametypeId
4840 where h.startTime <datetest>
4841 and hp.playerId in <player_test>
4846 ####################################
4847 # Query to get a single hand for the replayer
4848 ####################################
4849 self
.query
['singleHand'] = """
4854 ####################################
4855 # Query to get a single player hand for the replayer
4856 ####################################
4857 self
.query
['playerHand'] = """
4860 round(hp.winnings / 100.0,2) as winnings,
4862 round(hp.startCash / 100.0,2) as chips,
4863 hp.card1,hp.card2,hp.card3,hp.card4,hp.card5,
4864 hp.card6,hp.card7,hp.card8,hp.card9,hp.card10,
4865 hp.card11,hp.card12,hp.card13,hp.card14,hp.card15,
4866 hp.card16,hp.card17,hp.card18,hp.card19,hp.card20,
4873 and p.id = hp.playerId
4878 ####################################
4879 # Query for the actions of a hand
4880 ####################################
4881 self
.query
['handActions'] = """
4888 round(ha.amount / 100.0,2) as bet,
4897 AND ha.handId = h.id
4898 AND ha.playerId = p.id
4903 ####################################
4904 # Queries to rebuild/modify hudcache
4905 ####################################
4907 self
.query
['clearHudCache'] = """DELETE FROM HudCache"""
4908 self
.query
['clearHudCacheTourneyType'] = """DELETE FROM HudCache WHERE tourneyTypeId = %s"""
4911 if db_server
== 'mysql':
4912 self
.query
['rebuildHudCache'] = """
4913 INSERT INTO HudCache
4918 <tourney_insert_clause>
4928 ,street0CalledRaiseChance
4929 ,street0CalledRaiseDone
4936 ,street0_FoldTo3BChance
4937 ,street0_FoldTo3BDone
4938 ,street0_FoldTo4BChance
4939 ,street0_FoldTo4BDone
4940 ,street0_SqueezeChance
4941 ,street0_SqueezeDone
4959 ,foldToOtherRaisedStreet0
4960 ,foldToOtherRaisedStreet1
4961 ,foldToOtherRaisedStreet2
4962 ,foldToOtherRaisedStreet3
4963 ,foldToOtherRaisedStreet4
4966 ,foldBbToStealChance
4968 ,foldSbToStealChance
4978 ,foldToStreet1CBChance
4979 ,foldToStreet1CBDone
4980 ,foldToStreet2CBChance
4981 ,foldToStreet2CBDone
4982 ,foldToStreet3CBChance
4983 ,foldToStreet3CBDone
4984 ,foldToStreet4CBChance
4985 ,foldToStreet4CBDone
4988 ,street1CheckCallRaiseChance
4989 ,street1CheckCallRaiseDone
4990 ,street2CheckCallRaiseChance
4991 ,street2CheckCallRaiseDone
4992 ,street3CheckCallRaiseChance
4993 ,street3CheckCallRaiseDone
4994 ,street4CheckCallRaiseChance
4995 ,street4CheckCallRaiseDone
5016 <tourney_select_clause>
5019 ,sum(wonWhenSeenStreet1)
5020 ,sum(wonWhenSeenStreet2)
5021 ,sum(wonWhenSeenStreet3)
5022 ,sum(wonWhenSeenStreet4)
5026 ,sum(street0CalledRaiseChance)
5027 ,sum(street0CalledRaiseDone)
5028 ,sum(street0_3BChance)
5029 ,sum(street0_3BDone)
5030 ,sum(street0_4BChance)
5031 ,sum(street0_4BDone)
5032 ,sum(street0_C4BChance)
5033 ,sum(street0_C4BDone)
5034 ,sum(street0_FoldTo3BChance)
5035 ,sum(street0_FoldTo3BDone)
5036 ,sum(street0_FoldTo4BChance)
5037 ,sum(street0_FoldTo4BDone)
5038 ,sum(street0_SqueezeChance)
5039 ,sum(street0_SqueezeDone)
5040 ,sum(raiseToStealChance)
5041 ,sum(raiseToStealDone)
5052 ,sum(otherRaisedStreet0)
5053 ,sum(otherRaisedStreet1)
5054 ,sum(otherRaisedStreet2)
5055 ,sum(otherRaisedStreet3)
5056 ,sum(otherRaisedStreet4)
5057 ,sum(foldToOtherRaisedStreet0)
5058 ,sum(foldToOtherRaisedStreet1)
5059 ,sum(foldToOtherRaisedStreet2)
5060 ,sum(foldToOtherRaisedStreet3)
5061 ,sum(foldToOtherRaisedStreet4)
5062 ,sum(raiseFirstInChance)
5064 ,sum(foldBbToStealChance)
5065 ,sum(foldedBbToSteal)
5066 ,sum(foldSbToStealChance)
5067 ,sum(foldedSbToSteal)
5068 ,sum(street1CBChance)
5070 ,sum(street2CBChance)
5072 ,sum(street3CBChance)
5074 ,sum(street4CBChance)
5076 ,sum(foldToStreet1CBChance)
5077 ,sum(foldToStreet1CBDone)
5078 ,sum(foldToStreet2CBChance)
5079 ,sum(foldToStreet2CBDone)
5080 ,sum(foldToStreet3CBChance)
5081 ,sum(foldToStreet3CBDone)
5082 ,sum(foldToStreet4CBChance)
5083 ,sum(foldToStreet4CBDone)
5086 ,sum(street1CheckCallRaiseChance)
5087 ,sum(street1CheckCallRaiseDone)
5088 ,sum(street2CheckCallRaiseChance)
5089 ,sum(street2CheckCallRaiseDone)
5090 ,sum(street3CheckCallRaiseChance)
5091 ,sum(street3CheckCallRaiseDone)
5092 ,sum(street4CheckCallRaiseChance)
5093 ,sum(street4CheckCallRaiseDone)
5104 ,sum(hp.street0Raises)
5105 ,sum(hp.street1Raises)
5106 ,sum(hp.street2Raises)
5107 ,sum(hp.street3Raises)
5108 ,sum(hp.street4Raises)
5109 FROM HandsPlayers hp
5110 INNER JOIN Hands h ON (h.id = hp.handId)
5111 <tourney_join_clause>
5113 GROUP BY h.gametypeId
5117 <tourney_group_clause>
5120 elif db_server
== 'postgresql':
5121 self
.query
['rebuildHudCache'] = """
5122 INSERT INTO HudCache
5127 <tourney_insert_clause>
5137 ,street0CalledRaiseChance
5138 ,street0CalledRaiseDone
5145 ,street0_FoldTo3BChance
5146 ,street0_FoldTo3BDone
5147 ,street0_FoldTo4BChance
5148 ,street0_FoldTo4BDone
5149 ,street0_SqueezeChance
5150 ,street0_SqueezeDone
5168 ,foldToOtherRaisedStreet0
5169 ,foldToOtherRaisedStreet1
5170 ,foldToOtherRaisedStreet2
5171 ,foldToOtherRaisedStreet3
5172 ,foldToOtherRaisedStreet4
5175 ,foldBbToStealChance
5177 ,foldSbToStealChance
5187 ,foldToStreet1CBChance
5188 ,foldToStreet1CBDone
5189 ,foldToStreet2CBChance
5190 ,foldToStreet2CBDone
5191 ,foldToStreet3CBChance
5192 ,foldToStreet3CBDone
5193 ,foldToStreet4CBChance
5194 ,foldToStreet4CBDone
5197 ,street1CheckCallRaiseChance
5198 ,street1CheckCallRaiseDone
5199 ,street2CheckCallRaiseChance
5200 ,street2CheckCallRaiseDone
5201 ,street3CheckCallRaiseChance
5202 ,street3CheckCallRaiseDone
5203 ,street4CheckCallRaiseChance
5204 ,street4CheckCallRaiseDone
5225 <tourney_select_clause>
5228 ,sum(wonWhenSeenStreet1)
5229 ,sum(wonWhenSeenStreet2)
5230 ,sum(wonWhenSeenStreet3)
5231 ,sum(wonWhenSeenStreet4)
5233 ,sum(CAST(street0VPI as integer))
5234 ,sum(CAST(street0Aggr as integer))
5235 ,sum(CAST(street0CalledRaiseChance as integer))
5236 ,sum(CAST(street0CalledRaiseDone as integer))
5237 ,sum(CAST(street0_3BChance as integer))
5238 ,sum(CAST(street0_3BDone as integer))
5239 ,sum(CAST(street0_4BChance as integer))
5240 ,sum(CAST(street0_4BDone as integer))
5241 ,sum(CAST(street0_C4BChance as integer))
5242 ,sum(CAST(street0_C4BDone as integer))
5243 ,sum(CAST(street0_FoldTo3BChance as integer))
5244 ,sum(CAST(street0_FoldTo3BDone as integer))
5245 ,sum(CAST(street0_FoldTo4BChance as integer))
5246 ,sum(CAST(street0_FoldTo4BDone as integer))
5247 ,sum(CAST(street0_SqueezeChance as integer))
5248 ,sum(CAST(street0_SqueezeDone as integer))
5249 ,sum(CAST(raiseToStealChance as integer))
5250 ,sum(CAST(raiseToStealDone as integer))
5251 ,sum(CAST(success_Steal as integer))
5252 ,sum(CAST(street1Seen as integer))
5253 ,sum(CAST(street2Seen as integer))
5254 ,sum(CAST(street3Seen as integer))
5255 ,sum(CAST(street4Seen as integer))
5256 ,sum(CAST(sawShowdown as integer))
5257 ,sum(CAST(street1Aggr as integer))
5258 ,sum(CAST(street2Aggr as integer))
5259 ,sum(CAST(street3Aggr as integer))
5260 ,sum(CAST(street4Aggr as integer))
5261 ,sum(CAST(otherRaisedStreet0 as integer))
5262 ,sum(CAST(otherRaisedStreet1 as integer))
5263 ,sum(CAST(otherRaisedStreet2 as integer))
5264 ,sum(CAST(otherRaisedStreet3 as integer))
5265 ,sum(CAST(otherRaisedStreet4 as integer))
5266 ,sum(CAST(foldToOtherRaisedStreet0 as integer))
5267 ,sum(CAST(foldToOtherRaisedStreet1 as integer))
5268 ,sum(CAST(foldToOtherRaisedStreet2 as integer))
5269 ,sum(CAST(foldToOtherRaisedStreet3 as integer))
5270 ,sum(CAST(foldToOtherRaisedStreet4 as integer))
5271 ,sum(CAST(raiseFirstInChance as integer))
5272 ,sum(CAST(raisedFirstIn as integer))
5273 ,sum(CAST(foldBbToStealChance as integer))
5274 ,sum(CAST(foldedBbToSteal as integer))
5275 ,sum(CAST(foldSbToStealChance as integer))
5276 ,sum(CAST(foldedSbToSteal as integer))
5277 ,sum(CAST(street1CBChance as integer))
5278 ,sum(CAST(street1CBDone as integer))
5279 ,sum(CAST(street2CBChance as integer))
5280 ,sum(CAST(street2CBDone as integer))
5281 ,sum(CAST(street3CBChance as integer))
5282 ,sum(CAST(street3CBDone as integer))
5283 ,sum(CAST(street4CBChance as integer))
5284 ,sum(CAST(street4CBDone as integer))
5285 ,sum(CAST(foldToStreet1CBChance as integer))
5286 ,sum(CAST(foldToStreet1CBDone as integer))
5287 ,sum(CAST(foldToStreet2CBChance as integer))
5288 ,sum(CAST(foldToStreet2CBDone as integer))
5289 ,sum(CAST(foldToStreet3CBChance as integer))
5290 ,sum(CAST(foldToStreet3CBDone as integer))
5291 ,sum(CAST(foldToStreet4CBChance as integer))
5292 ,sum(CAST(foldToStreet4CBDone as integer))
5293 ,sum(CAST(totalProfit as integer))
5294 ,sum(CAST(rake as integer))
5295 ,sum(CAST(street1CheckCallRaiseChance as integer))
5296 ,sum(CAST(street1CheckCallRaiseDone as integer))
5297 ,sum(CAST(street2CheckCallRaiseChance as integer))
5298 ,sum(CAST(street2CheckCallRaiseDone as integer))
5299 ,sum(CAST(street3CheckCallRaiseChance as integer))
5300 ,sum(CAST(street3CheckCallRaiseDone as integer))
5301 ,sum(CAST(street4CheckCallRaiseChance as integer))
5302 ,sum(CAST(street4CheckCallRaiseDone as integer))
5303 ,sum(CAST(street0Calls as integer))
5304 ,sum(CAST(street1Calls as integer))
5305 ,sum(CAST(street2Calls as integer))
5306 ,sum(CAST(street3Calls as integer))
5307 ,sum(CAST(street4Calls as integer))
5308 ,sum(CAST(street0Bets as integer))
5309 ,sum(CAST(street1Bets as integer))
5310 ,sum(CAST(street2Bets as integer))
5311 ,sum(CAST(street3Bets as integer))
5312 ,sum(CAST(street4Bets as integer))
5313 ,sum(CAST(hp.street0Raises as integer))
5314 ,sum(CAST(hp.street1Raises as integer))
5315 ,sum(CAST(hp.street2Raises as integer))
5316 ,sum(CAST(hp.street3Raises as integer))
5317 ,sum(CAST(hp.street4Raises as integer))
5318 FROM HandsPlayers hp
5319 INNER JOIN Hands h ON (h.id = hp.handId)
5320 <tourney_join_clause>
5322 GROUP BY h.gametypeId
5326 <tourney_group_clause>
5329 else: # assume sqlite
5330 self
.query
['rebuildHudCache'] = """
5331 INSERT INTO HudCache
5336 <tourney_insert_clause>
5346 ,street0CalledRaiseChance
5347 ,street0CalledRaiseDone
5354 ,street0_FoldTo3BChance
5355 ,street0_FoldTo3BDone
5356 ,street0_FoldTo4BChance
5357 ,street0_FoldTo4BDone
5358 ,street0_SqueezeChance
5359 ,street0_SqueezeDone
5377 ,foldToOtherRaisedStreet0
5378 ,foldToOtherRaisedStreet1
5379 ,foldToOtherRaisedStreet2
5380 ,foldToOtherRaisedStreet3
5381 ,foldToOtherRaisedStreet4
5384 ,foldBbToStealChance
5386 ,foldSbToStealChance
5396 ,foldToStreet1CBChance
5397 ,foldToStreet1CBDone
5398 ,foldToStreet2CBChance
5399 ,foldToStreet2CBDone
5400 ,foldToStreet3CBChance
5401 ,foldToStreet3CBDone
5402 ,foldToStreet4CBChance
5403 ,foldToStreet4CBDone
5406 ,street1CheckCallRaiseChance
5407 ,street1CheckCallRaiseDone
5408 ,street2CheckCallRaiseChance
5409 ,street2CheckCallRaiseDone
5410 ,street3CheckCallRaiseChance
5411 ,street3CheckCallRaiseDone
5412 ,street4CheckCallRaiseChance
5413 ,street4CheckCallRaiseDone
5434 <tourney_select_clause>
5437 ,sum(wonWhenSeenStreet1)
5438 ,sum(wonWhenSeenStreet2)
5439 ,sum(wonWhenSeenStreet3)
5440 ,sum(wonWhenSeenStreet4)
5442 ,sum(CAST(street0VPI as integer))
5443 ,sum(CAST(street0Aggr as integer))
5444 ,sum(CAST(street0CalledRaiseChance as integer))
5445 ,sum(CAST(street0CalledRaiseDone as integer))
5446 ,sum(CAST(street0_3BChance as integer))
5447 ,sum(CAST(street0_3BDone as integer))
5448 ,sum(CAST(street0_4BChance as integer))
5449 ,sum(CAST(street0_4BDone as integer))
5450 ,sum(CAST(street0_C4BChance as integer))
5451 ,sum(CAST(street0_C4BDone as integer))
5452 ,sum(CAST(street0_FoldTo3BChance as integer))
5453 ,sum(CAST(street0_FoldTo3BDone as integer))
5454 ,sum(CAST(street0_FoldTo4BChance as integer))
5455 ,sum(CAST(street0_FoldTo4BDone as integer))
5456 ,sum(CAST(street0_SqueezeChance as integer))
5457 ,sum(CAST(street0_SqueezeDone as integer))
5458 ,sum(CAST(raiseToStealChance as integer))
5459 ,sum(CAST(raiseToStealDone as integer))
5460 ,sum(CAST(success_Steal as integer))
5461 ,sum(CAST(street1Seen as integer))
5462 ,sum(CAST(street2Seen as integer))
5463 ,sum(CAST(street3Seen as integer))
5464 ,sum(CAST(street4Seen as integer))
5465 ,sum(CAST(sawShowdown as integer))
5466 ,sum(CAST(street1Aggr as integer))
5467 ,sum(CAST(street2Aggr as integer))
5468 ,sum(CAST(street3Aggr as integer))
5469 ,sum(CAST(street4Aggr as integer))
5470 ,sum(CAST(otherRaisedStreet0 as integer))
5471 ,sum(CAST(otherRaisedStreet1 as integer))
5472 ,sum(CAST(otherRaisedStreet2 as integer))
5473 ,sum(CAST(otherRaisedStreet3 as integer))
5474 ,sum(CAST(otherRaisedStreet4 as integer))
5475 ,sum(CAST(foldToOtherRaisedStreet0 as integer))
5476 ,sum(CAST(foldToOtherRaisedStreet1 as integer))
5477 ,sum(CAST(foldToOtherRaisedStreet2 as integer))
5478 ,sum(CAST(foldToOtherRaisedStreet3 as integer))
5479 ,sum(CAST(foldToOtherRaisedStreet4 as integer))
5480 ,sum(CAST(raiseFirstInChance as integer))
5481 ,sum(CAST(raisedFirstIn as integer))
5482 ,sum(CAST(foldBbToStealChance as integer))
5483 ,sum(CAST(foldedBbToSteal as integer))
5484 ,sum(CAST(foldSbToStealChance as integer))
5485 ,sum(CAST(foldedSbToSteal as integer))
5486 ,sum(CAST(street1CBChance as integer))
5487 ,sum(CAST(street1CBDone as integer))
5488 ,sum(CAST(street2CBChance as integer))
5489 ,sum(CAST(street2CBDone as integer))
5490 ,sum(CAST(street3CBChance as integer))
5491 ,sum(CAST(street3CBDone as integer))
5492 ,sum(CAST(street4CBChance as integer))
5493 ,sum(CAST(street4CBDone as integer))
5494 ,sum(CAST(foldToStreet1CBChance as integer))
5495 ,sum(CAST(foldToStreet1CBDone as integer))
5496 ,sum(CAST(foldToStreet2CBChance as integer))
5497 ,sum(CAST(foldToStreet2CBDone as integer))
5498 ,sum(CAST(foldToStreet3CBChance as integer))
5499 ,sum(CAST(foldToStreet3CBDone as integer))
5500 ,sum(CAST(foldToStreet4CBChance as integer))
5501 ,sum(CAST(foldToStreet4CBDone as integer))
5502 ,sum(CAST(totalProfit as integer))
5503 ,sum(CAST(rake as integer))
5504 ,sum(CAST(street1CheckCallRaiseChance as integer))
5505 ,sum(CAST(street1CheckCallRaiseDone as integer))
5506 ,sum(CAST(street2CheckCallRaiseChance as integer))
5507 ,sum(CAST(street2CheckCallRaiseDone as integer))
5508 ,sum(CAST(street3CheckCallRaiseChance as integer))
5509 ,sum(CAST(street3CheckCallRaiseDone as integer))
5510 ,sum(CAST(street4CheckCallRaiseChance as integer))
5511 ,sum(CAST(street4CheckCallRaiseDone as integer))
5512 ,sum(CAST(street0Calls as integer))
5513 ,sum(CAST(street1Calls as integer))
5514 ,sum(CAST(street2Calls as integer))
5515 ,sum(CAST(street3Calls as integer))
5516 ,sum(CAST(street4Calls as integer))
5517 ,sum(CAST(street0Bets as integer))
5518 ,sum(CAST(street1Bets as integer))
5519 ,sum(CAST(street2Bets as integer))
5520 ,sum(CAST(street3Bets as integer))
5521 ,sum(CAST(street4Bets as integer))
5522 ,sum(CAST(hp.street0Raises as integer))
5523 ,sum(CAST(hp.street1Raises as integer))
5524 ,sum(CAST(hp.street2Raises as integer))
5525 ,sum(CAST(hp.street3Raises as integer))
5526 ,sum(CAST(hp.street4Raises as integer))
5527 FROM HandsPlayers hp
5528 INNER JOIN Hands h ON (h.id = hp.handId)
5529 <tourney_join_clause>
5531 GROUP BY h.gametypeId
5535 <tourney_group_clause>
5539 self
.query
['insert_hudcache'] = """
5540 insert into HudCache (
5550 street0CalledRaiseChance,
5551 street0CalledRaiseDone,
5558 street0_FoldTo3BChance,
5559 street0_FoldTo3BDone,
5560 street0_FoldTo4BChance,
5561 street0_FoldTo4BDone,
5562 street0_SqueezeChance,
5563 street0_SqueezeDone,
5581 foldToOtherRaisedStreet0,
5582 foldToOtherRaisedStreet1,
5583 foldToOtherRaisedStreet2,
5584 foldToOtherRaisedStreet3,
5585 foldToOtherRaisedStreet4,
5593 foldBbToStealChance,
5595 foldSbToStealChance,
5605 foldToStreet1CBChance,
5606 foldToStreet1CBDone,
5607 foldToStreet2CBChance,
5608 foldToStreet2CBDone,
5609 foldToStreet3CBChance,
5610 foldToStreet3CBDone,
5611 foldToStreet4CBChance,
5612 foldToStreet4CBDone,
5615 street1CheckCallRaiseChance,
5616 street1CheckCallRaiseDone,
5617 street2CheckCallRaiseChance,
5618 street2CheckCallRaiseDone,
5619 street3CheckCallRaiseChance,
5620 street3CheckCallRaiseDone,
5621 street4CheckCallRaiseChance,
5622 street4CheckCallRaiseDone,
5638 values (%s, %s, %s, %s, %s,
5659 self
.query
['update_hudcache'] = """
5662 street0VPI=street0VPI+%s,
5663 street0Aggr=street0Aggr+%s,
5664 street0CalledRaiseChance=street0CalledRaiseChance+%s,
5665 street0CalledRaiseDone=street0CalledRaiseDone+%s,
5666 street0_3BChance=street0_3BChance+%s,
5667 street0_3BDone=street0_3BDone+%s,
5668 street0_4BChance=street0_4BChance+%s,
5669 street0_4BDone=street0_4BDone+%s,
5670 street0_C4BChance=street0_C4BChance+%s,
5671 street0_C4BDone=street0_C4BDone+%s,
5672 street0_FoldTo3BChance=street0_FoldTo3BChance+%s,
5673 street0_FoldTo3BDone=street0_FoldTo3BDone+%s,
5674 street0_FoldTo4BChance=street0_FoldTo4BChance+%s,
5675 street0_FoldTo4BDone=street0_FoldTo4BDone+%s,
5676 street0_SqueezeChance=street0_SqueezeChance+%s,
5677 street0_SqueezeDone=street0_SqueezeDone+%s,
5678 raiseToStealChance=raiseToStealChance+%s,
5679 raiseToStealDone=raiseToStealDone+%s,
5680 success_Steal=success_Steal+%s,
5681 street1Seen=street1Seen+%s,
5682 street2Seen=street2Seen+%s,
5683 street3Seen=street3Seen+%s,
5684 street4Seen=street4Seen+%s,
5685 sawShowdown=sawShowdown+%s,
5686 street1Aggr=street1Aggr+%s,
5687 street2Aggr=street2Aggr+%s,
5688 street3Aggr=street3Aggr+%s,
5689 street4Aggr=street4Aggr+%s,
5690 otherRaisedStreet0=otherRaisedStreet0+%s,
5691 otherRaisedStreet1=otherRaisedStreet1+%s,
5692 otherRaisedStreet2=otherRaisedStreet2+%s,
5693 otherRaisedStreet3=otherRaisedStreet3+%s,
5694 otherRaisedStreet4=otherRaisedStreet4+%s,
5695 foldToOtherRaisedStreet0=foldToOtherRaisedStreet0+%s,
5696 foldToOtherRaisedStreet1=foldToOtherRaisedStreet1+%s,
5697 foldToOtherRaisedStreet2=foldToOtherRaisedStreet2+%s,
5698 foldToOtherRaisedStreet3=foldToOtherRaisedStreet3+%s,
5699 foldToOtherRaisedStreet4=foldToOtherRaisedStreet4+%s,
5700 wonWhenSeenStreet1=wonWhenSeenStreet1+%s,
5701 wonWhenSeenStreet2=wonWhenSeenStreet2+%s,
5702 wonWhenSeenStreet3=wonWhenSeenStreet3+%s,
5703 wonWhenSeenStreet4=wonWhenSeenStreet4+%s,
5705 raiseFirstInChance=raiseFirstInChance+%s,
5706 raisedFirstIn=raisedFirstIn+%s,
5707 foldBbToStealChance=foldBbToStealChance+%s,
5708 foldedBbToSteal=foldedBbToSteal+%s,
5709 foldSbToStealChance=foldSbToStealChance+%s,
5710 foldedSbToSteal=foldedSbToSteal+%s,
5711 street1CBChance=street1CBChance+%s,
5712 street1CBDone=street1CBDone+%s,
5713 street2CBChance=street2CBChance+%s,
5714 street2CBDone=street2CBDone+%s,
5715 street3CBChance=street3CBChance+%s,
5716 street3CBDone=street3CBDone+%s,
5717 street4CBChance=street4CBChance+%s,
5718 street4CBDone=street4CBDone+%s,
5719 foldToStreet1CBChance=foldToStreet1CBChance+%s,
5720 foldToStreet1CBDone=foldToStreet1CBDone+%s,
5721 foldToStreet2CBChance=foldToStreet2CBChance+%s,
5722 foldToStreet2CBDone=foldToStreet2CBDone+%s,
5723 foldToStreet3CBChance=foldToStreet3CBChance+%s,
5724 foldToStreet3CBDone=foldToStreet3CBDone+%s,
5725 foldToStreet4CBChance=foldToStreet4CBChance+%s,
5726 foldToStreet4CBDone=foldToStreet4CBDone+%s,
5727 totalProfit=totalProfit+%s,
5729 street1CheckCallRaiseChance=street1CheckCallRaiseChance+%s,
5730 street1CheckCallRaiseDone=street1CheckCallRaiseDone+%s,
5731 street2CheckCallRaiseChance=street2CheckCallRaiseChance+%s,
5732 street2CheckCallRaiseDone=street2CheckCallRaiseDone+%s,
5733 street3CheckCallRaiseChance=street3CheckCallRaiseChance+%s,
5734 street3CheckCallRaiseDone=street3CheckCallRaiseDone+%s,
5735 street4CheckCallRaiseChance=street4CheckCallRaiseChance+%s,
5736 street4CheckCallRaiseDone=street4CheckCallRaiseDone+%s,
5737 street0Calls=street0Calls+%s,
5738 street1Calls=street1Calls+%s,
5739 street2Calls=street2Calls+%s,
5740 street3Calls=street3Calls+%s,
5741 street4Calls=street4Calls+%s,
5742 street0Bets=street0Bets+%s,
5743 street1Bets=street1Bets+%s,
5744 street2Bets=street2Bets+%s,
5745 street3Bets=street3Bets+%s,
5746 street4Bets=street4Bets+%s,
5747 street0Raises=street0Raises+%s,
5748 street1Raises=street1Raises+%s,
5749 street2Raises=street2Raises+%s,
5750 street3Raises=street3Raises+%s,
5751 street4Raises=street4Raises+%s
5752 WHERE gametypeId+0=%s
5756 AND (case when tourneyTypeId is NULL then 1 else
5757 (case when tourneyTypeId+0=%s then 1 else 0 end) end)=1
5760 self
.query
['get_hero_hudcache_start'] = """select min(hc.styleKey)
5762 where hc.playerId in <playerid_list>
5763 and hc.styleKey like 'd%'"""
5765 ####################################
5766 # Queries to insert/update cardscache
5767 ####################################
5769 self
.query
['insert_cardscache'] = """
5770 insert into CardsCache (
5779 street0CalledRaiseChance,
5780 street0CalledRaiseDone,
5787 street0_FoldTo3BChance,
5788 street0_FoldTo3BDone,
5789 street0_FoldTo4BChance,
5790 street0_FoldTo4BDone,
5791 street0_SqueezeChance,
5792 street0_SqueezeDone,
5810 foldToOtherRaisedStreet0,
5811 foldToOtherRaisedStreet1,
5812 foldToOtherRaisedStreet2,
5813 foldToOtherRaisedStreet3,
5814 foldToOtherRaisedStreet4,
5822 foldBbToStealChance,
5824 foldSbToStealChance,
5834 foldToStreet1CBChance,
5835 foldToStreet1CBDone,
5836 foldToStreet2CBChance,
5837 foldToStreet2CBDone,
5838 foldToStreet3CBChance,
5839 foldToStreet3CBDone,
5840 foldToStreet4CBChance,
5841 foldToStreet4CBDone,
5844 street1CheckCallRaiseChance,
5845 street1CheckCallRaiseDone,
5846 street2CheckCallRaiseChance,
5847 street2CheckCallRaiseDone,
5848 street3CheckCallRaiseChance,
5849 street3CheckCallRaiseDone,
5850 street4CheckCallRaiseChance,
5851 street4CheckCallRaiseDone,
5867 values (%s, %s, %s, %s, %s,
5889 self
.query
['update_cardscache'] = """
5890 UPDATE CardsCache SET
5892 street0VPI=street0VPI+%s,
5893 street0Aggr=street0Aggr+%s,
5894 street0CalledRaiseChance=street0CalledRaiseChance+%s,
5895 street0CalledRaiseDone=street0CalledRaiseDone+%s,
5896 street0_3BChance=street0_3BChance+%s,
5897 street0_3BDone=street0_3BDone+%s,
5898 street0_4BChance=street0_4BChance+%s,
5899 street0_4BDone=street0_4BDone+%s,
5900 street0_C4BChance=street0_C4BChance+%s,
5901 street0_C4BDone=street0_C4BDone+%s,
5902 street0_FoldTo3BChance=street0_FoldTo3BChance+%s,
5903 street0_FoldTo3BDone=street0_FoldTo3BDone+%s,
5904 street0_FoldTo4BChance=street0_FoldTo4BChance+%s,
5905 street0_FoldTo4BDone=street0_FoldTo4BDone+%s,
5906 street0_SqueezeChance=street0_SqueezeChance+%s,
5907 street0_SqueezeDone=street0_SqueezeDone+%s,
5908 raiseToStealChance=raiseToStealChance+%s,
5909 raiseToStealDone=raiseToStealDone+%s,
5910 success_Steal=success_Steal+%s,
5911 street1Seen=street1Seen+%s,
5912 street2Seen=street2Seen+%s,
5913 street3Seen=street3Seen+%s,
5914 street4Seen=street4Seen+%s,
5915 sawShowdown=sawShowdown+%s,
5916 street1Aggr=street1Aggr+%s,
5917 street2Aggr=street2Aggr+%s,
5918 street3Aggr=street3Aggr+%s,
5919 street4Aggr=street4Aggr+%s,
5920 otherRaisedStreet0=otherRaisedStreet0+%s,
5921 otherRaisedStreet1=otherRaisedStreet1+%s,
5922 otherRaisedStreet2=otherRaisedStreet2+%s,
5923 otherRaisedStreet3=otherRaisedStreet3+%s,
5924 otherRaisedStreet4=otherRaisedStreet4+%s,
5925 foldToOtherRaisedStreet0=foldToOtherRaisedStreet0+%s,
5926 foldToOtherRaisedStreet1=foldToOtherRaisedStreet1+%s,
5927 foldToOtherRaisedStreet2=foldToOtherRaisedStreet2+%s,
5928 foldToOtherRaisedStreet3=foldToOtherRaisedStreet3+%s,
5929 foldToOtherRaisedStreet4=foldToOtherRaisedStreet4+%s,
5930 wonWhenSeenStreet1=wonWhenSeenStreet1+%s,
5931 wonWhenSeenStreet2=wonWhenSeenStreet2+%s,
5932 wonWhenSeenStreet3=wonWhenSeenStreet3+%s,
5933 wonWhenSeenStreet4=wonWhenSeenStreet4+%s,
5935 raiseFirstInChance=raiseFirstInChance+%s,
5936 raisedFirstIn=raisedFirstIn+%s,
5937 foldBbToStealChance=foldBbToStealChance+%s,
5938 foldedBbToSteal=foldedBbToSteal+%s,
5939 foldSbToStealChance=foldSbToStealChance+%s,
5940 foldedSbToSteal=foldedSbToSteal+%s,
5941 street1CBChance=street1CBChance+%s,
5942 street1CBDone=street1CBDone+%s,
5943 street2CBChance=street2CBChance+%s,
5944 street2CBDone=street2CBDone+%s,
5945 street3CBChance=street3CBChance+%s,
5946 street3CBDone=street3CBDone+%s,
5947 street4CBChance=street4CBChance+%s,
5948 street4CBDone=street4CBDone+%s,
5949 foldToStreet1CBChance=foldToStreet1CBChance+%s,
5950 foldToStreet1CBDone=foldToStreet1CBDone+%s,
5951 foldToStreet2CBChance=foldToStreet2CBChance+%s,
5952 foldToStreet2CBDone=foldToStreet2CBDone+%s,
5953 foldToStreet3CBChance=foldToStreet3CBChance+%s,
5954 foldToStreet3CBDone=foldToStreet3CBDone+%s,
5955 foldToStreet4CBChance=foldToStreet4CBChance+%s,
5956 foldToStreet4CBDone=foldToStreet4CBDone+%s,
5957 totalProfit=totalProfit+%s,
5959 street1CheckCallRaiseChance=street1CheckCallRaiseChance+%s,
5960 street1CheckCallRaiseDone=street1CheckCallRaiseDone+%s,
5961 street2CheckCallRaiseChance=street2CheckCallRaiseChance+%s,
5962 street2CheckCallRaiseDone=street2CheckCallRaiseDone+%s,
5963 street3CheckCallRaiseChance=street3CheckCallRaiseChance+%s,
5964 street3CheckCallRaiseDone=street3CheckCallRaiseDone+%s,
5965 street4CheckCallRaiseChance=street4CheckCallRaiseChance+%s,
5966 street4CheckCallRaiseDone=street4CheckCallRaiseDone+%s,
5967 street0Calls=street0Calls+%s,
5968 street1Calls=street1Calls+%s,
5969 street2Calls=street2Calls+%s,
5970 street3Calls=street3Calls+%s,
5971 street4Calls=street4Calls+%s,
5972 street0Bets=street0Bets+%s,
5973 street1Bets=street1Bets+%s,
5974 street2Bets=street2Bets+%s,
5975 street3Bets=street3Bets+%s,
5976 street4Bets=street4Bets+%s,
5977 street0Raises=street0Raises+%s,
5978 street1Raises=street1Raises+%s,
5979 street2Raises=street2Raises+%s,
5980 street3Raises=street3Raises+%s,
5981 street4Raises=street4Raises+%s
5986 AND startCards=%s"""
5988 ####################################
5989 # Queries to insert/update positionscache
5990 ####################################
5992 self
.query
['insert_positionscache'] = """
5993 insert into PositionsCache (
6005 street0CalledRaiseChance,
6006 street0CalledRaiseDone,
6013 street0_FoldTo3BChance,
6014 street0_FoldTo3BDone,
6015 street0_FoldTo4BChance,
6016 street0_FoldTo4BDone,
6017 street0_SqueezeChance,
6018 street0_SqueezeDone,
6036 foldToOtherRaisedStreet0,
6037 foldToOtherRaisedStreet1,
6038 foldToOtherRaisedStreet2,
6039 foldToOtherRaisedStreet3,
6040 foldToOtherRaisedStreet4,
6048 foldBbToStealChance,
6050 foldSbToStealChance,
6060 foldToStreet1CBChance,
6061 foldToStreet1CBDone,
6062 foldToStreet2CBChance,
6063 foldToStreet2CBDone,
6064 foldToStreet3CBChance,
6065 foldToStreet3CBDone,
6066 foldToStreet4CBChance,
6067 foldToStreet4CBDone,
6070 street1CheckCallRaiseChance,
6071 street1CheckCallRaiseDone,
6072 street2CheckCallRaiseChance,
6073 street2CheckCallRaiseDone,
6074 street3CheckCallRaiseChance,
6075 street3CheckCallRaiseDone,
6076 street4CheckCallRaiseChance,
6077 street4CheckCallRaiseDone,
6093 values (%s, %s, %s, %s, %s,
6115 self
.query
['update_positionscache'] = """
6116 UPDATE PositionsCache SET
6118 street0VPI=street0VPI+%s,
6119 street0Aggr=street0Aggr+%s,
6120 street0CalledRaiseChance=street0CalledRaiseChance+%s,
6121 street0CalledRaiseDone=street0CalledRaiseDone+%s,
6122 street0_3BChance=street0_3BChance+%s,
6123 street0_3BDone=street0_3BDone+%s,
6124 street0_4BChance=street0_4BChance+%s,
6125 street0_4BDone=street0_4BDone+%s,
6126 street0_C4BChance=street0_C4BChance+%s,
6127 street0_C4BDone=street0_C4BDone+%s,
6128 street0_FoldTo3BChance=street0_FoldTo3BChance+%s,
6129 street0_FoldTo3BDone=street0_FoldTo3BDone+%s,
6130 street0_FoldTo4BChance=street0_FoldTo4BChance+%s,
6131 street0_FoldTo4BDone=street0_FoldTo4BDone+%s,
6132 street0_SqueezeChance=street0_SqueezeChance+%s,
6133 street0_SqueezeDone=street0_SqueezeDone+%s,
6134 raiseToStealChance=raiseToStealChance+%s,
6135 raiseToStealDone=raiseToStealDone+%s,
6136 success_Steal=success_Steal+%s,
6137 street1Seen=street1Seen+%s,
6138 street2Seen=street2Seen+%s,
6139 street3Seen=street3Seen+%s,
6140 street4Seen=street4Seen+%s,
6141 sawShowdown=sawShowdown+%s,
6142 street1Aggr=street1Aggr+%s,
6143 street2Aggr=street2Aggr+%s,
6144 street3Aggr=street3Aggr+%s,
6145 street4Aggr=street4Aggr+%s,
6146 otherRaisedStreet0=otherRaisedStreet0+%s,
6147 otherRaisedStreet1=otherRaisedStreet1+%s,
6148 otherRaisedStreet2=otherRaisedStreet2+%s,
6149 otherRaisedStreet3=otherRaisedStreet3+%s,
6150 otherRaisedStreet4=otherRaisedStreet4+%s,
6151 foldToOtherRaisedStreet0=foldToOtherRaisedStreet0+%s,
6152 foldToOtherRaisedStreet1=foldToOtherRaisedStreet1+%s,
6153 foldToOtherRaisedStreet2=foldToOtherRaisedStreet2+%s,
6154 foldToOtherRaisedStreet3=foldToOtherRaisedStreet3+%s,
6155 foldToOtherRaisedStreet4=foldToOtherRaisedStreet4+%s,
6156 wonWhenSeenStreet1=wonWhenSeenStreet1+%s,
6157 wonWhenSeenStreet2=wonWhenSeenStreet2+%s,
6158 wonWhenSeenStreet3=wonWhenSeenStreet3+%s,
6159 wonWhenSeenStreet4=wonWhenSeenStreet4+%s,
6161 raiseFirstInChance=raiseFirstInChance+%s,
6162 raisedFirstIn=raisedFirstIn+%s,
6163 foldBbToStealChance=foldBbToStealChance+%s,
6164 foldedBbToSteal=foldedBbToSteal+%s,
6165 foldSbToStealChance=foldSbToStealChance+%s,
6166 foldedSbToSteal=foldedSbToSteal+%s,
6167 street1CBChance=street1CBChance+%s,
6168 street1CBDone=street1CBDone+%s,
6169 street2CBChance=street2CBChance+%s,
6170 street2CBDone=street2CBDone+%s,
6171 street3CBChance=street3CBChance+%s,
6172 street3CBDone=street3CBDone+%s,
6173 street4CBChance=street4CBChance+%s,
6174 street4CBDone=street4CBDone+%s,
6175 foldToStreet1CBChance=foldToStreet1CBChance+%s,
6176 foldToStreet1CBDone=foldToStreet1CBDone+%s,
6177 foldToStreet2CBChance=foldToStreet2CBChance+%s,
6178 foldToStreet2CBDone=foldToStreet2CBDone+%s,
6179 foldToStreet3CBChance=foldToStreet3CBChance+%s,
6180 foldToStreet3CBDone=foldToStreet3CBDone+%s,
6181 foldToStreet4CBChance=foldToStreet4CBChance+%s,
6182 foldToStreet4CBDone=foldToStreet4CBDone+%s,
6183 totalProfit=totalProfit+%s,
6185 street1CheckCallRaiseChance=street1CheckCallRaiseChance+%s,
6186 street1CheckCallRaiseDone=street1CheckCallRaiseDone+%s,
6187 street2CheckCallRaiseChance=street2CheckCallRaiseChance+%s,
6188 street2CheckCallRaiseDone=street2CheckCallRaiseDone+%s,
6189 street3CheckCallRaiseChance=street3CheckCallRaiseChance+%s,
6190 street3CheckCallRaiseDone=street3CheckCallRaiseDone+%s,
6191 street4CheckCallRaiseChance=street4CheckCallRaiseChance+%s,
6192 street4CheckCallRaiseDone=street4CheckCallRaiseDone+%s,
6193 street0Calls=street0Calls+%s,
6194 street1Calls=street1Calls+%s,
6195 street2Calls=street2Calls+%s,
6196 street3Calls=street3Calls+%s,
6197 street4Calls=street4Calls+%s,
6198 street0Bets=street0Bets+%s,
6199 street1Bets=street1Bets+%s,
6200 street2Bets=street2Bets+%s,
6201 street3Bets=street3Bets+%s,
6202 street4Bets=street4Bets+%s,
6203 street0Raises=street0Raises+%s,
6204 street1Raises=street1Raises+%s,
6205 street2Raises=street2Raises+%s,
6206 street3Raises=street3Raises+%s,
6207 street4Raises=street4Raises+%s
6217 ####################################
6218 # Queries to rebuild/modify sessionscache
6219 ####################################
6221 self
.query
['clear_GC_H'] = """UPDATE Hands SET gameId = NULL"""
6222 self
.query
['clear_SC_H'] = """UPDATE Hands SET sessionId = NULL"""
6223 self
.query
['clear_SC_T'] = """UPDATE Tourneys SET sessionId = NULL"""
6224 self
.query
['clear_SC_TP'] = """UPDATE TourneysPlayers SET startTime = NULL, endTime = NULL, played=0, hands=0"""
6225 self
.query
['clear_SC_GC'] = """UPDATE GamesCache SET sessionId = NULL"""
6226 self
.query
['clearSessionsCache'] = """DELETE FROM SessionsCache WHERE 1"""
6227 self
.query
['clearGamesCache'] = """DELETE FROM GamesCache WHERE 1"""
6228 self
.query
['update_RSC_H'] = """UPDATE Hands SET sessionId = %s, gameId = %s WHERE id = %s"""
6230 self
.query
['rebuildSessionsCache'] = """
6231 SELECT Hands.id as id,
6232 Hands.startTime as startTime,
6233 HandsPlayers.playerId as playerId,
6234 Hands.tourneyId as tourneyId,
6235 Hands.gametypeId as gametypeId,
6236 Gametypes.type as game,
6237 <tourney_type_clause>
6238 HandsPlayers.totalProfit as totalProfit,
6239 HandsPlayers.rake as rake,
6240 HandsPlayers.allInEV as allInEV,
6241 HandsPlayers.street0VPI as street0VPI,
6242 HandsPlayers.street1Seen as street1Seen,
6243 HandsPlayers.sawShowdown as sawShowdown
6244 FROM HandsPlayers HandsPlayers
6245 INNER JOIN Hands ON (HandsPlayers.handId = Hands.id)
6246 INNER JOIN Gametypes ON (Gametypes.id = Hands.gametypeId)
6247 <tourney_join_clause>
6248 WHERE (HandsPlayers.playerId = <where_clause>)
6249 AND Gametypes.type = %s
6250 ORDER BY Hands.startTime ASC
6251 LIMIT %s OFFSET %s"""
6253 ####################################
6255 ####################################
6257 self
.query
['select_SC'] = """
6262 WHERE sessionEnd>=%s
6263 AND sessionStart<=%s"""
6265 self
.query
['select_GC'] = """
6275 nonShowdownWinnings,
6284 ####################################
6286 ####################################
6288 self
.query
['insert_SC'] = """
6289 insert into SessionsCache (
6294 self
.query
['insert_GC'] = """
6295 insert into GamesCache (
6307 nonShowdownWinnings,
6309 values (%s, %s, %s, %s, %s, %s, %s,
6310 %s, %s, %s, %s, %s, %s)"""
6312 ####################################
6314 ####################################
6316 self
.query
['update_SC'] = """
6317 UPDATE SessionsCache SET
6322 self
.query
['update_GC'] = """
6323 UPDATE GamesCache SET
6328 totalProfit=totalProfit+%s,
6330 showdownWinnings=showdownWinnings+%s,
6331 nonShowdownWinnings=nonShowdownWinnings+%s,
6335 ####################################
6337 ####################################
6339 self
.query
['delete_SC'] = """
6340 DELETE FROM SessionsCache
6343 self
.query
['delete_GC'] = """
6344 DELETE FROM GamesCache
6347 ####################################
6348 # update GamesCache, Hands, Tourneys
6349 ####################################
6351 self
.query
['update_SC_GC'] = """
6352 UPDATE GamesCache SET
6354 WHERE sessionId=%s"""
6356 self
.query
['update_SC_T'] = """
6359 WHERE sessionId=%s"""
6361 self
.query
['update_SC_H'] = """
6364 WHERE sessionId=%s"""
6366 self
.query
['update_GC_H'] = """
6371 ####################################
6372 # update Tourneys w. sessionIds, hands, start/end
6373 ####################################
6375 self
.query
['updateTourneysSessions'] = """
6380 self
.query
['selectTourneysPlayersStartEnd'] = """
6381 SELECT startTime, endTime
6382 FROM TourneysPlayers
6385 self
.query
['updateTourneysPlayersStart'] = """
6386 UPDATE TourneysPlayers SET
6392 self
.query
['updateTourneysPlayersEnd'] = """
6393 UPDATE TourneysPlayers SET
6400 self
.query
['updateTourneysPlayersStartEnd'] = """
6401 UPDATE TourneysPlayers SET
6409 self
.query
['updateTourneysPlayers'] = """
6410 UPDATE TourneysPlayers SET
6416 ####################################
6417 # Database management queries
6418 ####################################
6420 if db_server
== 'mysql':
6421 self
.query
['analyze'] = """
6422 analyze table Actions, Autorates, Backings, Boards, Files, Gametypes, Hands, HandsActions, HandsPlayers,
6423 HandsStove, HudCache, Players, RawHands, RawTourneys, SessionsCache, Settings, Sites,
6424 Tourneys, TourneysPlayers, TourneyTypes
6426 elif db_server
== 'postgresql':
6427 self
.query
['analyze'] = "analyze"
6428 elif db_server
== 'sqlite':
6429 self
.query
['analyze'] = "analyze"
6432 if db_server
== 'mysql':
6433 self
.query
['vacuum'] = """
6434 optimize table Actions, Autorates, Backings, Boards, Files, Gametypes, Hands, HandsActions, HandsPlayers,
6435 HandsStove, HudCache, Players, RawHands, RawTourneys, SessionsCache, Settings, Sites,
6436 Tourneys, TourneysPlayers, TourneyTypes
6438 elif db_server
== 'postgresql':
6439 self
.query
['vacuum'] = """ vacuum """
6440 elif db_server
== 'sqlite':
6441 self
.query
['vacuum'] = """ vacuum """
6443 if db_server
== 'mysql':
6444 self
.query
['switchLockOn'] = """
6445 UPDATE InsertLock k1,
6446 (SELECT count(locked) as locks FROM InsertLock WHERE locked=True) as k2 SET
6451 if db_server
== 'mysql':
6452 self
.query
['switchLockOff'] = """
6453 UPDATE InsertLock SET
6457 if db_server
== 'mysql':
6458 self
.query
['lockForInsert'] = """
6459 lock tables Hands write, HandsPlayers write, HandsActions write, Players write
6460 , HudCache write, Gametypes write, Sites write, Tourneys write
6461 , TourneysPlayers write, TourneyTypes write, Autorates write
6463 elif db_server
== 'postgresql':
6464 self
.query
['lockForInsert'] = ""
6465 elif db_server
== 'sqlite':
6466 self
.query
['lockForInsert'] = ""
6468 self
.query
['getGametypeFL'] = """SELECT id
6478 """ #TODO: seems odd to have limitType variable in this query
6480 self
.query
['getGametypeNL'] = """SELECT id
6492 """ #TODO: seems odd to have limitType variable in this query
6494 self
.query
['insertGameTypes'] = """INSERT INTO Gametypes
6495 (siteId, currency, type, base, category, limitType
6496 ,hiLo, mix, smallBlind, bigBlind, smallBet, bigBet, maxSeats, ante)
6497 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
6499 self
.query
['isAlreadyInDB'] = """SELECT id FROM Hands
6500 WHERE gametypeId=%s AND siteHandNo=%s
6503 self
.query
['getTourneyTypeIdByTourneyNo'] = """SELECT tt.id,
6521 FROM TourneyTypes tt
6522 INNER JOIN Tourneys t ON (t.tourneyTypeId = tt.id)
6523 WHERE t.siteTourneyNo=%s AND tt.siteId=%s
6526 self
.query
['getTourneyTypeId'] = """SELECT id
6547 self
.query
['insertTourneyType'] = """INSERT INTO TourneyTypes
6548 (siteId, currency, buyin, fee, category, limitType, maxSeats, sng, knockout, koBounty,
6549 rebuy, rebuyCost, addOn, addOnCost, speed, shootout, matrix)
6550 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
6553 self
.query
['updateTourneyTypeId'] = """UPDATE Tourneys
6554 SET tourneyTypeId = %s
6555 WHERE siteTourneyNo=%s
6558 self
.query
['selectTourneyWithTypeId'] = """SELECT id
6560 WHERE tourneyTypeId = %s
6563 self
.query
['deleteTourneyTypeId'] = """DELETE FROM TourneyTypes WHERE id = %s
6566 self
.query
['updateTourneyTypeId'] = """UPDATE Tourneys
6567 SET tourneyTypeId = %s
6568 WHERE siteTourneyNo=%s
6571 self
.query
['fetchNewTourneyTypeIds'] = """SELECT TT.id
6572 FROM TourneyTypes TT
6573 LEFT OUTER JOIN `HudCache` HC ON (TT.id = HC.tourneyTypeId)
6574 WHERE HC.tourneyTypeId is NULL
6577 self
.query
['getTourneyByTourneyNo'] = """SELECT t.*
6579 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
6580 WHERE tt.siteId=%s AND t.siteTourneyNo=%s
6583 self
.query
['getTourneyInfo'] = """SELECT tt.*, t.*
6585 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
6586 INNER JOIN Sites s ON (tt.siteId = s.id)
6587 WHERE s.name=%s AND t.siteTourneyNo=%s
6590 self
.query
['getSiteTourneyNos'] = """SELECT t.siteTourneyNo
6592 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
6593 INNER JOIN Sites s ON (tt.siteId = s.id)
6597 self
.query
['getTourneyPlayerInfo'] = """SELECT tp.*
6599 INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
6600 INNER JOIN Sites s ON (tt.siteId = s.id)
6601 INNER JOIN TourneysPlayers tp ON (tp.tourneyId = t.id)
6602 INNER JOIN Players p ON (p.id = tp.playerId)
6603 WHERE s.name=%s AND t.siteTourneyNo=%s AND p.name=%s
6606 self
.query
['insertTourney'] = """INSERT INTO Tourneys
6607 (tourneyTypeId, sessionId, siteTourneyNo, entries, prizepool,
6608 startTime, endTime, tourneyName, matrixIdProcessed,
6609 totalRebuyCount, totalAddOnCount)
6610 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
6613 self
.query
['updateTourney'] = """UPDATE Tourneys
6619 matrixIdProcessed = %s,
6620 totalRebuyCount = %s,
6621 totalAddOnCount = %s,
6627 self
.query
['getTourneysPlayersByIds'] = """SELECT *
6628 FROM TourneysPlayers
6629 WHERE tourneyId=%s AND playerId+0=%s
6632 self
.query
['getTourneysPlayersByTourney'] = """SELECT playerId
6633 FROM TourneysPlayers
6637 self
.query
['updateTourneysPlayer'] = """UPDATE TourneysPlayers
6640 winningsCurrency = %s,
6647 self
.query
['insertTourneysPlayer'] = """insert into TourneysPlayers(
6661 values (%s, %s, %s, %s, %s, %s,
6662 %s, %s, %s, %s, %s, %s)
6665 self
.query
['selectHandsPlayersWithWrongTTypeId'] = """SELECT id
6667 WHERE tourneyTypeId <> %s AND (TourneysPlayersId+0=%s)
6670 # self.query['updateHandsPlayersForTTypeId2'] = """UPDATE HandsPlayers
6671 # SET tourneyTypeId= %s
6672 # WHERE (TourneysPlayersId+0=%s)
6675 self
.query
['updateHandsPlayersForTTypeId'] = """UPDATE HandsPlayers
6676 SET tourneyTypeId= %s
6681 self
.query
['handsPlayersTTypeId_joiner'] = " OR TourneysPlayersId+0="
6682 self
.query
['handsPlayersTTypeId_joiner_id'] = " OR id="
6684 self
.query
['store_hand'] = """insert into Hands (
6720 (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
6721 %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
6722 %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
6725 self
.query
['store_hands_players'] = """insert into HandsPlayers (
6793 street0CalledRaiseChance,
6794 street0CalledRaiseDone,
6801 street0_FoldTo3BChance,
6802 street0_FoldTo3BDone,
6803 street0_FoldTo4BChance,
6804 street0_FoldTo4BDone,
6805 street0_SqueezeChance,
6806 street0_SqueezeDone,
6815 foldToOtherRaisedStreet0,
6816 foldToOtherRaisedStreet1,
6817 foldToOtherRaisedStreet2,
6818 foldToOtherRaisedStreet3,
6819 foldToOtherRaisedStreet4,
6822 foldBbToStealChance,
6824 foldSbToStealChance,
6826 foldToStreet1CBChance,
6827 foldToStreet1CBDone,
6828 foldToStreet2CBChance,
6829 foldToStreet2CBDone,
6830 foldToStreet3CBChance,
6831 foldToStreet3CBDone,
6832 foldToStreet4CBChance,
6833 foldToStreet4CBDone,
6834 street1CheckCallRaiseChance,
6835 street1CheckCallRaiseDone,
6836 street2CheckCallRaiseChance,
6837 street2CheckCallRaiseDone,
6838 street3CheckCallRaiseChance,
6839 street3CheckCallRaiseDone,
6840 street4CheckCallRaiseChance,
6841 street4CheckCallRaiseDone,
6876 self
.query
['store_hands_actions'] = """insert into HandsActions (
6896 self
.query
['store_hands_stove'] = """insert into HandsStove (
6910 self
.query
['store_boards'] = """insert into Boards (
6924 ################################
6925 # queries for Files Table
6926 ################################
6928 self
.query
['store_file'] = """ insert into Files (
6946 self
.query
['update_file'] = """
6956 ttime100=ttime100+%s,
6960 ################################
6961 # Counts for DB stats window
6962 ################################
6963 self
.query
['getHandCount'] = "SELECT COUNT(*) FROM Hands"
6964 self
.query
['getTourneyCount'] = "SELECT COUNT(*) FROM Tourneys"
6965 self
.query
['getTourneyTypeCount'] = "SELECT COUNT(*) FROM TourneyTypes"
6967 ################################
6968 # queries for dumpDatabase
6969 ################################
6970 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'):
6971 self
.query
['get'+table
] = u
"SELECT * FROM "+table
6973 ################################
6974 # placeholders and substitution stuff
6975 ################################
6976 if db_server
== 'mysql':
6977 self
.query
['placeholder'] = u
'%s'
6978 elif db_server
== 'postgresql':
6979 self
.query
['placeholder'] = u
'%s'
6980 elif db_server
== 'sqlite':
6981 self
.query
['placeholder'] = u
'?'
6984 # If using sqlite, use the ? placeholder instead of %s
6985 if db_server
== 'sqlite':
6986 for k
,q
in self
.query
.iteritems():
6987 self
.query
[k
] = re
.sub('%s','?',q
)
6989 if __name__
== "__main__":
6990 # just print the default queries and exit
6993 print "For query " + key
+ ", sql ="