From e0f76a508c8e1c51e49f2f2e6888ce10129084e4 Mon Sep 17 00:00:00 2001 From: Chaz Date: Tue, 30 Nov 2010 14:05:28 -0500 Subject: [PATCH] reverted HudCache styleKey to include only YYMMDD - however, it now stores the d000000 date based off the tz & offset --- pyfpdb/Database.py | 37 ++++++++++++++++++++++--------------- pyfpdb/SQL.py | 22 +++++++++++----------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 99d1322d..64d42a06 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -73,7 +73,7 @@ except ImportError: use_numpy = False -DB_VERSION = 145 +DB_VERSION = 144 # 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: 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.h_date_ndays_ago = 'd00000000' # date N days ago ('d' + YYMMDD) for hero + self.date_ndays_ago = 'd000000' # date N days ago ('d' + YYMMDD) + 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.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) 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) 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): # not sure if this is workable, to be continued ... try: # 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 :-( - self.date_nhands_ago[str(playerid)] = 'd00000000' + self.date_nhands_ago[str(playerid)] = 'd000000' # should use aggregated version of query if appropriate c.execute(self.sql.query['get_date_nhands_ago'], (self.hud_hands, playerid)) @@ -780,11 +780,11 @@ class Database: if hud_style == 'T': stylekey = self.date_ndays_ago 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': - stylekey = 'zzzzzzzzz' # all stylekey values should be lower than this + stylekey = 'zzzzzzz' # all stylekey values should be lower than this else: - stylekey = '000000000' + stylekey = '0000000' log.info('hud_style: %s' % hud_style) #elif hud_style == 'H': @@ -793,9 +793,9 @@ class Database: if h_hud_style == 'T': h_stylekey = self.h_date_ndays_ago 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': - h_stylekey = 'zzzzzzzzz' # all stylekey values should be lower than this + h_stylekey = 'zzzzzzz' # all stylekey values should be lower than this else: h_stylekey = '00000000' log.info('h_hud_style: %s' % h_hud_style) @@ -1832,12 +1832,19 @@ class Database: def storeHudCache(self, gid, pids, starttime, pdata): """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: - styleKey = datetime.strftime(starttime, 'd%y%m%d%H') - #styleKey = "d%02d%02d%02d%02d" % (hand_start_time.year-2000, hand_start_time.month, hand_start_time.day, hand_start_time.hour) + styleKey = datetime.strftime(starttime_offset, 'd%y%m%d') + #styleKey = "d%02d%02d%02d" % (hand_start_time.year-2000, hand_start_time.month, hand_start_time.day) else: - # hard-code styleKey as 'A00000000' (all-time cache, no key) for now - styleKey = 'A00000000' + # hard-code styleKey as 'A000000' (all-time cache, no key) for now + styleKey = 'A000000' update_hudcache = self.sql.query['update_hudcache'] update_hudcache = update_hudcache.replace('%s', self.sql.query['placeholder']) diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index 6a505eae..d45ccd38 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -1064,7 +1064,7 @@ class Sql: activeSeats SMALLINT NOT NULL, position CHAR(1), 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, wonWhenSeenStreet1 FLOAT, @@ -1165,7 +1165,7 @@ class Sql: activeSeats SMALLINT, position CHAR(1), 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, wonWhenSeenStreet1 FLOAT, @@ -2047,7 +2047,7 @@ class Sql: # gets a date, would need to use handsplayers (not hudcache) to get exact hand Id if db_server == 'mysql': 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 ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx from HandsPlayers hp @@ -2059,7 +2059,7 @@ class Sql: """ elif db_server == 'postgresql': 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 ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx from HandsPlayers hp @@ -2071,7 +2071,7 @@ class Sql: """ elif db_server == 'sqlite': # untested guess at query: self.query['get_date_nhands_ago'] = """ - select 'd' || strftime(max(h3.startTime), 'YYMMDDHH') + select 'd' || strftime(max(h3.startTime), 'YYMMDD') from (select hp.playerId ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx from HandsPlayers hp @@ -3290,7 +3290,7 @@ class Sql: else 'E' end AS hc_position - ,date_format(h.startTime, 'd%y%m%d%H') + ,date_format(h.startTime, 'd%y%m%d') ,count(1) ,sum(wonWhenSeenStreet1) ,sum(wonWhenSeenStreet2) @@ -3379,7 +3379,7 @@ class Sql: ,h.seats ,hc_position - ,date_format(h.startTime, 'd%y%m%d%H') + ,date_format(h.startTime, 'd%y%m%d') """ elif db_server == 'postgresql': self.query['rebuildHudCache'] = """ @@ -3488,7 +3488,7 @@ class Sql: else 'E' end AS hc_position - ,'d' || to_char(h.startTime, 'YYMMDDHH') + ,'d' || to_char(h.startTime, 'YYMMDD') ,count(1) ,sum(wonWhenSeenStreet1) ,sum(wonWhenSeenStreet2) @@ -3577,7 +3577,7 @@ class Sql: ,h.seats ,hc_position - ,to_char(h.startTime, 'YYMMDDHH') + ,to_char(h.startTime, 'YYMMDD') """ else: # assume sqlite self.query['rebuildHudCache'] = """ @@ -3686,7 +3686,7 @@ class Sql: else 'E' end AS hc_position - ,'d' || substr(strftime('%Y%m%d%H', h.startTime),3,9) + ,'d' || substr(strftime('%Y%m%d', h.startTime),3,7) ,count(1) ,sum(wonWhenSeenStreet1) ,sum(wonWhenSeenStreet2) @@ -3775,7 +3775,7 @@ class Sql: ,h.seats ,hc_position - ,'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'] = """