global: snapshot

This commit is contained in:
nym21
2026-03-01 11:39:02 +01:00
parent a6664bbb93
commit e10013fd2c
23 changed files with 367 additions and 467 deletions
+51 -68
View File
@@ -2437,38 +2437,6 @@ impl AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern {
}
}
/// Pattern struct for repeated tree structure.
pub struct AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern {
pub average: _1y24h30d7dPattern<StoredU64>,
pub cumulative: MetricPattern1<StoredU64>,
pub max: _1y24h30d7dPattern<StoredU64>,
pub median: _1y24h30d7dPattern<StoredU64>,
pub min: _1y24h30d7dPattern<StoredU64>,
pub pct10: _1y24h30d7dPattern<StoredU64>,
pub pct25: _1y24h30d7dPattern<StoredU64>,
pub pct75: _1y24h30d7dPattern<StoredU64>,
pub pct90: _1y24h30d7dPattern<StoredU64>,
pub sum: _1y24h30d7dPattern<StoredU64>,
}
impl AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern {
/// Create a new pattern node with accumulated metric name.
pub fn new(client: Arc<BrkClientBase>, acc: String) -> Self {
Self {
average: _1y24h30d7dPattern::new(client.clone(), _m(&acc, "average")),
cumulative: MetricPattern1::new(client.clone(), _m(&acc, "cumulative")),
max: _1y24h30d7dPattern::new(client.clone(), _m(&acc, "max")),
median: _1y24h30d7dPattern::new(client.clone(), _m(&acc, "median")),
min: _1y24h30d7dPattern::new(client.clone(), _m(&acc, "min")),
pct10: _1y24h30d7dPattern::new(client.clone(), _m(&acc, "p10")),
pct25: _1y24h30d7dPattern::new(client.clone(), _m(&acc, "p25")),
pct75: _1y24h30d7dPattern::new(client.clone(), _m(&acc, "p75")),
pct90: _1y24h30d7dPattern::new(client.clone(), _m(&acc, "p90")),
sum: _1y24h30d7dPattern::new(client.clone(), _m(&acc, "sum")),
}
}
}
/// Pattern struct for repeated tree structure.
pub struct AverageGainsLossesRsiStochPattern {
pub average_gain: MetricPattern1<StoredF32>,
@@ -3129,22 +3097,6 @@ impl BaseCumulativePattern {
}
}
/// Pattern struct for repeated tree structure.
pub struct BaseRestPattern {
pub base: MetricPattern20<StoredU64>,
pub rest: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
}
impl BaseRestPattern {
/// Create a new pattern node with accumulated metric name.
pub fn new(client: Arc<BrkClientBase>, acc: String) -> Self {
Self {
base: MetricPattern20::new(client.clone(), acc.clone()),
rest: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), acc.clone()),
}
}
}
/// Pattern struct for repeated tree structure.
pub struct CumulativeHeightPattern {
pub cumulative: MetricPattern1<Dollars>,
@@ -3295,7 +3247,7 @@ pub struct MetricsTree_Blocks {
pub interval: AverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern<Timestamp>,
pub halving: MetricsTree_Blocks_Halving,
pub vbytes: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
pub size: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
pub size: MetricsTree_Blocks_Size,
pub fullness: AverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern<StoredF32>,
}
@@ -3311,7 +3263,7 @@ impl MetricsTree_Blocks {
interval: AverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern::new(client.clone(), "block_interval".to_string()),
halving: MetricsTree_Blocks_Halving::new(client.clone(), format!("{base_path}_halving")),
vbytes: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "block_vbytes".to_string()),
size: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "block_size".to_string()),
size: MetricsTree_Blocks_Size::new(client.clone(), format!("{base_path}_size")),
fullness: AverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern::new(client.clone(), "block_fullness".to_string()),
}
}
@@ -3486,6 +3438,37 @@ impl MetricsTree_Blocks_Halving {
}
}
/// Metrics tree node.
pub struct MetricsTree_Blocks_Size {
pub cumulative: MetricPattern1<StoredU64>,
pub sum: _1y24h30d7dPattern<StoredU64>,
pub average: _1y24h30d7dPattern<StoredU64>,
pub min: _1y24h30d7dPattern<StoredU64>,
pub max: _1y24h30d7dPattern<StoredU64>,
pub pct10: _1y24h30d7dPattern<StoredU64>,
pub pct25: _1y24h30d7dPattern<StoredU64>,
pub median: _1y24h30d7dPattern<StoredU64>,
pub pct75: _1y24h30d7dPattern<StoredU64>,
pub pct90: _1y24h30d7dPattern<StoredU64>,
}
impl MetricsTree_Blocks_Size {
pub fn new(client: Arc<BrkClientBase>, base_path: String) -> Self {
Self {
cumulative: MetricPattern1::new(client.clone(), "block_size_cumulative".to_string()),
sum: _1y24h30d7dPattern::new(client.clone(), "block_size_sum".to_string()),
average: _1y24h30d7dPattern::new(client.clone(), "block_size_average".to_string()),
min: _1y24h30d7dPattern::new(client.clone(), "block_size_min".to_string()),
max: _1y24h30d7dPattern::new(client.clone(), "block_size_max".to_string()),
pct10: _1y24h30d7dPattern::new(client.clone(), "block_size_p10".to_string()),
pct25: _1y24h30d7dPattern::new(client.clone(), "block_size_p25".to_string()),
median: _1y24h30d7dPattern::new(client.clone(), "block_size_median".to_string()),
pct75: _1y24h30d7dPattern::new(client.clone(), "block_size_p75".to_string()),
pct90: _1y24h30d7dPattern::new(client.clone(), "block_size_p90".to_string()),
}
}
}
/// Metrics tree node.
pub struct MetricsTree_Transactions {
pub first_txindex: MetricPattern20<TxIndex>,
@@ -6786,29 +6769,29 @@ impl MetricsTree_Distribution_TotalAddrCount {
/// Metrics tree node.
pub struct MetricsTree_Distribution_NewAddrCount {
pub all: BaseRestPattern,
pub p2pk65: BaseRestPattern,
pub p2pk33: BaseRestPattern,
pub p2pkh: BaseRestPattern,
pub p2sh: BaseRestPattern,
pub p2wpkh: BaseRestPattern,
pub p2wsh: BaseRestPattern,
pub p2tr: BaseRestPattern,
pub p2a: BaseRestPattern,
pub all: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
pub p2pk65: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
pub p2pk33: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
pub p2pkh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
pub p2sh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
pub p2wpkh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
pub p2wsh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
pub p2tr: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
pub p2a: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
}
impl MetricsTree_Distribution_NewAddrCount {
pub fn new(client: Arc<BrkClientBase>, base_path: String) -> Self {
Self {
all: BaseRestPattern::new(client.clone(), "new_addr_count".to_string()),
p2pk65: BaseRestPattern::new(client.clone(), "p2pk65_new_addr_count".to_string()),
p2pk33: BaseRestPattern::new(client.clone(), "p2pk33_new_addr_count".to_string()),
p2pkh: BaseRestPattern::new(client.clone(), "p2pkh_new_addr_count".to_string()),
p2sh: BaseRestPattern::new(client.clone(), "p2sh_new_addr_count".to_string()),
p2wpkh: BaseRestPattern::new(client.clone(), "p2wpkh_new_addr_count".to_string()),
p2wsh: BaseRestPattern::new(client.clone(), "p2wsh_new_addr_count".to_string()),
p2tr: BaseRestPattern::new(client.clone(), "p2tr_new_addr_count".to_string()),
p2a: BaseRestPattern::new(client.clone(), "p2a_new_addr_count".to_string()),
all: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "new_addr_count".to_string()),
p2pk65: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "p2pk65_new_addr_count".to_string()),
p2pk33: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "p2pk33_new_addr_count".to_string()),
p2pkh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "p2pkh_new_addr_count".to_string()),
p2sh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "p2sh_new_addr_count".to_string()),
p2wpkh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "p2wpkh_new_addr_count".to_string()),
p2wsh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "p2wsh_new_addr_count".to_string()),
p2tr: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "p2tr_new_addr_count".to_string()),
p2a: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "p2a_new_addr_count".to_string()),
}
}
}
@@ -20,9 +20,9 @@ use brk_traversable::Traversable;
use brk_types::{Height, StoredU32, Version};
use derive_more::{Deref, DerefMut};
use rayon::prelude::*;
use vecdb::{AnyStoredVec, AnyVec, Database, Rw, StorageMode, WritableVec};
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec};
use crate::{indexes, internal::ComputedFromHeightDistribution};
use crate::{indexes, internal::{ComputedFromHeightDistribution, WindowStarts}};
/// Per-block activity counts - reset each block.
///
@@ -187,6 +187,20 @@ impl ActivityCountVecs {
Ok(())
}
pub(crate) fn compute_rest(
&mut self,
max_from: Height,
windows: &WindowStarts<'_>,
exit: &Exit,
) -> Result<()> {
self.reactivated.compute_rest(max_from, windows, exit)?;
self.sending.compute_rest(max_from, windows, exit)?;
self.receiving.compute_rest(max_from, windows, exit)?;
self.balance_increased.compute_rest(max_from, windows, exit)?;
self.balance_decreased.compute_rest(max_from, windows, exit)?;
self.both.compute_rest(max_from, windows, exit)?;
Ok(())
}
}
/// Per-address-type activity count vecs.
@@ -253,6 +267,18 @@ impl AddressTypeToActivityCountVecs {
Ok(())
}
pub(crate) fn compute_rest(
&mut self,
max_from: Height,
windows: &WindowStarts<'_>,
exit: &Exit,
) -> Result<()> {
for type_vecs in self.0.values_mut() {
type_vecs.compute_rest(max_from, windows, exit)?;
}
Ok(())
}
pub(crate) fn truncate_push_height(
&mut self,
height: Height,
@@ -315,6 +341,17 @@ impl AddressActivityVecs {
Ok(())
}
pub(crate) fn compute_rest(
&mut self,
max_from: Height,
windows: &WindowStarts<'_>,
exit: &Exit,
) -> Result<()> {
self.all.compute_rest(max_from, windows, exit)?;
self.by_addresstype.compute_rest(max_from, windows, exit)?;
Ok(())
}
pub(crate) fn truncate_push_height(
&mut self,
height: Height,
@@ -1,23 +1,21 @@
//! New address count: delta of total_addr_count (global + per-type)
//! New address count: per-block delta of total_addr_count (global + per-type)
//! New address count: delta of total_addr_count (global + per-type)
use brk_cohort::{ByAddressType, zip_by_addresstype};
use brk_cohort::ByAddressType;
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Height, StoredU64, Version};
use vecdb::{Database, Exit, Ident, Rw, StorageMode};
use vecdb::{Database, Exit, Rw, StorageMode};
use crate::{indexes, internal::{LazyComputedFromHeightFull, WindowStarts}};
use crate::{indexes, internal::{ComputedFromHeightCumulativeFull, WindowStarts}};
use super::TotalAddrCountVecs;
/// New address count per block (global + per-type)
#[derive(Traversable)]
pub struct NewAddrCountVecs<M: StorageMode = Rw> {
pub all: LazyComputedFromHeightFull<StoredU64, StoredU64, M>,
pub all: ComputedFromHeightCumulativeFull<StoredU64, M>,
#[traversable(flatten)]
pub by_addresstype: ByAddressType<LazyComputedFromHeightFull<StoredU64, StoredU64, M>>,
pub by_addresstype: ByAddressType<ComputedFromHeightCumulativeFull<StoredU64, M>>,
}
impl NewAddrCountVecs {
@@ -25,23 +23,20 @@ impl NewAddrCountVecs {
db: &Database,
version: Version,
indexes: &indexes::Vecs,
total_addr_count: &TotalAddrCountVecs,
) -> Result<Self> {
let all = LazyComputedFromHeightFull::forced_import::<Ident>(
let all = ComputedFromHeightCumulativeFull::forced_import(
db,
"new_addr_count",
version,
&total_addr_count.all.height,
indexes,
)?;
let by_addresstype: ByAddressType<LazyComputedFromHeightFull<StoredU64, StoredU64>> =
zip_by_addresstype(&total_addr_count.by_addresstype, |name, total| {
LazyComputedFromHeightFull::forced_import::<Ident>(
let by_addresstype: ByAddressType<ComputedFromHeightCumulativeFull<StoredU64>> =
ByAddressType::new_with_name(|name| {
ComputedFromHeightCumulativeFull::forced_import(
db,
&format!("{name}_new_addr_count"),
version,
&total.height,
indexes,
)
})?;
@@ -56,12 +51,23 @@ impl NewAddrCountVecs {
&mut self,
max_from: Height,
windows: &WindowStarts<'_>,
total_addr_count: &TotalAddrCountVecs,
exit: &Exit,
) -> Result<()> {
self.all.compute(max_from, windows, exit)?;
for vecs in self.by_addresstype.values_mut() {
vecs.compute(max_from, windows, exit)?;
self.all.compute(max_from, windows, exit, |height_vec| {
Ok(height_vec.compute_change(max_from, &total_addr_count.all.height, 1, exit)?)
})?;
for ((_, new), (_, total)) in self
.by_addresstype
.iter_mut()
.zip(total_addr_count.by_addresstype.iter())
{
new.compute(max_from, windows, exit, |height_vec| {
Ok(height_vec.compute_change(max_from, &total.height, 1, exit)?)
})?;
}
Ok(())
}
}
@@ -6,7 +6,7 @@ use vecdb::{AnyStoredVec, AnyVec, EagerVec, Exit, ImportableVec, PcoVec, Rw, Sto
use crate::{
ComputeIndexes, blocks,
internal::{ComputedFromHeightCumulativeSum, LazyComputedValueFromHeightCumulative, ValueEmaFromHeight},
internal::{ComputedFromHeightCumulativeSum, ValueFromHeightCumulative, ValueFromHeightLast},
};
use super::ImportConfig;
@@ -15,10 +15,10 @@ use super::ImportConfig;
#[derive(Traversable)]
pub struct ActivityMetrics<M: StorageMode = Rw> {
/// Total satoshis sent at each height + derived indexes
pub sent: LazyComputedValueFromHeightCumulative<M>,
pub sent: ValueFromHeightCumulative<M>,
/// 14-day EMA of sent supply (sats, btc, usd)
pub sent_14d_ema: ValueEmaFromHeight<M>,
pub sent_14d_ema: ValueFromHeightLast<M>,
/// Satoshi-blocks destroyed (supply * blocks_old when spent)
pub satblocks_destroyed: M::Stored<EagerVec<PcoVec<Height, Sats>>>,
@@ -37,14 +37,14 @@ impl ActivityMetrics {
/// Import activity metrics from database.
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(Self {
sent: LazyComputedValueFromHeightCumulative::forced_import(
sent: ValueFromHeightCumulative::forced_import(
cfg.db,
&cfg.name("sent"),
cfg.version,
cfg.indexes,
)?,
sent_14d_ema: ValueEmaFromHeight::forced_import(
sent_14d_ema: ValueFromHeightLast::forced_import(
cfg.db,
&cfg.name("sent_14d_ema"),
cfg.version,
@@ -165,8 +165,8 @@ impl ActivityMetrics {
) -> Result<()> {
let window_starts = blocks.count.window_starts();
// 14-day rolling average of sent (sats and dollars)
self.sent_14d_ema.compute_rolling_average(
// 14-day EMA of sent (sats and dollars)
self.sent_14d_ema.compute_ema(
starting_indexes.height,
&blocks.count.height_2w_ago,
&self.sent.base.sats.height,
@@ -262,7 +262,7 @@ impl RealizedAdjusted {
// Adjusted SOPR EMAs
self.adjusted_sopr_24h_7d_ema
.height
.compute_rolling_average(
.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.adjusted_sopr.height,
@@ -270,7 +270,7 @@ impl RealizedAdjusted {
)?;
self.adjusted_sopr_24h_30d_ema
.height
.compute_rolling_average(
.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1m_ago,
&self.adjusted_sopr.height,
@@ -13,9 +13,9 @@ use crate::{
distribution::state::RealizedState,
internal::{
CentsUnsignedToDollars, ComputedFromHeightCumulative, ComputedFromHeightLast,
ComputedFromHeightRatio, DollarsPlus, LazyComputedValueFromHeightCumulative, LazyFromHeightLast,
ComputedFromHeightRatio, DollarsPlus, ValueFromHeightCumulative, LazyFromHeightLast,
PercentageDollarsF32, Price, Ratio64,
StoredF32Identity, ValueEmaFromHeight,
StoredF32Identity, ValueFromHeightLast,
},
prices,
};
@@ -130,10 +130,10 @@ pub struct RealizedBase<M: StorageMode = Rw> {
pub peak_regret_rel_to_realized_cap: ComputedFromHeightLast<StoredF32, M>,
// === Sent in Profit/Loss ===
pub sent_in_profit: LazyComputedValueFromHeightCumulative<M>,
pub sent_in_profit_14d_ema: ValueEmaFromHeight<M>,
pub sent_in_loss: LazyComputedValueFromHeightCumulative<M>,
pub sent_in_loss_14d_ema: ValueEmaFromHeight<M>,
pub sent_in_profit: ValueFromHeightCumulative<M>,
pub sent_in_profit_14d_ema: ValueFromHeightLast<M>,
pub sent_in_loss: ValueFromHeightCumulative<M>,
pub sent_in_loss_14d_ema: ValueFromHeightLast<M>,
}
impl RealizedBase {
@@ -540,25 +540,25 @@ impl RealizedBase {
)?,
peak_regret,
peak_regret_rel_to_realized_cap,
sent_in_profit: LazyComputedValueFromHeightCumulative::forced_import(
sent_in_profit: ValueFromHeightCumulative::forced_import(
cfg.db,
&cfg.name("sent_in_profit"),
cfg.version,
cfg.indexes,
)?,
sent_in_profit_14d_ema: ValueEmaFromHeight::forced_import(
sent_in_profit_14d_ema: ValueFromHeightLast::forced_import(
cfg.db,
&cfg.name("sent_in_profit_14d_ema"),
cfg.version,
cfg.indexes,
)?,
sent_in_loss: LazyComputedValueFromHeightCumulative::forced_import(
sent_in_loss: ValueFromHeightCumulative::forced_import(
cfg.db,
&cfg.name("sent_in_loss"),
cfg.version,
cfg.indexes,
)?,
sent_in_loss_14d_ema: ValueEmaFromHeight::forced_import(
sent_in_loss_14d_ema: ValueFromHeightLast::forced_import(
cfg.db,
&cfg.name("sent_in_loss_14d_ema"),
cfg.version,
@@ -1021,14 +1021,14 @@ impl RealizedBase {
exit,
)?;
// 7d rolling averages
self.realized_profit_7d_ema.height.compute_rolling_average(
// 7d EMAs
self.realized_profit_7d_ema.height.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.realized_profit.height,
exit,
)?;
self.realized_loss_7d_ema.height.compute_rolling_average(
self.realized_loss_7d_ema.height.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.realized_loss.height,
@@ -1036,22 +1036,22 @@ impl RealizedBase {
)?;
self.net_realized_pnl_7d_ema
.height
.compute_rolling_average(
.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.net_realized_pnl.height,
exit,
)?;
// 14-day rolling average of sent in profit/loss
self.sent_in_profit_14d_ema.compute_rolling_average(
// 14-day EMA of sent in profit/loss
self.sent_in_profit_14d_ema.compute_ema(
starting_indexes.height,
&blocks.count.height_2w_ago,
&self.sent_in_profit.base.sats.height,
&self.sent_in_profit.base.usd.height,
exit,
)?;
self.sent_in_loss_14d_ema.compute_rolling_average(
self.sent_in_loss_14d_ema.compute_ema(
starting_indexes.height,
&blocks.count.height_2w_ago,
&self.sent_in_loss.base.sats.height,
@@ -1060,13 +1060,13 @@ impl RealizedBase {
)?;
// SOPR EMAs
self.sopr_24h_7d_ema.height.compute_rolling_average(
self.sopr_24h_7d_ema.height.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.sopr.height,
exit,
)?;
self.sopr_24h_30d_ema.height.compute_rolling_average(
self.sopr_24h_30d_ema.height.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1m_ago,
&self.sopr.height,
@@ -1076,7 +1076,7 @@ impl RealizedBase {
// Sell side risk EMAs
self.sell_side_risk_ratio_24h_7d_ema
.height
.compute_rolling_average(
.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.sell_side_risk_ratio.height,
@@ -1084,7 +1084,7 @@ impl RealizedBase {
)?;
self.sell_side_risk_ratio_24h_30d_ema
.height
.compute_rolling_average(
.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1m_ago,
&self.sell_side_risk_ratio.height,
@@ -8,7 +8,7 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
use crate::internal::{
HalveDollars, HalveSats, HalveSatsToBitcoin,
LazyValueFromHeightLast, ValueChangeFromHeight, ValueFromHeightLast,
LazyValueFromHeightLast, ValueFromHeightChange, ValueFromHeightLast,
};
use super::ImportConfig;
@@ -19,7 +19,7 @@ pub struct SupplyMetrics<M: StorageMode = Rw> {
pub total: ValueFromHeightLast<M>,
pub halved: LazyValueFromHeightLast,
/// 30-day change in supply (net position change) - sats, btc, usd
pub _30d_change: ValueChangeFromHeight<M>,
pub _30d_change: ValueFromHeightChange<M>,
}
impl SupplyMetrics {
@@ -38,7 +38,7 @@ impl SupplyMetrics {
HalveDollars,
>(&cfg.name("supply_halved"), &supply, cfg.version);
let _30d_change = ValueChangeFromHeight::forced_import(
let _30d_change = ValueFromHeightChange::forced_import(
cfg.db,
&cfg.name("_30d_change"),
cfg.version,
+7 -5
View File
@@ -52,7 +52,7 @@ pub struct Vecs<M: StorageMode = Rw> {
/// Total addresses ever seen (addr_count + empty_addr_count) - stored, global + per-type
pub total_addr_count: TotalAddrCountVecs<M>,
/// New addresses per block (delta of total) - lazy height, stored day1 stats, global + per-type
/// New addresses per block (delta of total) - stored height + cumulative + rolling, global + per-type
pub new_addr_count: NewAddrCountVecs<M>,
/// Growth rate (new / addr_count) - stored ratio with distribution stats, global + per-type
pub growth_rate: GrowthRateVecs<M>,
@@ -117,9 +117,9 @@ impl Vecs {
// Stored total = addr_count + empty_addr_count (global + per-type, with all derived indexes)
let total_addr_count = TotalAddrCountVecs::forced_import(&db, version, indexes)?;
// Lazy delta of total (global + per-type)
// Per-block delta of total (global + per-type)
let new_addr_count =
NewAddrCountVecs::forced_import(&db, version, indexes, &total_addr_count)?;
NewAddrCountVecs::forced_import(&db, version, indexes)?;
// Growth rate: new / addr_count (global + per-type)
let growth_rate = GrowthRateVecs::forced_import(&db, version, indexes)?;
@@ -352,10 +352,12 @@ impl Vecs {
exit,
)?;
// 6d. Compute new_addr_count cumulative + rolling (height is lazy delta)
let window_starts = blocks.count.window_starts();
self.address_activity
.compute_rest(starting_indexes.height, &window_starts, exit)?;
self.new_addr_count
.compute(starting_indexes.height, &window_starts, exit)?;
.compute(starting_indexes.height, &window_starts, &self.total_addr_count, exit)?;
// 6e. Compute growth_rate = new_addr_count / addr_count
self.growth_rate.compute(
@@ -58,6 +58,20 @@ where
f64: From<T>,
{
compute_height(&mut self.height)?;
self.compute_rest(max_from, windows, exit)
}
/// Compute rolling distribution from already-populated height data.
pub(crate) fn compute_rest(
&mut self,
max_from: Height,
windows: &WindowStarts<'_>,
exit: &Exit,
) -> Result<()>
where
T: Copy + Ord + From<f64> + Default,
f64: From<T>,
{
self.rolling
.compute_distribution(max_from, windows, &self.height, exit)?;
Ok(())
@@ -1,69 +0,0 @@
//! LazyComputedFromHeightCumulativeFull - block full with lazy height transform + cumulative + rolling.
use std::ops::SubAssign;
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Height, Version};
use derive_more::{Deref, DerefMut};
use schemars::JsonSchema;
use vecdb::{Database, Exit, LazyVecFrom1, ReadableCloneableVec, Rw, StorageMode, UnaryTransform};
use crate::{
indexes,
internal::{ComputedHeightDerivedCumulativeFull, ComputedVecValue, NumericValue, WindowStarts},
};
const VERSION: Version = Version::ZERO;
/// Block full aggregation with lazy height transform + cumulative + rolling windows.
#[derive(Deref, DerefMut, Traversable)]
pub struct LazyComputedFromHeightFull<T, S = T, M: StorageMode = Rw>
where
T: NumericValue + JsonSchema,
S: ComputedVecValue,
{
#[traversable(rename = "base")]
pub height: LazyVecFrom1<Height, T, Height, S>,
#[deref]
#[deref_mut]
pub rest: Box<ComputedHeightDerivedCumulativeFull<T, M>>,
}
impl<T, S> LazyComputedFromHeightFull<T, S>
where
T: NumericValue + JsonSchema,
S: ComputedVecValue + JsonSchema,
{
pub(crate) fn forced_import<F: UnaryTransform<S, T>>(
db: &Database,
name: &str,
version: Version,
source: &impl ReadableCloneableVec<Height, S>,
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
let height = LazyVecFrom1::transformed::<F>(name, v, source.read_only_boxed_clone());
let rest = ComputedHeightDerivedCumulativeFull::forced_import(db, name, v, indexes)?;
Ok(Self {
height,
rest: Box::new(rest),
})
}
pub(crate) fn compute(
&mut self,
max_from: Height,
windows: &WindowStarts<'_>,
exit: &Exit,
) -> Result<()>
where
T: From<f64> + Default + SubAssign + Copy + Ord,
f64: From<T>,
{
self.rest.compute(max_from, windows, &self.height, exit)
}
}
@@ -6,17 +6,14 @@ mod cumulative_sum;
mod distribution;
mod full;
mod last;
mod lazy_computed_full;
mod lazy_computed_value_cumulative;
mod value_cumulative;
mod lazy_last;
mod lazy_value_last;
mod percentiles;
mod price;
mod ratio;
mod stddev;
mod stored_value_last;
mod value_change;
mod value_ema;
mod value_full;
mod value_last;
mod value_last_rolling;
@@ -30,17 +27,14 @@ pub use cumulative_sum::*;
pub use distribution::*;
pub use full::*;
pub use last::*;
pub use lazy_computed_full::*;
pub use lazy_computed_value_cumulative::*;
pub use value_cumulative::*;
pub use lazy_last::*;
pub use lazy_value_last::*;
pub use percentiles::*;
pub use price::*;
pub use ratio::*;
pub use stddev::*;
pub use stored_value_last::*;
pub use value_change::*;
pub use value_ema::*;
pub use value_full::*;
pub use value_last::*;
pub use value_last_rolling::*;
@@ -1,53 +0,0 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Dollars, Height, Sats, Version};
use derive_more::{Deref, DerefMut};
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
use crate::{
indexes,
internal::ByUnit,
};
const VERSION: Version = Version::ZERO;
#[derive(Deref, DerefMut, Traversable)]
#[traversable(transparent)]
pub struct StoredValueFromHeightLast<M: StorageMode = Rw> {
#[deref]
#[deref_mut]
pub base: ByUnit<M>,
}
impl StoredValueFromHeightLast {
pub(crate) fn forced_import(
db: &Database,
name: &str,
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
Ok(Self {
base: ByUnit::forced_import(db, name, v, indexes)?,
})
}
pub(crate) fn compute_rolling_sum(
&mut self,
max_from: Height,
window_starts: &impl ReadableVec<Height, Height>,
sats_source: &impl ReadableVec<Height, Sats>,
usd_source: &impl ReadableVec<Height, Dollars>,
exit: &Exit,
) -> Result<()> {
self.base
.sats
.height
.compute_rolling_sum(max_from, window_starts, sats_source, exit)?;
self.base
.usd
.height
.compute_rolling_sum(max_from, window_starts, usd_source, exit)?;
Ok(())
}
}
@@ -14,13 +14,13 @@ const VERSION: Version = Version::ZERO;
/// Change values indexed by height - sats (stored), btc (lazy), usd (stored).
#[derive(Traversable)]
pub struct ValueChangeFromHeight<M: StorageMode = Rw> {
pub struct ValueFromHeightChange<M: StorageMode = Rw> {
pub sats: ComputedFromHeightLast<SatsSigned, M>,
pub btc: LazyFromHeightLast<Bitcoin, SatsSigned>,
pub usd: ComputedFromHeightLast<Dollars, M>,
}
impl ValueChangeFromHeight {
impl ValueFromHeightChange {
pub(crate) fn forced_import(
db: &Database,
name: &str,
@@ -10,14 +10,14 @@ use crate::{
};
#[derive(Traversable)]
pub struct LazyComputedValueFromHeightCumulative<M: StorageMode = Rw> {
pub struct ValueFromHeightCumulative<M: StorageMode = Rw> {
pub base: ByUnit<M>,
pub cumulative: ByUnit<M>,
}
const VERSION: Version = Version::ONE;
impl LazyComputedValueFromHeightCumulative {
impl ValueFromHeightCumulative {
pub(crate) fn forced_import(
db: &Database,
name: &str,
@@ -1,53 +0,0 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Dollars, Height, Sats, Version};
use derive_more::{Deref, DerefMut};
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
use crate::{
indexes,
internal::ByUnit,
};
const VERSION: Version = Version::ZERO;
#[derive(Deref, DerefMut, Traversable)]
#[traversable(transparent)]
pub struct ValueEmaFromHeight<M: StorageMode = Rw> {
#[deref]
#[deref_mut]
pub base: ByUnit<M>,
}
impl ValueEmaFromHeight {
pub(crate) fn forced_import(
db: &Database,
name: &str,
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
Ok(Self {
base: ByUnit::forced_import(db, name, v, indexes)?,
})
}
pub(crate) fn compute_rolling_average(
&mut self,
starting_height: Height,
window_starts: &impl ReadableVec<Height, Height>,
sats_source: &impl ReadableVec<Height, Sats>,
dollars_source: &(impl ReadableVec<Height, Dollars> + Sync),
exit: &Exit,
) -> Result<()> {
self.base
.sats
.height
.compute_rolling_average(starting_height, window_starts, sats_source, exit)?;
self.base
.usd
.height
.compute_rolling_average(starting_height, window_starts, dollars_source, exit)?;
Ok(())
}
}
@@ -2,7 +2,7 @@ use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Dollars, Height, Sats, Version};
use derive_more::{Deref, DerefMut};
use vecdb::{Database, Exit, Rw, StorageMode};
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
use crate::{
indexes, prices,
@@ -46,4 +46,42 @@ impl ValueFromHeightLast {
)?;
Ok(())
}
pub(crate) fn compute_rolling_sum(
&mut self,
max_from: Height,
window_starts: &impl ReadableVec<Height, Height>,
sats_source: &impl ReadableVec<Height, Sats>,
usd_source: &impl ReadableVec<Height, Dollars>,
exit: &Exit,
) -> Result<()> {
self.base
.sats
.height
.compute_rolling_sum(max_from, window_starts, sats_source, exit)?;
self.base
.usd
.height
.compute_rolling_sum(max_from, window_starts, usd_source, exit)?;
Ok(())
}
pub(crate) fn compute_ema(
&mut self,
starting_height: Height,
window_starts: &impl ReadableVec<Height, Height>,
sats_source: &impl ReadableVec<Height, Sats>,
dollars_source: &(impl ReadableVec<Height, Dollars> + Sync),
exit: &Exit,
) -> Result<()> {
self.base
.sats
.height
.compute_rolling_ema(starting_height, window_starts, sats_source, exit)?;
self.base
.usd
.height
.compute_rolling_ema(starting_height, window_starts, dollars_source, exit)?;
Ok(())
}
}
@@ -1,7 +1,7 @@
//! Value type for Height + Rolling pattern.
//!
//! Combines ValueFromHeight (sats/btc/usd per height, no period views) with
//! StoredValueRollingWindows (rolling sums across 4 windows).
//! ValueFromHeightLastWindows (rolling sums across 4 windows).
use brk_error::Result;
use brk_traversable::Traversable;
@@ -11,7 +11,7 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
use crate::{
indexes,
internal::{StoredValueRollingWindows, ValueFromHeight, WindowStarts},
internal::{ValueFromHeightLastWindows, ValueFromHeight, WindowStarts},
prices,
};
@@ -22,7 +22,7 @@ pub struct ValueFromHeightLastRolling<M: StorageMode = Rw> {
#[traversable(flatten)]
pub value: ValueFromHeight<M>,
#[traversable(flatten)]
pub rolling: StoredValueRollingWindows<M>,
pub rolling: ValueFromHeightLastWindows<M>,
}
const VERSION: Version = Version::ZERO;
@@ -37,7 +37,7 @@ impl ValueFromHeightLastRolling {
let v = version + VERSION;
Ok(Self {
value: ValueFromHeight::forced_import(db, name, v)?,
rolling: StoredValueRollingWindows::forced_import(db, name, v, indexes)?,
rolling: ValueFromHeightLastWindows::forced_import(db, name, v, indexes)?,
})
}
@@ -1,4 +1,4 @@
//! StoredValueRollingWindows - window-first ordering.
//! ValueFromHeightLastWindows - window-first ordering.
//!
//! Access pattern: `coinbase_sum._24h.sats.height`
//! Each window (24h, 7d, 30d, 1y) contains sats (stored) + btc (lazy) + usd (stored).
@@ -14,21 +14,21 @@ use brk_types::{Dollars, Sats};
use crate::{
indexes,
internal::{StoredValueFromHeightLast, WindowStarts, Windows},
internal::{ValueFromHeightLast, WindowStarts, Windows},
};
const VERSION: Version = Version::ZERO;
/// Stored value rolling windows — window-first, currency-last.
/// Value rolling windows — window-first, currency-last.
///
/// Each window contains `StoredValueFromHeightLast` (sats + btc lazy + usd).
/// Each window contains `ValueFromHeightLast` (sats + btc lazy + usd).
#[derive(Deref, DerefMut, Traversable)]
#[traversable(transparent)]
pub struct StoredValueRollingWindows<M: StorageMode = Rw>(
pub Windows<StoredValueFromHeightLast<M>>,
pub struct ValueFromHeightLastWindows<M: StorageMode = Rw>(
pub Windows<ValueFromHeightLast<M>>,
);
impl StoredValueRollingWindows {
impl ValueFromHeightLastWindows {
pub(crate) fn forced_import(
db: &Database,
name: &str,
@@ -37,25 +37,25 @@ impl StoredValueRollingWindows {
) -> Result<Self> {
let v = version + VERSION;
Ok(Self(Windows {
_24h: StoredValueFromHeightLast::forced_import(
_24h: ValueFromHeightLast::forced_import(
db,
&format!("{name}_24h"),
v,
indexes,
)?,
_7d: StoredValueFromHeightLast::forced_import(
_7d: ValueFromHeightLast::forced_import(
db,
&format!("{name}_7d"),
v,
indexes,
)?,
_30d: StoredValueFromHeightLast::forced_import(
_30d: ValueFromHeightLast::forced_import(
db,
&format!("{name}_30d"),
v,
indexes,
)?,
_1y: StoredValueFromHeightLast::forced_import(
_1y: ValueFromHeightLast::forced_import(
db,
&format!("{name}_1y"),
v,
@@ -27,7 +27,7 @@ impl Vecs {
) -> Result<()> {
self.puell_multiple.height.compute_divide(
starting_indexes.height,
&rewards.coinbase.base.usd.height,
&rewards.subsidy.base.usd.height,
&rewards.subsidy_usd_1y_sma.height,
exit,
)?;
@@ -100,11 +100,11 @@ impl Vecs {
exit,
)?;
// NVT: realized_cap / tx_volume_24h
// NVT: market_cap / tx_volume_24h
self.nvt.compute_binary::<Dollars, Dollars, Ratio32>(
starting_indexes.height,
&distribution.utxo_cohorts.all.metrics.supply.total.usd.height,
&transactions.volume.sent_sum.usd,
&transactions.volume.sent_sum.rolling._24h.usd.height,
exit,
)?;
@@ -193,7 +193,7 @@ impl Vecs {
self.subsidy_usd_1y_sma.height.compute_rolling_average(
starting_indexes.height,
&count_vecs.height_1y_ago,
&self.coinbase.base.usd.height,
&self.subsidy.base.usd.height,
exit,
)?;
+45 -74
View File
@@ -3077,41 +3077,6 @@ function createAverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern
};
}
/**
* @typedef {Object} AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern
* @property {_1y24h30d7dPattern<StoredU64>} average
* @property {MetricPattern1<StoredU64>} cumulative
* @property {_1y24h30d7dPattern<StoredU64>} max
* @property {_1y24h30d7dPattern<StoredU64>} median
* @property {_1y24h30d7dPattern<StoredU64>} min
* @property {_1y24h30d7dPattern<StoredU64>} pct10
* @property {_1y24h30d7dPattern<StoredU64>} pct25
* @property {_1y24h30d7dPattern<StoredU64>} pct75
* @property {_1y24h30d7dPattern<StoredU64>} pct90
* @property {_1y24h30d7dPattern<StoredU64>} sum
*/
/**
* Create a AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern pattern node
* @param {BrkClientBase} client
* @param {string} acc - Accumulated metric name
* @returns {AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern}
*/
function createAverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, acc) {
return {
average: create_1y24h30d7dPattern(client, _m(acc, 'average')),
cumulative: createMetricPattern1(client, _m(acc, 'cumulative')),
max: create_1y24h30d7dPattern(client, _m(acc, 'max')),
median: create_1y24h30d7dPattern(client, _m(acc, 'median')),
min: create_1y24h30d7dPattern(client, _m(acc, 'min')),
pct10: create_1y24h30d7dPattern(client, _m(acc, 'p10')),
pct25: create_1y24h30d7dPattern(client, _m(acc, 'p25')),
pct75: create_1y24h30d7dPattern(client, _m(acc, 'p75')),
pct90: create_1y24h30d7dPattern(client, _m(acc, 'p90')),
sum: create_1y24h30d7dPattern(client, _m(acc, 'sum')),
};
}
/**
* @typedef {Object} AverageGainsLossesRsiStochPattern
* @property {MetricPattern1<StoredF32>} averageGain
@@ -3866,25 +3831,6 @@ function createBaseCumulativePattern(client, acc) {
};
}
/**
* @typedef {Object} BaseRestPattern
* @property {MetricPattern20<StoredU64>} base
* @property {AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern} rest
*/
/**
* Create a BaseRestPattern pattern node
* @param {BrkClientBase} client
* @param {string} acc - Accumulated metric name
* @returns {BaseRestPattern}
*/
function createBaseRestPattern(client, acc) {
return {
base: createMetricPattern20(client, acc),
rest: createAverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, acc),
};
}
/**
* @typedef {Object} CumulativeHeightPattern
* @property {MetricPattern1<Dollars>} cumulative
@@ -4030,7 +3976,7 @@ function createRatioPattern2(client, acc) {
* @property {AverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern<Timestamp>} interval
* @property {MetricsTree_Blocks_Halving} halving
* @property {AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern} vbytes
* @property {AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern} size
* @property {MetricsTree_Blocks_Size} size
* @property {AverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern<StoredF32>} fullness
*/
@@ -4111,6 +4057,20 @@ function createRatioPattern2(client, acc) {
* @property {MetricPattern1<StoredF32>} daysBeforeNextHalving
*/
/**
* @typedef {Object} MetricsTree_Blocks_Size
* @property {MetricPattern1<StoredU64>} cumulative
* @property {_1y24h30d7dPattern<StoredU64>} sum
* @property {_1y24h30d7dPattern<StoredU64>} average
* @property {_1y24h30d7dPattern<StoredU64>} min
* @property {_1y24h30d7dPattern<StoredU64>} max
* @property {_1y24h30d7dPattern<StoredU64>} pct10
* @property {_1y24h30d7dPattern<StoredU64>} pct25
* @property {_1y24h30d7dPattern<StoredU64>} median
* @property {_1y24h30d7dPattern<StoredU64>} pct75
* @property {_1y24h30d7dPattern<StoredU64>} pct90
*/
/**
* @typedef {Object} MetricsTree_Transactions
* @property {MetricPattern20<TxIndex>} firstTxindex
@@ -5585,15 +5545,15 @@ function createRatioPattern2(client, acc) {
/**
* @typedef {Object} MetricsTree_Distribution_NewAddrCount
* @property {BaseRestPattern} all
* @property {BaseRestPattern} p2pk65
* @property {BaseRestPattern} p2pk33
* @property {BaseRestPattern} p2pkh
* @property {BaseRestPattern} p2sh
* @property {BaseRestPattern} p2wpkh
* @property {BaseRestPattern} p2wsh
* @property {BaseRestPattern} p2tr
* @property {BaseRestPattern} p2a
* @property {AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern} all
* @property {AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern} p2pk65
* @property {AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern} p2pk33
* @property {AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern} p2pkh
* @property {AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern} p2sh
* @property {AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern} p2wpkh
* @property {AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern} p2wsh
* @property {AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern} p2tr
* @property {AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern} p2a
*/
/**
@@ -6653,7 +6613,18 @@ class BrkClient extends BrkClientBase {
daysBeforeNextHalving: createMetricPattern1(this, 'days_before_next_halving'),
},
vbytes: createAverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'block_vbytes'),
size: createAverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'block_size'),
size: {
cumulative: createMetricPattern1(this, 'block_size_cumulative'),
sum: create_1y24h30d7dPattern(this, 'block_size_sum'),
average: create_1y24h30d7dPattern(this, 'block_size_average'),
min: create_1y24h30d7dPattern(this, 'block_size_min'),
max: create_1y24h30d7dPattern(this, 'block_size_max'),
pct10: create_1y24h30d7dPattern(this, 'block_size_p10'),
pct25: create_1y24h30d7dPattern(this, 'block_size_p25'),
median: create_1y24h30d7dPattern(this, 'block_size_median'),
pct75: create_1y24h30d7dPattern(this, 'block_size_p75'),
pct90: create_1y24h30d7dPattern(this, 'block_size_p90'),
},
fullness: createAverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern(this, 'block_fullness'),
},
transactions: {
@@ -7784,15 +7755,15 @@ class BrkClient extends BrkClientBase {
p2a: createMetricPattern1(this, 'p2a_total_addr_count'),
},
newAddrCount: {
all: createBaseRestPattern(this, 'new_addr_count'),
p2pk65: createBaseRestPattern(this, 'p2pk65_new_addr_count'),
p2pk33: createBaseRestPattern(this, 'p2pk33_new_addr_count'),
p2pkh: createBaseRestPattern(this, 'p2pkh_new_addr_count'),
p2sh: createBaseRestPattern(this, 'p2sh_new_addr_count'),
p2wpkh: createBaseRestPattern(this, 'p2wpkh_new_addr_count'),
p2wsh: createBaseRestPattern(this, 'p2wsh_new_addr_count'),
p2tr: createBaseRestPattern(this, 'p2tr_new_addr_count'),
p2a: createBaseRestPattern(this, 'p2a_new_addr_count'),
all: createAverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'new_addr_count'),
p2pk65: createAverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'p2pk65_new_addr_count'),
p2pk33: createAverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'p2pk33_new_addr_count'),
p2pkh: createAverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'p2pkh_new_addr_count'),
p2sh: createAverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'p2sh_new_addr_count'),
p2wpkh: createAverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'p2wpkh_new_addr_count'),
p2wsh: createAverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'p2wsh_new_addr_count'),
p2tr: createAverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'p2tr_new_addr_count'),
p2a: createAverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'p2a_new_addr_count'),
},
growthRate: {
all: createAverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern(this, 'growth_rate'),
+25 -34
View File
@@ -2813,22 +2813,6 @@ class AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern:
self.pct90: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, _m(acc, 'p90'))
self.sum: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, _m(acc, 'sum'))
class AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern:
"""Pattern struct for repeated tree structure."""
def __init__(self, client: BrkClientBase, acc: str):
"""Create pattern node with accumulated metric name."""
self.average: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, _m(acc, 'average'))
self.cumulative: MetricPattern1[StoredU64] = MetricPattern1(client, _m(acc, 'cumulative'))
self.max: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, _m(acc, 'max'))
self.median: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, _m(acc, 'median'))
self.min: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, _m(acc, 'min'))
self.pct10: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, _m(acc, 'p10'))
self.pct25: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, _m(acc, 'p25'))
self.pct75: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, _m(acc, 'p75'))
self.pct90: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, _m(acc, 'p90'))
self.sum: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, _m(acc, 'sum'))
class AverageGainsLossesRsiStochPattern:
"""Pattern struct for repeated tree structure."""
@@ -3159,14 +3143,6 @@ class BaseCumulativePattern:
self.base: BtcSatsUsdPattern = BtcSatsUsdPattern(client, acc)
self.cumulative: BtcSatsUsdPattern = BtcSatsUsdPattern(client, _m(acc, 'cumulative'))
class BaseRestPattern:
"""Pattern struct for repeated tree structure."""
def __init__(self, client: BrkClientBase, acc: str):
"""Create pattern node with accumulated metric name."""
self.base: MetricPattern20[StoredU64] = MetricPattern20(client, acc)
self.rest: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, acc)
class CumulativeHeightPattern:
"""Pattern struct for repeated tree structure."""
@@ -3298,6 +3274,21 @@ class MetricsTree_Blocks_Halving:
self.blocks_before_next_halving: MetricPattern1[StoredU32] = MetricPattern1(client, 'blocks_before_next_halving')
self.days_before_next_halving: MetricPattern1[StoredF32] = MetricPattern1(client, 'days_before_next_halving')
class MetricsTree_Blocks_Size:
"""Metrics tree node."""
def __init__(self, client: BrkClientBase, base_path: str = ''):
self.cumulative: MetricPattern1[StoredU64] = MetricPattern1(client, 'block_size_cumulative')
self.sum: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, 'block_size_sum')
self.average: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, 'block_size_average')
self.min: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, 'block_size_min')
self.max: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, 'block_size_max')
self.pct10: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, 'block_size_p10')
self.pct25: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, 'block_size_p25')
self.median: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, 'block_size_median')
self.pct75: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, 'block_size_p75')
self.pct90: _1y24h30d7dPattern[StoredU64] = _1y24h30d7dPattern(client, 'block_size_p90')
class MetricsTree_Blocks:
"""Metrics tree node."""
@@ -3311,7 +3302,7 @@ class MetricsTree_Blocks:
self.interval: AverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern[Timestamp] = AverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, 'block_interval')
self.halving: MetricsTree_Blocks_Halving = MetricsTree_Blocks_Halving(client)
self.vbytes: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'block_vbytes')
self.size: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'block_size')
self.size: MetricsTree_Blocks_Size = MetricsTree_Blocks_Size(client)
self.fullness: AverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern[StoredF32] = AverageHeightMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, 'block_fullness')
class MetricsTree_Transactions_Count:
@@ -4890,15 +4881,15 @@ class MetricsTree_Distribution_NewAddrCount:
"""Metrics tree node."""
def __init__(self, client: BrkClientBase, base_path: str = ''):
self.all: BaseRestPattern = BaseRestPattern(client, 'new_addr_count')
self.p2pk65: BaseRestPattern = BaseRestPattern(client, 'p2pk65_new_addr_count')
self.p2pk33: BaseRestPattern = BaseRestPattern(client, 'p2pk33_new_addr_count')
self.p2pkh: BaseRestPattern = BaseRestPattern(client, 'p2pkh_new_addr_count')
self.p2sh: BaseRestPattern = BaseRestPattern(client, 'p2sh_new_addr_count')
self.p2wpkh: BaseRestPattern = BaseRestPattern(client, 'p2wpkh_new_addr_count')
self.p2wsh: BaseRestPattern = BaseRestPattern(client, 'p2wsh_new_addr_count')
self.p2tr: BaseRestPattern = BaseRestPattern(client, 'p2tr_new_addr_count')
self.p2a: BaseRestPattern = BaseRestPattern(client, 'p2a_new_addr_count')
self.all: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'new_addr_count')
self.p2pk65: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'p2pk65_new_addr_count')
self.p2pk33: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'p2pk33_new_addr_count')
self.p2pkh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'p2pkh_new_addr_count')
self.p2sh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'p2sh_new_addr_count')
self.p2wpkh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'p2wpkh_new_addr_count')
self.p2wsh: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'p2wsh_new_addr_count')
self.p2tr: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'p2tr_new_addr_count')
self.p2a: AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageCumulativeHeightMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'p2a_new_addr_count')
class MetricsTree_Distribution_GrowthRate:
"""Metrics tree node."""
+65 -26
View File
@@ -215,15 +215,23 @@ export function createNetworkSection() {
name: "Sum",
title: t,
bottom: [
line({ metric: p.base, name: "base", unit: Unit.count }),
line({ metric: p.height, name: "base", unit: Unit.count }),
],
},
rollingWindowsTree({ windows: p.rest.sum, title: t, unit: Unit.count }),
rollingWindowsTree({
windows: p.sum,
title: t,
unit: Unit.count,
}),
{
name: "Cumulative",
title: `${t} (Total)`,
bottom: [
line({ metric: p.rest.cumulative, name: "all-time", unit: Unit.count }),
line({
metric: p.cumulative,
name: "all-time",
unit: Unit.count,
}),
],
},
];
@@ -304,13 +312,13 @@ export function createNetworkSection() {
title: `${groupName} New Address Count`,
bottom: types.flatMap((t) => [
line({
metric: distribution.newAddrCount[t.key].base,
metric: distribution.newAddrCount[t.key].height,
name: t.name,
color: t.color,
unit: Unit.count,
}),
line({
metric: distribution.newAddrCount[t.key].rest.sum._24h,
metric: distribution.newAddrCount[t.key].sum._24h,
name: t.name,
color: t.color,
unit: Unit.count,
@@ -367,8 +375,7 @@ export function createNetworkSection() {
unit: Unit.count,
}),
line({
metric:
distribution.addressActivity[t.key][tr.key].average._24h,
metric: distribution.addressActivity[t.key][tr.key].average._24h,
name: t.name,
color: t.color,
unit: Unit.count,
@@ -389,8 +396,7 @@ export function createNetworkSection() {
unit: Unit.count,
}),
line({
metric:
distribution.addressActivity[t.key][b.key].average._24h,
metric: distribution.addressActivity[t.key][b.key].average._24h,
name: t.name,
color: t.color,
unit: Unit.count,
@@ -405,7 +411,11 @@ export function createNetworkSection() {
const legacyScripts = legacyAddresses.slice(1); // p2pkh, p2pk33, p2pk65
const scriptHashScripts = [legacyAddresses[0], nonAddressableTypes[0]]; // p2sh, p2ms
const segwitScripts = [
/** @type {const} */ ({ key: "segwit", name: "All SegWit", color: colors.segwit }),
/** @type {const} */ ({
key: "segwit",
name: "All SegWit",
color: colors.segwit,
}),
...segwitAddresses,
];
const otherScripts = nonAddressableTypes.slice(1); // opreturn, empty, unknown
@@ -424,7 +434,8 @@ export function createNetworkSection() {
title: `${groupName} Output Count`,
bottom: types.map((t) =>
line({
metric: /** @type {CountPattern<number>} */ (scripts.count[t.key]).sum._24h,
metric: /** @type {CountPattern<number>} */ (scripts.count[t.key])
.sum._24h,
name: t.name,
color: t.color,
unit: Unit.count,
@@ -436,7 +447,8 @@ export function createNetworkSection() {
title: `${groupName} Output Count (Total)`,
bottom: types.map((t) =>
line({
metric: /** @type {CountPattern<number>} */ (scripts.count[t.key]).cumulative,
metric: /** @type {CountPattern<number>} */ (scripts.count[t.key])
.cumulative,
name: t.name,
color: t.color,
unit: Unit.count,
@@ -687,7 +699,11 @@ export function createNetworkSection() {
}),
],
},
rollingWindowsTree({ windows: blocks.size.sum, title: "Block Size", unit: Unit.bytes }),
rollingWindowsTree({
windows: blocks.size.sum,
title: "Block Size",
unit: Unit.bytes,
}),
{
name: "Distribution",
title: "Block Size Distribution",
@@ -730,7 +746,11 @@ export function createNetworkSection() {
}),
],
},
rollingWindowsTree({ windows: blocks.weight.sum, title: "Block Weight", unit: Unit.wu }),
rollingWindowsTree({
windows: blocks.weight.sum,
title: "Block Weight",
unit: Unit.wu,
}),
{
name: "Distribution",
title: "Block Weight Distribution",
@@ -773,7 +793,11 @@ export function createNetworkSection() {
}),
],
},
rollingWindowsTree({ windows: blocks.vbytes.sum, title: "Block vBytes", unit: Unit.vb }),
rollingWindowsTree({
windows: blocks.vbytes.sum,
title: "Block vBytes",
unit: Unit.vb,
}),
{
name: "Distribution",
title: "Block vBytes Distribution",
@@ -933,14 +957,14 @@ export function createNetworkSection() {
title: "New Address Count by Type",
bottom: addressTypes.flatMap((t) => [
line({
metric: distribution.newAddrCount[t.key].base,
metric: distribution.newAddrCount[t.key].height,
name: t.name,
color: t.color,
unit: Unit.count,
defaultActive: t.defaultActive,
}),
line({
metric: distribution.newAddrCount[t.key].rest.sum._24h,
metric: distribution.newAddrCount[t.key].sum._24h,
name: t.name,
color: t.color,
unit: Unit.count,
@@ -962,7 +986,8 @@ export function createNetworkSection() {
}),
line({
metric:
distribution.addressActivity[t.key].reactivated.average._24h,
distribution.addressActivity[t.key].reactivated.average
._24h,
name: t.name,
color: t.color,
unit: Unit.count,
@@ -997,7 +1022,8 @@ export function createNetworkSection() {
title: tr.compareTitle,
bottom: addressTypes.flatMap((t) => [
line({
metric: distribution.addressActivity[t.key][tr.key].height,
metric:
distribution.addressActivity[t.key][tr.key].height,
name: t.name,
color: t.color,
unit: Unit.count,
@@ -1005,7 +1031,8 @@ export function createNetworkSection() {
}),
line({
metric:
distribution.addressActivity[t.key][tr.key].average._24h,
distribution.addressActivity[t.key][tr.key].average
._24h,
name: t.name,
color: t.color,
unit: Unit.count,
@@ -1095,7 +1122,9 @@ export function createNetworkSection() {
title: "Output Count by Script Type",
bottom: scriptTypes.map((t) =>
line({
metric: /** @type {CountPattern<number>} */ (scripts.count[t.key]).sum._24h,
metric: /** @type {CountPattern<number>} */ (
scripts.count[t.key]
).sum._24h,
name: t.name,
color: t.color,
unit: Unit.count,
@@ -1125,7 +1154,9 @@ export function createNetworkSection() {
...legacyScripts.map((t) => ({
name: t.name,
tree: chartsFromCount({
pattern: /** @type {CountPattern<number>} */ (scripts.count[t.key]),
pattern: /** @type {CountPattern<number>} */ (
scripts.count[t.key]
),
title: `${t.name} Output Count`,
unit: Unit.count,
}),
@@ -1139,7 +1170,9 @@ export function createNetworkSection() {
...scriptHashScripts.map((t) => ({
name: t.name,
tree: chartsFromCount({
pattern: /** @type {CountPattern<number>} */ (scripts.count[t.key]),
pattern: /** @type {CountPattern<number>} */ (
scripts.count[t.key]
),
title: `${t.name} Output Count`,
unit: Unit.count,
}),
@@ -1153,7 +1186,9 @@ export function createNetworkSection() {
...segwitScripts.map((t) => ({
name: t.name,
tree: chartsFromCount({
pattern: /** @type {CountPattern<number>} */ (scripts.count[t.key]),
pattern: /** @type {CountPattern<number>} */ (
scripts.count[t.key]
),
title: `${t.name} Output Count`,
unit: Unit.count,
}),
@@ -1167,7 +1202,9 @@ export function createNetworkSection() {
...taprootAddresses.map((t) => ({
name: t.name,
tree: chartsFromCount({
pattern: /** @type {CountPattern<number>} */ (scripts.count[t.key]),
pattern: /** @type {CountPattern<number>} */ (
scripts.count[t.key]
),
title: `${t.name} Output Count`,
unit: Unit.count,
}),
@@ -1181,7 +1218,9 @@ export function createNetworkSection() {
...otherScripts.map((t) => ({
name: t.name,
tree: chartsFromCount({
pattern: /** @type {CountPattern<number>} */ (scripts.count[t.key]),
pattern: /** @type {CountPattern<number>} */ (
scripts.count[t.key]
),
title: `${t.name} Output Count`,
unit: Unit.count,
}),