diff --git a/tools/rankserver/app.py b/tools/rankserver/app.py index 3beaf46..544ea90 100644 --- a/tools/rankserver/app.py +++ b/tools/rankserver/app.py @@ -12,6 +12,7 @@ import time import datetime import redis import os + CONFIG_DIR = '' def IsOnlineEnv(): @@ -72,7 +73,10 @@ def refreshData(row, data_list, data_info): alive_time = safeDiv(row[4], row[7]) harm = safeDiv(row[5], row[7]) win_times = safeDiv(row[6], row[7]) - data_list.append((row[0], row[1].decode('utf-8'), row[2], kill, alive_time, harm, win_times, row[6], row[9])) + num = row[9] + if (time.time() > row[10]): + num = 0 + data_list.append((row[0], row[1].decode('utf-8'), row[2], kill, alive_time, harm, win_times, row[6], num)) data_list.sort(key=key_info, reverse=True) if (len(data_list) > 50): del data_list[50:] @@ -97,8 +101,7 @@ def updateRank(r, kill_list, win_list ,integral_list): integral_rank.append(integral_list[integral_index]) r.set("game2001api: integral_rank", json.dumps(integral_rank)) -#每日定时读取mysql里的数据生成排行榜写入redis后php读取redis返回客户端显示 -def dayReadMysqlData(rushtime): +def internalDayReadMysqlData(): mysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.mysql.cluster.json', 'r').read()) kill_list = [] alive_list = [] @@ -119,7 +122,7 @@ def dayReadMysqlData(rushtime): temp_idx = 0 while 1: cursor.execute('SELECT accountid, user_name, avatar_url, kills, alive_time,' - ' harm, win_times, game_times, idx, integral FROM user WHERE idx > %s LIMIT 0, 1000' % (last_idx)) + ' harm, win_times, game_times, idx, integral, season_time FROM user WHERE idx > %s LIMIT 0, 1000' % (last_idx)) has_data = False for row in cursor: @@ -139,6 +142,10 @@ def dayReadMysqlData(rushtime): r = getRedis() updateRank(r, kill_list, win_list, integral_list) + +#每日定时读取mysql里的数据生成排行榜写入redis后php读取redis返回客户端显示 +def dayReadMysqlData(rushtime): + internalDayReadMysqlData() tornado.ioloop.IOLoop.current().call_later(getDaySeconds(time.time(), 1) + rushtime, lambda : dayReadMysqlData(rushtime) ) @@ -178,17 +185,48 @@ def readMysqlData(rushtime): temp_idx = 0 while 1: cursor.execute('SELECT accountid, user_name, avatar_url, kills, alive_time,' - ' harm, win_times, game_times, idx, integral, modify_time FROM user ' - ' WHERE modify_time > %s AND idx > %s LIMIT 0, 1000' % (time.time() - 300, last_idx)) + ' harm, win_times, game_times, idx, integral, season_time, kill_modifytime FROM user ' + ' WHERE kill_modifytime > %s AND idx > %s LIMIT 0, 1000' % (time.time() - 300, last_idx)) has_data = False for row in cursor: has_data = True #更新击杀榜 delRepeatData(row, kill_list) refreshData(row, kill_list, take_kills) + temp_idx = int(row[8]) + if (temp_idx > last_idx) : + last_idx = int(row[8]) + if not has_data: + break + + last_idx = 0 + temp_idx = 0 + while 1: + cursor.execute('SELECT accountid, user_name, avatar_url, kills, alive_time,' + ' harm, win_times, game_times, idx, integral, season_time, win_modifytime FROM user ' + ' WHERE win_modifytime > %s AND idx > %s LIMIT 0, 1000' % (time.time() - 300, last_idx)) + has_data = False + for row in cursor: + has_data = True #更新胜场榜 delRepeatData(row, win_list) refreshData(row, win_list, take_game_times) + temp_idx = int(row[8]) + if (temp_idx > last_idx) : + last_idx = int(row[8]) + if not has_data: + break + + last_idx = 0 + temp_idx = 0 + while 1: + cursor.execute('SELECT accountid, user_name, avatar_url, kills, alive_time,' + ' harm, win_times, game_times, idx, integral, season_time, rank_modifytime FROM user ' + ' WHERE rank_modifytime > %s AND idx > %s LIMIT 0, 1000' % (time.time() - 300, last_idx)) + + has_data = False + for row in cursor: + has_data = True #更新积分榜 delRepeatData(row, integral_list) refreshData(row, integral_list, take_integral_times) @@ -202,7 +240,6 @@ def readMysqlData(rushtime): lambda : readMysqlData(rushtime) ) - class SelfCheckingHandler(tornado.web.RequestHandler): def get(self): @@ -228,8 +265,9 @@ if __name__ == "__main__": lambda : readMysqlData(conf['rushtime']) ) - conf['day_rushtime'] = 17 * 3600 + conf['day_rushtime'] = 0 tornado.ioloop.IOLoop.current().call_later(getDaySeconds(time.time(), 1) + conf['day_rushtime'], lambda : dayReadMysqlData(conf['day_rushtime']) ) + tornado.ioloop.IOLoop.current().start()