mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-29 09:09:58 -07:00
computer: indexes + rolling
This commit is contained in:
@@ -46,6 +46,23 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Rolling sums for sent and received
|
||||
let window_starts = blocks.count.window_starts();
|
||||
self.sent_sum_rolling.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.sent_sum.sats.height,
|
||||
&self.sent_sum.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
self.received_sum_rolling.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.received_sum.sats.height,
|
||||
&self.received_sum.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// tx_per_sec: per-block tx count / block interval
|
||||
self.tx_per_sec.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
@@ -83,7 +100,7 @@ impl Vecs {
|
||||
// outputs_per_sec: per-block output count / block interval
|
||||
self.outputs_per_sec.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&outputs_count.total_count.height.sum_cum.sum.0,
|
||||
&outputs_count.total_count.sum_cum.sum.0,
|
||||
&blocks.interval.interval.height,
|
||||
|(h, output_count, interval, ..)| {
|
||||
let interval_f64 = f64::from(*interval);
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, ValueFromHeightLast, ValueFromHeightSum},
|
||||
internal::{ComputedFromHeightLast, StoredValueRollingWindows, ValueFromHeightLast},
|
||||
prices,
|
||||
};
|
||||
|
||||
@@ -18,13 +18,17 @@ impl Vecs {
|
||||
) -> Result<Self> {
|
||||
let v2 = Version::TWO;
|
||||
Ok(Self {
|
||||
sent_sum: ValueFromHeightSum::forced_import(db, "sent_sum", version, indexes, prices)?,
|
||||
received_sum: ValueFromHeightSum::forced_import(
|
||||
db,
|
||||
"received_sum",
|
||||
version,
|
||||
indexes,
|
||||
prices,
|
||||
sent_sum: ValueFromHeightLast::forced_import(
|
||||
db, "sent_sum", version, indexes, prices,
|
||||
)?,
|
||||
sent_sum_rolling: StoredValueRollingWindows::forced_import(
|
||||
db, "sent_sum", version, indexes,
|
||||
)?,
|
||||
received_sum: ValueFromHeightLast::forced_import(
|
||||
db, "received_sum", version, indexes, prices,
|
||||
)?,
|
||||
received_sum_rolling: StoredValueRollingWindows::forced_import(
|
||||
db, "received_sum", version, indexes,
|
||||
)?,
|
||||
annualized_volume: ValueFromHeightLast::forced_import(
|
||||
db,
|
||||
|
||||
@@ -2,13 +2,20 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredF32;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, ValueFromHeightLast, ValueFromHeightSum};
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, StoredValueRollingWindows, ValueFromHeightLast,
|
||||
};
|
||||
|
||||
/// Volume metrics
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub sent_sum: ValueFromHeightSum<M>,
|
||||
pub received_sum: ValueFromHeightSum<M>,
|
||||
#[traversable(flatten)]
|
||||
pub sent_sum: ValueFromHeightLast<M>,
|
||||
pub sent_sum_rolling: StoredValueRollingWindows<M>,
|
||||
#[traversable(flatten)]
|
||||
pub received_sum: ValueFromHeightLast<M>,
|
||||
pub received_sum_rolling: StoredValueRollingWindows<M>,
|
||||
#[traversable(flatten)]
|
||||
pub annualized_volume: ValueFromHeightLast<M>,
|
||||
pub tx_per_sec: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub outputs_per_sec: ComputedFromHeightLast<StoredF32, M>,
|
||||
|
||||
Reference in New Issue
Block a user