Time based stats are now daily and (all time) hourly

Cuts down on unnecessary detail/storage
This commit is contained in:
moneromooo 2015-01-20 08:41:18 +00:00
parent 5d56c82cad
commit 866c1f485c

View file

@ -116,40 +116,48 @@ def RecordGameResult(link,game,win,lose,units):
identity=link.identity()
try:
ts=datetime.datetime.utcnow()
ts="%u-%02u-%02u-%02u" % (ts.year,ts.month,ts.day,ts.hour)
tsh="%u" % (ts.hour)
tsd="%u-%02u-%02u" % (ts.year,ts.month,ts.day)
p = redis_pipeline()
tname="%s:stats:"%game+identity
rtname="%s:stats:reset:"%game+identity
alltname="%s:stats:"%game
ztname="%s:zstats:"%game+":"
zhtname="%s:zstats:hourly:"%game
zdtname="%s:zstats:daily:"%game
p.hincrby(tname,"bets",1)
p.hincrby(rtname,"bets",1)
p.hincrby(alltname,"bets",1)
p.zincrby(ztname+"bets",ts,1)
p.zincrby(zhtname+"bets",tsh,1)
p.zincrby(zdtname+"bets",tsd,1)
p.hincrby(tname,"wagered",units)
p.hincrby(rtname,"wagered",units)
p.hincrby(alltname,"wagered",units)
p.zincrby(ztname+"wagered",ts,units)
p.zincrby(zhtname+"wagered",tsh,units)
p.zincrby(zdtname+"wagered",tsd,units)
if win:
p.hincrby("balances",identity,units)
p.hincrby(tname,"won",units)
p.hincrby(rtname,"won",units)
p.hincrby(alltname,"won",units)
p.zincrby(ztname+"won",ts,units)
p.zincrby(zhtname+"won",tsh,units)
p.zincrby(zdtname+"won",tsd,units)
p.hincrby(tname,"nwon",1)
p.hincrby(rtname,"nwon",1)
p.hincrby(alltname,"nwon",1)
p.zincrby(ztname+"nwon",ts,1)
p.zincrby(zhtname+"nwon",tsh,1)
p.zincrby(zdtname+"nwon",tsd,1)
if lose:
p.hincrby("balances",identity,-units)
p.hincrby(tname,"lost",units)
p.hincrby(rtname,"lost",units)
p.hincrby(alltname,"lost",units)
p.zincrby(ztname+"lost",ts,units)
p.zincrby(zhtname+"lost",tsh,units)
p.zincrby(zdtname+"lost",tsd,units)
p.hincrby(tname,"nlost",1)
p.hincrby(rtname,"nlost",1)
p.hincrby(alltname,"nlost",1)
p.zincrby(ztname+"nlost",ts,1)
p.zincrby(zhtname+"nlost",tsh,1)
p.zincrby(zdtname+"nlost",tsd,1)
p.execute()
except Exception,e:
log_error('RecordGameResult: exception updating redis: %s' % str(e))