Adds rudementary networth graph

This commit is contained in:
Luís Murta 2021-12-01 18:41:07 +00:00
parent 59406c35c1
commit ab10a5834c
Signed by: satprog
GPG Key ID: DDF2EFC6179009DC
2 changed files with 47 additions and 1 deletions

View File

@ -177,3 +177,47 @@ def discrete(
plt.savefig("graph.png")
else:
plt.show()
def networth(
db: DBManager, args: dict, start: dt.date = dt.date.min, end: dt.date = dt.date.max
):
transactions = db.get_daterange(start, end)
start, end = transactions[0].date, transactions[-1].date
accum = 0
monthly_networth = tuple(
(
month,
accum := sum(
transaction.value
for transaction in transactions
if transaction.original != "No"
and transaction.category not in pfbudget.categories.groups["investment"]
and month
<= transaction.date
<= month + dt.timedelta(days=monthrange(month.year, month.month)[1] - 1)
) + accum
)
for month in [
month.date()
for month in rrule(
MONTHLY, dtstart=start.replace(day=1), until=end.replace(day=1)
)
]
)
plt.figure(tight_layout=True)
plt.plot(
list(rrule(MONTHLY, dtstart=start.replace(day=1), until=end.replace(day=1))),
[
value for _, value in monthly_networth
],
label="Total networth"
)
plt.grid()
plt.legend(loc="upper left")
if args["save"]:
plt.savefig("graph.png")
else:
plt.show()

View File

@ -123,7 +123,7 @@ def argparser() -> argparse.ArgumentParser:
p_graph.add_argument(
"option",
type=str,
choices=["monthly", "discrete"],
choices=["monthly", "discrete", "networth"],
nargs="?",
default="monthly",
help="graph option help",
@ -173,6 +173,8 @@ def graph(args):
pfbudget.graph.monthly(DBManager(args.database), vars(args), start, end)
elif args.option == "discrete":
pfbudget.graph.discrete(DBManager(args.database), vars(args), start, end)
elif args.option == "networth":
pfbudget.graph.networth(DBManager(args.database), vars(args), start, end)
def report(args):