#!/usr/bin/python # -*- coding: utf-8 -*- # @todo: 区服汇总 import CommFunc import ConfigParser import CTGOKSort import mylog import logging #==================== 配置 ==================== cfg = ConfigParser.ConfigParser() cfg.read("../../InterfaceConfig.php") ServerPath = cfg.get("ServerInfo", "ServerPath") # 需要处理的流向名及顺序列表 DRNameList = ["FirstLogin", "CTGOK"] #==================== 配置 ==================== class ValueObj(): def __init__(self): return def getServerSum(argvDict): ## 统计所有玩家充值累加 logging.info("getServerSum %s" % str(argvDict)) startDate = argvDict.get("startDate", "") endDate = argvDict.get("endDate", CommFunc.getCurrentDateStr()) serverSumInfo = {} # 查询中心备份的 if CommFunc.isQueryCenterbak(argvDict): queryCenterBak(startDate, endDate, argvDict) return needQueryCenterbak = CommFunc.loopMainServerDR(cfg, startDate, endDate, argvDict, checkDrFileNeedParseFunc, parseLineFunc, serverSumInfo, drNameList=DRNameList) logging.info("needQueryCenterbak %s" % needQueryCenterbak) if needQueryCenterbak: bakDataInfo = CommFunc.queryBackupCenterDR(cfg, argvDict) logging.info("queryBackupCenterDR OK") if bakDataInfo == None: return serverSumInfoBak = bakDataInfo # 合并数据 for serverIDStr, serverInfoBak in serverSumInfoBak.items(): serverID = int(serverIDStr) if serverID not in serverSumInfo: serverSumInfo[serverID] = serverInfoBak else: serverInfo = serverSumInfo[serverID] serverInfo["FirstLoginTotal"] = serverInfo.get("FirstLoginTotal", 0) + serverInfoBak.get("FirstLoginTotal", 0) CTGOKTotalInfo = serverInfo.get("CTGOKTotal", {}) for payOrderType, orderValue in serverInfoBak.get("CTGOKTotal", {}).items(): CTGOKTotalInfo[str(payOrderType)] = CTGOKTotalInfo.get(str(payOrderType), 0) + orderValue serverInfo["CTGOKTotal"] = CTGOKTotalInfo logging.info("query all data OK") serverIDList = serverSumInfo.keys() serverIDList.sort() logging.info("serverIDList %s" % serverIDList) PayOrderTypeList = eval(CommFunc.getSPConfig(argvDict, "Config", "PayOrderType", "[]")) ctgOKTotalTDNameList, tdStyleInfo = [], {} for payOrderType in PayOrderTypeList: tdName = "CTGOKTotal%s" % payOrderType orderTypeName = CommFunc.getPayOrderTypeName(payOrderType) ctgOKTotalTDNameList.append(tdName) tdStyleInfo[tdName] = {"align":"right", "title":orderTypeName} dataList = [] for serverID in serverIDList: serverInfo = serverSumInfo[serverID] serverInfo["ServerID"] = serverID CTGOKTotalInfo = serverInfo.get("CTGOKTotal", {}) for payOrderType in PayOrderTypeList: tdName = "CTGOKTotal%s" % payOrderType ctgOKTotal = CTGOKTotalInfo.get(str(payOrderType), 0) if payOrderType not in CTGOKSort.PayByMoneyOrderTypeList: ctgOKTotal = CommFunc.coinToY(ctgOKTotal, CommFunc.getPayOrderCoinRate(payOrderType)) serverInfo[tdName] = ctgOKTotal dataList.append(serverInfo) printStr = "" #printStr = "

%s

" % _(u"区服汇总") if startDate: printStr += "%s: %s
" % (_(u"开始日期"), startDate) if endDate: printStr += "%s: %s
" % (_(u"结束日期"), endDate) # 表格输出 tdStyleInfo.update({"ServerID":{"title":_(u"区服ID")}, "FirstLoginTotal":{"align":"right", "title":_(u"总创角")}, }) printStr += CommFunc.editTableHtml(dataList, ["ServerID", "FirstLoginTotal"] + ctgOKTotalTDNameList, styleInfo=tdStyleInfo) logging.info("show OK") # 只会返回最后一个print的内容 print printStr def queryCenterBak(startDate, endDate, argvDict): serverSumInfoBak = {} if not CommFunc.loopCenterbakRarDR(cfg, startDate, endDate, argvDict, checkDrFileNeedParseFunc, parseLineFunc, serverSumInfoBak, argvDict, drNameList=DRNameList): return return CommFunc.queryBackupCenterOK(serverSumInfoBak) def checkDrFileNeedParseFunc(drFileName, *parseArgs, **kv): ''' 检查流向是否需要处理 @param drFileName: 流向文件名 xxx_日期.txt @param *parseArgs: 自定义参数 @return: isNeed, checkNeedParseRetInfo ''' return True, None def parseLineFunc(drName, dateStr, checkNeedParseRetInfo, line, *parseArgs, **kv): ''' 解析流向行内容 @param drName: 流向名 @param dateStr: 对应日期字符串 @param checkNeedParseRetInfo: checkDrFileNeedParseFunc 返回的内容 @param line: 本行内容 @param *parseArgs: 自定义参数 ''' serverSumInfo = parseArgs[0] drDict = eval(line) # 首登 if drName == "FirstLogin": accID = drDict["AccID"] serverID = CommFunc.getServerID(accID) if serverID not in serverSumInfo: serverSumInfo[serverID] = {} sumInfoDict = serverSumInfo[serverID] sumInfoDict["FirstLoginTotal"] = sumInfoDict.get("FirstLoginTotal", 0) + 1 # 统计充值 elif drName == "CTGOK": accID = drDict["AccID"] payOrderType = drDict.get("payOrderType", CTGOKSort.DefaultOrderType) if payOrderType in CTGOKSort.PayByMoneyOrderTypeList: orderValue = drDict["orderMoneyValue"] else: if not CTGOKSort.IsRealCTG(drDict): return orderValue = drDict["orderCoin"] serverID = CommFunc.getServerID(accID) if serverID not in serverSumInfo: serverSumInfo[serverID] = {} sumInfoDict = serverSumInfo[serverID] if "CTGOKTotal" not in sumInfoDict: sumInfoDict["CTGOKTotal"] = {} CTGOKTotalInfo = sumInfoDict["CTGOKTotal"] CTGOKTotalInfo[str(payOrderType)] = CTGOKTotalInfo.get(str(payOrderType), 0) + orderValue return def main(): CommFunc.setdefaultencoding() argvDict = CommFunc.parse_args() mylog.InitMyLog(argvDict.get("eventType", "")) CommFunc.gettextInstall(argvDict.get("lang", "")) getServerSum(argvDict) return if __name__ == "__main__": try: main() except: CommFunc.printExceptionError()