使用机器学习功能增加beancount导入程序。
smart-importer的Python项目详细描述
增强 Beancount进口商 具有机器学习功能。
安装
尚未在pypi上发布smart_importer包 因此必须从源安装:
git clone https://github.com/beancount/smart_importer.git pip install --editable smart_importer
快速启动
此包提供可以修改导入项的导入挂钩。什么时候? 运行进口商,现有条目将被用作训练数据。 机器学习模型,然后预测条目属性。
下面的示例演示如何将PredictPostingshook应用于 现有CSV进口商:
frombeancount.ingest.importersimportcsvfrombeancount.ingest.importers.csvimportColfromsmart_importerimportapply_hooks,PredictPostingsclassMyBankImporter(csv.Importer):'''Conventional importer for MyBank'''def__init__(self,*,account):super().__init__({Col.DATE:'Date',Col.PAYEE:'Transaction Details',Col.AMOUNT_DEBIT:'Funds Out',Col.AMOUNT_CREDIT:'Funds In'},account,'EUR',['Filename: .*MyBank.*\.csv','Contents:\n.*Date, Transaction Details, Funds Out, Funds In'])CONFIG=[apply_hooks(MyBankImporter(account='Assets:MyBank:MyAccount'),[PredictPostings()])]
文档
本节详细解释了相关的概念和工件 需要使用机器学习来增强Beancount进口商。
Beancount进口商
假设您为“mybank”创建了一个名为 MyBankImporter:
classMyBankImporter(importer.ImporterProtocol):"""My existing importer"""# the actual importer logic would be here...
注: 本文档假设您已经知道如何创建beancount导入程序。 相关文档可以在beancount ingest下找到。使用beancount.insert,用户可以 编写自己的导入程序并使用它们转换下载的银行对账单 进入beancount条目列表。 下面是beancount源代码的一部分 beancount/ingest/office。
应用智能导入程序
任何beancount导入程序都可以通过应用一个 下列钩子中的一个:
- PredictPostings-预测投递列表。
- PredictPayees-预测交易的收款人。
- DuplicateDetector-检测重复项
fromyour_custom_importerimportMyBankImporterfromsmart_importerimportapply_hooks,PredictPayees,PredictPostingsmy_bank_importer=MyBankImporter('whatever','config','is','needed')apply_hooks(my_bank_importer,[PredictPostings(),PredictPayees()])CONFIG=[my_bank_importer,]
注意,导入器钩子需要应用于导入器实例,如 如上图所示。
指定培训数据
^ {tt1}$钩子需要训练数据,即现有列表 为了有效的交易。培训数据可由 用引用现有BeaCeNT的参数调用bean提取 事务,例如bean-extract-f existing_transactions.beancount。什么时候? 使用FAWA中的进口商,将现有条目用作训练数据。 自动。
与fava一起使用
聪明的进口商与Fava玩得很好。 这意味着你可以用与fava完全相同的方式使用智能进口商。 就像你对待传统进口商一样。有关详细信息,请参见Fava’s help on importers 信息。
开发
拉请求欢迎!
执行单元测试
简单运行(需要TOX):
make test
配置日志
python的日志记录模块由smart_importer模块使用。 相应的日志级别可以更改如下:
importlogginglogging.getLogger('smart_importer').setLevel(logging.DEBUG)