Keep track of game stats against time

This commit is contained in:
moneromooo 2015-01-19 23:46:45 +00:00
parent 826902213c
commit 5d56c82cad

View file

@ -12,6 +12,7 @@
import random import random
import hashlib import hashlib
import time import time
import datetime
import tipbot.coinspecs as coinspecs import tipbot.coinspecs as coinspecs
from tipbot.command_manager import * from tipbot.command_manager import *
from utils import * from utils import *
@ -114,32 +115,41 @@ def GetServerSeedHash(link,game):
def RecordGameResult(link,game,win,lose,units): def RecordGameResult(link,game,win,lose,units):
identity=link.identity() identity=link.identity()
try: try:
ts=datetime.datetime.utcnow()
ts="%u-%02u-%02u-%02u" % (ts.year,ts.month,ts.day,ts.hour)
p = redis_pipeline() p = redis_pipeline()
tname="%s:stats:"%game+identity tname="%s:stats:"%game+identity
rtname="%s:stats:reset:"%game+identity rtname="%s:stats:reset:"%game+identity
alltname="%s:stats:"%game alltname="%s:stats:"%game
ztname="%s:zstats:"%game+":"
p.hincrby(tname,"bets",1) p.hincrby(tname,"bets",1)
p.hincrby(rtname,"bets",1) p.hincrby(rtname,"bets",1)
p.hincrby(alltname,"bets",1) p.hincrby(alltname,"bets",1)
p.zincrby(ztname+"bets",ts,1)
p.hincrby(tname,"wagered",units) p.hincrby(tname,"wagered",units)
p.hincrby(rtname,"wagered",units) p.hincrby(rtname,"wagered",units)
p.hincrby(alltname,"wagered",units) p.hincrby(alltname,"wagered",units)
p.zincrby(ztname+"wagered",ts,units)
if win: if win:
p.hincrby("balances",identity,units) p.hincrby("balances",identity,units)
p.hincrby(tname,"won",units) p.hincrby(tname,"won",units)
p.hincrby(rtname,"won",units) p.hincrby(rtname,"won",units)
p.hincrby(alltname,"won",units) p.hincrby(alltname,"won",units)
p.zincrby(ztname+"won",ts,units)
p.hincrby(tname,"nwon",1) p.hincrby(tname,"nwon",1)
p.hincrby(rtname,"nwon",1) p.hincrby(rtname,"nwon",1)
p.hincrby(alltname,"nwon",1) p.hincrby(alltname,"nwon",1)
p.zincrby(ztname+"nwon",ts,1)
if lose: if lose:
p.hincrby("balances",identity,-units) p.hincrby("balances",identity,-units)
p.hincrby(tname,"lost",units) p.hincrby(tname,"lost",units)
p.hincrby(rtname,"lost",units) p.hincrby(rtname,"lost",units)
p.hincrby(alltname,"lost",units) p.hincrby(alltname,"lost",units)
p.zincrby(ztname+"lost",ts,units)
p.hincrby(tname,"nlost",1) p.hincrby(tname,"nlost",1)
p.hincrby(rtname,"nlost",1) p.hincrby(rtname,"nlost",1)
p.hincrby(alltname,"nlost",1) p.hincrby(alltname,"nlost",1)
p.zincrby(ztname+"nlost",ts,1)
p.execute() p.execute()
except Exception,e: except Exception,e:
log_error('RecordGameResult: exception updating redis: %s' % str(e)) log_error('RecordGameResult: exception updating redis: %s' % str(e))