def main(): expenses = [ Expense("Coffee", 2.45, 1), Expense("Gas", 20, 4), Expense("Lunch", 6.59, 1, spread=(0, 4)) ] #start pyplot fig = plt.figure() ax = plt.axes() days = np.linspace(0, 14, 15) totalCost = 0 totalCostPlot = [] #y's of the total cost at a particular point in time for d in days: for e in expenses: #go through every expense we listed if d % e.rate == 0: #if its time to add another purchase if e.spread != (0, 0): randValue = random.uniform( -e.spread[0], e.spread[1]) #calculate the variance in the purchase else: randValue = 0 totalCost += (e.cost + randValue) e.cumCost += (e.cost + randValue) e.count += 1 e.plot.append(e.cumCost) totalCostPlot.append(totalCost) plt.plot(days, totalCostPlot, label="Total Expenses", color="black") #plot expenses for e in expenses: plt.plot(days, e.plot, label=(e.name + ": $" + str(e.cost) + " ±\$(" + str(e.spread[0]) + ", " + str(e.spread[1]) + ") every ~" + str(e.rate) + " days")) #ticks plt.xticks(days) ax.yaxis.set_major_formatter(tick.StrMethodFormatter( '${x:,.0f}')) #add the dollar signs to the y axis ax.legend() #labels plt.title("The cost of your actions") plt.xlabel("Days") plt.ylabel("Cash Outflow (USD)") plt.show()
def main(): myBudgeList = BudgeList(budget=1200) # S9 expenses = Expense.Expenses() expenses.read_expenses('data/spending_data.csv') # S10 for expense in expenses.list: myBudgeList.append(expense.amount) # S11 print('The count of all expenses: ' + str(len(myBudgeList)))
def main(): myBudgetList = BudgetList(1200) expenses = Expense.Expenses() expenses.read_expenses('../data/spending_data.csv') for expense in expenses.list: myBudgetList.append(expense.amount) print('The count of all expenses: ' + str(len(myBudgetList))) for entry in myBudgetList: print(entry) fig, ax = plt.subplots() labels = ['Expenses', 'Overages', 'Budget'] values = [ myBudgetList.sum_expenses, myBudgetList.sum_overages, myBudgetList.budget ] ax.bar(labels, values, color=['green', 'red', 'blue']) ax.set_title('Your total expenses vs. total budget') plt.show()
def main(): expenses = Expense.Expenses() expenses.read_expenses('data/spending_data.csv') divided_for_loop = expenses.categorize_for_loop() divided_set_comp = expenses.categorize_set_comprehension() if divided_set_comp != divided_for_loop: print('Sets are NOT equal by == test') for a, b in zip(divided_for_loop, divided_set_comp): if not (a.issubset(b) and b.issubset(a)): print("Sets are NOT equal by subset test") print( timeit.timeit(stmt="expenses.categorize_for_loop()", setup=''' import Expense expenses = Expense.Expenses() expenses.read_expenses('data/spending_data.csv') ''', number=100000, globals=globals())) print( timeit.timeit(stmt="expenses.categorize_set_comprehension()", setup=''' import Expense expenses = Expense.Expenses() expenses.read_expenses('data/spending_data.csv') ''', number=100000, globals=globals())) fig, ax = plt.subplots() labels = ['Necessary', 'Food', 'Unnecessary'] divided_expenses_sum = [] for category_exps in divided_set_comp: divided_expenses_sum.append(sum(x.amount for x in category_exps)) ax.pie(divided_expenses_sum, labels=labels, autopct='%1.1f%%') plt.show()
import Expense import collections import matplotlib.pyplot as plt #keep in right dict. expenses = Expense.Expenses() expenses.read_expenses('data/spending_data.csv') spending_categories = [] for expense in expenses.list: spending_categories.append(expense.category) spending_counter = collections.Counter(spending_categories) top5 = spending_counter.most_common(5) categories, count = zip(*top5) fix, ax = plt.subplots() ax.bar(categories, count) ax.set_title("# of Purchases by Category") plt.show()
def record(self): self.expense = Expense(self.date, self.amount, self.perGallon, self.location, self.details)
exit() def read_file(temp_file): """Read file and turn to list of lists""" line_string = "" for line in temp_file: line_string += line return line_string file_to_string = read_file(temp_file) # Call function to create string file_to_string = '{' + file_to_string + '}' # add brackets for dict conversion string_to_dictionary = eval(file_to_string) # Convert to dictionary temp_file.close() # Close File # Instantiate person and expense object expense = Expense(**string_to_dictionary) person = Person(first, last, age, income, tax_rate) # Print Name and Age print('\n') print("Here's a summary of your financial picture and expenses") print('\n') name_age_dictionary = person.name_age_display() print('Your Name & Age:') for key, value in name_age_dictionary.items(): print(key, ':', value) # Private method call - Print Income, Tax Rate, and After Tax Income income_tax_dictionary = person._Person__income_tax_display() print('Your Income, Tax Rate, and estimated after-Tax Income:') for key, value in income_tax_dictionary.items():