class ModelFinance(Model): field_names = EssenceFinance.field_names + list([ "Account", "Category", "Subcategory", "SimplifiedAlias", "Year", "YearMonth", ]) # constructor def __init__(self, obj): #self.checkClass(obj, ModelFinance, EssenceFinance) self.accounts = Db_Accounts( '/data/proj/git/finance/run/in/BeyondBanking/Accounts_All.csv') Model.__init__(self, obj) # implementations of abstract methods def fieldNames(self): return self.field_names def sortBeforeTransform(self): return list([ 'Date', 'Amount' ]) # horizontally, expand from the essence def transform(self, essence_col, next_col): derived_col = dict(essence_col) derived_col['Year'] = \ Container.convertStandardDateToYear(essence_col['Date']) derived_col['YearMonth'] = \ Container.convertStandardDateToYearMonth(essence_col['Date']) derived_col['SimplifiedAlias'], \ derived_col['Account'], \ derived_col['Category'], \ derived_col['Subcategory'] = \ self.processAccountAlias(essence_col['AccountAlias']) return True, derived_col # helper def processAccountAlias(self, account_alias): simplified_alias = db.finance.helpers.Account.simplifyAlias(account_alias) account_title = self.accounts.getAccountTitle(account_alias) subcategory = self.accounts.getSubcategory(account_title) category = self.accounts.getCategory(account_title) return simplified_alias, account_title, category, subcategory
class ModelFinance(Model): field_names = EssenceFinance.field_names + list([ "Account", "Category", "Subcategory", "SimplifiedAlias", "Year", "YearMonth", ]) # constructor def __init__(self, obj): #self.checkClass(obj, ModelFinance, EssenceFinance) self.accounts = Db_Accounts( '/home/kurt/checked-out/apps/finance/svn-run/in/All/Accounts_All.csv') Model.__init__(self, obj) # implementations of abstract methods def fieldNames(self): return self.field_names def isSelectedRow(self, row): partial_first_month = Container.convertStandardDateToYearMonth(self.first_row['Date']) ignore_partial_first_month = (partial_first_month == row["YearMonth"]) return ( not (row["Category"] == "Banking" and row["Subcategory"] == "ML Internal Transfer") and not (row["Category"] == "Banking" and row["Subcategory"] == "Wire In") and not (row["Category"] == "Banking" and row["Subcategory"] == "Check Deposit" and row["Amount"] == "123,755.05") and not (row["Category"] == "Charitable Donations" and row["Subcategory"] == "Wire Out" and row["Amount"] == "-200,000.00") and not (row["Category"] == "Credit Card" and row["Subcategory"] == "Pay Credit Card" and row["Account"] == "Capital One") and not (row["Category"] == "Credit Card" and row["Subcategory"] == "Pay Credit Card" and row["Account"] == "Chase" and row["Date"] > "2013-07-19") and not ignore_partial_first_month ) return True def sortBeforeTransform(self): return list([ 'Date', 'Amount' ]) # horizontally, expand from the essence def transform(self, essence_col, next_col): derived_col = dict(essence_col) derived_col['Year'] = \ Container.convertStandardDateToYear(essence_col['Date']) derived_col['YearMonth'] = \ Container.convertStandardDateToYearMonth(essence_col['Date']) derived_col['SimplifiedAlias'], \ derived_col['Account'], \ derived_col['Category'], \ derived_col['Subcategory'] = \ self.processAccountAlias(essence_col['AccountAlias']) return True, derived_col # helper def processAccountAlias(self, account_alias): simplified_alias = db.finance.helpers.Account.simplifyAlias(account_alias) account_title = self.accounts.getAccountTitle(account_alias) subcategory = self.accounts.getSubcategory(account_title) category = self.accounts.getCategory(account_title) return simplified_alias, account_title, category, subcategory