playerstats changes: modify columns shown, use left join in case

playeractions data is missing, correct postgres syntax but now
giving divide by zero error
This commit is contained in:
sqlcoder 2008-12-13 14:15:03 +00:00
parent e9fa9e4324
commit 6e72d602e9
2 changed files with 28 additions and 19 deletions

View File

@ -664,11 +664,15 @@ class FpdbSQLQueries:
if(self.dbname == 'MySQL InnoDB'): if(self.dbname == 'MySQL InnoDB'):
self.query['playerStats'] = """ self.query['playerStats'] = """
SELECT stats.gametypeId SELECT
,stats.base concat(upper(stats.limitType), ' '
,stats.limitType ,concat(upper(substring(stats.category,1,1)),substring(stats.category,2) ), ' '
,stats.name ,stats.name, ' $'
,format(stats.bigBlind/100,2) as BigBlind ,cast(trim(leading ' ' from
case when stats.bigBlind < 100 then format(stats.bigBlind/100.0,2)
else format(stats.bigBlind/100.0,0)
end ) as char)
) AS Game
,stats.n ,stats.n
,stats.vpip ,stats.vpip
,stats.pfr ,stats.pfr
@ -687,6 +691,7 @@ class FpdbSQLQueries:
FROM FROM
(select # stats from hudcache (select # stats from hudcache
gt.base gt.base
,gt.category
,upper(gt.limitType) limitType ,upper(gt.limitType) limitType
,s.name ,s.name
,gt.bigBlind ,gt.bigBlind
@ -719,8 +724,8 @@ class FpdbSQLQueries:
(select hp.handId, h.gameTypeId, hp.winnings, SUM(ha.amount) (select hp.handId, h.gameTypeId, hp.winnings, SUM(ha.amount)
costs, hp.winnings - SUM(ha.amount) profit costs, hp.winnings - SUM(ha.amount) profit
from HandsPlayers hp from HandsPlayers hp
inner join Hands h ON h.id = hp.handId inner join Hands h ON h.id = hp.handId
inner join HandsActions ha ON ha.handPlayerId = hp.id left join HandsActions ha ON ha.handPlayerId = hp.id
where hp.playerId in <player_test> where hp.playerId in <player_test>
# use <gametype_test> here ? # use <gametype_test> here ?
and hp.tourneysPlayersId IS NULL and hp.tourneysPlayersId IS NULL
@ -732,11 +737,13 @@ class FpdbSQLQueries:
order by stats.base, stats.limittype, stats.bigBlind""" order by stats.base, stats.limittype, stats.bigBlind"""
elif(self.dbname == 'PostgreSQL'): elif(self.dbname == 'PostgreSQL'):
self.query['playerStats'] = """ self.query['playerStats'] = """
SELECT stats.gametypeId SELECT upper(stats.limitType) || ' '
,stats.base || initcap(stats.category) || ' '
,stats.limitType || stats.name || ' $'
,stats.name || trim(leading ' ' from
,(stats.bigBlind/100) as BigBlind case when stats.bigBlind < 100 then to_char(stats.bigBlind/100.0,'0D00')
else to_char(stats.bigBlind/100.0,'99990')
end ) AS Game
,stats.n ,stats.n
,stats.vpip ,stats.vpip
,stats.pfr ,stats.pfr
@ -754,6 +761,7 @@ class FpdbSQLQueries:
,hprof2.variance as Variance ,hprof2.variance as Variance
FROM FROM
(select gt.base (select gt.base
,gt.category
,upper(gt.limitType) as limitType ,upper(gt.limitType) as limitType
,s.name ,s.name
,gt.bigBlind ,gt.bigBlind
@ -775,6 +783,7 @@ class FpdbSQLQueries:
inner join HudCache hc on hc.gameTypeId = gt.Id inner join HudCache hc on hc.gameTypeId = gt.Id
where hc.playerId in <player_test> where hc.playerId in <player_test>
group by gt.base group by gt.base
,gt.category
,upper(gt.limitType) ,upper(gt.limitType)
,s.name ,s.name
,gt.bigBlind ,gt.bigBlind
@ -782,9 +791,9 @@ class FpdbSQLQueries:
) stats ) stats
inner join inner join
( select ( select
hprof.gameTypeId, sum(hprof.profit) sum_profit, hprof.gameTypeId, sum(hprof.profit) AS sum_profit,
avg(hprof.profit/100.0) profitperhand, avg(hprof.profit/100.0) AS profitperhand,
variance(hprof.profit/100.0) variance variance(hprof.profit/100.0) AS variance
from from
(select hp.handId, (select hp.handId,
h.gameTypeId, h.gameTypeId,
@ -792,8 +801,8 @@ class FpdbSQLQueries:
SUM(ha.amount) as costs, SUM(ha.amount) as costs,
hp.winnings - SUM(ha.amount) as profit hp.winnings - SUM(ha.amount) as profit
from HandsPlayers hp from HandsPlayers hp
inner join Hands h ON h.id = hp.handId inner join Hands h ON h.id = hp.handId
inner join HandsActions ha ON ha.handPlayerId = hp.id left join HandsActions ha ON ha.handPlayerId = hp.id
where hp.playerId in <player_test> where hp.playerId in <player_test>
and hp.tourneysPlayersId IS NULL and hp.tourneysPlayersId IS NULL
group by hp.handId, h.gameTypeId, hp.position, hp.winnings group by hp.handId, h.gameTypeId, hp.position, hp.winnings

View File

@ -52,7 +52,7 @@ class GuiPlayerStats (threading.Thread):
tmp = tmp.replace("<player_test>", "(" + str(pid) + ")") tmp = tmp.replace("<player_test>", "(" + str(pid) + ")")
self.cursor.execute(tmp) self.cursor.execute(tmp)
result = self.db.cursor.fetchall() result = self.db.cursor.fetchall()
cols = 20 cols = 16
rows = len(result)+1 # +1 for title row rows = len(result)+1 # +1 for title row
self.stats_table = gtk.Table(rows, cols, False) self.stats_table = gtk.Table(rows, cols, False)
self.stats_table.set_col_spacings(4) self.stats_table.set_col_spacings(4)
@ -60,7 +60,7 @@ class GuiPlayerStats (threading.Thread):
vbox.add(self.stats_table) vbox.add(self.stats_table)
# Create header row # Create header row
titles = ("GID", "base", "Style", "Site", "$BB", "Hands", "VPIP", "PFR", "saw_f", "sawsd", "wtsdwsf", "wmsd", "FlAFq", "TuAFq", "RvAFq", "PFAFq", "Net($)", "BB/100", "$/hand", "Variance") titles = ("Game", "Hands", "VPIP", "PFR", "saw_f", "sawsd", "wtsdwsf", "wmsd", "FlAFq", "TuAFq", "RvAFq", "PFAFq", "Net($)", "BB/100", "$/hand", "Variance")
col = 0 col = 0
row = 0 row = 0