| | |
| | | class IPY_DataMgr():
|
| | |
|
| | | def __init__(self):
|
| | | Log("IPY_DataMgr Init...")
|
| | | self.fileMD5Dict = {} # æ°æ®è¡¨æä»¶md5åå
¸, ç¨äºå¯¹æ¯æä»¶å·®å¼å¤ææ¯å¦é读 {dtName:md5, ...}
|
| | | self.ipyConfigEx = {} # èªå®ä¹æ°æ®ç¼å {key:configData, ...}
|
| | | self.ipyDataIndexMap = {} # æ°æ®è¡¨ç´¢å¼æ¥è¯¢ç¼å {dtName:{args:[index, ...], ...}, ...}
|
| | | self.ipyDataIndexMapEx = {} # æ°æ®è¡¨èªå®ä¹æ¥è¯¢æ¡ä»¶æ¥è¯¢ç¼å {dtName_(findKey,...):{(findKeyValue, ...):[index, ...], ...}, ...}
|
| | | self.ipyFuncConfigDict = {} # åè½é
置表ç¼å {key:IPY_FuncConfig, ...}
|
| | | self.IpyDataClear()
|
| | | self.classSizeDict = {} # æ°æ®è¡¨ç±»å¯¹è±¡å ç¨å
åå¤§å° {dtName:size, ...}
|
| | | self.IpyDataClear(True)
|
| | | return
|
| | |
|
| | | def IpyDataClear(self):
|
| | | Log("IPY_DataMgr Init...")
|
| | | self.ipyConfigEx = {}
|
| | | def IpyDataClear(self, onlyCheck=False):
|
| | | Log("IPY_DataMgr Reload... onlyCheck=%s" % onlyCheck)
|
| | | if not onlyCheck:
|
| | | self.ipyConfigEx = {}
|
| | | #<%Ipy_Cache_Init%>
|
| | | Log("IPY_FuncConfig count=%s" % len(self.ipyFuncConfigDict))
|
| | | Log("IPY_DataMgr InitOK!")
|
| | | Log("IPY_DataMgr ReloadOK! onlyCheck=%s" % onlyCheck)
|
| | | return
|
| | |
|
| | | def __LoadFileData(self, tableName, Class):
|
| | | def CheckLoadData(self, dtName):
|
| | | if hasattr(self, "ipy%sLen" % dtName):
|
| | | return
|
| | | setattr(self, "ipy%sLen" % dtName, 0) # è®¾ç½®è¯¥å±æ§ï¼éè¿å¤ææ¯å¦æè¯¥å±æ§å³å®æ¯å¦å è½½
|
| | | self.__LoadFileData(dtName)
|
| | | return
|
| | | |
| | | def __LoadFileData(self, tableName, onlyCheck=False):
|
| | | # @param onlyCheck: æ¯å¦ä»
æ£æ¥æ ¼å¼ï¼ä¸è¬å¯å¨æ¶ç¨
|
| | | curPath = "<%LoadStructPath%>" + "\\PySysDB\\tag" + tableName + ".txt"
|
| | | if not os.path.isfile(curPath):
|
| | | ErrLog("can not find file = %s,%s" % (tableName, curPath))
|
| | | raise Exception("can not find file = %s,%s" % (tableName, curPath))
|
| | |
|
| | | if not onlyCheck:
|
| | | if not hasattr(self, "ipy%sLen" % tableName):
|
| | | # 没æè¯¥å±æ§çä¸å è½½
|
| | | return
|
| | | |
| | | fileObj = open(curPath, 'rb')
|
| | | content = fileObj.read()
|
| | | fileObj.close()
|
| | |
|
| | | md5_obj = hashlib.md5()
|
| | | md5_obj.update(content)
|
| | | newMD5Code = md5_obj.hexdigest()
|
| | | if tableName in self.fileMD5Dict:
|
| | | oldMD5Code = self.fileMD5Dict[tableName]
|
| | | if newMD5Code == oldMD5Code:
|
| | | return getattr(self, "ipy%sCache" % tableName)
|
| | | if not onlyCheck:
|
| | | md5_obj = hashlib.md5()
|
| | | md5_obj.update(content)
|
| | | newMD5Code = md5_obj.hexdigest()
|
| | | if tableName in self.fileMD5Dict:
|
| | | oldMD5Code = self.fileMD5Dict[tableName]
|
| | | if newMD5Code == oldMD5Code:
|
| | | return getattr(self, "ipy%sCache" % tableName)
|
| | | |
| | | if tableName in self.ipyDataIndexMap:
|
| | | self.ipyDataIndexMap.pop(tableName)
|
| | | for dtName_Findkey in self.ipyDataIndexMapEx.keys():
|
| | | findStr = "%s_" % tableName
|
| | | if findStr in dtName_Findkey:
|
| | | self.ipyDataIndexMapEx.pop(dtName_Findkey)
|
| | | if tableName == "FuncConfig":
|
| | | self.ipyFuncConfigDict = {}
|
| | | self.fileMD5Dict[tableName] = newMD5Code
|
| | |
|
| | | if tableName in self.ipyDataIndexMap:
|
| | | self.ipyDataIndexMap.pop(tableName)
|
| | | for dtName_Findkey in self.ipyDataIndexMapEx.keys():
|
| | | findStr = "%s_" % tableName
|
| | | if findStr in dtName_Findkey:
|
| | | self.ipyDataIndexMapEx.pop(dtName_Findkey)
|
| | | if tableName == "FuncConfig":
|
| | | self.ipyFuncConfigDict = {}
|
| | | self.fileMD5Dict[tableName] = newMD5Code
|
| | | |
| | | dataIndex = 0
|
| | | indexDict = {}
|
| | | cacheList = []
|
| | | fieldList = Def_IpyTable[tableName]
|
| | | infoList = content.split('\r\n')
|
| | | curClassSizeTotal = 0
|
| | | dataCount = 0
|
| | | Class = eval("IPY_%s" % tableName)
|
| | | for line in xrange(len(infoList)):
|
| | | if line == 0:
|
| | | continue
|
| | |
| | | if len(fieldList) != len(rowList):
|
| | | ErrLog("field count error!, %s, line=%s, len=%s,rowCount=%s" % (tableName, line, len(fieldList), len(rowList)))
|
| | | raise Exception("field count error!, %s, line=%s, len=%s,rowCount=%s" % (tableName, line,len(fieldList), len(rowList)))
|
| | | |
| | | if tableName == "FuncConfig":
|
| | | classObj = self.__LoadFuncConfigData(fieldList, rowList, onlyCheck)
|
| | | dataCount += 1
|
| | | if onlyCheck:
|
| | | continue
|
| | | curClassSizeTotal += ChConfig.GetSizeof(classObj)
|
| | | continue
|
| | | try:
|
| | | indexKey = []
|
| | | classObj = Class()
|
| | | valueList = []
|
| | | for j, value in enumerate(rowList):
|
| | | fieldType, fieldName, isIndex = fieldList[j]
|
| | | if fieldType == "char":
|
| | |
| | | attrValue = float(value)
|
| | | else:
|
| | | attrValue = 0 if not value.isdigit() else int(value)
|
| | | setattr(classObj, "%s" % fieldName, attrValue)
|
| | | valueList.append(attrValue)
|
| | | if isIndex:
|
| | | indexKey.append(attrValue)
|
| | | dataCount += 1
|
| | | if onlyCheck:
|
| | | continue
|
| | | classObj = Class()
|
| | | setattr(classObj, "attrTuple", tuple(valueList))
|
| | | curClassSizeTotal += ChConfig.GetSizeof(classObj)
|
| | | cacheList.append(classObj)
|
| | | indexKey = tuple(indexKey)
|
| | | indexList = indexDict.get(indexKey, [])
|
| | |
| | | except BaseException:
|
| | | ErrLog("SetIpyDataError: tableName=%s,line=%s,fieldName=%s,fieldType=%s,value=%s" % (tableName, line, fieldName, fieldType, value))
|
| | | raise
|
| | | if tableName == "FuncConfig":
|
| | | self.__LoadFuncConfigData(fieldList, rowList)
|
| | | if onlyCheck:
|
| | | Log("CheckIpydata: %s, dataCount=%s OK" % (tableName, dataCount))
|
| | | return
|
| | | if tableName != "FuncConfig":
|
| | | self.ipyDataIndexMap[tableName] = indexDict
|
| | | Log("LoadIpydata: %s, content count=%s" % (tableName, len(cacheList)))
|
| | | return cacheList
|
| | | self.classSizeDict[tableName] = curClassSizeTotal
|
| | | classSizeTotal = sum(self.classSizeDict.values())
|
| | | alreadyLoad = len(self.classSizeDict)
|
| | | setattr(self, "ipy%sCache" % tableName, cacheList)
|
| | | setattr(self, "ipy%sLen" % tableName, len(cacheList))
|
| | | Log("LoadIpydata: %s, dataCount=%s, alreadyLoad=%s" % (tableName, dataCount, alreadyLoad), curClassSizeTotal, classSizeTotal)
|
| | | return
|
| | |
|
| | | def __LoadFuncConfigData(self, fieldList, rowList):
|
| | | funcConfigObj = IPY_FuncConfig()
|
| | | def __LoadFuncConfigData(self, fieldList, rowList, onlyCheck):
|
| | | key = rowList[0]
|
| | | funcConfigObj.Key = key
|
| | | valueList = [key]
|
| | | for i, strValue in enumerate(rowList):
|
| | | if i == 0:
|
| | | continue
|
| | | try:
|
| | | fieldName = fieldList[i][1]
|
| | | strValue = strValue.lstrip().rstrip()
|
| | | if strValue.isdigit():
|
| | | configValue = int(strValue)
|
| | |
| | | except BaseException:
|
| | | ErrLog("SetIpyDataError: tableName=%s,key=%s,i=%s,value=%s" % ("FuncConfig", key, i, strValue))
|
| | | raise
|
| | | setattr(funcConfigObj, fieldName, configValue)
|
| | | if onlyCheck:
|
| | | continue
|
| | | valueList.append(configValue)
|
| | | if onlyCheck:
|
| | | return
|
| | | funcConfigObj = IPY_FuncConfig()
|
| | | setattr(funcConfigObj, "attrTuple", tuple(valueList))
|
| | | self.ipyFuncConfigDict[key] = funcConfigObj
|
| | | return
|
| | | return funcConfigObj
|
| | |
|
| | | def __ToFloat(self, strValue):
|
| | | try:
|
| | |
| | | @return: å¯¹åºæ¥è¯¢æ¡ä»¶ç ipyData æ°æ®å®ä¾ï¼åªè¿åå个å®ä¾
|
| | | @使ç¨è¯´æ: IpyGameDataPY.GetIpyGameData(表å, ç´¢å¼1æ¥è¯¢å¼, ç´¢å¼2æ¥è¯¢å¼, ⦠)
|
| | | '''
|
| | | IPYData.CheckLoadData(dtName)
|
| | | if dtName not in IPYData.ipyDataIndexMap:
|
| | | ErrLog("Can not found ipyData dtName=%s" % (dtName))
|
| | | return
|
| | |
| | | @return: å¯¹åºæ¥è¯¢æ¡ä»¶ç ipyData æ°æ®å®ä¾å表
|
| | | @使ç¨è¯´æ: ä¸ GetIpyGameData 彿°ç¸å
|
| | | '''
|
| | | IPYData.CheckLoadData(dtName)
|
| | | if dtName not in IPYData.ipyDataIndexMap:
|
| | | ErrLog("Can not found ipyDataList dtName=%s" % (dtName))
|
| | | return
|
| | |
| | | def GetIpyGameDataNotLog(dtName, *args):
|
| | | '''ä¸ GetIpyGameData 彿°ç¸å, åªæ¯æ¾ä¸å°æ°æ®æ¶ä¸ä¼è¾åºæ¥å¿
|
| | | '''
|
| | | IPYData.CheckLoadData(dtName)
|
| | | if dtName not in IPYData.ipyDataIndexMap:
|
| | | #ErrLog("Can not found ipyData dtName=%s" % (dtName))
|
| | | return
|
| | |
| | | def GetIpyGameDataListNotLog(dtName, *args):
|
| | | '''ä¸ GetIpyGameDataList 彿°ç¸å, åªæ¯æ¾ä¸å°æ°æ®æ¶ä¸ä¼è¾åºæ¥å¿
|
| | | '''
|
| | | IPYData.CheckLoadData(dtName)
|
| | | if dtName not in IPYData.ipyDataIndexMap:
|
| | | #ErrLog("Can not found ipyDataList dtName=%s" % (dtName))
|
| | | return
|
| | |
| | | @param isLogNone: æ¾ä¸å°æ°æ®æ¶æ¯å¦æ°æ®æ¥å¿ï¼é»è®¤æ¯
|
| | | @return: æ¾ä¸å°æ°æ®æ¶è¿å Noneï¼ææ°æ®æ¶æ ¹æ®åæ°æ¯å¦è¿åå表è¿å对åºçæ°æ®å®ä¾ææ°æ®å®ä¾å表
|
| | | '''
|
| | | IPYData.CheckLoadData(dtName)
|
| | | fieldList = keyDict.keys()
|
| | | valueList = keyDict.values()
|
| | | findFieldKey = "%s_%s" % (dtName, fieldList)
|
| | |
| | | if findFieldKey not in IPYData.ipyDataIndexMapEx:
|
| | | indexMapDict = {}
|
| | | for index, iData in enumerate(cacheList):
|
| | | valuekey = tuple([getattr(iData, "%s" % field) for field in fieldList])
|
| | | valuekey = tuple([getattr(iData, "Get%s" % field)() for field in fieldList])
|
| | | indexList = indexMapDict.get(valuekey, [])
|
| | | indexList.append(index)
|
| | | indexMapDict[valuekey] = indexList
|
| | |
| | | @param key: é
ç½®key
|
| | | @return: ç´æ¥è¿å该é
ç½®key对åºçé
ç½®ipyDataå®ä¾
|
| | | '''
|
| | | IPYData.CheckLoadData("FuncConfig")
|
| | | if key not in IPYData.ipyFuncConfigDict:
|
| | | ErrLog("Can not found ipyData FuncConfig key=%s!" % key)
|
| | | return ""
|
| | |
| | | @param index: 第å 个é
ç½®å¼ï¼æ¯æ1~5
|
| | | @return: ç´æ¥è¿å对åºçæ°æ®ç±»å intãstrï¼ä¸ç¨åæå¨è½¬int
|
| | | '''
|
| | | IPYData.CheckLoadData("FuncConfig")
|
| | | if key not in IPYData.ipyFuncConfigDict:
|
| | | ErrLog("Can not found ipyData FuncConfig key=%s!" % key)
|
| | | return ""
|
| | | cfgObj = IPYData.ipyFuncConfigDict[key]
|
| | | if index == 1:
|
| | | return cfgObj.Numerical1
|
| | | return cfgObj.attrTuple[1]
|
| | | if index == 2:
|
| | | return cfgObj.Numerical2
|
| | | return cfgObj.attrTuple[2]
|
| | | if index == 3:
|
| | | return cfgObj.Numerical3
|
| | | return cfgObj.attrTuple[3]
|
| | | if index == 4:
|
| | | return cfgObj.Numerical4
|
| | | return cfgObj.attrTuple[4]
|
| | | if index == 5:
|
| | | return cfgObj.Numerical5
|
| | | return cfgObj.attrTuple[5]
|
| | | ErrLog("Can not found ipyData FuncConfig key=%s,index=%s!" % (key, index))
|
| | | return ""
|
| | |
|
| | |
| | | å½ç¶å¦æé
ç½®çå
容æ¬èº«å°±ä¸ºpythonçå表ãåå
¸ç»æçè¯å¯ä½¿ç¨ä¸é¢ç彿°
|
| | | ä¸è¿ä¸ºäºç»ä¸ï¼å»ºè®®åè½é
置表读å表ãåå
¸æ¶é½ä½¿ç¨è¯¥å½æ°
|
| | | '''
|
| | | IPYData.CheckLoadData("FuncConfig")
|
| | | if key not in IPYData.ipyFuncConfigDict:
|
| | | ErrLog("Can not found ipyData FuncConfig key=%s!" % key)
|
| | | return defaultValue
|
| | | cfgObj = IPYData.ipyFuncConfigDict[key]
|
| | | if index == 1:
|
| | | curConfig = cfgObj.Numerical1
|
| | | curConfig = cfgObj.attrTuple[1]
|
| | | elif index == 2:
|
| | | curConfig = cfgObj.Numerical2
|
| | | curConfig = cfgObj.attrTuple[2]
|
| | | elif index == 3:
|
| | | curConfig = cfgObj.Numerical3
|
| | | curConfig = cfgObj.attrTuple[3]
|
| | | elif index == 4:
|
| | | curConfig = cfgObj.Numerical4
|
| | | curConfig = cfgObj.attrTuple[4]
|
| | | elif index == 5:
|
| | | curConfig = cfgObj.Numerical5
|
| | | curConfig = cfgObj.attrTuple[5]
|
| | | else:
|
| | | ErrLog("Can not found ipyData FuncConfig key=%s,index=%s!" % (key, index))
|
| | | return defaultValue
|
| | |
| | | @param conditionDict: æ¥è¯¢æ¡ä»¶ï¼{æ¥è¯¢å段å:åæ®µå¼, ...}
|
| | | @return: æ¾ä¸å°æ°æ®è¿å None ï¼ å¦åè¿å对åºç ipyData æ°æ®å®ä¾
|
| | | '''
|
| | | IPYData.CheckLoadData(dtName)
|
| | | if not conditionDict:
|
| | | dataList = getattr(IPYData, "ipy%sCache" % dtName)
|
| | | else:
|
| | |
| | |
|
| | | low = 0
|
| | | lowData = dataList[0]
|
| | | lowValue = getattr(lowData, "%s" % keyName)
|
| | | lowValue = getattr(lowData, "Get%s" % keyName)()
|
| | | if keyValue < lowValue:
|
| | | return
|
| | |
|
| | | high = len(dataList) - 1
|
| | | highData = dataList[high]
|
| | | highValue = getattr(highData, "%s" % keyName)
|
| | | highValue = getattr(highData, "Get%s" % keyName)()
|
| | | if keyValue >= highValue:
|
| | | return highData
|
| | |
|
| | | near = low + int((high - low) * (keyValue - lowValue)/(highValue - lowValue))
|
| | |
|
| | | nearData = dataList[near]
|
| | | nearValue = getattr(nearData, "%s" % keyName)
|
| | | nearValue = getattr(nearData, "Get%s" % keyName)()
|
| | |
|
| | | if keyValue < nearValue:
|
| | | for i in xrange(near - 1, low - 1, -1):
|
| | | nearData = dataList[i]
|
| | | nearValue = getattr(nearData, "%s" % keyName)
|
| | | nearValue = getattr(nearData, "Get%s" % keyName)()
|
| | | if nearValue <= keyValue:
|
| | | return nearData
|
| | |
|
| | | elif keyValue > nearValue:
|
| | | for i in xrange(near + 1, high + 1):
|
| | | nearData = dataList[i]
|
| | | nearValue = getattr(nearData, "%s" % keyName)
|
| | | nearValue = getattr(nearData, "Get%s" % keyName)()
|
| | | if nearValue > keyValue:
|
| | | return dataList[i - 1]
|
| | |
|
| | | return nearData
|
| | |
|
| | | #if __name__ == "__main__":
|
| | | # IPYDataTotalSize = ChConfig.GetSizeof(IPYData)
|
| | | # classSizeSum = sum(IPYData.classSizeDict.values())
|
| | | # Log("æ°æ®ç±»å
å: %s b = %s M" % (classSizeSum, str(classSizeSum/float(1024*1024))))
|
| | | # Log("æ»å ç¨å
å: %s b = %s M" % (IPYDataTotalSize, str(IPYDataTotalSize/float(1024*1024))))
|
| | | # for key in ["OpenBagItem", "RuneUnlock", "IceLodeNeedPoint", "RealmDifficulty", "TongTianLing", "TongTianLingaaa"]:
|
| | | # for i in range(1, 6):
|
| | | # v = GetFuncCfg(key, i)
|
| | | # Log("key:%s,i=%s,value=%s\t%s" % (key, i, type(v), str(v)))
|
| | | # |
| | | # ipyData = GetIpyGameData("FlashGiftbag", 303)
|
| | | # giftbagIpyDataList = GetIpyGameDataByCondition("FlashGiftbag", {"GiftbagType":1002}, True, True)
|
| | | # for ipyData in giftbagIpyDataList:
|
| | | # print |
| | | # print type(ipyData.GetGiftbagID()), ipyData.GetGiftbagID()
|
| | | # print type(ipyData.GetGiftbagType()), ipyData.GetGiftbagType()
|
| | | # print type(ipyData.GetOriginalRMB()), ipyData.GetOriginalRMB()
|
| | | # print type(ipyData.GetBuyCountLimit()), ipyData.GetBuyCountLimit()
|
| | | # print type(ipyData.GetGiftItemList()), ipyData.GetGiftItemList()
|
| | | # print type(ipyData.GetMainItemID()), ipyData.GetMainItemID()
|
| | | # print type(ipyData.GetNotifyKey()), ipyData.GetNotifyKey()
|
| | | # |
| | | # collNPCIpyDataList = GetIpyGameDataListNotLog("MapRefreshNPC", 32050)
|
| | | # if collNPCIpyDataList:
|
| | | # npcIDList = []
|
| | | # for ipyData in collNPCIpyDataList:
|
| | | # print |
| | | # print type(ipyData.GetMapID()), ipyData.GetMapID()
|
| | | # print type(ipyData.GetNPCIDList()), ipyData.GetNPCIDList()
|
| | | # print type(ipyData.GetRefreshMarkList()), ipyData.GetRefreshMarkList()
|
| | | # npcIDList += ipyData.GetNPCIDList()
|
| | | # print "npcIDList", npcIDList
|
| | | # else:
|
| | | # print "None"
|
| | | # |
| | | # ipyData = GetIpyGameData("RuneCompound", 4415)
|
| | | # if ipyData:
|
| | | # print |
| | | # print type(ipyData.GetTagItemID()), ipyData.GetTagItemID()
|
| | | # print type(ipyData.GetNeedItem()), ipyData.GetNeedItem()
|
| | | # print type(ipyData.GetNeedMJ()), ipyData.GetNeedMJ()
|
| | | # else:
|
| | | # print "None"
|
| | | # |
| | | # ipyData = GetIpyGameData("DailyGiftbag", 703, 105)
|
| | | # if ipyData:
|
| | | # print |
| | | # print type(ipyData.GetGiftbagType()), ipyData.GetGiftbagType()
|
| | | # print type(ipyData.GetGiftbagID()), ipyData.GetGiftbagID()
|
| | | # print type(ipyData.GetBuyCountLimit()), ipyData.GetBuyCountLimit()
|
| | | # print type(ipyData.GetGiftItemList()), ipyData.GetGiftItemList()
|
| | | # else:
|
| | | # print "None"
|
| | | |