Example #1
0
	def prepareOperand(self,operand,inputLeadDataDict,executionStack):
		from Utils.Log import Log
		from Utils.TriumphKey import TriumphKey
		if len(executionStack) > 0:
			currentAgentDataDict=executionStack[-1].currentIterationData
		else:
			currentAgentDataDict=None
		if operand.opType == TriumphKey.OperandType.LITERAL:
			return operand.opTag
		elif operand.opType == TriumphKey.OperandType.FEATURE:
			if inputLeadDataDict.has_key(operand.opTag) is True:
				return inputLeadDataDict[operand.opTag]					
			elif currentAgentDataDict is not None:
				#check for data in current execution stack
				Log.d(Allocation.TAG,currentAgentDataDict)
				if currentAgentDataDict.has_key(operand.opTag) is True:
					return currentAgentDataDict[operand.opTag]
				return None
			else:
				#TODO: Ideally allocation type of feature should be handled here
				Log.log(Allocation.TAG,'Could not find data for this feature'+str(operand.opTag))
				return None
		elif operand.opType == TriumphKey.OperandType.OPERATION:
			subRule=operand.subRule[0]
			subRuleName=subRule.operands[0].opTag
			subWorkflow=self.workflowManager.getWorkflow(subRuleName,'tech',0,'sanket')
			if subWorkflow is not None:
				return self.runWorkflow(subWorkflow,inputLeadDataDict,executionStack)
		elif operand.opType == TriumphKey.OperandType.VAR:
			if operand.opTag=='agents':
				agentDataList=[]
				for key,agentData in self.inputAgentsData.iteritems():
					agentDataList.append(agentData)
				return agentDataList
Example #2
0
	def runOperation(self,workflowName,curRule,operandList,executionStack,inputLeadDataDict):
		#Process Operator on gathered list of operands
		from Utils.TriumphKey import TriumphKey
		from Utils.Log import Log
		result=0
		if curRule.operator == TriumphKey.Operator.FEATURE:
			from FeatureManager.FeatureStore import FeatureStore
			fs=FeatureStore()
			allocationFeature=curRule.operands[0].opTag
			allocOperandList=operandList[1:]
			allocOperandTuple=tuple(operandList[1:])
			featureType=fs.getFeatureType(allocationFeature)	
			if featureType==TriumphKey.FeatureType.ALLOCATION:				
				if self.mCache.getData(allocationFeature,allocOperandList) is None:
					result=self.executionContext.fetchAllocationFeatureValues(allocationFeature,allocOperandTuple)
					result=result[0][0][1]
					self.mCache.saveData(allocationFeature,allocOperandList,result)
				else:
					result=self.mCache.getData(allocationFeature,allocOperandList)
				if result is not None:
					Log.d(Allocation.TAG,'Found an allocation feature name'+str(allocationFeature))
				#result=result[0]
		elif curRule.operator == TriumphKey.Operator.LOOP:
			dataList=operandList[0]
			executionStack.append(ExecutionStackNode(workflowName,curRule.depth,curRule.nextRuleIndex,ExecutionStackNode.STACKNODETYPE.DATALOOP,dataList))								
		elif curRule.operator == TriumphKey.Operator.SUBRULE:
			from AllocationService import AllocationService
			self.workflowManager=AllocationService.getWorkflowManager()
			if operandList[0] == 'assignA1' or operandList[0] == 'assignA2' or operandList[0] =='assignA3':
				executionStack[-1].assigned=True
			newWorkflow=self.workflowManager.getWorkflow(operandList[0],'tech',0,'sanket')				
			if newWorkflow is not None:
				result=self.runWorkflow(newWorkflow,inputLeadDataDict,executionStack)	
		else:					
			from Executor.Operation import Operation
			operandListTuple=tuple(operandList)
			operation=Operation(curRule.operator,operandListTuple)	
			result=operation.operate()
		return result
    def fetchFeatureValueForLeads(self, leadsData, agentsData):
        from FeatureExec import FeatureExec
        from Utils.Log import Log
        from Utils.TriumphKey import TriumphKey
        featureExec = FeatureExec()
        self.currentLeadsData.actorDataDict = {}
        leadsList = []
        if leadsData is not None:
            for leadIdKey in leadsData.keys():
                leadsList.append(leadIdKey)
                self.currentLeadsData.actorDataDict[leadIdKey] = leadsData[
                    leadIdKey]

        self.currentAgentsData.actorDataDict = agentsData
        inputProperties = {}
        inputProperties[TriumphKey.FeatureFetchProperty.
                        dataType] = TriumphKey.FeatureType.LEAD
        inputProperties[TriumphKey.FeatureFetchProperty.
                        inputDataField] = TriumphKey.LeadInputDataField.leadId
        inputProperties[TriumphKey.FeatureFetchProperty.data] = leadsList
        from FeatureManager.FeatureStore import FeatureStore
        fs = FeatureStore()
        featureFoundOut = []
        Log.d(
            ExecutionContext.TAG,
            'List of all features from workflow to be fetched are ' +
            str(self.featureList))
        for feature in self.featureList:
            featureType = fs.getFeatureType(feature)
            if featureType == TriumphKey.FeatureType.AGENT or featureType == TriumphKey.FeatureType.ALLOCATION:
                continue
            #To avoid fetching same feature multiple times
            if feature not in featureFoundOut:
                featureFoundOut.append(feature)
            else:
                #Feature has already been found out for each lead
                continue

            #Now beginning to fetch feature data
            featureValues4AllLeads = featureExec.fetchFeatureValue(
                feature, inputProperties)
            #In case sql query failed and no data was fetched
            if featureValues4AllLeads is None:
                continue

            #Processing data lead by lead as data has been fetched for multiple leads
            for featureValuesPerLead in featureValues4AllLeads:
                leadPropDict = {}
                #Saving data for all attributes: first argument being attribute name and second being value
                for featureValTuple in featureValuesPerLead:
                    if featureValTuple[0] != 'leadId':
                        leadPropDict[str(
                            featureValTuple[0])] = featureValTuple[1]
                    else:
                        leadId = featureValTuple[1]

                #In case of data being already present for a lead append new attributes to existing dictionaries
                #else create a dictionary entry for this lead in currentLeadsData
                #Skipping putting an entry for an attribute of a lead if its already present
                if self.currentLeadsData.actorDataDict.has_key(leadId) is True:
                    prevDataTemp = self.currentLeadsData.actorDataDict[leadId]
                    for key in leadPropDict.keys():
                        if prevDataTemp.has_key(key) is False:
                            prevDataTemp[key] = leadPropDict[key]
                        else:
                            Log.d(
                                ExecutionContext.TAG,
                                'Entry already present in dictionary for this lead so skipping'
                                + str(key))
                    self.currentLeadsData.actorDataDict[leadId] = prevDataTemp
                else:
                    self.currentLeadsData.actorDataDict[leadId] = leadPropDict