improve handling of hud_style options

This commit is contained in:
sqlcoder 2009-07-18 18:29:06 +01:00
parent 8386dd594e
commit cdd94d512f
2 changed files with 27 additions and 7 deletions

View File

@ -64,32 +64,47 @@ class Database:
# Future values may also include: # Future values may also include:
# H=Hands (last n hands) # H=Hands (last n hands)
self.hud_hands = 1000 # Max number of hands from each player to use for hud stats self.hud_hands = 1000 # Max number of hands from each player to use for hud stats
self.hud_days = 90 # Max number of days from each player to use for hud stats self.hud_days = 30 # Max number of days from each player to use for hud stats
self.hud_session_gap = 30 # Gap (minutes) between hands that indicates a change of session self.hud_session_gap = 30 # Gap (minutes) between hands that indicates a change of session
# (hands every 2 mins for 1 hour = one session, if followed # (hands every 2 mins for 1 hour = one session, if followed
# by a 40 minute gap and then more hands on same table that is # by a 40 minute gap and then more hands on same table that is
# a new session) # a new session)
cur = self.connection.cursor() self.cursor = self.fdb.cursor
if self.fdb.wrongDbVersion == False: if self.fdb.wrongDbVersion == False:
# self.hand_1day_ago used to fetch stats for current session (i.e. if hud_style = 'S')
self.hand_1day_ago = 0 self.hand_1day_ago = 0
cur.execute(self.sql.query['get_hand_1day_ago']) self.cursor.execute(self.sql.query['get_hand_1day_ago'])
row = cur.fetchone() row = self.cursor.fetchone()
if row and row[0]: if row and row[0]:
self.hand_1day_ago = row[0] self.hand_1day_ago = row[0]
#print "hand 1day ago =", self.hand_1day_ago #print "hand 1day ago =", self.hand_1day_ago
# self.date_ndays_ago used if hud_style = 'T'
d = timedelta(days=self.hud_days) d = timedelta(days=self.hud_days)
now = datetime.utcnow() - d now = datetime.utcnow() - d
self.date_ndays_ago = "d%02d%02d%02d" % (now.year-2000, now.month, now.day) self.date_ndays_ago = "d%02d%02d%02d" % (now.year-2000, now.month, now.day)
self.hand_nhands_ago = 0 # todo # self.hand_nhands_ago is used for fetching stats for last n hands (hud_style = 'H')
#cur.execute(self.sql.query['get_table_name'], (hand_id, )) # This option not used yet
#row = cur.fetchone() self.hand_nhands_ago = 0
# should use aggregated version of query if appropriate
self.cursor.execute(self.sql.query['get_hand_nhands_ago'], (self.hud_hands,self.hud_hands))
row = self.cursor.fetchone()
if row and row[0]:
self.hand_nhands_ago = row[0]
print "hand n hands ago =", self.hand_nhands_ago
#self.cursor.execute(self.sql.query['get_table_name'], (hand_id, ))
#row = self.cursor.fetchone()
else: else:
print "Bailing on DB query, not sure it exists yet" print "Bailing on DB query, not sure it exists yet"
self.saveActions = False if self.import_options['saveActions'] == False else True self.saveActions = False if self.import_options['saveActions'] == False else True
# could be used by hud to change hud style
def set_hud_style(self, style):
self.hud_style = style
def do_connect(self, c): def do_connect(self, c):
self.fdb.do_connect(c) self.fdb.do_connect(c)

View File

@ -571,6 +571,11 @@ class Sql:
from Hands from Hands
where handStart < now() at time zone 'UTC' - interval '1 day'""" where handStart < now() at time zone 'UTC' - interval '1 day'"""
#if db_server == 'mysql':
self.query['get_hand_nhands_ago'] = """
select coalesce(greatest(max(id),%s)-%s,0)
from Hands"""
if __name__== "__main__": if __name__== "__main__":
# just print the default queries and exit # just print the default queries and exit
s = Sql(game = 'razz', type = 'ptracks') s = Sql(game = 'razz', type = 'ptracks')