reverted HudCache styleKey to include only YYMMDD - however, it now stores the d000000 date based off the tz & offset

This commit is contained in:
Chaz 2010-11-30 14:05:28 -05:00
parent c6802484cb
commit e0f76a508c
2 changed files with 33 additions and 26 deletions

View File

@ -73,7 +73,7 @@ except ImportError:
use_numpy = False use_numpy = False
DB_VERSION = 145 DB_VERSION = 144
# Variance created as sqlite has a bunch of undefined aggregate functions. # Variance created as sqlite has a bunch of undefined aggregate functions.
@ -296,8 +296,8 @@ class Database:
# vars for hand ids or dates fetched according to above config: # vars for hand ids or dates fetched according to above config:
self.hand_1day_ago = 0 # max hand id more than 24 hrs earlier than now self.hand_1day_ago = 0 # max hand id more than 24 hrs earlier than now
self.date_ndays_ago = 'd00000000' # date N days ago ('d' + YYMMDD) self.date_ndays_ago = 'd000000' # date N days ago ('d' + YYMMDD)
self.h_date_ndays_ago = 'd00000000' # date N days ago ('d' + YYMMDD) for hero self.h_date_ndays_ago = 'd000000' # date N days ago ('d' + YYMMDD) for hero
self.date_nhands_ago = {} # dates N hands ago per player - not used yet self.date_nhands_ago = {} # dates N hands ago per player - not used yet
self.saveActions = False if self.import_options['saveActions'] == False else True self.saveActions = False if self.import_options['saveActions'] == False else True
@ -701,18 +701,18 @@ class Database:
d = timedelta(days=hud_days, hours=tz_day_start_offset) d = timedelta(days=hud_days, hours=tz_day_start_offset)
now = datetime.utcnow() - d now = datetime.utcnow() - d
self.date_ndays_ago = "d%02d%02d%02d%02d" % (now.year - 2000, now.month, now.day, tz_day_start_offset) self.date_ndays_ago = "d%02d%02d%02d" % (now.year - 2000, now.month, now.day)
d = timedelta(days=h_hud_days, hours=tz_day_start_offset) d = timedelta(days=h_hud_days, hours=tz_day_start_offset)
now = datetime.utcnow() - d now = datetime.utcnow() - d
self.h_date_ndays_ago = "d%02d%02d%02d%02d" % (now.year - 2000, now.month, now.day, tz_day_start_offset) self.h_date_ndays_ago = "d%02d%02d%02d" % (now.year - 2000, now.month, now.day)
def init_player_hud_stat_vars(self, playerid): def init_player_hud_stat_vars(self, playerid):
# not sure if this is workable, to be continued ... # not sure if this is workable, to be continued ...
try: try:
# self.date_nhands_ago is used for fetching stats for last n hands (hud_style = 'H') # self.date_nhands_ago is used for fetching stats for last n hands (hud_style = 'H')
# This option not used yet - needs to be called for each player :-( # This option not used yet - needs to be called for each player :-(
self.date_nhands_ago[str(playerid)] = 'd00000000' self.date_nhands_ago[str(playerid)] = 'd000000'
# should use aggregated version of query if appropriate # should use aggregated version of query if appropriate
c.execute(self.sql.query['get_date_nhands_ago'], (self.hud_hands, playerid)) c.execute(self.sql.query['get_date_nhands_ago'], (self.hud_hands, playerid))
@ -780,11 +780,11 @@ class Database:
if hud_style == 'T': if hud_style == 'T':
stylekey = self.date_ndays_ago stylekey = self.date_ndays_ago
elif hud_style == 'A': elif hud_style == 'A':
stylekey = '000000000' # all stylekey values should be higher than this stylekey = '0000000' # all stylekey values should be higher than this
elif hud_style == 'S': elif hud_style == 'S':
stylekey = 'zzzzzzzzz' # all stylekey values should be lower than this stylekey = 'zzzzzzz' # all stylekey values should be lower than this
else: else:
stylekey = '000000000' stylekey = '0000000'
log.info('hud_style: %s' % hud_style) log.info('hud_style: %s' % hud_style)
#elif hud_style == 'H': #elif hud_style == 'H':
@ -793,9 +793,9 @@ class Database:
if h_hud_style == 'T': if h_hud_style == 'T':
h_stylekey = self.h_date_ndays_ago h_stylekey = self.h_date_ndays_ago
elif h_hud_style == 'A': elif h_hud_style == 'A':
h_stylekey = '000000000' # all stylekey values should be higher than this h_stylekey = '0000000' # all stylekey values should be higher than this
elif h_hud_style == 'S': elif h_hud_style == 'S':
h_stylekey = 'zzzzzzzzz' # all stylekey values should be lower than this h_stylekey = 'zzzzzzz' # all stylekey values should be lower than this
else: else:
h_stylekey = '00000000' h_stylekey = '00000000'
log.info('h_hud_style: %s' % h_hud_style) log.info('h_hud_style: %s' % h_hud_style)
@ -1832,12 +1832,19 @@ class Database:
def storeHudCache(self, gid, pids, starttime, pdata): def storeHudCache(self, gid, pids, starttime, pdata):
"""Update cached statistics. If update fails because no record exists, do an insert.""" """Update cached statistics. If update fails because no record exists, do an insert."""
tz = datetime.utcnow() - datetime.today()
tz_offset = tz.seconds/3600
tz_day_start_offset = self.day_start + tz_offset
d = timedelta(days=hud_days, hours=tz_day_start_offset)
starttime_offset = starttime - d
if self.use_date_in_hudcache: if self.use_date_in_hudcache:
styleKey = datetime.strftime(starttime, 'd%y%m%d%H') styleKey = datetime.strftime(starttime_offset, 'd%y%m%d')
#styleKey = "d%02d%02d%02d%02d" % (hand_start_time.year-2000, hand_start_time.month, hand_start_time.day, hand_start_time.hour) #styleKey = "d%02d%02d%02d" % (hand_start_time.year-2000, hand_start_time.month, hand_start_time.day)
else: else:
# hard-code styleKey as 'A00000000' (all-time cache, no key) for now # hard-code styleKey as 'A000000' (all-time cache, no key) for now
styleKey = 'A00000000' styleKey = 'A000000'
update_hudcache = self.sql.query['update_hudcache'] update_hudcache = self.sql.query['update_hudcache']
update_hudcache = update_hudcache.replace('%s', self.sql.query['placeholder']) update_hudcache = update_hudcache.replace('%s', self.sql.query['placeholder'])

View File

@ -1064,7 +1064,7 @@ class Sql:
activeSeats SMALLINT NOT NULL, activeSeats SMALLINT NOT NULL,
position CHAR(1), position CHAR(1),
tourneyTypeId SMALLINT UNSIGNED, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), tourneyTypeId SMALLINT UNSIGNED, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
styleKey CHAR(9) NOT NULL, /* 1st char is style (A/T/H/S), other 8 are the key */ styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
HDs INT NOT NULL, HDs INT NOT NULL,
wonWhenSeenStreet1 FLOAT, wonWhenSeenStreet1 FLOAT,
@ -1165,7 +1165,7 @@ class Sql:
activeSeats SMALLINT, activeSeats SMALLINT,
position CHAR(1), position CHAR(1),
tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
styleKey CHAR(9) NOT NULL, /* 1st char is style (A/T/H/S), other 8 are the key */ styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
HDs INT, HDs INT,
wonWhenSeenStreet1 FLOAT, wonWhenSeenStreet1 FLOAT,
@ -2047,7 +2047,7 @@ class Sql:
# gets a date, would need to use handsplayers (not hudcache) to get exact hand Id # gets a date, would need to use handsplayers (not hudcache) to get exact hand Id
if db_server == 'mysql': if db_server == 'mysql':
self.query['get_date_nhands_ago'] = """ self.query['get_date_nhands_ago'] = """
select concat( 'd', date_format(max(h.startTime), '%Y%m%d%H') ) select concat( 'd', date_format(max(h.startTime), '%Y%m%d') )
from (select hp.playerId from (select hp.playerId
,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
from HandsPlayers hp from HandsPlayers hp
@ -2059,7 +2059,7 @@ class Sql:
""" """
elif db_server == 'postgresql': elif db_server == 'postgresql':
self.query['get_date_nhands_ago'] = """ self.query['get_date_nhands_ago'] = """
select 'd' || to_char(max(h3.startTime), 'YYMMDDHH') select 'd' || to_char(max(h3.startTime), 'YYMMDD')
from (select hp.playerId from (select hp.playerId
,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
from HandsPlayers hp from HandsPlayers hp
@ -2071,7 +2071,7 @@ class Sql:
""" """
elif db_server == 'sqlite': # untested guess at query: elif db_server == 'sqlite': # untested guess at query:
self.query['get_date_nhands_ago'] = """ self.query['get_date_nhands_ago'] = """
select 'd' || strftime(max(h3.startTime), 'YYMMDDHH') select 'd' || strftime(max(h3.startTime), 'YYMMDD')
from (select hp.playerId from (select hp.playerId
,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx
from HandsPlayers hp from HandsPlayers hp
@ -3290,7 +3290,7 @@ class Sql:
else 'E' else 'E'
end AS hc_position end AS hc_position
<tourney_select_clause> <tourney_select_clause>
,date_format(h.startTime, 'd%y%m%d%H') ,date_format(h.startTime, 'd%y%m%d')
,count(1) ,count(1)
,sum(wonWhenSeenStreet1) ,sum(wonWhenSeenStreet1)
,sum(wonWhenSeenStreet2) ,sum(wonWhenSeenStreet2)
@ -3379,7 +3379,7 @@ class Sql:
,h.seats ,h.seats
,hc_position ,hc_position
<tourney_group_clause> <tourney_group_clause>
,date_format(h.startTime, 'd%y%m%d%H') ,date_format(h.startTime, 'd%y%m%d')
""" """
elif db_server == 'postgresql': elif db_server == 'postgresql':
self.query['rebuildHudCache'] = """ self.query['rebuildHudCache'] = """
@ -3488,7 +3488,7 @@ class Sql:
else 'E' else 'E'
end AS hc_position end AS hc_position
<tourney_select_clause> <tourney_select_clause>
,'d' || to_char(h.startTime, 'YYMMDDHH') ,'d' || to_char(h.startTime, 'YYMMDD')
,count(1) ,count(1)
,sum(wonWhenSeenStreet1) ,sum(wonWhenSeenStreet1)
,sum(wonWhenSeenStreet2) ,sum(wonWhenSeenStreet2)
@ -3577,7 +3577,7 @@ class Sql:
,h.seats ,h.seats
,hc_position ,hc_position
<tourney_group_clause> <tourney_group_clause>
,to_char(h.startTime, 'YYMMDDHH') ,to_char(h.startTime, 'YYMMDD')
""" """
else: # assume sqlite else: # assume sqlite
self.query['rebuildHudCache'] = """ self.query['rebuildHudCache'] = """
@ -3686,7 +3686,7 @@ class Sql:
else 'E' else 'E'
end AS hc_position end AS hc_position
<tourney_select_clause> <tourney_select_clause>
,'d' || substr(strftime('%Y%m%d%H', h.startTime),3,9) ,'d' || substr(strftime('%Y%m%d', h.startTime),3,7)
,count(1) ,count(1)
,sum(wonWhenSeenStreet1) ,sum(wonWhenSeenStreet1)
,sum(wonWhenSeenStreet2) ,sum(wonWhenSeenStreet2)
@ -3775,7 +3775,7 @@ class Sql:
,h.seats ,h.seats
,hc_position ,hc_position
<tourney_group_clause> <tourney_group_clause>
,'d' || substr(strftime('%Y%m%d%H', h.startTime),3,9) ,'d' || substr(strftime('%Y%m%d', h.startTime),3,7)
""" """
self.query['insert_hudcache'] = """ self.query['insert_hudcache'] = """