def test_sort_file_by_date(self): data = read_expense_file('../Data/VandV/ReadExpenses/Read_File.csv') sort_dataframe_by_date(data, '../Data/VandV/ReadExpenses/Read_File.csv', test=True) new_data = read_expense_file( '../Data/VandV/ReadExpenses/Read_FileTemp.csv') date = [ '2015-01-07', '2015-01-07', '2015-01-07', '2015-01-05', '2015-01-05', '2015-01-03', '2015-01-02', '2015-01-02', '2015-01-02', '2015-01-02', '2015-01-01' ] check_debit = [ 342.1, 981.0, 3185.0, 55.0, 75.0, 287.0, 64.8, 75.0, 1280.0, 245.0, 45.0 ] check_add = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] savings_debit = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] savings_add = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 75.0, 0.0, 0.0, 0.0] expense = [ 'State Taxes', 'Fed Taxes', 'Paycheck', 'Restaurant', 'Bar', 'Misc', 'Groceries', 'Transfer', 'Bills', 'Misc', 'Misc' ] descript = [ 'Income Tax', 'Income Tax', 'Paycheck', 'Dinner', 'None', 'Oil Change', 'Party', 'Savings Account', 'Rent', 'Camera', 'Jeans' ] self.assertTrue((date == new_data['Date']).all()) self.assertTrue((check_debit == new_data['Checking_Debit']).all()) self.assertTrue((check_add == new_data['Checking_Addition']).all()) self.assertTrue((savings_debit == new_data['Savings_Debit']).all()) self.assertTrue((savings_add == new_data['Savings_Addition']).all()) self.assertTrue((expense == new_data['Expense_Type']).all()) self.assertTrue((descript == new_data['Description']).all()) return
def test_exception_handling(self): try: read_expense_file('../Data/VandV/ReadExpenses/Exception.csv') self.assertEqual(1, 0) except SystemExit: self.assertEqual(1, 1) return
def draft_daily_log_file(checking_start, savings_start, expense_file_name, log_file, log_end_date): """ :param checking_start: float The starting amount in the checking account \ in dollars U.S. :param savings_start: float The starting amount in the savings account \ in dollars U.S. :param expense_file_name: char str The name of the expense file to include the \ relative or absolute path link :param log_file: char str The name of the log file to include the relative \ or absolute path length :param log_end_date: char str Today equates to current day, File equates to \ the last date in the expense file :return: NA This function organizes all of the function calls required to create a \ log file containing the value of the checking and savings account at every date between start_date and end_date. """ data = read_expense_file(expense_file_name) start_date = pd.to_datetime(min(data['Date'])).date() if log_end_date.upper() == 'TODAY': end_date = pd.to_datetime('today').date() else: end_date = max(data['Date']).date() daily_account_value(checking_start, savings_start, start_date, end_date, data, log_file) return
def tabulate_expense(file_name, expense_type, expense_keyword, start_date, end_date): data = read_expense_file(file_name) value = sum_expense(start_date, end_date, data, expense_keyword, expense_type) print('{}{}{}'.format(expense_keyword, ': ', round(value, 2))) return
def sum_account_values(start_date, end_date, expense_file): """ :param start_date: object Datetime object representing the start date \ (Year, Month, Day) :param end_date: object Datetime object represernting the end date \ (Year, Month, Day) :param expense_file: char str The name of the file containing expense information :return NA: """ data = read_expense_file(expense_file) data = data.set_index("Date") grouped = data.ix[end_date:start_date].groupby('Expense_Type').Checking_Debit.sum() + \ data.ix[end_date:start_date].groupby('Expense_Type').Checking_Addition.sum() print('=================================================') print('=================================================') print('=========== CHECKING ACCOUNT ==========') print('=================================================') print('=================================================') print(grouped) # grouped = data.ix[end_date:start_date].groupby('Expense_Type').Savings_Debit.sum() + \ # data.ix[end_date:start_date].groupby('Expense_Type').Savings_Addition.sum() # print('=================================================') # print('=================================================') # print('=========== SAVINGS ACCOUNT ===========') # print('=================================================') # print('=================================================') # print(grouped) return
def test_daily_log(self): check_start = 8500.0 savings_start = 4000.0 start_date = pd.to_datetime('2015-1-1').date() end_date = pd.to_datetime('2015-1-7').date() data = read_expense_file('../Data/VandV/ReadExpenses/Read_File.csv') daily_account_value(check_start, savings_start, start_date, end_date, data, '../Data/VandV/ReadExpenses/Log_File.csv')
def vendor_expenses(expense_file, start_date, end_date): data = read_expense_file(expense_file) data = data.set_index("Date") grouped = data.ix[end_date:start_date].groupby('Vendor').Checking_Debit.sum() + \ data.ix[end_date:start_date].groupby('Vendor').Checking_Addition.sum() print('=================================================') print('=================================================') print('=========== CHECKING ACCOUNT ==========') print('=================================================') print('=================================================') print(grouped) return
def organize_expense_file_by_date(file_name): """ :param file_name: char str the name of the expense file to include the \ relative or absolute path length :return: NA This function organizes all function calls required to sort and re-write \ the expense file by date """ data = read_expense_file(file_name) sort_dataframe_by_date(data, file_name) return
def create_histogram_tables(expense_file, histogram_directory, hist_end_date): """ :param expense_file: char str The name of the file containing expense information :param histogram_directory: char str The name of the directory containing histogram \ information :param hist_end_date: char str 'Today' or 'File' :return NA: """ data = read_expense_file(expense_file) start_date = min(data['Date']).date() if hist_end_date.upper() == 'TODAY': end_date = pd.to_datetime('today').date() else: end_date = max(data['Date']).date() info = [] bar_expense = histogram_values(start_date, end_date, data, 'Bar') groceries_expense = histogram_values(start_date, end_date, data, 'Groceries') restaurant_expense = histogram_values(start_date, end_date, data, 'Restaurant') misc_expense = histogram_values(start_date, end_date, data, 'Misc') gas_expense, date = histogram_values(start_date, end_date, data, 'Gas') information = { 'Date': date, 'Bar': bar_expense[0], 'Groceries': groceries_expense[0], 'Restaurant': restaurant_expense[0], 'Misc': misc_expense[0], 'Gas': gas_expense } df = pd.DataFrame(data=information) df = df.set_index("Date") df = df[::-1] df.to_csv(histogram_directory + 'HistFile.csv') return
def test_file_reader(self): data = read_expense_file('../Data/VandV/ReadExpenses/Read_File.csv') dates = [ '2015-01-05', '2015-01-01', '2015-01-02', '2015-01-02', '2015-01-02', '2015-01-05', '2015-01-03', '2015-01-07', '2015-01-07', '2015-01-07', '2015-01-02' ] check_debit = [ 75.00, 45.00, 245.00, 1280.00, 75.00, 55.00, 287.00, 3185.0, 981.00, 342.10, 64.80 ] check_add = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] savings_debit = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] savings_add = [0.0, 0.0, 0.0, 0.0, 75.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] exp_type = [ 'Bar', 'Misc', 'Misc', 'Bills', 'Transfer', 'Restaurant', 'Misc', 'Paycheck', 'Fed Taxes', 'State Taxes', 'Groceries' ] vendor = [ 'The Pub', 'JC Penny', 'Amazon', 'Apartment Complex', 'Checking to Savings', 'Olive Garden', 'Car Dealer', 'My Company', 'Federal Income Tax', 'Utah State Income Tax', 'Fresh Market' ] descript = [ 'None', 'Jeans', 'Camera', 'Rent', 'Savings Account', 'Dinner', 'Oil Change', 'Paycheck', 'Income Tax', 'Income Tax', 'Party' ] self.assertTrue((dates == data['Date']).all()) self.assertTrue((check_debit == data['Checking_Debit']).all()) self.assertTrue((check_add == data['Checking_Addition']).all()) self.assertTrue((savings_debit == data['Savings_Debit']).all()) self.assertTrue((savings_add == data['Savings_Addition']).all()) self.assertTrue((exp_type == data['Expense_Type']).all()) self.assertTrue((vendor == data['Vendor']).all()) self.assertTrue((descript == data['Description']).all())