move code closer to carl's repo
This commit is contained in:
parent
160db08689
commit
ec01f7ae40
|
@ -30,13 +30,6 @@ class FpdbSQLQueries:
|
|||
self.query = {}
|
||||
self.dbname = db
|
||||
|
||||
#Boilerplate code.
|
||||
# if(self.dbname == 'MySQL InnoDB'):
|
||||
# self.query[''] = """ """
|
||||
# elif(self.dbname == 'PostgreSQL'):
|
||||
# elif(self.dbname == 'SQLite'):
|
||||
|
||||
|
||||
################################
|
||||
# List tables
|
||||
################################
|
||||
|
@ -80,13 +73,13 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createSitesTable'] = """CREATE TABLE Sites (
|
||||
id SMALLINT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
name varchar(32) NOT NULL,
|
||||
currency char(3) NOT NULL)
|
||||
ENGINE=INNODB"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['createSitesTable'] = """CREATE TABLE Sites (
|
||||
id SERIAL UNIQUE, PRIMARY KEY (id),
|
||||
id SERIAL, PRIMARY KEY (id),
|
||||
name varchar(32),
|
||||
currency char(3))"""
|
||||
elif(self.dbname == 'SQLite'):
|
||||
|
@ -99,7 +92,7 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createGametypesTable'] = """CREATE TABLE Gametypes (
|
||||
id SMALLINT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||
type char(4) NOT NULL,
|
||||
base char(4) NOT NULL,
|
||||
|
@ -113,7 +106,7 @@ class FpdbSQLQueries:
|
|||
ENGINE=INNODB"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['createGametypesTable'] = """CREATE TABLE Gametypes (
|
||||
id SERIAL UNIQUE, PRIMARY KEY (id),
|
||||
id SERIAL, PRIMARY KEY (id),
|
||||
siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||
type char(4),
|
||||
base char(4),
|
||||
|
@ -134,7 +127,7 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createPlayersTable'] = """CREATE TABLE Players (
|
||||
id INT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
name VARCHAR(32) CHARACTER SET utf8 NOT NULL,
|
||||
siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||
comment text,
|
||||
|
@ -142,7 +135,7 @@ class FpdbSQLQueries:
|
|||
ENGINE=INNODB"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['createPlayersTable'] = """CREATE TABLE Players (
|
||||
id SERIAL UNIQUE, PRIMARY KEY (id),
|
||||
id SERIAL, PRIMARY KEY (id),
|
||||
name VARCHAR(32),
|
||||
siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||
comment text,
|
||||
|
@ -157,7 +150,7 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createAutoratesTable'] = """CREATE TABLE Autorates (
|
||||
id BIGINT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||
description varchar(50) NOT NULL,
|
||||
|
@ -167,7 +160,7 @@ class FpdbSQLQueries:
|
|||
ENGINE=INNODB"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['createAutoratesTable'] = """CREATE TABLE Autorates (
|
||||
id BIGSERIAL UNIQUE, PRIMARY KEY (id),
|
||||
id BIGSERIAL, PRIMARY KEY (id),
|
||||
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||
description varchar(50),
|
||||
|
@ -184,7 +177,7 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createHandsTable'] = """CREATE TABLE Hands (
|
||||
id BIGINT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
tableName VARCHAR(20) NOT NULL,
|
||||
siteHandNo BIGINT NOT NULL,
|
||||
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||
|
@ -197,7 +190,7 @@ class FpdbSQLQueries:
|
|||
ENGINE=INNODB"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['createHandsTable'] = """CREATE TABLE Hands (
|
||||
id BIGSERIAL UNIQUE, PRIMARY KEY (id),
|
||||
id BIGSERIAL, PRIMARY KEY (id),
|
||||
tableName VARCHAR(20),
|
||||
siteHandNo BIGINT,
|
||||
gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||
|
@ -217,7 +210,7 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createBoardCardsTable'] = """CREATE TABLE BoardCards (
|
||||
id BIGINT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
|
||||
card1Value smallint NOT NULL,
|
||||
card1Suit char(1) NOT NULL,
|
||||
|
@ -232,7 +225,7 @@ class FpdbSQLQueries:
|
|||
ENGINE=INNODB"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['createBoardCardsTable'] = """CREATE TABLE BoardCards (
|
||||
id BIGSERIAL UNIQUE, PRIMARY KEY (id),
|
||||
id BIGSERIAL, PRIMARY KEY (id),
|
||||
handId BIGINT, FOREIGN KEY (handId) REFERENCES Hands(id),
|
||||
card1Value smallint,
|
||||
card1Suit char(1),
|
||||
|
@ -254,7 +247,7 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
|
||||
id SMALLINT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||
buyin INT NOT NULL,
|
||||
fee INT NOT NULL,
|
||||
|
@ -279,7 +272,7 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
|
||||
id INT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
siteTourneyNo BIGINT NOT NULL,
|
||||
entries INT NOT NULL,
|
||||
|
@ -290,7 +283,7 @@ class FpdbSQLQueries:
|
|||
ENGINE=INNODB"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
|
||||
id SERIAL UNIQUE, PRIMARY KEY (id),
|
||||
id SERIAL, PRIMARY KEY (id),
|
||||
tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
siteTourneyNo BIGINT,
|
||||
entries INT,
|
||||
|
@ -307,7 +300,7 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
|
||||
id BIGINT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
|
||||
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
startCash INT NOT NULL,
|
||||
|
@ -339,7 +332,7 @@ class FpdbSQLQueries:
|
|||
ENGINE=INNODB"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
|
||||
id BIGSERIAL UNIQUE, PRIMARY KEY (id),
|
||||
id BIGSERIAL, PRIMARY KEY (id),
|
||||
handId BIGINT, FOREIGN KEY (handId) REFERENCES Hands(id),
|
||||
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
startCash INT,
|
||||
|
@ -377,7 +370,7 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
|
||||
id BIGINT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
tourneyId INT UNSIGNED NOT NULL, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
|
||||
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
payinAmount INT NOT NULL,
|
||||
|
@ -388,7 +381,7 @@ class FpdbSQLQueries:
|
|||
ENGINE=INNODB"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
|
||||
id BIGSERIAL UNIQUE, PRIMARY KEY (id),
|
||||
id BIGSERIAL, PRIMARY KEY (id),
|
||||
tourneyId INT, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
|
||||
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
payinAmount INT,
|
||||
|
@ -406,7 +399,7 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
|
||||
id BIGINT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
handPlayerId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handPlayerId) REFERENCES HandsPlayers(id),
|
||||
street SMALLINT NOT NULL,
|
||||
actionNo SMALLINT NOT NULL,
|
||||
|
@ -418,7 +411,7 @@ class FpdbSQLQueries:
|
|||
ENGINE=INNODB"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
|
||||
id BIGSERIAL UNIQUE, PRIMARY KEY (id),
|
||||
id BIGSERIAL, PRIMARY KEY (id),
|
||||
handPlayerId BIGINT, FOREIGN KEY (handPlayerId) REFERENCES HandsPlayers(id),
|
||||
street SMALLINT,
|
||||
actionNo SMALLINT,
|
||||
|
@ -437,7 +430,7 @@ class FpdbSQLQueries:
|
|||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['createHudCacheTable'] = """CREATE TABLE HudCache (
|
||||
id BIGINT UNSIGNED UNIQUE AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
activeSeats SMALLINT NOT NULL,
|
||||
|
@ -510,7 +503,7 @@ class FpdbSQLQueries:
|
|||
ENGINE=INNODB"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['createHudCacheTable'] = """CREATE TABLE HudCache (
|
||||
id BIGSERIAL UNIQUE, PRIMARY KEY (id),
|
||||
id BIGSERIAL, PRIMARY KEY (id),
|
||||
gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
activeSeats SMALLINT,
|
||||
|
@ -580,6 +573,30 @@ class FpdbSQLQueries:
|
|||
elif(self.dbname == 'SQLite'):
|
||||
self.query['createHudCacheTable'] = """ """
|
||||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['addTourneyIndex'] = """ALTER TABLE Tourneys ADD INDEX siteTourneyNo(siteTourneyNo)"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
# FIXME: This query has a different syntax
|
||||
self.query['addTourneyIndex'] = """ALTER TABLE Tourneys ADD INDEX siteTourneyNo(siteTourneyNo)"""
|
||||
elif(self.dbname == 'SQLite'):
|
||||
self.query['addHandsIndex'] = """ """
|
||||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['addHandsIndex'] = """ALTER TABLE Hands ADD INDEX siteHandNo(siteHandNo)"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
# FIXME: This query has a different syntax
|
||||
self.query['addHandsIndex'] = """ALTER TABLE Hands ADD INDEX siteHandNo(siteHandNo)"""
|
||||
elif(self.dbname == 'SQLite'):
|
||||
self.query['addHandsIndex'] = """ """
|
||||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['addPlayersIndex'] = """ALTER TABLE Players ADD INDEX name(name)"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
# FIXME: This query has a different syntax
|
||||
self.query['addHandsIndex'] = """ALTER TABLE Hands ADD INDEX siteHandNo(siteHandNo)"""
|
||||
elif(self.dbname == 'SQLite'):
|
||||
self.query['addHandsIndex'] = """ """
|
||||
|
||||
################################
|
||||
# Queries used in GuiGraphViewer
|
||||
################################
|
||||
|
@ -601,10 +618,24 @@ class FpdbSQLQueries:
|
|||
WHERE Players.name = %s AND Players.siteId = %s AND (tourneysPlayersId IS NULL)
|
||||
ORDER BY handStart"""
|
||||
|
||||
# Returns the profit for all hands, Total pot - money invested by playerId
|
||||
# Returns the profit for a given ring game handId, Total pot - money invested by playerId
|
||||
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
|
||||
self.query['getRingProfitFromHandId'] = """SELECT SUM(amount) FROM HandsActions
|
||||
INNER JOIN HandsPlayers ON HandsActions.handPlayerId = HandsPlayers.id
|
||||
INNER JOIN Players ON HandsPlayers.playerId = Players.id
|
||||
WHERE Players.name = %s AND HandsPlayers.handId = %s
|
||||
AND Players.siteId = %s AND (tourneysPlayersId IS NULL)"""
|
||||
elif(self.dbname == 'SQLite'):
|
||||
#Probably doesn't work.
|
||||
self.query['getRingProfitFromHandId'] = """SELECT SUM(amount) FROM HandsActions
|
||||
INNER JOIN HandsPlayers ON HandsActions.handPlayerId = HandsPlayers.id
|
||||
INNER JOIN Players ON HandsPlayers.playerId = Players.id
|
||||
WHERE Players.name = %s AND HandsPlayers.handId = %s
|
||||
AND Players.siteId = %s AND (tourneysPlayersId IS NULL)"""
|
||||
|
||||
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
|
||||
self.query['getRingProfitAllHandsPlayerIdSite'] = """
|
||||
SELECT hp.handId, hp.winnings, SUM(ha.amount) costs, hp.winnings - SUM(ha.amount) profit
|
||||
SELECT hp.handId, hp.winnings, SUM(ha.amount), hp.winnings - SUM(ha.amount)
|
||||
FROM HandsPlayers hp
|
||||
INNER JOIN Players pl ON hp.playerId = pl.id
|
||||
INNER JOIN Hands h ON h.id = hp.handId
|
||||
|
@ -612,12 +643,12 @@ class FpdbSQLQueries:
|
|||
WHERE pl.name = %s
|
||||
AND pl.siteId = %s
|
||||
AND hp.tourneysPlayersId IS NULL
|
||||
group by hp.handId, hp.winnings, h.handStart
|
||||
GROUP BY hp.handId, hp.winnings, h.handStart
|
||||
ORDER BY h.handStart"""
|
||||
elif(self.dbname == 'SQLite'):
|
||||
#May not work.
|
||||
#Probably doesn't work.
|
||||
self.query['getRingProfitAllHandsPlayerIdSite'] = """
|
||||
SELECT hp.handId, hp.winnings, SUM(ha.amount) costs, hp.winnings - SUM(ha.amount) profit
|
||||
SELECT hp.handId, hp.winnings, SUM(ha.amount), hp.winnings - SUM(ha.amount)
|
||||
FROM HandsPlayers hp
|
||||
INNER JOIN Players pl ON hp.playerId = pl.id
|
||||
INNER JOIN Hands h ON h.id = hp.handId
|
||||
|
@ -625,7 +656,7 @@ class FpdbSQLQueries:
|
|||
WHERE pl.name = %s
|
||||
AND pl.siteId = %s
|
||||
AND hp.tourneysPlayersId IS NULL
|
||||
group by hp.handId, hp.winnings, h.handStart
|
||||
GROUP BY hp.handId, hp.winnings, h.handStart
|
||||
ORDER BY h.handStart"""
|
||||
|
||||
# Returns the profit for a given ring game handId, Total pot - money invested by playerId - WRONG, returns players costs
|
||||
|
@ -643,6 +674,188 @@ class FpdbSQLQueries:
|
|||
WHERE Players.name = %s AND HandsPlayers.handId = %s
|
||||
AND Players.siteId = %s AND (tourneysPlayersId IS NULL)"""
|
||||
|
||||
# Returns a list of the tables in the database
|
||||
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL'):
|
||||
self.query['getTableList'] = """
|
||||
SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_type = 'BASE TABLE'
|
||||
AND table_schema = %s
|
||||
"""
|
||||
elif(self.dbname == 'getTableList'):
|
||||
#Probably doesn't work.
|
||||
self.query['getTableList'] = """
|
||||
SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_type = 'BASE TABLE'
|
||||
AND table_schema = %s
|
||||
"""
|
||||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['playerStats'] = """
|
||||
SELECT stats.gametypeId
|
||||
,stats.base
|
||||
,stats.limitType
|
||||
,stats.name
|
||||
,format(stats.bigBlind/100,2) as BigBlind
|
||||
,stats.n
|
||||
,stats.vpip
|
||||
,stats.pfr
|
||||
,stats.saw_f
|
||||
,stats.sawsd
|
||||
,stats.wtsdwsf
|
||||
,stats.wmsd
|
||||
,stats.FlAFq
|
||||
,stats.TuAFq
|
||||
,stats.RvAFq
|
||||
,stats.PFAFq
|
||||
,hprof2.sum_profit/100 as Net
|
||||
,(hprof2.sum_profit/stats.bigBlind)/(stats.n/100) as BBlPer100
|
||||
FROM
|
||||
(select # stats from hudcache
|
||||
gt.base
|
||||
,upper(gt.limitType) limitType
|
||||
,s.name
|
||||
,gt.bigBlind
|
||||
,hc.gametypeId
|
||||
,sum(HDs) as n
|
||||
,round(100*sum(street0VPI)/sum(HDs)) as vpip
|
||||
,round(100*sum(street0Aggr)/sum(HDs)) as pfr
|
||||
,round(100*sum(street1Seen)/sum(HDs)) AS saw_f
|
||||
,round(100*sum(sawShowdown)/sum(HDs)) AS sawsd
|
||||
,round(100*sum(sawShowdown)/sum(street1Seen)) AS wtsdwsf
|
||||
,round(100*sum(wonAtSD)/sum(sawShowdown)) AS wmsd
|
||||
,round(100*sum(street1Aggr)/sum(street1Seen)) AS FlAFq
|
||||
,round(100*sum(street2Aggr)/sum(street2Seen)) AS TuAFq
|
||||
,round(100*sum(street3Aggr)/sum(street3Seen)) AS RvAFq
|
||||
,round(100*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
|
||||
/(sum(street1Seen)+sum(street2Seen)+sum(street3Seen))) AS PFAFq
|
||||
from Gametypes gt
|
||||
inner join Sites s on s.Id = gt.siteId
|
||||
inner join HudCache hc on hc.gameTypeId = gt.Id
|
||||
where gt.limittype = 'nl'
|
||||
and hc.playerId in (3) # use <player_test> here?
|
||||
# use <gametype_test> here ?
|
||||
group by hc.gametypeId
|
||||
) stats
|
||||
inner join
|
||||
( select # profit from handsplayers/handsactions
|
||||
hprof.gameTypeId, sum(hprof.profit) sum_profit
|
||||
from
|
||||
(select hp.handId, h.gameTypeId, hp.winnings, SUM(ha.amount)
|
||||
costs, hp.winnings - SUM(ha.amount) profit
|
||||
from HandsPlayers hp
|
||||
inner join Hands h ON h.id = hp.handId
|
||||
inner join HandsActions ha ON ha.handPlayerId = hp.id
|
||||
where hp.playerId in (3) # use <player_test> here?
|
||||
# use <gametype_test> here ?
|
||||
and hp.tourneysPlayersId IS NULL
|
||||
group by hp.handId, h.gameTypeId, hp.position, hp.winnings
|
||||
) hprof
|
||||
group by hprof.gameTypeId
|
||||
) hprof2
|
||||
on hprof2.gameTypeId = stats.gameTypeId
|
||||
order by stats.base, stats.limittype, stats.bigBlind"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['playerStats'] = """ """
|
||||
elif(self.dbname == 'SQLite'):
|
||||
self.query['playerStats'] = """ """
|
||||
|
||||
if(self.dbname == 'MySQL InnoDB'):
|
||||
self.query['playerStatsByPosition'] = """
|
||||
SELECT stats.gametypeId
|
||||
,stats.base
|
||||
,stats.limitType
|
||||
,stats.name
|
||||
,format(stats.bigBlind/100,2) as BigBlind
|
||||
,p.name
|
||||
,stats.pl_position
|
||||
,stats.n
|
||||
,stats.vpip
|
||||
,stats.pfr
|
||||
,stats.saw_f
|
||||
,stats.sawsd
|
||||
,stats.wtsdwsf
|
||||
,stats.wmsd
|
||||
,stats.FlAFq
|
||||
,stats.TuAFq
|
||||
,stats.RvAFq
|
||||
,stats.PFAFq
|
||||
,hprof2.sum_profit/100 as Net
|
||||
,(hprof2.sum_profit/stats.bigBlind)/(stats.n/100) as BBlPer100
|
||||
# ... any other stats you want to add
|
||||
FROM
|
||||
(select # stats from hudcache
|
||||
hc.playerId
|
||||
,gt.base
|
||||
,upper(gt.limitType) as limitType
|
||||
,s.name
|
||||
,gt.bigBlind
|
||||
,hc.gametypeId
|
||||
,case when hc.position = 'B' then -2
|
||||
when hc.position = 'S' then -1
|
||||
when hc.position = 'D' then 0
|
||||
when hc.position = 'C' then 1
|
||||
when hc.position = 'M' then 2
|
||||
when hc.position = 'E' then 5
|
||||
else 9
|
||||
end as pl_position
|
||||
,sum(HDs) as n
|
||||
,round(100*sum(street0VPI)/sum(HDs)) as vpip
|
||||
,round(100*sum(street0Aggr)/sum(HDs)) as pfr
|
||||
,round(100*sum(street1Seen)/sum(HDs)) AS saw_f
|
||||
,round(100*sum(sawShowdown)/sum(HDs)) AS sawsd
|
||||
,round(100*sum(sawShowdown)/sum(street1Seen)) AS wtsdwsf
|
||||
,round(100*sum(wonAtSD)/sum(sawShowdown)) AS wmsd
|
||||
,round(100*sum(street1Aggr)/sum(street1Seen)) AS FlAFq
|
||||
,round(100*sum(street2Aggr)/sum(street2Seen)) AS TuAFq
|
||||
,round(100*sum(street3Aggr)/sum(street3Seen)) AS RvAFq
|
||||
,round(100*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr))
|
||||
/(sum(street1Seen)+sum(street2Seen)+sum(street3Seen))) AS PFAFq
|
||||
from Gametypes gt
|
||||
inner join Sites s on (s.Id = gt.siteId)
|
||||
inner join HudCache hc on (hc.gameTypeId = gt.Id)
|
||||
where gt.limittype = 'nl'
|
||||
and hc.playerId in (3) # always specify player for position stats
|
||||
# use <gametype_test> here
|
||||
# use <activeseats_test> here
|
||||
group by hc.playerId, hc.gametypeId, pl_position
|
||||
) stats
|
||||
inner join
|
||||
( select # profit from handsplayers/handsactions
|
||||
hprof.playerId
|
||||
, hprof.gameTypeId
|
||||
, case when hprof.position = 'B' then -2
|
||||
when hprof.position = 'S' then -1
|
||||
when hprof.position in ('3','4') then 2
|
||||
when hprof.position in ('6','7') then 5
|
||||
else hprof.position
|
||||
end as pl_position
|
||||
, sum(hprof.profit) as sum_profit
|
||||
from
|
||||
(select hp.playerId, hp.handId, h.gameTypeId, hp.position, hp.winnings
|
||||
, SUM(ha.amount) costs, hp.winnings - SUM(ha.amount) profit
|
||||
from HandsPlayers hp
|
||||
inner join Hands h ON (h.id = hp.handId)
|
||||
inner join HandsActions ha ON (ha.handPlayerId = hp.id)
|
||||
where hp.playerId in (3) # always specify player for position stats
|
||||
# use <gametype_test> here
|
||||
# use <activeseats_test> here
|
||||
and hp.tourneysPlayersId IS NULL
|
||||
group by hp.playerId, hp.handId, h.gameTypeId, hp.position, hp.winnings
|
||||
) hprof
|
||||
group by hprof.playerId, hprof.gameTypeId, pl_position
|
||||
) hprof2
|
||||
on ( hprof2.gameTypeId = stats.gameTypeId
|
||||
and hprof2.pl_position = stats.pl_position)
|
||||
inner join Players p on (p.id = stats.playerId)
|
||||
where 1 = 1
|
||||
order by stats.base, stats.limittype, stats.bigBlind, stats.pl_position, BBlPer100 desc
|
||||
"""
|
||||
elif(self.dbname == 'PostgreSQL'):
|
||||
self.query['playerStatsByPosition'] = """ """
|
||||
elif(self.dbname == 'SQLite'):
|
||||
self.query['playerStatsByPosition'] = """ """
|
||||
|
||||
if __name__== "__main__":
|
||||
from optparse import OptionParser
|
||||
|
|
|
@ -47,6 +47,8 @@ class fpdb_db:
|
|||
else:
|
||||
raise fpdb_simple.FpdbError("unrecognised database backend:"+backend)
|
||||
self.cursor=self.db.cursor()
|
||||
self.cursor.execute('SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED')
|
||||
|
||||
# Set up query dictionary as early in the connection process as we can.
|
||||
self.sql = FpdbSQLQueries.FpdbSQLQueries(self.get_backend_name())
|
||||
self.wrongDbVersion=False
|
||||
|
@ -92,6 +94,9 @@ class fpdb_db:
|
|||
self.cursor.execute(self.sql.query['createHandsPlayersTable'])
|
||||
self.cursor.execute(self.sql.query['createHandsActionsTable'])
|
||||
self.cursor.execute(self.sql.query['createHudCacheTable'])
|
||||
self.cursor.execute(self.sql.query['addTourneyIndex'])
|
||||
self.cursor.execute(self.sql.query['addHandsIndex'])
|
||||
self.cursor.execute(self.sql.query['addPlayersIndex'])
|
||||
self.fillDefaultData()
|
||||
self.db.commit()
|
||||
#end def disconnect
|
||||
|
|
Loading…
Reference in New Issue
Block a user