From dc6d1d0b0275a804677d76154b84d37df97ab469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Murta?= Date: Sun, 4 Jul 2021 00:36:27 +0100 Subject: [PATCH] Add groups to categories in YAML Groups will later be used to aggregate categories into related groups to present graphs and reports by type of categories. --- categories.yaml | 11 +++++++++++ pfbudget/categories.py | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/categories.yaml b/categories.yaml index a66fe56..f69bf74 100644 --- a/categories.yaml +++ b/categories.yaml @@ -1,24 +1,29 @@ Income1: + group: income regex: - company A Income2: + group: income regex: - transfer banks: - BankA Income3: + group: income regex: - company B Commute: + group: required regex: - uber regular: - [train, 50] Utilities: + group: fixed regex: - electricity regular: @@ -26,24 +31,29 @@ Utilities: - [internet, 30.5] Groceries: + group: required regex: - lidl - e.leclerc - aldi Eating Out: + group: discretionary regex: - restaurant 1 - restaurant 2 Entertainment: + group: discretionary regex: - cinema - steam Pets: + group: required Medical: + group: health regex: - hospital - pharmacy @@ -51,6 +61,7 @@ Medical: Miscellaneous: Travel: + group: discretionary regex: - ryanair - easyjet diff --git a/pfbudget/categories.py b/pfbudget/categories.py index e5aa424..58421bf 100644 --- a/pfbudget/categories.py +++ b/pfbudget/categories.py @@ -15,6 +15,7 @@ if TYPE_CHECKING: Options = namedtuple( "Options", [ + "group", "regex", "banks", "regular", @@ -23,11 +24,17 @@ Options = namedtuple( "vacations", "timedelta", ], - defaults=[[], [], [], [], "", [], 4], + defaults=["", [], [], [], [], "", [], 4], ) cfg = yaml.safe_load(open("categories.yaml")) categories = {k: Options(**v) if v else Options() for k, v in cfg.items()} +groups = { + group: [ + category for category, options in categories.items() if options.group == group + ] + for group in set(category.group for category in categories.values()) +} categories["Null"] = Options()