async def future_budget(budget: Budget): """ Suggest a budget for a specified user. ### Request Body - `bank_account_id`: int - `monthly_savings_goal`: integer ### Response - `category`: grandparent category name - `budgeted_amount`: integer suggesting the maximum the user should spend in that catgory next month """ # Get the JSON object from the request body and cast it to a dictionary input_dict = budget.to_dict() bank_account_id = input_dict['bank_account_id'] monthly_savings_goal = input_dict['monthly_savings_goal'] transactions = load_user_data(bank_account_id) # instantiate the user and chooses category column # user = User(transactions, cat_column='grandparent_category_name') # user = User(transactions, cat_column='parent_category_name') user = User(transactions, cat_column='merchant_name') # predict budget using time series model pred_bud = user.predict_budget() # if a fatal error was encountered while generating the budget, # return no budget along with the warning list if user.warning == 2: return json.dumps([None, user.warning_list]) # modify budget based on savings goal modified_budget = user.budget_modifier( pred_bud, monthly_savings_goal=monthly_savings_goal) # if a fatal error was encountered while modifying the budget, # return no budget along with the warning list if user.warning == 2: return json.dumps([None, user.warning_list]) # if a non-fatal warning was encountered in predict_budget() or # budget_modifier(), return the budget along with the warning list elif user.warning == 1: return json.dumps([modified_budget, user.warning_list]) return modified_budget