From 24f344c0b1f56bbc0e434c60f24604437d9ff8d0 Mon Sep 17 00:00:00 2001 From: nym21 Date: Wed, 18 Mar 2026 13:14:43 +0100 Subject: [PATCH] global: snapshot --- crates/brk_client/src/lib.rs | 12 ++-- .../src/transactions/volume/compute.rs | 66 +++++++++++-------- .../src/transactions/volume/import.rs | 26 ++++---- .../src/transactions/volume/vecs.rs | 8 +-- modules/brk-client/index.js | 12 ++-- packages/brk_client/brk_client/__init__.py | 6 +- website/scripts/options/network.js | 45 +++++++------ 7 files changed, 94 insertions(+), 81 deletions(-) diff --git a/crates/brk_client/src/lib.rs b/crates/brk_client/src/lib.rs index f7853d47f..71d4d54fb 100644 --- a/crates/brk_client/src/lib.rs +++ b/crates/brk_client/src/lib.rs @@ -3382,18 +3382,18 @@ impl SeriesTree_Transactions_Versions { /// Series tree node. pub struct SeriesTree_Transactions_Volume { pub transfer_volume: BaseCumulativeSumPattern4, - pub tx_per_sec: SeriesPattern1, - pub outputs_per_sec: SeriesPattern1, - pub inputs_per_sec: SeriesPattern1, + pub tx_per_sec: _1m1w1y24hPattern, + pub outputs_per_sec: _1m1w1y24hPattern, + pub inputs_per_sec: _1m1w1y24hPattern, } impl SeriesTree_Transactions_Volume { pub fn new(client: Arc, base_path: String) -> Self { Self { transfer_volume: BaseCumulativeSumPattern4::new(client.clone(), "transfer_volume_bis".to_string()), - tx_per_sec: SeriesPattern1::new(client.clone(), "tx_per_sec".to_string()), - outputs_per_sec: SeriesPattern1::new(client.clone(), "outputs_per_sec".to_string()), - inputs_per_sec: SeriesPattern1::new(client.clone(), "inputs_per_sec".to_string()), + tx_per_sec: _1m1w1y24hPattern::new(client.clone(), "tx_per_sec".to_string()), + outputs_per_sec: _1m1w1y24hPattern::new(client.clone(), "outputs_per_sec".to_string()), + inputs_per_sec: _1m1w1y24hPattern::new(client.clone(), "inputs_per_sec".to_string()), } } } diff --git a/crates/brk_computer/src/transactions/volume/compute.rs b/crates/brk_computer/src/transactions/volume/compute.rs index 278bcdbe1..582f071c2 100644 --- a/crates/brk_computer/src/transactions/volume/compute.rs +++ b/crates/brk_computer/src/transactions/volume/compute.rs @@ -1,11 +1,18 @@ use brk_error::Result; use brk_indexer::Indexer; -use brk_types::{Indexes, Timestamp}; +use brk_types::{Indexes, StoredF32}; use vecdb::Exit; use super::Vecs; use crate::transactions::{count, fees}; -use crate::{blocks, indexes, inputs, internal::PerSec, outputs, prices}; +use crate::{blocks, indexes, inputs, outputs, prices}; + +const WINDOW_SECS: [f64; 4] = [ + 86400.0, + 7.0 * 86400.0, + 30.0 * 86400.0, + 365.0 * 86400.0, +]; impl Vecs { #[allow(clippy::too_many_arguments)] @@ -38,30 +45,37 @@ impl Vecs { }, )?; - self.tx_per_sec - .height - .compute_binary::<_, Timestamp, PerSec>( - starting_indexes.height, - &count_vecs.total.base.height, - &blocks.interval.base, - exit, - )?; - self.inputs_per_sec - .height - .compute_binary::<_, Timestamp, PerSec>( - starting_indexes.height, - &inputs_count.sum.height, - &blocks.interval.base, - exit, - )?; - self.outputs_per_sec - .height - .compute_binary::<_, Timestamp, PerSec>( - starting_indexes.height, - &outputs_count.total.sum.height, - &blocks.interval.base, - exit, - )?; + let h = starting_indexes.height; + let tx_sums = count_vecs.total.rolling.sum.0.as_array(); + let input_sums = inputs_count.rolling.sum.0.as_array(); + let output_sums = outputs_count.total.rolling.sum.0.as_array(); + + for (i, &secs) in WINDOW_SECS.iter().enumerate() { + self.tx_per_sec.as_mut_array()[i] + .height + .compute_transform( + h, + &tx_sums[i].height, + |(h, sum, ..)| (h, StoredF32::from(*sum as f64 / secs)), + exit, + )?; + self.inputs_per_sec.as_mut_array()[i] + .height + .compute_transform( + h, + &input_sums[i].height, + |(h, sum, ..)| (h, StoredF32::from(*sum as f64 / secs)), + exit, + )?; + self.outputs_per_sec.as_mut_array()[i] + .height + .compute_transform( + h, + &output_sums[i].height, + |(h, sum, ..)| (h, StoredF32::from(*sum as f64 / secs)), + exit, + )?; + } Ok(()) } diff --git a/crates/brk_computer/src/transactions/volume/import.rs b/crates/brk_computer/src/transactions/volume/import.rs index 6e312aa5f..1bd589216 100644 --- a/crates/brk_computer/src/transactions/volume/import.rs +++ b/crates/brk_computer/src/transactions/volume/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{AmountPerBlockCumulativeWithSums, CachedWindowStarts, PerBlock}, + internal::{AmountPerBlockCumulativeWithSums, CachedWindowStarts, PerBlock, Windows}, }; impl Vecs { @@ -15,7 +15,7 @@ impl Vecs { indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { - let v2 = Version::TWO; + let v = version + Version::TWO; Ok(Self { transfer_volume: AmountPerBlockCumulativeWithSums::forced_import( db, @@ -24,19 +24,15 @@ impl Vecs { indexes, cached_starts, )?, - tx_per_sec: PerBlock::forced_import(db, "tx_per_sec", version + v2, indexes)?, - outputs_per_sec: PerBlock::forced_import( - db, - "outputs_per_sec", - version + v2, - indexes, - )?, - inputs_per_sec: PerBlock::forced_import( - db, - "inputs_per_sec", - version + v2, - indexes, - )?, + tx_per_sec: Windows::try_from_fn(|suffix| { + PerBlock::forced_import(db, &format!("tx_per_sec_{suffix}"), v, indexes) + })?, + outputs_per_sec: Windows::try_from_fn(|suffix| { + PerBlock::forced_import(db, &format!("outputs_per_sec_{suffix}"), v, indexes) + })?, + inputs_per_sec: Windows::try_from_fn(|suffix| { + PerBlock::forced_import(db, &format!("inputs_per_sec_{suffix}"), v, indexes) + })?, }) } } diff --git a/crates/brk_computer/src/transactions/volume/vecs.rs b/crates/brk_computer/src/transactions/volume/vecs.rs index 982e95173..22b1a5d5c 100644 --- a/crates/brk_computer/src/transactions/volume/vecs.rs +++ b/crates/brk_computer/src/transactions/volume/vecs.rs @@ -2,12 +2,12 @@ use brk_traversable::Traversable; use brk_types::StoredF32; use vecdb::{Rw, StorageMode}; -use crate::internal::{AmountPerBlockCumulativeWithSums, PerBlock}; +use crate::internal::{AmountPerBlockCumulativeWithSums, PerBlock, Windows}; #[derive(Traversable)] pub struct Vecs { pub transfer_volume: AmountPerBlockCumulativeWithSums, - pub tx_per_sec: PerBlock, - pub outputs_per_sec: PerBlock, - pub inputs_per_sec: PerBlock, + pub tx_per_sec: Windows>, + pub outputs_per_sec: Windows>, + pub inputs_per_sec: Windows>, } diff --git a/modules/brk-client/index.js b/modules/brk-client/index.js index ec30e9031..74da90c6b 100644 --- a/modules/brk-client/index.js +++ b/modules/brk-client/index.js @@ -4100,9 +4100,9 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} SeriesTree_Transactions_Volume * @property {BaseCumulativeSumPattern4} transferVolume - * @property {SeriesPattern1} txPerSec - * @property {SeriesPattern1} outputsPerSec - * @property {SeriesPattern1} inputsPerSec + * @property {_1m1w1y24hPattern} txPerSec + * @property {_1m1w1y24hPattern} outputsPerSec + * @property {_1m1w1y24hPattern} inputsPerSec */ /** @@ -7612,9 +7612,9 @@ class BrkClient extends BrkClientBase { }, volume: { transferVolume: createBaseCumulativeSumPattern4(this, 'transfer_volume_bis'), - txPerSec: createSeriesPattern1(this, 'tx_per_sec'), - outputsPerSec: createSeriesPattern1(this, 'outputs_per_sec'), - inputsPerSec: createSeriesPattern1(this, 'inputs_per_sec'), + txPerSec: create_1m1w1y24hPattern(this, 'tx_per_sec'), + outputsPerSec: create_1m1w1y24hPattern(this, 'outputs_per_sec'), + inputsPerSec: create_1m1w1y24hPattern(this, 'inputs_per_sec'), }, }, inputs: { diff --git a/packages/brk_client/brk_client/__init__.py b/packages/brk_client/brk_client/__init__.py index 5654e5c49..6ebf455fb 100644 --- a/packages/brk_client/brk_client/__init__.py +++ b/packages/brk_client/brk_client/__init__.py @@ -3323,9 +3323,9 @@ class SeriesTree_Transactions_Volume: def __init__(self, client: BrkClientBase, base_path: str = ''): self.transfer_volume: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, 'transfer_volume_bis') - self.tx_per_sec: SeriesPattern1[StoredF32] = SeriesPattern1(client, 'tx_per_sec') - self.outputs_per_sec: SeriesPattern1[StoredF32] = SeriesPattern1(client, 'outputs_per_sec') - self.inputs_per_sec: SeriesPattern1[StoredF32] = SeriesPattern1(client, 'inputs_per_sec') + self.tx_per_sec: _1m1w1y24hPattern[StoredF32] = _1m1w1y24hPattern(client, 'tx_per_sec') + self.outputs_per_sec: _1m1w1y24hPattern[StoredF32] = _1m1w1y24hPattern(client, 'outputs_per_sec') + self.inputs_per_sec: _1m1w1y24hPattern[StoredF32] = _1m1w1y24hPattern(client, 'inputs_per_sec') class SeriesTree_Transactions: """Series tree node.""" diff --git a/website/scripts/options/network.js b/website/scripts/options/network.js index 163bfcadf..758ddde76 100644 --- a/website/scripts/options/network.js +++ b/website/scripts/options/network.js @@ -779,27 +779,30 @@ export function createNetworkSection() { }, { name: "Activity Rate", - title: "Activity Rate", - bottom: [ - dots({ - series: transactions.volume.txPerSec, - name: "TX/sec", - color: colors.entity.tx, - unit: Unit.perSec, - }), - dots({ - series: transactions.volume.inputsPerSec, - name: "Inputs/sec", - color: colors.entity.input, - unit: Unit.perSec, - }), - dots({ - series: transactions.volume.outputsPerSec, - name: "Outputs/sec", - color: colors.entity.output, - unit: Unit.perSec, - }), - ], + tree: ROLLING_WINDOWS.map((w) => ({ + name: w.name, + title: `Activity Rate (${w.name})`, + bottom: [ + line({ + series: transactions.volume.txPerSec[w.key], + name: "TX/sec", + color: colors.entity.tx, + unit: Unit.perSec, + }), + line({ + series: transactions.volume.inputsPerSec[w.key], + name: "Inputs/sec", + color: colors.entity.input, + unit: Unit.perSec, + }), + line({ + series: transactions.volume.outputsPerSec[w.key], + name: "Outputs/sec", + color: colors.entity.output, + unit: Unit.perSec, + }), + ], + })), }, // Addresses