Ejemplo n.º 1
0
def modifyRules(desc):
    # user input for new lines
    isValid = False
    while not isValid:
        print "Available rules: " + rules.getRules()
        rule = raw_input('Need a rule for "' + desc + '": ')
        isValid = rules.checkRule(rule)

        # slurp in the input file
    ruleFile = open("rules.py", "r")
    tempFile = open("rules.temp", "w")
    lines = ruleFile.readlines()
    for line in lines[:-1]:
        tempFile.write(line)

        # write out the new rule and replace the last line
    tempFile.write("\tif '" + desc + "' in desc:\n")
    tempFile.write("\t\treturn Rules." + rule + "\n")
    tempFile.write("\treturn 'none'\n")

    # close and replace file
    ruleFile.close()
    tempFile.close()
    subprocess.call("mv rules.temp rules.py", shell=True)

    # reload the rules module because it has changed
    reload(rules)

    return rule
Ejemplo n.º 2
0
def buildArgument(conclusion):
    """
    builds an argument for the conclusion given. The conclusion should contain "filled" parameters,
    if it has any parameters.
    """
    
    ruleList = rules.getRules(conclusion)
    runRules = []
    
    #list of rules might be long, let's try to avoid killing too much memory
    for rule in ruleList:
        #print samples.initEnv
        try:
            if rule.canRun(conclusion):
                runRules.append(rule.run(conclusion))
        except KeyError:
            print 'still getting KeyErrors, I guess'
            """
            This fab error means we tried to do something with some data that the user didn't enter.
            We just silently fail for the moment. Frankly I think this is a much more elegant way to
            handle the issue I've been running into here.
            Also useful: later we can save these rules and use them to say something about what sort
            of new data might change our conclusions.
            """
            pass
    
    return arguments.Argument(conclusion, runRules)
    
    
Ejemplo n.º 3
0
		month = report[0].replace('m','')
		year = report[1].replace('y','')
		return datetime(int(year),int(month),calendar.monthrange(int(year),int(month))[1])
	if length == 3:
		[month, day, year] = report[2].split('/')
		return datetime(int(year),int(month),int(day))
	print "Invalid stop date. Exiting."
	sys.exit(1)

report = getType().split('-')
length = len(report)
f = open(rules.getPath()+'expenses.csv','r')
reader = csv.reader(f)
startDate = getStart(report,length)
stopDate = getStop(report,length)
ruleList = rules.getRules().split(',')
costList = [0] * len(ruleList)
itemList = ['']
sum = 0
category = raw_input("All or "+rules.getRules()+": ")

for line in reader:
	date = datetime.strptime(line[0], '%m/%d/%Y')
	if (date >= startDate and date <= stopDate):
		index = ruleList.index(line[-1])
		costList[index] = costList[index] + float(line[-2])
	if (category == line[3]):
		itemList.append(line)
itemList.remove('')
if (category == "All"):
	for i in range(0,len(ruleList)):