Visualizing a Ledger with pgledger-ui

Visualizing a Ledger with pgledger-ui

I’ve been working on a ledger implementation in pure PostgreSQL called pgledger. As I’ve written about previously, I think more applications should use double-entry ledgers. However, once a ledger is integrated, it can be a bit hard to wrap your head around it visually. What are the money flows? What are the main set of accounts per user? Why is the balance in this account not what I expect?

我一直在开发一个名为 pgledger 的纯 PostgreSQL 分类账实现。正如我之前所写的那样,我认为更多的应用程序应该使用复式记账法。然而,一旦集成了分类账,从视觉上理解它可能会有些困难。资金流向是怎样的?每个用户的主要账户集是什么?为什么这个账户的余额与我预期的不符?

In my work with companies, I’ve often tried to make the ledger more visual and understandable, either with a database dashboard like Metabase or with custom in-app code. The same way that pgledger is meant to be a common, reusable ledger across applications, I thought we could have a common, reusable visualization tool. And thus pgledger-ui was born.

在与各家公司合作的过程中,我经常尝试通过 Metabase 等数据库仪表板或自定义的应用内代码,使分类账变得更加直观和易于理解。正如 pgledger 旨在成为跨应用程序的通用、可重用分类账一样,我认为我们也应该拥有一个通用、可重用的可视化工具。于是,pgledger-ui 应运而生。

Overview

In general, pgledger-ui is pretty simple. It runs database queries and shows them in a webpage. There are some charts and extra aggregate information. And the whole thing is bundled into a single Go binary: go run github.com/pgr0ss/pgledger-ui@latest --database-url postgres://user:pass@host:5432/dbname

概述

总的来说,pgledger-ui 非常简单。它运行数据库查询并将结果显示在网页上。其中包含一些图表和额外的汇总信息。整个程序被打包成一个单一的 Go 二进制文件:go run github.com/pgr0ss/pgledger-ui@latest --database-url postgres://user:pass@host:5432/dbname

Beyond this, there are a few main ideas baked into pgledger-ui:

除此之外,pgledger-ui 还融入了几个核心理念:

Everything Is Linked and Clickable

Often, when debugging an issue, you start by realizing a ledger account doesn’t have the balance you expect. Then, you want to see the transfers in and out of that account. And maybe you want to trace a given metadata key across transfers (e.g. the payment_id). As you continue debugging, you may follow an account to a transfer to another account and so on. With pgledger-ui, each entity shows the related entities, and you can click on any of them to trace a flow. This even includes metadata keys, so you can see related transfers which share the same key/value pair.

一切皆可链接且可点击

通常,在调试问题时,你会先发现某个分类账账户的余额与预期不符。接着,你会想要查看该账户的转入和转出记录。或许你还想追踪跨转账的特定元数据键(例如 payment_id)。随着调试的深入,你可能会从一个账户追踪到一笔转账,再到另一个账户,依此类推。在 pgledger-ui 中,每个实体都会显示相关实体,你可以点击其中任何一个来追踪资金流向。这甚至包括元数据键,因此你可以查看共享相同键值对的相关转账。

It should be easy to find what you want, so pgledger-ui has a single, universal search box. You can search by id, account name, idempotency key, metadata values, etc., and it will show you all matches across all entities. For example, if you name your accounts hierarchically (e.g. user01.available, user01.pending, etc.) you can search for user01 and see all accounts and transfers for that user.

搜索

找到你想要的内容应该很容易,因此 pgledger-ui 提供了一个单一的通用搜索框。你可以按 ID、账户名称、幂等键、元数据值等进行搜索,它会显示所有实体中的匹配项。例如,如果你以层级方式命名账户(如 user01.available, user01.pending 等),你可以搜索 user01 并查看该用户的所有账户和转账记录。

Information Density

I like interfaces which are information dense, without being overwhelming. The goal is to show a lot of useful information in each page, and make it easy to scan for what you need.

信息密度

我喜欢信息密集但又不至于让人感到压力的界面。其目标是在每个页面中展示大量有用的信息,并使用户能够轻松扫描到所需内容。

Column-Based Views

Normally, when you query data from a database, you get row-based results. However, I find that visualizing ledgers in a columnar format is often more useful. For example, say you are looking at all of the transfer entries for a given payment.

基于列的视图

通常,当你从数据库查询数据时,得到的是基于行的结果。然而,我发现以列格式可视化分类账通常更有用。例如,假设你正在查看某笔付款的所有转账条目。

(Example from the pgledger reconciliation.sql.out script) PostgreSQL calls this a crosstab (or crosstabview in psql). A pivot table in a spreadsheet may be similar. And it’s a common way to visualize a ledger. This type of view exists in pgledger-ui as well, especially if you’re tracing a flow via a metadata key: And you can separate the in/out flows, making it resemble a standard ledger T-account view:

(示例来自 pgledger 的 reconciliation.sql.out 脚本)PostgreSQL 将此称为交叉表(在 psql 中为 crosstabview)。电子表格中的数据透视表与之类似。这是可视化分类账的一种常见方式。这种视图也存在于 pgledger-ui 中,特别是当你通过元数据键追踪资金流向时:你还可以将流入/流出分开,使其类似于标准的分类账 T 型账户视图:

Feedback Please

Please check out pgledger-ui, and I’d love to hear what you think, especially if you work with pgledger or other ledgers today. Are there other useful visualizations or tools you’ve seen in this space? And if pgledger-ui is something that you are interested in using, please let me know.

请提供反馈

请查看 pgledger-ui,我很乐意听听你的想法,特别是如果你目前正在使用 pgledger 或其他分类账系统的话。在这个领域,你还见过其他有用的可视化工具吗?如果你对使用 pgledger-ui 感兴趣,请告诉我。