From 3709ceff8e2bdaffa6fe505d30b4da5aba29b0c8 Mon Sep 17 00:00:00 2001 From: nym21 Date: Fri, 13 Mar 2026 16:27:10 +0100 Subject: [PATCH] global: snapshot --- crates/brk_client/src/lib.rs | 834 +++++++-------- .../brk_computer/src/blocks/count/compute.rs | 2 +- .../brk_computer/src/blocks/count/import.rs | 4 +- crates/brk_computer/src/blocks/count/vecs.rs | 4 +- .../src/blocks/difficulty/compute.rs | 33 +- .../src/blocks/difficulty/import.rs | 52 +- .../src/blocks/difficulty/vecs.rs | 12 +- .../src/blocks/halving/compute.rs | 8 - .../brk_computer/src/blocks/halving/import.rs | 34 +- .../brk_computer/src/blocks/halving/vecs.rs | 8 +- crates/brk_computer/src/blocks/import.rs | 2 +- .../src/blocks/interval/import.rs | 4 +- .../brk_computer/src/blocks/interval/vecs.rs | 4 +- crates/brk_computer/src/blocks/size/import.rs | 6 +- crates/brk_computer/src/blocks/size/vecs.rs | 6 +- .../brk_computer/src/blocks/weight/import.rs | 4 +- crates/brk_computer/src/blocks/weight/vecs.rs | 4 +- .../src/cointime/activity/compute.rs | 13 +- .../src/cointime/activity/import.rs | 42 +- .../src/cointime/activity/vecs.rs | 12 +- .../src/cointime/adjusted/import.rs | 6 +- .../src/cointime/adjusted/vecs.rs | 6 +- crates/brk_computer/src/cointime/import.rs | 2 +- .../src/cointime/prices/import.rs | 4 +- .../brk_computer/src/cointime/prices/vecs.rs | 4 +- .../src/cointime/reserve_risk/compute.rs | 4 +- .../src/cointime/reserve_risk/import.rs | 4 +- .../src/cointime/reserve_risk/vecs.rs | 4 +- .../src/cointime/value/compute.rs | 8 +- .../brk_computer/src/cointime/value/import.rs | 10 +- .../brk_computer/src/cointime/value/vecs.rs | 10 +- .../src/distribution/address/activity.rs | 18 +- .../src/distribution/address/address_count.rs | 6 +- .../distribution/address/new_address_count.rs | 10 +- .../address/total_address_count.rs | 12 +- .../src/distribution/cohorts/address/vecs.rs | 6 +- .../src/distribution/cohorts/utxo/fenwick.rs | 2 +- .../src/distribution/cohorts/utxo/groups.rs | 4 +- .../src/distribution/compute/block_loop.rs | 4 +- .../src/distribution/compute/write.rs | 2 +- .../src/distribution/metrics/activity/core.rs | 44 +- .../src/distribution/metrics/activity/full.rs | 12 +- .../src/distribution/metrics/cohort/all.rs | 4 +- .../metrics/cohort/extended_adjusted.rs | 4 +- .../src/distribution/metrics/config.rs | 12 +- .../distribution/metrics/cost_basis/mod.rs | 6 +- .../src/distribution/metrics/outputs/base.rs | 6 +- .../src/distribution/metrics/profitability.rs | 10 +- .../distribution/metrics/realized/adjusted.rs | 10 +- .../src/distribution/metrics/realized/core.rs | 8 +- .../src/distribution/metrics/realized/full.rs | 84 +- .../distribution/metrics/realized/minimal.rs | 38 +- .../relative/extended_own_market_cap.rs | 4 +- .../metrics/relative/extended_own_pnl.rs | 4 +- .../src/distribution/metrics/relative/full.rs | 4 +- .../distribution/metrics/unrealized/basic.rs | 16 +- .../distribution/metrics/unrealized/core.rs | 8 +- .../distribution/metrics/unrealized/full.rs | 4 +- crates/brk_computer/src/distribution/vecs.rs | 8 +- crates/brk_computer/src/indexes/mod.rs | 2 +- crates/brk_computer/src/indicators/import.rs | 14 +- crates/brk_computer/src/indicators/vecs.rs | 14 +- .../brk_computer/src/inputs/count/import.rs | 4 +- crates/brk_computer/src/inputs/count/vecs.rs | 4 +- crates/brk_computer/src/inputs/import.rs | 2 +- .../src/internal/aggregate/distribution.rs | 3 +- .../{full.rs => distribution_full.rs} | 10 +- .../src/internal/aggregate/mod.rs | 4 +- .../internal/{amount/lazy.rs => amount.rs} | 0 .../brk_computer/src/internal/amount/mod.rs | 3 - .../computed => containers}/constant.rs | 0 .../src/internal/containers/mod.rs | 2 + .../src/internal/containers/windows.rs | 7 - crates/brk_computer/src/internal/mod.rs | 6 +- .../src/internal/per_block/amount/base.rs | 10 +- .../per_block/amount/cumulative_sum.rs | 16 +- .../per_block/amount/rolling_distribution.rs | 2 +- .../internal/per_block/computed/aggregated.rs | 20 +- .../src/internal/per_block/computed/base.rs | 4 +- .../internal/per_block/computed/cumulative.rs | 24 +- .../per_block/computed/cumulative_sum.rs | 28 +- .../src/internal/per_block/computed/full.rs | 32 +- ...zy_resolutions_full.rs => lazy_rolling.rs} | 18 +- .../src/internal/per_block/computed/mod.rs | 10 +- .../{resolutions_full.rs => rolling.rs} | 18 +- .../per_block/computed/rolling_average.rs | 6 +- .../per_block/computed/with_deltas.rs | 10 +- .../src/internal/per_block/fiat/base.rs | 6 +- .../internal/per_block/fiat/cumulative_sum.rs | 8 +- .../src/internal/per_block/fiat/lazy.rs | 4 +- .../src/internal/per_block/lazy/base.rs | 4 +- .../per_block/lazy/derived_resolutions.rs | 4 +- .../src/internal/per_block/percent/base.rs | 8 +- .../src/internal/per_block/percent/lazy.rs | 46 + .../per_block/percent/lazy_windows.rs | 33 + .../src/internal/per_block/percent/mod.rs | 4 + .../per_block/percent/rolling_average.rs | 6 +- .../src/internal/per_block/percentiles.rs | 6 +- .../src/internal/per_block/price.rs | 8 +- .../src/internal/per_block/ratio/base.rs | 6 +- .../internal/per_block/ratio/percentiles.rs | 6 +- .../per_block/ratio/price_extended.rs | 6 +- .../rolling/{full.rs => complete.rs} | 6 +- .../per_block/rolling/distribution.rs | 2 +- .../{lazy_full.rs => lazy_complete.rs} | 16 +- .../src/internal/per_block/rolling/mod.rs | 8 +- .../src/internal/per_block/rolling/windows.rs | 25 +- .../src/internal/per_block/stddev/base.rs | 10 +- .../src/internal/per_block/stddev/extended.rs | 14 +- .../src/internal/per_tx/distribution.rs | 6 +- ...ed.rs => lazy_distribution_transformed.rs} | 4 +- .../brk_computer/src/internal/per_tx/mod.rs | 4 +- .../src/internal/transform/arithmetic.rs | 48 +- .../src/internal/transform/mod.rs | 5 +- crates/brk_computer/src/market/ath/import.rs | 6 +- crates/brk_computer/src/market/ath/vecs.rs | 8 +- crates/brk_computer/src/market/dca/vecs.rs | 6 +- crates/brk_computer/src/market/import.rs | 2 +- .../brk_computer/src/market/lookback/vecs.rs | 4 +- .../brk_computer/src/market/range/import.rs | 6 +- crates/brk_computer/src/market/range/vecs.rs | 14 +- .../src/market/technical/import.rs | 14 +- .../brk_computer/src/market/technical/vecs.rs | 20 +- .../src/mining/hashrate/compute.rs | 44 +- .../src/mining/hashrate/import.rs | 136 +-- .../brk_computer/src/mining/hashrate/vecs.rs | 22 +- crates/brk_computer/src/mining/import.rs | 2 +- .../src/mining/rewards/compute.rs | 19 +- .../brk_computer/src/mining/rewards/import.rs | 31 +- .../brk_computer/src/mining/rewards/vecs.rs | 5 +- .../brk_computer/src/outputs/count/import.rs | 6 +- crates/brk_computer/src/outputs/count/vecs.rs | 6 +- crates/brk_computer/src/outputs/import.rs | 2 +- crates/brk_computer/src/pools/major.rs | 4 +- crates/brk_computer/src/pools/minor.rs | 6 +- crates/brk_computer/src/pools/mod.rs | 2 +- crates/brk_computer/src/positions.rs | 2 +- crates/brk_computer/src/prices/by_unit.rs | 4 +- crates/brk_computer/src/prices/mod.rs | 6 +- crates/brk_computer/src/scripts/adoption.rs | 4 +- .../brk_computer/src/scripts/count/compute.rs | 6 +- .../brk_computer/src/scripts/count/import.rs | 28 +- crates/brk_computer/src/scripts/count/vecs.rs | 28 +- crates/brk_computer/src/scripts/import.rs | 2 +- .../brk_computer/src/supply/burned/compute.rs | 4 +- crates/brk_computer/src/supply/import.rs | 3 +- .../src/supply/velocity/compute.rs | 4 +- .../src/supply/velocity/import.rs | 6 +- .../brk_computer/src/supply/velocity/vecs.rs | 6 +- .../src/transactions/count/import.rs | 4 +- .../src/transactions/count/vecs.rs | 4 +- .../src/transactions/fees/import.rs | 6 +- .../src/transactions/fees/vecs.rs | 6 +- .../brk_computer/src/transactions/import.rs | 2 +- .../src/transactions/size/import.rs | 4 +- .../src/transactions/size/vecs.rs | 4 +- .../src/transactions/versions/compute.rs | 4 +- .../src/transactions/versions/import.rs | 8 +- .../src/transactions/versions/vecs.rs | 8 +- .../src/transactions/volume/compute.rs | 2 +- .../src/transactions/volume/import.rs | 8 +- .../src/transactions/volume/vecs.rs | 8 +- .../src/impl/mining/block_rewards.rs | 2 +- crates/brk_query/src/impl/mining/epochs.rs | 2 +- crates/brk_query/src/impl/mining/hashrate.rs | 4 +- .../brk_query/src/impl/mining/reward_stats.rs | 4 +- modules/brk-client/index.js | 954 +++++++++--------- packages/brk_client/brk_client/__init__.py | 437 ++++---- 168 files changed, 2007 insertions(+), 2008 deletions(-) rename crates/brk_computer/src/internal/aggregate/{full.rs => distribution_full.rs} (87%) rename crates/brk_computer/src/internal/{amount/lazy.rs => amount.rs} (100%) delete mode 100644 crates/brk_computer/src/internal/amount/mod.rs rename crates/brk_computer/src/internal/{per_block/computed => containers}/constant.rs (100%) rename crates/brk_computer/src/internal/per_block/computed/{lazy_resolutions_full.rs => lazy_rolling.rs} (66%) rename crates/brk_computer/src/internal/per_block/computed/{resolutions_full.rs => rolling.rs} (70%) create mode 100644 crates/brk_computer/src/internal/per_block/percent/lazy.rs create mode 100644 crates/brk_computer/src/internal/per_block/percent/lazy_windows.rs rename crates/brk_computer/src/internal/per_block/rolling/{full.rs => complete.rs} (91%) rename crates/brk_computer/src/internal/per_block/rolling/{lazy_full.rs => lazy_complete.rs} (77%) rename crates/brk_computer/src/internal/per_tx/{lazy_distribution_derived.rs => lazy_distribution_transformed.rs} (90%) diff --git a/crates/brk_client/src/lib.rs b/crates/brk_client/src/lib.rs index 8f147a326..e626c8dd5 100644 --- a/crates/brk_client/src/lib.rs +++ b/crates/brk_client/src/lib.rs @@ -1106,14 +1106,14 @@ impl _10y1m1w1y2y3m3y4y5y6m6y8yPattern3 { /// Pattern struct for repeated tree structure. pub struct CapGrossInvestorLossMvrvNetPeakPriceProfitSellSoprPattern { pub cap: CentsDeltaRelUsdPattern, - pub gross_pnl: CumulativeRawSumPattern3, + pub gross_pnl: BaseCumulativeSumPattern3, pub investor: LowerPriceUpperPattern, - pub loss: CapitulationCumulativeNegativeRawRelSumValuePattern, + pub loss: BaseCapitulationCumulativeNegativeRelSumValuePattern, pub mvrv: MetricPattern1, - pub net_pnl: ChangeCumulativeDeltaRawRelSumPattern, - pub peak_regret: CumulativeRawRelPattern, + pub net_pnl: BaseChangeCumulativeDeltaRelSumPattern, + pub peak_regret: BaseCumulativeRelPattern, pub price: BpsCentsPercentilesRatioSatsSmaStdUsdPattern, - pub profit: CumulativeDistributionRawRelSumValuePattern, + pub profit: BaseCumulativeDistributionRelSumValuePattern, pub profit_to_loss_ratio: _1m1w1y24hPattern, pub sell_side_risk_ratio: _1m1w1y24hPattern2, pub sopr: AdjustedRatioValuePattern, @@ -1124,14 +1124,14 @@ impl CapGrossInvestorLossMvrvNetPeakPriceProfitSellSoprPattern { pub fn new(client: Arc, acc: String) -> Self { Self { cap: CentsDeltaRelUsdPattern::new(client.clone(), _m(&acc, "realized_cap")), - gross_pnl: CumulativeRawSumPattern3::new(client.clone(), _m(&acc, "realized_gross_pnl")), + gross_pnl: BaseCumulativeSumPattern3::new(client.clone(), _m(&acc, "realized_gross_pnl")), investor: LowerPriceUpperPattern::new(client.clone(), acc.clone()), - loss: CapitulationCumulativeNegativeRawRelSumValuePattern::new(client.clone(), acc.clone()), + loss: BaseCapitulationCumulativeNegativeRelSumValuePattern::new(client.clone(), acc.clone()), mvrv: MetricPattern1::new(client.clone(), _m(&acc, "mvrv")), - net_pnl: ChangeCumulativeDeltaRawRelSumPattern::new(client.clone(), _m(&acc, "net")), - peak_regret: CumulativeRawRelPattern::new(client.clone(), _m(&acc, "realized_peak_regret")), + net_pnl: BaseChangeCumulativeDeltaRelSumPattern::new(client.clone(), _m(&acc, "net")), + peak_regret: BaseCumulativeRelPattern::new(client.clone(), _m(&acc, "realized_peak_regret")), price: BpsCentsPercentilesRatioSatsSmaStdUsdPattern::new(client.clone(), _m(&acc, "realized_price")), - profit: CumulativeDistributionRawRelSumValuePattern::new(client.clone(), acc.clone()), + profit: BaseCumulativeDistributionRelSumValuePattern::new(client.clone(), acc.clone()), profit_to_loss_ratio: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "realized_profit_to_loss_ratio")), sell_side_risk_ratio: _1m1w1y24hPattern2::new(client.clone(), _m(&acc, "sell_side_risk_ratio")), sopr: AdjustedRatioValuePattern::new(client.clone(), acc.clone()), @@ -1174,8 +1174,9 @@ impl AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RollingSumPattern { } /// Pattern struct for repeated tree structure. -pub struct AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern { +pub struct AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern { pub average: _1m1w1y24hPattern, + pub base: MetricPattern1, pub cumulative: MetricPattern1, pub max: _1m1w1y24hPattern, pub median: _1m1w1y24hPattern, @@ -1184,15 +1185,15 @@ pub struct AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern { pub pct25: _1m1w1y24hPattern, pub pct75: _1m1w1y24hPattern, pub pct90: _1m1w1y24hPattern, - pub raw: MetricPattern1, pub sum: _1m1w1y24hPattern, } -impl AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern { +impl AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { average: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "average")), + base: MetricPattern1::new(client.clone(), acc.clone()), cumulative: MetricPattern1::new(client.clone(), _m(&acc, "cumulative")), max: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "max")), median: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "median")), @@ -1201,7 +1202,6 @@ impl AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern { pct25: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "pct25")), pct75: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "pct75")), pct90: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "pct90")), - raw: MetricPattern1::new(client.clone(), acc.clone()), sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sum")), } } @@ -1327,6 +1327,34 @@ impl AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern { } } +/// Pattern struct for repeated tree structure. +pub struct BaseCapitulationCumulativeNegativeRelSumValuePattern { + pub base: CentsUsdPattern2, + pub capitulation_flow: MetricPattern1, + pub cumulative: CentsUsdPattern2, + pub negative: MetricPattern1, + pub rel_to_rcap: BpsPercentRatioPattern, + pub sum: _1m1w1y24hPattern5, + pub value_created: BaseCumulativeSumPattern, + pub value_destroyed: BaseCumulativeSumPattern, +} + +impl BaseCapitulationCumulativeNegativeRelSumValuePattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + base: CentsUsdPattern2::new(client.clone(), _m(&acc, "realized_loss")), + capitulation_flow: MetricPattern1::new(client.clone(), _m(&acc, "capitulation_flow")), + cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "realized_loss_cumulative")), + negative: MetricPattern1::new(client.clone(), _m(&acc, "neg_realized_loss")), + rel_to_rcap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_loss_rel_to_rcap")), + sum: _1m1w1y24hPattern5::new(client.clone(), _m(&acc, "realized_loss_sum")), + value_created: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "loss_value_created")), + value_destroyed: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "loss_value_destroyed")), + } + } +} + /// Pattern struct for repeated tree structure. pub struct BpsCentsPercentilesRatioSatsSmaStdUsdPattern { pub bps: MetricPattern1, @@ -1355,34 +1383,6 @@ impl BpsCentsPercentilesRatioSatsSmaStdUsdPattern { } } -/// Pattern struct for repeated tree structure. -pub struct CapitulationCumulativeNegativeRawRelSumValuePattern { - pub capitulation_flow: MetricPattern1, - pub cumulative: CentsUsdPattern2, - pub negative: MetricPattern1, - pub raw: CentsUsdPattern2, - pub rel_to_rcap: BpsPercentRatioPattern, - pub sum: _1m1w1y24hPattern5, - pub value_created: CumulativeRawSumPattern, - pub value_destroyed: CumulativeRawSumPattern, -} - -impl CapitulationCumulativeNegativeRawRelSumValuePattern { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - capitulation_flow: MetricPattern1::new(client.clone(), _m(&acc, "capitulation_flow")), - cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "realized_loss_cumulative")), - negative: MetricPattern1::new(client.clone(), _m(&acc, "neg_realized_loss")), - raw: CentsUsdPattern2::new(client.clone(), _m(&acc, "realized_loss")), - rel_to_rcap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_loss_rel_to_rcap")), - sum: _1m1w1y24hPattern5::new(client.clone(), _m(&acc, "realized_loss_sum")), - value_created: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "loss_value_created")), - value_destroyed: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "loss_value_destroyed")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern2 { pub average: MetricPattern18, @@ -1464,75 +1464,49 @@ impl _1m1w1y24hBpsPercentRatioPattern { } /// Pattern struct for repeated tree structure. -pub struct CapLossMvrvNetPriceProfitSoprPattern { - pub cap: CentsDeltaUsdPattern, - pub loss: CumulativeNegativeRawSumPattern, - pub mvrv: MetricPattern1, - pub net_pnl: CumulativeDeltaRawSumPattern, - pub price: BpsCentsRatioSatsUsdPattern, - pub profit: CumulativeRawSumPattern3, - pub sopr: RatioValuePattern, -} - -impl CapLossMvrvNetPriceProfitSoprPattern { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - cap: CentsDeltaUsdPattern::new(client.clone(), _m(&acc, "realized_cap")), - loss: CumulativeNegativeRawSumPattern::new(client.clone(), acc.clone()), - mvrv: MetricPattern1::new(client.clone(), _m(&acc, "mvrv")), - net_pnl: CumulativeDeltaRawSumPattern::new(client.clone(), _m(&acc, "net_realized_pnl")), - price: BpsCentsRatioSatsUsdPattern::new(client.clone(), _m(&acc, "realized_price")), - profit: CumulativeRawSumPattern3::new(client.clone(), _m(&acc, "realized_profit")), - sopr: RatioValuePattern::new(client.clone(), acc.clone()), - } - } -} - -/// Pattern struct for repeated tree structure. -pub struct CumulativeDistributionRawRelSumValuePattern { +pub struct BaseCumulativeDistributionRelSumValuePattern { + pub base: CentsUsdPattern2, pub cumulative: CentsUsdPattern2, pub distribution_flow: MetricPattern1, - pub raw: CentsUsdPattern2, pub rel_to_rcap: BpsPercentRatioPattern, pub sum: _1m1w1y24hPattern5, - pub value_created: CumulativeRawSumPattern, - pub value_destroyed: CumulativeRawSumPattern, + pub value_created: BaseCumulativeSumPattern, + pub value_destroyed: BaseCumulativeSumPattern, } -impl CumulativeDistributionRawRelSumValuePattern { +impl BaseCumulativeDistributionRelSumValuePattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { + base: CentsUsdPattern2::new(client.clone(), _m(&acc, "realized_profit")), cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "realized_profit_cumulative")), distribution_flow: MetricPattern1::new(client.clone(), _m(&acc, "distribution_flow")), - raw: CentsUsdPattern2::new(client.clone(), _m(&acc, "realized_profit")), rel_to_rcap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_profit_rel_to_rcap")), sum: _1m1w1y24hPattern5::new(client.clone(), _m(&acc, "realized_profit_sum")), - value_created: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "profit_value_created")), - value_destroyed: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "profit_value_destroyed")), + value_created: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "profit_value_created")), + value_destroyed: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "profit_value_destroyed")), } } } /// Pattern struct for repeated tree structure. -pub struct CumulativeNegativeRawRelSumPattern2 { +pub struct BaseCumulativeNegativeRelSumPattern2 { + pub base: CentsUsdPattern2, pub cumulative: CentsUsdPattern2, pub negative: MetricPattern1, - pub raw: CentsUsdPattern2, pub rel_to_mcap: BpsPercentRatioPattern4, pub rel_to_own_gross: BpsPercentRatioPattern4, pub rel_to_own_mcap: BpsPercentRatioPattern, pub sum: _1m1w1y24hPattern5, } -impl CumulativeNegativeRawRelSumPattern2 { +impl BaseCumulativeNegativeRelSumPattern2 { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { + base: CentsUsdPattern2::new(client.clone(), _m(&acc, "unrealized_loss")), cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "unrealized_loss_cumulative")), negative: MetricPattern1::new(client.clone(), _m(&acc, "neg_unrealized_loss")), - raw: CentsUsdPattern2::new(client.clone(), _m(&acc, "unrealized_loss")), rel_to_mcap: BpsPercentRatioPattern4::new(client.clone(), _m(&acc, "unrealized_loss_rel_to_mcap")), rel_to_own_gross: BpsPercentRatioPattern4::new(client.clone(), _m(&acc, "unrealized_loss_rel_to_own_gross_pnl")), rel_to_own_mcap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "unrealized_loss_rel_to_own_mcap")), @@ -1541,14 +1515,40 @@ impl CumulativeNegativeRawRelSumPattern2 { } } +/// Pattern struct for repeated tree structure. +pub struct CapLossMvrvNetPriceProfitSoprPattern { + pub cap: CentsDeltaUsdPattern, + pub loss: BaseCumulativeNegativeSumPattern, + pub mvrv: MetricPattern1, + pub net_pnl: BaseCumulativeDeltaSumPattern, + pub price: BpsCentsRatioSatsUsdPattern, + pub profit: BaseCumulativeSumPattern3, + pub sopr: RatioValuePattern, +} + +impl CapLossMvrvNetPriceProfitSoprPattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + cap: CentsDeltaUsdPattern::new(client.clone(), _m(&acc, "realized_cap")), + loss: BaseCumulativeNegativeSumPattern::new(client.clone(), acc.clone()), + mvrv: MetricPattern1::new(client.clone(), _m(&acc, "mvrv")), + net_pnl: BaseCumulativeDeltaSumPattern::new(client.clone(), _m(&acc, "net_realized_pnl")), + price: BpsCentsRatioSatsUsdPattern::new(client.clone(), _m(&acc, "realized_price")), + profit: BaseCumulativeSumPattern3::new(client.clone(), _m(&acc, "realized_profit")), + sopr: RatioValuePattern::new(client.clone(), acc.clone()), + } + } +} + /// Pattern struct for repeated tree structure. pub struct GrossInvestedLossNetNuplProfitSentimentPattern2 { pub gross_pnl: CentsUsdPattern2, pub invested_capital: InPattern, - pub loss: CumulativeNegativeRawRelSumPattern2, + pub loss: BaseCumulativeNegativeRelSumPattern2, pub net_pnl: CentsRelUsdPattern2, pub nupl: BpsRatioPattern, - pub profit: CumulativeRawRelSumPattern2, + pub profit: BaseCumulativeRelSumPattern2, pub sentiment: GreedNetPainPattern, } @@ -1558,10 +1558,10 @@ impl GrossInvestedLossNetNuplProfitSentimentPattern2 { Self { gross_pnl: CentsUsdPattern2::new(client.clone(), _m(&acc, "unrealized_gross_pnl")), invested_capital: InPattern::new(client.clone(), _m(&acc, "invested_capital_in")), - loss: CumulativeNegativeRawRelSumPattern2::new(client.clone(), acc.clone()), + loss: BaseCumulativeNegativeRelSumPattern2::new(client.clone(), acc.clone()), net_pnl: CentsRelUsdPattern2::new(client.clone(), _m(&acc, "net_unrealized_pnl")), nupl: BpsRatioPattern::new(client.clone(), _m(&acc, "nupl")), - profit: CumulativeRawRelSumPattern2::new(client.clone(), _m(&acc, "unrealized_profit")), + profit: BaseCumulativeRelSumPattern2::new(client.clone(), _m(&acc, "unrealized_profit")), sentiment: GreedNetPainPattern::new(client.clone(), acc.clone()), } } @@ -1591,6 +1591,54 @@ impl _1m1w1y2y4yAllPattern { } } +/// Pattern struct for repeated tree structure. +pub struct BaseChangeCumulativeDeltaRelSumPattern { + pub base: CentsUsdPattern, + pub change_1m: RelPattern, + pub cumulative: CentsUsdPattern, + pub delta: ChangeRatePattern3, + pub rel_to_rcap: BpsPercentRatioPattern2, + pub sum: _1m1w1y24hPattern4, +} + +impl BaseChangeCumulativeDeltaRelSumPattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + base: CentsUsdPattern::new(client.clone(), _m(&acc, "realized_pnl")), + change_1m: RelPattern::new(client.clone(), _m(&acc, "pnl_change_1m_rel_to")), + cumulative: CentsUsdPattern::new(client.clone(), _m(&acc, "realized_pnl_cumulative")), + delta: ChangeRatePattern3::new(client.clone(), _m(&acc, "realized_pnl_delta")), + rel_to_rcap: BpsPercentRatioPattern2::new(client.clone(), _m(&acc, "realized_pnl_rel_to_rcap")), + sum: _1m1w1y24hPattern4::new(client.clone(), _m(&acc, "realized_pnl_sum")), + } + } +} + +/// Pattern struct for repeated tree structure. +pub struct BaseCumulativeRelSumPattern2 { + pub base: CentsUsdPattern2, + pub cumulative: CentsUsdPattern2, + pub rel_to_mcap: BpsPercentRatioPattern4, + pub rel_to_own_gross: BpsPercentRatioPattern4, + pub rel_to_own_mcap: BpsPercentRatioPattern4, + pub sum: _1m1w1y24hPattern5, +} + +impl BaseCumulativeRelSumPattern2 { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + base: CentsUsdPattern2::new(client.clone(), acc.clone()), + cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "cumulative")), + rel_to_mcap: BpsPercentRatioPattern4::new(client.clone(), _m(&acc, "rel_to_mcap")), + rel_to_own_gross: BpsPercentRatioPattern4::new(client.clone(), _m(&acc, "rel_to_own_gross_pnl")), + rel_to_own_mcap: BpsPercentRatioPattern4::new(client.clone(), _m(&acc, "rel_to_own_mcap")), + sum: _1m1w1y24hPattern5::new(client.clone(), _m(&acc, "sum")), + } + } +} + /// Pattern struct for repeated tree structure. pub struct BpsCentsPercentilesRatioSatsUsdPattern { pub bps: MetricPattern1, @@ -1642,10 +1690,10 @@ impl BtcCentsRelSatsUsdPattern3 { /// Pattern struct for repeated tree structure. pub struct CapLossMvrvPriceProfitSoprPattern { pub cap: CentsDeltaUsdPattern, - pub loss: CumulativeRawSumPattern3, + pub loss: BaseCumulativeSumPattern3, pub mvrv: MetricPattern1, pub price: BpsCentsRatioSatsUsdPattern, - pub profit: CumulativeRawSumPattern3, + pub profit: BaseCumulativeSumPattern3, pub sopr: ValuePattern, } @@ -1654,63 +1702,15 @@ impl CapLossMvrvPriceProfitSoprPattern { pub fn new(client: Arc, acc: String) -> Self { Self { cap: CentsDeltaUsdPattern::new(client.clone(), _m(&acc, "realized_cap")), - loss: CumulativeRawSumPattern3::new(client.clone(), _m(&acc, "realized_loss")), + loss: BaseCumulativeSumPattern3::new(client.clone(), _m(&acc, "realized_loss")), mvrv: MetricPattern1::new(client.clone(), _m(&acc, "mvrv")), price: BpsCentsRatioSatsUsdPattern::new(client.clone(), _m(&acc, "realized_price")), - profit: CumulativeRawSumPattern3::new(client.clone(), _m(&acc, "realized_profit")), + profit: BaseCumulativeSumPattern3::new(client.clone(), _m(&acc, "realized_profit")), sopr: ValuePattern::new(client.clone(), _m(&acc, "value")), } } } -/// Pattern struct for repeated tree structure. -pub struct ChangeCumulativeDeltaRawRelSumPattern { - pub change_1m: RelPattern, - pub cumulative: CentsUsdPattern, - pub delta: ChangeRatePattern3, - pub raw: CentsUsdPattern, - pub rel_to_rcap: BpsPercentRatioPattern2, - pub sum: _1m1w1y24hPattern4, -} - -impl ChangeCumulativeDeltaRawRelSumPattern { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - change_1m: RelPattern::new(client.clone(), _m(&acc, "pnl_change_1m_rel_to")), - cumulative: CentsUsdPattern::new(client.clone(), _m(&acc, "realized_pnl_cumulative")), - delta: ChangeRatePattern3::new(client.clone(), _m(&acc, "realized_pnl_delta")), - raw: CentsUsdPattern::new(client.clone(), _m(&acc, "realized_pnl")), - rel_to_rcap: BpsPercentRatioPattern2::new(client.clone(), _m(&acc, "realized_pnl_rel_to_rcap")), - sum: _1m1w1y24hPattern4::new(client.clone(), _m(&acc, "realized_pnl_sum")), - } - } -} - -/// Pattern struct for repeated tree structure. -pub struct CumulativeRawRelSumPattern2 { - pub cumulative: CentsUsdPattern2, - pub raw: CentsUsdPattern2, - pub rel_to_mcap: BpsPercentRatioPattern4, - pub rel_to_own_gross: BpsPercentRatioPattern4, - pub rel_to_own_mcap: BpsPercentRatioPattern4, - pub sum: _1m1w1y24hPattern5, -} - -impl CumulativeRawRelSumPattern2 { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "cumulative")), - raw: CentsUsdPattern2::new(client.clone(), acc.clone()), - rel_to_mcap: BpsPercentRatioPattern4::new(client.clone(), _m(&acc, "rel_to_mcap")), - rel_to_own_gross: BpsPercentRatioPattern4::new(client.clone(), _m(&acc, "rel_to_own_gross_pnl")), - rel_to_own_mcap: BpsPercentRatioPattern4::new(client.clone(), _m(&acc, "rel_to_own_mcap")), - sum: _1m1w1y24hPattern5::new(client.clone(), _m(&acc, "sum")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct DeltaHalfInRelTotalPattern { pub delta: ChangeRatePattern2, @@ -1827,6 +1827,28 @@ impl AddressOutputsRealizedSupplyUnrealizedPattern { } } +/// Pattern struct for repeated tree structure. +pub struct BaseCumulativeInSumPattern { + pub base: MetricPattern1, + pub cumulative: MetricPattern1, + pub in_loss: BaseCumulativeSumPattern4, + pub in_profit: BaseCumulativeSumPattern4, + pub sum: _1m1w1y24hPattern, +} + +impl BaseCumulativeInSumPattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + base: MetricPattern1::new(client.clone(), acc.clone()), + cumulative: MetricPattern1::new(client.clone(), _m(&acc, "cumulative")), + in_loss: BaseCumulativeSumPattern4::new(client.clone(), _m(&acc, "in_loss")), + in_profit: BaseCumulativeSumPattern4::new(client.clone(), _m(&acc, "in_profit")), + sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sum")), + } + } +} + /// Pattern struct for repeated tree structure. pub struct BpsCentsRatioSatsUsdPattern { pub bps: MetricPattern1, @@ -1895,10 +1917,10 @@ impl BtcCentsRelSatsUsdPattern2 { /// Pattern struct for repeated tree structure. pub struct CoindaysCoinyearsDormancySentVelocityPattern { - pub coindays_destroyed: CumulativeRawSumPattern, + pub coindays_destroyed: BaseCumulativeSumPattern, pub coinyears_destroyed: MetricPattern1, pub dormancy: MetricPattern1, - pub sent: CumulativeInRawSumPattern, + pub sent: BaseCumulativeInSumPattern, pub velocity: MetricPattern1, } @@ -1906,37 +1928,15 @@ impl CoindaysCoinyearsDormancySentVelocityPattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { - coindays_destroyed: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "coindays_destroyed")), + coindays_destroyed: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "coindays_destroyed")), coinyears_destroyed: MetricPattern1::new(client.clone(), _m(&acc, "coinyears_destroyed")), dormancy: MetricPattern1::new(client.clone(), _m(&acc, "dormancy")), - sent: CumulativeInRawSumPattern::new(client.clone(), _m(&acc, "sent")), + sent: BaseCumulativeInSumPattern::new(client.clone(), _m(&acc, "sent")), velocity: MetricPattern1::new(client.clone(), _m(&acc, "velocity")), } } } -/// Pattern struct for repeated tree structure. -pub struct CumulativeInRawSumPattern { - pub cumulative: MetricPattern1, - pub in_loss: CumulativeRawSumPattern4, - pub in_profit: CumulativeRawSumPattern4, - pub raw: MetricPattern1, - pub sum: _1m1w1y24hPattern, -} - -impl CumulativeInRawSumPattern { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - cumulative: MetricPattern1::new(client.clone(), _m(&acc, "cumulative")), - in_loss: CumulativeRawSumPattern4::new(client.clone(), _m(&acc, "in_loss")), - in_profit: CumulativeRawSumPattern4::new(client.clone(), _m(&acc, "in_profit")), - raw: MetricPattern1::new(client.clone(), acc.clone()), - sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sum")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct DeltaHalfInTotalPattern2 { pub delta: ChangeRatePattern2, @@ -2191,8 +2191,8 @@ impl _1y2y4yAllPattern { pub struct AdjustedRatioValuePattern { pub adjusted: RatioValuePattern2, pub ratio: _1m1w1y24hPattern, - pub value_created: CumulativeRawSumPattern, - pub value_destroyed: CumulativeRawSumPattern, + pub value_created: BaseCumulativeSumPattern, + pub value_destroyed: BaseCumulativeSumPattern, } impl AdjustedRatioValuePattern { @@ -2201,8 +2201,48 @@ impl AdjustedRatioValuePattern { Self { adjusted: RatioValuePattern2::new(client.clone(), acc.clone()), ratio: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sopr")), - value_created: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "value_created")), - value_destroyed: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "value_destroyed")), + value_created: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "value_created")), + value_destroyed: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "value_destroyed")), + } + } +} + +/// Pattern struct for repeated tree structure. +pub struct BaseCumulativeDeltaSumPattern { + pub base: CentsUsdPattern, + pub cumulative: CentsUsdPattern, + pub delta: ChangeRatePattern3, + pub sum: _1m1w1y24hPattern4, +} + +impl BaseCumulativeDeltaSumPattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + base: CentsUsdPattern::new(client.clone(), acc.clone()), + cumulative: CentsUsdPattern::new(client.clone(), _m(&acc, "cumulative")), + delta: ChangeRatePattern3::new(client.clone(), _m(&acc, "delta")), + sum: _1m1w1y24hPattern4::new(client.clone(), _m(&acc, "sum")), + } + } +} + +/// Pattern struct for repeated tree structure. +pub struct BaseCumulativeNegativeSumPattern { + pub base: CentsUsdPattern2, + pub cumulative: CentsUsdPattern2, + pub negative: MetricPattern1, + pub sum: _1m1w1y24hPattern5, +} + +impl BaseCumulativeNegativeSumPattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + base: CentsUsdPattern2::new(client.clone(), _m(&acc, "unrealized_loss")), + cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "unrealized_loss_cumulative")), + negative: MetricPattern1::new(client.clone(), _m(&acc, "neg_unrealized_loss")), + sum: _1m1w1y24hPattern5::new(client.clone(), _m(&acc, "unrealized_loss_sum")), } } } @@ -2287,62 +2327,22 @@ impl CentsRelUsdPattern2 { } } -/// Pattern struct for repeated tree structure. -pub struct CumulativeDeltaRawSumPattern { - pub cumulative: CentsUsdPattern, - pub delta: ChangeRatePattern3, - pub raw: CentsUsdPattern, - pub sum: _1m1w1y24hPattern4, -} - -impl CumulativeDeltaRawSumPattern { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - cumulative: CentsUsdPattern::new(client.clone(), _m(&acc, "cumulative")), - delta: ChangeRatePattern3::new(client.clone(), _m(&acc, "delta")), - raw: CentsUsdPattern::new(client.clone(), acc.clone()), - sum: _1m1w1y24hPattern4::new(client.clone(), _m(&acc, "sum")), - } - } -} - -/// Pattern struct for repeated tree structure. -pub struct CumulativeNegativeRawSumPattern { - pub cumulative: CentsUsdPattern2, - pub negative: MetricPattern1, - pub raw: CentsUsdPattern2, - pub sum: _1m1w1y24hPattern5, -} - -impl CumulativeNegativeRawSumPattern { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "unrealized_loss_cumulative")), - negative: MetricPattern1::new(client.clone(), _m(&acc, "neg_unrealized_loss")), - raw: CentsUsdPattern2::new(client.clone(), _m(&acc, "unrealized_loss")), - sum: _1m1w1y24hPattern5::new(client.clone(), _m(&acc, "unrealized_loss_sum")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct LossNetNuplProfitPattern { - pub loss: CumulativeNegativeRawSumPattern, + pub loss: BaseCumulativeNegativeSumPattern, pub net_pnl: CentsUsdPattern, pub nupl: BpsRatioPattern, - pub profit: CumulativeRawSumPattern3, + pub profit: BaseCumulativeSumPattern3, } impl LossNetNuplProfitPattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { - loss: CumulativeNegativeRawSumPattern::new(client.clone(), acc.clone()), + loss: BaseCumulativeNegativeSumPattern::new(client.clone(), acc.clone()), net_pnl: CentsUsdPattern::new(client.clone(), _m(&acc, "net_unrealized_pnl")), nupl: BpsRatioPattern::new(client.clone(), _m(&acc, "nupl")), - profit: CumulativeRawSumPattern3::new(client.clone(), _m(&acc, "unrealized_profit")), + profit: BaseCumulativeSumPattern3::new(client.clone(), _m(&acc, "unrealized_profit")), } } } @@ -2407,20 +2407,92 @@ impl _1m1w1y24hPattern { } } +/// Pattern struct for repeated tree structure. +pub struct BaseCumulativeSumPattern4 { + pub base: BtcCentsSatsUsdPattern, + pub cumulative: BtcCentsSatsUsdPattern, + pub sum: _1m1w1y24hPattern6, +} + +impl BaseCumulativeSumPattern4 { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + base: BtcCentsSatsUsdPattern::new(client.clone(), acc.clone()), + cumulative: BtcCentsSatsUsdPattern::new(client.clone(), _m(&acc, "cumulative")), + sum: _1m1w1y24hPattern6::new(client.clone(), _m(&acc, "sum")), + } + } +} + +/// Pattern struct for repeated tree structure. +pub struct BaseCumulativeRelPattern { + pub base: MetricPattern1, + pub cumulative: MetricPattern1, + pub rel_to_rcap: BpsPercentRatioPattern, +} + +impl BaseCumulativeRelPattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + base: MetricPattern1::new(client.clone(), acc.clone()), + cumulative: MetricPattern1::new(client.clone(), _m(&acc, "cumulative")), + rel_to_rcap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "rel_to_rcap")), + } + } +} + +/// Pattern struct for repeated tree structure. +pub struct BaseCumulativeSumPattern3 { + pub base: CentsUsdPattern2, + pub cumulative: CentsUsdPattern2, + pub sum: _1m1w1y24hPattern5, +} + +impl BaseCumulativeSumPattern3 { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + base: CentsUsdPattern2::new(client.clone(), acc.clone()), + cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "cumulative")), + sum: _1m1w1y24hPattern5::new(client.clone(), _m(&acc, "sum")), + } + } +} + +/// Pattern struct for repeated tree structure. +pub struct BaseCumulativeSumPattern2 { + pub base: MetricPattern1, + pub cumulative: MetricPattern1, + pub sum: _1m1w1y24hPattern, +} + +impl BaseCumulativeSumPattern2 { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + base: MetricPattern1::new(client.clone(), acc.clone()), + cumulative: MetricPattern1::new(client.clone(), _m(&acc, "cumulative")), + sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sum")), + } + } +} + /// Pattern struct for repeated tree structure. pub struct BlocksDominanceRewardsPattern { - pub blocks_mined: CumulativeRawSumPattern2, + pub blocks_mined: BaseCumulativeSumPattern2, pub dominance: _1m1w1y24hBpsPercentRatioPattern, - pub rewards: CumulativeRawSumPattern4, + pub rewards: BaseCumulativeSumPattern4, } impl BlocksDominanceRewardsPattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { - blocks_mined: CumulativeRawSumPattern2::new(client.clone(), _m(&acc, "blocks_mined")), + blocks_mined: BaseCumulativeSumPattern2::new(client.clone(), _m(&acc, "blocks_mined")), dominance: _1m1w1y24hBpsPercentRatioPattern::new(client.clone(), _m(&acc, "dominance")), - rewards: CumulativeRawSumPattern4::new(client.clone(), _m(&acc, "rewards")), + rewards: BaseCumulativeSumPattern4::new(client.clone(), _m(&acc, "rewards")), } } } @@ -2569,78 +2641,6 @@ impl CentsSatsUsdPattern { } } -/// Pattern struct for repeated tree structure. -pub struct CumulativeRawSumPattern4 { - pub cumulative: BtcCentsSatsUsdPattern, - pub raw: BtcCentsSatsUsdPattern, - pub sum: _1m1w1y24hPattern6, -} - -impl CumulativeRawSumPattern4 { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - cumulative: BtcCentsSatsUsdPattern::new(client.clone(), _m(&acc, "cumulative")), - raw: BtcCentsSatsUsdPattern::new(client.clone(), acc.clone()), - sum: _1m1w1y24hPattern6::new(client.clone(), _m(&acc, "sum")), - } - } -} - -/// Pattern struct for repeated tree structure. -pub struct CumulativeRawRelPattern { - pub cumulative: MetricPattern1, - pub raw: MetricPattern1, - pub rel_to_rcap: BpsPercentRatioPattern, -} - -impl CumulativeRawRelPattern { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - cumulative: MetricPattern1::new(client.clone(), _m(&acc, "cumulative")), - raw: MetricPattern1::new(client.clone(), acc.clone()), - rel_to_rcap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "rel_to_rcap")), - } - } -} - -/// Pattern struct for repeated tree structure. -pub struct CumulativeRawSumPattern3 { - pub cumulative: CentsUsdPattern2, - pub raw: CentsUsdPattern2, - pub sum: _1m1w1y24hPattern5, -} - -impl CumulativeRawSumPattern3 { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "cumulative")), - raw: CentsUsdPattern2::new(client.clone(), acc.clone()), - sum: _1m1w1y24hPattern5::new(client.clone(), _m(&acc, "sum")), - } - } -} - -/// Pattern struct for repeated tree structure. -pub struct CumulativeRawSumPattern2 { - pub cumulative: MetricPattern1, - pub raw: MetricPattern1, - pub sum: _1m1w1y24hPattern, -} - -impl CumulativeRawSumPattern2 { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - cumulative: MetricPattern1::new(client.clone(), _m(&acc, "cumulative")), - raw: MetricPattern1::new(client.clone(), acc.clone()), - sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sum")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct DeltaHalfTotalPattern { pub delta: ChangeRatePattern2, @@ -2679,18 +2679,18 @@ impl GreedNetPainPattern { /// Pattern struct for repeated tree structure. pub struct LossNuplProfitPattern { - pub loss: CumulativeRawSumPattern3, + pub loss: BaseCumulativeSumPattern3, pub nupl: BpsRatioPattern, - pub profit: CumulativeRawSumPattern3, + pub profit: BaseCumulativeSumPattern3, } impl LossNuplProfitPattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { - loss: CumulativeRawSumPattern3::new(client.clone(), _m(&acc, "unrealized_loss")), + loss: BaseCumulativeSumPattern3::new(client.clone(), _m(&acc, "unrealized_loss")), nupl: BpsRatioPattern::new(client.clone(), _m(&acc, "nupl")), - profit: CumulativeRawSumPattern3::new(client.clone(), _m(&acc, "unrealized_profit")), + profit: BaseCumulativeSumPattern3::new(client.clone(), _m(&acc, "unrealized_profit")), } } } @@ -2716,8 +2716,8 @@ impl LowerPriceUpperPattern { /// Pattern struct for repeated tree structure. pub struct RatioValuePattern2 { pub ratio: _1m1w1y24hPattern, - pub value_created: CumulativeRawSumPattern, - pub value_destroyed: CumulativeRawSumPattern, + pub value_created: BaseCumulativeSumPattern, + pub value_destroyed: BaseCumulativeSumPattern, } impl RatioValuePattern2 { @@ -2725,8 +2725,8 @@ impl RatioValuePattern2 { pub fn new(client: Arc, acc: String) -> Self { Self { ratio: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "asopr")), - value_created: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "adj_value_created")), - value_destroyed: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "adj_value_destroyed")), + value_created: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "adj_value_created")), + value_destroyed: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "adj_value_destroyed")), } } } @@ -2734,8 +2734,8 @@ impl RatioValuePattern2 { /// Pattern struct for repeated tree structure. pub struct RatioValuePattern { pub ratio: _24hPattern, - pub value_created: CumulativeRawSumPattern, - pub value_destroyed: CumulativeRawSumPattern, + pub value_created: BaseCumulativeSumPattern, + pub value_destroyed: BaseCumulativeSumPattern, } impl RatioValuePattern { @@ -2743,8 +2743,8 @@ impl RatioValuePattern { pub fn new(client: Arc, acc: String) -> Self { Self { ratio: _24hPattern::new(client.clone(), _m(&acc, "sopr_24h")), - value_created: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "value_created")), - value_destroyed: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "value_destroyed")), + value_created: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "value_created")), + value_destroyed: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "value_destroyed")), } } } @@ -2768,18 +2768,18 @@ impl _6bBlockTxindexPattern { } /// Pattern struct for repeated tree structure. -pub struct CumulativeRawSumPattern { +pub struct BaseCumulativeSumPattern { + pub base: MetricPattern1, pub cumulative: MetricPattern1, - pub raw: MetricPattern1, pub sum: _1m1w1y24hPattern, } -impl CumulativeRawSumPattern { +impl BaseCumulativeSumPattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { + base: MetricPattern1::new(client.clone(), acc.clone()), cumulative: MetricPattern1::new(client.clone(), _m(&acc, "cumulative")), - raw: MetricPattern1::new(client.clone(), acc.clone()), sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sum")), } } @@ -2787,7 +2787,7 @@ impl CumulativeRawSumPattern { /// Pattern struct for repeated tree structure. pub struct BlocksDominancePattern { - pub blocks_mined: CumulativeRawSumPattern2, + pub blocks_mined: BaseCumulativeSumPattern2, pub dominance: BpsPercentRatioPattern4, } @@ -2795,7 +2795,7 @@ impl BlocksDominancePattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { - blocks_mined: CumulativeRawSumPattern2::new(client.clone(), _m(&acc, "blocks_mined")), + blocks_mined: BaseCumulativeSumPattern2::new(client.clone(), _m(&acc, "blocks_mined")), dominance: BpsPercentRatioPattern4::new(client.clone(), _m(&acc, "dominance")), } } @@ -2915,16 +2915,16 @@ impl ChangeRatePattern3 { /// Pattern struct for repeated tree structure. pub struct CoindaysSentPattern { - pub coindays_destroyed: CumulativeRawSumPattern, - pub sent: CumulativeInRawSumPattern, + pub coindays_destroyed: BaseCumulativeSumPattern, + pub sent: BaseCumulativeInSumPattern, } impl CoindaysSentPattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { - coindays_destroyed: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "coindays_destroyed")), - sent: CumulativeInRawSumPattern::new(client.clone(), _m(&acc, "sent")), + coindays_destroyed: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "coindays_destroyed")), + sent: BaseCumulativeInSumPattern::new(client.clone(), _m(&acc, "sent")), } } } @@ -3027,16 +3027,16 @@ impl SdSmaPattern { /// Pattern struct for repeated tree structure. pub struct ValuePattern { - pub value_created: CumulativeRawSumPattern, - pub value_destroyed: CumulativeRawSumPattern, + pub value_created: BaseCumulativeSumPattern, + pub value_destroyed: BaseCumulativeSumPattern, } impl ValuePattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { - value_created: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "created")), - value_destroyed: CumulativeRawSumPattern::new(client.clone(), _m(&acc, "destroyed")), + value_created: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "created")), + value_destroyed: BaseCumulativeSumPattern::new(client.clone(), _m(&acc, "destroyed")), } } } @@ -3139,7 +3139,7 @@ pub struct MetricsTree_Blocks { pub lookback: MetricsTree_Blocks_Lookback, pub interval: _1m1w1y24hHeightPattern, pub halving: MetricsTree_Blocks_Halving, - pub vbytes: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern, + pub vbytes: AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern, pub fullness: MetricsTree_Blocks_Fullness, } @@ -3155,7 +3155,7 @@ impl MetricsTree_Blocks { lookback: MetricsTree_Blocks_Lookback::new(client.clone(), format!("{base_path}_lookback")), interval: _1m1w1y24hHeightPattern::new(client.clone(), "block_interval".to_string()), halving: MetricsTree_Blocks_Halving::new(client.clone(), format!("{base_path}_halving")), - vbytes: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern::new(client.clone(), "block_vbytes".to_string()), + vbytes: AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "block_vbytes".to_string()), fullness: MetricsTree_Blocks_Fullness::new(client.clone(), format!("{base_path}_fullness")), } } @@ -3163,7 +3163,8 @@ impl MetricsTree_Blocks { /// Metrics tree node. pub struct MetricsTree_Blocks_Difficulty { - pub raw: MetricPattern1, + pub raw: MetricPattern18, + pub base: MetricPattern2, pub as_hash: MetricPattern1, pub adjustment: BpsPercentRatioPattern2, pub epoch: MetricPattern1, @@ -3174,7 +3175,8 @@ pub struct MetricsTree_Blocks_Difficulty { impl MetricsTree_Blocks_Difficulty { pub fn new(client: Arc, base_path: String) -> Self { Self { - raw: MetricPattern1::new(client.clone(), "difficulty".to_string()), + raw: MetricPattern18::new(client.clone(), "difficulty".to_string()), + base: MetricPattern2::new(client.clone(), "difficulty".to_string()), as_hash: MetricPattern1::new(client.clone(), "difficulty_as_hash".to_string()), adjustment: BpsPercentRatioPattern2::new(client.clone(), "difficulty_adjustment".to_string()), epoch: MetricPattern1::new(client.clone(), "difficulty_epoch".to_string()), @@ -3270,14 +3272,14 @@ impl MetricsTree_Blocks_Weight { /// Metrics tree node. pub struct MetricsTree_Blocks_Count { pub target: MetricPattern1, - pub total: CumulativeRawSumPattern2, + pub total: BaseCumulativeSumPattern2, } impl MetricsTree_Blocks_Count { pub fn new(client: Arc, base_path: String) -> Self { Self { target: MetricPattern1::new(client.clone(), "block_count_target".to_string()), - total: CumulativeRawSumPattern2::new(client.clone(), "block_count".to_string()), + total: BaseCumulativeSumPattern2::new(client.clone(), "block_count".to_string()), } } } @@ -3469,14 +3471,14 @@ impl MetricsTree_Transactions_Raw { /// Metrics tree node. pub struct MetricsTree_Transactions_Count { - pub total: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern, + pub total: AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern, pub is_coinbase: MetricPattern19, } impl MetricsTree_Transactions_Count { pub fn new(client: Arc, base_path: String) -> Self { Self { - total: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern::new(client.clone(), "tx_count".to_string()), + total: AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), "tx_count".to_string()), is_coinbase: MetricPattern19::new(client.clone(), "is_coinbase".to_string()), } } @@ -3518,25 +3520,25 @@ impl MetricsTree_Transactions_Fees { /// Metrics tree node. pub struct MetricsTree_Transactions_Versions { - pub v1: CumulativeRawSumPattern, - pub v2: CumulativeRawSumPattern, - pub v3: CumulativeRawSumPattern, + pub v1: BaseCumulativeSumPattern, + pub v2: BaseCumulativeSumPattern, + pub v3: BaseCumulativeSumPattern, } impl MetricsTree_Transactions_Versions { pub fn new(client: Arc, base_path: String) -> Self { Self { - v1: CumulativeRawSumPattern::new(client.clone(), "tx_v1".to_string()), - v2: CumulativeRawSumPattern::new(client.clone(), "tx_v2".to_string()), - v3: CumulativeRawSumPattern::new(client.clone(), "tx_v3".to_string()), + v1: BaseCumulativeSumPattern::new(client.clone(), "tx_v1".to_string()), + v2: BaseCumulativeSumPattern::new(client.clone(), "tx_v2".to_string()), + v3: BaseCumulativeSumPattern::new(client.clone(), "tx_v3".to_string()), } } } /// Metrics tree node. pub struct MetricsTree_Transactions_Volume { - pub sent_sum: CumulativeRawSumPattern4, - pub received_sum: CumulativeRawSumPattern4, + pub sent_sum: BaseCumulativeSumPattern4, + pub received_sum: BaseCumulativeSumPattern4, pub tx_per_sec: MetricPattern1, pub outputs_per_sec: MetricPattern1, pub inputs_per_sec: MetricPattern1, @@ -3545,8 +3547,8 @@ pub struct MetricsTree_Transactions_Volume { impl MetricsTree_Transactions_Volume { pub fn new(client: Arc, base_path: String) -> Self { Self { - sent_sum: CumulativeRawSumPattern4::new(client.clone(), "sent_sum".to_string()), - received_sum: CumulativeRawSumPattern4::new(client.clone(), "received_sum".to_string()), + sent_sum: BaseCumulativeSumPattern4::new(client.clone(), "sent_sum".to_string()), + received_sum: BaseCumulativeSumPattern4::new(client.clone(), "received_sum".to_string()), tx_per_sec: MetricPattern1::new(client.clone(), "tx_per_sec".to_string()), outputs_per_sec: MetricPattern1::new(client.clone(), "outputs_per_sec".to_string()), inputs_per_sec: MetricPattern1::new(client.clone(), "inputs_per_sec".to_string()), @@ -3926,29 +3928,29 @@ impl MetricsTree_Addresses_Activity { /// Metrics tree node. pub struct MetricsTree_Addresses_New { - pub all: CumulativeRawSumPattern, - pub p2pk65: CumulativeRawSumPattern, - pub p2pk33: CumulativeRawSumPattern, - pub p2pkh: CumulativeRawSumPattern, - pub p2sh: CumulativeRawSumPattern, - pub p2wpkh: CumulativeRawSumPattern, - pub p2wsh: CumulativeRawSumPattern, - pub p2tr: CumulativeRawSumPattern, - pub p2a: CumulativeRawSumPattern, + pub all: BaseCumulativeSumPattern, + pub p2pk65: BaseCumulativeSumPattern, + pub p2pk33: BaseCumulativeSumPattern, + pub p2pkh: BaseCumulativeSumPattern, + pub p2sh: BaseCumulativeSumPattern, + pub p2wpkh: BaseCumulativeSumPattern, + pub p2wsh: BaseCumulativeSumPattern, + pub p2tr: BaseCumulativeSumPattern, + pub p2a: BaseCumulativeSumPattern, } impl MetricsTree_Addresses_New { pub fn new(client: Arc, base_path: String) -> Self { Self { - all: CumulativeRawSumPattern::new(client.clone(), "new_address_count".to_string()), - p2pk65: CumulativeRawSumPattern::new(client.clone(), "p2pk65_new_address_count".to_string()), - p2pk33: CumulativeRawSumPattern::new(client.clone(), "p2pk33_new_address_count".to_string()), - p2pkh: CumulativeRawSumPattern::new(client.clone(), "p2pkh_new_address_count".to_string()), - p2sh: CumulativeRawSumPattern::new(client.clone(), "p2sh_new_address_count".to_string()), - p2wpkh: CumulativeRawSumPattern::new(client.clone(), "p2wpkh_new_address_count".to_string()), - p2wsh: CumulativeRawSumPattern::new(client.clone(), "p2wsh_new_address_count".to_string()), - p2tr: CumulativeRawSumPattern::new(client.clone(), "p2tr_new_address_count".to_string()), - p2a: CumulativeRawSumPattern::new(client.clone(), "p2a_new_address_count".to_string()), + all: BaseCumulativeSumPattern::new(client.clone(), "new_address_count".to_string()), + p2pk65: BaseCumulativeSumPattern::new(client.clone(), "p2pk65_new_address_count".to_string()), + p2pk33: BaseCumulativeSumPattern::new(client.clone(), "p2pk33_new_address_count".to_string()), + p2pkh: BaseCumulativeSumPattern::new(client.clone(), "p2pkh_new_address_count".to_string()), + p2sh: BaseCumulativeSumPattern::new(client.clone(), "p2sh_new_address_count".to_string()), + p2wpkh: BaseCumulativeSumPattern::new(client.clone(), "p2wpkh_new_address_count".to_string()), + p2wsh: BaseCumulativeSumPattern::new(client.clone(), "p2wsh_new_address_count".to_string()), + p2tr: BaseCumulativeSumPattern::new(client.clone(), "p2tr_new_address_count".to_string()), + p2a: BaseCumulativeSumPattern::new(client.clone(), "p2a_new_address_count".to_string()), } } } @@ -4082,37 +4084,37 @@ impl MetricsTree_Scripts_Raw_Unknown { /// Metrics tree node. pub struct MetricsTree_Scripts_Count { - pub p2a: CumulativeRawSumPattern, - pub p2ms: CumulativeRawSumPattern, - pub p2pk33: CumulativeRawSumPattern, - pub p2pk65: CumulativeRawSumPattern, - pub p2pkh: CumulativeRawSumPattern, - pub p2sh: CumulativeRawSumPattern, - pub p2tr: CumulativeRawSumPattern, - pub p2wpkh: CumulativeRawSumPattern, - pub p2wsh: CumulativeRawSumPattern, - pub opreturn: CumulativeRawSumPattern, - pub emptyoutput: CumulativeRawSumPattern, - pub unknownoutput: CumulativeRawSumPattern, - pub segwit: CumulativeRawSumPattern, + pub p2a: BaseCumulativeSumPattern, + pub p2ms: BaseCumulativeSumPattern, + pub p2pk33: BaseCumulativeSumPattern, + pub p2pk65: BaseCumulativeSumPattern, + pub p2pkh: BaseCumulativeSumPattern, + pub p2sh: BaseCumulativeSumPattern, + pub p2tr: BaseCumulativeSumPattern, + pub p2wpkh: BaseCumulativeSumPattern, + pub p2wsh: BaseCumulativeSumPattern, + pub opreturn: BaseCumulativeSumPattern, + pub emptyoutput: BaseCumulativeSumPattern, + pub unknownoutput: BaseCumulativeSumPattern, + pub segwit: BaseCumulativeSumPattern, } impl MetricsTree_Scripts_Count { pub fn new(client: Arc, base_path: String) -> Self { Self { - p2a: CumulativeRawSumPattern::new(client.clone(), "p2a_count".to_string()), - p2ms: CumulativeRawSumPattern::new(client.clone(), "p2ms_count".to_string()), - p2pk33: CumulativeRawSumPattern::new(client.clone(), "p2pk33_count".to_string()), - p2pk65: CumulativeRawSumPattern::new(client.clone(), "p2pk65_count".to_string()), - p2pkh: CumulativeRawSumPattern::new(client.clone(), "p2pkh_count".to_string()), - p2sh: CumulativeRawSumPattern::new(client.clone(), "p2sh_count".to_string()), - p2tr: CumulativeRawSumPattern::new(client.clone(), "p2tr_count".to_string()), - p2wpkh: CumulativeRawSumPattern::new(client.clone(), "p2wpkh_count".to_string()), - p2wsh: CumulativeRawSumPattern::new(client.clone(), "p2wsh_count".to_string()), - opreturn: CumulativeRawSumPattern::new(client.clone(), "opreturn_count".to_string()), - emptyoutput: CumulativeRawSumPattern::new(client.clone(), "emptyoutput_count".to_string()), - unknownoutput: CumulativeRawSumPattern::new(client.clone(), "unknownoutput_count".to_string()), - segwit: CumulativeRawSumPattern::new(client.clone(), "segwit_count".to_string()), + p2a: BaseCumulativeSumPattern::new(client.clone(), "p2a_count".to_string()), + p2ms: BaseCumulativeSumPattern::new(client.clone(), "p2ms_count".to_string()), + p2pk33: BaseCumulativeSumPattern::new(client.clone(), "p2pk33_count".to_string()), + p2pk65: BaseCumulativeSumPattern::new(client.clone(), "p2pk65_count".to_string()), + p2pkh: BaseCumulativeSumPattern::new(client.clone(), "p2pkh_count".to_string()), + p2sh: BaseCumulativeSumPattern::new(client.clone(), "p2sh_count".to_string()), + p2tr: BaseCumulativeSumPattern::new(client.clone(), "p2tr_count".to_string()), + p2wpkh: BaseCumulativeSumPattern::new(client.clone(), "p2wpkh_count".to_string()), + p2wsh: BaseCumulativeSumPattern::new(client.clone(), "p2wsh_count".to_string()), + opreturn: BaseCumulativeSumPattern::new(client.clone(), "opreturn_count".to_string()), + emptyoutput: BaseCumulativeSumPattern::new(client.clone(), "emptyoutput_count".to_string()), + unknownoutput: BaseCumulativeSumPattern::new(client.clone(), "unknownoutput_count".to_string()), + segwit: BaseCumulativeSumPattern::new(client.clone(), "segwit_count".to_string()), } } } @@ -4177,19 +4179,19 @@ impl MetricsTree_Mining { /// Metrics tree node. pub struct MetricsTree_Mining_Rewards { - pub coinbase: CumulativeRawSumPattern4, + pub coinbase: BaseCumulativeSumPattern4, pub subsidy: MetricsTree_Mining_Rewards_Subsidy, pub fees: MetricsTree_Mining_Rewards_Fees, - pub unclaimed: CumulativeRawSumPattern4, + pub unclaimed: BaseCumulativeSumPattern4, } impl MetricsTree_Mining_Rewards { pub fn new(client: Arc, base_path: String) -> Self { Self { - coinbase: CumulativeRawSumPattern4::new(client.clone(), "coinbase".to_string()), + coinbase: BaseCumulativeSumPattern4::new(client.clone(), "coinbase".to_string()), subsidy: MetricsTree_Mining_Rewards_Subsidy::new(client.clone(), format!("{base_path}_subsidy")), fees: MetricsTree_Mining_Rewards_Fees::new(client.clone(), format!("{base_path}_fees")), - unclaimed: CumulativeRawSumPattern4::new(client.clone(), "unclaimed_rewards".to_string()), + unclaimed: BaseCumulativeSumPattern4::new(client.clone(), "unclaimed_rewards".to_string()), } } } @@ -4280,7 +4282,7 @@ impl MetricsTree_Mining_Hashrate { /// Metrics tree node. pub struct MetricsTree_Mining_Hashrate_Rate { - pub raw: MetricPattern1, + pub base: MetricPattern1, pub sma: MetricsTree_Mining_Hashrate_Rate_Sma, pub ath: MetricPattern1, pub drawdown: BpsPercentRatioPattern5, @@ -4289,7 +4291,7 @@ pub struct MetricsTree_Mining_Hashrate_Rate { impl MetricsTree_Mining_Hashrate_Rate { pub fn new(client: Arc, base_path: String) -> Self { Self { - raw: MetricPattern1::new(client.clone(), "hash_rate".to_string()), + base: MetricPattern1::new(client.clone(), "hash_rate".to_string()), sma: MetricsTree_Mining_Hashrate_Rate_Sma::new(client.clone(), format!("{base_path}_sma")), ath: MetricPattern1::new(client.clone(), "hash_rate_ath".to_string()), drawdown: BpsPercentRatioPattern5::new(client.clone(), "hash_rate_drawdown".to_string()), @@ -4345,8 +4347,8 @@ impl MetricsTree_Cointime { /// Metrics tree node. pub struct MetricsTree_Cointime_Activity { - pub coinblocks_created: CumulativeRawSumPattern, - pub coinblocks_stored: CumulativeRawSumPattern, + pub coinblocks_created: BaseCumulativeSumPattern, + pub coinblocks_stored: BaseCumulativeSumPattern, pub liveliness: MetricPattern1, pub vaultedness: MetricPattern1, pub ratio: MetricPattern1, @@ -4355,8 +4357,8 @@ pub struct MetricsTree_Cointime_Activity { impl MetricsTree_Cointime_Activity { pub fn new(client: Arc, base_path: String) -> Self { Self { - coinblocks_created: CumulativeRawSumPattern::new(client.clone(), "coinblocks_created".to_string()), - coinblocks_stored: CumulativeRawSumPattern::new(client.clone(), "coinblocks_stored".to_string()), + coinblocks_created: BaseCumulativeSumPattern::new(client.clone(), "coinblocks_created".to_string()), + coinblocks_stored: BaseCumulativeSumPattern::new(client.clone(), "coinblocks_stored".to_string()), liveliness: MetricPattern1::new(client.clone(), "liveliness".to_string()), vaultedness: MetricPattern1::new(client.clone(), "vaultedness".to_string()), ratio: MetricPattern1::new(client.clone(), "activity_to_vaultedness_ratio".to_string()), @@ -4381,19 +4383,19 @@ impl MetricsTree_Cointime_Supply { /// Metrics tree node. pub struct MetricsTree_Cointime_Value { - pub destroyed: CumulativeRawSumPattern, - pub created: CumulativeRawSumPattern, - pub stored: CumulativeRawSumPattern, - pub vocdd: CumulativeRawSumPattern, + pub destroyed: BaseCumulativeSumPattern, + pub created: BaseCumulativeSumPattern, + pub stored: BaseCumulativeSumPattern, + pub vocdd: BaseCumulativeSumPattern, } impl MetricsTree_Cointime_Value { pub fn new(client: Arc, base_path: String) -> Self { Self { - destroyed: CumulativeRawSumPattern::new(client.clone(), "cointime_value_destroyed".to_string()), - created: CumulativeRawSumPattern::new(client.clone(), "cointime_value_created".to_string()), - stored: CumulativeRawSumPattern::new(client.clone(), "cointime_value_stored".to_string()), - vocdd: CumulativeRawSumPattern::new(client.clone(), "vocdd".to_string()), + destroyed: BaseCumulativeSumPattern::new(client.clone(), "cointime_value_destroyed".to_string()), + created: BaseCumulativeSumPattern::new(client.clone(), "cointime_value_created".to_string()), + stored: BaseCumulativeSumPattern::new(client.clone(), "cointime_value_stored".to_string()), + vocdd: BaseCumulativeSumPattern::new(client.clone(), "vocdd".to_string()), } } } @@ -4486,14 +4488,14 @@ impl MetricsTree_Cointime_ReserveRisk { /// Metrics tree node. pub struct MetricsTree_Cointime_CoinblocksDestroyed { - pub raw: MetricPattern1, + pub base: MetricPattern1, pub cumulative: MetricPattern1, } impl MetricsTree_Cointime_CoinblocksDestroyed { pub fn new(client: Arc, base_path: String) -> Self { Self { - raw: MetricPattern1::new(client.clone(), "coinblocks_destroyed".to_string()), + base: MetricPattern1::new(client.clone(), "coinblocks_destroyed".to_string()), cumulative: MetricPattern1::new(client.clone(), "coinblocks_destroyed_cumulative".to_string()), } } @@ -6465,15 +6467,15 @@ impl MetricsTree_Supply { /// Metrics tree node. pub struct MetricsTree_Supply_Burned { - pub opreturn: CumulativeRawSumPattern4, - pub unspendable: CumulativeRawSumPattern4, + pub opreturn: BaseCumulativeSumPattern4, + pub unspendable: BaseCumulativeSumPattern4, } impl MetricsTree_Supply_Burned { pub fn new(client: Arc, base_path: String) -> Self { Self { - opreturn: CumulativeRawSumPattern4::new(client.clone(), "opreturn_supply".to_string()), - unspendable: CumulativeRawSumPattern4::new(client.clone(), "unspendable_supply".to_string()), + opreturn: BaseCumulativeSumPattern4::new(client.clone(), "opreturn_supply".to_string()), + unspendable: BaseCumulativeSumPattern4::new(client.clone(), "unspendable_supply".to_string()), } } } @@ -6619,7 +6621,7 @@ impl MetricsTree_Cohorts_Utxo_All_Unrealized { /// Metrics tree node. pub struct MetricsTree_Cohorts_Utxo_All_Unrealized_Loss { pub negative: MetricPattern1, - pub raw: CentsUsdPattern2, + pub base: CentsUsdPattern2, pub cumulative: CentsUsdPattern2, pub sum: _1m1w1y24hPattern5, pub rel_to_mcap: BpsPercentRatioPattern4, @@ -6630,7 +6632,7 @@ impl MetricsTree_Cohorts_Utxo_All_Unrealized_Loss { pub fn new(client: Arc, base_path: String) -> Self { Self { negative: MetricPattern1::new(client.clone(), "neg_unrealized_loss".to_string()), - raw: CentsUsdPattern2::new(client.clone(), "unrealized_loss".to_string()), + base: CentsUsdPattern2::new(client.clone(), "unrealized_loss".to_string()), cumulative: CentsUsdPattern2::new(client.clone(), "unrealized_loss_cumulative".to_string()), sum: _1m1w1y24hPattern5::new(client.clone(), "unrealized_loss_sum".to_string()), rel_to_mcap: BpsPercentRatioPattern4::new(client.clone(), "unrealized_loss_rel_to_mcap".to_string()), @@ -6658,7 +6660,7 @@ impl MetricsTree_Cohorts_Utxo_All_Unrealized_NetPnl { /// Metrics tree node. pub struct MetricsTree_Cohorts_Utxo_All_Unrealized_Profit { - pub raw: CentsUsdPattern2, + pub base: CentsUsdPattern2, pub cumulative: CentsUsdPattern2, pub sum: _1m1w1y24hPattern5, pub rel_to_mcap: BpsPercentRatioPattern4, @@ -6668,7 +6670,7 @@ pub struct MetricsTree_Cohorts_Utxo_All_Unrealized_Profit { impl MetricsTree_Cohorts_Utxo_All_Unrealized_Profit { pub fn new(client: Arc, base_path: String) -> Self { Self { - raw: CentsUsdPattern2::new(client.clone(), "unrealized_profit".to_string()), + base: CentsUsdPattern2::new(client.clone(), "unrealized_profit".to_string()), cumulative: CentsUsdPattern2::new(client.clone(), "unrealized_profit_cumulative".to_string()), sum: _1m1w1y24hPattern5::new(client.clone(), "unrealized_profit_sum".to_string()), rel_to_mcap: BpsPercentRatioPattern4::new(client.clone(), "unrealized_profit_rel_to_mcap".to_string()), @@ -6725,13 +6727,13 @@ impl MetricsTree_Cohorts_Utxo_Lth { /// Metrics tree node. pub struct MetricsTree_Cohorts_Utxo_Lth_Realized { - pub profit: CumulativeDistributionRawRelSumValuePattern, - pub loss: CapitulationCumulativeNegativeRawRelSumValuePattern, - pub gross_pnl: CumulativeRawSumPattern3, + pub profit: BaseCumulativeDistributionRelSumValuePattern, + pub loss: BaseCapitulationCumulativeNegativeRelSumValuePattern, + pub gross_pnl: BaseCumulativeSumPattern3, pub sell_side_risk_ratio: MetricsTree_Cohorts_Utxo_Lth_Realized_SellSideRiskRatio, - pub net_pnl: ChangeCumulativeDeltaRawRelSumPattern, + pub net_pnl: BaseChangeCumulativeDeltaRelSumPattern, pub sopr: MetricsTree_Cohorts_Utxo_Lth_Realized_Sopr, - pub peak_regret: CumulativeRawRelPattern, + pub peak_regret: BaseCumulativeRelPattern, pub investor: LowerPriceUpperPattern, pub profit_to_loss_ratio: _1m1w1y24hPattern, pub cap: CentsDeltaRelUsdPattern, @@ -6742,13 +6744,13 @@ pub struct MetricsTree_Cohorts_Utxo_Lth_Realized { impl MetricsTree_Cohorts_Utxo_Lth_Realized { pub fn new(client: Arc, base_path: String) -> Self { Self { - profit: CumulativeDistributionRawRelSumValuePattern::new(client.clone(), "lth".to_string()), - loss: CapitulationCumulativeNegativeRawRelSumValuePattern::new(client.clone(), "lth".to_string()), - gross_pnl: CumulativeRawSumPattern3::new(client.clone(), "lth_realized_gross_pnl".to_string()), + profit: BaseCumulativeDistributionRelSumValuePattern::new(client.clone(), "lth".to_string()), + loss: BaseCapitulationCumulativeNegativeRelSumValuePattern::new(client.clone(), "lth".to_string()), + gross_pnl: BaseCumulativeSumPattern3::new(client.clone(), "lth_realized_gross_pnl".to_string()), sell_side_risk_ratio: MetricsTree_Cohorts_Utxo_Lth_Realized_SellSideRiskRatio::new(client.clone(), format!("{base_path}_sell_side_risk_ratio")), - net_pnl: ChangeCumulativeDeltaRawRelSumPattern::new(client.clone(), "lth_net".to_string()), + net_pnl: BaseChangeCumulativeDeltaRelSumPattern::new(client.clone(), "lth_net".to_string()), sopr: MetricsTree_Cohorts_Utxo_Lth_Realized_Sopr::new(client.clone(), format!("{base_path}_sopr")), - peak_regret: CumulativeRawRelPattern::new(client.clone(), "lth_realized_peak_regret".to_string()), + peak_regret: BaseCumulativeRelPattern::new(client.clone(), "lth_realized_peak_regret".to_string()), investor: LowerPriceUpperPattern::new(client.clone(), "lth".to_string()), profit_to_loss_ratio: _1m1w1y24hPattern::new(client.clone(), "lth_realized_profit_to_loss_ratio".to_string()), cap: CentsDeltaRelUsdPattern::new(client.clone(), "lth_realized_cap".to_string()), @@ -6780,16 +6782,16 @@ impl MetricsTree_Cohorts_Utxo_Lth_Realized_SellSideRiskRatio { /// Metrics tree node. pub struct MetricsTree_Cohorts_Utxo_Lth_Realized_Sopr { pub ratio: _1m1w1y24hPattern, - pub value_created: CumulativeRawSumPattern, - pub value_destroyed: CumulativeRawSumPattern, + pub value_created: BaseCumulativeSumPattern, + pub value_destroyed: BaseCumulativeSumPattern, } impl MetricsTree_Cohorts_Utxo_Lth_Realized_Sopr { pub fn new(client: Arc, base_path: String) -> Self { Self { ratio: _1m1w1y24hPattern::new(client.clone(), "lth_sopr".to_string()), - value_created: CumulativeRawSumPattern::new(client.clone(), "lth_value_created".to_string()), - value_destroyed: CumulativeRawSumPattern::new(client.clone(), "lth_value_destroyed".to_string()), + value_created: BaseCumulativeSumPattern::new(client.clone(), "lth_value_created".to_string()), + value_destroyed: BaseCumulativeSumPattern::new(client.clone(), "lth_value_destroyed".to_string()), } } } diff --git a/crates/brk_computer/src/blocks/count/compute.rs b/crates/brk_computer/src/blocks/count/compute.rs index 0b5a99dd6..649a7f74b 100644 --- a/crates/brk_computer/src/blocks/count/compute.rs +++ b/crates/brk_computer/src/blocks/count/compute.rs @@ -13,7 +13,7 @@ impl Vecs { exit: &Exit, ) -> Result<()> { // Block count raw + cumulative - self.total.raw.height.compute_range( + self.total.base.height.compute_range( starting_indexes.height, &indexer.vecs.blocks.weight, |h| (h, StoredU32::from(1_u32)), diff --git a/crates/brk_computer/src/blocks/count/import.rs b/crates/brk_computer/src/blocks/count/import.rs index 565238520..abad7b32b 100644 --- a/crates/brk_computer/src/blocks/count/import.rs +++ b/crates/brk_computer/src/blocks/count/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{BlockCountTarget, CachedWindowStarts, ComputedPerBlockCumulativeWithSums, ConstantVecs}, + internal::{BlockCountTarget, CachedWindowStarts, PerBlockCumulativeWithSums, ConstantVecs}, }; impl Vecs { @@ -21,7 +21,7 @@ impl Vecs { version, indexes, ), - total: ComputedPerBlockCumulativeWithSums::forced_import( + total: PerBlockCumulativeWithSums::forced_import( db, "block_count", version + Version::ONE, diff --git a/crates/brk_computer/src/blocks/count/vecs.rs b/crates/brk_computer/src/blocks/count/vecs.rs index b3b6a94a9..2736bc339 100644 --- a/crates/brk_computer/src/blocks/count/vecs.rs +++ b/crates/brk_computer/src/blocks/count/vecs.rs @@ -2,10 +2,10 @@ use brk_traversable::Traversable; use brk_types::{StoredU32, StoredU64}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedPerBlockCumulativeWithSums, ConstantVecs}; +use crate::internal::{PerBlockCumulativeWithSums, ConstantVecs}; #[derive(Traversable)] pub struct Vecs { pub target: ConstantVecs, - pub total: ComputedPerBlockCumulativeWithSums, + pub total: PerBlockCumulativeWithSums, } diff --git a/crates/brk_computer/src/blocks/difficulty/compute.rs b/crates/brk_computer/src/blocks/difficulty/compute.rs index dfa537dea..028b9b259 100644 --- a/crates/brk_computer/src/blocks/difficulty/compute.rs +++ b/crates/brk_computer/src/blocks/difficulty/compute.rs @@ -1,9 +1,8 @@ use brk_error::Result; use brk_indexer::Indexer; -use brk_types::{Indexes, StoredF64, StoredU32}; +use brk_types::{Indexes, StoredU32}; use vecdb::Exit; -use super::super::TARGET_BLOCKS_PER_DAY_F32; use super::Vecs; use crate::indexes; @@ -15,18 +14,6 @@ impl Vecs { starting_indexes: &Indexes, exit: &Exit, ) -> Result<()> { - // raw is fully lazy from indexer height source — no compute needed - - // Compute difficulty as hash rate equivalent - let multiplier = 2.0_f64.powi(32) / 600.0; - self.as_hash.height.compute_transform( - starting_indexes.height, - &indexer.vecs.blocks.difficulty, - |(i, v, ..)| (i, StoredF64::from(*v * multiplier)), - exit, - )?; - - // Compute difficulty adjustment ratio: (current - previous) / previous self.adjustment.bps.height.compute_ratio_change( starting_indexes.height, &indexer.vecs.blocks.difficulty, @@ -34,7 +21,6 @@ impl Vecs { exit, )?; - // Compute epoch by height self.epoch.height.compute_transform( starting_indexes.height, &indexes.height.epoch, @@ -42,21 +28,10 @@ impl Vecs { exit, )?; - // Compute blocks before next adjustment - self.blocks_before_next - .height - .compute_transform( - starting_indexes.height, - &indexes.height.identity, - |(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())), - exit, - )?; - - // Compute days before next adjustment - self.days_before_next.height.compute_transform( + self.blocks_before_next.height.compute_transform( starting_indexes.height, - &self.blocks_before_next.height, - |(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()), + &indexes.height.identity, + |(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())), exit, )?; diff --git a/crates/brk_computer/src/blocks/difficulty/import.rs b/crates/brk_computer/src/blocks/difficulty/import.rs index aa96e8b11..ce461e65d 100644 --- a/crates/brk_computer/src/blocks/difficulty/import.rs +++ b/crates/brk_computer/src/blocks/difficulty/import.rs @@ -6,7 +6,9 @@ use vecdb::{Database, ReadableCloneableVec}; use super::Vecs; use crate::{ indexes, - internal::{ComputedPerBlock, Resolutions, PercentPerBlock}, + internal::{ + BlocksToDaysF32, DifficultyToHashF64, LazyPerBlock, PerBlock, PercentPerBlock, Resolutions, + }, }; impl Vecs { @@ -18,33 +20,39 @@ impl Vecs { ) -> Result { let v2 = Version::TWO; + let as_hash = LazyPerBlock::from_height_source::( + "difficulty_as_hash", + version, + indexer.vecs.blocks.difficulty.read_only_boxed_clone(), + indexes, + ); + + let blocks_before_next = PerBlock::forced_import( + db, + "blocks_before_next_difficulty_adjustment", + version + v2, + indexes, + )?; + + let days_before_next = LazyPerBlock::from_computed::( + "days_before_next_difficulty_adjustment", + version + v2, + blocks_before_next.height.read_only_boxed_clone(), + &blocks_before_next, + ); + Ok(Self { - raw: Resolutions::forced_import( + base: Resolutions::forced_import( "difficulty", indexer.vecs.blocks.difficulty.read_only_boxed_clone(), version, indexes, ), - as_hash: ComputedPerBlock::forced_import(db, "difficulty_as_hash", version, indexes)?, - adjustment: PercentPerBlock::forced_import( - db, - "difficulty_adjustment", - version, - indexes, - )?, - epoch: ComputedPerBlock::forced_import(db, "difficulty_epoch", version, indexes)?, - blocks_before_next: ComputedPerBlock::forced_import( - db, - "blocks_before_next_difficulty_adjustment", - version + v2, - indexes, - )?, - days_before_next: ComputedPerBlock::forced_import( - db, - "days_before_next_difficulty_adjustment", - version + v2, - indexes, - )?, + as_hash, + adjustment: PercentPerBlock::forced_import(db, "difficulty_adjustment", version, indexes)?, + epoch: PerBlock::forced_import(db, "difficulty_epoch", version, indexes)?, + blocks_before_next, + days_before_next, }) } } diff --git a/crates/brk_computer/src/blocks/difficulty/vecs.rs b/crates/brk_computer/src/blocks/difficulty/vecs.rs index 2e246477e..06b90d83c 100644 --- a/crates/brk_computer/src/blocks/difficulty/vecs.rs +++ b/crates/brk_computer/src/blocks/difficulty/vecs.rs @@ -2,13 +2,13 @@ use brk_traversable::Traversable; use brk_types::{BasisPointsSigned32, Epoch, StoredF32, StoredF64, StoredU32}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, Resolutions, PercentPerBlock}; +use crate::internal::{LazyPerBlock, PerBlock, Resolutions, PercentPerBlock}; #[derive(Traversable)] pub struct Vecs { - pub raw: Resolutions, - pub as_hash: ComputedPerBlock, + pub base: Resolutions, + pub as_hash: LazyPerBlock, pub adjustment: PercentPerBlock, - pub epoch: ComputedPerBlock, - pub blocks_before_next: ComputedPerBlock, - pub days_before_next: ComputedPerBlock, + pub epoch: PerBlock, + pub blocks_before_next: PerBlock, + pub days_before_next: LazyPerBlock, } diff --git a/crates/brk_computer/src/blocks/halving/compute.rs b/crates/brk_computer/src/blocks/halving/compute.rs index c106324b6..17f1b3c4a 100644 --- a/crates/brk_computer/src/blocks/halving/compute.rs +++ b/crates/brk_computer/src/blocks/halving/compute.rs @@ -2,7 +2,6 @@ use brk_error::Result; use brk_types::{Indexes, StoredU32}; use vecdb::Exit; -use super::super::TARGET_BLOCKS_PER_DAY_F32; use super::Vecs; use crate::indexes; @@ -27,13 +26,6 @@ impl Vecs { exit, )?; - self.days_before_next.height.compute_transform( - starting_indexes.height, - &self.blocks_before_next.height, - |(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()), - exit, - )?; - Ok(()) } } diff --git a/crates/brk_computer/src/blocks/halving/import.rs b/crates/brk_computer/src/blocks/halving/import.rs index 69f4c5cf9..5175e545b 100644 --- a/crates/brk_computer/src/blocks/halving/import.rs +++ b/crates/brk_computer/src/blocks/halving/import.rs @@ -1,9 +1,12 @@ use brk_error::Result; use brk_types::Version; -use vecdb::Database; +use vecdb::{Database, ReadableCloneableVec}; use super::Vecs; -use crate::{indexes, internal::ComputedPerBlock}; +use crate::{ + indexes, + internal::{BlocksToDaysF32, LazyPerBlock, PerBlock}, +}; impl Vecs { pub(crate) fn forced_import( @@ -13,20 +16,21 @@ impl Vecs { ) -> Result { let v2 = Version::TWO; + let blocks_before_next = PerBlock::forced_import( + db, "blocks_before_next_halving", version + v2, indexes, + )?; + + let days_before_next = LazyPerBlock::from_computed::( + "days_before_next_halving", + version + v2, + blocks_before_next.height.read_only_boxed_clone(), + &blocks_before_next, + ); + Ok(Self { - epoch: ComputedPerBlock::forced_import(db, "halving_epoch", version, indexes)?, - blocks_before_next: ComputedPerBlock::forced_import( - db, - "blocks_before_next_halving", - version + v2, - indexes, - )?, - days_before_next: ComputedPerBlock::forced_import( - db, - "days_before_next_halving", - version + v2, - indexes, - )?, + epoch: PerBlock::forced_import(db, "halving_epoch", version, indexes)?, + blocks_before_next, + days_before_next, }) } } diff --git a/crates/brk_computer/src/blocks/halving/vecs.rs b/crates/brk_computer/src/blocks/halving/vecs.rs index 3553bd08f..6068f6269 100644 --- a/crates/brk_computer/src/blocks/halving/vecs.rs +++ b/crates/brk_computer/src/blocks/halving/vecs.rs @@ -2,10 +2,10 @@ use brk_traversable::Traversable; use brk_types::{Halving, StoredF32, StoredU32}; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedPerBlock; +use crate::internal::{LazyPerBlock, PerBlock}; #[derive(Traversable)] pub struct Vecs { - pub epoch: ComputedPerBlock, - pub blocks_before_next: ComputedPerBlock, - pub days_before_next: ComputedPerBlock, + pub epoch: PerBlock, + pub blocks_before_next: PerBlock, + pub days_before_next: LazyPerBlock, } diff --git a/crates/brk_computer/src/blocks/import.rs b/crates/brk_computer/src/blocks/import.rs index 4b5894635..ce27837ce 100644 --- a/crates/brk_computer/src/blocks/import.rs +++ b/crates/brk_computer/src/blocks/import.rs @@ -6,7 +6,7 @@ use brk_types::Version; use crate::{ indexes, - internal::{finalize_db, open_db}, + internal::db_utils::{finalize_db, open_db}, }; use super::{ diff --git a/crates/brk_computer/src/blocks/interval/import.rs b/crates/brk_computer/src/blocks/interval/import.rs index 660efe06c..60bac478b 100644 --- a/crates/brk_computer/src/blocks/interval/import.rs +++ b/crates/brk_computer/src/blocks/interval/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::{CachedWindowStarts, ComputedPerBlockRollingAverage}}; +use crate::{indexes, internal::{CachedWindowStarts, PerBlockRollingAverage}}; impl Vecs { pub(crate) fn forced_import( @@ -12,7 +12,7 @@ impl Vecs { indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { - let interval = ComputedPerBlockRollingAverage::forced_import( + let interval = PerBlockRollingAverage::forced_import( db, "block_interval", version, diff --git a/crates/brk_computer/src/blocks/interval/vecs.rs b/crates/brk_computer/src/blocks/interval/vecs.rs index 3ed2b0b78..2a3f35d05 100644 --- a/crates/brk_computer/src/blocks/interval/vecs.rs +++ b/crates/brk_computer/src/blocks/interval/vecs.rs @@ -4,9 +4,9 @@ use brk_traversable::Traversable; use brk_types::Timestamp; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedPerBlockRollingAverage; +use crate::internal::PerBlockRollingAverage; #[derive(Deref, DerefMut, Traversable)] pub struct Vecs( - #[traversable(flatten)] pub ComputedPerBlockRollingAverage, + #[traversable(flatten)] pub PerBlockRollingAverage, ); diff --git a/crates/brk_computer/src/blocks/size/import.rs b/crates/brk_computer/src/blocks/size/import.rs index 8b962682b..b4dfbb671 100644 --- a/crates/brk_computer/src/blocks/size/import.rs +++ b/crates/brk_computer/src/blocks/size/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{CachedWindowStarts, ComputedPerBlockFull, ResolutionsFull}, + internal::{CachedWindowStarts, PerBlockFull, PerBlockRolling}, }; impl Vecs { @@ -16,14 +16,14 @@ impl Vecs { cached_starts: &CachedWindowStarts, ) -> Result { Ok(Self { - vbytes: ComputedPerBlockFull::forced_import( + vbytes: PerBlockFull::forced_import( db, "block_vbytes", version, indexes, cached_starts, )?, - size: ResolutionsFull::forced_import( + size: PerBlockRolling::forced_import( db, "block_size", version, diff --git a/crates/brk_computer/src/blocks/size/vecs.rs b/crates/brk_computer/src/blocks/size/vecs.rs index dcebb5735..1fbea4bbc 100644 --- a/crates/brk_computer/src/blocks/size/vecs.rs +++ b/crates/brk_computer/src/blocks/size/vecs.rs @@ -2,10 +2,10 @@ use brk_traversable::Traversable; use brk_types::StoredU64; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedPerBlockFull, ResolutionsFull}; +use crate::internal::{PerBlockFull, PerBlockRolling}; #[derive(Traversable)] pub struct Vecs { - pub vbytes: ComputedPerBlockFull, - pub size: ResolutionsFull, + pub vbytes: PerBlockFull, + pub size: PerBlockRolling, } diff --git a/crates/brk_computer/src/blocks/weight/import.rs b/crates/brk_computer/src/blocks/weight/import.rs index 9a2423030..59d925227 100644 --- a/crates/brk_computer/src/blocks/weight/import.rs +++ b/crates/brk_computer/src/blocks/weight/import.rs @@ -6,7 +6,7 @@ use super::Vecs; use crate::{ blocks::SizeVecs, indexes, - internal::{CachedWindowStarts, LazyResolutionsFull, PercentPerBlockRollingAverage, VBytesToWeight}, + internal::{CachedWindowStarts, LazyPerBlockRolling, PercentPerBlockRollingAverage, VBytesToWeight}, }; impl Vecs { @@ -17,7 +17,7 @@ impl Vecs { cached_starts: &CachedWindowStarts, size: &SizeVecs, ) -> Result { - let weight = LazyResolutionsFull::from_computed_per_block_full::( + let weight = LazyPerBlockRolling::from_per_block_full::( "block_weight", version, &size.vbytes, diff --git a/crates/brk_computer/src/blocks/weight/vecs.rs b/crates/brk_computer/src/blocks/weight/vecs.rs index 7ed999ef7..3782fe558 100644 --- a/crates/brk_computer/src/blocks/weight/vecs.rs +++ b/crates/brk_computer/src/blocks/weight/vecs.rs @@ -2,10 +2,10 @@ use brk_traversable::Traversable; use brk_types::{BasisPoints16, StoredU64, Weight}; use vecdb::{Rw, StorageMode}; -use crate::internal::{LazyResolutionsFull, PercentPerBlockRollingAverage}; +use crate::internal::{LazyPerBlockRolling, PercentPerBlockRollingAverage}; #[derive(Traversable)] pub struct Vecs { - pub weight: LazyResolutionsFull, + pub weight: LazyPerBlockRolling, pub fullness: PercentPerBlockRollingAverage, } diff --git a/crates/brk_computer/src/cointime/activity/compute.rs b/crates/brk_computer/src/cointime/activity/compute.rs index 06d22f8c9..e5e5deff7 100644 --- a/crates/brk_computer/src/cointime/activity/compute.rs +++ b/crates/brk_computer/src/cointime/activity/compute.rs @@ -1,5 +1,5 @@ use brk_error::Result; -use brk_types::{Bitcoin, CheckedSub, Indexes, StoredF64}; +use brk_types::{Bitcoin, Indexes, StoredF64}; use vecdb::Exit; use super::Vecs; @@ -30,8 +30,8 @@ impl Vecs { .compute(starting_indexes.height, exit, |vec| { vec.compute_subtract( starting_indexes.height, - &self.coinblocks_created.raw.height, - &distribution.coinblocks_destroyed.raw.height, + &self.coinblocks_created.base.height, + &distribution.coinblocks_destroyed.base.height, exit, )?; Ok(()) @@ -44,13 +44,6 @@ impl Vecs { exit, )?; - self.vaultedness.height.compute_transform( - starting_indexes.height, - &self.liveliness.height, - |(i, v, ..)| (i, StoredF64::from(1.0).checked_sub(v).unwrap()), - exit, - )?; - self.ratio.height.compute_divide( starting_indexes.height, &self.liveliness.height, diff --git a/crates/brk_computer/src/cointime/activity/import.rs b/crates/brk_computer/src/cointime/activity/import.rs index 868181f88..fdc889fa1 100644 --- a/crates/brk_computer/src/cointime/activity/import.rs +++ b/crates/brk_computer/src/cointime/activity/import.rs @@ -1,11 +1,13 @@ use brk_error::Result; use brk_types::Version; -use vecdb::Database; +use vecdb::{Database, ReadableCloneableVec}; use super::Vecs; use crate::{ indexes, - internal::{CachedWindowStarts, ComputedPerBlock, ComputedPerBlockCumulativeWithSums}, + internal::{ + CachedWindowStarts, LazyPerBlock, OneMinusF64, PerBlock, PerBlockCumulativeWithSums, + }, }; impl Vecs { @@ -15,29 +17,25 @@ impl Vecs { indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { + let liveliness = PerBlock::forced_import(db, "liveliness", version, indexes)?; + + let vaultedness = LazyPerBlock::from_computed::( + "vaultedness", + version, + liveliness.height.read_only_boxed_clone(), + &liveliness, + ); + Ok(Self { - coinblocks_created: ComputedPerBlockCumulativeWithSums::forced_import( - db, - "coinblocks_created", - version, - indexes, - cached_starts, + coinblocks_created: PerBlockCumulativeWithSums::forced_import( + db, "coinblocks_created", version, indexes, cached_starts, )?, - coinblocks_stored: ComputedPerBlockCumulativeWithSums::forced_import( - db, - "coinblocks_stored", - version, - indexes, - cached_starts, - )?, - liveliness: ComputedPerBlock::forced_import(db, "liveliness", version, indexes)?, - vaultedness: ComputedPerBlock::forced_import(db, "vaultedness", version, indexes)?, - ratio: ComputedPerBlock::forced_import( - db, - "activity_to_vaultedness_ratio", - version, - indexes, + coinblocks_stored: PerBlockCumulativeWithSums::forced_import( + db, "coinblocks_stored", version, indexes, cached_starts, )?, + liveliness, + vaultedness, + ratio: PerBlock::forced_import(db, "activity_to_vaultedness_ratio", version, indexes)?, }) } } diff --git a/crates/brk_computer/src/cointime/activity/vecs.rs b/crates/brk_computer/src/cointime/activity/vecs.rs index a04814ba3..85fc27ab2 100644 --- a/crates/brk_computer/src/cointime/activity/vecs.rs +++ b/crates/brk_computer/src/cointime/activity/vecs.rs @@ -2,13 +2,13 @@ use brk_traversable::Traversable; use brk_types::StoredF64; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, ComputedPerBlockCumulativeWithSums}; +use crate::internal::{LazyPerBlock, PerBlock, PerBlockCumulativeWithSums}; #[derive(Traversable)] pub struct Vecs { - pub coinblocks_created: ComputedPerBlockCumulativeWithSums, - pub coinblocks_stored: ComputedPerBlockCumulativeWithSums, - pub liveliness: ComputedPerBlock, - pub vaultedness: ComputedPerBlock, - pub ratio: ComputedPerBlock, + pub coinblocks_created: PerBlockCumulativeWithSums, + pub coinblocks_stored: PerBlockCumulativeWithSums, + pub liveliness: PerBlock, + pub vaultedness: LazyPerBlock, + pub ratio: PerBlock, } diff --git a/crates/brk_computer/src/cointime/adjusted/import.rs b/crates/brk_computer/src/cointime/adjusted/import.rs index 8a2cdc7ea..e4b9353e7 100644 --- a/crates/brk_computer/src/cointime/adjusted/import.rs +++ b/crates/brk_computer/src/cointime/adjusted/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{ComputedPerBlock, PercentPerBlock}, + internal::{PerBlock, PercentPerBlock}, }; impl Vecs { @@ -21,13 +21,13 @@ impl Vecs { version, indexes, )?, - tx_velocity_btc: ComputedPerBlock::forced_import( + tx_velocity_btc: PerBlock::forced_import( db, "cointime_adj_tx_velocity_btc", version, indexes, )?, - tx_velocity_usd: ComputedPerBlock::forced_import( + tx_velocity_usd: PerBlock::forced_import( db, "cointime_adj_tx_velocity_usd", version, diff --git a/crates/brk_computer/src/cointime/adjusted/vecs.rs b/crates/brk_computer/src/cointime/adjusted/vecs.rs index 3818f3e6e..9509251f5 100644 --- a/crates/brk_computer/src/cointime/adjusted/vecs.rs +++ b/crates/brk_computer/src/cointime/adjusted/vecs.rs @@ -2,11 +2,11 @@ use brk_traversable::Traversable; use brk_types::{BasisPointsSigned32, StoredF64}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, PercentPerBlock}; +use crate::internal::{PerBlock, PercentPerBlock}; #[derive(Traversable)] pub struct Vecs { pub inflation_rate: PercentPerBlock, - pub tx_velocity_btc: ComputedPerBlock, - pub tx_velocity_usd: ComputedPerBlock, + pub tx_velocity_btc: PerBlock, + pub tx_velocity_usd: PerBlock, } diff --git a/crates/brk_computer/src/cointime/import.rs b/crates/brk_computer/src/cointime/import.rs index 2085d9213..782b0d41c 100644 --- a/crates/brk_computer/src/cointime/import.rs +++ b/crates/brk_computer/src/cointime/import.rs @@ -5,7 +5,7 @@ use brk_types::Version; use crate::{ indexes, - internal::{finalize_db, open_db}, + internal::db_utils::{finalize_db, open_db}, }; use super::{ diff --git a/crates/brk_computer/src/cointime/prices/import.rs b/crates/brk_computer/src/cointime/prices/import.rs index 1af47edf5..1668a9ddb 100644 --- a/crates/brk_computer/src/cointime/prices/import.rs +++ b/crates/brk_computer/src/cointime/prices/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{ComputedPerBlock, PriceWithRatioExtendedPerBlock}, + internal::{PerBlock, PriceWithRatioExtendedPerBlock}, }; impl Vecs { @@ -29,7 +29,7 @@ impl Vecs { balanced: import!("balanced_price"), terminal: import!("terminal_price"), delta: import!("delta_price"), - cumulative_market_cap: ComputedPerBlock::forced_import( + cumulative_market_cap: PerBlock::forced_import( db, "cumulative_market_cap", version, diff --git a/crates/brk_computer/src/cointime/prices/vecs.rs b/crates/brk_computer/src/cointime/prices/vecs.rs index dbc703832..4135189aa 100644 --- a/crates/brk_computer/src/cointime/prices/vecs.rs +++ b/crates/brk_computer/src/cointime/prices/vecs.rs @@ -2,7 +2,7 @@ use brk_traversable::Traversable; use brk_types::Dollars; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, PriceWithRatioExtendedPerBlock}; +use crate::internal::{PerBlock, PriceWithRatioExtendedPerBlock}; #[derive(Traversable)] pub struct Vecs { @@ -15,5 +15,5 @@ pub struct Vecs { pub terminal: PriceWithRatioExtendedPerBlock, pub delta: PriceWithRatioExtendedPerBlock, - pub cumulative_market_cap: ComputedPerBlock, + pub cumulative_market_cap: PerBlock, } diff --git a/crates/brk_computer/src/cointime/reserve_risk/compute.rs b/crates/brk_computer/src/cointime/reserve_risk/compute.rs index aac339ccf..29e750bbb 100644 --- a/crates/brk_computer/src/cointime/reserve_risk/compute.rs +++ b/crates/brk_computer/src/cointime/reserve_risk/compute.rs @@ -3,7 +3,7 @@ use brk_types::{Indexes, StoredF64}; use vecdb::Exit; use super::{super::value, Vecs}; -use crate::{blocks, internal::ComputeRollingMedianFromStarts, prices}; +use crate::{blocks, internal::algo::ComputeRollingMedianFromStarts, prices}; impl Vecs { pub(crate) fn compute( @@ -17,7 +17,7 @@ impl Vecs { self.vocdd_median_1y.compute_rolling_median_from_starts( starting_indexes.height, &blocks.lookback._1y, - &value.vocdd.raw.height, + &value.vocdd.base.height, exit, )?; diff --git a/crates/brk_computer/src/cointime/reserve_risk/import.rs b/crates/brk_computer/src/cointime/reserve_risk/import.rs index 46eb88892..bcebbead6 100644 --- a/crates/brk_computer/src/cointime/reserve_risk/import.rs +++ b/crates/brk_computer/src/cointime/reserve_risk/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::{Database, EagerVec, ImportableVec}; use super::Vecs; -use crate::{indexes, internal::ComputedPerBlock}; +use crate::{indexes, internal::PerBlock}; impl Vecs { pub(crate) fn forced_import( @@ -15,7 +15,7 @@ impl Vecs { Ok(Self { vocdd_median_1y: EagerVec::forced_import(db, "vocdd_median_1y", v1)?, hodl_bank: EagerVec::forced_import(db, "hodl_bank", v1)?, - value: ComputedPerBlock::forced_import(db, "reserve_risk", v1, indexes)?, + value: PerBlock::forced_import(db, "reserve_risk", v1, indexes)?, }) } } diff --git a/crates/brk_computer/src/cointime/reserve_risk/vecs.rs b/crates/brk_computer/src/cointime/reserve_risk/vecs.rs index 973e18afd..2f4b416ec 100644 --- a/crates/brk_computer/src/cointime/reserve_risk/vecs.rs +++ b/crates/brk_computer/src/cointime/reserve_risk/vecs.rs @@ -2,11 +2,11 @@ use brk_traversable::Traversable; use brk_types::{Height, StoredF64}; use vecdb::{EagerVec, PcoVec, Rw, StorageMode}; -use crate::internal::ComputedPerBlock; +use crate::internal::PerBlock; #[derive(Traversable)] pub struct Vecs { - pub value: ComputedPerBlock, + pub value: PerBlock, pub vocdd_median_1y: M::Stored>>, pub hodl_bank: M::Stored>>, } diff --git a/crates/brk_computer/src/cointime/value/compute.rs b/crates/brk_computer/src/cointime/value/compute.rs index deab3ac17..a2549c6dc 100644 --- a/crates/brk_computer/src/cointime/value/compute.rs +++ b/crates/brk_computer/src/cointime/value/compute.rs @@ -25,7 +25,7 @@ impl Vecs { vec.compute_multiply( starting_indexes.height, &prices.spot.usd.height, - &coinblocks_destroyed.raw.height, + &coinblocks_destroyed.base.height, exit, )?; Ok(()) @@ -36,7 +36,7 @@ impl Vecs { vec.compute_multiply( starting_indexes.height, &prices.spot.usd.height, - &activity.coinblocks_created.raw.height, + &activity.coinblocks_created.base.height, exit, )?; Ok(()) @@ -47,7 +47,7 @@ impl Vecs { vec.compute_multiply( starting_indexes.height, &prices.spot.usd.height, - &activity.coinblocks_stored.raw.height, + &activity.coinblocks_stored.base.height, exit, )?; Ok(()) @@ -61,7 +61,7 @@ impl Vecs { vec.compute_transform3( starting_indexes.height, &prices.spot.usd.height, - &coindays_destroyed.raw.height, + &coindays_destroyed.base.height, circulating_supply, |(i, price, cdd, supply, _): (_, Dollars, StoredF64, Bitcoin, _)| { let supply_f64 = f64::from(supply); diff --git a/crates/brk_computer/src/cointime/value/import.rs b/crates/brk_computer/src/cointime/value/import.rs index fe933a619..85c0a3ebd 100644 --- a/crates/brk_computer/src/cointime/value/import.rs +++ b/crates/brk_computer/src/cointime/value/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{CachedWindowStarts, ComputedPerBlockCumulativeWithSums}, + internal::{CachedWindowStarts, PerBlockCumulativeWithSums}, }; impl Vecs { @@ -16,28 +16,28 @@ impl Vecs { cached_starts: &CachedWindowStarts, ) -> Result { Ok(Self { - destroyed: ComputedPerBlockCumulativeWithSums::forced_import( + destroyed: PerBlockCumulativeWithSums::forced_import( db, "cointime_value_destroyed", version, indexes, cached_starts, )?, - created: ComputedPerBlockCumulativeWithSums::forced_import( + created: PerBlockCumulativeWithSums::forced_import( db, "cointime_value_created", version, indexes, cached_starts, )?, - stored: ComputedPerBlockCumulativeWithSums::forced_import( + stored: PerBlockCumulativeWithSums::forced_import( db, "cointime_value_stored", version, indexes, cached_starts, )?, - vocdd: ComputedPerBlockCumulativeWithSums::forced_import( + vocdd: PerBlockCumulativeWithSums::forced_import( db, "vocdd", version + Version::ONE, diff --git a/crates/brk_computer/src/cointime/value/vecs.rs b/crates/brk_computer/src/cointime/value/vecs.rs index 14dda4a39..aafd627c3 100644 --- a/crates/brk_computer/src/cointime/value/vecs.rs +++ b/crates/brk_computer/src/cointime/value/vecs.rs @@ -2,12 +2,12 @@ use brk_traversable::Traversable; use brk_types::StoredF64; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedPerBlockCumulativeWithSums; +use crate::internal::PerBlockCumulativeWithSums; #[derive(Traversable)] pub struct Vecs { - pub destroyed: ComputedPerBlockCumulativeWithSums, - pub created: ComputedPerBlockCumulativeWithSums, - pub stored: ComputedPerBlockCumulativeWithSums, - pub vocdd: ComputedPerBlockCumulativeWithSums, + pub destroyed: PerBlockCumulativeWithSums, + pub created: PerBlockCumulativeWithSums, + pub stored: PerBlockCumulativeWithSums, + pub vocdd: PerBlockCumulativeWithSums, } diff --git a/crates/brk_computer/src/distribution/address/activity.rs b/crates/brk_computer/src/distribution/address/activity.rs index 8c12ce1e9..a0576be7c 100644 --- a/crates/brk_computer/src/distribution/address/activity.rs +++ b/crates/brk_computer/src/distribution/address/activity.rs @@ -19,7 +19,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec}; use crate::{ indexes, - internal::{CachedWindowStarts, ComputedPerBlockRollingAverage}, + internal::{CachedWindowStarts, PerBlockRollingAverage}, }; /// Per-block activity counts - reset each block. @@ -65,10 +65,10 @@ impl AddressTypeToActivityCounts { /// Activity count vectors for a single category (e.g., one address type or "all"). #[derive(Traversable)] pub struct ActivityCountVecs { - pub reactivated: ComputedPerBlockRollingAverage, - pub sending: ComputedPerBlockRollingAverage, - pub receiving: ComputedPerBlockRollingAverage, - pub both: ComputedPerBlockRollingAverage, + pub reactivated: PerBlockRollingAverage, + pub sending: PerBlockRollingAverage, + pub receiving: PerBlockRollingAverage, + pub both: PerBlockRollingAverage, } impl ActivityCountVecs { @@ -80,28 +80,28 @@ impl ActivityCountVecs { cached_starts: &CachedWindowStarts, ) -> Result { Ok(Self { - reactivated: ComputedPerBlockRollingAverage::forced_import( + reactivated: PerBlockRollingAverage::forced_import( db, &format!("{name}_reactivated"), version, indexes, cached_starts, )?, - sending: ComputedPerBlockRollingAverage::forced_import( + sending: PerBlockRollingAverage::forced_import( db, &format!("{name}_sending"), version, indexes, cached_starts, )?, - receiving: ComputedPerBlockRollingAverage::forced_import( + receiving: PerBlockRollingAverage::forced_import( db, &format!("{name}_receiving"), version, indexes, cached_starts, )?, - both: ComputedPerBlockRollingAverage::forced_import( + both: PerBlockRollingAverage::forced_import( db, &format!("{name}_both"), version, diff --git a/crates/brk_computer/src/distribution/address/address_count.rs b/crates/brk_computer/src/distribution/address/address_count.rs index b4d01b250..1641ee90d 100644 --- a/crates/brk_computer/src/distribution/address/address_count.rs +++ b/crates/brk_computer/src/distribution/address/address_count.rs @@ -9,11 +9,11 @@ use vecdb::{ WritableVec, }; -use crate::{indexes, internal::ComputedPerBlock}; +use crate::{indexes, internal::PerBlock}; #[derive(Deref, DerefMut, Traversable)] pub struct AddressCountVecs( - #[traversable(flatten)] pub ComputedPerBlock, + #[traversable(flatten)] pub PerBlock, ); impl AddressCountVecs { @@ -23,7 +23,7 @@ impl AddressCountVecs { version: Version, indexes: &indexes::Vecs, ) -> Result { - Ok(Self(ComputedPerBlock::forced_import( + Ok(Self(PerBlock::forced_import( db, name, version, indexes, )?)) } diff --git a/crates/brk_computer/src/distribution/address/new_address_count.rs b/crates/brk_computer/src/distribution/address/new_address_count.rs index 9f154f8fa..4608577e3 100644 --- a/crates/brk_computer/src/distribution/address/new_address_count.rs +++ b/crates/brk_computer/src/distribution/address/new_address_count.rs @@ -6,7 +6,7 @@ use vecdb::{Database, Exit, Rw, StorageMode}; use crate::{ indexes, - internal::{CachedWindowStarts, ComputedPerBlockCumulativeWithSums}, + internal::{CachedWindowStarts, PerBlockCumulativeWithSums}, }; use super::TotalAddressCountVecs; @@ -14,9 +14,9 @@ use super::TotalAddressCountVecs; /// New address count per block (global + per-type) #[derive(Traversable)] pub struct NewAddressCountVecs { - pub all: ComputedPerBlockCumulativeWithSums, + pub all: PerBlockCumulativeWithSums, #[traversable(flatten)] - pub by_addresstype: ByAddressType>, + pub by_addresstype: ByAddressType>, } impl NewAddressCountVecs { @@ -26,7 +26,7 @@ impl NewAddressCountVecs { indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { - let all = ComputedPerBlockCumulativeWithSums::forced_import( + let all = PerBlockCumulativeWithSums::forced_import( db, "new_address_count", version, @@ -35,7 +35,7 @@ impl NewAddressCountVecs { )?; let by_addresstype = ByAddressType::new_with_name(|name| { - ComputedPerBlockCumulativeWithSums::forced_import( + PerBlockCumulativeWithSums::forced_import( db, &format!("{name}_new_address_count"), version, diff --git a/crates/brk_computer/src/distribution/address/total_address_count.rs b/crates/brk_computer/src/distribution/address/total_address_count.rs index 17ded9c7a..cd140db5a 100644 --- a/crates/brk_computer/src/distribution/address/total_address_count.rs +++ b/crates/brk_computer/src/distribution/address/total_address_count.rs @@ -4,16 +4,16 @@ use brk_traversable::Traversable; use brk_types::{Height, StoredU64, Version}; use vecdb::{Database, Exit, Rw, StorageMode}; -use crate::{indexes, internal::ComputedPerBlock}; +use crate::{indexes, internal::PerBlock}; use super::AddressCountsVecs; /// Total address count (global + per-type) with all derived indexes #[derive(Traversable)] pub struct TotalAddressCountVecs { - pub all: ComputedPerBlock, + pub all: PerBlock, #[traversable(flatten)] - pub by_addresstype: ByAddressType>, + pub by_addresstype: ByAddressType>, } impl TotalAddressCountVecs { @@ -22,11 +22,11 @@ impl TotalAddressCountVecs { version: Version, indexes: &indexes::Vecs, ) -> Result { - let all = ComputedPerBlock::forced_import(db, "total_address_count", version, indexes)?; + let all = PerBlock::forced_import(db, "total_address_count", version, indexes)?; - let by_addresstype: ByAddressType> = + let by_addresstype: ByAddressType> = ByAddressType::new_with_name(|name| { - ComputedPerBlock::forced_import( + PerBlock::forced_import( db, &format!("{name}_total_address_count"), version, diff --git a/crates/brk_computer/src/distribution/cohorts/address/vecs.rs b/crates/brk_computer/src/distribution/cohorts/address/vecs.rs index a13c1348b..b5750b3cb 100644 --- a/crates/brk_computer/src/distribution/cohorts/address/vecs.rs +++ b/crates/brk_computer/src/distribution/cohorts/address/vecs.rs @@ -10,7 +10,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Rw, StorageMode, use crate::{ distribution::state::{AddressCohortState, MinimalRealizedState}, indexes, - internal::{CachedWindowStarts, ComputedPerBlockWithDeltas}, + internal::{CachedWindowStarts, PerBlockWithDeltas}, prices, }; @@ -27,7 +27,7 @@ pub struct AddressCohortVecs { #[traversable(flatten)] pub metrics: MinimalCohortMetrics, - pub address_count: ComputedPerBlockWithDeltas, + pub address_count: PerBlockWithDeltas, } impl AddressCohortVecs { @@ -51,7 +51,7 @@ impl AddressCohortVecs { cached_starts, }; - let address_count = ComputedPerBlockWithDeltas::forced_import( + let address_count = PerBlockWithDeltas::forced_import( db, &cfg.name("address_count"), version, diff --git a/crates/brk_computer/src/distribution/cohorts/utxo/fenwick.rs b/crates/brk_computer/src/distribution/cohorts/utxo/fenwick.rs index c613ad752..bf55d6445 100644 --- a/crates/brk_computer/src/distribution/cohorts/utxo/fenwick.rs +++ b/crates/brk_computer/src/distribution/cohorts/utxo/fenwick.rs @@ -3,7 +3,7 @@ use brk_types::{Cents, CentsCompact, Sats}; use crate::{ distribution::state::PendingDelta, - internal::{FenwickNode, FenwickTree, PERCENTILES, PERCENTILES_LEN}, + internal::{PERCENTILES, PERCENTILES_LEN, algo::{FenwickNode, FenwickTree}}, }; use super::COST_BASIS_PRICE_DIGITS; diff --git a/crates/brk_computer/src/distribution/cohorts/utxo/groups.rs b/crates/brk_computer/src/distribution/cohorts/utxo/groups.rs index 01bf2ae84..ebd65bf12 100644 --- a/crates/brk_computer/src/distribution/cohorts/utxo/groups.rs +++ b/crates/brk_computer/src/distribution/cohorts/utxo/groups.rs @@ -538,7 +538,7 @@ impl UTXOCohorts { .minimal .sopr .value_created - .raw + .base .height .read_only_clone(); let under_1h_value_destroyed = self @@ -549,7 +549,7 @@ impl UTXOCohorts { .minimal .sopr .value_destroyed - .raw + .base .height .read_only_clone(); diff --git a/crates/brk_computer/src/distribution/compute/block_loop.rs b/crates/brk_computer/src/distribution/compute/block_loop.rs index c9179b5a9..89911fec2 100644 --- a/crates/brk_computer/src/distribution/compute/block_loop.rs +++ b/crates/brk_computer/src/distribution/compute/block_loop.rs @@ -66,7 +66,7 @@ pub(crate) fn process_blocks( let height_to_first_txindex = &indexer.vecs.transactions.first_txindex; let height_to_first_txoutindex = &indexer.vecs.outputs.first_txoutindex; let height_to_first_txinindex = &indexer.vecs.inputs.first_txinindex; - let height_to_tx_count = &transactions.count.total.raw.height; + let height_to_tx_count = &transactions.count.total.base.height; let height_to_output_count = &outputs.count.total.full.sum; let height_to_input_count = &inputs.count.full.sum; let txindex_to_output_count = &indexes.txindex.output_count; @@ -364,7 +364,7 @@ pub(crate) fn process_blocks( blocks_old as u128 * u64::from(sent.spendable_supply.value) as u128 }) .sum(); - vecs.coinblocks_destroyed.raw.height.truncate_push( + vecs.coinblocks_destroyed.base.height.truncate_push( height, StoredF64::from(total_satblocks as f64 / Sats::ONE_BTC_U128 as f64), )?; diff --git a/crates/brk_computer/src/distribution/compute/write.rs b/crates/brk_computer/src/distribution/compute/write.rs index af94936b1..7de24b9e6 100644 --- a/crates/brk_computer/src/distribution/compute/write.rs +++ b/crates/brk_computer/src/distribution/compute/write.rs @@ -82,7 +82,7 @@ pub(crate) fn write( .chain( [ &mut vecs.supply_state as &mut dyn AnyStoredVec, - &mut vecs.coinblocks_destroyed.raw.height, + &mut vecs.coinblocks_destroyed.base.height, ] .into_par_iter(), ) diff --git a/crates/brk_computer/src/distribution/metrics/activity/core.rs b/crates/brk_computer/src/distribution/metrics/activity/core.rs index 8413feca6..5e3039be3 100644 --- a/crates/brk_computer/src/distribution/metrics/activity/core.rs +++ b/crates/brk_computer/src/distribution/metrics/activity/core.rs @@ -5,14 +5,14 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec}; use crate::{ distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}}, - internal::{AmountPerBlockCumulativeWithSums, ComputedPerBlockCumulativeWithSums}, + internal::{AmountPerBlockCumulativeWithSums, PerBlockCumulativeWithSums}, prices, }; #[derive(Traversable)] pub struct ActivityCore { - pub sent: ComputedPerBlockCumulativeWithSums, - pub coindays_destroyed: ComputedPerBlockCumulativeWithSums, + pub sent: PerBlockCumulativeWithSums, + pub coindays_destroyed: PerBlockCumulativeWithSums, #[traversable(wrap = "sent", rename = "in_profit")] pub sent_in_profit: AmountPerBlockCumulativeWithSums, #[traversable(wrap = "sent", rename = "in_loss")] @@ -32,12 +32,12 @@ impl ActivityCore { pub(crate) fn min_len(&self) -> usize { self.sent - .raw + .base .height .len() - .min(self.coindays_destroyed.raw.height.len()) - .min(self.sent_in_profit.raw.sats.height.len()) - .min(self.sent_in_loss.raw.sats.height.len()) + .min(self.coindays_destroyed.base.height.len()) + .min(self.sent_in_profit.base.sats.height.len()) + .min(self.sent_in_loss.base.sats.height.len()) } pub(crate) fn truncate_push( @@ -45,18 +45,18 @@ impl ActivityCore { height: Height, state: &CohortState, ) -> Result<()> { - self.sent.raw.height.truncate_push(height, state.sent)?; - self.coindays_destroyed.raw.height.truncate_push( + self.sent.base.height.truncate_push(height, state.sent)?; + self.coindays_destroyed.base.height.truncate_push( height, StoredF64::from(Bitcoin::from(state.satdays_destroyed)), )?; self.sent_in_profit - .raw + .base .sats .height .truncate_push(height, state.realized.sent_in_profit())?; self.sent_in_loss - .raw + .base .sats .height .truncate_push(height, state.realized.sent_in_loss())?; @@ -65,12 +65,12 @@ impl ActivityCore { pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> { vec![ - &mut self.sent.raw.height as &mut dyn AnyStoredVec, - &mut self.coindays_destroyed.raw.height, - &mut self.sent_in_profit.raw.sats.height, - &mut self.sent_in_profit.raw.cents.height, - &mut self.sent_in_loss.raw.sats.height, - &mut self.sent_in_loss.raw.cents.height, + &mut self.sent.base.height as &mut dyn AnyStoredVec, + &mut self.coindays_destroyed.base.height, + &mut self.sent_in_profit.base.sats.height, + &mut self.sent_in_profit.base.cents.height, + &mut self.sent_in_loss.base.sats.height, + &mut self.sent_in_loss.base.cents.height, ] } @@ -84,18 +84,18 @@ impl ActivityCore { others: &[&Self], exit: &Exit, ) -> Result<()> { - self.sent.raw.height.compute_sum_of_others( + self.sent.base.height.compute_sum_of_others( starting_indexes.height, &others .iter() - .map(|v| &v.sent.raw.height) + .map(|v| &v.sent.base.height) .collect::>(), exit, )?; - sum_others!(self, starting_indexes, others, exit; coindays_destroyed.raw.height); - sum_others!(self, starting_indexes, others, exit; sent_in_profit.raw.sats.height); - sum_others!(self, starting_indexes, others, exit; sent_in_loss.raw.sats.height); + sum_others!(self, starting_indexes, others, exit; coindays_destroyed.base.height); + sum_others!(self, starting_indexes, others, exit; sent_in_profit.base.sats.height); + sum_others!(self, starting_indexes, others, exit; sent_in_loss.base.sats.height); Ok(()) } diff --git a/crates/brk_computer/src/distribution/metrics/activity/full.rs b/crates/brk_computer/src/distribution/metrics/activity/full.rs index 35b4081c3..05f605e31 100644 --- a/crates/brk_computer/src/distribution/metrics/activity/full.rs +++ b/crates/brk_computer/src/distribution/metrics/activity/full.rs @@ -4,7 +4,7 @@ use brk_types::{Bitcoin, Height, Indexes, Sats, StoredF32, StoredF64, Version}; use derive_more::{Deref, DerefMut}; use vecdb::{AnyStoredVec, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, Identity, LazyPerBlock}; +use crate::internal::{PerBlock, Identity, LazyPerBlock}; use crate::distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}}; @@ -19,8 +19,8 @@ pub struct ActivityFull { pub coinyears_destroyed: LazyPerBlock, - pub dormancy: ComputedPerBlock, - pub velocity: ComputedPerBlock, + pub dormancy: PerBlock, + pub velocity: PerBlock, } impl ActivityFull { @@ -88,8 +88,8 @@ impl ActivityFull { ) -> Result<()> { self.dormancy.height.compute_transform2( starting_indexes.height, - &self.inner.coindays_destroyed.raw.height, - &self.inner.sent.raw.height, + &self.inner.coindays_destroyed.base.height, + &self.inner.sent.base.height, |(i, cdd, sent_sats, ..)| { let sent_btc = f64::from(Bitcoin::from(sent_sats)); if sent_btc == 0.0 { @@ -103,7 +103,7 @@ impl ActivityFull { self.velocity.height.compute_transform2( starting_indexes.height, - &self.inner.sent.raw.height, + &self.inner.sent.base.height, supply_total_sats, |(i, sent_sats, supply_sats, ..)| { let supply = supply_sats.as_u128() as f64; diff --git a/crates/brk_computer/src/distribution/metrics/cohort/all.rs b/crates/brk_computer/src/distribution/metrics/cohort/all.rs index a47275d8c..563258043 100644 --- a/crates/brk_computer/src/distribution/metrics/cohort/all.rs +++ b/crates/brk_computer/src/distribution/metrics/cohort/all.rs @@ -128,8 +128,8 @@ impl AllCohortMetrics { self.asopr.compute_rest_part2( starting_indexes, - &self.realized.minimal.sopr.value_created.raw.height, - &self.realized.minimal.sopr.value_destroyed.raw.height, + &self.realized.minimal.sopr.value_created.base.height, + &self.realized.minimal.sopr.value_destroyed.base.height, under_1h_value_created, under_1h_value_destroyed, exit, diff --git a/crates/brk_computer/src/distribution/metrics/cohort/extended_adjusted.rs b/crates/brk_computer/src/distribution/metrics/cohort/extended_adjusted.rs index df1b120bc..fdc677d87 100644 --- a/crates/brk_computer/src/distribution/metrics/cohort/extended_adjusted.rs +++ b/crates/brk_computer/src/distribution/metrics/cohort/extended_adjusted.rs @@ -80,8 +80,8 @@ impl ExtendedAdjustedCohortMetrics { self.asopr.compute_rest_part2( starting_indexes, - &self.inner.realized.minimal.sopr.value_created.raw.height, - &self.inner.realized.minimal.sopr.value_destroyed.raw.height, + &self.inner.realized.minimal.sopr.value_created.base.height, + &self.inner.realized.minimal.sopr.value_destroyed.base.height, under_1h_value_created, under_1h_value_destroyed, exit, diff --git a/crates/brk_computer/src/distribution/metrics/config.rs b/crates/brk_computer/src/distribution/metrics/config.rs index 8b487cec3..687ff0349 100644 --- a/crates/brk_computer/src/distribution/metrics/config.rs +++ b/crates/brk_computer/src/distribution/metrics/config.rs @@ -8,8 +8,8 @@ use crate::{ indexes, internal::{ AmountPerBlock, AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums, - CachedWindowStarts, CentsType, ComputedPerBlock, - ComputedPerBlockCumulative, ComputedPerBlockCumulativeWithSums, + CachedWindowStarts, CentsType, PerBlock, + PerBlockCumulative, PerBlockCumulativeWithSums, FiatPerBlock, FiatPerBlockCumulativeWithSums, NumericValue, PercentPerBlock, PercentRollingWindows, Price, PriceWithRatioExtendedPerBlock, PriceWithRatioPerBlock, RatioPerBlock, @@ -47,21 +47,21 @@ impl_config_import!( PercentPerBlock, PercentPerBlock, PercentRollingWindows, - Price>, + Price>, ); // Generic types (macro_rules can't parse generic bounds, so written out) -impl ConfigImport for ComputedPerBlock { +impl ConfigImport for PerBlock { fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result { Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) } } -impl ConfigImport for ComputedPerBlockCumulative { +impl ConfigImport for PerBlockCumulative { fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result { Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) } } -impl ConfigImport for ComputedPerBlockCumulativeWithSums +impl ConfigImport for PerBlockCumulativeWithSums where T: NumericValue + JsonSchema + Into, C: NumericValue + JsonSchema, diff --git a/crates/brk_computer/src/distribution/metrics/cost_basis/mod.rs b/crates/brk_computer/src/distribution/metrics/cost_basis/mod.rs index fa262b4d8..2cea43388 100644 --- a/crates/brk_computer/src/distribution/metrics/cost_basis/mod.rs +++ b/crates/brk_computer/src/distribution/metrics/cost_basis/mod.rs @@ -3,7 +3,7 @@ use brk_traversable::Traversable; use brk_types::{BasisPoints16, Cents, Height, Version}; use vecdb::{AnyStoredVec, AnyVec, Rw, StorageMode, WritableVec}; -use crate::internal::{ComputedPerBlock, PercentPerBlock, PercentilesVecs, Price, PERCENTILES_LEN}; +use crate::internal::{PerBlock, PercentPerBlock, PercentilesVecs, Price, PERCENTILES_LEN}; use super::ImportConfig; @@ -11,8 +11,8 @@ use super::ImportConfig; /// Used by all/sth/lth cohorts only. #[derive(Traversable)] pub struct CostBasis { - pub min: Price>, - pub max: Price>, + pub min: Price>, + pub max: Price>, pub percentiles: PercentilesVecs, pub invested_capital: PercentilesVecs, pub supply_density: PercentPerBlock, diff --git a/crates/brk_computer/src/distribution/metrics/outputs/base.rs b/crates/brk_computer/src/distribution/metrics/outputs/base.rs index 723831eb0..fd9984851 100644 --- a/crates/brk_computer/src/distribution/metrics/outputs/base.rs +++ b/crates/brk_computer/src/distribution/metrics/outputs/base.rs @@ -8,19 +8,19 @@ use crate::{ metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}, }, - internal::ComputedPerBlockWithDeltas, + internal::PerBlockWithDeltas, }; /// Base output metrics: utxo_count + delta. #[derive(Traversable)] pub struct OutputsBase { - pub unspent_count: ComputedPerBlockWithDeltas, + pub unspent_count: PerBlockWithDeltas, } impl OutputsBase { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { Ok(Self { - unspent_count: ComputedPerBlockWithDeltas::forced_import( + unspent_count: PerBlockWithDeltas::forced_import( cfg.db, &cfg.name("utxo_count"), cfg.version, diff --git a/crates/brk_computer/src/distribution/metrics/profitability.rs b/crates/brk_computer/src/distribution/metrics/profitability.rs index f1a237a26..de284075d 100644 --- a/crates/brk_computer/src/distribution/metrics/profitability.rs +++ b/crates/brk_computer/src/distribution/metrics/profitability.rs @@ -4,13 +4,13 @@ use brk_traversable::Traversable; use brk_types::{Dollars, Height, Sats, Version}; use vecdb::{AnyStoredVec, AnyVec, Database, Rw, StorageMode, WritableVec}; -use crate::{indexes, internal::ComputedPerBlock}; +use crate::{indexes, internal::PerBlock}; /// Supply + realized cap for a single profitability bucket. #[derive(Traversable)] pub struct ProfitabilityBucket { - pub supply: ComputedPerBlock, - pub realized_cap: ComputedPerBlock, + pub supply: PerBlock, + pub realized_cap: PerBlock, } impl ProfitabilityBucket { @@ -27,13 +27,13 @@ impl ProfitabilityBucket { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - supply: ComputedPerBlock::forced_import( + supply: PerBlock::forced_import( db, &format!("{name}_supply"), version, indexes, )?, - realized_cap: ComputedPerBlock::forced_import( + realized_cap: PerBlock::forced_import( db, &format!("{name}_realized_cap"), version, diff --git a/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs b/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs index 22f49535f..a7389efb3 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs @@ -5,13 +5,13 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode}; use crate::{ distribution::metrics::ImportConfig, - internal::{ComputedPerBlockCumulativeWithSums, RatioCents64, RollingWindows}, + internal::{PerBlockCumulativeWithSums, RatioCents64, RollingWindows}, }; #[derive(Traversable)] pub struct AdjustedSopr { - pub value_created: ComputedPerBlockCumulativeWithSums, - pub value_destroyed: ComputedPerBlockCumulativeWithSums, + pub value_created: PerBlockCumulativeWithSums, + pub value_destroyed: PerBlockCumulativeWithSums, pub ratio: RollingWindows, } @@ -35,13 +35,13 @@ impl AdjustedSopr { exit: &Exit, ) -> Result<()> { // Compute value_created = base.value_created - under_1h.value_created - self.value_created.raw.height.compute_subtract( + self.value_created.base.height.compute_subtract( starting_indexes.height, base_value_created, under_1h_value_created, exit, )?; - self.value_destroyed.raw.height.compute_subtract( + self.value_destroyed.base.height.compute_subtract( starting_indexes.height, base_value_destroyed, under_1h_value_destroyed, diff --git a/crates/brk_computer/src/distribution/metrics/realized/core.rs b/crates/brk_computer/src/distribution/metrics/realized/core.rs index d6b77b0fe..4e9cec4af 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/core.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/core.rs @@ -46,7 +46,7 @@ impl RealizedCore { let neg_realized_loss = LazyPerBlock::from_height_source::( &cfg.name("neg_realized_loss"), cfg.version + Version::ONE, - minimal.loss.raw.cents.height.read_only_boxed_clone(), + minimal.loss.base.cents.height.read_only_boxed_clone(), cfg.indexes, ); @@ -103,10 +103,10 @@ impl RealizedCore { self.minimal .compute_rest_part1(starting_indexes, exit)?; - self.net_pnl.raw.cents.height.compute_transform2( + self.net_pnl.base.cents.height.compute_transform2( starting_indexes.height, - &self.minimal.profit.raw.cents.height, - &self.minimal.loss.raw.cents.height, + &self.minimal.profit.base.cents.height, + &self.minimal.loss.base.cents.height, |(i, profit, loss, ..)| { ( i, diff --git a/crates/brk_computer/src/distribution/metrics/realized/full.rs b/crates/brk_computer/src/distribution/metrics/realized/full.rs index ade95d0f9..8889b449d 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/full.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/full.rs @@ -14,8 +14,8 @@ use crate::{ blocks, distribution::state::{WithCapital, CohortState, CostBasisData, RealizedState}, internal::{ - CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative, - ComputedPerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums, + CentsUnsignedToDollars, PerBlock, PerBlockCumulative, + PerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums, LazyPerBlock, PercentPerBlock, PercentRollingWindows, Price, PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32, RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32, @@ -32,16 +32,16 @@ use super::RealizedCore; #[derive(Traversable)] pub struct RealizedProfit { pub rel_to_rcap: PercentPerBlock, - pub value_created: ComputedPerBlockCumulativeWithSums, - pub value_destroyed: ComputedPerBlockCumulativeWithSums, + pub value_created: PerBlockCumulativeWithSums, + pub value_destroyed: PerBlockCumulativeWithSums, pub distribution_flow: LazyPerBlock, } #[derive(Traversable)] pub struct RealizedLoss { pub rel_to_rcap: PercentPerBlock, - pub value_created: ComputedPerBlockCumulativeWithSums, - pub value_destroyed: ComputedPerBlockCumulativeWithSums, + pub value_created: PerBlockCumulativeWithSums, + pub value_destroyed: PerBlockCumulativeWithSums, pub capitulation_flow: LazyPerBlock, } @@ -63,15 +63,15 @@ pub struct RealizedSopr { #[derive(Traversable)] pub struct RealizedPeakRegret { #[traversable(flatten)] - pub value: ComputedPerBlockCumulative, + pub value: PerBlockCumulative, pub rel_to_rcap: PercentPerBlock, } #[derive(Traversable)] pub struct RealizedInvestor { pub price: PriceWithRatioExtendedPerBlock, - pub lower_price_band: Price>, - pub upper_price_band: Price>, + pub lower_price_band: Price>, + pub upper_price_band: Price>, #[traversable(hidden)] pub cap_raw: M::Stored>, } @@ -115,13 +115,13 @@ impl RealizedFull { let core = RealizedCore::forced_import(cfg)?; // Profit - let profit_value_destroyed: ComputedPerBlockCumulativeWithSums = + let profit_value_destroyed: PerBlockCumulativeWithSums = cfg.import("profit_value_destroyed", v1)?; let profit_flow = LazyPerBlock::from_computed::( &cfg.name("distribution_flow"), cfg.version, - profit_value_destroyed.raw.height.read_only_boxed_clone(), - &profit_value_destroyed.raw, + profit_value_destroyed.base.height.read_only_boxed_clone(), + &profit_value_destroyed.base, ); let profit = RealizedProfit { rel_to_rcap: cfg.import("realized_profit_rel_to_rcap", Version::new(2))?, @@ -131,13 +131,13 @@ impl RealizedFull { }; // Loss - let loss_value_destroyed: ComputedPerBlockCumulativeWithSums = + let loss_value_destroyed: PerBlockCumulativeWithSums = cfg.import("loss_value_destroyed", v1)?; let capitulation_flow = LazyPerBlock::from_computed::( &cfg.name("capitulation_flow"), cfg.version, - loss_value_destroyed.raw.height.read_only_boxed_clone(), - &loss_value_destroyed.raw, + loss_value_destroyed.base.height.read_only_boxed_clone(), + &loss_value_destroyed.base, ); let loss = RealizedLoss { rel_to_rcap: cfg.import("realized_loss_rel_to_rcap", Version::new(2))?, @@ -222,16 +222,16 @@ impl RealizedFull { pub(crate) fn min_stateful_len(&self) -> usize { self.profit .value_created - .raw + .base .height .len() - .min(self.profit.value_destroyed.raw.height.len()) - .min(self.loss.value_created.raw.height.len()) - .min(self.loss.value_destroyed.raw.height.len()) + .min(self.profit.value_destroyed.base.height.len()) + .min(self.loss.value_created.base.height.len()) + .min(self.loss.value_destroyed.base.height.len()) .min(self.investor.price.cents.height.len()) .min(self.cap_raw.len()) .min(self.investor.cap_raw.len()) - .min(self.peak_regret.value.raw.height.len()) + .min(self.peak_regret.value.base.height.len()) } pub(crate) fn truncate_push( @@ -242,22 +242,22 @@ impl RealizedFull { self.core.truncate_push(height, state)?; self.profit .value_created - .raw + .base .height .truncate_push(height, state.realized.profit_value_created())?; self.profit .value_destroyed - .raw + .base .height .truncate_push(height, state.realized.profit_value_destroyed())?; self.loss .value_created - .raw + .base .height .truncate_push(height, state.realized.loss_value_created())?; self.loss .value_destroyed - .raw + .base .height .truncate_push(height, state.realized.loss_value_destroyed())?; self.investor @@ -272,7 +272,7 @@ impl RealizedFull { .truncate_push(height, state.realized.investor_cap_raw())?; self.peak_regret .value - .raw + .base .height .truncate_push(height, state.realized.peak_regret())?; @@ -281,14 +281,14 @@ impl RealizedFull { pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> { let mut vecs = self.core.collect_vecs_mut(); - vecs.push(&mut self.profit.value_created.raw.height as &mut dyn AnyStoredVec); - vecs.push(&mut self.profit.value_destroyed.raw.height); - vecs.push(&mut self.loss.value_created.raw.height); - vecs.push(&mut self.loss.value_destroyed.raw.height); + vecs.push(&mut self.profit.value_created.base.height as &mut dyn AnyStoredVec); + vecs.push(&mut self.profit.value_destroyed.base.height); + vecs.push(&mut self.loss.value_created.base.height); + vecs.push(&mut self.loss.value_destroyed.base.height); vecs.push(&mut self.investor.price.cents.height); vecs.push(&mut self.cap_raw as &mut dyn AnyStoredVec); vecs.push(&mut self.investor.cap_raw as &mut dyn AnyStoredVec); - vecs.push(&mut self.peak_regret.value.raw.height); + vecs.push(&mut self.peak_regret.value.base.height); vecs } @@ -311,22 +311,22 @@ impl RealizedFull { ) -> Result<()> { self.profit .value_created - .raw + .base .height .truncate_push(height, accum.profit_value_created)?; self.profit .value_destroyed - .raw + .base .height .truncate_push(height, accum.profit_value_destroyed)?; self.loss .value_created - .raw + .base .height .truncate_push(height, accum.loss_value_created)?; self.loss .value_destroyed - .raw + .base .height .truncate_push(height, accum.loss_value_destroyed)?; self.cap_raw @@ -351,7 +351,7 @@ impl RealizedFull { self.peak_regret .value - .raw + .base .height .truncate_push(height, accum.peak_regret)?; @@ -410,7 +410,7 @@ impl RealizedFull { .rel_to_rcap .compute_binary::( starting_indexes.height, - &self.core.minimal.profit.raw.cents.height, + &self.core.minimal.profit.base.cents.height, &self.core.minimal.cap.cents.height, exit, )?; @@ -418,7 +418,7 @@ impl RealizedFull { .rel_to_rcap .compute_binary::( starting_indexes.height, - &self.core.minimal.loss.raw.cents.height, + &self.core.minimal.loss.base.cents.height, &self.core.minimal.cap.cents.height, exit, )?; @@ -426,7 +426,7 @@ impl RealizedFull { .rel_to_rcap .compute_binary::( starting_indexes.height, - &self.core.net_pnl.raw.cents.height, + &self.core.net_pnl.base.cents.height, &self.core.minimal.cap.cents.height, exit, )?; @@ -446,10 +446,10 @@ impl RealizedFull { .compute_rest(starting_indexes.height, exit)?; // Gross PnL - self.gross_pnl.raw.cents.height.compute_add( + self.gross_pnl.base.cents.height.compute_add( starting_indexes.height, - &self.core.minimal.profit.raw.cents.height, - &self.core.minimal.loss.raw.cents.height, + &self.core.minimal.profit.base.cents.height, + &self.core.minimal.loss.base.cents.height, exit, )?; self.gross_pnl @@ -478,7 +478,7 @@ impl RealizedFull { .rel_to_rcap .compute_binary::( starting_indexes.height, - &self.peak_regret.value.raw.height, + &self.peak_regret.value.base.height, &self.core.minimal.cap.cents.height, exit, )?; diff --git a/crates/brk_computer/src/distribution/metrics/realized/minimal.rs b/crates/brk_computer/src/distribution/metrics/realized/minimal.rs index 78dce5318..6e3f4e833 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/minimal.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/minimal.rs @@ -11,7 +11,7 @@ use vecdb::{ use crate::{ distribution::state::{CohortState, CostBasisOps, RealizedOps}, internal::{ - ComputedPerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums, + PerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums, FiatPerBlockWithDeltas, Identity, LazyPerBlock, PriceWithRatioPerBlock, }, prices, @@ -21,8 +21,8 @@ use crate::distribution::metrics::ImportConfig; #[derive(Traversable)] pub struct RealizedSoprMinimal { - pub value_created: ComputedPerBlockCumulativeWithSums, - pub value_destroyed: ComputedPerBlockCumulativeWithSums, + pub value_created: PerBlockCumulativeWithSums, + pub value_destroyed: PerBlockCumulativeWithSums, } #[derive(Traversable)] @@ -74,24 +74,24 @@ impl RealizedMinimal { .cents .height .len() - .min(self.profit.raw.cents.height.len()) - .min(self.loss.raw.cents.height.len()) - .min(self.sopr.value_created.raw.height.len()) - .min(self.sopr.value_destroyed.raw.height.len()) + .min(self.profit.base.cents.height.len()) + .min(self.loss.base.cents.height.len()) + .min(self.sopr.value_created.base.height.len()) + .min(self.sopr.value_destroyed.base.height.len()) } pub(crate) fn truncate_push(&mut self, height: Height, state: &CohortState) -> Result<()> { self.cap.cents.height.truncate_push(height, state.realized.cap())?; - self.profit.raw.cents.height.truncate_push(height, state.realized.profit())?; - self.loss.raw.cents.height.truncate_push(height, state.realized.loss())?; + self.profit.base.cents.height.truncate_push(height, state.realized.profit())?; + self.loss.base.cents.height.truncate_push(height, state.realized.loss())?; self.sopr .value_created - .raw + .base .height .truncate_push(height, state.realized.value_created())?; self.sopr .value_destroyed - .raw + .base .height .truncate_push(height, state.realized.value_destroyed())?; Ok(()) @@ -100,10 +100,10 @@ impl RealizedMinimal { pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> { vec![ &mut self.cap.cents.height as &mut dyn AnyStoredVec, - &mut self.profit.raw.cents.height, - &mut self.loss.raw.cents.height, - &mut self.sopr.value_created.raw.height, - &mut self.sopr.value_destroyed.raw.height, + &mut self.profit.base.cents.height, + &mut self.loss.base.cents.height, + &mut self.sopr.value_created.base.height, + &mut self.sopr.value_destroyed.base.height, ] } @@ -114,10 +114,10 @@ impl RealizedMinimal { exit: &Exit, ) -> Result<()> { sum_others!(self, starting_indexes, others, exit; cap.cents.height); - sum_others!(self, starting_indexes, others, exit; profit.raw.cents.height); - sum_others!(self, starting_indexes, others, exit; loss.raw.cents.height); - sum_others!(self, starting_indexes, others, exit; sopr.value_created.raw.height); - sum_others!(self, starting_indexes, others, exit; sopr.value_destroyed.raw.height); + sum_others!(self, starting_indexes, others, exit; profit.base.cents.height); + sum_others!(self, starting_indexes, others, exit; loss.base.cents.height); + sum_others!(self, starting_indexes, others, exit; sopr.value_created.base.height); + sum_others!(self, starting_indexes, others, exit; sopr.value_destroyed.base.height); Ok(()) } diff --git a/crates/brk_computer/src/distribution/metrics/relative/extended_own_market_cap.rs b/crates/brk_computer/src/distribution/metrics/relative/extended_own_market_cap.rs index ecece17a9..1b37cc28d 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/extended_own_market_cap.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/extended_own_market_cap.rs @@ -42,14 +42,14 @@ impl RelativeExtendedOwnMarketCap { self.unrealized_profit_rel_to_own_mcap .compute_binary::( max_from, - &unrealized.profit.raw.usd.height, + &unrealized.profit.base.usd.height, own_market_cap, exit, )?; self.unrealized_loss_rel_to_own_mcap .compute_binary::( max_from, - &unrealized.loss.raw.usd.height, + &unrealized.loss.base.usd.height, own_market_cap, exit, )?; diff --git a/crates/brk_computer/src/distribution/metrics/relative/extended_own_pnl.rs b/crates/brk_computer/src/distribution/metrics/relative/extended_own_pnl.rs index 24bd655e4..5f54f9400 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/extended_own_pnl.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/extended_own_pnl.rs @@ -43,14 +43,14 @@ impl RelativeExtendedOwnPnl { self.unrealized_profit_rel_to_own_gross_pnl .compute_binary::( max_from, - &unrealized.profit.raw.usd.height, + &unrealized.profit.base.usd.height, gross_pnl_usd, exit, )?; self.unrealized_loss_rel_to_own_gross_pnl .compute_binary::( max_from, - &unrealized.loss.raw.usd.height, + &unrealized.loss.base.usd.height, gross_pnl_usd, exit, )?; diff --git a/crates/brk_computer/src/distribution/metrics/relative/full.rs b/crates/brk_computer/src/distribution/metrics/relative/full.rs index 6b217c70f..b1b5de4a4 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/full.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/full.rs @@ -64,14 +64,14 @@ impl RelativeFull { self.unrealized_profit_rel_to_mcap .compute_binary::( max_from, - &unrealized.profit.raw.usd.height, + &unrealized.profit.base.usd.height, market_cap, exit, )?; self.unrealized_loss_rel_to_mcap .compute_binary::( max_from, - &unrealized.loss.raw.usd.height, + &unrealized.loss.base.usd.height, market_cap, exit, )?; diff --git a/crates/brk_computer/src/distribution/metrics/unrealized/basic.rs b/crates/brk_computer/src/distribution/metrics/unrealized/basic.rs index 1e3f590d9..c010bd936 100644 --- a/crates/brk_computer/src/distribution/metrics/unrealized/basic.rs +++ b/crates/brk_computer/src/distribution/metrics/unrealized/basic.rs @@ -34,21 +34,21 @@ impl UnrealizedBasic { pub(crate) fn min_stateful_len(&self) -> usize { self.profit - .raw + .base .cents .height .len() - .min(self.loss.raw.cents.height.len()) + .min(self.loss.base.cents.height.len()) } pub(crate) fn truncate_push(&mut self, height: Height, state: &UnrealizedState) -> Result<()> { self.profit - .raw + .base .cents .height .truncate_push(height, state.unrealized_profit)?; self.loss - .raw + .base .cents .height .truncate_push(height, state.unrealized_loss)?; @@ -57,8 +57,8 @@ impl UnrealizedBasic { pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> { vec![ - &mut self.profit.raw.cents.height as &mut dyn AnyStoredVec, - &mut self.loss.raw.cents.height, + &mut self.profit.base.cents.height as &mut dyn AnyStoredVec, + &mut self.loss.base.cents.height, ] } @@ -68,8 +68,8 @@ impl UnrealizedBasic { others: &[&Self], exit: &Exit, ) -> Result<()> { - sum_others!(self, starting_indexes, others, exit; profit.raw.cents.height); - sum_others!(self, starting_indexes, others, exit; loss.raw.cents.height); + sum_others!(self, starting_indexes, others, exit; profit.base.cents.height); + sum_others!(self, starting_indexes, others, exit; loss.base.cents.height); Ok(()) } diff --git a/crates/brk_computer/src/distribution/metrics/unrealized/core.rs b/crates/brk_computer/src/distribution/metrics/unrealized/core.rs index 6c4a87848..432ee8494 100644 --- a/crates/brk_computer/src/distribution/metrics/unrealized/core.rs +++ b/crates/brk_computer/src/distribution/metrics/unrealized/core.rs @@ -35,8 +35,8 @@ impl UnrealizedCore { let neg_unrealized_loss = LazyPerBlock::from_computed::( &cfg.name("neg_unrealized_loss"), cfg.version, - basic.loss.raw.cents.height.read_only_boxed_clone(), - &basic.loss.raw.cents, + basic.loss.base.cents.height.read_only_boxed_clone(), + &basic.loss.base.cents, ); let net_unrealized_pnl = cfg.import("net_unrealized_pnl", Version::ZERO)?; @@ -90,8 +90,8 @@ impl UnrealizedCore { .height .compute_binary::( starting_indexes.height, - &self.basic.profit.raw.cents.height, - &self.basic.loss.raw.cents.height, + &self.basic.profit.base.cents.height, + &self.basic.loss.base.cents.height, exit, )?; diff --git a/crates/brk_computer/src/distribution/metrics/unrealized/full.rs b/crates/brk_computer/src/distribution/metrics/unrealized/full.rs index 04d4c78ee..7cc2ba484 100644 --- a/crates/brk_computer/src/distribution/metrics/unrealized/full.rs +++ b/crates/brk_computer/src/distribution/metrics/unrealized/full.rs @@ -96,8 +96,8 @@ impl UnrealizedFull { self.gross_pnl.cents.height.compute_add( starting_indexes.height, - &self.inner.core.basic.profit.raw.cents.height, - &self.inner.core.basic.loss.raw.cents.height, + &self.inner.core.basic.profit.base.cents.height, + &self.inner.core.basic.loss.base.cents.height, exit, )?; diff --git a/crates/brk_computer/src/distribution/vecs.rs b/crates/brk_computer/src/distribution/vecs.rs index 4403abe93..40c465471 100644 --- a/crates/brk_computer/src/distribution/vecs.rs +++ b/crates/brk_computer/src/distribution/vecs.rs @@ -23,7 +23,7 @@ use crate::{ state::BlockState, }, indexes, inputs, - internal::{CachedWindowStarts, ComputedPerBlockCumulative, finalize_db, open_db}, + internal::{CachedWindowStarts, PerBlockCumulative, db_utils::{finalize_db, open_db}}, outputs, prices, transactions, }; @@ -70,7 +70,7 @@ pub struct Vecs { #[traversable(wrap = "cohorts", rename = "address")] pub address_cohorts: AddressCohorts, #[traversable(wrap = "cointime")] - pub coinblocks_destroyed: ComputedPerBlockCumulative, + pub coinblocks_destroyed: PerBlockCumulative, pub addresses: AddressMetricsVecs, /// In-memory block state for UTXO processing. Persisted via supply_state. @@ -173,7 +173,7 @@ impl Vecs { utxo_cohorts, address_cohorts, - coinblocks_destroyed: ComputedPerBlockCumulative::forced_import( + coinblocks_destroyed: PerBlockCumulative::forced_import( &db, "coinblocks_destroyed", version + Version::TWO, @@ -489,6 +489,6 @@ impl Vecs { .min(Height::from(self.addresses.funded.min_stateful_len())) .min(Height::from(self.addresses.empty.min_stateful_len())) .min(Height::from(self.addresses.activity.min_stateful_len())) - .min(Height::from(self.coinblocks_destroyed.raw.height.len())) + .min(Height::from(self.coinblocks_destroyed.base.height.len())) } } diff --git a/crates/brk_computer/src/indexes/mod.rs b/crates/brk_computer/src/indexes/mod.rs index afe234454..fc4a3ada8 100644 --- a/crates/brk_computer/src/indexes/mod.rs +++ b/crates/brk_computer/src/indexes/mod.rs @@ -33,7 +33,7 @@ use vecdb::{CachedVec, Database, Exit, ReadableVec, Rw, StorageMode}; use crate::{ blocks, - internal::{finalize_db, open_db}, + internal::db_utils::{finalize_db, open_db}, }; pub use cached_mappings::CachedMappings; diff --git a/crates/brk_computer/src/indicators/import.rs b/crates/brk_computer/src/indicators/import.rs index 9d956dbb1..54e72e0f9 100644 --- a/crates/brk_computer/src/indicators/import.rs +++ b/crates/brk_computer/src/indicators/import.rs @@ -6,7 +6,7 @@ use brk_types::Version; use super::Vecs; use crate::{ indexes, - internal::{finalize_db, open_db, ComputedPerBlock, PercentPerBlock, RatioPerBlock}, + internal::{PerBlock, PercentPerBlock, RatioPerBlock, db_utils::{finalize_db, open_db}}, }; const VERSION: Version = Version::new(1); @@ -27,16 +27,16 @@ impl Vecs { let thermocap_multiple = RatioPerBlock::forced_import_raw(&db, "thermocap_multiple", v, indexes)?; let coindays_destroyed_supply_adjusted = - ComputedPerBlock::forced_import(&db, "coindays_destroyed_supply_adjusted", v, indexes)?; + PerBlock::forced_import(&db, "coindays_destroyed_supply_adjusted", v, indexes)?; let coinyears_destroyed_supply_adjusted = - ComputedPerBlock::forced_import(&db, "coinyears_destroyed_supply_adjusted", v, indexes)?; + PerBlock::forced_import(&db, "coinyears_destroyed_supply_adjusted", v, indexes)?; let dormancy = super::vecs::DormancyVecs { - supply_adjusted: ComputedPerBlock::forced_import(&db, "dormancy_supply_adjusted", v, indexes)?, - flow: ComputedPerBlock::forced_import(&db, "dormancy_flow", v, indexes)?, + supply_adjusted: PerBlock::forced_import(&db, "dormancy_supply_adjusted", v, indexes)?, + flow: PerBlock::forced_import(&db, "dormancy_flow", v, indexes)?, }; - let stock_to_flow = ComputedPerBlock::forced_import(&db, "stock_to_flow", v, indexes)?; + let stock_to_flow = PerBlock::forced_import(&db, "stock_to_flow", v, indexes)?; let seller_exhaustion_constant = - ComputedPerBlock::forced_import(&db, "seller_exhaustion_constant", v, indexes)?; + PerBlock::forced_import(&db, "seller_exhaustion_constant", v, indexes)?; let this = Self { db, diff --git a/crates/brk_computer/src/indicators/vecs.rs b/crates/brk_computer/src/indicators/vecs.rs index 5d389975b..e6a9cff1d 100644 --- a/crates/brk_computer/src/indicators/vecs.rs +++ b/crates/brk_computer/src/indicators/vecs.rs @@ -2,12 +2,12 @@ use brk_traversable::Traversable; use brk_types::{BasisPoints16, BasisPoints32, StoredF32}; use vecdb::{Database, Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, PercentPerBlock, RatioPerBlock}; +use crate::internal::{PerBlock, PercentPerBlock, RatioPerBlock}; #[derive(Traversable)] pub struct DormancyVecs { - pub supply_adjusted: ComputedPerBlock, - pub flow: ComputedPerBlock, + pub supply_adjusted: PerBlock, + pub flow: PerBlock, } #[derive(Traversable)] @@ -19,9 +19,9 @@ pub struct Vecs { pub gini: PercentPerBlock, pub rhodl_ratio: RatioPerBlock, pub thermocap_multiple: RatioPerBlock, - pub coindays_destroyed_supply_adjusted: ComputedPerBlock, - pub coinyears_destroyed_supply_adjusted: ComputedPerBlock, + pub coindays_destroyed_supply_adjusted: PerBlock, + pub coinyears_destroyed_supply_adjusted: PerBlock, pub dormancy: DormancyVecs, - pub stock_to_flow: ComputedPerBlock, - pub seller_exhaustion_constant: ComputedPerBlock, + pub stock_to_flow: PerBlock, + pub seller_exhaustion_constant: PerBlock, } diff --git a/crates/brk_computer/src/inputs/count/import.rs b/crates/brk_computer/src/inputs/count/import.rs index 7ea1d2bc0..2c07ff34e 100644 --- a/crates/brk_computer/src/inputs/count/import.rs +++ b/crates/brk_computer/src/inputs/count/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::{CachedWindowStarts, ComputedPerBlockAggregated}}; +use crate::{indexes, internal::{CachedWindowStarts, PerBlockAggregated}}; impl Vecs { pub(crate) fn forced_import( @@ -12,7 +12,7 @@ impl Vecs { indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { - Ok(Self(ComputedPerBlockAggregated::forced_import( + Ok(Self(PerBlockAggregated::forced_import( db, "input_count", version, diff --git a/crates/brk_computer/src/inputs/count/vecs.rs b/crates/brk_computer/src/inputs/count/vecs.rs index 900143b30..8adf0e565 100644 --- a/crates/brk_computer/src/inputs/count/vecs.rs +++ b/crates/brk_computer/src/inputs/count/vecs.rs @@ -4,9 +4,9 @@ use brk_traversable::Traversable; use brk_types::StoredU64; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedPerBlockAggregated; +use crate::internal::PerBlockAggregated; #[derive(Deref, DerefMut, Traversable)] pub struct Vecs( - #[traversable(flatten)] pub ComputedPerBlockAggregated, + #[traversable(flatten)] pub PerBlockAggregated, ); diff --git a/crates/brk_computer/src/inputs/import.rs b/crates/brk_computer/src/inputs/import.rs index c01252841..4f14611f3 100644 --- a/crates/brk_computer/src/inputs/import.rs +++ b/crates/brk_computer/src/inputs/import.rs @@ -5,7 +5,7 @@ use brk_types::Version; use crate::{ indexes, - internal::{finalize_db, open_db, CachedWindowStarts}, + internal::{CachedWindowStarts, db_utils::{finalize_db, open_db}}, }; use super::{CountVecs, SpentVecs, Vecs}; diff --git a/crates/brk_computer/src/internal/aggregate/distribution.rs b/crates/brk_computer/src/internal/aggregate/distribution.rs index 8c700665b..5130bc6c1 100644 --- a/crates/brk_computer/src/internal/aggregate/distribution.rs +++ b/crates/brk_computer/src/internal/aggregate/distribution.rs @@ -7,7 +7,8 @@ use vecdb::{ }; use crate::internal::{ - ComputedVecValue, DistributionStats, compute_aggregations, compute_aggregations_nblock_window, + ComputedVecValue, DistributionStats, + algo::{compute_aggregations, compute_aggregations_nblock_window}, }; #[derive(Traversable)] diff --git a/crates/brk_computer/src/internal/aggregate/full.rs b/crates/brk_computer/src/internal/aggregate/distribution_full.rs similarity index 87% rename from crates/brk_computer/src/internal/aggregate/full.rs rename to crates/brk_computer/src/internal/aggregate/distribution_full.rs index 577434427..c44cd8d38 100644 --- a/crates/brk_computer/src/internal/aggregate/full.rs +++ b/crates/brk_computer/src/internal/aggregate/distribution_full.rs @@ -6,20 +6,20 @@ use vecdb::{ VecIndex, VecValue, Version, }; -use crate::internal::{ComputedVecValue, compute_aggregations}; +use crate::internal::{ComputedVecValue, algo::compute_aggregations}; use super::Distribution; /// Full stats aggregate: distribution + sum + cumulative #[derive(Traversable)] -pub struct Full { +pub struct DistributionFull { #[traversable(flatten)] pub distribution: Distribution, pub sum: M::Stored>>, pub cumulative: M::Stored>>, } -impl Full { +impl DistributionFull { pub(crate) fn forced_import(db: &Database, name: &str, version: Version) -> Result { Ok(Self { distribution: Distribution::forced_import(db, name, version)?, @@ -65,8 +65,8 @@ impl Full { ) } - pub fn read_only_clone(&self) -> Full { - Full { + pub fn read_only_clone(&self) -> DistributionFull { + DistributionFull { distribution: self.distribution.read_only_clone(), sum: StoredVec::read_only_clone(&self.sum), cumulative: StoredVec::read_only_clone(&self.cumulative), diff --git a/crates/brk_computer/src/internal/aggregate/mod.rs b/crates/brk_computer/src/internal/aggregate/mod.rs index 5d89f7050..c51f59bb7 100644 --- a/crates/brk_computer/src/internal/aggregate/mod.rs +++ b/crates/brk_computer/src/internal/aggregate/mod.rs @@ -1,7 +1,7 @@ mod distribution; -mod full; +mod distribution_full; mod lazy_distribution; pub use distribution::*; -pub use full::*; +pub use distribution_full::*; pub use lazy_distribution::*; diff --git a/crates/brk_computer/src/internal/amount/lazy.rs b/crates/brk_computer/src/internal/amount.rs similarity index 100% rename from crates/brk_computer/src/internal/amount/lazy.rs rename to crates/brk_computer/src/internal/amount.rs diff --git a/crates/brk_computer/src/internal/amount/mod.rs b/crates/brk_computer/src/internal/amount/mod.rs deleted file mode 100644 index 2a1d11a5c..000000000 --- a/crates/brk_computer/src/internal/amount/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod lazy; - -pub use lazy::*; diff --git a/crates/brk_computer/src/internal/per_block/computed/constant.rs b/crates/brk_computer/src/internal/containers/constant.rs similarity index 100% rename from crates/brk_computer/src/internal/per_block/computed/constant.rs rename to crates/brk_computer/src/internal/containers/constant.rs diff --git a/crates/brk_computer/src/internal/containers/mod.rs b/crates/brk_computer/src/internal/containers/mod.rs index a79217bae..24981f0f3 100644 --- a/crates/brk_computer/src/internal/containers/mod.rs +++ b/crates/brk_computer/src/internal/containers/mod.rs @@ -1,9 +1,11 @@ +mod constant; mod distribution_stats; mod per_resolution; mod window_24h; mod windows; mod windows_from_1w; +pub use constant::*; pub use distribution_stats::*; pub use per_resolution::*; pub use window_24h::*; diff --git a/crates/brk_computer/src/internal/containers/windows.rs b/crates/brk_computer/src/internal/containers/windows.rs index 06286b93c..fab1fc86c 100644 --- a/crates/brk_computer/src/internal/containers/windows.rs +++ b/crates/brk_computer/src/internal/containers/windows.rs @@ -1,11 +1,4 @@ use brk_traversable::Traversable; -use brk_types::Height; -use vecdb::CachedVec; - -/// Cached window starts for lazy rolling computations. -/// Clone-cheap (all fields are Arc-backed). Shared across all metrics. -#[derive(Clone)] -pub struct CachedWindowStarts(pub Windows>); #[derive(Clone, Traversable)] pub struct Windows { diff --git a/crates/brk_computer/src/internal/mod.rs b/crates/brk_computer/src/internal/mod.rs index a82aafdf7..16d13b1fc 100644 --- a/crates/brk_computer/src/internal/mod.rs +++ b/crates/brk_computer/src/internal/mod.rs @@ -1,8 +1,8 @@ mod aggregate; -mod algo; +pub(crate) mod algo; mod amount; mod containers; -mod db_utils; +pub(crate) mod db_utils; mod per_block; mod per_tx; mod indexes; @@ -10,10 +10,8 @@ mod traits; mod transform; pub(crate) use aggregate::*; -pub(crate) use algo::*; pub(crate) use amount::*; pub(crate) use containers::*; -pub(crate) use db_utils::*; pub(crate) use per_block::*; pub(crate) use per_tx::*; pub(crate) use indexes::*; diff --git a/crates/brk_computer/src/internal/per_block/amount/base.rs b/crates/brk_computer/src/internal/per_block/amount/base.rs index 7a4589509..29b54d695 100644 --- a/crates/brk_computer/src/internal/per_block/amount/base.rs +++ b/crates/brk_computer/src/internal/per_block/amount/base.rs @@ -6,16 +6,16 @@ use vecdb::{AnyVec, Database, Exit, ReadableCloneableVec, Rw, StorageMode}; use crate::{ indexes, internal::{ - CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock, SatsToBitcoin, SatsToCents, + CentsUnsignedToDollars, PerBlock, LazyPerBlock, SatsToBitcoin, SatsToCents, }, prices, }; #[derive(Traversable)] pub struct AmountPerBlock { - pub sats: ComputedPerBlock, + pub sats: PerBlock, pub btc: LazyPerBlock, - pub cents: ComputedPerBlock, + pub cents: PerBlock, pub usd: LazyPerBlock, } @@ -27,7 +27,7 @@ impl AmountPerBlock { indexes: &indexes::Vecs, ) -> Result { let sats = - ComputedPerBlock::forced_import(db, &format!("{name}_sats"), version, indexes)?; + PerBlock::forced_import(db, &format!("{name}_sats"), version, indexes)?; let btc = LazyPerBlock::from_computed::( name, @@ -37,7 +37,7 @@ impl AmountPerBlock { ); let cents = - ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?; + PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?; let usd = LazyPerBlock::from_computed::( &format!("{name}_usd"), diff --git a/crates/brk_computer/src/internal/per_block/amount/cumulative_sum.rs b/crates/brk_computer/src/internal/per_block/amount/cumulative_sum.rs index 1d5039103..c3a6356c0 100644 --- a/crates/brk_computer/src/internal/per_block/amount/cumulative_sum.rs +++ b/crates/brk_computer/src/internal/per_block/amount/cumulative_sum.rs @@ -11,7 +11,7 @@ use crate::{ #[derive(Traversable)] pub struct AmountPerBlockCumulativeWithSums { - pub raw: AmountPerBlock, + pub base: AmountPerBlock, pub cumulative: AmountPerBlock, pub sum: LazyRollingSumsAmountFromHeight, } @@ -28,7 +28,7 @@ impl AmountPerBlockCumulativeWithSums { ) -> Result { let v = version + VERSION; - let raw = AmountPerBlock::forced_import(db, name, v, indexes)?; + let base = AmountPerBlock::forced_import(db, name, v, indexes)?; let cumulative = AmountPerBlock::forced_import(db, &format!("{name}_cumulative"), v, indexes)?; let sum = LazyRollingSumsAmountFromHeight::new( @@ -41,7 +41,7 @@ impl AmountPerBlockCumulativeWithSums { ); Ok(Self { - raw, + base, cumulative, sum, }) @@ -54,7 +54,7 @@ impl AmountPerBlockCumulativeWithSums { exit: &Exit, compute_sats: impl FnOnce(&mut EagerVec>) -> Result<()>, ) -> Result<()> { - compute_sats(&mut self.raw.sats.height)?; + compute_sats(&mut self.base.sats.height)?; self.compute_rest(max_from, prices, exit) } @@ -67,14 +67,14 @@ impl AmountPerBlockCumulativeWithSums { self.cumulative .sats .height - .compute_cumulative(max_from, &self.raw.sats.height, exit)?; + .compute_cumulative(max_from, &self.base.sats.height, exit)?; - self.raw + self.base .cents .height .compute_binary::( max_from, - &self.raw.sats.height, + &self.base.sats.height, &prices.spot.cents.height, exit, )?; @@ -82,7 +82,7 @@ impl AmountPerBlockCumulativeWithSums { self.cumulative .cents .height - .compute_cumulative(max_from, &self.raw.cents.height, exit)?; + .compute_cumulative(max_from, &self.base.cents.height, exit)?; Ok(()) } diff --git a/crates/brk_computer/src/internal/per_block/amount/rolling_distribution.rs b/crates/brk_computer/src/internal/per_block/amount/rolling_distribution.rs index 207be9fcc..dbed72c49 100644 --- a/crates/brk_computer/src/internal/per_block/amount/rolling_distribution.rs +++ b/crates/brk_computer/src/internal/per_block/amount/rolling_distribution.rs @@ -8,7 +8,7 @@ use crate::{ indexes, internal::{ AmountPerBlock, DistributionStats, WindowStarts, Windows, - compute_rolling_distribution_from_starts, + algo::compute_rolling_distribution_from_starts, }, }; diff --git a/crates/brk_computer/src/internal/per_block/computed/aggregated.rs b/crates/brk_computer/src/internal/per_block/computed/aggregated.rs index 20d4eb7ba..91de22941 100644 --- a/crates/brk_computer/src/internal/per_block/computed/aggregated.rs +++ b/crates/brk_computer/src/internal/per_block/computed/aggregated.rs @@ -1,4 +1,4 @@ -//! ComputedPerBlockAggregated - Full (distribution + sum + cumulative) + RollingFull. +//! PerBlockAggregated - DistributionFull (distribution + sum + cumulative) + RollingComplete. //! //! For metrics aggregated per-block from finer-grained sources (e.g., per-tx data), //! where we want full per-block stats plus rolling window stats. @@ -11,20 +11,20 @@ use vecdb::{Database, Exit, Rw, StorageMode}; use crate::{ indexes, - internal::{CachedWindowStarts, Full, NumericValue, RollingFull, WindowStarts}, + internal::{CachedWindowStarts, DistributionFull, NumericValue, RollingComplete, WindowStarts}, }; #[derive(Traversable)] -pub struct ComputedPerBlockAggregated +pub struct PerBlockAggregated where T: NumericValue + JsonSchema, { #[traversable(flatten)] - pub full: Full, - pub rolling: RollingFull, + pub full: DistributionFull, + pub rolling: RollingComplete, } -impl ComputedPerBlockAggregated +impl PerBlockAggregated where T: NumericValue + JsonSchema, { @@ -35,8 +35,8 @@ where indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { - let full = Full::forced_import(db, name, version)?; - let rolling = RollingFull::forced_import( + let full = DistributionFull::forced_import(db, name, version)?; + let rolling = RollingComplete::forced_import( db, name, version, @@ -48,13 +48,13 @@ where Ok(Self { full, rolling }) } - /// Compute Full stats via closure, then rolling distribution from the per-block sum. + /// Compute DistributionFull stats via closure, then rolling distribution from the per-block sum. pub(crate) fn compute( &mut self, max_from: Height, windows: &WindowStarts<'_>, exit: &Exit, - compute_full: impl FnOnce(&mut Full) -> Result<()>, + compute_full: impl FnOnce(&mut DistributionFull) -> Result<()>, ) -> Result<()> where T: From + Default + Copy + Ord, diff --git a/crates/brk_computer/src/internal/per_block/computed/base.rs b/crates/brk_computer/src/internal/per_block/computed/base.rs index 8b4351e02..4bced8a58 100644 --- a/crates/brk_computer/src/internal/per_block/computed/base.rs +++ b/crates/brk_computer/src/internal/per_block/computed/base.rs @@ -15,7 +15,7 @@ use crate::internal::{Resolutions, ComputedVecValue, NumericValue}; #[derive(Deref, DerefMut, Traversable)] #[traversable(merge)] -pub struct ComputedPerBlock +pub struct PerBlock where T: ComputedVecValue + PartialOrd + JsonSchema, { @@ -26,7 +26,7 @@ where pub resolutions: Box>, } -impl ComputedPerBlock +impl PerBlock where T: NumericValue + JsonSchema, { diff --git a/crates/brk_computer/src/internal/per_block/computed/cumulative.rs b/crates/brk_computer/src/internal/per_block/computed/cumulative.rs index dab0f8dee..df43696bf 100644 --- a/crates/brk_computer/src/internal/per_block/computed/cumulative.rs +++ b/crates/brk_computer/src/internal/per_block/computed/cumulative.rs @@ -1,6 +1,6 @@ -//! ComputedPerBlockCumulative - raw ComputedPerBlock + cumulative ComputedPerBlock. +//! PerBlockCumulative - base PerBlock + cumulative PerBlock. //! -//! Like ComputedPerBlockCumulativeWithSums but without RollingWindows. +//! Like PerBlockCumulativeWithSums but without RollingWindows. //! Used for distribution metrics where rolling is optional per cohort. use brk_error::Result; @@ -11,19 +11,19 @@ use vecdb::{Database, Exit, Rw, StorageMode}; use crate::{ indexes, - internal::{ComputedPerBlock, NumericValue}, + internal::{PerBlock, NumericValue}, }; #[derive(Traversable)] -pub struct ComputedPerBlockCumulative +pub struct PerBlockCumulative where T: NumericValue + JsonSchema, { - pub raw: ComputedPerBlock, - pub cumulative: ComputedPerBlock, + pub base: PerBlock, + pub cumulative: PerBlock, } -impl ComputedPerBlockCumulative +impl PerBlockCumulative where T: NumericValue + JsonSchema, { @@ -33,21 +33,21 @@ where version: Version, indexes: &indexes::Vecs, ) -> Result { - let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?; + let base = PerBlock::forced_import(db, name, version, indexes)?; let cumulative = - ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; + PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; - Ok(Self { raw, cumulative }) + Ok(Self { base, cumulative }) } - /// Compute cumulative from already-filled raw vec. + /// Compute cumulative from already-filled base vec. pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()> where T: Default, { self.cumulative .height - .compute_cumulative(max_from, &self.raw.height, exit)?; + .compute_cumulative(max_from, &self.base.height, exit)?; Ok(()) } } diff --git a/crates/brk_computer/src/internal/per_block/computed/cumulative_sum.rs b/crates/brk_computer/src/internal/per_block/computed/cumulative_sum.rs index 364197f79..c60466bed 100644 --- a/crates/brk_computer/src/internal/per_block/computed/cumulative_sum.rs +++ b/crates/brk_computer/src/internal/per_block/computed/cumulative_sum.rs @@ -1,4 +1,4 @@ -//! ComputedPerBlockCumulativeWithSums - raw ComputedPerBlock + cumulative ComputedPerBlock + lazy rolling sums. +//! PerBlockCumulativeWithSums - base PerBlock + cumulative PerBlock + lazy rolling sums. //! //! Rolling sums are derived lazily from the cumulative vec via LazyDeltaVec. //! No rolling sum vecs are stored on disk. @@ -17,21 +17,21 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{CachedWindowStarts, ComputedPerBlock, LazyRollingSumsFromHeight, NumericValue}, + internal::{CachedWindowStarts, PerBlock, LazyRollingSumsFromHeight, NumericValue}, }; #[derive(Traversable)] -pub struct ComputedPerBlockCumulativeWithSums +pub struct PerBlockCumulativeWithSums where T: NumericValue + JsonSchema, C: NumericValue + JsonSchema, { - pub raw: ComputedPerBlock, - pub cumulative: ComputedPerBlock, + pub base: PerBlock, + pub cumulative: PerBlock, pub sum: LazyRollingSumsFromHeight, } -impl ComputedPerBlockCumulativeWithSums +impl PerBlockCumulativeWithSums where T: NumericValue + JsonSchema + Into, C: NumericValue + JsonSchema, @@ -43,9 +43,9 @@ where indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { - let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?; + let base = PerBlock::forced_import(db, name, version, indexes)?; let cumulative = - ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; + PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; let sum = LazyRollingSumsFromHeight::new( &format!("{name}_sum"), version, @@ -55,34 +55,34 @@ where ); Ok(Self { - raw, + base, cumulative, sum, }) } - /// Compute raw data via closure, then cumulative. Rolling sums are lazy. + /// Compute base data via closure, then cumulative. Rolling sums are lazy. pub(crate) fn compute( &mut self, max_from: Height, exit: &Exit, - compute_raw: impl FnOnce(&mut EagerVec>) -> Result<()>, + compute_base: impl FnOnce(&mut EagerVec>) -> Result<()>, ) -> Result<()> where C: Default, { - compute_raw(&mut self.raw.height)?; + compute_base(&mut self.base.height)?; self.compute_rest(max_from, exit) } - /// Compute cumulative from already-populated raw data. Rolling sums are lazy. + /// Compute cumulative from already-populated base data. Rolling sums are lazy. pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()> where C: Default, { self.cumulative .height - .compute_cumulative(max_from, &self.raw.height, exit)?; + .compute_cumulative(max_from, &self.base.height, exit)?; Ok(()) } } diff --git a/crates/brk_computer/src/internal/per_block/computed/full.rs b/crates/brk_computer/src/internal/per_block/computed/full.rs index 523971313..a9936a07b 100644 --- a/crates/brk_computer/src/internal/per_block/computed/full.rs +++ b/crates/brk_computer/src/internal/per_block/computed/full.rs @@ -1,4 +1,4 @@ -//! ComputedPerBlockFull - raw ComputedPerBlock + cumulative ComputedPerBlock + RollingFull. +//! PerBlockFull - base PerBlock + cumulative PerBlock + RollingComplete. //! //! For metrics with stored per-block data, cumulative sums, and rolling windows. @@ -10,21 +10,21 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{CachedWindowStarts, ComputedPerBlock, NumericValue, RollingFull, WindowStarts}, + internal::{CachedWindowStarts, PerBlock, NumericValue, RollingComplete, WindowStarts}, }; #[derive(Traversable)] -pub struct ComputedPerBlockFull +pub struct PerBlockFull where T: NumericValue + JsonSchema, { - pub raw: ComputedPerBlock, - pub cumulative: ComputedPerBlock, + pub base: PerBlock, + pub cumulative: PerBlock, #[traversable(flatten)] - pub rolling: RollingFull, + pub rolling: RollingComplete, } -impl ComputedPerBlockFull +impl PerBlockFull where T: NumericValue + JsonSchema, { @@ -35,10 +35,10 @@ where indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { - let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?; + let base = PerBlock::forced_import(db, name, version, indexes)?; let cumulative = - ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; - let rolling = RollingFull::forced_import( + PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; + let rolling = RollingComplete::forced_import( db, name, version, @@ -48,30 +48,30 @@ where )?; Ok(Self { - raw, + base, cumulative, rolling, }) } - /// Compute raw data via closure, then cumulative + rolling distribution. + /// Compute base data via closure, then cumulative + rolling distribution. pub(crate) fn compute( &mut self, max_from: Height, windows: &WindowStarts<'_>, exit: &Exit, - compute_raw: impl FnOnce(&mut EagerVec>) -> Result<()>, + compute_base: impl FnOnce(&mut EagerVec>) -> Result<()>, ) -> Result<()> where T: From + Default + Copy + Ord, f64: From, { - compute_raw(&mut self.raw.height)?; + compute_base(&mut self.base.height)?; self.cumulative .height - .compute_cumulative(max_from, &self.raw.height, exit)?; + .compute_cumulative(max_from, &self.base.height, exit)?; self.rolling - .compute(max_from, windows, &self.raw.height, exit)?; + .compute(max_from, windows, &self.base.height, exit)?; Ok(()) } } diff --git a/crates/brk_computer/src/internal/per_block/computed/lazy_resolutions_full.rs b/crates/brk_computer/src/internal/per_block/computed/lazy_rolling.rs similarity index 66% rename from crates/brk_computer/src/internal/per_block/computed/lazy_resolutions_full.rs rename to crates/brk_computer/src/internal/per_block/computed/lazy_rolling.rs index c258fe773..fac2d6bdf 100644 --- a/crates/brk_computer/src/internal/per_block/computed/lazy_resolutions_full.rs +++ b/crates/brk_computer/src/internal/per_block/computed/lazy_rolling.rs @@ -6,33 +6,33 @@ use vecdb::{ReadableCloneableVec, UnaryTransform}; use crate::{ indexes, internal::{ - CachedWindowStarts, ComputedPerBlockFull, ComputedVecValue, LazyPerBlock, LazyRollingFull, + CachedWindowStarts, PerBlockFull, ComputedVecValue, LazyPerBlock, LazyRollingComplete, NumericValue, }, }; -/// Lazy analog of `ResolutionsFull`: lazy cumulative + lazy rolling full. -/// Derived by transforming a `ComputedPerBlockFull`. Zero stored vecs. +/// Lazy analog of `PerBlockRolling`: lazy cumulative + lazy rolling complete. +/// Derived by transforming a `PerBlockFull`. Zero stored vecs. #[derive(Clone, Traversable)] -pub struct LazyResolutionsFull +pub struct LazyPerBlockRolling where T: NumericValue + JsonSchema, S1T: ComputedVecValue + JsonSchema, { pub cumulative: LazyPerBlock, #[traversable(flatten)] - pub rolling: LazyRollingFull, + pub rolling: LazyRollingComplete, } -impl LazyResolutionsFull +impl LazyPerBlockRolling where T: NumericValue + JsonSchema + 'static, S1T: NumericValue + JsonSchema, { - pub(crate) fn from_computed_per_block_full>( + pub(crate) fn from_per_block_full>( name: &str, version: Version, - source: &ComputedPerBlockFull, + source: &PerBlockFull, cached_starts: &CachedWindowStarts, indexes: &indexes::Vecs, ) -> Self { @@ -43,7 +43,7 @@ where &source.cumulative, ); - let rolling = LazyRollingFull::from_rolling_full::( + let rolling = LazyRollingComplete::from_rolling_complete::( name, version, &cumulative.height, diff --git a/crates/brk_computer/src/internal/per_block/computed/mod.rs b/crates/brk_computer/src/internal/per_block/computed/mod.rs index 9c6a53066..4ee0b7ccc 100644 --- a/crates/brk_computer/src/internal/per_block/computed/mod.rs +++ b/crates/brk_computer/src/internal/per_block/computed/mod.rs @@ -1,23 +1,21 @@ mod aggregated; mod base; -mod constant; mod cumulative; mod cumulative_sum; mod resolutions; -mod resolutions_full; -mod lazy_resolutions_full; +mod rolling; +mod lazy_rolling; mod full; mod rolling_average; mod with_deltas; pub use aggregated::*; pub use base::*; -pub use constant::*; pub use cumulative::*; pub use cumulative_sum::*; pub use resolutions::*; -pub use resolutions_full::*; -pub use lazy_resolutions_full::*; +pub use rolling::*; +pub use lazy_rolling::*; pub use full::*; pub use rolling_average::*; pub use with_deltas::*; diff --git a/crates/brk_computer/src/internal/per_block/computed/resolutions_full.rs b/crates/brk_computer/src/internal/per_block/computed/rolling.rs similarity index 70% rename from crates/brk_computer/src/internal/per_block/computed/resolutions_full.rs rename to crates/brk_computer/src/internal/per_block/computed/rolling.rs index d14291ebc..b751a6afd 100644 --- a/crates/brk_computer/src/internal/per_block/computed/resolutions_full.rs +++ b/crates/brk_computer/src/internal/per_block/computed/rolling.rs @@ -1,7 +1,7 @@ -//! ResolutionsFull - LazyAggVec index views + cumulative (from height) + RollingFull. +//! PerBlockRolling - LazyAggVec index views + cumulative (from height) + RollingComplete. //! //! For metrics derived from indexer sources (no stored height vec). -//! Cumulative gets its own ComputedPerBlock so it has LazyAggVec index views too. +//! Cumulative gets its own PerBlock so it has LazyAggVec index views too. use brk_error::Result; use brk_traversable::Traversable; @@ -11,20 +11,20 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; use crate::{ indexes, - internal::{CachedWindowStarts, ComputedPerBlock, NumericValue, RollingFull, WindowStarts}, + internal::{CachedWindowStarts, PerBlock, NumericValue, RollingComplete, WindowStarts}, }; #[derive(Traversable)] -pub struct ResolutionsFull +pub struct PerBlockRolling where T: NumericValue + JsonSchema, { - pub cumulative: ComputedPerBlock, + pub cumulative: PerBlock, #[traversable(flatten)] - pub rolling: RollingFull, + pub rolling: RollingComplete, } -impl ResolutionsFull +impl PerBlockRolling where T: NumericValue + JsonSchema, { @@ -36,8 +36,8 @@ where cached_starts: &CachedWindowStarts, ) -> Result { let cumulative = - ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; - let rolling = RollingFull::forced_import( + PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; + let rolling = RollingComplete::forced_import( db, name, version, diff --git a/crates/brk_computer/src/internal/per_block/computed/rolling_average.rs b/crates/brk_computer/src/internal/per_block/computed/rolling_average.rs index 4398d8861..6cae3ad6d 100644 --- a/crates/brk_computer/src/internal/per_block/computed/rolling_average.rs +++ b/crates/brk_computer/src/internal/per_block/computed/rolling_average.rs @@ -1,4 +1,4 @@ -//! ComputedPerBlock with rolling average (no distribution stats). +//! PerBlock with rolling average (no distribution stats). //! //! Stored height data + f64 cumulative + lazy 4-window rolling averages. //! Rolling averages are computed on-the-fly from the cumulative via DeltaAvg. @@ -15,7 +15,7 @@ use crate::indexes; use crate::internal::{CachedWindowStarts, LazyRollingAvgsFromHeight, NumericValue}; #[derive(Traversable)] -pub struct ComputedPerBlockRollingAverage +pub struct PerBlockRollingAverage where T: NumericValue + JsonSchema, { @@ -26,7 +26,7 @@ where pub average: LazyRollingAvgsFromHeight, } -impl ComputedPerBlockRollingAverage +impl PerBlockRollingAverage where T: NumericValue + JsonSchema, { diff --git a/crates/brk_computer/src/internal/per_block/computed/with_deltas.rs b/crates/brk_computer/src/internal/per_block/computed/with_deltas.rs index 3d10ceea9..1145651e2 100644 --- a/crates/brk_computer/src/internal/per_block/computed/with_deltas.rs +++ b/crates/brk_computer/src/internal/per_block/computed/with_deltas.rs @@ -8,12 +8,12 @@ use vecdb::{Rw, StorageMode}; use crate::{ indexes, internal::{ - BpsType, CachedWindowStarts, ComputedPerBlock, LazyRollingDeltasFromHeight, NumericValue, + BpsType, CachedWindowStarts, PerBlock, LazyRollingDeltasFromHeight, NumericValue, }, }; #[derive(Deref, DerefMut, Traversable)] -pub struct ComputedPerBlockWithDeltas +pub struct PerBlockWithDeltas where S: NumericValue + JsonSchema + Into, C: NumericValue + JsonSchema + From, @@ -22,11 +22,11 @@ where #[deref] #[deref_mut] #[traversable(flatten)] - pub inner: ComputedPerBlock, + pub inner: PerBlock, pub delta: LazyRollingDeltasFromHeight, } -impl ComputedPerBlockWithDeltas +impl PerBlockWithDeltas where S: NumericValue + JsonSchema + Into, C: NumericValue + JsonSchema + From, @@ -40,7 +40,7 @@ where indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { - let inner = ComputedPerBlock::forced_import(db, name, version, indexes)?; + let inner = PerBlock::forced_import(db, name, version, indexes)?; let delta = LazyRollingDeltasFromHeight::new( &format!("{name}_delta"), diff --git a/crates/brk_computer/src/internal/per_block/fiat/base.rs b/crates/brk_computer/src/internal/per_block/fiat/base.rs index 1da01a0aa..670166a57 100644 --- a/crates/brk_computer/src/internal/per_block/fiat/base.rs +++ b/crates/brk_computer/src/internal/per_block/fiat/base.rs @@ -7,7 +7,7 @@ use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode, UnaryTransform}; use crate::{ indexes, internal::{ - CentsSignedToDollars, CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock, + CentsSignedToDollars, CentsUnsignedToDollars, PerBlock, LazyPerBlock, NumericValue, }, }; @@ -29,7 +29,7 @@ impl CentsType for CentsSigned { /// Generic over `C` to support both `Cents` (unsigned) and `CentsSigned` (signed). #[derive(Traversable)] pub struct FiatPerBlock { - pub cents: ComputedPerBlock, + pub cents: PerBlock, pub usd: LazyPerBlock, } @@ -41,7 +41,7 @@ impl FiatPerBlock { indexes: &indexes::Vecs, ) -> Result { let cents = - ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?; + PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?; let usd = LazyPerBlock::from_computed::( name, version, diff --git a/crates/brk_computer/src/internal/per_block/fiat/cumulative_sum.rs b/crates/brk_computer/src/internal/per_block/fiat/cumulative_sum.rs index b1d2c8512..0057a4175 100644 --- a/crates/brk_computer/src/internal/per_block/fiat/cumulative_sum.rs +++ b/crates/brk_computer/src/internal/per_block/fiat/cumulative_sum.rs @@ -10,7 +10,7 @@ use crate::{ #[derive(Traversable)] pub struct FiatPerBlockCumulativeWithSums { - pub raw: FiatPerBlock, + pub base: FiatPerBlock, pub cumulative: FiatPerBlock, pub sum: LazyRollingSumsFiatFromHeight, } @@ -23,7 +23,7 @@ impl FiatPerBlockCumulativeWithSums { indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { - let raw = FiatPerBlock::forced_import(db, name, version, indexes)?; + let base = FiatPerBlock::forced_import(db, name, version, indexes)?; let cumulative = FiatPerBlock::forced_import( db, &format!("{name}_cumulative"), @@ -37,7 +37,7 @@ impl FiatPerBlockCumulativeWithSums { cached_starts, indexes, ); - Ok(Self { raw, cumulative, sum }) + Ok(Self { base, cumulative, sum }) } pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()> @@ -47,7 +47,7 @@ impl FiatPerBlockCumulativeWithSums { self.cumulative .cents .height - .compute_cumulative(max_from, &self.raw.cents.height, exit)?; + .compute_cumulative(max_from, &self.base.cents.height, exit)?; Ok(()) } } diff --git a/crates/brk_computer/src/internal/per_block/fiat/lazy.rs b/crates/brk_computer/src/internal/per_block/fiat/lazy.rs index a7c6bf6cf..4a7b0f937 100644 --- a/crates/brk_computer/src/internal/per_block/fiat/lazy.rs +++ b/crates/brk_computer/src/internal/per_block/fiat/lazy.rs @@ -2,7 +2,7 @@ use brk_traversable::Traversable; use brk_types::{Dollars, Version}; use vecdb::ReadableCloneableVec; -use crate::internal::{CentsType, ComputedPerBlock, Identity, LazyPerBlock, NumericValue}; +use crate::internal::{CentsType, PerBlock, Identity, LazyPerBlock, NumericValue}; /// Lazy fiat: both cents and usd are lazy views of a stored source. /// Zero extra stored vecs. @@ -16,7 +16,7 @@ impl LazyFiatPerBlock { pub(crate) fn from_computed( name: &str, version: Version, - source: &ComputedPerBlock, + source: &PerBlock, ) -> Self where C: NumericValue, diff --git a/crates/brk_computer/src/internal/per_block/lazy/base.rs b/crates/brk_computer/src/internal/per_block/lazy/base.rs index 113f26f21..b26e96618 100644 --- a/crates/brk_computer/src/internal/per_block/lazy/base.rs +++ b/crates/brk_computer/src/internal/per_block/lazy/base.rs @@ -6,7 +6,7 @@ use vecdb::{LazyVecFrom1, ReadableBoxedVec, ReadableCloneableVec, UnaryTransform use crate::{ indexes, - internal::{ComputedPerBlock, ComputedVecValue, DerivedResolutions, NumericValue}, + internal::{PerBlock, ComputedVecValue, DerivedResolutions, NumericValue}, }; #[derive(Clone, Deref, DerefMut, Traversable)] #[traversable(merge)] @@ -31,7 +31,7 @@ where name: &str, version: Version, height_source: ReadableBoxedVec, - source: &ComputedPerBlock, + source: &PerBlock, ) -> Self where S1T: NumericValue, diff --git a/crates/brk_computer/src/internal/per_block/lazy/derived_resolutions.rs b/crates/brk_computer/src/internal/per_block/lazy/derived_resolutions.rs index fa534b236..19f9b5174 100644 --- a/crates/brk_computer/src/internal/per_block/lazy/derived_resolutions.rs +++ b/crates/brk_computer/src/internal/per_block/lazy/derived_resolutions.rs @@ -10,7 +10,7 @@ use vecdb::{ReadableBoxedVec, ReadableCloneableVec, UnaryTransform, VecValue}; use crate::{ indexes, internal::{ - ComputedPerBlock, Resolutions, ComputedVecValue, NumericValue, PerResolution, + PerBlock, Resolutions, ComputedVecValue, NumericValue, PerResolution, }, }; @@ -50,7 +50,7 @@ where pub(crate) fn from_computed>( name: &str, version: Version, - source: &ComputedPerBlock, + source: &PerBlock, ) -> Self where S1T: NumericValue, diff --git a/crates/brk_computer/src/internal/per_block/percent/base.rs b/crates/brk_computer/src/internal/per_block/percent/base.rs index d5d30d1d7..72ea6f7bd 100644 --- a/crates/brk_computer/src/internal/per_block/percent/base.rs +++ b/crates/brk_computer/src/internal/per_block/percent/base.rs @@ -7,10 +7,10 @@ use vecdb::{ use crate::{ indexes, - internal::{BpsType, ComputeDrawdown}, + internal::{BpsType, algo::ComputeDrawdown}, }; -use crate::internal::{ComputedPerBlock, LazyPerBlock}; +use crate::internal::{PerBlock, LazyPerBlock}; /// Basis-point storage with both ratio and percentage float views. /// @@ -20,7 +20,7 @@ use crate::internal::{ComputedPerBlock, LazyPerBlock}; /// - `percent`: bps / 100 (e.g., 4523 bps -> 45.23%) #[derive(Traversable)] pub struct PercentPerBlock { - pub bps: ComputedPerBlock, + pub bps: PerBlock, pub ratio: LazyPerBlock, pub percent: LazyPerBlock, } @@ -32,7 +32,7 @@ impl PercentPerBlock { version: Version, indexes: &indexes::Vecs, ) -> Result { - let bps = ComputedPerBlock::forced_import(db, &format!("{name}_bps"), version, indexes)?; + let bps = PerBlock::forced_import(db, &format!("{name}_bps"), version, indexes)?; let bps_clone = bps.height.read_only_boxed_clone(); let ratio = LazyPerBlock::from_computed::( diff --git a/crates/brk_computer/src/internal/per_block/percent/lazy.rs b/crates/brk_computer/src/internal/per_block/percent/lazy.rs new file mode 100644 index 000000000..fae815648 --- /dev/null +++ b/crates/brk_computer/src/internal/per_block/percent/lazy.rs @@ -0,0 +1,46 @@ +use brk_traversable::Traversable; +use brk_types::{StoredF32, Version}; +use vecdb::{ReadableCloneableVec, UnaryTransform}; + +use crate::internal::{BpsType, LazyPerBlock, PercentPerBlock}; + +/// Fully lazy variant of `PercentPerBlock` — no stored vecs. +/// +/// BPS values are lazily derived from a source `PercentPerBlock` via a unary transform, +/// and ratio/percent float views are chained from the lazy BPS. +#[derive(Clone, Traversable)] +pub struct LazyPercentPerBlock { + pub bps: LazyPerBlock, + pub ratio: LazyPerBlock, + pub percent: LazyPerBlock, +} + +impl LazyPercentPerBlock { + /// Create from a stored `PercentPerBlock` source via a BPS-to-BPS unary transform. + pub(crate) fn from_percent>( + name: &str, + version: Version, + source: &PercentPerBlock, + ) -> Self { + let bps = LazyPerBlock::from_computed::( + &format!("{name}_bps"), + version, + source.bps.height.read_only_boxed_clone(), + &source.bps, + ); + + let ratio = LazyPerBlock::from_lazy::( + &format!("{name}_ratio"), + version, + &bps, + ); + + let percent = LazyPerBlock::from_lazy::(name, version, &bps); + + Self { + bps, + ratio, + percent, + } + } +} diff --git a/crates/brk_computer/src/internal/per_block/percent/lazy_windows.rs b/crates/brk_computer/src/internal/per_block/percent/lazy_windows.rs new file mode 100644 index 000000000..33a502f4a --- /dev/null +++ b/crates/brk_computer/src/internal/per_block/percent/lazy_windows.rs @@ -0,0 +1,33 @@ +use brk_traversable::Traversable; +use brk_types::Version; +use derive_more::{Deref, DerefMut}; +use vecdb::UnaryTransform; + +use crate::internal::{BpsType, PercentRollingWindows, Windows}; + +use super::LazyPercentPerBlock; + +/// Fully lazy rolling percent windows — 4 windows (24h, 1w, 1m, 1y), +/// each with lazy BPS + lazy ratio/percent float views. +/// +/// No stored vecs. All values derived from a source `PercentRollingWindows`. +#[derive(Clone, Deref, DerefMut, Traversable)] +#[traversable(transparent)] +pub struct LazyPercentRollingWindows(pub Windows>); + +impl LazyPercentRollingWindows { + /// Create from a stored `PercentRollingWindows` source via a BPS-to-BPS unary transform. + pub(crate) fn from_rolling>( + name: &str, + version: Version, + source: &PercentRollingWindows, + ) -> Self { + Self(source.0.map_with_suffix(|suffix, source_window| { + LazyPercentPerBlock::from_percent::( + &format!("{name}_{suffix}"), + version, + source_window, + ) + })) + } +} diff --git a/crates/brk_computer/src/internal/per_block/percent/mod.rs b/crates/brk_computer/src/internal/per_block/percent/mod.rs index 0afe55ae3..32f1fe257 100644 --- a/crates/brk_computer/src/internal/per_block/percent/mod.rs +++ b/crates/brk_computer/src/internal/per_block/percent/mod.rs @@ -1,7 +1,11 @@ mod base; +mod lazy; +mod lazy_windows; mod rolling_average; mod windows; pub use base::*; +pub use lazy::*; +pub use lazy_windows::*; pub use rolling_average::*; pub use windows::*; diff --git a/crates/brk_computer/src/internal/per_block/percent/rolling_average.rs b/crates/brk_computer/src/internal/per_block/percent/rolling_average.rs index 0d132ba88..ddfacab85 100644 --- a/crates/brk_computer/src/internal/per_block/percent/rolling_average.rs +++ b/crates/brk_computer/src/internal/per_block/percent/rolling_average.rs @@ -8,12 +8,12 @@ use crate::{ internal::{BpsType, CachedWindowStarts}, }; -use crate::internal::{ComputedPerBlockRollingAverage, LazyPerBlock}; +use crate::internal::{PerBlockRollingAverage, LazyPerBlock}; /// Like PercentPerBlock but with rolling average stats on the bps data. #[derive(Traversable)] pub struct PercentPerBlockRollingAverage { - pub bps: ComputedPerBlockRollingAverage, + pub bps: PerBlockRollingAverage, pub ratio: LazyPerBlock, pub percent: LazyPerBlock, } @@ -26,7 +26,7 @@ impl PercentPerBlockRollingAverage { indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { - let bps = ComputedPerBlockRollingAverage::forced_import( + let bps = PerBlockRollingAverage::forced_import( db, &format!("{name}_bps"), version, diff --git a/crates/brk_computer/src/internal/per_block/percentiles.rs b/crates/brk_computer/src/internal/per_block/percentiles.rs index 33db180b5..1db4b0ac9 100644 --- a/crates/brk_computer/src/internal/per_block/percentiles.rs +++ b/crates/brk_computer/src/internal/per_block/percentiles.rs @@ -4,7 +4,7 @@ use brk_types::{Cents, Height, Version}; use vecdb::{AnyExportableVec, Database, ReadOnlyClone, Ro, Rw, StorageMode, WritableVec}; use crate::indexes; -use crate::internal::{ComputedPerBlock, Price}; +use crate::internal::{PerBlock, Price}; pub const PERCENTILES: [u8; 19] = [ 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, @@ -12,7 +12,7 @@ pub const PERCENTILES: [u8; 19] = [ pub const PERCENTILES_LEN: usize = PERCENTILES.len(); pub struct PercentilesVecs { - pub vecs: [Price>; PERCENTILES_LEN], + pub vecs: [Price>; PERCENTILES_LEN], } const VERSION: Version = Version::ONE; @@ -73,7 +73,7 @@ impl ReadOnlyClone for PercentilesVecs { impl Traversable for PercentilesVecs where - Price>: Traversable, + Price>: Traversable, { fn to_tree_node(&self) -> TreeNode { TreeNode::Branch( diff --git a/crates/brk_computer/src/internal/per_block/price.rs b/crates/brk_computer/src/internal/per_block/price.rs index c6af82837..888c5c6cd 100644 --- a/crates/brk_computer/src/internal/per_block/price.rs +++ b/crates/brk_computer/src/internal/per_block/price.rs @@ -10,7 +10,7 @@ use brk_types::{Cents, Dollars, SatsFract, Version}; use schemars::JsonSchema; use vecdb::{Database, ReadableCloneableVec, UnaryTransform}; -use super::{ComputedPerBlock, LazyPerBlock}; +use super::{PerBlock, LazyPerBlock}; use crate::{ indexes, internal::{CentsUnsignedToDollars, ComputedVecValue, DollarsToSatsFract, NumericValue}, @@ -24,7 +24,7 @@ pub struct Price { pub sats: LazyPerBlock, } -impl Price> { +impl Price> { /// Import from database: stored cents, lazy USD + sats. pub(crate) fn forced_import( db: &Database, @@ -33,7 +33,7 @@ impl Price> { indexes: &indexes::Vecs, ) -> Result { let cents = - ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?; + PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?; let usd = LazyPerBlock::from_computed::( name, version, @@ -57,7 +57,7 @@ where pub(crate) fn from_cents_source>( name: &str, version: Version, - source: &ComputedPerBlock, + source: &PerBlock, ) -> Self { let cents = LazyPerBlock::from_computed::( &format!("{name}_cents"), diff --git a/crates/brk_computer/src/internal/per_block/ratio/base.rs b/crates/brk_computer/src/internal/per_block/ratio/base.rs index 7b211807e..b5e35c492 100644 --- a/crates/brk_computer/src/internal/per_block/ratio/base.rs +++ b/crates/brk_computer/src/internal/per_block/ratio/base.rs @@ -5,12 +5,12 @@ use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode}; use crate::{ indexes, - internal::{BpsType, ComputedPerBlock, LazyPerBlock}, + internal::{BpsType, PerBlock, LazyPerBlock}, }; #[derive(Traversable)] pub struct RatioPerBlock { - pub bps: ComputedPerBlock, + pub bps: PerBlock, pub ratio: LazyPerBlock, } @@ -34,7 +34,7 @@ impl RatioPerBlock { ) -> Result { let v = version + VERSION; - let bps = ComputedPerBlock::forced_import(db, &format!("{name}_bps"), v, indexes)?; + let bps = PerBlock::forced_import(db, &format!("{name}_bps"), v, indexes)?; let ratio = LazyPerBlock::from_computed::( name, diff --git a/crates/brk_computer/src/internal/per_block/ratio/percentiles.rs b/crates/brk_computer/src/internal/per_block/ratio/percentiles.rs index d11caffdb..35a84ecbb 100644 --- a/crates/brk_computer/src/internal/per_block/ratio/percentiles.rs +++ b/crates/brk_computer/src/internal/per_block/ratio/percentiles.rs @@ -8,16 +8,16 @@ use vecdb::{ use crate::{ indexes, - internal::{ExpandingPercentiles, Price, PriceTimesRatioBp32Cents}, + internal::{Price, PriceTimesRatioBp32Cents, algo::ExpandingPercentiles}, }; -use super::{super::ComputedPerBlock, RatioPerBlock}; +use super::{super::PerBlock, RatioPerBlock}; #[derive(Traversable)] pub struct RatioBand { #[traversable(flatten)] pub ratio: RatioPerBlock, - pub price: Price>, + pub price: Price>, } #[derive(Traversable)] diff --git a/crates/brk_computer/src/internal/per_block/ratio/price_extended.rs b/crates/brk_computer/src/internal/per_block/ratio/price_extended.rs index 73dc707c1..c297134cf 100644 --- a/crates/brk_computer/src/internal/per_block/ratio/price_extended.rs +++ b/crates/brk_computer/src/internal/per_block/ratio/price_extended.rs @@ -4,17 +4,17 @@ use brk_types::{BasisPoints32, Cents, Dollars, Height, Indexes, SatsFract, Store use derive_more::{Deref, DerefMut}; use vecdb::{Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, LazyPerBlock, Price}; +use crate::internal::{PerBlock, LazyPerBlock, Price}; use crate::{indexes, prices}; use super::{RatioPerBlock, RatioPerBlockPercentiles}; #[derive(Traversable)] pub struct PriceWithRatioPerBlock { - pub cents: ComputedPerBlock, + pub cents: PerBlock, pub usd: LazyPerBlock, pub sats: LazyPerBlock, - pub bps: ComputedPerBlock, + pub bps: PerBlock, pub ratio: LazyPerBlock, } diff --git a/crates/brk_computer/src/internal/per_block/rolling/full.rs b/crates/brk_computer/src/internal/per_block/rolling/complete.rs similarity index 91% rename from crates/brk_computer/src/internal/per_block/rolling/full.rs rename to crates/brk_computer/src/internal/per_block/rolling/complete.rs index c0cbd85cb..9a6f8f7f4 100644 --- a/crates/brk_computer/src/internal/per_block/rolling/full.rs +++ b/crates/brk_computer/src/internal/per_block/rolling/complete.rs @@ -1,4 +1,4 @@ -//! RollingFull - Lazy rolling sums + stored rolling distribution per window. +//! RollingComplete - Lazy rolling sums + stored rolling distribution per window. use brk_error::Result; @@ -17,7 +17,7 @@ use crate::{ /// Lazy rolling sums + stored rolling distribution (8 stats × 4 windows). #[derive(Traversable)] -pub struct RollingFull +pub struct RollingComplete where T: NumericValue + JsonSchema, { @@ -26,7 +26,7 @@ where pub distribution: RollingDistribution, } -impl RollingFull +impl RollingComplete where T: NumericValue + JsonSchema, { diff --git a/crates/brk_computer/src/internal/per_block/rolling/distribution.rs b/crates/brk_computer/src/internal/per_block/rolling/distribution.rs index f57457d76..6c051ce1a 100644 --- a/crates/brk_computer/src/internal/per_block/rolling/distribution.rs +++ b/crates/brk_computer/src/internal/per_block/rolling/distribution.rs @@ -10,7 +10,7 @@ use crate::{ indexes, internal::{ ComputedVecValue, DistributionStats, NumericValue, RollingWindows, WindowStarts, - compute_rolling_distribution_from_starts, + algo::compute_rolling_distribution_from_starts, }, }; diff --git a/crates/brk_computer/src/internal/per_block/rolling/lazy_full.rs b/crates/brk_computer/src/internal/per_block/rolling/lazy_complete.rs similarity index 77% rename from crates/brk_computer/src/internal/per_block/rolling/lazy_full.rs rename to crates/brk_computer/src/internal/per_block/rolling/lazy_complete.rs index 11f38b36b..8903b0d69 100644 --- a/crates/brk_computer/src/internal/per_block/rolling/lazy_full.rs +++ b/crates/brk_computer/src/internal/per_block/rolling/lazy_complete.rs @@ -1,22 +1,20 @@ use brk_traversable::Traversable; -use brk_types::Version; +use brk_types::{Height, Version}; use schemars::JsonSchema; use vecdb::{ReadableCloneableVec, UnaryTransform}; -use brk_types::Height; - use crate::{ indexes, internal::{ CachedWindowStarts, ComputedVecValue, LazyRollingDistribution, LazyRollingSumsFromHeight, - NumericValue, RollingFull, + NumericValue, RollingComplete, }, }; -/// Lazy analog of `RollingFull`: lazy rolling sums + lazy rolling distribution. +/// Lazy analog of `RollingComplete`: lazy rolling sums + lazy rolling distribution. /// Zero stored vecs. #[derive(Clone, Traversable)] -pub struct LazyRollingFull +pub struct LazyRollingComplete where T: NumericValue + JsonSchema, S1T: ComputedVecValue + JsonSchema, @@ -26,16 +24,16 @@ where pub distribution: LazyRollingDistribution, } -impl LazyRollingFull +impl LazyRollingComplete where T: NumericValue + JsonSchema + 'static, S1T: NumericValue + JsonSchema, { - pub(crate) fn from_rolling_full>( + pub(crate) fn from_rolling_complete>( name: &str, version: Version, cumulative: &(impl ReadableCloneableVec + 'static), - source: &RollingFull, + source: &RollingComplete, cached_starts: &CachedWindowStarts, indexes: &indexes::Vecs, ) -> Self { diff --git a/crates/brk_computer/src/internal/per_block/rolling/mod.rs b/crates/brk_computer/src/internal/per_block/rolling/mod.rs index 2d9c9a8fc..3e991db44 100644 --- a/crates/brk_computer/src/internal/per_block/rolling/mod.rs +++ b/crates/brk_computer/src/internal/per_block/rolling/mod.rs @@ -2,9 +2,9 @@ mod avg; mod avgs; mod delta; mod distribution; -mod full; +mod complete; +mod lazy_complete; mod lazy_distribution; -mod lazy_full; mod sum; mod sums; mod windows; @@ -13,9 +13,9 @@ pub use avg::*; pub use avgs::*; pub use delta::*; pub use distribution::*; -pub use full::*; +pub use complete::*; +pub use lazy_complete::*; pub use lazy_distribution::*; -pub use lazy_full::*; pub use sum::*; pub use sums::*; pub use windows::*; diff --git a/crates/brk_computer/src/internal/per_block/rolling/windows.rs b/crates/brk_computer/src/internal/per_block/rolling/windows.rs index 7eafe7c5b..b9d8b4af8 100644 --- a/crates/brk_computer/src/internal/per_block/rolling/windows.rs +++ b/crates/brk_computer/src/internal/per_block/rolling/windows.rs @@ -1,4 +1,4 @@ -//! RollingWindows - newtype on Windows with ComputedPerBlock per window duration. +//! RollingWindows - newtype on Windows with PerBlock per window duration. //! //! Each of the 4 windows (24h, 1w, 1m, 1y) contains a height-level stored vec //! plus all 17 LazyAggVec index views. @@ -11,18 +11,25 @@ use derive_more::{Deref, DerefMut}; use schemars::JsonSchema; use vecdb::{Database, EagerVec, PcoVec, Rw, StorageMode}; +use vecdb::CachedVec; + use crate::{ indexes, - internal::{ComputedPerBlock, ComputedVecValue, NumericValue, RollingWindow24h, Windows, WindowsFrom1w}, + internal::{PerBlock, ComputedVecValue, NumericValue, RollingWindow24h, Windows, WindowsFrom1w}, }; +/// Cached window starts for lazy rolling computations. +/// Clone-cheap (all fields are Arc-backed). Shared across all metrics. +#[derive(Clone)] +pub struct CachedWindowStarts(pub Windows>); + /// Rolling window start heights — the 4 height-ago vecs (24h, 1w, 1m, 1y). pub type WindowStarts<'a> = Windows<&'a EagerVec>>; /// 4 rolling window vecs (24h, 1w, 1m, 1y), each with height data + all 17 index views. #[derive(Deref, DerefMut, Traversable)] #[traversable(transparent)] -pub struct RollingWindows(pub Windows>) +pub struct RollingWindows(pub Windows>) where T: ComputedVecValue + PartialOrd + JsonSchema; @@ -37,16 +44,16 @@ where indexes: &indexes::Vecs, ) -> Result { Ok(Self(Windows::try_from_fn(|suffix| { - ComputedPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes) + PerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes) })?)) } } -/// Single 24h rolling window backed by ComputedPerBlock (1 stored vec). +/// Single 24h rolling window backed by PerBlock (1 stored vec). #[derive(Deref, DerefMut, Traversable)] #[traversable(transparent)] pub struct RollingWindow24hPerBlock( - pub RollingWindow24h>, + pub RollingWindow24h>, ) where T: ComputedVecValue + PartialOrd + JsonSchema; @@ -62,7 +69,7 @@ where indexes: &indexes::Vecs, ) -> Result { Ok(Self(RollingWindow24h { - _24h: ComputedPerBlock::forced_import( + _24h: PerBlock::forced_import( db, &format!("{name}_24h"), version, @@ -75,7 +82,7 @@ where /// Extended rolling windows: 1w + 1m + 1y (3 stored vecs). #[derive(Deref, DerefMut, Traversable)] #[traversable(transparent)] -pub struct RollingWindowsFrom1w(pub WindowsFrom1w>) +pub struct RollingWindowsFrom1w(pub WindowsFrom1w>) where T: ComputedVecValue + PartialOrd + JsonSchema; @@ -90,7 +97,7 @@ where indexes: &indexes::Vecs, ) -> Result { Ok(Self(WindowsFrom1w::try_from_fn(|suffix| { - ComputedPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes) + PerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes) })?)) } } diff --git a/crates/brk_computer/src/internal/per_block/stddev/base.rs b/crates/brk_computer/src/internal/per_block/stddev/base.rs index 30ffa8e0b..3d26be4bb 100644 --- a/crates/brk_computer/src/internal/per_block/stddev/base.rs +++ b/crates/brk_computer/src/internal/per_block/stddev/base.rs @@ -3,15 +3,15 @@ use brk_traversable::Traversable; use brk_types::{Height, Indexes, StoredF32, Version}; use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; -use crate::{blocks, indexes, internal::ComputedPerBlock}; +use crate::{blocks, indexes, internal::PerBlock}; use super::period_suffix; #[derive(Traversable)] pub struct StdDevPerBlock { days: usize, - pub sma: ComputedPerBlock, - pub sd: ComputedPerBlock, + pub sma: PerBlock, + pub sd: PerBlock, } impl StdDevPerBlock { @@ -27,8 +27,8 @@ impl StdDevPerBlock { let p = period_suffix(period); let sma = - ComputedPerBlock::forced_import(db, &format!("{name}_sma{p}"), version, indexes)?; - let sd = ComputedPerBlock::forced_import(db, &format!("{name}_sd{p}"), version, indexes)?; + PerBlock::forced_import(db, &format!("{name}_sma{p}"), version, indexes)?; + let sd = PerBlock::forced_import(db, &format!("{name}_sd{p}"), version, indexes)?; Ok(Self { days, sma, sd }) } diff --git a/crates/brk_computer/src/internal/per_block/stddev/extended.rs b/crates/brk_computer/src/internal/per_block/stddev/extended.rs index 5e1b01016..e8bfba4d8 100644 --- a/crates/brk_computer/src/internal/per_block/stddev/extended.rs +++ b/crates/brk_computer/src/internal/per_block/stddev/extended.rs @@ -8,23 +8,23 @@ use vecdb::{ use crate::{ blocks, indexes, - internal::{ComputedPerBlock, Price, PriceTimesRatioCents}, + internal::{PerBlock, Price, PriceTimesRatioCents}, }; #[derive(Traversable)] pub struct StdDevBand { #[traversable(flatten)] - pub value: ComputedPerBlock, - pub price: Price>, + pub value: PerBlock, + pub price: Price>, } #[derive(Traversable)] pub struct StdDevPerBlockExtended { days: usize, - pub sd: ComputedPerBlock, - pub zscore: ComputedPerBlock, + pub sd: PerBlock, + pub zscore: PerBlock, - pub _0sd: Price>, + pub _0sd: Price>, pub p0_5sd: StdDevBand, pub p1sd: StdDevBand, pub p1_5sd: StdDevBand, @@ -53,7 +53,7 @@ impl StdDevPerBlockExtended { macro_rules! import { ($suffix:expr) => { - ComputedPerBlock::forced_import( + PerBlock::forced_import( db, &format!("{name}_{}{p}", $suffix), version, diff --git a/crates/brk_computer/src/internal/per_tx/distribution.rs b/crates/brk_computer/src/internal/per_tx/distribution.rs index 6554110cc..7bfda01d0 100644 --- a/crates/brk_computer/src/internal/per_tx/distribution.rs +++ b/crates/brk_computer/src/internal/per_tx/distribution.rs @@ -1,4 +1,4 @@ -//! ComputedPerTxDistribution - stored per-tx EagerVec + computed distribution. +//! PerTxDistribution - stored per-tx EagerVec + computed distribution. //! //! Like LazyFromTxDistribution, but the per-tx source is eagerly computed //! and stored rather than lazily derived. @@ -16,7 +16,7 @@ use crate::{ }; #[derive(Traversable)] -pub struct ComputedPerTxDistribution +pub struct PerTxDistribution where T: ComputedVecValue + PartialOrd + JsonSchema, { @@ -25,7 +25,7 @@ where pub distribution: TxDerivedDistribution, } -impl ComputedPerTxDistribution +impl PerTxDistribution where T: NumericValue + JsonSchema, { diff --git a/crates/brk_computer/src/internal/per_tx/lazy_distribution_derived.rs b/crates/brk_computer/src/internal/per_tx/lazy_distribution_transformed.rs similarity index 90% rename from crates/brk_computer/src/internal/per_tx/lazy_distribution_derived.rs rename to crates/brk_computer/src/internal/per_tx/lazy_distribution_transformed.rs index 131e1c966..516310ef4 100644 --- a/crates/brk_computer/src/internal/per_tx/lazy_distribution_derived.rs +++ b/crates/brk_computer/src/internal/per_tx/lazy_distribution_transformed.rs @@ -8,7 +8,7 @@ use crate::internal::{ComputedVecValue, LazyTxDerivedDistribution, TxDerivedDist /// Like `LazyPerTxDistribution` but with a lazy-derived distribution /// (transformed from another type's distribution rather than eagerly computed). #[derive(Clone, Traversable)] -pub struct LazyPerTxDistributionDerived +pub struct LazyPerTxDistributionTransformed where T: ComputedVecValue + JsonSchema, S1: ComputedVecValue, @@ -20,7 +20,7 @@ where pub distribution: LazyTxDerivedDistribution, } -impl LazyPerTxDistributionDerived +impl LazyPerTxDistributionTransformed where T: ComputedVecValue + JsonSchema + 'static, S1: ComputedVecValue + JsonSchema, diff --git a/crates/brk_computer/src/internal/per_tx/mod.rs b/crates/brk_computer/src/internal/per_tx/mod.rs index 59156d9c6..31eac0154 100644 --- a/crates/brk_computer/src/internal/per_tx/mod.rs +++ b/crates/brk_computer/src/internal/per_tx/mod.rs @@ -2,10 +2,10 @@ mod derived; mod distribution; mod lazy_derived; mod lazy_distribution; -mod lazy_distribution_derived; +mod lazy_distribution_transformed; pub use derived::*; pub use distribution::*; pub use lazy_derived::*; pub use lazy_distribution::*; -pub use lazy_distribution_derived::*; +pub use lazy_distribution_transformed::*; diff --git a/crates/brk_computer/src/internal/transform/arithmetic.rs b/crates/brk_computer/src/internal/transform/arithmetic.rs index 6697d24ba..fdada424e 100644 --- a/crates/brk_computer/src/internal/transform/arithmetic.rs +++ b/crates/brk_computer/src/internal/transform/arithmetic.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use brk_types::{Bitcoin, Cents, Dollars, Sats, StoredF32, StoredI8, StoredU16, StoredU32, StoredU64, VSize, Weight}; +use brk_types::{BasisPoints16, Bitcoin, Cents, Dollars, Sats, StoredF32, StoredF64, StoredI8, StoredU16, StoredU32, StoredU64, VSize, Weight}; use vecdb::{BinaryTransform, UnaryTransform, VecValue}; pub struct Identity(PhantomData); @@ -88,6 +88,52 @@ impl UnaryTransform for ReturnI8 { } } +pub struct ThsToPhsF32; + +impl UnaryTransform for ThsToPhsF32 { + #[inline(always)] + fn apply(ths: StoredF32) -> StoredF32 { + (*ths * 1000.0).into() + } +} + +pub struct BlocksToDaysF32; + +impl UnaryTransform for BlocksToDaysF32 { + #[inline(always)] + fn apply(blocks: StoredU32) -> StoredF32 { + (*blocks as f32 / crate::blocks::TARGET_BLOCKS_PER_DAY_F32).into() + } +} + +pub struct OneMinusF64; + +impl UnaryTransform for OneMinusF64 { + #[inline(always)] + fn apply(v: StoredF64) -> StoredF64 { + StoredF64::from(1.0 - *v) + } +} + +pub struct DifficultyToHashF64; + +impl UnaryTransform for DifficultyToHashF64 { + #[inline(always)] + fn apply(difficulty: StoredF64) -> StoredF64 { + const MULTIPLIER: f64 = 4_294_967_296.0 / 600.0; // 2^32 / 600 + StoredF64::from(*difficulty * MULTIPLIER) + } +} + +pub struct OneMinusBp16; + +impl UnaryTransform for OneMinusBp16 { + #[inline(always)] + fn apply(v: BasisPoints16) -> BasisPoints16 { + BasisPoints16::ONE - v + } +} + pub struct VBytesToWeight; impl UnaryTransform for VBytesToWeight { diff --git a/crates/brk_computer/src/internal/transform/mod.rs b/crates/brk_computer/src/internal/transform/mod.rs index 3077d6663..af6966f75 100644 --- a/crates/brk_computer/src/internal/transform/mod.rs +++ b/crates/brk_computer/src/internal/transform/mod.rs @@ -6,8 +6,9 @@ mod ratio; mod specialized; pub use arithmetic::{ - HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin, Identity, MaskSats, ReturnF32Tenths, - ReturnI8, ReturnU16, VBytesToWeight, VSizeToWeight, + BlocksToDaysF32, DifficultyToHashF64, HalveCents, HalveDollars, HalveSats, + HalveSatsToBitcoin, Identity, MaskSats, OneMinusBp16, OneMinusF64, ReturnF32Tenths, ReturnI8, + ReturnU16, ThsToPhsF32, VBytesToWeight, VSizeToWeight, }; pub use bps::{ Bp16ToFloat, Bp16ToPercent, Bp32ToFloat, Bp32ToPercent, Bps16ToFloat, Bps16ToPercent, Bps32ToFloat, diff --git a/crates/brk_computer/src/market/ath/import.rs b/crates/brk_computer/src/market/ath/import.rs index b9f80e1bd..be7d1c710 100644 --- a/crates/brk_computer/src/market/ath/import.rs +++ b/crates/brk_computer/src/market/ath/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{ComputedPerBlock, DaysToYears, DerivedResolutions, PercentPerBlock, Price}, + internal::{PerBlock, DaysToYears, DerivedResolutions, PercentPerBlock, Price}, }; const VERSION: Version = Version::ONE; @@ -21,7 +21,7 @@ impl Vecs { let high = Price::forced_import(db, "price_ath", v, indexes)?; let max_days_between = - ComputedPerBlock::forced_import(db, "max_days_between_price_ath", v, indexes)?; + PerBlock::forced_import(db, "max_days_between_price_ath", v, indexes)?; let max_years_between = DerivedResolutions::from_computed::( "max_years_between_price_ath", @@ -30,7 +30,7 @@ impl Vecs { ); let days_since = - ComputedPerBlock::forced_import(db, "days_since_price_ath", v, indexes)?; + PerBlock::forced_import(db, "days_since_price_ath", v, indexes)?; let years_since = DerivedResolutions::from_computed::( "years_since_price_ath", diff --git a/crates/brk_computer/src/market/ath/vecs.rs b/crates/brk_computer/src/market/ath/vecs.rs index 9e6ab93c0..dac621d51 100644 --- a/crates/brk_computer/src/market/ath/vecs.rs +++ b/crates/brk_computer/src/market/ath/vecs.rs @@ -2,14 +2,14 @@ use brk_traversable::Traversable; use brk_types::{BasisPointsSigned16, Cents, StoredF32}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, DerivedResolutions, PercentPerBlock, Price}; +use crate::internal::{PerBlock, DerivedResolutions, PercentPerBlock, Price}; #[derive(Traversable)] pub struct Vecs { - pub high: Price>, + pub high: Price>, pub drawdown: PercentPerBlock, - pub days_since: ComputedPerBlock, + pub days_since: PerBlock, pub years_since: DerivedResolutions, - pub max_days_between: ComputedPerBlock, + pub max_days_between: PerBlock, pub max_years_between: DerivedResolutions, } diff --git a/crates/brk_computer/src/market/dca/vecs.rs b/crates/brk_computer/src/market/dca/vecs.rs index 38a6ab8ae..9320f41ef 100644 --- a/crates/brk_computer/src/market/dca/vecs.rs +++ b/crates/brk_computer/src/market/dca/vecs.rs @@ -3,12 +3,12 @@ use brk_types::{BasisPointsSigned32, Cents, Height, Sats}; use vecdb::{EagerVec, PcoVec, Rw, StorageMode}; use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod}; -use crate::internal::{AmountPerBlock, ComputedPerBlock, PercentPerBlock, Price}; +use crate::internal::{AmountPerBlock, PerBlock, PercentPerBlock, Price}; #[derive(Traversable)] pub struct PeriodVecs { pub stack: ByDcaPeriod>, - pub cost_basis: ByDcaPeriod>>, + pub cost_basis: ByDcaPeriod>>, pub r#return: ByDcaPeriod>, pub cagr: ByDcaCagr>, pub lump_sum_stack: ByDcaPeriod>, @@ -18,7 +18,7 @@ pub struct PeriodVecs { #[derive(Traversable)] pub struct ClassVecs { pub stack: ByDcaClass>, - pub cost_basis: ByDcaClass>>, + pub cost_basis: ByDcaClass>>, pub r#return: ByDcaClass>, } diff --git a/crates/brk_computer/src/market/import.rs b/crates/brk_computer/src/market/import.rs index 6e55ca779..2a996bcc4 100644 --- a/crates/brk_computer/src/market/import.rs +++ b/crates/brk_computer/src/market/import.rs @@ -5,7 +5,7 @@ use brk_types::Version; use crate::{ indexes, - internal::{finalize_db, open_db}, + internal::db_utils::{finalize_db, open_db}, }; use super::{ diff --git a/crates/brk_computer/src/market/lookback/vecs.rs b/crates/brk_computer/src/market/lookback/vecs.rs index 3498cc921..51edded19 100644 --- a/crates/brk_computer/src/market/lookback/vecs.rs +++ b/crates/brk_computer/src/market/lookback/vecs.rs @@ -3,9 +3,9 @@ use brk_types::Cents; use vecdb::{Rw, StorageMode}; use super::ByLookbackPeriod; -use crate::internal::{ComputedPerBlock, Price}; +use crate::internal::{PerBlock, Price}; #[derive(Traversable)] pub struct Vecs { #[traversable(flatten)] - pub price_lookback: ByLookbackPeriod>>, + pub price_lookback: ByLookbackPeriod>>, } diff --git a/crates/brk_computer/src/market/range/import.rs b/crates/brk_computer/src/market/range/import.rs index 0827c1322..9967719c8 100644 --- a/crates/brk_computer/src/market/range/import.rs +++ b/crates/brk_computer/src/market/range/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::{vecs::PriceMinMaxVecs, Vecs}; use crate::{ indexes, - internal::{ComputedPerBlock, PercentPerBlock, Price}, + internal::{PerBlock, PercentPerBlock, Price}, }; impl Vecs { @@ -29,13 +29,13 @@ impl Vecs { _1m: Price::forced_import(db, "price_max_1m", version + v1, indexes)?, _1y: Price::forced_import(db, "price_max_1y", version + v1, indexes)?, }, - true_range: ComputedPerBlock::forced_import( + true_range: PerBlock::forced_import( db, "price_true_range", version + v1, indexes, )?, - true_range_sum_2w: ComputedPerBlock::forced_import( + true_range_sum_2w: PerBlock::forced_import( db, "price_true_range_sum_2w", version + v1, diff --git a/crates/brk_computer/src/market/range/vecs.rs b/crates/brk_computer/src/market/range/vecs.rs index 08abd71f9..122148953 100644 --- a/crates/brk_computer/src/market/range/vecs.rs +++ b/crates/brk_computer/src/market/range/vecs.rs @@ -2,21 +2,21 @@ use brk_traversable::Traversable; use brk_types::{BasisPoints16, Cents, StoredF32}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, PercentPerBlock, Price}; +use crate::internal::{PerBlock, PercentPerBlock, Price}; #[derive(Traversable)] pub struct PriceMinMaxVecs { - pub _1w: Price>, - pub _2w: Price>, - pub _1m: Price>, - pub _1y: Price>, + pub _1w: Price>, + pub _2w: Price>, + pub _1m: Price>, + pub _1y: Price>, } #[derive(Traversable)] pub struct Vecs { pub min: PriceMinMaxVecs, pub max: PriceMinMaxVecs, - pub true_range: ComputedPerBlock, - pub true_range_sum_2w: ComputedPerBlock, + pub true_range: PerBlock, + pub true_range_sum_2w: PerBlock, pub choppiness_index_2w: PercentPerBlock, } diff --git a/crates/brk_computer/src/market/technical/import.rs b/crates/brk_computer/src/market/technical/import.rs index 51470e8d6..667e0840a 100644 --- a/crates/brk_computer/src/market/technical/import.rs +++ b/crates/brk_computer/src/market/technical/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::{MacdChain, RsiChain, Vecs}; use crate::{ indexes, - internal::{ComputedPerBlock, PercentPerBlock, RatioPerBlock, Windows}, + internal::{PerBlock, PercentPerBlock, RatioPerBlock, Windows}, }; const VERSION: Version = Version::new(2); @@ -19,7 +19,7 @@ impl RsiChain { ) -> Result { macro_rules! import { ($name:expr) => { - ComputedPerBlock::forced_import( + PerBlock::forced_import( db, &format!("rsi_{}_{}", $name, tf), version, @@ -67,11 +67,11 @@ impl MacdChain { indexes: &indexes::Vecs, ) -> Result { let line = - ComputedPerBlock::forced_import(db, &format!("macd_line_{tf}"), version, indexes)?; + PerBlock::forced_import(db, &format!("macd_line_{tf}"), version, indexes)?; let signal = - ComputedPerBlock::forced_import(db, &format!("macd_signal_{tf}"), version, indexes)?; + PerBlock::forced_import(db, &format!("macd_signal_{tf}"), version, indexes)?; - let histogram = ComputedPerBlock::forced_import( + let histogram = PerBlock::forced_import( db, &format!("macd_histogram_{tf}"), version, @@ -79,13 +79,13 @@ impl MacdChain { )?; Ok(Self { - ema_fast: ComputedPerBlock::forced_import( + ema_fast: PerBlock::forced_import( db, &format!("macd_ema_fast_{tf}"), version, indexes, )?, - ema_slow: ComputedPerBlock::forced_import( + ema_slow: PerBlock::forced_import( db, &format!("macd_ema_slow_{tf}"), version, diff --git a/crates/brk_computer/src/market/technical/vecs.rs b/crates/brk_computer/src/market/technical/vecs.rs index 3a0ec9516..0979476b3 100644 --- a/crates/brk_computer/src/market/technical/vecs.rs +++ b/crates/brk_computer/src/market/technical/vecs.rs @@ -2,14 +2,14 @@ use brk_traversable::Traversable; use brk_types::{BasisPoints16, BasisPoints32, StoredF32}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, PercentPerBlock, RatioPerBlock, Windows}; +use crate::internal::{PerBlock, PercentPerBlock, RatioPerBlock, Windows}; #[derive(Traversable)] pub struct RsiChain { - pub gains: ComputedPerBlock, - pub losses: ComputedPerBlock, - pub average_gain: ComputedPerBlock, - pub average_loss: ComputedPerBlock, + pub gains: PerBlock, + pub losses: PerBlock, + pub average_gain: PerBlock, + pub average_loss: PerBlock, pub rsi: PercentPerBlock, pub rsi_min: PercentPerBlock, pub rsi_max: PercentPerBlock, @@ -20,11 +20,11 @@ pub struct RsiChain { #[derive(Traversable)] pub struct MacdChain { - pub ema_fast: ComputedPerBlock, - pub ema_slow: ComputedPerBlock, - pub line: ComputedPerBlock, - pub signal: ComputedPerBlock, - pub histogram: ComputedPerBlock, + pub ema_fast: PerBlock, + pub ema_slow: PerBlock, + pub line: PerBlock, + pub signal: PerBlock, + pub histogram: PerBlock, } #[derive(Traversable)] diff --git a/crates/brk_computer/src/mining/hashrate/compute.rs b/crates/brk_computer/src/mining/hashrate/compute.rs index 5a7efd3b2..ac79425a5 100644 --- a/crates/brk_computer/src/mining/hashrate/compute.rs +++ b/crates/brk_computer/src/mining/hashrate/compute.rs @@ -20,7 +20,7 @@ impl Vecs { starting_indexes: &Indexes, exit: &Exit, ) -> Result<()> { - self.rate.raw.height.compute_transform2( + self.rate.base.height.compute_transform2( starting_indexes.height, &count_vecs.total.sum._24h.height, &difficulty_vecs.as_hash.height, @@ -36,7 +36,7 @@ impl Vecs { exit, )?; - let hash_rate = &self.rate.raw.height; + let hash_rate = &self.rate.base.height; for (sma, window) in [ (&mut self.rate.sma._1w.height, &lookback._1w), (&mut self.rate.sma._1m.height, &lookback._1m), @@ -48,13 +48,13 @@ impl Vecs { self.rate.ath.height.compute_all_time_high( starting_indexes.height, - &self.rate.raw.height, + &self.rate.base.height, exit, )?; self.rate.drawdown.compute_drawdown( starting_indexes.height, - &self.rate.raw.height, + &self.rate.base.height, &self.rate.ath.height, exit, )?; @@ -62,7 +62,7 @@ impl Vecs { self.price.ths.height.compute_transform2( starting_indexes.height, coinbase_usd_24h_sum, - &self.rate.raw.height, + &self.rate.base.height, |(i, coinbase_sum, hashrate, ..)| { let hashrate_ths = *hashrate / ONE_TERA_HASH; let price = if hashrate_ths == 0.0 { @@ -75,17 +75,10 @@ impl Vecs { exit, )?; - self.price.phs.height.compute_transform( - starting_indexes.height, - &self.price.ths.height, - |(i, price, ..)| (i, (*price * 1000.0).into()), - exit, - )?; - self.value.ths.height.compute_transform2( starting_indexes.height, coinbase_sats_24h_sum, - &self.rate.raw.height, + &self.rate.base.height, |(i, coinbase_sum, hashrate, ..)| { let hashrate_ths = *hashrate / ONE_TERA_HASH; let value = if hashrate_ths == 0.0 { @@ -98,30 +91,9 @@ impl Vecs { exit, )?; - self.value.phs.height.compute_transform( - starting_indexes.height, - &self.value.ths.height, - |(i, value, ..)| (i, (*value * 1000.0).into()), - exit, - )?; - for (min_vec, src_vec) in [ - ( - &mut self.price.ths_min.height, - &self.price.ths.height, - ), - ( - &mut self.price.phs_min.height, - &self.price.phs.height, - ), - ( - &mut self.value.ths_min.height, - &self.value.ths.height, - ), - ( - &mut self.value.phs_min.height, - &self.value.phs.height, - ), + (&mut self.price.ths_min.height, &self.price.ths.height), + (&mut self.value.ths_min.height, &self.value.ths.height), ] { min_vec.compute_all_time_low_(starting_indexes.height, src_vec, exit, true)?; } diff --git a/crates/brk_computer/src/mining/hashrate/import.rs b/crates/brk_computer/src/mining/hashrate/import.rs index 1511e0102..3e2f64d4f 100644 --- a/crates/brk_computer/src/mining/hashrate/import.rs +++ b/crates/brk_computer/src/mining/hashrate/import.rs @@ -1,6 +1,6 @@ use brk_error::Result; use brk_types::Version; -use vecdb::Database; +use vecdb::{Database, ReadableCloneableVec}; use super::{ vecs::{HashPriceValueVecs, HashRateSmaVecs, RateVecs}, @@ -8,7 +8,7 @@ use super::{ }; use crate::{ indexes, - internal::{ComputedPerBlock, PercentPerBlock}, + internal::{LazyPerBlock, PerBlock, PercentPerBlock, ThsToPhsF32}, }; impl Vecs { @@ -20,111 +20,49 @@ impl Vecs { let v4 = Version::new(4); let v5 = Version::new(5); + let price_ths = PerBlock::forced_import(db, "hash_price_ths", version + v4, indexes)?; + let price_ths_min = PerBlock::forced_import(db, "hash_price_ths_min", version + v4, indexes)?; + let price_phs = LazyPerBlock::from_computed::( + "hash_price_phs", version + v4, price_ths.height.read_only_boxed_clone(), &price_ths, + ); + let price_phs_min = LazyPerBlock::from_computed::( + "hash_price_phs_min", version + v4, price_ths_min.height.read_only_boxed_clone(), &price_ths_min, + ); + + let value_ths = PerBlock::forced_import(db, "hash_value_ths", version + v4, indexes)?; + let value_ths_min = PerBlock::forced_import(db, "hash_value_ths_min", version + v4, indexes)?; + let value_phs = LazyPerBlock::from_computed::( + "hash_value_phs", version + v4, value_ths.height.read_only_boxed_clone(), &value_ths, + ); + let value_phs_min = LazyPerBlock::from_computed::( + "hash_value_phs_min", version + v4, value_ths_min.height.read_only_boxed_clone(), &value_ths_min, + ); + Ok(Self { rate: RateVecs { - raw: ComputedPerBlock::forced_import(db, "hash_rate", version + v5, indexes)?, + base: PerBlock::forced_import(db, "hash_rate", version + v5, indexes)?, sma: HashRateSmaVecs { - _1w: ComputedPerBlock::forced_import( - db, - "hash_rate_sma_1w", - version, - indexes, - )?, - _1m: ComputedPerBlock::forced_import( - db, - "hash_rate_sma_1m", - version, - indexes, - )?, - _2m: ComputedPerBlock::forced_import( - db, - "hash_rate_sma_2m", - version, - indexes, - )?, - _1y: ComputedPerBlock::forced_import( - db, - "hash_rate_sma_1y", - version, - indexes, - )?, + _1w: PerBlock::forced_import(db, "hash_rate_sma_1w", version, indexes)?, + _1m: PerBlock::forced_import(db, "hash_rate_sma_1m", version, indexes)?, + _2m: PerBlock::forced_import(db, "hash_rate_sma_2m", version, indexes)?, + _1y: PerBlock::forced_import(db, "hash_rate_sma_1y", version, indexes)?, }, - ath: ComputedPerBlock::forced_import( - db, - "hash_rate_ath", - version, - indexes, - )?, - drawdown: PercentPerBlock::forced_import( - db, - "hash_rate_drawdown", - version, - indexes, - )?, + ath: PerBlock::forced_import(db, "hash_rate_ath", version, indexes)?, + drawdown: PercentPerBlock::forced_import(db, "hash_rate_drawdown", version, indexes)?, }, price: HashPriceValueVecs { - ths: ComputedPerBlock::forced_import( - db, - "hash_price_ths", - version + v4, - indexes, - )?, - ths_min: ComputedPerBlock::forced_import( - db, - "hash_price_ths_min", - version + v4, - indexes, - )?, - phs: ComputedPerBlock::forced_import( - db, - "hash_price_phs", - version + v4, - indexes, - )?, - phs_min: ComputedPerBlock::forced_import( - db, - "hash_price_phs_min", - version + v4, - indexes, - )?, - rebound: PercentPerBlock::forced_import( - db, - "hash_price_rebound", - version + v4, - indexes, - )?, + ths: price_ths, + ths_min: price_ths_min, + phs: price_phs, + phs_min: price_phs_min, + rebound: PercentPerBlock::forced_import(db, "hash_price_rebound", version + v4, indexes)?, }, value: HashPriceValueVecs { - ths: ComputedPerBlock::forced_import( - db, - "hash_value_ths", - version + v4, - indexes, - )?, - ths_min: ComputedPerBlock::forced_import( - db, - "hash_value_ths_min", - version + v4, - indexes, - )?, - phs: ComputedPerBlock::forced_import( - db, - "hash_value_phs", - version + v4, - indexes, - )?, - phs_min: ComputedPerBlock::forced_import( - db, - "hash_value_phs_min", - version + v4, - indexes, - )?, - rebound: PercentPerBlock::forced_import( - db, - "hash_value_rebound", - version + v4, - indexes, - )?, + ths: value_ths, + ths_min: value_ths_min, + phs: value_phs, + phs_min: value_phs_min, + rebound: PercentPerBlock::forced_import(db, "hash_value_rebound", version + v4, indexes)?, }, }) } diff --git a/crates/brk_computer/src/mining/hashrate/vecs.rs b/crates/brk_computer/src/mining/hashrate/vecs.rs index 29c7b7371..8dbb9f59e 100644 --- a/crates/brk_computer/src/mining/hashrate/vecs.rs +++ b/crates/brk_computer/src/mining/hashrate/vecs.rs @@ -2,30 +2,30 @@ use brk_traversable::Traversable; use brk_types::{BasisPointsSigned16, BasisPointsSigned32, StoredF32, StoredF64}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, PercentPerBlock}; +use crate::internal::{LazyPerBlock, PerBlock, PercentPerBlock}; #[derive(Traversable)] pub struct HashRateSmaVecs { - pub _1w: ComputedPerBlock, - pub _1m: ComputedPerBlock, - pub _2m: ComputedPerBlock, - pub _1y: ComputedPerBlock, + pub _1w: PerBlock, + pub _1m: PerBlock, + pub _2m: PerBlock, + pub _1y: PerBlock, } #[derive(Traversable)] pub struct HashPriceValueVecs { - pub ths: ComputedPerBlock, - pub ths_min: ComputedPerBlock, - pub phs: ComputedPerBlock, - pub phs_min: ComputedPerBlock, + pub ths: PerBlock, + pub ths_min: PerBlock, + pub phs: LazyPerBlock, + pub phs_min: LazyPerBlock, pub rebound: PercentPerBlock, } #[derive(Traversable)] pub struct RateVecs { - pub raw: ComputedPerBlock, + pub base: PerBlock, pub sma: HashRateSmaVecs, - pub ath: ComputedPerBlock, + pub ath: PerBlock, pub drawdown: PercentPerBlock, } diff --git a/crates/brk_computer/src/mining/import.rs b/crates/brk_computer/src/mining/import.rs index 281cf814e..8d6492d7d 100644 --- a/crates/brk_computer/src/mining/import.rs +++ b/crates/brk_computer/src/mining/import.rs @@ -5,7 +5,7 @@ use brk_types::Version; use crate::{ indexes, - internal::{finalize_db, open_db, CachedWindowStarts}, + internal::{CachedWindowStarts, db_utils::{finalize_db, open_db}}, }; use super::{HashrateVecs, RewardsVecs, Vecs}; diff --git a/crates/brk_computer/src/mining/rewards/compute.rs b/crates/brk_computer/src/mining/rewards/compute.rs index d213dc4a8..091caee1f 100644 --- a/crates/brk_computer/src/mining/rewards/compute.rs +++ b/crates/brk_computer/src/mining/rewards/compute.rs @@ -1,6 +1,6 @@ use brk_error::Result; use brk_indexer::Indexer; -use brk_types::{BasisPoints16, CheckedSub, Dollars, Halving, Indexes, Sats}; +use brk_types::{CheckedSub, Dollars, Halving, Indexes, Sats}; use vecdb::{Exit, ReadableVec, VecIndex}; use super::Vecs; @@ -77,7 +77,7 @@ impl Vecs { self.subsidy.base.sats.height.compute_transform2( starting_indexes.height, - &self.coinbase.raw.sats.height, + &self.coinbase.base.sats.height, &self.fees.base.sats.height, |(height, coinbase, fees, ..)| { ( @@ -137,21 +137,6 @@ impl Vecs { exit, )?; - // Rolling subsidy dominance = 1 - fee_dominance - for (sub_dom, fee_dom) in self - .subsidy_dominance_rolling - .as_mut_array() - .into_iter() - .zip(self.fee_dominance_rolling.as_array()) - { - sub_dom.bps.height.compute_transform( - starting_indexes.height, - &fee_dom.bps.height, - |(height, fee, _)| (height, BasisPoints16::ONE - fee), - exit, - )?; - } - self.subsidy_sma_1y.cents.height.compute_rolling_average( starting_indexes.height, &lookback._1y, diff --git a/crates/brk_computer/src/mining/rewards/import.rs b/crates/brk_computer/src/mining/rewards/import.rs index a1cf68655..f5fecdb22 100644 --- a/crates/brk_computer/src/mining/rewards/import.rs +++ b/crates/brk_computer/src/mining/rewards/import.rs @@ -7,8 +7,8 @@ use crate::{ indexes, internal::{ AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums, AmountPerBlockFull, - CachedWindowStarts, FiatPerBlock, PercentPerBlock, PercentRollingWindows, - RatioRollingWindows, + CachedWindowStarts, FiatPerBlock, LazyPercentRollingWindows, OneMinusBp16, + PercentPerBlock, PercentRollingWindows, RatioRollingWindows, }, }; @@ -19,6 +19,19 @@ impl Vecs { indexes: &indexes::Vecs, cached_starts: &CachedWindowStarts, ) -> Result { + let fee_dominance_rolling = PercentRollingWindows::forced_import( + db, + "fee_dominance", + version, + indexes, + )?; + + let subsidy_dominance_rolling = LazyPercentRollingWindows::from_rolling::( + "subsidy_dominance", + version, + &fee_dominance_rolling, + ); + Ok(Self { coinbase: AmountPerBlockCumulativeWithSums::forced_import( db, "coinbase", version, indexes, cached_starts, @@ -33,24 +46,14 @@ impl Vecs { cached_starts, )?, fee_dominance: PercentPerBlock::forced_import(db, "fee_dominance", version, indexes)?, - fee_dominance_rolling: PercentRollingWindows::forced_import( - db, - "fee_dominance", - version, - indexes, - )?, + fee_dominance_rolling, subsidy_dominance: PercentPerBlock::forced_import( db, "subsidy_dominance", version, indexes, )?, - subsidy_dominance_rolling: PercentRollingWindows::forced_import( - db, - "subsidy_dominance", - version, - indexes, - )?, + subsidy_dominance_rolling, subsidy_sma_1y: FiatPerBlock::forced_import(db, "subsidy_sma_1y", version, indexes)?, fee_ratio_multiple: RatioRollingWindows::forced_import( db, diff --git a/crates/brk_computer/src/mining/rewards/vecs.rs b/crates/brk_computer/src/mining/rewards/vecs.rs index e06f48432..cb16734bd 100644 --- a/crates/brk_computer/src/mining/rewards/vecs.rs +++ b/crates/brk_computer/src/mining/rewards/vecs.rs @@ -4,7 +4,8 @@ use vecdb::{Rw, StorageMode}; use crate::internal::{ AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums, AmountPerBlockFull, - FiatPerBlock, PercentPerBlock, PercentRollingWindows, RatioRollingWindows, + FiatPerBlock, LazyPercentRollingWindows, PercentPerBlock, PercentRollingWindows, + RatioRollingWindows, }; #[derive(Traversable)] @@ -20,7 +21,7 @@ pub struct Vecs { #[traversable(wrap = "subsidy", rename = "dominance")] pub subsidy_dominance: PercentPerBlock, #[traversable(wrap = "subsidy", rename = "dominance")] - pub subsidy_dominance_rolling: PercentRollingWindows, + pub subsidy_dominance_rolling: LazyPercentRollingWindows, #[traversable(wrap = "subsidy", rename = "sma_1y")] pub subsidy_sma_1y: FiatPerBlock, #[traversable(wrap = "fees", rename = "ratio_multiple")] diff --git a/crates/brk_computer/src/outputs/count/import.rs b/crates/brk_computer/src/outputs/count/import.rs index 78e258acc..6c4cce900 100644 --- a/crates/brk_computer/src/outputs/count/import.rs +++ b/crates/brk_computer/src/outputs/count/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{CachedWindowStarts, ComputedPerBlock, ComputedPerBlockAggregated}, + internal::{CachedWindowStarts, PerBlock, PerBlockAggregated}, }; impl Vecs { @@ -16,14 +16,14 @@ impl Vecs { cached_starts: &CachedWindowStarts, ) -> Result { Ok(Self { - total: ComputedPerBlockAggregated::forced_import( + total: PerBlockAggregated::forced_import( db, "output_count", version, indexes, cached_starts, )?, - unspent: ComputedPerBlock::forced_import( + unspent: PerBlock::forced_import( db, "exact_utxo_count", version, diff --git a/crates/brk_computer/src/outputs/count/vecs.rs b/crates/brk_computer/src/outputs/count/vecs.rs index 9e89486dc..163876746 100644 --- a/crates/brk_computer/src/outputs/count/vecs.rs +++ b/crates/brk_computer/src/outputs/count/vecs.rs @@ -2,10 +2,10 @@ use brk_traversable::Traversable; use brk_types::StoredU64; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedPerBlock, ComputedPerBlockAggregated}; +use crate::internal::{PerBlock, PerBlockAggregated}; #[derive(Traversable)] pub struct Vecs { - pub total: ComputedPerBlockAggregated, - pub unspent: ComputedPerBlock, + pub total: PerBlockAggregated, + pub unspent: PerBlock, } diff --git a/crates/brk_computer/src/outputs/import.rs b/crates/brk_computer/src/outputs/import.rs index d733f7fd1..86331b3f3 100644 --- a/crates/brk_computer/src/outputs/import.rs +++ b/crates/brk_computer/src/outputs/import.rs @@ -5,7 +5,7 @@ use brk_types::Version; use crate::{ indexes, - internal::{finalize_db, open_db, CachedWindowStarts}, + internal::{CachedWindowStarts, db_utils::{finalize_db, open_db}}, }; use super::{CountVecs, SpentVecs, Vecs}; diff --git a/crates/brk_computer/src/pools/major.rs b/crates/brk_computer/src/pools/major.rs index 8ff8e3790..d4e6a586d 100644 --- a/crates/brk_computer/src/pools/major.rs +++ b/crates/brk_computer/src/pools/major.rs @@ -93,8 +93,8 @@ impl Vecs { |vec| { Ok(vec.compute_transform2( starting_indexes.height, - &self.base.blocks_mined.raw.height, - &mining.rewards.coinbase.raw.sats.height, + &self.base.blocks_mined.base.height, + &mining.rewards.coinbase.base.sats.height, |(h, mask, val, ..)| (h, MaskSats::apply(mask, val)), exit, )?) diff --git a/crates/brk_computer/src/pools/minor.rs b/crates/brk_computer/src/pools/minor.rs index 5ef41f36e..30544cd56 100644 --- a/crates/brk_computer/src/pools/minor.rs +++ b/crates/brk_computer/src/pools/minor.rs @@ -8,7 +8,7 @@ use vecdb::{ use crate::{ blocks, indexes, internal::{ - CachedWindowStarts, ComputedPerBlockCumulativeWithSums, PercentPerBlock, RatioU64Bp16, + CachedWindowStarts, PerBlockCumulativeWithSums, PercentPerBlock, RatioU64Bp16, }, }; @@ -17,7 +17,7 @@ pub struct Vecs { #[traversable(skip)] slug: PoolSlug, - pub blocks_mined: ComputedPerBlockCumulativeWithSums, + pub blocks_mined: PerBlockCumulativeWithSums, pub dominance: PercentPerBlock, } @@ -31,7 +31,7 @@ impl Vecs { ) -> Result { let suffix = |s: &str| format!("{}_{s}", slug); - let blocks_mined = ComputedPerBlockCumulativeWithSums::forced_import( + let blocks_mined = PerBlockCumulativeWithSums::forced_import( db, &suffix("blocks_mined"), version + Version::ONE, diff --git a/crates/brk_computer/src/pools/mod.rs b/crates/brk_computer/src/pools/mod.rs index 3ed11c0cc..bf36eb117 100644 --- a/crates/brk_computer/src/pools/mod.rs +++ b/crates/brk_computer/src/pools/mod.rs @@ -18,7 +18,7 @@ pub mod minor; use crate::{ blocks, indexes, - internal::{finalize_db, open_db, CachedWindowStarts}, + internal::{CachedWindowStarts, db_utils::{finalize_db, open_db}}, mining, prices, }; diff --git a/crates/brk_computer/src/positions.rs b/crates/brk_computer/src/positions.rs index 415ecae9c..16a40e7c3 100644 --- a/crates/brk_computer/src/positions.rs +++ b/crates/brk_computer/src/positions.rs @@ -11,7 +11,7 @@ use vecdb::{ VecIndex, WritableVec, }; -use crate::internal::{finalize_db, open_db}; +use crate::internal::db_utils::{finalize_db, open_db}; pub const DB_NAME: &str = "positions"; diff --git a/crates/brk_computer/src/prices/by_unit.rs b/crates/brk_computer/src/prices/by_unit.rs index 8a3411283..4ba9eba60 100644 --- a/crates/brk_computer/src/prices/by_unit.rs +++ b/crates/brk_computer/src/prices/by_unit.rs @@ -3,7 +3,7 @@ use brk_types::{Cents, Dollars, OHLCCents, OHLCDollars, OHLCSats, Sats}; use vecdb::{Rw, StorageMode}; use crate::internal::{ - ComputedPerBlock, Resolutions, EagerIndexes, LazyEagerIndexes, LazyPerBlock, + PerBlock, Resolutions, EagerIndexes, LazyEagerIndexes, LazyPerBlock, }; use super::ohlcs::{LazyOhlcVecs, OhlcVecs}; @@ -39,7 +39,7 @@ pub struct OhlcByUnit { #[derive(Traversable)] pub struct PriceByUnit { - pub cents: ComputedPerBlock, + pub cents: PerBlock, pub usd: LazyPerBlock, pub sats: LazyPerBlock, } diff --git a/crates/brk_computer/src/prices/mod.rs b/crates/brk_computer/src/prices/mod.rs index 16ff66037..5eb09509a 100644 --- a/crates/brk_computer/src/prices/mod.rs +++ b/crates/brk_computer/src/prices/mod.rs @@ -11,9 +11,9 @@ use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode}; use crate::{ indexes, internal::{ - CentsUnsignedToDollars, CentsUnsignedToSats, ComputedPerBlock, Resolutions, + CentsUnsignedToDollars, CentsUnsignedToSats, PerBlock, Resolutions, EagerIndexes, LazyEagerIndexes, LazyPerBlock, OhlcCentsToDollars, OhlcCentsToSats, - finalize_db, open_db, + db_utils::{finalize_db, open_db}, }, }; @@ -51,7 +51,7 @@ impl Vecs { ) -> brk_error::Result { let version = version + Version::new(11); - let price_cents = ComputedPerBlock::forced_import(db, "price_cents", version, indexes)?; + let price_cents = PerBlock::forced_import(db, "price_cents", version, indexes)?; let open_cents = EagerIndexes::forced_import(db, "price_open_cents", version)?; let high_cents = EagerIndexes::forced_import(db, "price_high_cents", version)?; diff --git a/crates/brk_computer/src/scripts/adoption.rs b/crates/brk_computer/src/scripts/adoption.rs index 6b5b5c992..1d8fb3530 100644 --- a/crates/brk_computer/src/scripts/adoption.rs +++ b/crates/brk_computer/src/scripts/adoption.rs @@ -38,14 +38,14 @@ impl Vecs { ) -> Result<()> { self.taproot.compute_binary::<_, _, RatioU64Bp16>( starting_indexes.height, - &count.p2tr.raw.height, + &count.p2tr.base.height, &outputs_count.total.full.sum, exit, )?; self.segwit.compute_binary::<_, _, RatioU64Bp16>( starting_indexes.height, - &count.segwit.raw.height, + &count.segwit.base.height, &outputs_count.total.full.sum, exit, )?; diff --git a/crates/brk_computer/src/scripts/count/compute.rs b/crates/brk_computer/src/scripts/count/compute.rs index 1fe3c9906..511d3eccd 100644 --- a/crates/brk_computer/src/scripts/count/compute.rs +++ b/crates/brk_computer/src/scripts/count/compute.rs @@ -137,9 +137,9 @@ impl Vecs { .compute(starting_indexes.height, exit, |v| { Ok(v.compute_transform3( starting_indexes.height, - &self.p2wpkh.raw.height, - &self.p2wsh.raw.height, - &self.p2tr.raw.height, + &self.p2wpkh.base.height, + &self.p2wsh.base.height, + &self.p2tr.base.height, |(h, p2wpkh, p2wsh, p2tr, ..)| (h, StoredU64::from(*p2wpkh + *p2wsh + *p2tr)), exit, )?) diff --git a/crates/brk_computer/src/scripts/count/import.rs b/crates/brk_computer/src/scripts/count/import.rs index e31e80d81..85613a94c 100644 --- a/crates/brk_computer/src/scripts/count/import.rs +++ b/crates/brk_computer/src/scripts/count/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{CachedWindowStarts, ComputedPerBlockCumulativeWithSums}, + internal::{CachedWindowStarts, PerBlockCumulativeWithSums}, }; impl Vecs { @@ -16,25 +16,25 @@ impl Vecs { cached_starts: &CachedWindowStarts, ) -> Result { let p2a = - ComputedPerBlockCumulativeWithSums::forced_import(db, "p2a_count", version, indexes, cached_starts)?; + PerBlockCumulativeWithSums::forced_import(db, "p2a_count", version, indexes, cached_starts)?; let p2ms = - ComputedPerBlockCumulativeWithSums::forced_import(db, "p2ms_count", version, indexes, cached_starts)?; + PerBlockCumulativeWithSums::forced_import(db, "p2ms_count", version, indexes, cached_starts)?; let p2pk33 = - ComputedPerBlockCumulativeWithSums::forced_import(db, "p2pk33_count", version, indexes, cached_starts)?; + PerBlockCumulativeWithSums::forced_import(db, "p2pk33_count", version, indexes, cached_starts)?; let p2pk65 = - ComputedPerBlockCumulativeWithSums::forced_import(db, "p2pk65_count", version, indexes, cached_starts)?; + PerBlockCumulativeWithSums::forced_import(db, "p2pk65_count", version, indexes, cached_starts)?; let p2pkh = - ComputedPerBlockCumulativeWithSums::forced_import(db, "p2pkh_count", version, indexes, cached_starts)?; + PerBlockCumulativeWithSums::forced_import(db, "p2pkh_count", version, indexes, cached_starts)?; let p2sh = - ComputedPerBlockCumulativeWithSums::forced_import(db, "p2sh_count", version, indexes, cached_starts)?; + PerBlockCumulativeWithSums::forced_import(db, "p2sh_count", version, indexes, cached_starts)?; let p2tr = - ComputedPerBlockCumulativeWithSums::forced_import(db, "p2tr_count", version, indexes, cached_starts)?; + PerBlockCumulativeWithSums::forced_import(db, "p2tr_count", version, indexes, cached_starts)?; let p2wpkh = - ComputedPerBlockCumulativeWithSums::forced_import(db, "p2wpkh_count", version, indexes, cached_starts)?; + PerBlockCumulativeWithSums::forced_import(db, "p2wpkh_count", version, indexes, cached_starts)?; let p2wsh = - ComputedPerBlockCumulativeWithSums::forced_import(db, "p2wsh_count", version, indexes, cached_starts)?; + PerBlockCumulativeWithSums::forced_import(db, "p2wsh_count", version, indexes, cached_starts)?; let segwit = - ComputedPerBlockCumulativeWithSums::forced_import(db, "segwit_count", version, indexes, cached_starts)?; + PerBlockCumulativeWithSums::forced_import(db, "segwit_count", version, indexes, cached_starts)?; Ok(Self { p2a, @@ -46,21 +46,21 @@ impl Vecs { p2tr, p2wpkh, p2wsh, - opreturn: ComputedPerBlockCumulativeWithSums::forced_import( + opreturn: PerBlockCumulativeWithSums::forced_import( db, "opreturn_count", version, indexes, cached_starts, )?, - emptyoutput: ComputedPerBlockCumulativeWithSums::forced_import( + emptyoutput: PerBlockCumulativeWithSums::forced_import( db, "emptyoutput_count", version, indexes, cached_starts, )?, - unknownoutput: ComputedPerBlockCumulativeWithSums::forced_import( + unknownoutput: PerBlockCumulativeWithSums::forced_import( db, "unknownoutput_count", version, diff --git a/crates/brk_computer/src/scripts/count/vecs.rs b/crates/brk_computer/src/scripts/count/vecs.rs index e40498040..9c05b6361 100644 --- a/crates/brk_computer/src/scripts/count/vecs.rs +++ b/crates/brk_computer/src/scripts/count/vecs.rs @@ -2,22 +2,22 @@ use brk_traversable::Traversable; use brk_types::StoredU64; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedPerBlockCumulativeWithSums; +use crate::internal::PerBlockCumulativeWithSums; #[derive(Traversable)] pub struct Vecs { - pub p2a: ComputedPerBlockCumulativeWithSums, - pub p2ms: ComputedPerBlockCumulativeWithSums, - pub p2pk33: ComputedPerBlockCumulativeWithSums, - pub p2pk65: ComputedPerBlockCumulativeWithSums, - pub p2pkh: ComputedPerBlockCumulativeWithSums, - pub p2sh: ComputedPerBlockCumulativeWithSums, - pub p2tr: ComputedPerBlockCumulativeWithSums, - pub p2wpkh: ComputedPerBlockCumulativeWithSums, - pub p2wsh: ComputedPerBlockCumulativeWithSums, - pub opreturn: ComputedPerBlockCumulativeWithSums, - pub emptyoutput: ComputedPerBlockCumulativeWithSums, - pub unknownoutput: ComputedPerBlockCumulativeWithSums, + pub p2a: PerBlockCumulativeWithSums, + pub p2ms: PerBlockCumulativeWithSums, + pub p2pk33: PerBlockCumulativeWithSums, + pub p2pk65: PerBlockCumulativeWithSums, + pub p2pkh: PerBlockCumulativeWithSums, + pub p2sh: PerBlockCumulativeWithSums, + pub p2tr: PerBlockCumulativeWithSums, + pub p2wpkh: PerBlockCumulativeWithSums, + pub p2wsh: PerBlockCumulativeWithSums, + pub opreturn: PerBlockCumulativeWithSums, + pub emptyoutput: PerBlockCumulativeWithSums, + pub unknownoutput: PerBlockCumulativeWithSums, - pub segwit: ComputedPerBlockCumulativeWithSums, + pub segwit: PerBlockCumulativeWithSums, } diff --git a/crates/brk_computer/src/scripts/import.rs b/crates/brk_computer/src/scripts/import.rs index 2a5455b73..3d9e63d02 100644 --- a/crates/brk_computer/src/scripts/import.rs +++ b/crates/brk_computer/src/scripts/import.rs @@ -5,7 +5,7 @@ use brk_types::Version; use crate::{ indexes, - internal::{finalize_db, open_db}, + internal::db_utils::{finalize_db, open_db}, }; use super::{AdoptionVecs, CountVecs, ValueVecs, Vecs}; diff --git a/crates/brk_computer/src/supply/burned/compute.rs b/crates/brk_computer/src/supply/burned/compute.rs index f3d335662..591938237 100644 --- a/crates/brk_computer/src/supply/burned/compute.rs +++ b/crates/brk_computer/src/supply/burned/compute.rs @@ -54,8 +54,8 @@ impl Vecs { // 2. Compute unspendable supply = opreturn + unclaimed_rewards + genesis (at height 0) // Get reference to opreturn height vec for computing unspendable - let opreturn_height = &self.opreturn.raw.sats.height; - let unclaimed_height = &mining.rewards.unclaimed.raw.sats.height; + let opreturn_height = &self.opreturn.base.sats.height; + let unclaimed_height = &mining.rewards.unclaimed.base.sats.height; self.unspendable.compute( starting_indexes.height, diff --git a/crates/brk_computer/src/supply/import.rs b/crates/brk_computer/src/supply/import.rs index ae3fbade2..2e7644ace 100644 --- a/crates/brk_computer/src/supply/import.rs +++ b/crates/brk_computer/src/supply/import.rs @@ -7,7 +7,8 @@ use crate::{ cointime, distribution, indexes, internal::{ CachedWindowStarts, LazyAmountPerBlock, LazyFiatPerBlock, - LazyRollingDeltasFiatFromHeight, PercentPerBlock, RollingWindows, finalize_db, open_db, + LazyRollingDeltasFiatFromHeight, PercentPerBlock, RollingWindows, + db_utils::{finalize_db, open_db}, }, supply::burned, }; diff --git a/crates/brk_computer/src/supply/velocity/compute.rs b/crates/brk_computer/src/supply/velocity/compute.rs index 73aaeb0f8..47154534f 100644 --- a/crates/brk_computer/src/supply/velocity/compute.rs +++ b/crates/brk_computer/src/supply/velocity/compute.rs @@ -21,7 +21,7 @@ impl Vecs { self.btc.height.compute_rolling_ratio( starting_indexes.height, &blocks.lookback._1y, - &transactions.volume.sent_sum.raw.sats.height, + &transactions.volume.sent_sum.base.sats.height, &circulating_supply.sats.height, exit, )?; @@ -30,7 +30,7 @@ impl Vecs { self.usd.height.compute_rolling_ratio( starting_indexes.height, &blocks.lookback._1y, - &transactions.volume.sent_sum.raw.usd.height, + &transactions.volume.sent_sum.base.usd.height, &circulating_supply.usd.height, exit, )?; diff --git a/crates/brk_computer/src/supply/velocity/import.rs b/crates/brk_computer/src/supply/velocity/import.rs index 4d6bbd14d..af93a41bd 100644 --- a/crates/brk_computer/src/supply/velocity/import.rs +++ b/crates/brk_computer/src/supply/velocity/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::ComputedPerBlock}; +use crate::{indexes, internal::PerBlock}; impl Vecs { pub(crate) fn forced_import( @@ -12,8 +12,8 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - btc: ComputedPerBlock::forced_import(db, "velocity_btc", version, indexes)?, - usd: ComputedPerBlock::forced_import(db, "velocity_usd", version, indexes)?, + btc: PerBlock::forced_import(db, "velocity_btc", version, indexes)?, + usd: PerBlock::forced_import(db, "velocity_usd", version, indexes)?, }) } } diff --git a/crates/brk_computer/src/supply/velocity/vecs.rs b/crates/brk_computer/src/supply/velocity/vecs.rs index 70e59ef9d..0ca397ba3 100644 --- a/crates/brk_computer/src/supply/velocity/vecs.rs +++ b/crates/brk_computer/src/supply/velocity/vecs.rs @@ -2,10 +2,10 @@ use brk_traversable::Traversable; use brk_types::StoredF64; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedPerBlock; +use crate::internal::PerBlock; #[derive(Traversable)] pub struct Vecs { - pub btc: ComputedPerBlock, - pub usd: ComputedPerBlock, + pub btc: PerBlock, + pub usd: PerBlock, } diff --git a/crates/brk_computer/src/transactions/count/import.rs b/crates/brk_computer/src/transactions/count/import.rs index c04909cc9..f0f54e43f 100644 --- a/crates/brk_computer/src/transactions/count/import.rs +++ b/crates/brk_computer/src/transactions/count/import.rs @@ -4,7 +4,7 @@ use brk_types::{StoredBool, TxIndex, Version}; use vecdb::{Database, LazyVecFrom2, ReadableCloneableVec}; use super::Vecs; -use crate::{indexes, internal::{CachedWindowStarts, ComputedPerBlockFull}}; +use crate::{indexes, internal::{CachedWindowStarts, PerBlockFull}}; impl Vecs { pub(crate) fn forced_import( @@ -27,7 +27,7 @@ impl Vecs { ); Ok(Self { - total: ComputedPerBlockFull::forced_import( + total: PerBlockFull::forced_import( db, "tx_count", version, diff --git a/crates/brk_computer/src/transactions/count/vecs.rs b/crates/brk_computer/src/transactions/count/vecs.rs index ddc423d83..7719959f6 100644 --- a/crates/brk_computer/src/transactions/count/vecs.rs +++ b/crates/brk_computer/src/transactions/count/vecs.rs @@ -2,10 +2,10 @@ use brk_traversable::Traversable; use brk_types::{Height, StoredBool, StoredU64, TxIndex}; use vecdb::{LazyVecFrom2, Rw, StorageMode}; -use crate::internal::ComputedPerBlockFull; +use crate::internal::PerBlockFull; #[derive(Traversable)] pub struct Vecs { - pub total: ComputedPerBlockFull, + pub total: PerBlockFull, pub is_coinbase: LazyVecFrom2, } diff --git a/crates/brk_computer/src/transactions/fees/import.rs b/crates/brk_computer/src/transactions/fees/import.rs index b764f25fb..28e3b843e 100644 --- a/crates/brk_computer/src/transactions/fees/import.rs +++ b/crates/brk_computer/src/transactions/fees/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::{Database, EagerVec, ImportableVec}; use super::Vecs; -use crate::internal::ComputedPerTxDistribution; +use crate::internal::PerTxDistribution; /// Bump this when fee/feerate aggregation logic changes (e.g., skip coinbase). const VERSION: Version = Version::new(2); @@ -14,8 +14,8 @@ impl Vecs { Ok(Self { input_value: EagerVec::forced_import(db, "input_value", version)?, output_value: EagerVec::forced_import(db, "output_value", version)?, - fee: ComputedPerTxDistribution::forced_import(db, "fee", v)?, - fee_rate: ComputedPerTxDistribution::forced_import(db, "fee_rate", v)?, + fee: PerTxDistribution::forced_import(db, "fee", v)?, + fee_rate: PerTxDistribution::forced_import(db, "fee_rate", v)?, }) } } diff --git a/crates/brk_computer/src/transactions/fees/vecs.rs b/crates/brk_computer/src/transactions/fees/vecs.rs index 7668adf08..099fd28e1 100644 --- a/crates/brk_computer/src/transactions/fees/vecs.rs +++ b/crates/brk_computer/src/transactions/fees/vecs.rs @@ -2,12 +2,12 @@ use brk_traversable::Traversable; use brk_types::{FeeRate, Sats, TxIndex}; use vecdb::{EagerVec, PcoVec, Rw, StorageMode}; -use crate::internal::ComputedPerTxDistribution; +use crate::internal::PerTxDistribution; #[derive(Traversable)] pub struct Vecs { pub input_value: M::Stored>>, pub output_value: M::Stored>>, - pub fee: ComputedPerTxDistribution, - pub fee_rate: ComputedPerTxDistribution, + pub fee: PerTxDistribution, + pub fee_rate: PerTxDistribution, } diff --git a/crates/brk_computer/src/transactions/import.rs b/crates/brk_computer/src/transactions/import.rs index 9c026fdb3..02f998fcb 100644 --- a/crates/brk_computer/src/transactions/import.rs +++ b/crates/brk_computer/src/transactions/import.rs @@ -6,7 +6,7 @@ use brk_types::Version; use crate::{ indexes, - internal::{finalize_db, open_db, CachedWindowStarts}, + internal::{CachedWindowStarts, db_utils::{finalize_db, open_db}}, }; use super::{CountVecs, FeesVecs, SizeVecs, Vecs, VersionsVecs, VolumeVecs}; diff --git a/crates/brk_computer/src/transactions/size/import.rs b/crates/brk_computer/src/transactions/size/import.rs index 0446c7c5a..85895d3a2 100644 --- a/crates/brk_computer/src/transactions/size/import.rs +++ b/crates/brk_computer/src/transactions/size/import.rs @@ -4,7 +4,7 @@ use brk_types::{TxIndex, VSize, Version, Weight}; use vecdb::{Database, LazyVecFrom2, ReadableCloneableVec}; use super::Vecs; -use crate::internal::{LazyPerTxDistribution, LazyPerTxDistributionDerived, VSizeToWeight}; +use crate::internal::{LazyPerTxDistribution, LazyPerTxDistributionTransformed, VSizeToWeight}; impl Vecs { pub(crate) fn forced_import( @@ -33,7 +33,7 @@ impl Vecs { |_index: TxIndex, base_size, total_size| Weight::from_sizes(*base_size, *total_size), ); - let weight = LazyPerTxDistributionDerived::new::( + let weight = LazyPerTxDistributionTransformed::new::( "tx_weight", version, txindex_to_weight, diff --git a/crates/brk_computer/src/transactions/size/vecs.rs b/crates/brk_computer/src/transactions/size/vecs.rs index 33f51567d..292e3202d 100644 --- a/crates/brk_computer/src/transactions/size/vecs.rs +++ b/crates/brk_computer/src/transactions/size/vecs.rs @@ -2,10 +2,10 @@ use brk_traversable::Traversable; use brk_types::{StoredU32, VSize, Weight}; use vecdb::{Rw, StorageMode}; -use crate::internal::{LazyPerTxDistribution, LazyPerTxDistributionDerived}; +use crate::internal::{LazyPerTxDistribution, LazyPerTxDistributionTransformed}; #[derive(Traversable)] pub struct Vecs { pub vsize: LazyPerTxDistribution, - pub weight: LazyPerTxDistributionDerived, + pub weight: LazyPerTxDistributionTransformed, } diff --git a/crates/brk_computer/src/transactions/versions/compute.rs b/crates/brk_computer/src/transactions/versions/compute.rs index baab5a0ee..1b23fad46 100644 --- a/crates/brk_computer/src/transactions/versions/compute.rs +++ b/crates/brk_computer/src/transactions/versions/compute.rs @@ -4,7 +4,7 @@ use brk_types::{Indexes, StoredU64, TxVersion}; use vecdb::{Exit, ReadableVec, VecIndex}; use super::Vecs; -use crate::internal::ComputedPerBlockCumulativeWithSums; +use crate::internal::PerBlockCumulativeWithSums; impl Vecs { pub(crate) fn compute( @@ -13,7 +13,7 @@ impl Vecs { starting_indexes: &Indexes, exit: &Exit, ) -> Result<()> { - let tx_vany = |tx_vany: &mut ComputedPerBlockCumulativeWithSums, + let tx_vany = |tx_vany: &mut PerBlockCumulativeWithSums, txversion: TxVersion| { let txversion_vec = &indexer.vecs.transactions.txversion; // Cursor avoids per-transaction PcoVec page decompression. diff --git a/crates/brk_computer/src/transactions/versions/import.rs b/crates/brk_computer/src/transactions/versions/import.rs index 4b7d8dcbb..07c96335c 100644 --- a/crates/brk_computer/src/transactions/versions/import.rs +++ b/crates/brk_computer/src/transactions/versions/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{CachedWindowStarts, ComputedPerBlockCumulativeWithSums}, + internal::{CachedWindowStarts, PerBlockCumulativeWithSums}, }; impl Vecs { @@ -16,9 +16,9 @@ impl Vecs { cached_starts: &CachedWindowStarts, ) -> Result { Ok(Self { - v1: ComputedPerBlockCumulativeWithSums::forced_import(db, "tx_v1", version, indexes, cached_starts)?, - v2: ComputedPerBlockCumulativeWithSums::forced_import(db, "tx_v2", version, indexes, cached_starts)?, - v3: ComputedPerBlockCumulativeWithSums::forced_import(db, "tx_v3", version, indexes, cached_starts)?, + v1: PerBlockCumulativeWithSums::forced_import(db, "tx_v1", version, indexes, cached_starts)?, + v2: PerBlockCumulativeWithSums::forced_import(db, "tx_v2", version, indexes, cached_starts)?, + v3: PerBlockCumulativeWithSums::forced_import(db, "tx_v3", version, indexes, cached_starts)?, }) } } diff --git a/crates/brk_computer/src/transactions/versions/vecs.rs b/crates/brk_computer/src/transactions/versions/vecs.rs index 9b805bee6..161503916 100644 --- a/crates/brk_computer/src/transactions/versions/vecs.rs +++ b/crates/brk_computer/src/transactions/versions/vecs.rs @@ -2,11 +2,11 @@ use brk_traversable::Traversable; use brk_types::StoredU64; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedPerBlockCumulativeWithSums; +use crate::internal::PerBlockCumulativeWithSums; #[derive(Traversable)] pub struct Vecs { - pub v1: ComputedPerBlockCumulativeWithSums, - pub v2: ComputedPerBlockCumulativeWithSums, - pub v3: ComputedPerBlockCumulativeWithSums, + pub v1: PerBlockCumulativeWithSums, + pub v2: PerBlockCumulativeWithSums, + pub v3: PerBlockCumulativeWithSums, } diff --git a/crates/brk_computer/src/transactions/volume/compute.rs b/crates/brk_computer/src/transactions/volume/compute.rs index 5aea6c7d3..bcb723e72 100644 --- a/crates/brk_computer/src/transactions/volume/compute.rs +++ b/crates/brk_computer/src/transactions/volume/compute.rs @@ -57,7 +57,7 @@ impl Vecs { .height .compute_binary::<_, Timestamp, PerSec>( starting_indexes.height, - &count_vecs.total.raw.height, + &count_vecs.total.base.height, &blocks.interval.height, exit, )?; diff --git a/crates/brk_computer/src/transactions/volume/import.rs b/crates/brk_computer/src/transactions/volume/import.rs index 858712304..6a849f971 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, ComputedPerBlock}, + internal::{AmountPerBlockCumulativeWithSums, CachedWindowStarts, PerBlock}, }; impl Vecs { @@ -31,14 +31,14 @@ impl Vecs { indexes, cached_starts, )?, - tx_per_sec: ComputedPerBlock::forced_import(db, "tx_per_sec", version + v2, indexes)?, - outputs_per_sec: ComputedPerBlock::forced_import( + 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: ComputedPerBlock::forced_import( + inputs_per_sec: PerBlock::forced_import( db, "inputs_per_sec", version + v2, diff --git a/crates/brk_computer/src/transactions/volume/vecs.rs b/crates/brk_computer/src/transactions/volume/vecs.rs index 7e2311878..c0b904b32 100644 --- a/crates/brk_computer/src/transactions/volume/vecs.rs +++ b/crates/brk_computer/src/transactions/volume/vecs.rs @@ -2,13 +2,13 @@ use brk_traversable::Traversable; use brk_types::StoredF32; use vecdb::{Rw, StorageMode}; -use crate::internal::{AmountPerBlockCumulativeWithSums, ComputedPerBlock}; +use crate::internal::{AmountPerBlockCumulativeWithSums, PerBlock}; #[derive(Traversable)] pub struct Vecs { pub sent_sum: AmountPerBlockCumulativeWithSums, pub received_sum: AmountPerBlockCumulativeWithSums, - pub tx_per_sec: ComputedPerBlock, - pub outputs_per_sec: ComputedPerBlock, - pub inputs_per_sec: ComputedPerBlock, + pub tx_per_sec: PerBlock, + pub outputs_per_sec: PerBlock, + pub inputs_per_sec: PerBlock, } diff --git a/crates/brk_query/src/impl/mining/block_rewards.rs b/crates/brk_query/src/impl/mining/block_rewards.rs index 429a91a08..b87b5b5f5 100644 --- a/crates/brk_query/src/impl/mining/block_rewards.rs +++ b/crates/brk_query/src/impl/mining/block_rewards.rs @@ -11,7 +11,7 @@ impl Query { let current_height = self.height().to_usize(); let start = current_height.saturating_sub(time_period.block_count()); - let coinbase_vec = &computer.mining.rewards.coinbase.raw.sats.height; + let coinbase_vec = &computer.mining.rewards.coinbase.base.sats.height; let timestamp_vec = &indexer.vecs.blocks.timestamp; match time_period { diff --git a/crates/brk_query/src/impl/mining/epochs.rs b/crates/brk_query/src/impl/mining/epochs.rs index 9b224a51d..3330a74a0 100644 --- a/crates/brk_query/src/impl/mining/epochs.rs +++ b/crates/brk_query/src/impl/mining/epochs.rs @@ -23,7 +23,7 @@ pub fn iter_difficulty_epochs( let epoch_to_height = &computer.indexes.epoch.first_height; let epoch_to_timestamp = &computer.blocks.time.timestamp.epoch; - let epoch_to_difficulty = &computer.blocks.difficulty.raw.epoch; + let epoch_to_difficulty = &computer.blocks.difficulty.base.epoch; let mut results = Vec::with_capacity(end_epoch.to_usize() - start_epoch.to_usize() + 1); let mut prev_difficulty: Option = None; diff --git a/crates/brk_query/src/impl/mining/hashrate.rs b/crates/brk_query/src/impl/mining/hashrate.rs index 69256bb6a..34f025738 100644 --- a/crates/brk_query/src/impl/mining/hashrate.rs +++ b/crates/brk_query/src/impl/mining/hashrate.rs @@ -30,7 +30,7 @@ impl Query { let current_hashrate = *computer .mining .hashrate - .rate.raw + .rate.base .day1 .collect_one_flat(current_day1) .unwrap_or_default() as u128; @@ -55,7 +55,7 @@ impl Query { let total_days = end_day1.to_usize().saturating_sub(start_day1.to_usize()) + 1; let step = (total_days / 200).max(1); // Max ~200 data points - let hashrate_vec = &computer.mining.hashrate.rate.raw.day1; + let hashrate_vec = &computer.mining.hashrate.rate.base.day1; let timestamp_vec = &computer.blocks.time.timestamp.day1; let mut hashrates = Vec::with_capacity(total_days / step + 1); diff --git a/crates/brk_query/src/impl/mining/reward_stats.rs b/crates/brk_query/src/impl/mining/reward_stats.rs index 7503f7687..838bc13a8 100644 --- a/crates/brk_query/src/impl/mining/reward_stats.rs +++ b/crates/brk_query/src/impl/mining/reward_stats.rs @@ -12,9 +12,9 @@ impl Query { let end_block = current_height; let start_block = Height::from(current_height.to_usize().saturating_sub(block_count - 1)); - let coinbase_vec = &computer.mining.rewards.coinbase.raw.sats.height; + let coinbase_vec = &computer.mining.rewards.coinbase.base.sats.height; let fee_vec = &computer.mining.rewards.fees.base.sats.height; - let tx_count_vec = &computer.transactions.count.total.raw.height; + let tx_count_vec = &computer.transactions.count.total.base.height; let start = start_block.to_usize(); let end = end_block.to_usize() + 1; diff --git a/modules/brk-client/index.js b/modules/brk-client/index.js index 441b373f5..551f1a4cf 100644 --- a/modules/brk-client/index.js +++ b/modules/brk-client/index.js @@ -1783,14 +1783,14 @@ function create_10y1m1w1y2y3m3y4y5y6m6y8yPattern3(client, acc) { /** * @typedef {Object} CapGrossInvestorLossMvrvNetPeakPriceProfitSellSoprPattern * @property {CentsDeltaRelUsdPattern} cap - * @property {CumulativeRawSumPattern3} grossPnl + * @property {BaseCumulativeSumPattern3} grossPnl * @property {LowerPriceUpperPattern} investor - * @property {CapitulationCumulativeNegativeRawRelSumValuePattern} loss + * @property {BaseCapitulationCumulativeNegativeRelSumValuePattern} loss * @property {MetricPattern1} mvrv - * @property {ChangeCumulativeDeltaRawRelSumPattern} netPnl - * @property {CumulativeRawRelPattern} peakRegret + * @property {BaseChangeCumulativeDeltaRelSumPattern} netPnl + * @property {BaseCumulativeRelPattern} peakRegret * @property {BpsCentsPercentilesRatioSatsSmaStdUsdPattern} price - * @property {CumulativeDistributionRawRelSumValuePattern} profit + * @property {BaseCumulativeDistributionRelSumValuePattern} profit * @property {_1m1w1y24hPattern} profitToLossRatio * @property {_1m1w1y24hPattern2} sellSideRiskRatio * @property {AdjustedRatioValuePattern} sopr @@ -1805,14 +1805,14 @@ function create_10y1m1w1y2y3m3y4y5y6m6y8yPattern3(client, acc) { function createCapGrossInvestorLossMvrvNetPeakPriceProfitSellSoprPattern(client, acc) { return { cap: createCentsDeltaRelUsdPattern(client, _m(acc, 'realized_cap')), - grossPnl: createCumulativeRawSumPattern3(client, _m(acc, 'realized_gross_pnl')), + grossPnl: createBaseCumulativeSumPattern3(client, _m(acc, 'realized_gross_pnl')), investor: createLowerPriceUpperPattern(client, acc), - loss: createCapitulationCumulativeNegativeRawRelSumValuePattern(client, acc), + loss: createBaseCapitulationCumulativeNegativeRelSumValuePattern(client, acc), mvrv: createMetricPattern1(client, _m(acc, 'mvrv')), - netPnl: createChangeCumulativeDeltaRawRelSumPattern(client, _m(acc, 'net')), - peakRegret: createCumulativeRawRelPattern(client, _m(acc, 'realized_peak_regret')), + netPnl: createBaseChangeCumulativeDeltaRelSumPattern(client, _m(acc, 'net')), + peakRegret: createBaseCumulativeRelPattern(client, _m(acc, 'realized_peak_regret')), price: createBpsCentsPercentilesRatioSatsSmaStdUsdPattern(client, _m(acc, 'realized_price')), - profit: createCumulativeDistributionRawRelSumValuePattern(client, acc), + profit: createBaseCumulativeDistributionRelSumValuePattern(client, acc), profitToLossRatio: create_1m1w1y24hPattern(client, _m(acc, 'realized_profit_to_loss_ratio')), sellSideRiskRatio: create_1m1w1y24hPattern2(client, _m(acc, 'sell_side_risk_ratio')), sopr: createAdjustedRatioValuePattern(client, acc), @@ -1857,8 +1857,9 @@ function createAverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RollingSumPatter } /** - * @typedef {Object} AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern + * @typedef {Object} AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern * @property {_1m1w1y24hPattern} average + * @property {MetricPattern1} base * @property {MetricPattern1} cumulative * @property {_1m1w1y24hPattern} max * @property {_1m1w1y24hPattern} median @@ -1867,19 +1868,19 @@ function createAverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RollingSumPatter * @property {_1m1w1y24hPattern} pct25 * @property {_1m1w1y24hPattern} pct75 * @property {_1m1w1y24hPattern} pct90 - * @property {MetricPattern1} raw * @property {_1m1w1y24hPattern} sum */ /** - * Create a AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern pattern node + * Create a AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern pattern node * @param {BrkClientBase} client * @param {string} acc - Accumulated metric name - * @returns {AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern} + * @returns {AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern} */ -function createAverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern(client, acc) { +function createAverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, acc) { return { average: create_1m1w1y24hPattern(client, _m(acc, 'average')), + base: createMetricPattern1(client, acc), cumulative: createMetricPattern1(client, _m(acc, 'cumulative')), max: create_1m1w1y24hPattern(client, _m(acc, 'max')), median: create_1m1w1y24hPattern(client, _m(acc, 'median')), @@ -1888,7 +1889,6 @@ function createAverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern(cl pct25: create_1m1w1y24hPattern(client, _m(acc, 'pct25')), pct75: create_1m1w1y24hPattern(client, _m(acc, 'pct75')), pct90: create_1m1w1y24hPattern(client, _m(acc, 'pct90')), - raw: createMetricPattern1(client, acc), sum: create_1m1w1y24hPattern(client, _m(acc, 'sum')), }; } @@ -2025,6 +2025,37 @@ function createAverageMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, acc) { }; } +/** + * @typedef {Object} BaseCapitulationCumulativeNegativeRelSumValuePattern + * @property {CentsUsdPattern2} base + * @property {MetricPattern1} capitulationFlow + * @property {CentsUsdPattern2} cumulative + * @property {MetricPattern1} negative + * @property {BpsPercentRatioPattern} relToRcap + * @property {_1m1w1y24hPattern5} sum + * @property {BaseCumulativeSumPattern} valueCreated + * @property {BaseCumulativeSumPattern} valueDestroyed + */ + +/** + * Create a BaseCapitulationCumulativeNegativeRelSumValuePattern pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseCapitulationCumulativeNegativeRelSumValuePattern} + */ +function createBaseCapitulationCumulativeNegativeRelSumValuePattern(client, acc) { + return { + base: createCentsUsdPattern2(client, _m(acc, 'realized_loss')), + capitulationFlow: createMetricPattern1(client, _m(acc, 'capitulation_flow')), + cumulative: createCentsUsdPattern2(client, _m(acc, 'realized_loss_cumulative')), + negative: createMetricPattern1(client, _m(acc, 'neg_realized_loss')), + relToRcap: createBpsPercentRatioPattern(client, _m(acc, 'realized_loss_rel_to_rcap')), + sum: create_1m1w1y24hPattern5(client, _m(acc, 'realized_loss_sum')), + valueCreated: createBaseCumulativeSumPattern(client, _m(acc, 'loss_value_created')), + valueDestroyed: createBaseCumulativeSumPattern(client, _m(acc, 'loss_value_destroyed')), + }; +} + /** * @typedef {Object} BpsCentsPercentilesRatioSatsSmaStdUsdPattern * @property {MetricPattern1} bps @@ -2056,37 +2087,6 @@ function createBpsCentsPercentilesRatioSatsSmaStdUsdPattern(client, acc) { }; } -/** - * @typedef {Object} CapitulationCumulativeNegativeRawRelSumValuePattern - * @property {MetricPattern1} capitulationFlow - * @property {CentsUsdPattern2} cumulative - * @property {MetricPattern1} negative - * @property {CentsUsdPattern2} raw - * @property {BpsPercentRatioPattern} relToRcap - * @property {_1m1w1y24hPattern5} sum - * @property {CumulativeRawSumPattern} valueCreated - * @property {CumulativeRawSumPattern} valueDestroyed - */ - -/** - * Create a CapitulationCumulativeNegativeRawRelSumValuePattern pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CapitulationCumulativeNegativeRawRelSumValuePattern} - */ -function createCapitulationCumulativeNegativeRawRelSumValuePattern(client, acc) { - return { - capitulationFlow: createMetricPattern1(client, _m(acc, 'capitulation_flow')), - cumulative: createCentsUsdPattern2(client, _m(acc, 'realized_loss_cumulative')), - negative: createMetricPattern1(client, _m(acc, 'neg_realized_loss')), - raw: createCentsUsdPattern2(client, _m(acc, 'realized_loss')), - relToRcap: createBpsPercentRatioPattern(client, _m(acc, 'realized_loss_rel_to_rcap')), - sum: create_1m1w1y24hPattern5(client, _m(acc, 'realized_loss_sum')), - valueCreated: createCumulativeRawSumPattern(client, _m(acc, 'loss_value_created')), - valueDestroyed: createCumulativeRawSumPattern(client, _m(acc, 'loss_value_destroyed')), - }; -} - /** * @template T * @typedef {Object} AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern2 @@ -2178,14 +2178,72 @@ function create_1m1w1y24hBpsPercentRatioPattern(client, acc) { }; } +/** + * @typedef {Object} BaseCumulativeDistributionRelSumValuePattern + * @property {CentsUsdPattern2} base + * @property {CentsUsdPattern2} cumulative + * @property {MetricPattern1} distributionFlow + * @property {BpsPercentRatioPattern} relToRcap + * @property {_1m1w1y24hPattern5} sum + * @property {BaseCumulativeSumPattern} valueCreated + * @property {BaseCumulativeSumPattern} valueDestroyed + */ + +/** + * Create a BaseCumulativeDistributionRelSumValuePattern pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseCumulativeDistributionRelSumValuePattern} + */ +function createBaseCumulativeDistributionRelSumValuePattern(client, acc) { + return { + base: createCentsUsdPattern2(client, _m(acc, 'realized_profit')), + cumulative: createCentsUsdPattern2(client, _m(acc, 'realized_profit_cumulative')), + distributionFlow: createMetricPattern1(client, _m(acc, 'distribution_flow')), + relToRcap: createBpsPercentRatioPattern(client, _m(acc, 'realized_profit_rel_to_rcap')), + sum: create_1m1w1y24hPattern5(client, _m(acc, 'realized_profit_sum')), + valueCreated: createBaseCumulativeSumPattern(client, _m(acc, 'profit_value_created')), + valueDestroyed: createBaseCumulativeSumPattern(client, _m(acc, 'profit_value_destroyed')), + }; +} + +/** + * @typedef {Object} BaseCumulativeNegativeRelSumPattern2 + * @property {CentsUsdPattern2} base + * @property {CentsUsdPattern2} cumulative + * @property {MetricPattern1} negative + * @property {BpsPercentRatioPattern4} relToMcap + * @property {BpsPercentRatioPattern4} relToOwnGross + * @property {BpsPercentRatioPattern} relToOwnMcap + * @property {_1m1w1y24hPattern5} sum + */ + +/** + * Create a BaseCumulativeNegativeRelSumPattern2 pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseCumulativeNegativeRelSumPattern2} + */ +function createBaseCumulativeNegativeRelSumPattern2(client, acc) { + return { + base: createCentsUsdPattern2(client, _m(acc, 'unrealized_loss')), + cumulative: createCentsUsdPattern2(client, _m(acc, 'unrealized_loss_cumulative')), + negative: createMetricPattern1(client, _m(acc, 'neg_unrealized_loss')), + relToMcap: createBpsPercentRatioPattern4(client, _m(acc, 'unrealized_loss_rel_to_mcap')), + relToOwnGross: createBpsPercentRatioPattern4(client, _m(acc, 'unrealized_loss_rel_to_own_gross_pnl')), + relToOwnMcap: createBpsPercentRatioPattern(client, _m(acc, 'unrealized_loss_rel_to_own_mcap')), + sum: create_1m1w1y24hPattern5(client, _m(acc, 'unrealized_loss_sum')), + }; +} + /** * @typedef {Object} CapLossMvrvNetPriceProfitSoprPattern * @property {CentsDeltaUsdPattern} cap - * @property {CumulativeNegativeRawSumPattern} loss + * @property {BaseCumulativeNegativeSumPattern} loss * @property {MetricPattern1} mvrv - * @property {CumulativeDeltaRawSumPattern} netPnl + * @property {BaseCumulativeDeltaSumPattern} netPnl * @property {BpsCentsRatioSatsUsdPattern} price - * @property {CumulativeRawSumPattern3} profit + * @property {BaseCumulativeSumPattern3} profit * @property {RatioValuePattern} sopr */ @@ -2198,81 +2256,23 @@ function create_1m1w1y24hBpsPercentRatioPattern(client, acc) { function createCapLossMvrvNetPriceProfitSoprPattern(client, acc) { return { cap: createCentsDeltaUsdPattern(client, _m(acc, 'realized_cap')), - loss: createCumulativeNegativeRawSumPattern(client, acc), + loss: createBaseCumulativeNegativeSumPattern(client, acc), mvrv: createMetricPattern1(client, _m(acc, 'mvrv')), - netPnl: createCumulativeDeltaRawSumPattern(client, _m(acc, 'net_realized_pnl')), + netPnl: createBaseCumulativeDeltaSumPattern(client, _m(acc, 'net_realized_pnl')), price: createBpsCentsRatioSatsUsdPattern(client, _m(acc, 'realized_price')), - profit: createCumulativeRawSumPattern3(client, _m(acc, 'realized_profit')), + profit: createBaseCumulativeSumPattern3(client, _m(acc, 'realized_profit')), sopr: createRatioValuePattern(client, acc), }; } -/** - * @typedef {Object} CumulativeDistributionRawRelSumValuePattern - * @property {CentsUsdPattern2} cumulative - * @property {MetricPattern1} distributionFlow - * @property {CentsUsdPattern2} raw - * @property {BpsPercentRatioPattern} relToRcap - * @property {_1m1w1y24hPattern5} sum - * @property {CumulativeRawSumPattern} valueCreated - * @property {CumulativeRawSumPattern} valueDestroyed - */ - -/** - * Create a CumulativeDistributionRawRelSumValuePattern pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CumulativeDistributionRawRelSumValuePattern} - */ -function createCumulativeDistributionRawRelSumValuePattern(client, acc) { - return { - cumulative: createCentsUsdPattern2(client, _m(acc, 'realized_profit_cumulative')), - distributionFlow: createMetricPattern1(client, _m(acc, 'distribution_flow')), - raw: createCentsUsdPattern2(client, _m(acc, 'realized_profit')), - relToRcap: createBpsPercentRatioPattern(client, _m(acc, 'realized_profit_rel_to_rcap')), - sum: create_1m1w1y24hPattern5(client, _m(acc, 'realized_profit_sum')), - valueCreated: createCumulativeRawSumPattern(client, _m(acc, 'profit_value_created')), - valueDestroyed: createCumulativeRawSumPattern(client, _m(acc, 'profit_value_destroyed')), - }; -} - -/** - * @typedef {Object} CumulativeNegativeRawRelSumPattern2 - * @property {CentsUsdPattern2} cumulative - * @property {MetricPattern1} negative - * @property {CentsUsdPattern2} raw - * @property {BpsPercentRatioPattern4} relToMcap - * @property {BpsPercentRatioPattern4} relToOwnGross - * @property {BpsPercentRatioPattern} relToOwnMcap - * @property {_1m1w1y24hPattern5} sum - */ - -/** - * Create a CumulativeNegativeRawRelSumPattern2 pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CumulativeNegativeRawRelSumPattern2} - */ -function createCumulativeNegativeRawRelSumPattern2(client, acc) { - return { - cumulative: createCentsUsdPattern2(client, _m(acc, 'unrealized_loss_cumulative')), - negative: createMetricPattern1(client, _m(acc, 'neg_unrealized_loss')), - raw: createCentsUsdPattern2(client, _m(acc, 'unrealized_loss')), - relToMcap: createBpsPercentRatioPattern4(client, _m(acc, 'unrealized_loss_rel_to_mcap')), - relToOwnGross: createBpsPercentRatioPattern4(client, _m(acc, 'unrealized_loss_rel_to_own_gross_pnl')), - relToOwnMcap: createBpsPercentRatioPattern(client, _m(acc, 'unrealized_loss_rel_to_own_mcap')), - sum: create_1m1w1y24hPattern5(client, _m(acc, 'unrealized_loss_sum')), - }; -} - /** * @typedef {Object} GrossInvestedLossNetNuplProfitSentimentPattern2 * @property {CentsUsdPattern2} grossPnl * @property {InPattern} investedCapital - * @property {CumulativeNegativeRawRelSumPattern2} loss + * @property {BaseCumulativeNegativeRelSumPattern2} loss * @property {CentsRelUsdPattern2} netPnl * @property {BpsRatioPattern} nupl - * @property {CumulativeRawRelSumPattern2} profit + * @property {BaseCumulativeRelSumPattern2} profit * @property {GreedNetPainPattern} sentiment */ @@ -2286,10 +2286,10 @@ function createGrossInvestedLossNetNuplProfitSentimentPattern2(client, acc) { return { grossPnl: createCentsUsdPattern2(client, _m(acc, 'unrealized_gross_pnl')), investedCapital: createInPattern(client, _m(acc, 'invested_capital_in')), - loss: createCumulativeNegativeRawRelSumPattern2(client, acc), + loss: createBaseCumulativeNegativeRelSumPattern2(client, acc), netPnl: createCentsRelUsdPattern2(client, _m(acc, 'net_unrealized_pnl')), nupl: createBpsRatioPattern(client, _m(acc, 'nupl')), - profit: createCumulativeRawRelSumPattern2(client, _m(acc, 'unrealized_profit')), + profit: createBaseCumulativeRelSumPattern2(client, _m(acc, 'unrealized_profit')), sentiment: createGreedNetPainPattern(client, acc), }; } @@ -2321,6 +2321,60 @@ function create_1m1w1y2y4yAllPattern(client, acc) { }; } +/** + * @typedef {Object} BaseChangeCumulativeDeltaRelSumPattern + * @property {CentsUsdPattern} base + * @property {RelPattern} change1m + * @property {CentsUsdPattern} cumulative + * @property {ChangeRatePattern3} delta + * @property {BpsPercentRatioPattern2} relToRcap + * @property {_1m1w1y24hPattern4} sum + */ + +/** + * Create a BaseChangeCumulativeDeltaRelSumPattern pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseChangeCumulativeDeltaRelSumPattern} + */ +function createBaseChangeCumulativeDeltaRelSumPattern(client, acc) { + return { + base: createCentsUsdPattern(client, _m(acc, 'realized_pnl')), + change1m: createRelPattern(client, _m(acc, 'pnl_change_1m_rel_to')), + cumulative: createCentsUsdPattern(client, _m(acc, 'realized_pnl_cumulative')), + delta: createChangeRatePattern3(client, _m(acc, 'realized_pnl_delta')), + relToRcap: createBpsPercentRatioPattern2(client, _m(acc, 'realized_pnl_rel_to_rcap')), + sum: create_1m1w1y24hPattern4(client, _m(acc, 'realized_pnl_sum')), + }; +} + +/** + * @typedef {Object} BaseCumulativeRelSumPattern2 + * @property {CentsUsdPattern2} base + * @property {CentsUsdPattern2} cumulative + * @property {BpsPercentRatioPattern4} relToMcap + * @property {BpsPercentRatioPattern4} relToOwnGross + * @property {BpsPercentRatioPattern4} relToOwnMcap + * @property {_1m1w1y24hPattern5} sum + */ + +/** + * Create a BaseCumulativeRelSumPattern2 pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseCumulativeRelSumPattern2} + */ +function createBaseCumulativeRelSumPattern2(client, acc) { + return { + base: createCentsUsdPattern2(client, acc), + cumulative: createCentsUsdPattern2(client, _m(acc, 'cumulative')), + relToMcap: createBpsPercentRatioPattern4(client, _m(acc, 'rel_to_mcap')), + relToOwnGross: createBpsPercentRatioPattern4(client, _m(acc, 'rel_to_own_gross_pnl')), + relToOwnMcap: createBpsPercentRatioPattern4(client, _m(acc, 'rel_to_own_mcap')), + sum: create_1m1w1y24hPattern5(client, _m(acc, 'sum')), + }; +} + /** * @typedef {Object} BpsCentsPercentilesRatioSatsUsdPattern * @property {MetricPattern1} bps @@ -2378,10 +2432,10 @@ function createBtcCentsRelSatsUsdPattern3(client, acc) { /** * @typedef {Object} CapLossMvrvPriceProfitSoprPattern * @property {CentsDeltaUsdPattern} cap - * @property {CumulativeRawSumPattern3} loss + * @property {BaseCumulativeSumPattern3} loss * @property {MetricPattern1} mvrv * @property {BpsCentsRatioSatsUsdPattern} price - * @property {CumulativeRawSumPattern3} profit + * @property {BaseCumulativeSumPattern3} profit * @property {ValuePattern} sopr */ @@ -2394,68 +2448,14 @@ function createBtcCentsRelSatsUsdPattern3(client, acc) { function createCapLossMvrvPriceProfitSoprPattern(client, acc) { return { cap: createCentsDeltaUsdPattern(client, _m(acc, 'realized_cap')), - loss: createCumulativeRawSumPattern3(client, _m(acc, 'realized_loss')), + loss: createBaseCumulativeSumPattern3(client, _m(acc, 'realized_loss')), mvrv: createMetricPattern1(client, _m(acc, 'mvrv')), price: createBpsCentsRatioSatsUsdPattern(client, _m(acc, 'realized_price')), - profit: createCumulativeRawSumPattern3(client, _m(acc, 'realized_profit')), + profit: createBaseCumulativeSumPattern3(client, _m(acc, 'realized_profit')), sopr: createValuePattern(client, _m(acc, 'value')), }; } -/** - * @typedef {Object} ChangeCumulativeDeltaRawRelSumPattern - * @property {RelPattern} change1m - * @property {CentsUsdPattern} cumulative - * @property {ChangeRatePattern3} delta - * @property {CentsUsdPattern} raw - * @property {BpsPercentRatioPattern2} relToRcap - * @property {_1m1w1y24hPattern4} sum - */ - -/** - * Create a ChangeCumulativeDeltaRawRelSumPattern pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {ChangeCumulativeDeltaRawRelSumPattern} - */ -function createChangeCumulativeDeltaRawRelSumPattern(client, acc) { - return { - change1m: createRelPattern(client, _m(acc, 'pnl_change_1m_rel_to')), - cumulative: createCentsUsdPattern(client, _m(acc, 'realized_pnl_cumulative')), - delta: createChangeRatePattern3(client, _m(acc, 'realized_pnl_delta')), - raw: createCentsUsdPattern(client, _m(acc, 'realized_pnl')), - relToRcap: createBpsPercentRatioPattern2(client, _m(acc, 'realized_pnl_rel_to_rcap')), - sum: create_1m1w1y24hPattern4(client, _m(acc, 'realized_pnl_sum')), - }; -} - -/** - * @typedef {Object} CumulativeRawRelSumPattern2 - * @property {CentsUsdPattern2} cumulative - * @property {CentsUsdPattern2} raw - * @property {BpsPercentRatioPattern4} relToMcap - * @property {BpsPercentRatioPattern4} relToOwnGross - * @property {BpsPercentRatioPattern4} relToOwnMcap - * @property {_1m1w1y24hPattern5} sum - */ - -/** - * Create a CumulativeRawRelSumPattern2 pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CumulativeRawRelSumPattern2} - */ -function createCumulativeRawRelSumPattern2(client, acc) { - return { - cumulative: createCentsUsdPattern2(client, _m(acc, 'cumulative')), - raw: createCentsUsdPattern2(client, acc), - relToMcap: createBpsPercentRatioPattern4(client, _m(acc, 'rel_to_mcap')), - relToOwnGross: createBpsPercentRatioPattern4(client, _m(acc, 'rel_to_own_gross_pnl')), - relToOwnMcap: createBpsPercentRatioPattern4(client, _m(acc, 'rel_to_own_mcap')), - sum: create_1m1w1y24hPattern5(client, _m(acc, 'sum')), - }; -} - /** * @typedef {Object} DeltaHalfInRelTotalPattern * @property {ChangeRatePattern2} delta @@ -2587,6 +2587,31 @@ function createAddressOutputsRealizedSupplyUnrealizedPattern(client, acc) { }; } +/** + * @typedef {Object} BaseCumulativeInSumPattern + * @property {MetricPattern1} base + * @property {MetricPattern1} cumulative + * @property {BaseCumulativeSumPattern4} inLoss + * @property {BaseCumulativeSumPattern4} inProfit + * @property {_1m1w1y24hPattern} sum + */ + +/** + * Create a BaseCumulativeInSumPattern pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseCumulativeInSumPattern} + */ +function createBaseCumulativeInSumPattern(client, acc) { + return { + base: createMetricPattern1(client, acc), + cumulative: createMetricPattern1(client, _m(acc, 'cumulative')), + inLoss: createBaseCumulativeSumPattern4(client, _m(acc, 'in_loss')), + inProfit: createBaseCumulativeSumPattern4(client, _m(acc, 'in_profit')), + sum: create_1m1w1y24hPattern(client, _m(acc, 'sum')), + }; +} + /** * @typedef {Object} BpsCentsRatioSatsUsdPattern * @property {MetricPattern1} bps @@ -2664,10 +2689,10 @@ function createBtcCentsRelSatsUsdPattern2(client, acc) { /** * @typedef {Object} CoindaysCoinyearsDormancySentVelocityPattern - * @property {CumulativeRawSumPattern} coindaysDestroyed + * @property {BaseCumulativeSumPattern} coindaysDestroyed * @property {MetricPattern1} coinyearsDestroyed * @property {MetricPattern1} dormancy - * @property {CumulativeInRawSumPattern} sent + * @property {BaseCumulativeInSumPattern} sent * @property {MetricPattern1} velocity */ @@ -2679,39 +2704,14 @@ function createBtcCentsRelSatsUsdPattern2(client, acc) { */ function createCoindaysCoinyearsDormancySentVelocityPattern(client, acc) { return { - coindaysDestroyed: createCumulativeRawSumPattern(client, _m(acc, 'coindays_destroyed')), + coindaysDestroyed: createBaseCumulativeSumPattern(client, _m(acc, 'coindays_destroyed')), coinyearsDestroyed: createMetricPattern1(client, _m(acc, 'coinyears_destroyed')), dormancy: createMetricPattern1(client, _m(acc, 'dormancy')), - sent: createCumulativeInRawSumPattern(client, _m(acc, 'sent')), + sent: createBaseCumulativeInSumPattern(client, _m(acc, 'sent')), velocity: createMetricPattern1(client, _m(acc, 'velocity')), }; } -/** - * @typedef {Object} CumulativeInRawSumPattern - * @property {MetricPattern1} cumulative - * @property {CumulativeRawSumPattern4} inLoss - * @property {CumulativeRawSumPattern4} inProfit - * @property {MetricPattern1} raw - * @property {_1m1w1y24hPattern} sum - */ - -/** - * Create a CumulativeInRawSumPattern pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CumulativeInRawSumPattern} - */ -function createCumulativeInRawSumPattern(client, acc) { - return { - cumulative: createMetricPattern1(client, _m(acc, 'cumulative')), - inLoss: createCumulativeRawSumPattern4(client, _m(acc, 'in_loss')), - inProfit: createCumulativeRawSumPattern4(client, _m(acc, 'in_profit')), - raw: createMetricPattern1(client, acc), - sum: create_1m1w1y24hPattern(client, _m(acc, 'sum')), - }; -} - /** * @typedef {Object} DeltaHalfInTotalPattern2 * @property {ChangeRatePattern2} delta @@ -3004,8 +3004,8 @@ function create_1y2y4yAllPattern(client, acc) { * @typedef {Object} AdjustedRatioValuePattern * @property {RatioValuePattern2} adjusted * @property {_1m1w1y24hPattern} ratio - * @property {CumulativeRawSumPattern} valueCreated - * @property {CumulativeRawSumPattern} valueDestroyed + * @property {BaseCumulativeSumPattern} valueCreated + * @property {BaseCumulativeSumPattern} valueDestroyed */ /** @@ -3018,8 +3018,54 @@ function createAdjustedRatioValuePattern(client, acc) { return { adjusted: createRatioValuePattern2(client, acc), ratio: create_1m1w1y24hPattern(client, _m(acc, 'sopr')), - valueCreated: createCumulativeRawSumPattern(client, _m(acc, 'value_created')), - valueDestroyed: createCumulativeRawSumPattern(client, _m(acc, 'value_destroyed')), + valueCreated: createBaseCumulativeSumPattern(client, _m(acc, 'value_created')), + valueDestroyed: createBaseCumulativeSumPattern(client, _m(acc, 'value_destroyed')), + }; +} + +/** + * @typedef {Object} BaseCumulativeDeltaSumPattern + * @property {CentsUsdPattern} base + * @property {CentsUsdPattern} cumulative + * @property {ChangeRatePattern3} delta + * @property {_1m1w1y24hPattern4} sum + */ + +/** + * Create a BaseCumulativeDeltaSumPattern pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseCumulativeDeltaSumPattern} + */ +function createBaseCumulativeDeltaSumPattern(client, acc) { + return { + base: createCentsUsdPattern(client, acc), + cumulative: createCentsUsdPattern(client, _m(acc, 'cumulative')), + delta: createChangeRatePattern3(client, _m(acc, 'delta')), + sum: create_1m1w1y24hPattern4(client, _m(acc, 'sum')), + }; +} + +/** + * @typedef {Object} BaseCumulativeNegativeSumPattern + * @property {CentsUsdPattern2} base + * @property {CentsUsdPattern2} cumulative + * @property {MetricPattern1} negative + * @property {_1m1w1y24hPattern5} sum + */ + +/** + * Create a BaseCumulativeNegativeSumPattern pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseCumulativeNegativeSumPattern} + */ +function createBaseCumulativeNegativeSumPattern(client, acc) { + return { + base: createCentsUsdPattern2(client, _m(acc, 'unrealized_loss')), + cumulative: createCentsUsdPattern2(client, _m(acc, 'unrealized_loss_cumulative')), + negative: createMetricPattern1(client, _m(acc, 'neg_unrealized_loss')), + sum: create_1m1w1y24hPattern5(client, _m(acc, 'unrealized_loss_sum')), }; } @@ -3115,58 +3161,12 @@ function createCentsRelUsdPattern2(client, acc) { }; } -/** - * @typedef {Object} CumulativeDeltaRawSumPattern - * @property {CentsUsdPattern} cumulative - * @property {ChangeRatePattern3} delta - * @property {CentsUsdPattern} raw - * @property {_1m1w1y24hPattern4} sum - */ - -/** - * Create a CumulativeDeltaRawSumPattern pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CumulativeDeltaRawSumPattern} - */ -function createCumulativeDeltaRawSumPattern(client, acc) { - return { - cumulative: createCentsUsdPattern(client, _m(acc, 'cumulative')), - delta: createChangeRatePattern3(client, _m(acc, 'delta')), - raw: createCentsUsdPattern(client, acc), - sum: create_1m1w1y24hPattern4(client, _m(acc, 'sum')), - }; -} - -/** - * @typedef {Object} CumulativeNegativeRawSumPattern - * @property {CentsUsdPattern2} cumulative - * @property {MetricPattern1} negative - * @property {CentsUsdPattern2} raw - * @property {_1m1w1y24hPattern5} sum - */ - -/** - * Create a CumulativeNegativeRawSumPattern pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CumulativeNegativeRawSumPattern} - */ -function createCumulativeNegativeRawSumPattern(client, acc) { - return { - cumulative: createCentsUsdPattern2(client, _m(acc, 'unrealized_loss_cumulative')), - negative: createMetricPattern1(client, _m(acc, 'neg_unrealized_loss')), - raw: createCentsUsdPattern2(client, _m(acc, 'unrealized_loss')), - sum: create_1m1w1y24hPattern5(client, _m(acc, 'unrealized_loss_sum')), - }; -} - /** * @typedef {Object} LossNetNuplProfitPattern - * @property {CumulativeNegativeRawSumPattern} loss + * @property {BaseCumulativeNegativeSumPattern} loss * @property {CentsUsdPattern} netPnl * @property {BpsRatioPattern} nupl - * @property {CumulativeRawSumPattern3} profit + * @property {BaseCumulativeSumPattern3} profit */ /** @@ -3177,10 +3177,10 @@ function createCumulativeNegativeRawSumPattern(client, acc) { */ function createLossNetNuplProfitPattern(client, acc) { return { - loss: createCumulativeNegativeRawSumPattern(client, acc), + loss: createBaseCumulativeNegativeSumPattern(client, acc), netPnl: createCentsUsdPattern(client, _m(acc, 'net_unrealized_pnl')), nupl: createBpsRatioPattern(client, _m(acc, 'nupl')), - profit: createCumulativeRawSumPattern3(client, _m(acc, 'unrealized_profit')), + profit: createBaseCumulativeSumPattern3(client, _m(acc, 'unrealized_profit')), }; } @@ -3255,11 +3255,95 @@ function create_1m1w1y24hPattern(client, acc) { }; } +/** + * @typedef {Object} BaseCumulativeSumPattern4 + * @property {BtcCentsSatsUsdPattern} base + * @property {BtcCentsSatsUsdPattern} cumulative + * @property {_1m1w1y24hPattern6} sum + */ + +/** + * Create a BaseCumulativeSumPattern4 pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseCumulativeSumPattern4} + */ +function createBaseCumulativeSumPattern4(client, acc) { + return { + base: createBtcCentsSatsUsdPattern(client, acc), + cumulative: createBtcCentsSatsUsdPattern(client, _m(acc, 'cumulative')), + sum: create_1m1w1y24hPattern6(client, _m(acc, 'sum')), + }; +} + +/** + * @typedef {Object} BaseCumulativeRelPattern + * @property {MetricPattern1} base + * @property {MetricPattern1} cumulative + * @property {BpsPercentRatioPattern} relToRcap + */ + +/** + * Create a BaseCumulativeRelPattern pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseCumulativeRelPattern} + */ +function createBaseCumulativeRelPattern(client, acc) { + return { + base: createMetricPattern1(client, acc), + cumulative: createMetricPattern1(client, _m(acc, 'cumulative')), + relToRcap: createBpsPercentRatioPattern(client, _m(acc, 'rel_to_rcap')), + }; +} + +/** + * @typedef {Object} BaseCumulativeSumPattern3 + * @property {CentsUsdPattern2} base + * @property {CentsUsdPattern2} cumulative + * @property {_1m1w1y24hPattern5} sum + */ + +/** + * Create a BaseCumulativeSumPattern3 pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseCumulativeSumPattern3} + */ +function createBaseCumulativeSumPattern3(client, acc) { + return { + base: createCentsUsdPattern2(client, acc), + cumulative: createCentsUsdPattern2(client, _m(acc, 'cumulative')), + sum: create_1m1w1y24hPattern5(client, _m(acc, 'sum')), + }; +} + +/** + * @typedef {Object} BaseCumulativeSumPattern2 + * @property {MetricPattern1} base + * @property {MetricPattern1} cumulative + * @property {_1m1w1y24hPattern} sum + */ + +/** + * Create a BaseCumulativeSumPattern2 pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {BaseCumulativeSumPattern2} + */ +function createBaseCumulativeSumPattern2(client, acc) { + return { + base: createMetricPattern1(client, acc), + cumulative: createMetricPattern1(client, _m(acc, 'cumulative')), + sum: create_1m1w1y24hPattern(client, _m(acc, 'sum')), + }; +} + /** * @typedef {Object} BlocksDominanceRewardsPattern - * @property {CumulativeRawSumPattern2} blocksMined + * @property {BaseCumulativeSumPattern2} blocksMined * @property {_1m1w1y24hBpsPercentRatioPattern} dominance - * @property {CumulativeRawSumPattern4} rewards + * @property {BaseCumulativeSumPattern4} rewards */ /** @@ -3270,9 +3354,9 @@ function create_1m1w1y24hPattern(client, acc) { */ function createBlocksDominanceRewardsPattern(client, acc) { return { - blocksMined: createCumulativeRawSumPattern2(client, _m(acc, 'blocks_mined')), + blocksMined: createBaseCumulativeSumPattern2(client, _m(acc, 'blocks_mined')), dominance: create_1m1w1y24hBpsPercentRatioPattern(client, _m(acc, 'dominance')), - rewards: createCumulativeRawSumPattern4(client, _m(acc, 'rewards')), + rewards: createBaseCumulativeSumPattern4(client, _m(acc, 'rewards')), }; } @@ -3444,90 +3528,6 @@ function createCentsSatsUsdPattern(client, acc) { }; } -/** - * @typedef {Object} CumulativeRawSumPattern4 - * @property {BtcCentsSatsUsdPattern} cumulative - * @property {BtcCentsSatsUsdPattern} raw - * @property {_1m1w1y24hPattern6} sum - */ - -/** - * Create a CumulativeRawSumPattern4 pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CumulativeRawSumPattern4} - */ -function createCumulativeRawSumPattern4(client, acc) { - return { - cumulative: createBtcCentsSatsUsdPattern(client, _m(acc, 'cumulative')), - raw: createBtcCentsSatsUsdPattern(client, acc), - sum: create_1m1w1y24hPattern6(client, _m(acc, 'sum')), - }; -} - -/** - * @typedef {Object} CumulativeRawRelPattern - * @property {MetricPattern1} cumulative - * @property {MetricPattern1} raw - * @property {BpsPercentRatioPattern} relToRcap - */ - -/** - * Create a CumulativeRawRelPattern pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CumulativeRawRelPattern} - */ -function createCumulativeRawRelPattern(client, acc) { - return { - cumulative: createMetricPattern1(client, _m(acc, 'cumulative')), - raw: createMetricPattern1(client, acc), - relToRcap: createBpsPercentRatioPattern(client, _m(acc, 'rel_to_rcap')), - }; -} - -/** - * @typedef {Object} CumulativeRawSumPattern3 - * @property {CentsUsdPattern2} cumulative - * @property {CentsUsdPattern2} raw - * @property {_1m1w1y24hPattern5} sum - */ - -/** - * Create a CumulativeRawSumPattern3 pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CumulativeRawSumPattern3} - */ -function createCumulativeRawSumPattern3(client, acc) { - return { - cumulative: createCentsUsdPattern2(client, _m(acc, 'cumulative')), - raw: createCentsUsdPattern2(client, acc), - sum: create_1m1w1y24hPattern5(client, _m(acc, 'sum')), - }; -} - -/** - * @typedef {Object} CumulativeRawSumPattern2 - * @property {MetricPattern1} cumulative - * @property {MetricPattern1} raw - * @property {_1m1w1y24hPattern} sum - */ - -/** - * Create a CumulativeRawSumPattern2 pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CumulativeRawSumPattern2} - */ -function createCumulativeRawSumPattern2(client, acc) { - return { - cumulative: createMetricPattern1(client, _m(acc, 'cumulative')), - raw: createMetricPattern1(client, acc), - sum: create_1m1w1y24hPattern(client, _m(acc, 'sum')), - }; -} - /** * @typedef {Object} DeltaHalfTotalPattern * @property {ChangeRatePattern2} delta @@ -3572,9 +3572,9 @@ function createGreedNetPainPattern(client, acc) { /** * @typedef {Object} LossNuplProfitPattern - * @property {CumulativeRawSumPattern3} loss + * @property {BaseCumulativeSumPattern3} loss * @property {BpsRatioPattern} nupl - * @property {CumulativeRawSumPattern3} profit + * @property {BaseCumulativeSumPattern3} profit */ /** @@ -3585,9 +3585,9 @@ function createGreedNetPainPattern(client, acc) { */ function createLossNuplProfitPattern(client, acc) { return { - loss: createCumulativeRawSumPattern3(client, _m(acc, 'unrealized_loss')), + loss: createBaseCumulativeSumPattern3(client, _m(acc, 'unrealized_loss')), nupl: createBpsRatioPattern(client, _m(acc, 'nupl')), - profit: createCumulativeRawSumPattern3(client, _m(acc, 'unrealized_profit')), + profit: createBaseCumulativeSumPattern3(client, _m(acc, 'unrealized_profit')), }; } @@ -3615,8 +3615,8 @@ function createLowerPriceUpperPattern(client, acc) { /** * @typedef {Object} RatioValuePattern2 * @property {_1m1w1y24hPattern} ratio - * @property {CumulativeRawSumPattern} valueCreated - * @property {CumulativeRawSumPattern} valueDestroyed + * @property {BaseCumulativeSumPattern} valueCreated + * @property {BaseCumulativeSumPattern} valueDestroyed */ /** @@ -3628,16 +3628,16 @@ function createLowerPriceUpperPattern(client, acc) { function createRatioValuePattern2(client, acc) { return { ratio: create_1m1w1y24hPattern(client, _m(acc, 'asopr')), - valueCreated: createCumulativeRawSumPattern(client, _m(acc, 'adj_value_created')), - valueDestroyed: createCumulativeRawSumPattern(client, _m(acc, 'adj_value_destroyed')), + valueCreated: createBaseCumulativeSumPattern(client, _m(acc, 'adj_value_created')), + valueDestroyed: createBaseCumulativeSumPattern(client, _m(acc, 'adj_value_destroyed')), }; } /** * @typedef {Object} RatioValuePattern * @property {_24hPattern} ratio - * @property {CumulativeRawSumPattern} valueCreated - * @property {CumulativeRawSumPattern} valueDestroyed + * @property {BaseCumulativeSumPattern} valueCreated + * @property {BaseCumulativeSumPattern} valueDestroyed */ /** @@ -3649,8 +3649,8 @@ function createRatioValuePattern2(client, acc) { function createRatioValuePattern(client, acc) { return { ratio: create_24hPattern(client, _m(acc, 'sopr_24h')), - valueCreated: createCumulativeRawSumPattern(client, _m(acc, 'value_created')), - valueDestroyed: createCumulativeRawSumPattern(client, _m(acc, 'value_destroyed')), + valueCreated: createBaseCumulativeSumPattern(client, _m(acc, 'value_created')), + valueDestroyed: createBaseCumulativeSumPattern(client, _m(acc, 'value_destroyed')), }; } @@ -3679,30 +3679,30 @@ function create_6bBlockTxindexPattern(client, acc) { /** * @template T - * @typedef {Object} CumulativeRawSumPattern + * @typedef {Object} BaseCumulativeSumPattern + * @property {MetricPattern1} base * @property {MetricPattern1} cumulative - * @property {MetricPattern1} raw * @property {_1m1w1y24hPattern} sum */ /** - * Create a CumulativeRawSumPattern pattern node + * Create a BaseCumulativeSumPattern pattern node * @template T * @param {BrkClientBase} client * @param {string} acc - Accumulated metric name - * @returns {CumulativeRawSumPattern} + * @returns {BaseCumulativeSumPattern} */ -function createCumulativeRawSumPattern(client, acc) { +function createBaseCumulativeSumPattern(client, acc) { return { + base: createMetricPattern1(client, acc), cumulative: createMetricPattern1(client, _m(acc, 'cumulative')), - raw: createMetricPattern1(client, acc), sum: create_1m1w1y24hPattern(client, _m(acc, 'sum')), }; } /** * @typedef {Object} BlocksDominancePattern - * @property {CumulativeRawSumPattern2} blocksMined + * @property {BaseCumulativeSumPattern2} blocksMined * @property {BpsPercentRatioPattern4} dominance */ @@ -3714,7 +3714,7 @@ function createCumulativeRawSumPattern(client, acc) { */ function createBlocksDominancePattern(client, acc) { return { - blocksMined: createCumulativeRawSumPattern2(client, _m(acc, 'blocks_mined')), + blocksMined: createBaseCumulativeSumPattern2(client, _m(acc, 'blocks_mined')), dominance: createBpsPercentRatioPattern4(client, _m(acc, 'dominance')), }; } @@ -3854,8 +3854,8 @@ function createChangeRatePattern3(client, acc) { /** * @typedef {Object} CoindaysSentPattern - * @property {CumulativeRawSumPattern} coindaysDestroyed - * @property {CumulativeInRawSumPattern} sent + * @property {BaseCumulativeSumPattern} coindaysDestroyed + * @property {BaseCumulativeInSumPattern} sent */ /** @@ -3866,8 +3866,8 @@ function createChangeRatePattern3(client, acc) { */ function createCoindaysSentPattern(client, acc) { return { - coindaysDestroyed: createCumulativeRawSumPattern(client, _m(acc, 'coindays_destroyed')), - sent: createCumulativeInRawSumPattern(client, _m(acc, 'sent')), + coindaysDestroyed: createBaseCumulativeSumPattern(client, _m(acc, 'coindays_destroyed')), + sent: createBaseCumulativeInSumPattern(client, _m(acc, 'sent')), }; } @@ -3987,8 +3987,8 @@ function createSdSmaPattern(client, acc) { /** * @typedef {Object} ValuePattern - * @property {CumulativeRawSumPattern} valueCreated - * @property {CumulativeRawSumPattern} valueDestroyed + * @property {BaseCumulativeSumPattern} valueCreated + * @property {BaseCumulativeSumPattern} valueDestroyed */ /** @@ -3999,8 +3999,8 @@ function createSdSmaPattern(client, acc) { */ function createValuePattern(client, acc) { return { - valueCreated: createCumulativeRawSumPattern(client, _m(acc, 'created')), - valueDestroyed: createCumulativeRawSumPattern(client, _m(acc, 'destroyed')), + valueCreated: createBaseCumulativeSumPattern(client, _m(acc, 'created')), + valueDestroyed: createBaseCumulativeSumPattern(client, _m(acc, 'destroyed')), }; } @@ -4088,13 +4088,14 @@ function createUnspentPattern(client, acc) { * @property {MetricsTree_Blocks_Lookback} lookback * @property {_1m1w1y24hHeightPattern} interval * @property {MetricsTree_Blocks_Halving} halving - * @property {AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern} vbytes + * @property {AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern} vbytes * @property {MetricsTree_Blocks_Fullness} fullness */ /** * @typedef {Object} MetricsTree_Blocks_Difficulty - * @property {MetricPattern1} raw + * @property {MetricPattern18} raw + * @property {MetricPattern2} base * @property {MetricPattern1} asHash * @property {BpsPercentRatioPattern2} adjustment * @property {MetricPattern1} epoch @@ -4142,7 +4143,7 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Blocks_Count * @property {MetricPattern1} target - * @property {CumulativeRawSumPattern2} total + * @property {BaseCumulativeSumPattern2} total */ /** @@ -4232,7 +4233,7 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Transactions_Count - * @property {AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern} total + * @property {AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern} total * @property {MetricPattern19} isCoinbase */ @@ -4252,15 +4253,15 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Transactions_Versions - * @property {CumulativeRawSumPattern} v1 - * @property {CumulativeRawSumPattern} v2 - * @property {CumulativeRawSumPattern} v3 + * @property {BaseCumulativeSumPattern} v1 + * @property {BaseCumulativeSumPattern} v2 + * @property {BaseCumulativeSumPattern} v3 */ /** * @typedef {Object} MetricsTree_Transactions_Volume - * @property {CumulativeRawSumPattern4} sentSum - * @property {CumulativeRawSumPattern4} receivedSum + * @property {BaseCumulativeSumPattern4} sentSum + * @property {BaseCumulativeSumPattern4} receivedSum * @property {MetricPattern1} txPerSec * @property {MetricPattern1} outputsPerSec * @property {MetricPattern1} inputsPerSec @@ -4423,15 +4424,15 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Addresses_New - * @property {CumulativeRawSumPattern} all - * @property {CumulativeRawSumPattern} p2pk65 - * @property {CumulativeRawSumPattern} p2pk33 - * @property {CumulativeRawSumPattern} p2pkh - * @property {CumulativeRawSumPattern} p2sh - * @property {CumulativeRawSumPattern} p2wpkh - * @property {CumulativeRawSumPattern} p2wsh - * @property {CumulativeRawSumPattern} p2tr - * @property {CumulativeRawSumPattern} p2a + * @property {BaseCumulativeSumPattern} all + * @property {BaseCumulativeSumPattern} p2pk65 + * @property {BaseCumulativeSumPattern} p2pk33 + * @property {BaseCumulativeSumPattern} p2pkh + * @property {BaseCumulativeSumPattern} p2sh + * @property {BaseCumulativeSumPattern} p2wpkh + * @property {BaseCumulativeSumPattern} p2wsh + * @property {BaseCumulativeSumPattern} p2tr + * @property {BaseCumulativeSumPattern} p2a */ /** @@ -4489,19 +4490,19 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Scripts_Count - * @property {CumulativeRawSumPattern} p2a - * @property {CumulativeRawSumPattern} p2ms - * @property {CumulativeRawSumPattern} p2pk33 - * @property {CumulativeRawSumPattern} p2pk65 - * @property {CumulativeRawSumPattern} p2pkh - * @property {CumulativeRawSumPattern} p2sh - * @property {CumulativeRawSumPattern} p2tr - * @property {CumulativeRawSumPattern} p2wpkh - * @property {CumulativeRawSumPattern} p2wsh - * @property {CumulativeRawSumPattern} opreturn - * @property {CumulativeRawSumPattern} emptyoutput - * @property {CumulativeRawSumPattern} unknownoutput - * @property {CumulativeRawSumPattern} segwit + * @property {BaseCumulativeSumPattern} p2a + * @property {BaseCumulativeSumPattern} p2ms + * @property {BaseCumulativeSumPattern} p2pk33 + * @property {BaseCumulativeSumPattern} p2pk65 + * @property {BaseCumulativeSumPattern} p2pkh + * @property {BaseCumulativeSumPattern} p2sh + * @property {BaseCumulativeSumPattern} p2tr + * @property {BaseCumulativeSumPattern} p2wpkh + * @property {BaseCumulativeSumPattern} p2wsh + * @property {BaseCumulativeSumPattern} opreturn + * @property {BaseCumulativeSumPattern} emptyoutput + * @property {BaseCumulativeSumPattern} unknownoutput + * @property {BaseCumulativeSumPattern} segwit */ /** @@ -4529,10 +4530,10 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Mining_Rewards - * @property {CumulativeRawSumPattern4} coinbase + * @property {BaseCumulativeSumPattern4} coinbase * @property {MetricsTree_Mining_Rewards_Subsidy} subsidy * @property {MetricsTree_Mining_Rewards_Fees} fees - * @property {CumulativeRawSumPattern4} unclaimed + * @property {BaseCumulativeSumPattern4} unclaimed */ /** @@ -4573,7 +4574,7 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Mining_Hashrate_Rate - * @property {MetricPattern1} raw + * @property {MetricPattern1} base * @property {MetricsTree_Mining_Hashrate_Rate_Sma} sma * @property {MetricPattern1} ath * @property {BpsPercentRatioPattern5} drawdown @@ -4601,8 +4602,8 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Cointime_Activity - * @property {CumulativeRawSumPattern} coinblocksCreated - * @property {CumulativeRawSumPattern} coinblocksStored + * @property {BaseCumulativeSumPattern} coinblocksCreated + * @property {BaseCumulativeSumPattern} coinblocksStored * @property {MetricPattern1} liveliness * @property {MetricPattern1} vaultedness * @property {MetricPattern1} ratio @@ -4616,10 +4617,10 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Cointime_Value - * @property {CumulativeRawSumPattern} destroyed - * @property {CumulativeRawSumPattern} created - * @property {CumulativeRawSumPattern} stored - * @property {CumulativeRawSumPattern} vocdd + * @property {BaseCumulativeSumPattern} destroyed + * @property {BaseCumulativeSumPattern} created + * @property {BaseCumulativeSumPattern} stored + * @property {BaseCumulativeSumPattern} vocdd */ /** @@ -4661,7 +4662,7 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Cointime_CoinblocksDestroyed - * @property {MetricPattern1} raw + * @property {MetricPattern1} base * @property {MetricPattern1} cumulative */ @@ -5532,8 +5533,8 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Supply_Burned - * @property {CumulativeRawSumPattern4} opreturn - * @property {CumulativeRawSumPattern4} unspendable + * @property {BaseCumulativeSumPattern4} opreturn + * @property {BaseCumulativeSumPattern4} unspendable */ /** @@ -5599,7 +5600,7 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Cohorts_Utxo_All_Unrealized_Loss * @property {MetricPattern1} negative - * @property {CentsUsdPattern2} raw + * @property {CentsUsdPattern2} base * @property {CentsUsdPattern2} cumulative * @property {_1m1w1y24hPattern5} sum * @property {BpsPercentRatioPattern4} relToMcap @@ -5615,7 +5616,7 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Cohorts_Utxo_All_Unrealized_Profit - * @property {CentsUsdPattern2} raw + * @property {CentsUsdPattern2} base * @property {CentsUsdPattern2} cumulative * @property {_1m1w1y24hPattern5} sum * @property {BpsPercentRatioPattern4} relToMcap @@ -5644,13 +5645,13 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Cohorts_Utxo_Lth_Realized - * @property {CumulativeDistributionRawRelSumValuePattern} profit - * @property {CapitulationCumulativeNegativeRawRelSumValuePattern} loss - * @property {CumulativeRawSumPattern3} grossPnl + * @property {BaseCumulativeDistributionRelSumValuePattern} profit + * @property {BaseCapitulationCumulativeNegativeRelSumValuePattern} loss + * @property {BaseCumulativeSumPattern3} grossPnl * @property {MetricsTree_Cohorts_Utxo_Lth_Realized_SellSideRiskRatio} sellSideRiskRatio - * @property {ChangeCumulativeDeltaRawRelSumPattern} netPnl + * @property {BaseChangeCumulativeDeltaRelSumPattern} netPnl * @property {MetricsTree_Cohorts_Utxo_Lth_Realized_Sopr} sopr - * @property {CumulativeRawRelPattern} peakRegret + * @property {BaseCumulativeRelPattern} peakRegret * @property {LowerPriceUpperPattern} investor * @property {_1m1w1y24hPattern} profitToLossRatio * @property {CentsDeltaRelUsdPattern} cap @@ -5669,8 +5670,8 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Cohorts_Utxo_Lth_Realized_Sopr * @property {_1m1w1y24hPattern} ratio - * @property {CumulativeRawSumPattern} valueCreated - * @property {CumulativeRawSumPattern} valueDestroyed + * @property {BaseCumulativeSumPattern} valueCreated + * @property {BaseCumulativeSumPattern} valueDestroyed */ /** @@ -6942,7 +6943,8 @@ class BrkClient extends BrkClientBase { blocks: { blockhash: createMetricPattern18(this, 'blockhash'), difficulty: { - raw: createMetricPattern1(this, 'difficulty'), + raw: createMetricPattern18(this, 'difficulty'), + base: createMetricPattern2(this, 'difficulty'), asHash: createMetricPattern1(this, 'difficulty_as_hash'), adjustment: createBpsPercentRatioPattern2(this, 'difficulty_adjustment'), epoch: createMetricPattern1(this, 'difficulty_epoch'), @@ -6982,7 +6984,7 @@ class BrkClient extends BrkClientBase { }, count: { target: createMetricPattern1(this, 'block_count_target'), - total: createCumulativeRawSumPattern2(this, 'block_count'), + total: createBaseCumulativeSumPattern2(this, 'block_count'), }, lookback: { _1h: createMetricPattern18(this, 'height_1h_ago'), @@ -7035,7 +7037,7 @@ class BrkClient extends BrkClientBase { blocksBeforeNext: createMetricPattern1(this, 'blocks_before_next_halving'), daysBeforeNext: createMetricPattern1(this, 'days_before_next_halving'), }, - vbytes: createAverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern(this, 'block_vbytes'), + vbytes: createAverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'block_vbytes'), fullness: { bps: create_1m1w1y24hHeightPattern(this, 'block_fullness_bps'), ratio: createMetricPattern1(this, 'block_fullness_ratio'), @@ -7056,7 +7058,7 @@ class BrkClient extends BrkClientBase { firstTxoutindex: createMetricPattern19(this, 'first_txoutindex'), }, count: { - total: createAverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern(this, 'tx_count'), + total: createAverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern(this, 'tx_count'), isCoinbase: createMetricPattern19(this, 'is_coinbase'), }, size: { @@ -7070,13 +7072,13 @@ class BrkClient extends BrkClientBase { feeRate: create_6bBlockTxindexPattern(this, 'fee_rate'), }, versions: { - v1: createCumulativeRawSumPattern(this, 'tx_v1'), - v2: createCumulativeRawSumPattern(this, 'tx_v2'), - v3: createCumulativeRawSumPattern(this, 'tx_v3'), + v1: createBaseCumulativeSumPattern(this, 'tx_v1'), + v2: createBaseCumulativeSumPattern(this, 'tx_v2'), + v3: createBaseCumulativeSumPattern(this, 'tx_v3'), }, volume: { - sentSum: createCumulativeRawSumPattern4(this, 'sent_sum'), - receivedSum: createCumulativeRawSumPattern4(this, 'received_sum'), + sentSum: createBaseCumulativeSumPattern4(this, 'sent_sum'), + receivedSum: createBaseCumulativeSumPattern4(this, 'received_sum'), txPerSec: createMetricPattern1(this, 'tx_per_sec'), outputsPerSec: createMetricPattern1(this, 'outputs_per_sec'), inputsPerSec: createMetricPattern1(this, 'inputs_per_sec'), @@ -7178,15 +7180,15 @@ class BrkClient extends BrkClientBase { }, total: createAllP2aP2pk33P2pk65P2pkhP2shP2trP2wpkhP2wshPattern3(this, 'total_address_count'), new: { - all: createCumulativeRawSumPattern(this, 'new_address_count'), - p2pk65: createCumulativeRawSumPattern(this, 'p2pk65_new_address_count'), - p2pk33: createCumulativeRawSumPattern(this, 'p2pk33_new_address_count'), - p2pkh: createCumulativeRawSumPattern(this, 'p2pkh_new_address_count'), - p2sh: createCumulativeRawSumPattern(this, 'p2sh_new_address_count'), - p2wpkh: createCumulativeRawSumPattern(this, 'p2wpkh_new_address_count'), - p2wsh: createCumulativeRawSumPattern(this, 'p2wsh_new_address_count'), - p2tr: createCumulativeRawSumPattern(this, 'p2tr_new_address_count'), - p2a: createCumulativeRawSumPattern(this, 'p2a_new_address_count'), + all: createBaseCumulativeSumPattern(this, 'new_address_count'), + p2pk65: createBaseCumulativeSumPattern(this, 'p2pk65_new_address_count'), + p2pk33: createBaseCumulativeSumPattern(this, 'p2pk33_new_address_count'), + p2pkh: createBaseCumulativeSumPattern(this, 'p2pkh_new_address_count'), + p2sh: createBaseCumulativeSumPattern(this, 'p2sh_new_address_count'), + p2wpkh: createBaseCumulativeSumPattern(this, 'p2wpkh_new_address_count'), + p2wsh: createBaseCumulativeSumPattern(this, 'p2wsh_new_address_count'), + p2tr: createBaseCumulativeSumPattern(this, 'p2tr_new_address_count'), + p2a: createBaseCumulativeSumPattern(this, 'p2a_new_address_count'), }, delta: { all: createChangeRatePattern(this, 'address_count'), @@ -7220,19 +7222,19 @@ class BrkClient extends BrkClientBase { }, }, count: { - p2a: createCumulativeRawSumPattern(this, 'p2a_count'), - p2ms: createCumulativeRawSumPattern(this, 'p2ms_count'), - p2pk33: createCumulativeRawSumPattern(this, 'p2pk33_count'), - p2pk65: createCumulativeRawSumPattern(this, 'p2pk65_count'), - p2pkh: createCumulativeRawSumPattern(this, 'p2pkh_count'), - p2sh: createCumulativeRawSumPattern(this, 'p2sh_count'), - p2tr: createCumulativeRawSumPattern(this, 'p2tr_count'), - p2wpkh: createCumulativeRawSumPattern(this, 'p2wpkh_count'), - p2wsh: createCumulativeRawSumPattern(this, 'p2wsh_count'), - opreturn: createCumulativeRawSumPattern(this, 'opreturn_count'), - emptyoutput: createCumulativeRawSumPattern(this, 'emptyoutput_count'), - unknownoutput: createCumulativeRawSumPattern(this, 'unknownoutput_count'), - segwit: createCumulativeRawSumPattern(this, 'segwit_count'), + p2a: createBaseCumulativeSumPattern(this, 'p2a_count'), + p2ms: createBaseCumulativeSumPattern(this, 'p2ms_count'), + p2pk33: createBaseCumulativeSumPattern(this, 'p2pk33_count'), + p2pk65: createBaseCumulativeSumPattern(this, 'p2pk65_count'), + p2pkh: createBaseCumulativeSumPattern(this, 'p2pkh_count'), + p2sh: createBaseCumulativeSumPattern(this, 'p2sh_count'), + p2tr: createBaseCumulativeSumPattern(this, 'p2tr_count'), + p2wpkh: createBaseCumulativeSumPattern(this, 'p2wpkh_count'), + p2wsh: createBaseCumulativeSumPattern(this, 'p2wsh_count'), + opreturn: createBaseCumulativeSumPattern(this, 'opreturn_count'), + emptyoutput: createBaseCumulativeSumPattern(this, 'emptyoutput_count'), + unknownoutput: createBaseCumulativeSumPattern(this, 'unknownoutput_count'), + segwit: createBaseCumulativeSumPattern(this, 'segwit_count'), }, value: { opreturn: { @@ -7247,7 +7249,7 @@ class BrkClient extends BrkClientBase { }, mining: { rewards: { - coinbase: createCumulativeRawSumPattern4(this, 'coinbase'), + coinbase: createBaseCumulativeSumPattern4(this, 'coinbase'), subsidy: { base: createBtcCentsSatsUsdPattern(this, 'subsidy'), cumulative: createBtcCentsSatsUsdPattern(this, 'subsidy_cumulative'), @@ -7270,11 +7272,11 @@ class BrkClient extends BrkClientBase { _1y: createBpsRatioPattern2(this, 'fee_ratio_multiple_1y'), }, }, - unclaimed: createCumulativeRawSumPattern4(this, 'unclaimed_rewards'), + unclaimed: createBaseCumulativeSumPattern4(this, 'unclaimed_rewards'), }, hashrate: { rate: { - raw: createMetricPattern1(this, 'hash_rate'), + base: createMetricPattern1(this, 'hash_rate'), sma: { _1w: createMetricPattern1(this, 'hash_rate_sma_1w'), _1m: createMetricPattern1(this, 'hash_rate_sma_1m'), @@ -7290,8 +7292,8 @@ class BrkClient extends BrkClientBase { }, cointime: { activity: { - coinblocksCreated: createCumulativeRawSumPattern(this, 'coinblocks_created'), - coinblocksStored: createCumulativeRawSumPattern(this, 'coinblocks_stored'), + coinblocksCreated: createBaseCumulativeSumPattern(this, 'coinblocks_created'), + coinblocksStored: createBaseCumulativeSumPattern(this, 'coinblocks_stored'), liveliness: createMetricPattern1(this, 'liveliness'), vaultedness: createMetricPattern1(this, 'vaultedness'), ratio: createMetricPattern1(this, 'activity_to_vaultedness_ratio'), @@ -7301,10 +7303,10 @@ class BrkClient extends BrkClientBase { active: createBtcCentsSatsUsdPattern(this, 'active_supply'), }, value: { - destroyed: createCumulativeRawSumPattern(this, 'cointime_value_destroyed'), - created: createCumulativeRawSumPattern(this, 'cointime_value_created'), - stored: createCumulativeRawSumPattern(this, 'cointime_value_stored'), - vocdd: createCumulativeRawSumPattern(this, 'vocdd'), + destroyed: createBaseCumulativeSumPattern(this, 'cointime_value_destroyed'), + created: createBaseCumulativeSumPattern(this, 'cointime_value_created'), + stored: createBaseCumulativeSumPattern(this, 'cointime_value_stored'), + vocdd: createBaseCumulativeSumPattern(this, 'vocdd'), }, cap: { thermo: createCentsUsdPattern2(this, 'thermo_cap'), @@ -7336,7 +7338,7 @@ class BrkClient extends BrkClientBase { hodlBank: createMetricPattern18(this, 'hodl_bank'), }, coinblocksDestroyed: { - raw: createMetricPattern1(this, 'coinblocks_destroyed'), + base: createMetricPattern1(this, 'coinblocks_destroyed'), cumulative: createMetricPattern1(this, 'coinblocks_destroyed_cumulative'), }, }, @@ -7971,8 +7973,8 @@ class BrkClient extends BrkClientBase { supply: { circulating: createBtcCentsSatsUsdPattern(this, 'circulating_supply'), burned: { - opreturn: createCumulativeRawSumPattern4(this, 'opreturn_supply'), - unspendable: createCumulativeRawSumPattern4(this, 'unspendable_supply'), + opreturn: createBaseCumulativeSumPattern4(this, 'opreturn_supply'), + unspendable: createBaseCumulativeSumPattern4(this, 'unspendable_supply'), }, inflationRate: createBpsPercentRatioPattern2(this, 'inflation_rate'), velocity: { @@ -8004,7 +8006,7 @@ class BrkClient extends BrkClientBase { sentiment: createGreedNetPainPattern(this, ''), loss: { negative: createMetricPattern1(this, 'neg_unrealized_loss'), - raw: createCentsUsdPattern2(this, 'unrealized_loss'), + base: createCentsUsdPattern2(this, 'unrealized_loss'), cumulative: createCentsUsdPattern2(this, 'unrealized_loss_cumulative'), sum: create_1m1w1y24hPattern5(this, 'unrealized_loss_sum'), relToMcap: createBpsPercentRatioPattern4(this, 'unrealized_loss_rel_to_mcap'), @@ -8016,7 +8018,7 @@ class BrkClient extends BrkClientBase { relToOwnGross: createBpsPercentRatioPattern2(this, 'net_unrealized_pnl_rel_to_own_gross_pnl'), }, profit: { - raw: createCentsUsdPattern2(this, 'unrealized_profit'), + base: createCentsUsdPattern2(this, 'unrealized_profit'), cumulative: createCentsUsdPattern2(this, 'unrealized_profit_cumulative'), sum: create_1m1w1y24hPattern5(this, 'unrealized_profit_sum'), relToMcap: createBpsPercentRatioPattern4(this, 'unrealized_profit_rel_to_mcap'), @@ -8038,22 +8040,22 @@ class BrkClient extends BrkClientBase { outputs: createUnspentPattern(this, 'lth_utxo_count'), activity: createCoindaysCoinyearsDormancySentVelocityPattern(this, 'lth'), realized: { - profit: createCumulativeDistributionRawRelSumValuePattern(this, 'lth'), - loss: createCapitulationCumulativeNegativeRawRelSumValuePattern(this, 'lth'), - grossPnl: createCumulativeRawSumPattern3(this, 'lth_realized_gross_pnl'), + profit: createBaseCumulativeDistributionRelSumValuePattern(this, 'lth'), + loss: createBaseCapitulationCumulativeNegativeRelSumValuePattern(this, 'lth'), + grossPnl: createBaseCumulativeSumPattern3(this, 'lth_realized_gross_pnl'), sellSideRiskRatio: { _24h: createBpsPercentRatioPattern(this, 'lth_sell_side_risk_ratio_24h'), _1w: createBpsPercentRatioPattern(this, 'lth_sell_side_risk_ratio_1w'), _1m: createBpsPercentRatioPattern(this, 'lth_sell_side_risk_ratio_1m'), _1y: createBpsPercentRatioPattern(this, 'lth_sell_side_risk_ratio_1y'), }, - netPnl: createChangeCumulativeDeltaRawRelSumPattern(this, 'lth_net'), + netPnl: createBaseChangeCumulativeDeltaRelSumPattern(this, 'lth_net'), sopr: { ratio: create_1m1w1y24hPattern(this, 'lth_sopr'), - valueCreated: createCumulativeRawSumPattern(this, 'lth_value_created'), - valueDestroyed: createCumulativeRawSumPattern(this, 'lth_value_destroyed'), + valueCreated: createBaseCumulativeSumPattern(this, 'lth_value_created'), + valueDestroyed: createBaseCumulativeSumPattern(this, 'lth_value_destroyed'), }, - peakRegret: createCumulativeRawRelPattern(this, 'lth_realized_peak_regret'), + peakRegret: createBaseCumulativeRelPattern(this, 'lth_realized_peak_regret'), investor: createLowerPriceUpperPattern(this, 'lth'), profitToLossRatio: create_1m1w1y24hPattern(this, 'lth_realized_profit_to_loss_ratio'), cap: createCentsDeltaRelUsdPattern(this, 'lth_realized_cap'), diff --git a/packages/brk_client/brk_client/__init__.py b/packages/brk_client/brk_client/__init__.py index 25b705223..cc106045e 100644 --- a/packages/brk_client/brk_client/__init__.py +++ b/packages/brk_client/brk_client/__init__.py @@ -2208,14 +2208,14 @@ class CapGrossInvestorLossMvrvNetPeakPriceProfitSellSoprPattern: def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" self.cap: CentsDeltaRelUsdPattern = CentsDeltaRelUsdPattern(client, _m(acc, 'realized_cap')) - self.gross_pnl: CumulativeRawSumPattern3 = CumulativeRawSumPattern3(client, _m(acc, 'realized_gross_pnl')) + self.gross_pnl: BaseCumulativeSumPattern3 = BaseCumulativeSumPattern3(client, _m(acc, 'realized_gross_pnl')) self.investor: LowerPriceUpperPattern = LowerPriceUpperPattern(client, acc) - self.loss: CapitulationCumulativeNegativeRawRelSumValuePattern = CapitulationCumulativeNegativeRawRelSumValuePattern(client, acc) + self.loss: BaseCapitulationCumulativeNegativeRelSumValuePattern = BaseCapitulationCumulativeNegativeRelSumValuePattern(client, acc) self.mvrv: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'mvrv')) - self.net_pnl: ChangeCumulativeDeltaRawRelSumPattern = ChangeCumulativeDeltaRawRelSumPattern(client, _m(acc, 'net')) - self.peak_regret: CumulativeRawRelPattern = CumulativeRawRelPattern(client, _m(acc, 'realized_peak_regret')) + self.net_pnl: BaseChangeCumulativeDeltaRelSumPattern = BaseChangeCumulativeDeltaRelSumPattern(client, _m(acc, 'net')) + self.peak_regret: BaseCumulativeRelPattern = BaseCumulativeRelPattern(client, _m(acc, 'realized_peak_regret')) self.price: BpsCentsPercentilesRatioSatsSmaStdUsdPattern = BpsCentsPercentilesRatioSatsSmaStdUsdPattern(client, _m(acc, 'realized_price')) - self.profit: CumulativeDistributionRawRelSumValuePattern = CumulativeDistributionRawRelSumValuePattern(client, acc) + self.profit: BaseCumulativeDistributionRelSumValuePattern = BaseCumulativeDistributionRelSumValuePattern(client, acc) self.profit_to_loss_ratio: _1m1w1y24hPattern[StoredF64] = _1m1w1y24hPattern(client, _m(acc, 'realized_profit_to_loss_ratio')) self.sell_side_risk_ratio: _1m1w1y24hPattern2 = _1m1w1y24hPattern2(client, _m(acc, 'sell_side_risk_ratio')) self.sopr: AdjustedRatioValuePattern = AdjustedRatioValuePattern(client, acc) @@ -2237,12 +2237,13 @@ class AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RollingSumPattern: self.rolling: AverageMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, acc) self.sum: MetricPattern18[StoredU64] = MetricPattern18(client, _m(acc, 'sum')) -class AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern: +class AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern: """Pattern struct for repeated tree structure.""" def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" self.average: _1m1w1y24hPattern[StoredU64] = _1m1w1y24hPattern(client, _m(acc, 'average')) + self.base: MetricPattern1[StoredU64] = MetricPattern1(client, acc) self.cumulative: MetricPattern1[StoredU64] = MetricPattern1(client, _m(acc, 'cumulative')) self.max: _1m1w1y24hPattern[StoredU64] = _1m1w1y24hPattern(client, _m(acc, 'max')) self.median: _1m1w1y24hPattern[StoredU64] = _1m1w1y24hPattern(client, _m(acc, 'median')) @@ -2251,7 +2252,6 @@ class AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern: self.pct25: _1m1w1y24hPattern[StoredU64] = _1m1w1y24hPattern(client, _m(acc, 'pct25')) self.pct75: _1m1w1y24hPattern[StoredU64] = _1m1w1y24hPattern(client, _m(acc, 'pct75')) self.pct90: _1m1w1y24hPattern[StoredU64] = _1m1w1y24hPattern(client, _m(acc, 'pct90')) - self.raw: MetricPattern1[StoredU64] = MetricPattern1(client, acc) self.sum: _1m1w1y24hPattern[StoredU64] = _1m1w1y24hPattern(client, _m(acc, 'sum')) class AverageGainsLossesRsiStochPattern: @@ -2314,6 +2314,20 @@ class AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern: self.pct75: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'pct75')) self.pct90: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'pct90')) +class BaseCapitulationCumulativeNegativeRelSumValuePattern: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'realized_loss')) + self.capitulation_flow: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'capitulation_flow')) + self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'realized_loss_cumulative')) + self.negative: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'neg_realized_loss')) + self.rel_to_rcap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_loss_rel_to_rcap')) + self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'realized_loss_sum')) + self.value_created: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'loss_value_created')) + self.value_destroyed: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'loss_value_destroyed')) + class BpsCentsPercentilesRatioSatsSmaStdUsdPattern: """Pattern struct for repeated tree structure.""" @@ -2328,20 +2342,6 @@ class BpsCentsPercentilesRatioSatsSmaStdUsdPattern: self.std_dev: _1y2y4yAllPattern = _1y2y4yAllPattern(client, _m(acc, 'ratio')) self.usd: MetricPattern1[Dollars] = MetricPattern1(client, acc) -class CapitulationCumulativeNegativeRawRelSumValuePattern: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.capitulation_flow: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'capitulation_flow')) - self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'realized_loss_cumulative')) - self.negative: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'neg_realized_loss')) - self.raw: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'realized_loss')) - self.rel_to_rcap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_loss_rel_to_rcap')) - self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'realized_loss_sum')) - self.value_created: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'loss_value_created')) - self.value_destroyed: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'loss_value_destroyed')) - class AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern2(Generic[T]): """Pattern struct for repeated tree structure.""" @@ -2382,45 +2382,45 @@ class _1m1w1y24hBpsPercentRatioPattern: self.percent: MetricPattern1[StoredF32] = MetricPattern1(client, acc) self.ratio: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'ratio')) +class BaseCumulativeDistributionRelSumValuePattern: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'realized_profit')) + self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'realized_profit_cumulative')) + self.distribution_flow: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'distribution_flow')) + self.rel_to_rcap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_profit_rel_to_rcap')) + self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'realized_profit_sum')) + self.value_created: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'profit_value_created')) + self.value_destroyed: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'profit_value_destroyed')) + +class BaseCumulativeNegativeRelSumPattern2: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'unrealized_loss')) + self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'unrealized_loss_cumulative')) + self.negative: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'neg_unrealized_loss')) + self.rel_to_mcap: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, _m(acc, 'unrealized_loss_rel_to_mcap')) + self.rel_to_own_gross: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, _m(acc, 'unrealized_loss_rel_to_own_gross_pnl')) + self.rel_to_own_mcap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'unrealized_loss_rel_to_own_mcap')) + self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'unrealized_loss_sum')) + class CapLossMvrvNetPriceProfitSoprPattern: """Pattern struct for repeated tree structure.""" def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" self.cap: CentsDeltaUsdPattern = CentsDeltaUsdPattern(client, _m(acc, 'realized_cap')) - self.loss: CumulativeNegativeRawSumPattern = CumulativeNegativeRawSumPattern(client, acc) + self.loss: BaseCumulativeNegativeSumPattern = BaseCumulativeNegativeSumPattern(client, acc) self.mvrv: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'mvrv')) - self.net_pnl: CumulativeDeltaRawSumPattern = CumulativeDeltaRawSumPattern(client, _m(acc, 'net_realized_pnl')) + self.net_pnl: BaseCumulativeDeltaSumPattern = BaseCumulativeDeltaSumPattern(client, _m(acc, 'net_realized_pnl')) self.price: BpsCentsRatioSatsUsdPattern = BpsCentsRatioSatsUsdPattern(client, _m(acc, 'realized_price')) - self.profit: CumulativeRawSumPattern3 = CumulativeRawSumPattern3(client, _m(acc, 'realized_profit')) + self.profit: BaseCumulativeSumPattern3 = BaseCumulativeSumPattern3(client, _m(acc, 'realized_profit')) self.sopr: RatioValuePattern = RatioValuePattern(client, acc) -class CumulativeDistributionRawRelSumValuePattern: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'realized_profit_cumulative')) - self.distribution_flow: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'distribution_flow')) - self.raw: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'realized_profit')) - self.rel_to_rcap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_profit_rel_to_rcap')) - self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'realized_profit_sum')) - self.value_created: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'profit_value_created')) - self.value_destroyed: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'profit_value_destroyed')) - -class CumulativeNegativeRawRelSumPattern2: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'unrealized_loss_cumulative')) - self.negative: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'neg_unrealized_loss')) - self.raw: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'unrealized_loss')) - self.rel_to_mcap: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, _m(acc, 'unrealized_loss_rel_to_mcap')) - self.rel_to_own_gross: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, _m(acc, 'unrealized_loss_rel_to_own_gross_pnl')) - self.rel_to_own_mcap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'unrealized_loss_rel_to_own_mcap')) - self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'unrealized_loss_sum')) - class GrossInvestedLossNetNuplProfitSentimentPattern2: """Pattern struct for repeated tree structure.""" @@ -2428,10 +2428,10 @@ class GrossInvestedLossNetNuplProfitSentimentPattern2: """Create pattern node with accumulated metric name.""" self.gross_pnl: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'unrealized_gross_pnl')) self.invested_capital: InPattern = InPattern(client, _m(acc, 'invested_capital_in')) - self.loss: CumulativeNegativeRawRelSumPattern2 = CumulativeNegativeRawRelSumPattern2(client, acc) + self.loss: BaseCumulativeNegativeRelSumPattern2 = BaseCumulativeNegativeRelSumPattern2(client, acc) self.net_pnl: CentsRelUsdPattern2 = CentsRelUsdPattern2(client, _m(acc, 'net_unrealized_pnl')) self.nupl: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'nupl')) - self.profit: CumulativeRawRelSumPattern2 = CumulativeRawRelSumPattern2(client, _m(acc, 'unrealized_profit')) + self.profit: BaseCumulativeRelSumPattern2 = BaseCumulativeRelSumPattern2(client, _m(acc, 'unrealized_profit')) self.sentiment: GreedNetPainPattern = GreedNetPainPattern(client, acc) class _1m1w1y2y4yAllPattern: @@ -2446,6 +2446,30 @@ class _1m1w1y2y4yAllPattern: self._4y: BpsRatioPattern2 = BpsRatioPattern2(client, _m(acc, '4y')) self.all: BpsRatioPattern2 = BpsRatioPattern2(client, _m(acc, 'all')) +class BaseChangeCumulativeDeltaRelSumPattern: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'realized_pnl')) + self.change_1m: RelPattern = RelPattern(client, _m(acc, 'pnl_change_1m_rel_to')) + self.cumulative: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'realized_pnl_cumulative')) + self.delta: ChangeRatePattern3 = ChangeRatePattern3(client, _m(acc, 'realized_pnl_delta')) + self.rel_to_rcap: BpsPercentRatioPattern2 = BpsPercentRatioPattern2(client, _m(acc, 'realized_pnl_rel_to_rcap')) + self.sum: _1m1w1y24hPattern4 = _1m1w1y24hPattern4(client, _m(acc, 'realized_pnl_sum')) + +class BaseCumulativeRelSumPattern2: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: CentsUsdPattern2 = CentsUsdPattern2(client, acc) + self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'cumulative')) + self.rel_to_mcap: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, _m(acc, 'rel_to_mcap')) + self.rel_to_own_gross: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, _m(acc, 'rel_to_own_gross_pnl')) + self.rel_to_own_mcap: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, _m(acc, 'rel_to_own_mcap')) + self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'sum')) + class BpsCentsPercentilesRatioSatsUsdPattern: """Pattern struct for repeated tree structure.""" @@ -2476,36 +2500,12 @@ class CapLossMvrvPriceProfitSoprPattern: def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" self.cap: CentsDeltaUsdPattern = CentsDeltaUsdPattern(client, _m(acc, 'realized_cap')) - self.loss: CumulativeRawSumPattern3 = CumulativeRawSumPattern3(client, _m(acc, 'realized_loss')) + self.loss: BaseCumulativeSumPattern3 = BaseCumulativeSumPattern3(client, _m(acc, 'realized_loss')) self.mvrv: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'mvrv')) self.price: BpsCentsRatioSatsUsdPattern = BpsCentsRatioSatsUsdPattern(client, _m(acc, 'realized_price')) - self.profit: CumulativeRawSumPattern3 = CumulativeRawSumPattern3(client, _m(acc, 'realized_profit')) + self.profit: BaseCumulativeSumPattern3 = BaseCumulativeSumPattern3(client, _m(acc, 'realized_profit')) self.sopr: ValuePattern = ValuePattern(client, _m(acc, 'value')) -class ChangeCumulativeDeltaRawRelSumPattern: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.change_1m: RelPattern = RelPattern(client, _m(acc, 'pnl_change_1m_rel_to')) - self.cumulative: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'realized_pnl_cumulative')) - self.delta: ChangeRatePattern3 = ChangeRatePattern3(client, _m(acc, 'realized_pnl_delta')) - self.raw: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'realized_pnl')) - self.rel_to_rcap: BpsPercentRatioPattern2 = BpsPercentRatioPattern2(client, _m(acc, 'realized_pnl_rel_to_rcap')) - self.sum: _1m1w1y24hPattern4 = _1m1w1y24hPattern4(client, _m(acc, 'realized_pnl_sum')) - -class CumulativeRawRelSumPattern2: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'cumulative')) - self.raw: CentsUsdPattern2 = CentsUsdPattern2(client, acc) - self.rel_to_mcap: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, _m(acc, 'rel_to_mcap')) - self.rel_to_own_gross: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, _m(acc, 'rel_to_own_gross_pnl')) - self.rel_to_own_mcap: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, _m(acc, 'rel_to_own_mcap')) - self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'sum')) - class DeltaHalfInRelTotalPattern: """Pattern struct for repeated tree structure.""" @@ -2564,6 +2564,17 @@ class AddressOutputsRealizedSupplyUnrealizedPattern: self.supply: DeltaHalfTotalPattern = DeltaHalfTotalPattern(client, _m(acc, 'supply')) self.unrealized: NuplPattern = NuplPattern(client, _m(acc, 'nupl')) +class BaseCumulativeInSumPattern: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: MetricPattern1[Sats] = MetricPattern1(client, acc) + self.cumulative: MetricPattern1[Sats] = MetricPattern1(client, _m(acc, 'cumulative')) + self.in_loss: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, _m(acc, 'in_loss')) + self.in_profit: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, _m(acc, 'in_profit')) + self.sum: _1m1w1y24hPattern[Sats] = _1m1w1y24hPattern(client, _m(acc, 'sum')) + class BpsCentsRatioSatsUsdPattern: """Pattern struct for repeated tree structure.""" @@ -2602,23 +2613,12 @@ class CoindaysCoinyearsDormancySentVelocityPattern: def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" - self.coindays_destroyed: CumulativeRawSumPattern[StoredF64] = CumulativeRawSumPattern(client, _m(acc, 'coindays_destroyed')) + self.coindays_destroyed: BaseCumulativeSumPattern[StoredF64] = BaseCumulativeSumPattern(client, _m(acc, 'coindays_destroyed')) self.coinyears_destroyed: MetricPattern1[StoredF64] = MetricPattern1(client, _m(acc, 'coinyears_destroyed')) self.dormancy: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'dormancy')) - self.sent: CumulativeInRawSumPattern = CumulativeInRawSumPattern(client, _m(acc, 'sent')) + self.sent: BaseCumulativeInSumPattern = BaseCumulativeInSumPattern(client, _m(acc, 'sent')) self.velocity: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'velocity')) -class CumulativeInRawSumPattern: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.cumulative: MetricPattern1[Sats] = MetricPattern1(client, _m(acc, 'cumulative')) - self.in_loss: CumulativeRawSumPattern4 = CumulativeRawSumPattern4(client, _m(acc, 'in_loss')) - self.in_profit: CumulativeRawSumPattern4 = CumulativeRawSumPattern4(client, _m(acc, 'in_profit')) - self.raw: MetricPattern1[Sats] = MetricPattern1(client, acc) - self.sum: _1m1w1y24hPattern[Sats] = _1m1w1y24hPattern(client, _m(acc, 'sum')) - class DeltaHalfInTotalPattern2: """Pattern struct for repeated tree structure.""" @@ -2751,8 +2751,28 @@ class AdjustedRatioValuePattern: """Create pattern node with accumulated metric name.""" self.adjusted: RatioValuePattern2 = RatioValuePattern2(client, acc) self.ratio: _1m1w1y24hPattern[StoredF64] = _1m1w1y24hPattern(client, _m(acc, 'sopr')) - self.value_created: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'value_created')) - self.value_destroyed: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'value_destroyed')) + self.value_created: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'value_created')) + self.value_destroyed: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'value_destroyed')) + +class BaseCumulativeDeltaSumPattern: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: CentsUsdPattern = CentsUsdPattern(client, acc) + self.cumulative: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'cumulative')) + self.delta: ChangeRatePattern3 = ChangeRatePattern3(client, _m(acc, 'delta')) + self.sum: _1m1w1y24hPattern4 = _1m1w1y24hPattern4(client, _m(acc, 'sum')) + +class BaseCumulativeNegativeSumPattern: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'unrealized_loss')) + self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'unrealized_loss_cumulative')) + self.negative: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'neg_unrealized_loss')) + self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'unrealized_loss_sum')) class BothReactivatedReceivingSendingPattern: """Pattern struct for repeated tree structure.""" @@ -2794,35 +2814,15 @@ class CentsRelUsdPattern2: self.rel_to_own_mcap: BpsPercentRatioPattern2 = BpsPercentRatioPattern2(client, _m(acc, 'rel_to_own_mcap')) self.usd: MetricPattern1[Dollars] = MetricPattern1(client, acc) -class CumulativeDeltaRawSumPattern: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.cumulative: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'cumulative')) - self.delta: ChangeRatePattern3 = ChangeRatePattern3(client, _m(acc, 'delta')) - self.raw: CentsUsdPattern = CentsUsdPattern(client, acc) - self.sum: _1m1w1y24hPattern4 = _1m1w1y24hPattern4(client, _m(acc, 'sum')) - -class CumulativeNegativeRawSumPattern: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'unrealized_loss_cumulative')) - self.negative: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'neg_unrealized_loss')) - self.raw: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'unrealized_loss')) - self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'unrealized_loss_sum')) - class LossNetNuplProfitPattern: """Pattern struct for repeated tree structure.""" def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" - self.loss: CumulativeNegativeRawSumPattern = CumulativeNegativeRawSumPattern(client, acc) + self.loss: BaseCumulativeNegativeSumPattern = BaseCumulativeNegativeSumPattern(client, acc) self.net_pnl: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'net_unrealized_pnl')) self.nupl: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'nupl')) - self.profit: CumulativeRawSumPattern3 = CumulativeRawSumPattern3(client, _m(acc, 'unrealized_profit')) + self.profit: BaseCumulativeSumPattern3 = BaseCumulativeSumPattern3(client, _m(acc, 'unrealized_profit')) class OutputsRealizedSupplyUnrealizedPattern2: """Pattern struct for repeated tree structure.""" @@ -2854,14 +2854,50 @@ class _1m1w1y24hPattern(Generic[T]): self._1y: MetricPattern1[T] = MetricPattern1(client, _m(acc, '1y')) self._24h: MetricPattern1[T] = MetricPattern1(client, _m(acc, '24h')) +class BaseCumulativeSumPattern4: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, acc) + self.cumulative: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'cumulative')) + self.sum: _1m1w1y24hPattern6 = _1m1w1y24hPattern6(client, _m(acc, 'sum')) + +class BaseCumulativeRelPattern: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: MetricPattern1[Cents] = MetricPattern1(client, acc) + self.cumulative: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'cumulative')) + self.rel_to_rcap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'rel_to_rcap')) + +class BaseCumulativeSumPattern3: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: CentsUsdPattern2 = CentsUsdPattern2(client, acc) + self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'cumulative')) + self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'sum')) + +class BaseCumulativeSumPattern2: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.base: MetricPattern1[StoredU32] = MetricPattern1(client, acc) + self.cumulative: MetricPattern1[StoredU64] = MetricPattern1(client, _m(acc, 'cumulative')) + self.sum: _1m1w1y24hPattern[StoredU64] = _1m1w1y24hPattern(client, _m(acc, 'sum')) + class BlocksDominanceRewardsPattern: """Pattern struct for repeated tree structure.""" def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" - self.blocks_mined: CumulativeRawSumPattern2 = CumulativeRawSumPattern2(client, _m(acc, 'blocks_mined')) + self.blocks_mined: BaseCumulativeSumPattern2 = BaseCumulativeSumPattern2(client, _m(acc, 'blocks_mined')) self.dominance: _1m1w1y24hBpsPercentRatioPattern = _1m1w1y24hBpsPercentRatioPattern(client, _m(acc, 'dominance')) - self.rewards: CumulativeRawSumPattern4 = CumulativeRawSumPattern4(client, _m(acc, 'rewards')) + self.rewards: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, _m(acc, 'rewards')) class BpsPercentRatioPattern4: """Pattern struct for repeated tree structure.""" @@ -2935,42 +2971,6 @@ class CentsSatsUsdPattern: self.sats: MetricPattern1[SatsFract] = MetricPattern1(client, _m(acc, 'sats')) self.usd: MetricPattern1[Dollars] = MetricPattern1(client, acc) -class CumulativeRawSumPattern4: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.cumulative: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'cumulative')) - self.raw: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, acc) - self.sum: _1m1w1y24hPattern6 = _1m1w1y24hPattern6(client, _m(acc, 'sum')) - -class CumulativeRawRelPattern: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.cumulative: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'cumulative')) - self.raw: MetricPattern1[Cents] = MetricPattern1(client, acc) - self.rel_to_rcap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'rel_to_rcap')) - -class CumulativeRawSumPattern3: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, _m(acc, 'cumulative')) - self.raw: CentsUsdPattern2 = CentsUsdPattern2(client, acc) - self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, _m(acc, 'sum')) - -class CumulativeRawSumPattern2: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.cumulative: MetricPattern1[StoredU64] = MetricPattern1(client, _m(acc, 'cumulative')) - self.raw: MetricPattern1[StoredU32] = MetricPattern1(client, acc) - self.sum: _1m1w1y24hPattern[StoredU64] = _1m1w1y24hPattern(client, _m(acc, 'sum')) - class DeltaHalfTotalPattern: """Pattern struct for repeated tree structure.""" @@ -2994,9 +2994,9 @@ class LossNuplProfitPattern: def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" - self.loss: CumulativeRawSumPattern3 = CumulativeRawSumPattern3(client, _m(acc, 'unrealized_loss')) + self.loss: BaseCumulativeSumPattern3 = BaseCumulativeSumPattern3(client, _m(acc, 'unrealized_loss')) self.nupl: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'nupl')) - self.profit: CumulativeRawSumPattern3 = CumulativeRawSumPattern3(client, _m(acc, 'unrealized_profit')) + self.profit: BaseCumulativeSumPattern3 = BaseCumulativeSumPattern3(client, _m(acc, 'unrealized_profit')) class LowerPriceUpperPattern: """Pattern struct for repeated tree structure.""" @@ -3013,8 +3013,8 @@ class RatioValuePattern2: def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" self.ratio: _1m1w1y24hPattern[StoredF64] = _1m1w1y24hPattern(client, _m(acc, 'asopr')) - self.value_created: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'adj_value_created')) - self.value_destroyed: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'adj_value_destroyed')) + self.value_created: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'adj_value_created')) + self.value_destroyed: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'adj_value_destroyed')) class RatioValuePattern: """Pattern struct for repeated tree structure.""" @@ -3022,8 +3022,8 @@ class RatioValuePattern: def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" self.ratio: _24hPattern = _24hPattern(client, _m(acc, 'sopr_24h')) - self.value_created: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'value_created')) - self.value_destroyed: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'value_destroyed')) + self.value_created: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'value_created')) + self.value_destroyed: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'value_destroyed')) class _6bBlockTxindexPattern(Generic[T]): """Pattern struct for repeated tree structure.""" @@ -3034,13 +3034,13 @@ class _6bBlockTxindexPattern(Generic[T]): self.block: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern2[T] = AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern2(client, acc) self.txindex: MetricPattern19[T] = MetricPattern19(client, acc) -class CumulativeRawSumPattern(Generic[T]): +class BaseCumulativeSumPattern(Generic[T]): """Pattern struct for repeated tree structure.""" def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" + self.base: MetricPattern1[T] = MetricPattern1(client, acc) self.cumulative: MetricPattern1[T] = MetricPattern1(client, _m(acc, 'cumulative')) - self.raw: MetricPattern1[T] = MetricPattern1(client, acc) self.sum: _1m1w1y24hPattern[T] = _1m1w1y24hPattern(client, _m(acc, 'sum')) class BlocksDominancePattern: @@ -3048,7 +3048,7 @@ class BlocksDominancePattern: def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" - self.blocks_mined: CumulativeRawSumPattern2 = CumulativeRawSumPattern2(client, _m(acc, 'blocks_mined')) + self.blocks_mined: BaseCumulativeSumPattern2 = BaseCumulativeSumPattern2(client, _m(acc, 'blocks_mined')) self.dominance: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, _m(acc, 'dominance')) class BpsRatioPattern2: @@ -3112,8 +3112,8 @@ class CoindaysSentPattern: def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" - self.coindays_destroyed: CumulativeRawSumPattern[StoredF64] = CumulativeRawSumPattern(client, _m(acc, 'coindays_destroyed')) - self.sent: CumulativeInRawSumPattern = CumulativeInRawSumPattern(client, _m(acc, 'sent')) + self.coindays_destroyed: BaseCumulativeSumPattern[StoredF64] = BaseCumulativeSumPattern(client, _m(acc, 'coindays_destroyed')) + self.sent: BaseCumulativeInSumPattern = BaseCumulativeInSumPattern(client, _m(acc, 'sent')) class DeltaInnerPattern: """Pattern struct for repeated tree structure.""" @@ -3168,8 +3168,8 @@ class ValuePattern: def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" - self.value_created: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'created')) - self.value_destroyed: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, _m(acc, 'destroyed')) + self.value_created: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'created')) + self.value_destroyed: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, _m(acc, 'destroyed')) class _24hPattern: """Pattern struct for repeated tree structure.""" @@ -3198,7 +3198,8 @@ class MetricsTree_Blocks_Difficulty: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.raw: MetricPattern1[StoredF64] = MetricPattern1(client, 'difficulty') + self.raw: MetricPattern18[StoredF64] = MetricPattern18(client, 'difficulty') + self.base: MetricPattern2[StoredF64] = MetricPattern2(client, 'difficulty') self.as_hash: MetricPattern1[StoredF64] = MetricPattern1(client, 'difficulty_as_hash') self.adjustment: BpsPercentRatioPattern2 = BpsPercentRatioPattern2(client, 'difficulty_adjustment') self.epoch: MetricPattern1[Epoch] = MetricPattern1(client, 'difficulty_epoch') @@ -3250,7 +3251,7 @@ class MetricsTree_Blocks_Count: def __init__(self, client: BrkClientBase, base_path: str = ''): self.target: MetricPattern1[StoredU64] = MetricPattern1(client, 'block_count_target') - self.total: CumulativeRawSumPattern2 = CumulativeRawSumPattern2(client, 'block_count') + self.total: BaseCumulativeSumPattern2 = BaseCumulativeSumPattern2(client, 'block_count') class MetricsTree_Blocks_Lookback: """Metrics tree node.""" @@ -3329,7 +3330,7 @@ class MetricsTree_Blocks: self.lookback: MetricsTree_Blocks_Lookback = MetricsTree_Blocks_Lookback(client) self.interval: _1m1w1y24hHeightPattern[Timestamp] = _1m1w1y24hHeightPattern(client, 'block_interval') self.halving: MetricsTree_Blocks_Halving = MetricsTree_Blocks_Halving(client) - self.vbytes: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern = AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern(client, 'block_vbytes') + self.vbytes: AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'block_vbytes') self.fullness: MetricsTree_Blocks_Fullness = MetricsTree_Blocks_Fullness(client) class MetricsTree_Transactions_Raw: @@ -3351,7 +3352,7 @@ class MetricsTree_Transactions_Count: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.total: AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern = AverageCumulativeMaxMedianMinPct10Pct25Pct75Pct90RawSumPattern(client, 'tx_count') + self.total: AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern = AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern(client, 'tx_count') self.is_coinbase: MetricPattern19[StoredBool] = MetricPattern19(client, 'is_coinbase') class MetricsTree_Transactions_Size: @@ -3374,16 +3375,16 @@ class MetricsTree_Transactions_Versions: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.v1: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'tx_v1') - self.v2: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'tx_v2') - self.v3: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'tx_v3') + self.v1: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'tx_v1') + self.v2: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'tx_v2') + self.v3: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'tx_v3') class MetricsTree_Transactions_Volume: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.sent_sum: CumulativeRawSumPattern4 = CumulativeRawSumPattern4(client, 'sent_sum') - self.received_sum: CumulativeRawSumPattern4 = CumulativeRawSumPattern4(client, 'received_sum') + self.sent_sum: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, 'sent_sum') + self.received_sum: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, 'received_sum') self.tx_per_sec: MetricPattern1[StoredF32] = MetricPattern1(client, 'tx_per_sec') self.outputs_per_sec: MetricPattern1[StoredF32] = MetricPattern1(client, 'outputs_per_sec') self.inputs_per_sec: MetricPattern1[StoredF32] = MetricPattern1(client, 'inputs_per_sec') @@ -3564,15 +3565,15 @@ class MetricsTree_Addresses_New: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.all: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'new_address_count') - self.p2pk65: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2pk65_new_address_count') - self.p2pk33: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2pk33_new_address_count') - self.p2pkh: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2pkh_new_address_count') - self.p2sh: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2sh_new_address_count') - self.p2wpkh: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2wpkh_new_address_count') - self.p2wsh: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2wsh_new_address_count') - self.p2tr: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2tr_new_address_count') - self.p2a: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2a_new_address_count') + self.all: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'new_address_count') + self.p2pk65: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2pk65_new_address_count') + self.p2pk33: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2pk33_new_address_count') + self.p2pkh: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2pkh_new_address_count') + self.p2sh: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2sh_new_address_count') + self.p2wpkh: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2wpkh_new_address_count') + self.p2wsh: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2wsh_new_address_count') + self.p2tr: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2tr_new_address_count') + self.p2a: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2a_new_address_count') class MetricsTree_Addresses_Delta: """Metrics tree node.""" @@ -3643,19 +3644,19 @@ class MetricsTree_Scripts_Count: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.p2a: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2a_count') - self.p2ms: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2ms_count') - self.p2pk33: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2pk33_count') - self.p2pk65: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2pk65_count') - self.p2pkh: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2pkh_count') - self.p2sh: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2sh_count') - self.p2tr: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2tr_count') - self.p2wpkh: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2wpkh_count') - self.p2wsh: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'p2wsh_count') - self.opreturn: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'opreturn_count') - self.emptyoutput: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'emptyoutput_count') - self.unknownoutput: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'unknownoutput_count') - self.segwit: CumulativeRawSumPattern[StoredU64] = CumulativeRawSumPattern(client, 'segwit_count') + self.p2a: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2a_count') + self.p2ms: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2ms_count') + self.p2pk33: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2pk33_count') + self.p2pk65: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2pk65_count') + self.p2pkh: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2pkh_count') + self.p2sh: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2sh_count') + self.p2tr: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2tr_count') + self.p2wpkh: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2wpkh_count') + self.p2wsh: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2wsh_count') + self.opreturn: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'opreturn_count') + self.emptyoutput: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'emptyoutput_count') + self.unknownoutput: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'unknownoutput_count') + self.segwit: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'segwit_count') class MetricsTree_Scripts_Value_Opreturn: """Metrics tree node.""" @@ -3722,10 +3723,10 @@ class MetricsTree_Mining_Rewards: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.coinbase: CumulativeRawSumPattern4 = CumulativeRawSumPattern4(client, 'coinbase') + self.coinbase: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, 'coinbase') self.subsidy: MetricsTree_Mining_Rewards_Subsidy = MetricsTree_Mining_Rewards_Subsidy(client) self.fees: MetricsTree_Mining_Rewards_Fees = MetricsTree_Mining_Rewards_Fees(client) - self.unclaimed: CumulativeRawSumPattern4 = CumulativeRawSumPattern4(client, 'unclaimed_rewards') + self.unclaimed: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, 'unclaimed_rewards') class MetricsTree_Mining_Hashrate_Rate_Sma: """Metrics tree node.""" @@ -3740,7 +3741,7 @@ class MetricsTree_Mining_Hashrate_Rate: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.raw: MetricPattern1[StoredF64] = MetricPattern1(client, 'hash_rate') + self.base: MetricPattern1[StoredF64] = MetricPattern1(client, 'hash_rate') self.sma: MetricsTree_Mining_Hashrate_Rate_Sma = MetricsTree_Mining_Hashrate_Rate_Sma(client) self.ath: MetricPattern1[StoredF64] = MetricPattern1(client, 'hash_rate_ath') self.drawdown: BpsPercentRatioPattern5 = BpsPercentRatioPattern5(client, 'hash_rate_drawdown') @@ -3764,8 +3765,8 @@ class MetricsTree_Cointime_Activity: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.coinblocks_created: CumulativeRawSumPattern[StoredF64] = CumulativeRawSumPattern(client, 'coinblocks_created') - self.coinblocks_stored: CumulativeRawSumPattern[StoredF64] = CumulativeRawSumPattern(client, 'coinblocks_stored') + self.coinblocks_created: BaseCumulativeSumPattern[StoredF64] = BaseCumulativeSumPattern(client, 'coinblocks_created') + self.coinblocks_stored: BaseCumulativeSumPattern[StoredF64] = BaseCumulativeSumPattern(client, 'coinblocks_stored') self.liveliness: MetricPattern1[StoredF64] = MetricPattern1(client, 'liveliness') self.vaultedness: MetricPattern1[StoredF64] = MetricPattern1(client, 'vaultedness') self.ratio: MetricPattern1[StoredF64] = MetricPattern1(client, 'activity_to_vaultedness_ratio') @@ -3781,10 +3782,10 @@ class MetricsTree_Cointime_Value: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.destroyed: CumulativeRawSumPattern[StoredF64] = CumulativeRawSumPattern(client, 'cointime_value_destroyed') - self.created: CumulativeRawSumPattern[StoredF64] = CumulativeRawSumPattern(client, 'cointime_value_created') - self.stored: CumulativeRawSumPattern[StoredF64] = CumulativeRawSumPattern(client, 'cointime_value_stored') - self.vocdd: CumulativeRawSumPattern[StoredF64] = CumulativeRawSumPattern(client, 'vocdd') + self.destroyed: BaseCumulativeSumPattern[StoredF64] = BaseCumulativeSumPattern(client, 'cointime_value_destroyed') + self.created: BaseCumulativeSumPattern[StoredF64] = BaseCumulativeSumPattern(client, 'cointime_value_created') + self.stored: BaseCumulativeSumPattern[StoredF64] = BaseCumulativeSumPattern(client, 'cointime_value_stored') + self.vocdd: BaseCumulativeSumPattern[StoredF64] = BaseCumulativeSumPattern(client, 'vocdd') class MetricsTree_Cointime_Cap: """Metrics tree node.""" @@ -3831,7 +3832,7 @@ class MetricsTree_Cointime_CoinblocksDestroyed: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.raw: MetricPattern1[StoredF64] = MetricPattern1(client, 'coinblocks_destroyed') + self.base: MetricPattern1[StoredF64] = MetricPattern1(client, 'coinblocks_destroyed') self.cumulative: MetricPattern1[StoredF64] = MetricPattern1(client, 'coinblocks_destroyed_cumulative') class MetricsTree_Cointime: @@ -4781,8 +4782,8 @@ class MetricsTree_Supply_Burned: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.opreturn: CumulativeRawSumPattern4 = CumulativeRawSumPattern4(client, 'opreturn_supply') - self.unspendable: CumulativeRawSumPattern4 = CumulativeRawSumPattern4(client, 'unspendable_supply') + self.opreturn: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, 'opreturn_supply') + self.unspendable: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, 'unspendable_supply') class MetricsTree_Supply_Velocity: """Metrics tree node.""" @@ -4819,7 +4820,7 @@ class MetricsTree_Cohorts_Utxo_All_Unrealized_Loss: def __init__(self, client: BrkClientBase, base_path: str = ''): self.negative: MetricPattern1[Dollars] = MetricPattern1(client, 'neg_unrealized_loss') - self.raw: CentsUsdPattern2 = CentsUsdPattern2(client, 'unrealized_loss') + self.base: CentsUsdPattern2 = CentsUsdPattern2(client, 'unrealized_loss') self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, 'unrealized_loss_cumulative') self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, 'unrealized_loss_sum') self.rel_to_mcap: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, 'unrealized_loss_rel_to_mcap') @@ -4837,7 +4838,7 @@ class MetricsTree_Cohorts_Utxo_All_Unrealized_Profit: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.raw: CentsUsdPattern2 = CentsUsdPattern2(client, 'unrealized_profit') + self.base: CentsUsdPattern2 = CentsUsdPattern2(client, 'unrealized_profit') self.cumulative: CentsUsdPattern2 = CentsUsdPattern2(client, 'unrealized_profit_cumulative') self.sum: _1m1w1y24hPattern5 = _1m1w1y24hPattern5(client, 'unrealized_profit_sum') self.rel_to_mcap: BpsPercentRatioPattern4 = BpsPercentRatioPattern4(client, 'unrealized_profit_rel_to_mcap') @@ -4891,20 +4892,20 @@ class MetricsTree_Cohorts_Utxo_Lth_Realized_Sopr: def __init__(self, client: BrkClientBase, base_path: str = ''): self.ratio: _1m1w1y24hPattern[StoredF64] = _1m1w1y24hPattern(client, 'lth_sopr') - self.value_created: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, 'lth_value_created') - self.value_destroyed: CumulativeRawSumPattern[Cents] = CumulativeRawSumPattern(client, 'lth_value_destroyed') + self.value_created: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, 'lth_value_created') + self.value_destroyed: BaseCumulativeSumPattern[Cents] = BaseCumulativeSumPattern(client, 'lth_value_destroyed') class MetricsTree_Cohorts_Utxo_Lth_Realized: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.profit: CumulativeDistributionRawRelSumValuePattern = CumulativeDistributionRawRelSumValuePattern(client, 'lth') - self.loss: CapitulationCumulativeNegativeRawRelSumValuePattern = CapitulationCumulativeNegativeRawRelSumValuePattern(client, 'lth') - self.gross_pnl: CumulativeRawSumPattern3 = CumulativeRawSumPattern3(client, 'lth_realized_gross_pnl') + self.profit: BaseCumulativeDistributionRelSumValuePattern = BaseCumulativeDistributionRelSumValuePattern(client, 'lth') + self.loss: BaseCapitulationCumulativeNegativeRelSumValuePattern = BaseCapitulationCumulativeNegativeRelSumValuePattern(client, 'lth') + self.gross_pnl: BaseCumulativeSumPattern3 = BaseCumulativeSumPattern3(client, 'lth_realized_gross_pnl') self.sell_side_risk_ratio: MetricsTree_Cohorts_Utxo_Lth_Realized_SellSideRiskRatio = MetricsTree_Cohorts_Utxo_Lth_Realized_SellSideRiskRatio(client) - self.net_pnl: ChangeCumulativeDeltaRawRelSumPattern = ChangeCumulativeDeltaRawRelSumPattern(client, 'lth_net') + self.net_pnl: BaseChangeCumulativeDeltaRelSumPattern = BaseChangeCumulativeDeltaRelSumPattern(client, 'lth_net') self.sopr: MetricsTree_Cohorts_Utxo_Lth_Realized_Sopr = MetricsTree_Cohorts_Utxo_Lth_Realized_Sopr(client) - self.peak_regret: CumulativeRawRelPattern = CumulativeRawRelPattern(client, 'lth_realized_peak_regret') + self.peak_regret: BaseCumulativeRelPattern = BaseCumulativeRelPattern(client, 'lth_realized_peak_regret') self.investor: LowerPriceUpperPattern = LowerPriceUpperPattern(client, 'lth') self.profit_to_loss_ratio: _1m1w1y24hPattern[StoredF64] = _1m1w1y24hPattern(client, 'lth_realized_profit_to_loss_ratio') self.cap: CentsDeltaRelUsdPattern = CentsDeltaRelUsdPattern(client, 'lth_realized_cap')