def main(): food, clothing, entertainment = 0, 0, 0 budget = Budget(food, clothing, entertainment) performOperation = 'Y' while (performOperation == 'Y') or (performOperation == 'y'): print("What would you like to do?\n") print("1. Make deposit\n") print("2. Make withdrawals\n") print("3. Check balance\n") print("4. Transfer inter-budgets\n") option = input("Select from the above\n") if option == '1': amount = int(input("How much would you like to deposit? \n")) budget.deposit(amount) elif option == '2': amount = int(input("How much would you like to withdraw? \n")) budget.withdraw(amount) elif option == '3': budget.balance() elif option == '4': budget.transferBalance() else: print("You have entered an invalid input.") performOperation = input( "Wanna perform another operation? Enter Y for YES or any other character for NO\n" )
async def users_create_budget( pb_identifier=Form(...), category=Form(...), amount=Form(...), budget_type=Form(...), current_user: User = Depends(get_current_user), ): """ form for creating a new budget alternatively can use default param current user instead of using the pb_identifier """ try: new_budget = Budget(pb_identifier=pb_identifier, category=category, amount=amount, budget_type=budget_type) new_budget.create_budget() result_msg = { "status": "success", "message": "successfully created budget" } except: # errors include validation errors as well as db errors # check budget file result_msg = {"status": "error", "message": "failed to create budget"} return result_msg
def load_test_user(): """ Used to create Fam user for testing :return: """ games_budget = Budget("Games and Entertainment", 100) clothes_budget = Budget("Clothing and Accessories", 100) food_budget = Budget("Eating out", 100) misc_budget = Budget("Miscellaneous", 100) budgets = [games_budget, clothes_budget, food_budget, misc_budget] return Rebel("Ryan", 11, 2314, "TD", 1234, budgets)
def load_test_user(self): """ Creates a test user with budgets and a moderator to deal with the user. Applies moderator to instance variable. """ ba = BankAccount("Account number here", "Bank name there", 400) user = User("Nick McGrath", date(1996, 4, 9), ba, **UserTypes.REBEL.value) self.user = user self.budgets[BudgetTypes.GAMES_AND_ENTERTAINMENT] = Budget(100) self.budgets[BudgetTypes.MISCELLANEOUS] = Budget(100) self.budgets[BudgetTypes.EATING_OUT] = Budget(100) self.budgets[BudgetTypes.CLOTHING_AND_ACCESSORIES] = Budget(100)
def load_test_user(): """ Creates a test user with pre-set values to test the program's methods with :return: test user with assigned values """ test_bank_info = BankInfo("RBC", "12345678", "5000.00") budget1 = Budget("Games and Entertainment", 1000.00) budget2 = Budget("Clothing and Accessories", 1000.00) budget3 = Budget("Eating Out", 1000.00) budget4 = Budget("Misc.", 1000.00) test_budget_list = [budget1, budget2, budget3, budget4] test_user = User("John Doe", "20", test_bank_info, test_budget_list) return test_user
def load_user(self): """ Prompt user for information needed to create a user then create and set budgets. """ while True: try: print('Welcome! Please create a user!') # collect the info needed to create a User user_values = [] user_values.append(input('Name: ')) print('Date of birth (using integer values):') user_values.append(date(int(input('\tYear: ')), int(input( '\tMonth: ')), int(input('\tDay: ')))) bank_values = [] bank_values.append(input('Bank Account number: ')) bank_values.append(input('Bank Name: ')) bank_values.append(float(input('Bank Balance: '))) ba = BankAccount(*bank_values) user_values.append(ba) print('Type of account?') print('Angel') print('Trouble Maker') print('Rebel') user_type = UserTypes[input('Account type: ').replace(' ', '_').upper()].value # create and set the user in the moderator self.user = User(*user_values, **user_type) # set the budget dictionary in the user self.budgets[BudgetTypes.GAMES_AND_ENTERTAINMENT] = Budget(int( input( 'Budget for Games and Entertainment: '))) self.budgets[BudgetTypes.MISCELLANEOUS] = Budget( int(input('Budget for Miscellaneous: '))) self.budgets[BudgetTypes.EATING_OUT] = Budget( int(input('Budget for ' 'Eating out: '))) self.budgets[BudgetTypes.CLOTHING_AND_ACCESSORIES] = Budget( int(input( 'Budget for Clothing and Accessories: '))) except ValueError: print('Try again :) (bad value)') continue else: break
def __init__(self, username, password, email, id): self.__id = id self.__username = username self.__password = password self.__email = email self.budget = Budget() self.networth = Networth()
def test_insert_transactions_inserts(self): """Test that insert_transactions can insert data""" title_id = Budget(config='tests/test_config.yaml').insert_transactions( transactionfile='tests/test_transactions.txt') self.assertEqual( title_id, *self.run_query("SELECT id FROM title WHERE name='MING EXPRESS';"))
def test_budget_items(self, complex_item_dict): budget = Budget.from_item_dict(complex_item_dict) daily = budget.compute_daily_plan() assert len(daily.days.keys()) == 9 long_day = daily.days[date.fromisoformat('2019-01-01')] assert len(long_day.budget.items) == 4 assert long_day.budget.maximum == Decimal(7) before_next_change = daily.days[date.fromisoformat('2019-01-04')] assert before_next_change.budget.maximum == Decimal(7) change_day = daily.days[date.fromisoformat('2019-01-05')] assert len(change_day.budget.items) == 1 assert change_day.budget.maximum == Decimal(2) pause_day = daily.days[date.fromisoformat('2019-01-06')] assert pause_day.budget.maximum == Decimal(0) before_last = daily.days[date.fromisoformat('2019-01-08')] assert before_last.budget.maximum == Decimal(0) last_day = daily.days[date.fromisoformat('2019-01-09')] assert last_day.budget.maximum == Decimal('100.5') jan_budget = daily.months['2019-01']['budget'] assert jan_budget == Decimal('130.5')
def test_budget_init(self): budget_budget = Budget(mock_budget_base) budget_budget.items.append(mock_item_base) self.assertNotEqual(len(budget_budget.items), len(mock_budget_base.items)) budget_budget.warnings[0.5] = 'red' self.assertNotEqual(len(budget_budget.warnings), len(mock_budget_base.warnings))
def run_simulation(): response = { 'status': 'success' } budget = Budget.from_item_dict( format_budget() ) sim = Simulator(budget) sim.generate_costs() response['simulation'] = sim.get_summary() return jsonify(response)
def __init__(self, name, age, bank_account_number, bank_name, bank_bal, budgets, user_type): self._name = name self._age = age self._bank_account_number = bank_account_number self._bank_name = bank_name self._bank_bal = bank_bal self._warning_limit = 0 self._lockout_limit = 0 self._budgets = budgets self._user_type = user_type self._user_types = UserTypes(user_type) self._transaction_records = TransactionRecords() self._budgets = Budget(budgets, self._user_types.get_lockout_limit(), self._user_types.get_warning_limit())
def __getBudgetByName(soup, budget_name): budget_container_id = f"{budget_name}Budget-list-body" budget_container = soup.find("ul", {"id": budget_container_id}) budgets = budget_container.findAll("li") return_budgets = [] for budget in budgets: return_budgets.append(Budget(budget)) return return_budgets
def test_decimal(self, basic_item_dict): budget = Budget.from_item_dict(basic_item_dict) some_money = Decimal('7') assert some_money in budget.items.values() big_money = Decimal('100.5') assert big_money in budget.items.values() zero_money = Decimal('0') assert zero_money in budget.items.values()
def test_daily_limits(self, complex_item_dict): budget = Budget.from_item_dict(complex_item_dict) daily = budget.compute_daily_plan() daily_limit = daily.get_daily_limit( datetime.fromisoformat('2019-01-05T08:00:00')) assert daily_limit == Decimal('14') daily_limit = daily.get_daily_limit( datetime.fromisoformat('2019-01-05T13:00:00')) assert daily_limit == Decimal('4')
class User: def __init__(self, name, age, bank_account_number, bank_name, bank_bal, budgets, user_type): self._name = name self._age = age self._bank_account_number = bank_account_number self._bank_name = bank_name self._bank_bal = bank_bal self._warning_limit = 0 self._lockout_limit = 0 self._budgets = budgets self._user_type = user_type self._user_types = UserTypes(user_type) self._transaction_records = TransactionRecords() self._budgets = Budget(budgets, self._user_types.get_lockout_limit(), self._user_types.get_warning_limit()) def add_transaction_record(self, time, amount, budget_cat, name): self._transaction_records.add_record(time, amount, budget_cat, name) def get_transaction_record(self): return self._transaction_records def print_all_transactions(self): self._transaction_records.print_all_records() def notify_user(self, budget_cat): if self._budgets.check_notify(budget_cat): self._user_types.notify_user() def warn_user(self, budget_cat): if self._budgets.check_warning(budget_cat): self._user_types.notify_user() def get_budget(self): return self._budgets def get_bank_bal(self): return self._bank_bal def subtract_bank_bal(self, amount): self._bank_bal -= amount def check_warning(self, budget_cat): self._budgets.check_warning(budget_cat) def get_name(self): return self._name def view_budget(self): self._budgets.view_budget() def view_bank_details(self): print(f"\nBank account Number: {self._bank_account_number}\n" f"Bank name: {self._bank_name}\n" f"Bank bal: {self._bank_bal}")
def testReset(self): myBudget = Budget("Monthly Moolah", 1000) expected = 1000 myBudget.lowerFunds(100) myBudget.reset() actual = myBudget.getRemaining() self.assertEqual(expected, actual)
class User(): def __init__(self, login, password): self.login = str(login) self.password = str(password) self.budzet = Budget() def change_password(self, password): password = str(password) if password == self.password: raise ValueError('Nowe hasło nie może być takie same!') else: self.password = password def show_budget(self): return self.budzet.plan_budget() + '\n' + self.budzet.real_budget() def clear_budget(self): self.budzet = Budget() def show_trans(self): return self.budzet.show_transactions() def add_inc(self, category, t, amount, day): return self.budzet.add_income(category, t, amount, day) def add_exp(self, category, t, amount, day): return self.budzet.add_expense(category, t, amount, day) def show_warnings(self): return self.budzet.warnings()
def test_monthly_limits(self, complex_item_dict): budget = Budget.from_item_dict(complex_item_dict) daily = budget.compute_daily_plan() monthly_limit = daily.get_monthly_limit( date.fromisoformat('2019-01-09')) assert monthly_limit == Decimal('130.5') daily.add_monthly_cost(datetime.fromisoformat('2019-01-09T00:00:00'), Decimal('30.5')) monthly_limit = daily.get_monthly_limit( date.fromisoformat('2019-01-09')) assert monthly_limit == Decimal('100')
def transfer_balance(budget_categories): try: index1 = int( input( "Enter the category number of the category to transfer from: ") ) index2 = int( input( "Enter the category number of the category to transfer to: ")) amount = float(input("Enter the amount to transfer: ")) except: print("\nInvalid input!! Enter a valid number or amount") reduce_planned_expense(budget_categories) if index1 in range(1, len(budget_categories) + 1) and index2 in range( 1, len(budget_categories) + 1): Budget.transfer_balance(budget_categories[index1 - 1], budget_categories[index2 - 1], amount) init(budget_categories) else: print("\nInvalid input!! Enter a valid number") reduce_planned_expense(budget_categories)
def init(self): self._splash_screen = arcade.load_texture("images/logo.png") self._budget = Budget() self._audience_share = AudienceShare() self._on_screen_question = Question() self._questions_pool = QuestionsPool(*questions_data) self._questions_stages = QuestionsStages() self._background_controller = BackgroundController() self._current_contestant = random.choice(type(self).POSSIBLE_CONTESTANTS) self._popup_message = PopupMessage() self._sound_controller = SoundController() self._sound_controller.play_theme_in_loop() self._background_controller.set_index(self.current_contestant.bg_images_index) self.question_pool.show() self._popup_message.show(on_continue_callback=self._popup_next_contestant_callback) add_timer(3, self._after_splash_screen)
from budget import Budget # instantiate the class budget = Budget('food') clothing_budget = Budget('clothing') budget.deposit_funds(110, "deposit to food category") clothing_budget.deposit_funds(110) clothing_budget.withdraw_funds(10) print(budget.amount) print(clothing_budget.amount)
# -*- coding: utf-8 -*- from taxes import ISS, ICMS, ICPP, IKCV class CalculatorTaxes(object): def calculates(self, budget, taxe): print(round(taxe.calc(budget), 2)) if __name__ == '__main__': from budget import Budget, Item # Budget One budget = Budget() budget.add_item(Item('Product 1', 10)) budget.add_item(Item('Product 2', 5)) budget.add_item(Item('Product 3', 4)) budget.add_item(Item('Product 4', 4)) budget.add_item(Item('Product 5', 4)) budget.add_item(Item('Product 6', 1)) # Calculator Taxes calculator = CalculatorTaxes() print('ISS and ICMS') calculator.calculates(budget, ISS()) calculator.calculates(budget, ICMS()) print('ISPP and IKCV')
def testInitAmount(self): myBudget = Budget("Monthly Moolah", 1000) expected = 1000 actual = myBudget.getRemaining() self.assertEqual(expected, actual)
def test_date_span(self, date_dict): budget = Budget.from_item_dict(date_dict) date_span = budget.get_dates() assert (len(date_span) == 31)
def add_category(): response = input("Enter the Category Name: ") category = Budget(f"{response.title()}") categories.append(category)
def testBudgetName(self): myBudget = Budget("Monthly Moolah", 1000) expected = "Monthly Moolah" actual = myBudget.getName() self.assertEqual(expected, actual)
"Enter the category number of the category to transfer to: ")) amount = float(input("Enter the amount to transfer: ")) except: print("\nInvalid input!! Enter a valid number or amount") reduce_planned_expense(budget_categories) if index1 in range(1, len(budget_categories) + 1) and index2 in range( 1, len(budget_categories) + 1): Budget.transfer_balance(budget_categories[index1 - 1], budget_categories[index2 - 1], amount) init(budget_categories) else: print("\nInvalid input!! Enter a valid number") reduce_planned_expense(budget_categories) if __name__ == "__main__": food = Budget("Food") categories.append(food) clothing = Budget("Clothing") categories.append(clothing) entertainment = Budget("Entertainment") categories.append(entertainment) init(categories)
def test_item_date_filter(self, many_items_per_day, date_item_count): budget = Budget.from_item_dict(many_items_per_day) for budget_date, item_count in date_item_count.items(): items = budget.get_items_by_date(date.fromisoformat(budget_date)) assert len(items.keys()) == item_count
from discounts import * class Discount_calculator(object): def calculate(self, budget): discount = Discount_per_five_items( Discount_per_more_then_five_hundred_reais( Without_discount())).Calculate(budget) return discount if __name__ == '__main__': from budget import Budget, Item budget = Budget() budget.add_item(Item('Item - 1', 50)) budget.add_item(Item('Item - 2', 100)) budget.add_item(Item('Item - 3', 500)) print('Value without discount', budget.value) calculator = Discount_calculator() discount = calculator.calculate(budget) final_value = budget.value - discount print('Value with discount: ', discount)
# Routes app.add_url_rule('/', view_func=Main.as_view('main'), methods=['GET']) app.add_url_rule('/<page>/', view_func=Main.as_view('main1'), methods=['GET']) app.add_url_rule('/login/', view_func=Login.as_view('login'), methods=['GET', 'POST']) app.add_url_rule('/remote/', view_func=Remote.as_view('remote'), methods=['GET', 'POST']) app.add_url_rule('/budget/', view_func=Budget.as_view('budget'), methods=['GET', 'POST']) app.add_url_rule('/music/', view_func=Music.as_view('music'), methods=['GET']) @app.errorhandler(404) def page_not_found(error): return flask.render_template('404.html'), 404 app.debug = True app.run()
import random import validation from budget import Budget from getpass import getpass database = {} #dictionary for the details of the customer customer = Budget() def init(): print("Welcome to Kiitan's Bank") haveAccount = int(input("Do you have an account with us? 1. (Yes) 2. (No)\n")) if haveAccount == 1: login() elif haveAccount == 2: register() else: print("You have selected an invalid option. ") init() def login(): print("******* LOGIN ******") userAccountNumber = int(input("What is your account number? \n")) #print(database[userAccountNumber]) #password = input("What is your password? \n") isValidAccounntNumber = validation.account_number_validation (userAccountNumber) #print(isValidAccounntNumber) if isValidAccounntNumber:
# -*- coding: utf-8 -*- from taxes import ISS, ICMS, ICPP, IKCV class CalculatorTaxes(object): def calculates(self, budget, taxe): return taxe.calc(budget) if __name__ == '__main__': from budget import Budget, Item # Budget One budget = Budget('Budget One') budget.add_item(Item('Product 1', 10)) budget.add_item(Item('Product 2', 5)) budget.add_item(Item('Product 3', 4)) budget.add_item(Item('Product 4', 4)) budget.add_item(Item('Product 5', 4)) budget.add_item(Item('Product 6', 1)) # Calculator Taxes calculator = CalculatorTaxes() print('Budget: %s | Total of items: %s' % (budget.name, budget.total_items)) print('ISS: %s' % round(calculator.calculates(budget, ISS()), 2)) print('ICMS: %s' % round(calculator.calculates(budget, ICMS()), 2))
from budget import Budget food = Budget() clothing = Budget() entertainment = Budget() food.deposit(500) clothing.deposit(600) entertainment.deposit(1000) food.withdraw(300) clothing.withdraw(800) entertainment.withdraw(800) print("Balance after withdrawing") print(food.balance) print(clothing.balance) print(entertainment.balance) print("Balance after transferring") food.acceptTransfer(clothing.makeTransfer(300)) entertainment.acceptTransfer(food.makeTransfer(200)) print(food.balance) print(clothing.balance) print(entertainment.balance)
# Designer patterns # Strategy from budget import Budget from taxes import ISS, ICMS class Calculator_taxes: def calc_taxes(self, budget, tax): calculated_tax = tax.calc(budget) print(calculated_tax) if __name__ == '__main__': calc = Calculator_taxes() budget = Budget(100) calc.calc_taxes(budget, ISS()) calc.calc_taxes(budget, ICMS())