| Crates.io | tktax-histogram |
| lib.rs | tktax-histogram |
| version | 0.2.2 |
| created_at | 2025-02-01 05:05:09.815761+00 |
| updated_at | 2025-02-01 05:05:09.815761+00 |
| description | A Rust crate that provides robust monthly histogram utilities for financial transactions, using specialized types from the TKTAX ecosystem. |
| homepage | |
| repository | https://github.com/klebs6/tktax |
| max_upload_size | |
| id | 1538162 |
| size | 96,121 |
A Rust library that provides a robust method to construct, display, and analyze histograms of transaction distributions in conjunction with the tktax_account, tktax_money, tktax_transaction, and tktax_3p crates. The name Histogram is derived from the ancient Greek ῾ἱστός᾽ (histós), signifying something upright or a web’s warp, now used to depict the frequency distribution of numerical data.
This crate defines data structures for creating monthly binned data via user-specified price (monetary) bins and includes multiple strategies for rendering the histogram. It is especially useful for accounting or financial analysis applications, thanks to its integration with specialized monetary types from tktax_money. Its design is amenable to advanced usage scenarios where resourcefulness and comprehensive error handling are crucial.
AccountHistogram
Aggregates all transactions from an account into a month-based histogram, providing both a high-level overview of transaction volume and deeper transactional detail.
Multiple Histogram Display Strategies
Bins
Customizable bin edges (Vec<MonetaryAmount>) to accurately categorize transactions into discrete intervals, emulating a partitioned distribution (Latin: distributio) of monetary amounts (Latin: monetarius).
Monthly Granularity
Each transaction is grouped by its date into a HistogramMonth, which enforces strict month numbering (1 through 12) and ensures correctness with an assertion.
Production-Ready Error Handling
Below is a concise illustration of how to employ the histogram functionality. For an Account populated with transactions, the following snippet constructs and prints a full histogram to stdout:
use tktax_histogram::*;
use tktax_account::Account;
use tktax_money::MonetaryAmount;
use tktax_transaction::Transaction;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Suppose 'my_account' is constructed with a known set of transactions
let my_account = Account::new("My Checking Account");
// Example: build and push some transactions (pseudo-code)
// for each TX, we set transaction date, amount, description, etc.
// my_account.add_transaction(...);
// Create a strategy: show all transactions in the histogram
let strategy = HistogramDisplayStrategy::show_full_histogram();
// Generate a histogram with the default bin edges used in 'CreateAccountHistogram'
let histogram = my_account.histogram(&strategy);
// Print the histogram
println!("{}", histogram);
Ok(())
}
The library also exposes further customization options (e.g., HistogramDisplayStrategy::with_price_threshold(123.45)) for advanced applications. Simply select a strategy and generate the histogram from your Account object. You can then utilize fmt::Display to produce textual output.
MonetaryAmount type for safety and clarity.tktax_money, tktax_transaction, tktax_account, and tktax_3p for robust financial data handling.Rust 1.60 or higher is recommended, matching the dependencies of the TKTAX suite.
Licensed under either of:
at your option.
Contributions are welcome! Please open an issue or submit a pull request for improvements or bug fixes.