def pretty_print_items(self, items, title=None): logging.debug(items) if type(items) == str: data = pd.io.json.json_normalize(json.loads(items)) elif type(items) is list: data = mongoHelper.list_mongo_to_pandas(items) elif type(items) is pd.DataFrame: data = items else: raise NotImplementedError( f"Unhandled printable object {type(items)}") """ Convert Dates""" if 'date_stamp' in data.columns: data['date_stamp'] = pd.to_datetime(data['date_stamp'], unit='ms') if 'date' in data.columns: data['date'] = pd.to_datetime(data['date'], unit='ms') if 'date_stamp.$date' in data.columns: data['date_stamp.$date'] = pd.to_datetime(data['date_stamp.$date'], unit='ms') if title is None: title = "" else: title = title + "\n" print(f"{title}# of items {len(data)}") if len(data) > 0: pandasHelper.pretty_print_dataframe(data)
def print_waterfall_buckets(self, account: Account = None): account = account if account else self.uns.select_account() buckets = dsvca.buckets_by_account(account) data = mongoHelper.list_mongo_to_pandas(buckets) data.sort_values(by=["priority", 'due_day_of_month'], inplace=True) self.uns.pretty_print_items(data)
def positive_remaining_buckets(self, account: Account=None, amount_threshold: float = None): account = account if account else self.uns.select_account() buckets = dsvca.buckets_by_account(account) data = mongoHelper.list_mongo_to_pandas(buckets) filtered = data[data["saved_amount"] > 0].sort_values(by=["priority"]) if amount_threshold is not None: filtered = filtered[filtered['saved_amount']>amount_threshold] return filtered
def save_buckets_as_csv(self, account: Account = None): account = account if account else self.uns.select_account() buckets = dsvca.buckets_by_account(account) data = mongoHelper.list_mongo_to_pandas(buckets) filepath = self.uns.request_save_filepath() data.to_csv(filepath) if data is None: return self.uns.notify_user(f"Buckets data written successfully to {filepath}")
def print_waterfall_summary(self, account: Account = None): account = account if account else self.uns.select_account() buckets = dsvca.buckets_by_account(account) data = mongoHelper.list_mongo_to_pandas(buckets) waterfall_amount = data['waterfall_amount'].sum() saved_amount = data['saved_amount'].sum() total_saved = waterfall_amount + saved_amount self.uns.notify_user(f"\n------Waterfall Summary------\n" f"Total Balance: ${round(total_saved, 2)}\n" f"Saved for next cycle: S{round(saved_amount, 2)}", delay_sec=0)