Beispiel #1
0
def createFilter():
	#this function displays all the parameters that can be added to filters
	#uses 2 dicts and 1 user entry to setup the filter parameters
	#returns the filter statement op(cat,val)
	
	opDict={0:("!=",ne),1:("==",eq),2:("<",lt),3:("<=",le),4:(">=",ge),5:(">",gt)} #the operator dict (0) is the printable symbol (1) is the object
	
	#cat: the category we filter by
	
	#print out cat options 
	for key in Lift.memberDict.keys():		
		print "%s) %s"%(key,Lift.memberDict[key][0])
	#user input for the category, selects the key for memberdict from the items in memTemp
	(_cat,cat)=Lift.memberDict[optionValidate("Choose filter category",range(key+1))]
	
	#op: The operator we use in our filtering eg: ==, >
	for key in opDict.keys():		
		print "%s) %s"%(key,opDict[key][0])
	#user input for the category, selects the key for opDict from the items in opTemp
	(_op,op)=opDict[optionValidate("Choose filter category",range(key+1))]
	
	#val: teh value we are evaluating towards
	val=raw_input("%s %s "%(_cat,_op)).lower()										
	
	return condition(cat,val,op)	
Beispiel #2
0
def expandParam(cond):
	#allows the user to choose a condition to expand
	for key in filter.condition.keys():
		print "%s) %s"%(key,filter.condition[key][0])
	choice=int(raw_input("->"))
	andor={0:and_,1:or_}	#what type of expansion
	print "0) AND\n1) OR"
	filter.expandCondition(choice,cond,andor[optionValidate("->",range(2))])
Beispiel #3
0
def addFilterP():
	#this function displays all the parameters that can be added to filters
	#returns a string "rule" 
	newCond=createFilter()	#new filter is entered by user, if existing filters, determine if it's an "and" or an "or" filter
	if filter.condition=={}:			#if this is the first thignin our filter, we jsut add the case and call it a day
		filter.addCondition(newCond,"")
	else:								#if it's not, find out how it relates to the other cases
		#determine if it expands an existing option or creates a new one
		choice={0:expandParam,1:addParam}
		print "0) Expand Existing Parameter \n1) Add New Parameter"
		choice[optionValidate("->",range(2))](newCond)
Beispiel #4
0
def rmvFilterP():
	#function to remove a filter parameter
	#display parameters that can be removed
	#change conditions based on removing 1 from beginning, middle or end
	
	#choose parameter to remove
	print "Pick parameter to remove"
	for key in filter.condition.keys():
		print "%s) %s"%(key,filter.condition[key][0])
	choice=optionValidate("->",range(len(filter.condition.keys())))
	
	filter.hideCondition(choice)
Beispiel #5
0
def addParam(cond):
	#adds a new parameter to our filter
	andor={0:and_,1:or_}
	print "0) AND\n1) OR"
	filter.addCondition(cond,andor[optionValidate("->",range(2))],0)