#transaction #analytics #burst-detection

tktax-burst

A Rust library for identifying and printing heavy bursts of financial transactions in a sliding date window

1 unstable release

new 0.2.2 Feb 1, 2025

#91 in #transactions

MIT/Apache

155KB
2.5K SLoC

tktax-burst provides robust, production-grade routines for analyzing transaction flows over contiguous time spans, ensuring that financial or operational data can be processed quickly and accurately to reveal peak transaction intensities.

tktax-burst is a Rust library for detecting and displaying “heavy bursts” of transaction activity within a specified rolling time window. It computes daily aggregates from a collection of financial transactions, enumerates all possible windows, then ranks these windows by total transaction volume. Overlapping or consecutive windows are merged to provide a consolidated view of high-intensity activity intervals.

Features & Use Cases

  • Sliding-Window Summation: For each calendar day, the library computes totals over [day, day + (window_size - 1)] using chrono’s NaiveDate.
  • Automatic Merging: Date intervals that intersect or are adjacent are coalesced into a single, larger interval.
  • Sorting by Magnitude: Partial comparisons of monetary values order windows in descending fashion, permitting quick extraction of top-N bursts.
  • Transaction Traces: For each burst, the library optionally prints all contributing transactions, enabling further inspection of high-activity periods.
  • Tested & Production-Ready: A thorough set of unit tests illustrates robust usage and verifies correctness of the daily aggregator, sliding-window logic, and interval merging.

Example Usage

use tktax_burst::FindHeavyTransactionBursts;
use tktax_account::Account;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Assume `account` is already populated with transaction data.
    let account = Account::new(/* ... */);

    // Print the top 5 heaviest bursts, each spanning 7 days.
    account.print_heavy_bursts(5, 7);

    Ok(())
}

In this example:

  1. Collect daily totals: Each date’s aggregated value is computed.
  2. Build date windows: For each day, a 7-day window is formed with a cumulative sum.
  3. Sort in descending order: The windows are sorted by total transaction volume.
  4. Take the top N: Select the top 5 windows.
  5. Merge intervals: Overlapping or contiguous date ranges are merged.
  6. Print results: Display each burst and the contributing transaction lines.

Key Modules

  • collect_daily_totals: Aggregates transaction amounts by date.
  • build_date_windows: Constructs rolling date windows of configurable length.
  • merge_overlapping_burst_windows: Merges overlapping/adjacent date windows.
  • print_merged_bursts: Outputs consolidated intervals and their total amounts.
  • print_transaction_lines: Displays individual transactions within each interval.
  • FindHeavyTransactionBursts: Core trait for enumerating, merging, and displaying high-volume windows.

Testing

A comprehensive suite of tests is included under #[cfg(test)]. Run them with:

cargo test

This ensures correctness of daily totals, window merging, descending sort, and final burst-printing logic.

License

This crate can be licensed or distributed according to your project’s needs. Update the [package] section in your Cargo.toml accordingly.

Contributing

Please open an issue or submit a pull request to contribute improvements or bug fixes. Testing additions and suggestions for optimization of the interval-merging algorithm are especially welcome.

Dependencies

~26–38MB
~644K SLoC