async def spending(item: Item): """ Make visualizations based on past spending 📊 ### Request Body - `bank_account_id`: int - `graph_type`: str (pie or bar) - `time_period`: str (week, month, year, all) - `OPTIONAL: color_template`: [Color Template Options (Sequential only)](https://plotly.com/python/builtin-colorscales/#builtin-sequential-color-scales) - `OPTIONAL: hole`: float (0 - 1) ### Response - `plotly object`: visualizing the user's spending habits in the form of the selected graph type. """ # Get the JSON object from the request body and cast it to a dictionary input_dict = item.to_dict() bank_account_id = input_dict['bank_account_id'] graph_type = input_dict['graph_type'] time_period = input_dict['time_period'] color_template = input_dict['color_template'] hole = input_dict['hole'] transactions = load_user_data(bank_account_id) user = User(transactions, hole=hole) if graph_type == 'pie': return user.categorical_spending(time_period=time_period, color_template=color_template) if graph_type == 'bar': return user.bar_viz(time_period=time_period, color_template=color_template)