system-design-primer/solutions/system_design/mint/mint_snippets.py

51 lines
1.4 KiB
Python
Raw Normal View History

2017-03-05 08:05:31 +03:00
# -*- coding: utf-8 -*-
2018-05-07 04:26:01 +03:00
from enum import Enum
2021-03-14 13:08:05 +03:00
class DefaultCategories(Enum) :
2017-03-05 08:05:31 +03:00
HOUSING = 0
FOOD = 1
GAS = 2
SHOPPING = 3
2018-05-07 04:26:01 +03:00
# ...
2017-03-05 08:05:31 +03:00
seller_category_map = {}
seller_category_map['Exxon'] = DefaultCategories.GAS
seller_category_map['Target'] = DefaultCategories.SHOPPING
2021-03-14 13:08:05 +03:00
class Categorizer(object) :
2017-03-05 08:05:31 +03:00
2021-03-14 13:08:05 +03:00
def __init__(self, seller_category_map, seller_category_overrides_map) :
2017-03-05 08:05:31 +03:00
self.seller_category_map = seller_category_map
self.seller_category_overrides_map = seller_category_overrides_map
2021-03-14 13:08:05 +03:00
def categorize(self, transaction) :
2017-03-05 08:05:31 +03:00
if transaction.seller in self.seller_category_map:
return self.seller_category_map[transaction.seller]
if transaction.seller in self.seller_category_overrides_map:
seller_category_map[transaction.seller] = \
2021-03-14 13:08:05 +03:00
self.manual_overrides[transaction.seller].peek_min()
2017-03-05 08:05:31 +03:00
return self.seller_category_map[transaction.seller]
return None
2021-03-14 13:08:05 +03:00
class Transaction(object) :
2017-03-05 08:05:31 +03:00
2021-03-14 13:08:05 +03:00
def __init__(self, timestamp, seller, amount) :
2017-03-05 08:05:31 +03:00
self.timestamp = timestamp
self.seller = seller
self.amount = amount
2021-03-14 13:08:05 +03:00
class Budget(object) :
2017-03-05 08:05:31 +03:00
2021-03-14 13:08:05 +03:00
def __init__(self, template_categories_to_budget_map) :
2017-03-05 08:05:31 +03:00
self.categories_to_budget_map = template_categories_to_budget_map
2021-03-14 13:08:05 +03:00
def override_category_budget(self, category, amount) :
2017-03-05 08:05:31 +03:00
self.categories_to_budget_map[category] = amount