Adds rudementary networth graph
This commit is contained in:
parent
59406c35c1
commit
ab10a5834c
@ -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()
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user