def saveData(self, featureName, inputParamValList, dataDictionary): from Utils.DataUtils import DataUtils """inputParamList=[] inputParamValList=[] for tupleVal in inputParamTuple: inputParamList.append(tupleVal[0]) inputParamValList.append(tupleVal[1]) """ inputKeyList = [] inputKeyList.append(featureName) """for inputParam in inputParamList: inputKeyList.append(inputParam)""" featureKey = DataUtils.getUniqueKey(inputKeyList) inputParamListKey = DataUtils.getUniqueKey(inputParamValList) thisFeatureDict = {} #Check if this feature has been cached before if self.allFeaturesData.has_key(featureKey) is True: thisFeatureDict = self.allFeaturesData[featureKey] #Check if this input params set has been cached before if thisFeatureDict.has_key(inputParamListKey) is False: #Putting new entry thisFeatureDict[inputParamListKey] = dataDictionary else: #Replacing current entry thisFeatureDict[inputParamListKey] = dataDictionary self.allFeaturesData[featureKey] = thisFeatureDict else: thisFeatureDict = {} thisFeatureDict[inputParamListKey] = dataDictionary self.allFeaturesData[featureKey] = thisFeatureDict
def getData(self, featureName, inputParamValList): from Utils.DataUtils import DataUtils """inputParamList=[] inputParamValList=[] print inputParamTuple for tupleVal in inputParamTuple: inputParamList.append(tupleVal[0]) inputParamValList.append(tupleVal[1]) """ inputKeyList = [] inputKeyList.append(featureName) """for inputParam in inputParamList: inputKeyList.append(inputParam) """ featureKey = DataUtils.getUniqueKey(inputKeyList) dataKey = DataUtils.getUniqueKey(inputParamValList) if self.allFeaturesData.has_key(featureKey) is True: featureDataList = self.allFeaturesData[featureKey] if featureDataList.has_key(dataKey) is True: return featureDataList[dataKey] return None
def fetchInputAgents(self): if self.agentsFetchQuery is not None: from Utils.dbAdapter import dbAdapter from Utils.DataUtils import DataUtils from Utils.Log import Log dbAdapter = dbAdapter('REPLICASQL') self.agentsDataList = dbAdapter.fetchData(self.agentsFetchQuery) self.allAgentsDataDict = {} for agentData in self.agentsDataList: currentAgentData = {} #Converting complete agent data to dictionary for easy computation for element in agentData: currentAgentData[element[0]] = element[1] if currentAgentData['Grade'] not in (3, 4, 5): continue #Segregating parts of a key and generating key to calculate aggregate values for a key listOfKeyParts = [ currentAgentData['UserID'], currentAgentData['EmployeeId'], currentAgentData['Grade'], currentAgentData['GroupId'], currentAgentData['UserGroupName'], currentAgentData['limit'], currentAgentData['BucketSize'], currentAgentData['PPLLimit'] ] agentDataKey = DataUtils.getUniqueKey(listOfKeyParts) #To check if this agent key is already there in processed agents dictionary #Log.d(InputDataExtracter.TAG,str(agentDataKey)) if self.allAgentsDataDict.has_key(agentDataKey) is True: #If there was data corresponding to this agent key in all Agents dictionary previousAgentsData = self.allAgentsDataDict[agentDataKey] previousAgentsData[ 'LeadsCount'] = previousAgentsData['LeadsCount'] + 1 previousAgentsData['LeadsPPL'] = previousAgentsData[ 'LeadsPPL'] + currentAgentData['LeadsPPL'] previousAgentsData['L1Count'] = previousAgentsData[ 'L1Count'] + currentAgentData['L1Count'] previousAgentsData['L2Count'] = previousAgentsData[ 'L2Count'] + currentAgentData['L2Count'] previousAgentsData['L3Count'] = previousAgentsData[ 'L3Count'] + currentAgentData['L3Count'] else: #If there was no data previously for this agent in dictionary;previousAgentsData name misleading previousAgentsData = {} previousAgentsData['LeadsCount'] = 1 previousAgentsData['LeadsPPL'] = currentAgentData[ 'LeadsPPL'] previousAgentsData['Grade'] = currentAgentData['Grade'] previousAgentsData['GroupId'] = currentAgentData['GroupId'] previousAgentsData['GroupName'] = currentAgentData[ 'UserGroupName'] previousAgentsData['DailyLimit'] = currentAgentData[ 'limit'] previousAgentsData['BucketSize'] = currentAgentData[ 'BucketSize'] previousAgentsData['MaxLeadsPPLCount'] = currentAgentData[ 'PPLLimit'] previousAgentsData['L1Count'] = currentAgentData['L1Count'] previousAgentsData['L2Count'] = currentAgentData['L2Count'] previousAgentsData['L3Count'] = currentAgentData['L3Count'] previousAgentsData['UserId'] = currentAgentData['UserID'] previousAgentsData['EmployeeId'] = currentAgentData[ 'EmployeeId'] self.allAgentsDataDict[agentDataKey] = previousAgentsData return self.allAgentsDataDict else: return None