From cba3b7dc3895fc88418f6a134dd91359ed55c6f6 Mon Sep 17 00:00:00 2001 From: nym21 Date: Mon, 9 Mar 2026 14:27:35 +0100 Subject: [PATCH] computer: snapshot --- .../brk_computer/src/blocks/count/import.rs | 4 +- crates/brk_computer/src/blocks/count/vecs.rs | 4 +- .../src/blocks/difficulty/compute.rs | 2 +- .../src/blocks/difficulty/import.rs | 14 ++-- .../src/blocks/difficulty/vecs.rs | 14 ++-- .../src/blocks/halving/compute.rs | 2 +- .../brk_computer/src/blocks/halving/import.rs | 8 +-- .../brk_computer/src/blocks/halving/vecs.rs | 8 +-- .../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 +- crates/brk_computer/src/blocks/time/import.rs | 6 +- crates/brk_computer/src/blocks/time/vecs.rs | 18 ++--- .../brk_computer/src/blocks/weight/import.rs | 6 +- crates/brk_computer/src/blocks/weight/vecs.rs | 6 +- .../src/cointime/activity/import.rs | 12 ++-- .../src/cointime/activity/vecs.rs | 12 ++-- .../src/cointime/adjusted/import.rs | 8 +-- .../src/cointime/adjusted/vecs.rs | 8 +-- .../brk_computer/src/cointime/cap/import.rs | 12 ++-- crates/brk_computer/src/cointime/cap/vecs.rs | 12 ++-- .../src/cointime/pricing/import.rs | 10 +-- .../brk_computer/src/cointime/pricing/vecs.rs | 18 ++--- .../src/cointime/reserve_risk/import.rs | 4 +- .../src/cointime/reserve_risk/vecs.rs | 4 +- .../src/cointime/supply/import.rs | 6 +- .../brk_computer/src/cointime/supply/vecs.rs | 6 +- .../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_addr_count.rs | 12 ++-- .../distribution/address/total_addr_count.rs | 12 ++-- .../src/distribution/cohorts/address/vecs.rs | 6 +- .../src/distribution/cohorts/utxo/groups.rs | 8 +-- .../src/distribution/metrics/activity/base.rs | 6 +- .../src/distribution/metrics/activity/core.rs | 4 +- .../src/distribution/metrics/activity/full.rs | 6 +- .../src/distribution/metrics/cohort/all.rs | 6 +- .../distribution/metrics/cohort/extended.rs | 6 +- .../src/distribution/metrics/config.rs | 30 ++++---- .../distribution/metrics/cost_basis/mod.rs | 6 +- .../src/distribution/metrics/outputs.rs | 4 +- .../src/distribution/metrics/profitability.rs | 10 +-- .../distribution/metrics/realized/adjusted.rs | 6 +- .../src/distribution/metrics/realized/base.rs | 6 +- .../src/distribution/metrics/realized/core.rs | 12 ++-- .../src/distribution/metrics/realized/full.rs | 68 +++++++++--------- .../distribution/metrics/realized/minimal.rs | 26 +++---- .../relative/extended_own_market_cap.rs | 8 +-- .../metrics/relative/extended_own_pnl.rs | 8 +-- .../src/distribution/metrics/relative/full.rs | 18 ++--- .../distribution/metrics/relative/to_all.rs | 8 +-- .../src/distribution/metrics/supply.rs | 10 +-- .../distribution/metrics/unrealized/core.rs | 14 ++-- .../distribution/metrics/unrealized/full.rs | 14 ++-- .../metrics/unrealized/minimal.rs | 6 +- .../{difficultyepoch.rs => difficulty.rs} | 0 .../indexes/{halvingepoch.rs => halving.rs} | 0 crates/brk_computer/src/indexes/height.rs | 8 +-- crates/brk_computer/src/indexes/mod.rs | 54 +++++++------- .../brk_computer/src/inputs/count/import.rs | 4 +- crates/brk_computer/src/inputs/count/vecs.rs | 4 +- .../brk_computer/src/internal/amount/base.rs | 2 +- .../brk_computer/src/internal/amount/lazy.rs | 4 +- .../src/internal/containers/mod.rs | 4 +- .../{per_period.rs => per_resolution.rs} | 6 +- .../src/internal/indexes/eager.rs | 22 +++--- .../brk_computer/src/internal/indexes/lazy.rs | 10 +-- crates/brk_computer/src/internal/mod.rs | 8 +-- .../{from_height => per_block}/amount/base.rs | 26 +++---- .../amount/cumulative.rs | 14 ++-- .../amount/cumulative_sum.rs | 18 ++--- .../{from_height => per_block}/amount/full.rs | 18 ++--- .../{from_height => per_block}/amount/lazy.rs | 18 ++--- .../amount/lazy_derived_resolutions.rs} | 32 ++++----- .../{from_height => per_block}/amount/mod.rs | 4 +- .../amount/rolling.rs | 12 ++-- .../amount/rolling_full.rs | 16 ++--- .../amount/rolling_sum.rs | 8 +-- .../amount/windows.rs | 12 ++-- .../computed/aggregated.rs | 6 +- .../computed/base.rs | 12 ++-- .../computed/constant.rs | 8 +-- .../computed/cumulative.rs | 16 ++--- .../computed/cumulative_sum.rs | 16 ++--- .../computed/delta.rs | 34 ++++----- .../computed/fiat_delta.rs | 58 +++++++-------- .../computed/full.rs | 14 ++-- .../computed/mod.rs | 8 +-- .../computed/resolutions.rs} | 16 ++--- .../computed/resolutions_full.rs} | 14 ++-- .../computed/rolling_average.rs | 8 +-- .../computed/sum.rs | 8 +-- .../{from_height => per_block}/fiat/base.rs | 14 ++-- .../{from_height => per_block}/fiat/lazy.rs | 16 ++--- .../{from_height => per_block}/fiat/mod.rs | 0 .../{from_height => per_block}/lazy/base.rs | 22 +++--- .../lazy/derived_resolutions.rs} | 30 ++++---- .../lazy/map_option.rs | 0 .../{from_height => per_block}/lazy/mod.rs | 4 +- .../lazy/transform_last.rs | 0 .../{from_height => per_block}/mod.rs | 0 .../percent/base.rs | 18 ++--- .../{from_height => per_block}/percent/mod.rs | 0 .../percent/rolling_average.rs | 20 +++--- .../percent/windows.rs | 6 +- .../{from_height => per_block}/percentiles.rs | 6 +- .../{from_height => per_block}/price.rs | 24 +++---- .../{from_height => per_block}/ratio/base.rs | 14 ++-- .../ratio/extended.rs | 14 ++-- .../{from_height => per_block}/ratio/mod.rs | 0 .../ratio/percentiles.rs | 36 +++++----- .../ratio/price_extended.rs | 14 ++-- .../ratio/std_dev_bands.rs | 16 ++--- .../rolling/distribution.rs | 0 .../rolling/full.rs | 0 .../{from_height => per_block}/rolling/mod.rs | 0 .../rolling/windows.rs | 28 ++++---- .../{from_height => per_block}/stddev/base.rs | 14 ++-- .../stddev/extended.rs | 66 ++++++++--------- .../{from_height => per_block}/stddev/mod.rs | 0 .../internal/{from_tx => per_tx}/derived.rs | 0 .../{from_tx => per_tx}/distribution.rs | 6 +- .../{from_tx => per_tx}/lazy_distribution.rs | 4 +- .../src/internal/{from_tx => per_tx}/mod.rs | 0 crates/brk_computer/src/market/ath/import.rs | 12 ++-- crates/brk_computer/src/market/ath/vecs.rs | 14 ++-- crates/brk_computer/src/market/dca/import.rs | 16 ++--- crates/brk_computer/src/market/dca/vecs.rs | 20 +++--- .../src/market/indicators/gini.rs | 4 +- .../src/market/indicators/import.rs | 30 ++++---- .../src/market/indicators/vecs.rs | 44 ++++++------ .../brk_computer/src/market/lookback/vecs.rs | 4 +- .../src/market/moving_average/import.rs | 4 +- .../src/market/moving_average/vecs.rs | 72 +++++++++---------- .../brk_computer/src/market/range/import.rs | 8 +-- crates/brk_computer/src/market/range/vecs.rs | 24 +++---- .../brk_computer/src/market/returns/import.rs | 12 ++-- .../brk_computer/src/market/returns/vecs.rs | 12 ++-- .../src/market/volatility/import.rs | 8 +-- .../src/market/volatility/vecs.rs | 8 +-- .../src/mining/hashrate/import.rs | 36 +++++----- .../brk_computer/src/mining/hashrate/vecs.rs | 36 +++++----- .../brk_computer/src/mining/rewards/import.rs | 18 ++--- .../brk_computer/src/mining/rewards/vecs.rs | 18 ++--- .../brk_computer/src/outputs/count/import.rs | 6 +- crates/brk_computer/src/outputs/count/vecs.rs | 6 +- crates/brk_computer/src/pools/major.rs | 6 +- crates/brk_computer/src/pools/minor.rs | 10 +-- crates/brk_computer/src/prices/by_unit.rs | 14 ++-- crates/brk_computer/src/prices/mod.rs | 16 ++--- crates/brk_computer/src/prices/ohlcs.rs | 24 +++---- crates/brk_computer/src/scripts/adoption.rs | 10 +-- .../brk_computer/src/scripts/count/import.rs | 28 ++++---- crates/brk_computer/src/scripts/count/vecs.rs | 28 ++++---- .../brk_computer/src/scripts/value/import.rs | 4 +- crates/brk_computer/src/scripts/value/vecs.rs | 4 +- .../brk_computer/src/supply/burned/import.rs | 6 +- crates/brk_computer/src/supply/burned/vecs.rs | 6 +- crates/brk_computer/src/supply/import.rs | 8 +-- crates/brk_computer/src/supply/vecs.rs | 8 +-- .../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 +- .../src/transactions/size/import.rs | 6 +- .../src/transactions/size/vecs.rs | 6 +- .../src/transactions/versions/compute.rs | 4 +- .../src/transactions/versions/import.rs | 8 +-- .../src/transactions/versions/vecs.rs | 8 +-- .../src/transactions/volume/import.rs | 14 ++-- .../src/transactions/volume/vecs.rs | 14 ++-- .../brk_query/src/impl/mining/difficulty.rs | 10 +-- crates/brk_query/src/impl/mining/epochs.rs | 10 +-- 178 files changed, 1089 insertions(+), 1089 deletions(-) rename crates/brk_computer/src/indexes/{difficultyepoch.rs => difficulty.rs} (100%) rename crates/brk_computer/src/indexes/{halvingepoch.rs => halving.rs} (100%) rename crates/brk_computer/src/internal/containers/{per_period.rs => per_resolution.rs} (70%) rename crates/brk_computer/src/internal/{from_height => per_block}/amount/base.rs (72%) rename crates/brk_computer/src/internal/{from_height => per_block}/amount/cumulative.rs (82%) rename crates/brk_computer/src/internal/{from_height => per_block}/amount/cumulative_sum.rs (78%) rename crates/brk_computer/src/internal/{from_height => per_block}/amount/full.rs (76%) rename crates/brk_computer/src/internal/{from_height => per_block}/amount/lazy.rs (74%) rename crates/brk_computer/src/internal/{from_height/amount/lazy_derived.rs => per_block/amount/lazy_derived_resolutions.rs} (53%) rename crates/brk_computer/src/internal/{from_height => per_block}/amount/mod.rs (82%) rename crates/brk_computer/src/internal/{from_height => per_block}/amount/rolling.rs (80%) rename crates/brk_computer/src/internal/{from_height => per_block}/amount/rolling_full.rs (83%) rename crates/brk_computer/src/internal/{from_height => per_block}/amount/rolling_sum.rs (84%) rename crates/brk_computer/src/internal/{from_height => per_block}/amount/windows.rs (75%) rename crates/brk_computer/src/internal/{from_height => per_block}/computed/aggregated.rs (89%) rename crates/brk_computer/src/internal/{from_height => per_block}/computed/base.rs (83%) rename crates/brk_computer/src/internal/{from_height => per_block}/computed/constant.rs (91%) rename crates/brk_computer/src/internal/{from_height => per_block}/computed/cumulative.rs (73%) rename crates/brk_computer/src/internal/{from_height => per_block}/computed/cumulative_sum.rs (76%) rename crates/brk_computer/src/internal/{from_height => per_block}/computed/delta.rs (89%) rename crates/brk_computer/src/internal/{from_height => per_block}/computed/fiat_delta.rs (80%) rename crates/brk_computer/src/internal/{from_height => per_block}/computed/full.rs (77%) rename crates/brk_computer/src/internal/{from_height => per_block}/computed/mod.rs (79%) rename crates/brk_computer/src/internal/{from_height/computed/derived.rs => per_block/computed/resolutions.rs} (92%) rename crates/brk_computer/src/internal/{from_height/computed/derived_full.rs => per_block/computed/resolutions_full.rs} (72%) rename crates/brk_computer/src/internal/{from_height => per_block}/computed/rolling_average.rs (89%) rename crates/brk_computer/src/internal/{from_height => per_block}/computed/sum.rs (85%) rename crates/brk_computer/src/internal/{from_height => per_block}/fiat/base.rs (72%) rename crates/brk_computer/src/internal/{from_height => per_block}/fiat/lazy.rs (60%) rename crates/brk_computer/src/internal/{from_height => per_block}/fiat/mod.rs (100%) rename crates/brk_computer/src/internal/{from_height => per_block}/lazy/base.rs (74%) rename crates/brk_computer/src/internal/{from_height/lazy/derived.rs => per_block/lazy/derived_resolutions.rs} (86%) rename crates/brk_computer/src/internal/{from_height => per_block}/lazy/map_option.rs (100%) rename crates/brk_computer/src/internal/{from_height => per_block}/lazy/mod.rs (66%) rename crates/brk_computer/src/internal/{from_height => per_block}/lazy/transform_last.rs (100%) rename crates/brk_computer/src/internal/{from_height => per_block}/mod.rs (100%) rename crates/brk_computer/src/internal/{from_height => per_block}/percent/base.rs (77%) rename crates/brk_computer/src/internal/{from_height => per_block}/percent/mod.rs (100%) rename crates/brk_computer/src/internal/{from_height => per_block}/percent/rolling_average.rs (66%) rename crates/brk_computer/src/internal/{from_height => per_block}/percent/windows.rs (78%) rename crates/brk_computer/src/internal/{from_height => per_block}/percentiles.rs (93%) rename crates/brk_computer/src/internal/{from_height => per_block}/price.rs (72%) rename crates/brk_computer/src/internal/{from_height => per_block}/ratio/base.rs (79%) rename crates/brk_computer/src/internal/{from_height => per_block}/ratio/extended.rs (74%) rename crates/brk_computer/src/internal/{from_height => per_block}/ratio/mod.rs (100%) rename crates/brk_computer/src/internal/{from_height => per_block}/ratio/percentiles.rs (85%) rename crates/brk_computer/src/internal/{from_height => per_block}/ratio/price_extended.rs (76%) rename crates/brk_computer/src/internal/{from_height => per_block}/ratio/std_dev_bands.rs (77%) rename crates/brk_computer/src/internal/{from_height => per_block}/rolling/distribution.rs (100%) rename crates/brk_computer/src/internal/{from_height => per_block}/rolling/full.rs (100%) rename crates/brk_computer/src/internal/{from_height => per_block}/rolling/mod.rs (100%) rename crates/brk_computer/src/internal/{from_height => per_block}/rolling/windows.rs (84%) rename crates/brk_computer/src/internal/{from_height => per_block}/stddev/base.rs (78%) rename crates/brk_computer/src/internal/{from_height => per_block}/stddev/extended.rs (80%) rename crates/brk_computer/src/internal/{from_height => per_block}/stddev/mod.rs (100%) rename crates/brk_computer/src/internal/{from_tx => per_tx}/derived.rs (100%) rename crates/brk_computer/src/internal/{from_tx => per_tx}/distribution.rs (89%) rename crates/brk_computer/src/internal/{from_tx => per_tx}/lazy_distribution.rs (93%) rename crates/brk_computer/src/internal/{from_tx => per_tx}/mod.rs (100%) diff --git a/crates/brk_computer/src/blocks/count/import.rs b/crates/brk_computer/src/blocks/count/import.rs index 8bcca01ed..78421fd0f 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, ComputedFromHeightCumulativeSum, ConstantVecs}, + internal::{BlockCountTarget, ComputedPerBlockCumulativeSum, ConstantVecs}, }; impl Vecs { @@ -20,7 +20,7 @@ impl Vecs { version, indexes, ), - block_count: ComputedFromHeightCumulativeSum::forced_import( + block_count: ComputedPerBlockCumulativeSum::forced_import( db, "block_count", version, diff --git a/crates/brk_computer/src/blocks/count/vecs.rs b/crates/brk_computer/src/blocks/count/vecs.rs index 4ee93a92d..5653611ce 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::{ComputedFromHeightCumulativeSum, ConstantVecs}; +use crate::internal::{ComputedPerBlockCumulativeSum, ConstantVecs}; #[derive(Traversable)] pub struct Vecs { pub block_count_target: ConstantVecs, - pub block_count: ComputedFromHeightCumulativeSum, + pub block_count: ComputedPerBlockCumulativeSum, } diff --git a/crates/brk_computer/src/blocks/difficulty/compute.rs b/crates/brk_computer/src/blocks/difficulty/compute.rs index 639bcd3ba..1925d6e98 100644 --- a/crates/brk_computer/src/blocks/difficulty/compute.rs +++ b/crates/brk_computer/src/blocks/difficulty/compute.rs @@ -37,7 +37,7 @@ impl Vecs { // Compute epoch by height self.epoch.height.compute_transform( starting_indexes.height, - &indexes.height.difficultyepoch, + &indexes.height.difficulty, |(h, epoch, ..)| (h, epoch), exit, )?; diff --git a/crates/brk_computer/src/blocks/difficulty/import.rs b/crates/brk_computer/src/blocks/difficulty/import.rs index 633585bd4..a799d8fbe 100644 --- a/crates/brk_computer/src/blocks/difficulty/import.rs +++ b/crates/brk_computer/src/blocks/difficulty/import.rs @@ -6,7 +6,7 @@ use vecdb::{Database, ReadableCloneableVec}; use super::Vecs; use crate::{ indexes, - internal::{ComputedFromHeight, ComputedHeightDerived, PercentFromHeight}, + internal::{ComputedPerBlock, Resolutions, PercentPerBlock}, }; impl Vecs { @@ -19,27 +19,27 @@ impl Vecs { let v2 = Version::TWO; Ok(Self { - raw: ComputedHeightDerived::forced_import( + raw: Resolutions::forced_import( "difficulty", indexer.vecs.blocks.difficulty.read_only_boxed_clone(), version, indexes, ), - as_hash: ComputedFromHeight::forced_import(db, "difficulty_as_hash", version, indexes)?, - adjustment: PercentFromHeight::forced_import( + as_hash: ComputedPerBlock::forced_import(db, "difficulty_as_hash", version, indexes)?, + adjustment: PercentPerBlock::forced_import( db, "difficulty_adjustment", version, indexes, )?, - epoch: ComputedFromHeight::forced_import(db, "difficulty_epoch", version, indexes)?, - blocks_before_next_adjustment: ComputedFromHeight::forced_import( + epoch: ComputedPerBlock::forced_import(db, "difficulty_epoch", version, indexes)?, + blocks_before_next_adjustment: ComputedPerBlock::forced_import( db, "blocks_before_next_difficulty_adjustment", version + v2, indexes, )?, - days_before_next_adjustment: ComputedFromHeight::forced_import( + days_before_next_adjustment: ComputedPerBlock::forced_import( db, "days_before_next_difficulty_adjustment", version + v2, diff --git a/crates/brk_computer/src/blocks/difficulty/vecs.rs b/crates/brk_computer/src/blocks/difficulty/vecs.rs index 1ef4ebd24..37020a65e 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, DifficultyEpoch, StoredF32, StoredF64, StoredU32}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeight, ComputedHeightDerived, PercentFromHeight}; +use crate::internal::{ComputedPerBlock, Resolutions, PercentPerBlock}; #[derive(Traversable)] pub struct Vecs { - pub raw: ComputedHeightDerived, - pub as_hash: ComputedFromHeight, - pub adjustment: PercentFromHeight, - pub epoch: ComputedFromHeight, - pub blocks_before_next_adjustment: ComputedFromHeight, - pub days_before_next_adjustment: ComputedFromHeight, + pub raw: Resolutions, + pub as_hash: ComputedPerBlock, + pub adjustment: PercentPerBlock, + pub epoch: ComputedPerBlock, + pub blocks_before_next_adjustment: ComputedPerBlock, + pub days_before_next_adjustment: ComputedPerBlock, } diff --git a/crates/brk_computer/src/blocks/halving/compute.rs b/crates/brk_computer/src/blocks/halving/compute.rs index bf7ceb029..c720914b7 100644 --- a/crates/brk_computer/src/blocks/halving/compute.rs +++ b/crates/brk_computer/src/blocks/halving/compute.rs @@ -15,7 +15,7 @@ impl Vecs { ) -> Result<()> { self.epoch.height.compute_transform( starting_indexes.height, - &indexes.height.halvingepoch, + &indexes.height.halving, |(h, epoch, ..)| (h, epoch), exit, )?; diff --git a/crates/brk_computer/src/blocks/halving/import.rs b/crates/brk_computer/src/blocks/halving/import.rs index 1087051ec..4db2ae4cd 100644 --- a/crates/brk_computer/src/blocks/halving/import.rs +++ b/crates/brk_computer/src/blocks/halving/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::ComputedFromHeight}; +use crate::{indexes, internal::ComputedPerBlock}; impl Vecs { pub(crate) fn forced_import( @@ -14,14 +14,14 @@ impl Vecs { let v2 = Version::TWO; Ok(Self { - epoch: ComputedFromHeight::forced_import(db, "halving_epoch", version, indexes)?, - blocks_before_next_halving: ComputedFromHeight::forced_import( + epoch: ComputedPerBlock::forced_import(db, "halving_epoch", version, indexes)?, + blocks_before_next_halving: ComputedPerBlock::forced_import( db, "blocks_before_next_halving", version + v2, indexes, )?, - days_before_next_halving: ComputedFromHeight::forced_import( + days_before_next_halving: ComputedPerBlock::forced_import( db, "days_before_next_halving", version + v2, diff --git a/crates/brk_computer/src/blocks/halving/vecs.rs b/crates/brk_computer/src/blocks/halving/vecs.rs index c0ca8afea..8b4ad8bdd 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::{HalvingEpoch, StoredF32, StoredU32}; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedFromHeight; +use crate::internal::ComputedPerBlock; #[derive(Traversable)] pub struct Vecs { - pub epoch: ComputedFromHeight, - pub blocks_before_next_halving: ComputedFromHeight, - pub days_before_next_halving: ComputedFromHeight, + pub epoch: ComputedPerBlock, + pub blocks_before_next_halving: ComputedPerBlock, + pub days_before_next_halving: ComputedPerBlock, } diff --git a/crates/brk_computer/src/blocks/interval/import.rs b/crates/brk_computer/src/blocks/interval/import.rs index 6247e46ae..c7e2816df 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::ComputedFromHeightRollingAverage}; +use crate::{indexes, internal::ComputedPerBlockRollingAverage}; impl Vecs { pub(crate) fn forced_import( @@ -11,7 +11,7 @@ impl Vecs { version: Version, indexes: &indexes::Vecs, ) -> Result { - let interval = ComputedFromHeightRollingAverage::forced_import( + let interval = ComputedPerBlockRollingAverage::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 24f39759f..3ed2b0b78 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::ComputedFromHeightRollingAverage; +use crate::internal::ComputedPerBlockRollingAverage; #[derive(Deref, DerefMut, Traversable)] pub struct Vecs( - #[traversable(flatten)] pub ComputedFromHeightRollingAverage, + #[traversable(flatten)] pub ComputedPerBlockRollingAverage, ); diff --git a/crates/brk_computer/src/blocks/size/import.rs b/crates/brk_computer/src/blocks/size/import.rs index 538626211..6407b1ddb 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::{ComputedFromHeightFull, ComputedHeightDerivedFull}, + internal::{ComputedPerBlockFull, ResolutionsFull}, }; impl Vecs { @@ -15,8 +15,8 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - vbytes: ComputedFromHeightFull::forced_import(db, "block_vbytes", version, indexes)?, - size: ComputedHeightDerivedFull::forced_import(db, "block_size", version, indexes)?, + vbytes: ComputedPerBlockFull::forced_import(db, "block_vbytes", version, indexes)?, + size: ResolutionsFull::forced_import(db, "block_size", version, indexes)?, }) } } diff --git a/crates/brk_computer/src/blocks/size/vecs.rs b/crates/brk_computer/src/blocks/size/vecs.rs index d2ae9a51c..dcebb5735 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::{ComputedFromHeightFull, ComputedHeightDerivedFull}; +use crate::internal::{ComputedPerBlockFull, ResolutionsFull}; #[derive(Traversable)] pub struct Vecs { - pub vbytes: ComputedFromHeightFull, - pub size: ComputedHeightDerivedFull, + pub vbytes: ComputedPerBlockFull, + pub size: ResolutionsFull, } diff --git a/crates/brk_computer/src/blocks/time/import.rs b/crates/brk_computer/src/blocks/time/import.rs index 68aa2aaf9..4d7e1867e 100644 --- a/crates/brk_computer/src/blocks/time/import.rs +++ b/crates/brk_computer/src/blocks/time/import.rs @@ -45,7 +45,7 @@ impl TimestampIndexes { }; } - Ok(Self(crate::internal::PerPeriod { + Ok(Self(crate::internal::PerResolution { minute10: period!(minute10), minute30: period!(minute30), hour1: period!(hour1), @@ -59,8 +59,8 @@ impl TimestampIndexes { month6: period!(month6), year1: period!(year1), year10: period!(year10), - halvingepoch: epoch!(halvingepoch), - difficultyepoch: epoch!(difficultyepoch), + halving: epoch!(halving), + difficulty: epoch!(difficulty), })) } } diff --git a/crates/brk_computer/src/blocks/time/vecs.rs b/crates/brk_computer/src/blocks/time/vecs.rs index 2d1f30c5b..648e99675 100644 --- a/crates/brk_computer/src/blocks/time/vecs.rs +++ b/crates/brk_computer/src/blocks/time/vecs.rs @@ -7,7 +7,7 @@ use brk_types::{ use derive_more::{Deref, DerefMut}; use vecdb::{EagerVec, Exit, LazyVecFrom1, PcoVec, ReadableVec, Rw, StorageMode}; -use crate::{indexes, internal::PerPeriod}; +use crate::{indexes, internal::PerResolution}; #[derive(Traversable)] pub struct Vecs { pub date: LazyVecFrom1, @@ -19,13 +19,13 @@ pub struct Vecs { /// /// Time-based periods (minute10–year10) are lazy: `idx.to_timestamp()` is a pure /// function of the index, so no storage or decompression is needed. -/// Epoch-based periods (halvingepoch, difficultyepoch) are eager: their timestamps +/// Epoch-based periods (halving, difficulty) are eager: their timestamps /// come from block data via `compute_indirect_sequential`. #[derive(Deref, DerefMut, Traversable)] #[traversable(transparent)] pub struct TimestampIndexes( #[allow(clippy::type_complexity)] - pub PerPeriod< + pub PerResolution< LazyVecFrom1, LazyVecFrom1, LazyVecFrom1, @@ -55,23 +55,23 @@ impl TimestampIndexes { exit: &Exit, ) -> Result<()> { let prev_height = starting_indexes.height.decremented().unwrap_or_default(); - self.halvingepoch.compute_indirect_sequential( + self.halving.compute_indirect_sequential( indexes .height - .halvingepoch + .halving .collect_one(prev_height) .unwrap_or_default(), - &indexes.halvingepoch.first_height, + &indexes.halving.first_height, &indexer.vecs.blocks.timestamp, exit, )?; - self.difficultyepoch.compute_indirect_sequential( + self.difficulty.compute_indirect_sequential( indexes .height - .difficultyepoch + .difficulty .collect_one(prev_height) .unwrap_or_default(), - &indexes.difficultyepoch.first_height, + &indexes.difficulty.first_height, &indexer.vecs.blocks.timestamp, exit, )?; diff --git a/crates/brk_computer/src/blocks/weight/import.rs b/crates/brk_computer/src/blocks/weight/import.rs index 2ff9549f2..0ba81ef55 100644 --- a/crates/brk_computer/src/blocks/weight/import.rs +++ b/crates/brk_computer/src/blocks/weight/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{ComputedHeightDerivedFull, PercentFromHeightRollingAverage}, + internal::{ResolutionsFull, PercentPerBlockRollingAverage}, }; impl Vecs { @@ -15,9 +15,9 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { let weight = - ComputedHeightDerivedFull::forced_import(db, "block_weight", version, indexes)?; + ResolutionsFull::forced_import(db, "block_weight", version, indexes)?; - let fullness = PercentFromHeightRollingAverage::forced_import( + let fullness = PercentPerBlockRollingAverage::forced_import( db, "block_fullness", version, diff --git a/crates/brk_computer/src/blocks/weight/vecs.rs b/crates/brk_computer/src/blocks/weight/vecs.rs index b9c972944..23745d052 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, Weight}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedHeightDerivedFull, PercentFromHeightRollingAverage}; +use crate::internal::{ResolutionsFull, PercentPerBlockRollingAverage}; #[derive(Traversable)] pub struct Vecs { - pub weight: ComputedHeightDerivedFull, - pub fullness: PercentFromHeightRollingAverage, + pub weight: ResolutionsFull, + pub fullness: PercentPerBlockRollingAverage, } diff --git a/crates/brk_computer/src/cointime/activity/import.rs b/crates/brk_computer/src/cointime/activity/import.rs index c37947bab..ae0a4d600 100644 --- a/crates/brk_computer/src/cointime/activity/import.rs +++ b/crates/brk_computer/src/cointime/activity/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{ComputedFromHeight, ComputedFromHeightCumulativeSum}, + internal::{ComputedPerBlock, ComputedPerBlockCumulativeSum}, }; impl Vecs { @@ -15,21 +15,21 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - coinblocks_created: ComputedFromHeightCumulativeSum::forced_import( + coinblocks_created: ComputedPerBlockCumulativeSum::forced_import( db, "coinblocks_created", version, indexes, )?, - coinblocks_stored: ComputedFromHeightCumulativeSum::forced_import( + coinblocks_stored: ComputedPerBlockCumulativeSum::forced_import( db, "coinblocks_stored", version, indexes, )?, - liveliness: ComputedFromHeight::forced_import(db, "liveliness", version, indexes)?, - vaultedness: ComputedFromHeight::forced_import(db, "vaultedness", version, indexes)?, - activity_to_vaultedness_ratio: ComputedFromHeight::forced_import( + liveliness: ComputedPerBlock::forced_import(db, "liveliness", version, indexes)?, + vaultedness: ComputedPerBlock::forced_import(db, "vaultedness", version, indexes)?, + activity_to_vaultedness_ratio: ComputedPerBlock::forced_import( db, "activity_to_vaultedness_ratio", version, diff --git a/crates/brk_computer/src/cointime/activity/vecs.rs b/crates/brk_computer/src/cointime/activity/vecs.rs index 79d11a499..19e88ded6 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::{ComputedFromHeight, ComputedFromHeightCumulativeSum}; +use crate::internal::{ComputedPerBlock, ComputedPerBlockCumulativeSum}; #[derive(Traversable)] pub struct Vecs { - pub coinblocks_created: ComputedFromHeightCumulativeSum, - pub coinblocks_stored: ComputedFromHeightCumulativeSum, - pub liveliness: ComputedFromHeight, - pub vaultedness: ComputedFromHeight, - pub activity_to_vaultedness_ratio: ComputedFromHeight, + pub coinblocks_created: ComputedPerBlockCumulativeSum, + pub coinblocks_stored: ComputedPerBlockCumulativeSum, + pub liveliness: ComputedPerBlock, + pub vaultedness: ComputedPerBlock, + pub activity_to_vaultedness_ratio: ComputedPerBlock, } diff --git a/crates/brk_computer/src/cointime/adjusted/import.rs b/crates/brk_computer/src/cointime/adjusted/import.rs index f5e23032b..1ed9da6c0 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::{ComputedFromHeight, PercentFromHeight}, + internal::{ComputedPerBlock, PercentPerBlock}, }; impl Vecs { @@ -15,19 +15,19 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - cointime_adj_inflation_rate: PercentFromHeight::forced_import( + cointime_adj_inflation_rate: PercentPerBlock::forced_import( db, "cointime_adj_inflation_rate", version, indexes, )?, - cointime_adj_tx_velocity_btc: ComputedFromHeight::forced_import( + cointime_adj_tx_velocity_btc: ComputedPerBlock::forced_import( db, "cointime_adj_tx_velocity_btc", version, indexes, )?, - cointime_adj_tx_velocity_usd: ComputedFromHeight::forced_import( + cointime_adj_tx_velocity_usd: ComputedPerBlock::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 d55178777..beb857527 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::{ComputedFromHeight, PercentFromHeight}; +use crate::internal::{ComputedPerBlock, PercentPerBlock}; #[derive(Traversable)] pub struct Vecs { - pub cointime_adj_inflation_rate: PercentFromHeight, - pub cointime_adj_tx_velocity_btc: ComputedFromHeight, - pub cointime_adj_tx_velocity_usd: ComputedFromHeight, + pub cointime_adj_inflation_rate: PercentPerBlock, + pub cointime_adj_tx_velocity_btc: ComputedPerBlock, + pub cointime_adj_tx_velocity_usd: ComputedPerBlock, } diff --git a/crates/brk_computer/src/cointime/cap/import.rs b/crates/brk_computer/src/cointime/cap/import.rs index 9b04365d1..ea3b122c8 100644 --- a/crates/brk_computer/src/cointime/cap/import.rs +++ b/crates/brk_computer/src/cointime/cap/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::FiatFromHeight}; +use crate::{indexes, internal::FiatPerBlock}; impl Vecs { pub(crate) fn forced_import( @@ -12,11 +12,11 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - thermo_cap: FiatFromHeight::forced_import(db, "thermo_cap", version, indexes)?, - investor_cap: FiatFromHeight::forced_import(db, "investor_cap", version, indexes)?, - vaulted_cap: FiatFromHeight::forced_import(db, "vaulted_cap", version, indexes)?, - active_cap: FiatFromHeight::forced_import(db, "active_cap", version, indexes)?, - cointime_cap: FiatFromHeight::forced_import(db, "cointime_cap", version, indexes)?, + thermo_cap: FiatPerBlock::forced_import(db, "thermo_cap", version, indexes)?, + investor_cap: FiatPerBlock::forced_import(db, "investor_cap", version, indexes)?, + vaulted_cap: FiatPerBlock::forced_import(db, "vaulted_cap", version, indexes)?, + active_cap: FiatPerBlock::forced_import(db, "active_cap", version, indexes)?, + cointime_cap: FiatPerBlock::forced_import(db, "cointime_cap", version, indexes)?, }) } } diff --git a/crates/brk_computer/src/cointime/cap/vecs.rs b/crates/brk_computer/src/cointime/cap/vecs.rs index fda6b31ab..ab657bd15 100644 --- a/crates/brk_computer/src/cointime/cap/vecs.rs +++ b/crates/brk_computer/src/cointime/cap/vecs.rs @@ -2,13 +2,13 @@ use brk_traversable::Traversable; use brk_types::Cents; use vecdb::{Rw, StorageMode}; -use crate::internal::FiatFromHeight; +use crate::internal::FiatPerBlock; #[derive(Traversable)] pub struct Vecs { - pub thermo_cap: FiatFromHeight, - pub investor_cap: FiatFromHeight, - pub vaulted_cap: FiatFromHeight, - pub active_cap: FiatFromHeight, - pub cointime_cap: FiatFromHeight, + pub thermo_cap: FiatPerBlock, + pub investor_cap: FiatPerBlock, + pub vaulted_cap: FiatPerBlock, + pub active_cap: FiatPerBlock, + pub cointime_cap: FiatPerBlock, } diff --git a/crates/brk_computer/src/cointime/pricing/import.rs b/crates/brk_computer/src/cointime/pricing/import.rs index 70c031de2..a8d41a46e 100644 --- a/crates/brk_computer/src/cointime/pricing/import.rs +++ b/crates/brk_computer/src/cointime/pricing/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{ComputedFromHeightRatioExtended, Price}, + internal::{RatioPerBlockExtended, Price}, }; impl Vecs { @@ -16,14 +16,14 @@ impl Vecs { ) -> Result { let vaulted_price = Price::forced_import(db, "vaulted_price", version, indexes)?; let vaulted_price_ratio = - ComputedFromHeightRatioExtended::forced_import(db, "vaulted_price", version, indexes)?; + RatioPerBlockExtended::forced_import(db, "vaulted_price", version, indexes)?; let active_price = Price::forced_import(db, "active_price", version, indexes)?; let active_price_ratio = - ComputedFromHeightRatioExtended::forced_import(db, "active_price", version, indexes)?; + RatioPerBlockExtended::forced_import(db, "active_price", version, indexes)?; let true_market_mean = Price::forced_import(db, "true_market_mean", version, indexes)?; - let true_market_mean_ratio = ComputedFromHeightRatioExtended::forced_import( + let true_market_mean_ratio = RatioPerBlockExtended::forced_import( db, "true_market_mean", version, @@ -32,7 +32,7 @@ impl Vecs { let cointime_price = Price::forced_import(db, "cointime_price", version, indexes)?; let cointime_price_ratio = - ComputedFromHeightRatioExtended::forced_import(db, "cointime_price", version, indexes)?; + RatioPerBlockExtended::forced_import(db, "cointime_price", version, indexes)?; Ok(Self { vaulted_price, diff --git a/crates/brk_computer/src/cointime/pricing/vecs.rs b/crates/brk_computer/src/cointime/pricing/vecs.rs index c44aa0a5c..2f5f8e910 100644 --- a/crates/brk_computer/src/cointime/pricing/vecs.rs +++ b/crates/brk_computer/src/cointime/pricing/vecs.rs @@ -2,16 +2,16 @@ use brk_traversable::Traversable; use brk_types::Cents; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeight, ComputedFromHeightRatioExtended, Price}; +use crate::internal::{ComputedPerBlock, RatioPerBlockExtended, Price}; #[derive(Traversable)] pub struct Vecs { - pub vaulted_price: Price>, - pub vaulted_price_ratio: ComputedFromHeightRatioExtended, - pub active_price: Price>, - pub active_price_ratio: ComputedFromHeightRatioExtended, - pub true_market_mean: Price>, - pub true_market_mean_ratio: ComputedFromHeightRatioExtended, - pub cointime_price: Price>, - pub cointime_price_ratio: ComputedFromHeightRatioExtended, + pub vaulted_price: Price>, + pub vaulted_price_ratio: RatioPerBlockExtended, + pub active_price: Price>, + pub active_price_ratio: RatioPerBlockExtended, + pub true_market_mean: Price>, + pub true_market_mean_ratio: RatioPerBlockExtended, + pub cointime_price: Price>, + pub cointime_price_ratio: RatioPerBlockExtended, } diff --git a/crates/brk_computer/src/cointime/reserve_risk/import.rs b/crates/brk_computer/src/cointime/reserve_risk/import.rs index 1da7f71d2..0dab20284 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::ComputedFromHeight}; +use crate::{indexes, internal::ComputedPerBlock}; 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)?, - reserve_risk: ComputedFromHeight::forced_import(db, "reserve_risk", v1, indexes)?, + reserve_risk: ComputedPerBlock::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 e81e8e6f0..1a3f08193 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::ComputedFromHeight; +use crate::internal::ComputedPerBlock; #[derive(Traversable)] pub struct Vecs { pub vocdd_median_1y: M::Stored>>, pub hodl_bank: M::Stored>>, - pub reserve_risk: ComputedFromHeight, + pub reserve_risk: ComputedPerBlock, } diff --git a/crates/brk_computer/src/cointime/supply/import.rs b/crates/brk_computer/src/cointime/supply/import.rs index f7900a2c2..5955b6b38 100644 --- a/crates/brk_computer/src/cointime/supply/import.rs +++ b/crates/brk_computer/src/cointime/supply/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::AmountFromHeight}; +use crate::{indexes, internal::AmountPerBlock}; impl Vecs { pub(crate) fn forced_import( @@ -12,13 +12,13 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - vaulted_supply: AmountFromHeight::forced_import( + vaulted_supply: AmountPerBlock::forced_import( db, "vaulted_supply", version, indexes, )?, - active_supply: AmountFromHeight::forced_import(db, "active_supply", version, indexes)?, + active_supply: AmountPerBlock::forced_import(db, "active_supply", version, indexes)?, }) } } diff --git a/crates/brk_computer/src/cointime/supply/vecs.rs b/crates/brk_computer/src/cointime/supply/vecs.rs index 4ae433878..a688a041f 100644 --- a/crates/brk_computer/src/cointime/supply/vecs.rs +++ b/crates/brk_computer/src/cointime/supply/vecs.rs @@ -1,10 +1,10 @@ use brk_traversable::Traversable; use vecdb::{Rw, StorageMode}; -use crate::internal::AmountFromHeight; +use crate::internal::AmountPerBlock; #[derive(Traversable)] pub struct Vecs { - pub vaulted_supply: AmountFromHeight, - pub active_supply: AmountFromHeight, + pub vaulted_supply: AmountPerBlock, + pub active_supply: AmountPerBlock, } diff --git a/crates/brk_computer/src/cointime/value/import.rs b/crates/brk_computer/src/cointime/value/import.rs index 5601eaa11..650088992 100644 --- a/crates/brk_computer/src/cointime/value/import.rs +++ b/crates/brk_computer/src/cointime/value/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::ComputedFromHeightCumulativeSum}; +use crate::{indexes, internal::ComputedPerBlockCumulativeSum}; impl Vecs { pub(crate) fn forced_import( @@ -12,25 +12,25 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - cointime_value_destroyed: ComputedFromHeightCumulativeSum::forced_import( + cointime_value_destroyed: ComputedPerBlockCumulativeSum::forced_import( db, "cointime_value_destroyed", version, indexes, )?, - cointime_value_created: ComputedFromHeightCumulativeSum::forced_import( + cointime_value_created: ComputedPerBlockCumulativeSum::forced_import( db, "cointime_value_created", version, indexes, )?, - cointime_value_stored: ComputedFromHeightCumulativeSum::forced_import( + cointime_value_stored: ComputedPerBlockCumulativeSum::forced_import( db, "cointime_value_stored", version, indexes, )?, - vocdd: ComputedFromHeightCumulativeSum::forced_import( + vocdd: ComputedPerBlockCumulativeSum::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 214b3a1b9..76391b8b6 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::ComputedFromHeightCumulativeSum; +use crate::internal::ComputedPerBlockCumulativeSum; #[derive(Traversable)] pub struct Vecs { - pub cointime_value_destroyed: ComputedFromHeightCumulativeSum, - pub cointime_value_created: ComputedFromHeightCumulativeSum, - pub cointime_value_stored: ComputedFromHeightCumulativeSum, - pub vocdd: ComputedFromHeightCumulativeSum, + pub cointime_value_destroyed: ComputedPerBlockCumulativeSum, + pub cointime_value_created: ComputedPerBlockCumulativeSum, + pub cointime_value_stored: ComputedPerBlockCumulativeSum, + pub vocdd: ComputedPerBlockCumulativeSum, } diff --git a/crates/brk_computer/src/distribution/address/activity.rs b/crates/brk_computer/src/distribution/address/activity.rs index d9a8bffb1..911eee0e3 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::{ComputedFromHeightRollingAverage, WindowStarts}, + internal::{ComputedPerBlockRollingAverage, WindowStarts}, }; /// 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: ComputedFromHeightRollingAverage, - pub sending: ComputedFromHeightRollingAverage, - pub receiving: ComputedFromHeightRollingAverage, - pub both: ComputedFromHeightRollingAverage, + pub reactivated: ComputedPerBlockRollingAverage, + pub sending: ComputedPerBlockRollingAverage, + pub receiving: ComputedPerBlockRollingAverage, + pub both: ComputedPerBlockRollingAverage, } impl ActivityCountVecs { @@ -79,25 +79,25 @@ impl ActivityCountVecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - reactivated: ComputedFromHeightRollingAverage::forced_import( + reactivated: ComputedPerBlockRollingAverage::forced_import( db, &format!("{name}_reactivated"), version, indexes, )?, - sending: ComputedFromHeightRollingAverage::forced_import( + sending: ComputedPerBlockRollingAverage::forced_import( db, &format!("{name}_sending"), version, indexes, )?, - receiving: ComputedFromHeightRollingAverage::forced_import( + receiving: ComputedPerBlockRollingAverage::forced_import( db, &format!("{name}_receiving"), version, indexes, )?, - both: ComputedFromHeightRollingAverage::forced_import( + both: ComputedPerBlockRollingAverage::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 3fa8a6f6c..86be4525f 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::ComputedFromHeight}; +use crate::{indexes, internal::ComputedPerBlock}; #[derive(Deref, DerefMut, Traversable)] pub struct AddrCountVecs( - #[traversable(flatten)] pub ComputedFromHeight, + #[traversable(flatten)] pub ComputedPerBlock, ); impl AddrCountVecs { @@ -23,7 +23,7 @@ impl AddrCountVecs { version: Version, indexes: &indexes::Vecs, ) -> Result { - Ok(Self(ComputedFromHeight::forced_import( + Ok(Self(ComputedPerBlock::forced_import( db, name, version, indexes, )?)) } diff --git a/crates/brk_computer/src/distribution/address/new_addr_count.rs b/crates/brk_computer/src/distribution/address/new_addr_count.rs index 320e93884..ce8563faf 100644 --- a/crates/brk_computer/src/distribution/address/new_addr_count.rs +++ b/crates/brk_computer/src/distribution/address/new_addr_count.rs @@ -6,7 +6,7 @@ use vecdb::{Database, Exit, Rw, StorageMode}; use crate::{ indexes, - internal::{ComputedFromHeightSum, WindowStarts}, + internal::{ComputedPerBlockSum, WindowStarts}, }; use super::TotalAddrCountVecs; @@ -14,9 +14,9 @@ use super::TotalAddrCountVecs; /// New address count per block (global + per-type) #[derive(Traversable)] pub struct NewAddrCountVecs { - pub all: ComputedFromHeightSum, + pub all: ComputedPerBlockSum, #[traversable(flatten)] - pub by_addresstype: ByAddressType>, + pub by_addresstype: ByAddressType>, } impl NewAddrCountVecs { @@ -25,11 +25,11 @@ impl NewAddrCountVecs { version: Version, indexes: &indexes::Vecs, ) -> Result { - let all = ComputedFromHeightSum::forced_import(db, "new_addr_count", version, indexes)?; + let all = ComputedPerBlockSum::forced_import(db, "new_addr_count", version, indexes)?; - let by_addresstype: ByAddressType> = + let by_addresstype: ByAddressType> = ByAddressType::new_with_name(|name| { - ComputedFromHeightSum::forced_import( + ComputedPerBlockSum::forced_import( db, &format!("{name}_new_addr_count"), version, diff --git a/crates/brk_computer/src/distribution/address/total_addr_count.rs b/crates/brk_computer/src/distribution/address/total_addr_count.rs index d6c7c9c89..e7a72917e 100644 --- a/crates/brk_computer/src/distribution/address/total_addr_count.rs +++ b/crates/brk_computer/src/distribution/address/total_addr_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::ComputedFromHeight}; +use crate::{indexes, internal::ComputedPerBlock}; use super::AddrCountsVecs; /// Total address count (global + per-type) with all derived indexes #[derive(Traversable)] pub struct TotalAddrCountVecs { - pub all: ComputedFromHeight, + pub all: ComputedPerBlock, #[traversable(flatten)] - pub by_addresstype: ByAddressType>, + pub by_addresstype: ByAddressType>, } impl TotalAddrCountVecs { @@ -22,11 +22,11 @@ impl TotalAddrCountVecs { version: Version, indexes: &indexes::Vecs, ) -> Result { - let all = ComputedFromHeight::forced_import(db, "total_addr_count", version, indexes)?; + let all = ComputedPerBlock::forced_import(db, "total_addr_count", version, indexes)?; - let by_addresstype: ByAddressType> = + let by_addresstype: ByAddressType> = ByAddressType::new_with_name(|name| { - ComputedFromHeight::forced_import( + ComputedPerBlock::forced_import( db, &format!("{name}_total_addr_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 86cbf7343..b93a21150 100644 --- a/crates/brk_computer/src/distribution/cohorts/address/vecs.rs +++ b/crates/brk_computer/src/distribution/cohorts/address/vecs.rs @@ -11,7 +11,7 @@ use crate::{ blocks, distribution::state::{AddressCohortState, MinimalRealizedState}, indexes, - internal::{ComputedFromHeight, RollingDelta1m}, + internal::{ComputedPerBlock, RollingDelta1m}, prices, }; @@ -28,7 +28,7 @@ pub struct AddressCohortVecs { #[traversable(flatten)] pub metrics: MinimalCohortMetrics, - pub addr_count: ComputedFromHeight, + pub addr_count: ComputedPerBlock, pub addr_count_delta: RollingDelta1m, } @@ -58,7 +58,7 @@ impl AddressCohortVecs { metrics: MinimalCohortMetrics::forced_import(&cfg)?, - addr_count: ComputedFromHeight::forced_import( + addr_count: ComputedPerBlock::forced_import( db, &cfg.name("addr_count"), version, diff --git a/crates/brk_computer/src/distribution/cohorts/utxo/groups.rs b/crates/brk_computer/src/distribution/cohorts/utxo/groups.rs index 312cb833a..6bdc0ad32 100644 --- a/crates/brk_computer/src/distribution/cohorts/utxo/groups.rs +++ b/crates/brk_computer/src/distribution/cohorts/utxo/groups.rs @@ -24,7 +24,7 @@ use crate::{ state::UTXOCohortState, }, indexes, - internal::AmountFromHeight, + internal::AmountPerBlock, prices, }; @@ -49,7 +49,7 @@ pub struct UTXOCohorts { #[traversable(rename = "type")] pub type_: BySpendableType>>, pub profitability: ProfitabilityMetrics, - pub matured: ByAgeRange>, + pub matured: ByAgeRange>, #[traversable(skip)] pub(super) fenwick: CostBasisFenwick, /// Cached partition_point positions for tick_tock boundary searches. @@ -230,8 +230,8 @@ impl UTXOCohorts { let matured = ByAgeRange::try_new(&|_f: Filter, name: &'static str| - -> Result { - AmountFromHeight::forced_import(db, &format!("utxo_{name}_matured"), v, indexes) + -> Result { + AmountPerBlock::forced_import(db, &format!("utxo_{name}_matured"), v, indexes) })?; Ok(Self { diff --git a/crates/brk_computer/src/distribution/metrics/activity/base.rs b/crates/brk_computer/src/distribution/metrics/activity/base.rs index 192e4beba..ab5056738 100644 --- a/crates/brk_computer/src/distribution/metrics/activity/base.rs +++ b/crates/brk_computer/src/distribution/metrics/activity/base.rs @@ -4,7 +4,7 @@ use brk_types::{Bitcoin, Height, Indexes, Sats, StoredF64, Version}; use derive_more::{Deref, DerefMut}; use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec}; -use crate::internal::ComputedFromHeight; +use crate::internal::ComputedPerBlock; use crate::{blocks, distribution::metrics::ImportConfig}; @@ -17,8 +17,8 @@ pub struct ActivityBase { #[traversable(flatten)] pub core: ActivityCore, - pub coinblocks_destroyed: ComputedFromHeight, - pub coindays_destroyed: ComputedFromHeight, + pub coinblocks_destroyed: ComputedPerBlock, + pub coindays_destroyed: ComputedPerBlock, } impl ActivityBase { diff --git a/crates/brk_computer/src/distribution/metrics/activity/core.rs b/crates/brk_computer/src/distribution/metrics/activity/core.rs index fafa6ac0a..ea9c7c48e 100644 --- a/crates/brk_computer/src/distribution/metrics/activity/core.rs +++ b/crates/brk_computer/src/distribution/metrics/activity/core.rs @@ -3,13 +3,13 @@ use brk_traversable::Traversable; use brk_types::{Height, Indexes, Sats, Version}; use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec}; -use crate::internal::{ComputedFromHeight, RollingWindow24h}; +use crate::internal::{ComputedPerBlock, RollingWindow24h}; use crate::{blocks, distribution::metrics::ImportConfig}; #[derive(Traversable)] pub struct ActivityCore { - pub sent: ComputedFromHeight, + pub sent: ComputedPerBlock, pub sent_sum: RollingWindow24h, } diff --git a/crates/brk_computer/src/distribution/metrics/activity/full.rs b/crates/brk_computer/src/distribution/metrics/activity/full.rs index eaca5f4a2..4f39ae9b4 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::{Indexes, Sats, StoredF64, Version}; use derive_more::{Deref, DerefMut}; use vecdb::{Exit, Rw, StorageMode}; -use crate::internal::{ComputedFromHeight, RollingWindows, RollingWindowsFrom1w}; +use crate::internal::{ComputedPerBlock, RollingWindows, RollingWindowsFrom1w}; use crate::{blocks, distribution::metrics::ImportConfig}; @@ -17,8 +17,8 @@ pub struct ActivityFull { #[traversable(flatten)] pub inner: ActivityBase, - pub coinblocks_destroyed_cumulative: ComputedFromHeight, - pub coindays_destroyed_cumulative: ComputedFromHeight, + pub coinblocks_destroyed_cumulative: ComputedPerBlock, + pub coindays_destroyed_cumulative: ComputedPerBlock, pub coindays_destroyed_sum: RollingWindows, #[traversable(rename = "sent_sum")] diff --git a/crates/brk_computer/src/distribution/metrics/cohort/all.rs b/crates/brk_computer/src/distribution/metrics/cohort/all.rs index 784a3d99d..e5fd2d998 100644 --- a/crates/brk_computer/src/distribution/metrics/cohort/all.rs +++ b/crates/brk_computer/src/distribution/metrics/cohort/all.rs @@ -10,7 +10,7 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode}; use crate::{blocks, prices}; -use crate::internal::{ComputedFromHeight, RollingDeltaExcept1m}; +use crate::internal::{ComputedPerBlock, RollingDeltaExcept1m}; use crate::distribution::metrics::{ ActivityFull, CohortMetricsBase, CostBasis, ImportConfig, OutputsMetrics, @@ -32,8 +32,8 @@ pub struct AllCohortMetrics { pub unrealized: Box>, pub adjusted: Box>, pub relative: Box>, - pub dormancy: ComputedFromHeight, - pub velocity: ComputedFromHeight, + pub dormancy: ComputedPerBlock, + pub velocity: ComputedPerBlock, #[traversable(wrap = "supply", rename = "delta")] pub supply_delta_extended: RollingDeltaExcept1m, diff --git a/crates/brk_computer/src/distribution/metrics/cohort/extended.rs b/crates/brk_computer/src/distribution/metrics/cohort/extended.rs index a0253f9e6..09290840f 100644 --- a/crates/brk_computer/src/distribution/metrics/cohort/extended.rs +++ b/crates/brk_computer/src/distribution/metrics/cohort/extended.rs @@ -9,7 +9,7 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode}; use crate::{blocks, prices}; -use crate::internal::{ComputedFromHeight, RollingDeltaExcept1m}; +use crate::internal::{ComputedPerBlock, RollingDeltaExcept1m}; use crate::distribution::metrics::{ ActivityFull, CohortMetricsBase, CostBasis, ImportConfig, OutputsMetrics, @@ -29,8 +29,8 @@ pub struct ExtendedCohortMetrics { pub cost_basis: Box>, pub unrealized: Box>, pub relative: Box>, - pub dormancy: ComputedFromHeight, - pub velocity: ComputedFromHeight, + pub dormancy: ComputedPerBlock, + pub velocity: ComputedPerBlock, #[traversable(wrap = "supply", rename = "delta")] pub supply_delta_extended: RollingDeltaExcept1m, diff --git a/crates/brk_computer/src/distribution/metrics/config.rs b/crates/brk_computer/src/distribution/metrics/config.rs index a889aeb25..e6051dc39 100644 --- a/crates/brk_computer/src/distribution/metrics/config.rs +++ b/crates/brk_computer/src/distribution/metrics/config.rs @@ -7,10 +7,10 @@ use vecdb::{BytesVec, BytesVecValue, Database, ImportableVec}; use crate::{ indexes, internal::{ - AmountFromHeight, AmountFromHeightCumulative, CentsType, ComputedFromHeight, - ComputedFromHeightCumulative, ComputedFromHeightCumulativeSum, ComputedFromHeightRatio, - FiatFromHeight, FiatRollingDelta1m, FiatRollingDeltaExcept1m, NumericValue, - PercentFromHeight, PercentRollingWindows, Price, RollingDelta1m, RollingDeltaExcept1m, + AmountPerBlock, AmountPerBlockCumulative, CentsType, ComputedPerBlock, + ComputedPerBlockCumulative, ComputedPerBlockCumulativeSum, RatioPerBlock, + FiatPerBlock, FiatRollingDelta1m, FiatRollingDeltaExcept1m, NumericValue, + PercentPerBlock, PercentRollingWindows, Price, RollingDelta1m, RollingDeltaExcept1m, RollingWindow24h, RollingWindows, RollingWindowsFrom1w, }, }; @@ -35,28 +35,28 @@ macro_rules! impl_config_import { // Non-generic types impl_config_import!( - AmountFromHeight, - AmountFromHeightCumulative, - ComputedFromHeightRatio, - PercentFromHeight, - PercentFromHeight, - PercentFromHeight, + AmountPerBlock, + AmountPerBlockCumulative, + RatioPerBlock, + PercentPerBlock, + PercentPerBlock, + PercentPerBlock, PercentRollingWindows, - Price>, + Price>, ); // Generic types (macro_rules can't parse generic bounds, so written out) -impl ConfigImport for ComputedFromHeight { +impl ConfigImport for ComputedPerBlock { 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 ComputedFromHeightCumulative { +impl ConfigImport for ComputedPerBlockCumulative { 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 ComputedFromHeightCumulativeSum { +impl ConfigImport for ComputedPerBlockCumulativeSum { fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result { Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) } @@ -76,7 +76,7 @@ impl ConfigImport for RollingWindowsFrom1w { Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) } } -impl ConfigImport for FiatFromHeight { +impl ConfigImport for FiatPerBlock { fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result { Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes) } 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 df85318a3..782675161 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::{Cents, Height, Version}; use vecdb::{AnyStoredVec, AnyVec, Rw, StorageMode, WritableVec}; -use crate::internal::{ComputedFromHeight, PercentilesVecs, Price, PERCENTILES_LEN}; +use crate::internal::{ComputedPerBlock, 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, } diff --git a/crates/brk_computer/src/distribution/metrics/outputs.rs b/crates/brk_computer/src/distribution/metrics/outputs.rs index 7894ea7d5..6dacc7130 100644 --- a/crates/brk_computer/src/distribution/metrics/outputs.rs +++ b/crates/brk_computer/src/distribution/metrics/outputs.rs @@ -3,14 +3,14 @@ use brk_traversable::Traversable; use brk_types::{Height, Indexes, StoredI64, StoredU64, Version}; use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec}; -use crate::{blocks, internal::{ComputedFromHeight, RollingDelta1m}}; +use crate::{blocks, internal::{ComputedPerBlock, RollingDelta1m}}; use super::ImportConfig; /// Output metrics for a cohort. #[derive(Traversable)] pub struct OutputsMetrics { - pub utxo_count: ComputedFromHeight, + pub utxo_count: ComputedPerBlock, pub utxo_count_delta: RollingDelta1m, } diff --git a/crates/brk_computer/src/distribution/metrics/profitability.rs b/crates/brk_computer/src/distribution/metrics/profitability.rs index 4695a2976..3b314cc90 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::ComputedFromHeight}; +use crate::{indexes, internal::ComputedPerBlock}; /// Supply + realized cap for a single profitability bucket. #[derive(Traversable)] pub struct ProfitabilityBucket { - pub supply: ComputedFromHeight, - pub realized_cap: ComputedFromHeight, + pub supply: ComputedPerBlock, + pub realized_cap: ComputedPerBlock, } impl ProfitabilityBucket { @@ -27,13 +27,13 @@ impl ProfitabilityBucket { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - supply: ComputedFromHeight::forced_import( + supply: ComputedPerBlock::forced_import( db, &format!("{name}_supply"), version, indexes, )?, - realized_cap: ComputedFromHeight::forced_import( + realized_cap: ComputedPerBlock::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 62c406a4e..a17377706 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs @@ -5,15 +5,15 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode}; use crate::{ blocks, - internal::{ComputedFromHeight, RatioCents64, RollingWindows}, + internal::{ComputedPerBlock, RatioCents64, RollingWindows}, }; use crate::distribution::metrics::ImportConfig; #[derive(Traversable)] pub struct RealizedAdjusted { - pub value_created: ComputedFromHeight, - pub value_destroyed: ComputedFromHeight, + pub value_created: ComputedPerBlock, + pub value_destroyed: ComputedPerBlock, pub value_created_sum: RollingWindows, pub value_destroyed_sum: RollingWindows, pub sopr: RollingWindows, diff --git a/crates/brk_computer/src/distribution/metrics/realized/base.rs b/crates/brk_computer/src/distribution/metrics/realized/base.rs index 014bed5b4..f76960c18 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/base.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/base.rs @@ -7,7 +7,7 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec}; use crate::{ blocks, distribution::state::RealizedOps, - internal::{ComputedFromHeight, RollingWindow24h}, + internal::{ComputedPerBlock, RollingWindow24h}, }; use crate::distribution::metrics::ImportConfig; @@ -21,8 +21,8 @@ pub struct RealizedBase { #[traversable(flatten)] pub core: RealizedCore, - pub sent_in_profit: ComputedFromHeight, - pub sent_in_loss: ComputedFromHeight, + pub sent_in_profit: ComputedPerBlock, + pub sent_in_loss: ComputedPerBlock, pub sent_in_profit_sum: RollingWindow24h, pub sent_in_loss_sum: RollingWindow24h, diff --git a/crates/brk_computer/src/distribution/metrics/realized/core.rs b/crates/brk_computer/src/distribution/metrics/realized/core.rs index 69e30ece9..605194b7f 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/core.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/core.rs @@ -10,7 +10,7 @@ use crate::{ blocks, distribution::state::RealizedOps, internal::{ - ComputedFromHeight, FiatRollingDelta1m, LazyFromHeight, NegCentsUnsignedToDollars, + ComputedPerBlock, FiatRollingDelta1m, LazyPerBlock, NegCentsUnsignedToDollars, RatioCents64, RollingWindow24h, }, prices, @@ -29,12 +29,12 @@ pub struct RealizedCore { pub realized_cap_delta: FiatRollingDelta1m, - pub neg_realized_loss: LazyFromHeight, - pub net_realized_pnl: ComputedFromHeight, + pub neg_realized_loss: LazyPerBlock, + pub net_realized_pnl: ComputedPerBlock, pub net_realized_pnl_sum: RollingWindow24h, - pub value_created: ComputedFromHeight, - pub value_destroyed: ComputedFromHeight, + pub value_created: ComputedPerBlock, + pub value_destroyed: ComputedPerBlock, pub value_created_sum: RollingWindow24h, pub value_destroyed_sum: RollingWindow24h, pub sopr: RollingWindow24h, @@ -47,7 +47,7 @@ impl RealizedCore { let minimal = RealizedMinimal::forced_import(cfg)?; - let neg_realized_loss = LazyFromHeight::from_height_source::( + let neg_realized_loss = LazyPerBlock::from_height_source::( &cfg.name("neg_realized_loss"), cfg.version + Version::ONE, minimal.realized_loss.height.read_only_boxed_clone(), diff --git a/crates/brk_computer/src/distribution/metrics/realized/full.rs b/crates/brk_computer/src/distribution/metrics/realized/full.rs index 4f03c2c5e..29424f0d2 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/full.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/full.rs @@ -14,10 +14,10 @@ use crate::{ blocks, distribution::state::RealizedState, internal::{ - CentsUnsignedToDollars, ComputedFromHeight, ComputedFromHeightCumulative, - ComputedFromHeightRatio, ComputedFromHeightRatioPercentiles, - ComputedFromHeightRatioStdDevBands, FiatFromHeight, FiatRollingDelta1m, - FiatRollingDeltaExcept1m, LazyFromHeight, PercentFromHeight, PercentRollingWindows, Price, + CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative, + RatioPerBlock, RatioPerBlockPercentiles, + RatioPerBlockStdDevBands, FiatPerBlock, FiatRollingDelta1m, + FiatRollingDeltaExcept1m, LazyPerBlock, PercentPerBlock, PercentRollingWindows, Price, RatioCents64, RatioCentsBp32, RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32, RollingWindows, RollingWindowsFrom1w, }, @@ -35,55 +35,55 @@ pub struct RealizedFull { #[traversable(flatten)] pub base: RealizedBase, - pub gross_pnl: FiatFromHeight, + pub gross_pnl: FiatPerBlock, - pub realized_profit_rel_to_realized_cap: PercentFromHeight, - pub realized_loss_rel_to_realized_cap: PercentFromHeight, - pub net_realized_pnl_rel_to_realized_cap: PercentFromHeight, + pub realized_profit_rel_to_realized_cap: PercentPerBlock, + pub realized_loss_rel_to_realized_cap: PercentPerBlock, + pub net_realized_pnl_rel_to_realized_cap: PercentPerBlock, - pub profit_value_created: ComputedFromHeight, - pub profit_value_destroyed: ComputedFromHeight, - pub loss_value_created: ComputedFromHeight, - pub loss_value_destroyed: ComputedFromHeight, + pub profit_value_created: ComputedPerBlock, + pub profit_value_destroyed: ComputedPerBlock, + pub loss_value_created: ComputedPerBlock, + pub loss_value_destroyed: ComputedPerBlock, pub profit_value_created_sum: RollingWindows, pub profit_value_destroyed_sum: RollingWindows, pub loss_value_created_sum: RollingWindows, pub loss_value_destroyed_sum: RollingWindows, - pub capitulation_flow: LazyFromHeight, - pub profit_flow: LazyFromHeight, + pub capitulation_flow: LazyPerBlock, + pub profit_flow: LazyPerBlock, pub gross_pnl_sum: RollingWindows, - pub net_realized_pnl_cumulative: ComputedFromHeight, + pub net_realized_pnl_cumulative: ComputedPerBlock, #[traversable(rename = "net_realized_pnl_sum")] pub net_realized_pnl_sum_extended: RollingWindowsFrom1w, pub net_pnl_delta: FiatRollingDelta1m, #[traversable(rename = "net_pnl_delta")] pub net_pnl_delta_extended: FiatRollingDeltaExcept1m, - pub net_pnl_change_1m_rel_to_realized_cap: PercentFromHeight, - pub net_pnl_change_1m_rel_to_market_cap: PercentFromHeight, + pub net_pnl_change_1m_rel_to_realized_cap: PercentPerBlock, + pub net_pnl_change_1m_rel_to_market_cap: PercentPerBlock, #[traversable(rename = "realized_cap_delta")] pub realized_cap_delta_extended: FiatRollingDeltaExcept1m, - pub investor_price: Price>, - pub investor_price_ratio: ComputedFromHeightRatio, + pub investor_price: Price>, + pub investor_price_ratio: RatioPerBlock, - pub lower_price_band: Price>, - pub upper_price_band: Price>, + pub lower_price_band: Price>, + pub upper_price_band: Price>, pub cap_raw: M::Stored>, pub investor_cap_raw: M::Stored>, pub sell_side_risk_ratio: PercentRollingWindows, - pub peak_regret: ComputedFromHeightCumulative, - pub peak_regret_rel_to_realized_cap: PercentFromHeight, + pub peak_regret: ComputedPerBlockCumulative, + pub peak_regret_rel_to_realized_cap: PercentPerBlock, - pub realized_cap_rel_to_own_market_cap: PercentFromHeight, + pub realized_cap_rel_to_own_market_cap: PercentPerBlock, #[traversable(rename = "realized_profit_sum")] pub realized_profit_sum_extended: RollingWindowsFrom1w, @@ -103,9 +103,9 @@ pub struct RealizedFull { #[traversable(rename = "sent_in_loss_sum")] pub sent_in_loss_sum_extended: RollingWindowsFrom1w, - pub realized_price_ratio_percentiles: ComputedFromHeightRatioPercentiles, - pub realized_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands, - pub investor_price_ratio_percentiles: ComputedFromHeightRatioPercentiles, + pub realized_price_ratio_percentiles: RatioPerBlockPercentiles, + pub realized_price_ratio_std_dev: RatioPerBlockStdDevBands, + pub investor_price_ratio_percentiles: RatioPerBlockPercentiles, } impl RealizedFull { @@ -118,10 +118,10 @@ impl RealizedFull { let gross_pnl = cfg.import("realized_gross_pnl", v0)?; let profit_value_created = cfg.import("profit_value_created", v0)?; - let profit_value_destroyed: ComputedFromHeight = + let profit_value_destroyed: ComputedPerBlock = cfg.import("profit_value_destroyed", v0)?; let loss_value_created = cfg.import("loss_value_created", v0)?; - let loss_value_destroyed: ComputedFromHeight = + let loss_value_destroyed: ComputedPerBlock = cfg.import("loss_value_destroyed", v0)?; let profit_value_created_sum = cfg.import("profit_value_created", v1)?; @@ -129,13 +129,13 @@ impl RealizedFull { let loss_value_created_sum = cfg.import("loss_value_created", v1)?; let loss_value_destroyed_sum = cfg.import("loss_value_destroyed", v1)?; - let capitulation_flow = LazyFromHeight::from_computed::( + let capitulation_flow = LazyPerBlock::from_computed::( &cfg.name("capitulation_flow"), cfg.version, loss_value_destroyed.height.read_only_boxed_clone(), &loss_value_destroyed, ); - let profit_flow = LazyFromHeight::from_computed::( + let profit_flow = LazyPerBlock::from_computed::( &cfg.name("profit_flow"), cfg.version, profit_value_destroyed.height.read_only_boxed_clone(), @@ -221,19 +221,19 @@ impl RealizedFull { sopr_extended, sent_in_profit_sum_extended: cfg.import("sent_in_profit", v1)?, sent_in_loss_sum_extended: cfg.import("sent_in_loss", v1)?, - realized_price_ratio_percentiles: ComputedFromHeightRatioPercentiles::forced_import( + realized_price_ratio_percentiles: RatioPerBlockPercentiles::forced_import( cfg.db, &realized_price_name, realized_price_version, cfg.indexes, )?, - realized_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands::forced_import( + realized_price_ratio_std_dev: RatioPerBlockStdDevBands::forced_import( cfg.db, &realized_price_name, realized_price_version, cfg.indexes, )?, - investor_price_ratio_percentiles: ComputedFromHeightRatioPercentiles::forced_import( + investor_price_ratio_percentiles: RatioPerBlockPercentiles::forced_import( cfg.db, &investor_price_name, investor_price_version, diff --git a/crates/brk_computer/src/distribution/metrics/realized/minimal.rs b/crates/brk_computer/src/distribution/metrics/realized/minimal.rs index ac0e2dc58..3d147f27f 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/minimal.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/minimal.rs @@ -9,8 +9,8 @@ use crate::{ blocks, distribution::state::RealizedOps, internal::{ - CentsUnsignedToDollars, ComputedFromHeight, ComputedFromHeightCumulative, - ComputedFromHeightRatio, Identity, LazyFromHeight, Price, RollingWindow24h, + CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative, + RatioPerBlock, Identity, LazyPerBlock, Price, RollingWindow24h, }, prices, }; @@ -19,13 +19,13 @@ use crate::distribution::metrics::ImportConfig; #[derive(Traversable)] pub struct RealizedMinimal { - pub realized_cap_cents: ComputedFromHeight, - pub realized_profit: ComputedFromHeightCumulative, - pub realized_loss: ComputedFromHeightCumulative, - pub realized_cap: LazyFromHeight, - pub realized_price: Price>, - pub realized_price_ratio: ComputedFromHeightRatio, - pub mvrv: LazyFromHeight, + pub realized_cap_cents: ComputedPerBlock, + pub realized_profit: ComputedPerBlockCumulative, + pub realized_loss: ComputedPerBlockCumulative, + pub realized_cap: LazyPerBlock, + pub realized_price: Price>, + pub realized_price_ratio: RatioPerBlock, + pub mvrv: LazyPerBlock, pub realized_profit_sum: RollingWindow24h, pub realized_loss_sum: RollingWindow24h, @@ -33,9 +33,9 @@ pub struct RealizedMinimal { impl RealizedMinimal { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { - let realized_cap_cents: ComputedFromHeight = + let realized_cap_cents: ComputedPerBlock = cfg.import("realized_cap_cents", Version::ZERO)?; - let realized_cap = LazyFromHeight::from_computed::( + let realized_cap = LazyPerBlock::from_computed::( &cfg.name("realized_cap"), cfg.version, realized_cap_cents.height.read_only_boxed_clone(), @@ -46,9 +46,9 @@ impl RealizedMinimal { let realized_loss = cfg.import("realized_loss", Version::ZERO)?; let realized_price = cfg.import("realized_price", Version::ONE)?; - let realized_price_ratio: ComputedFromHeightRatio = + let realized_price_ratio: RatioPerBlock = cfg.import("realized_price", Version::ONE)?; - let mvrv = LazyFromHeight::from_lazy::, BasisPoints32>( + let mvrv = LazyPerBlock::from_lazy::, BasisPoints32>( &cfg.name("mvrv"), cfg.version, &realized_price_ratio.ratio, 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 5d5795a5b..e2e8b17da 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 @@ -3,16 +3,16 @@ use brk_traversable::Traversable; use brk_types::{BasisPoints16, BasisPoints32, BasisPointsSigned32, Dollars, Height, Version}; use vecdb::{Exit, ReadableVec, Rw, StorageMode}; -use crate::internal::{PercentFromHeight, RatioDollarsBp16, RatioDollarsBp32, RatioDollarsBps32}; +use crate::internal::{PercentPerBlock, RatioDollarsBp16, RatioDollarsBp32, RatioDollarsBps32}; use crate::distribution::metrics::{ImportConfig, UnrealizedCore}; /// Extended relative metrics for own market cap (extended && rel_to_all). #[derive(Traversable)] pub struct RelativeExtendedOwnMarketCap { - pub unrealized_profit_rel_to_own_market_cap: PercentFromHeight, - pub unrealized_loss_rel_to_own_market_cap: PercentFromHeight, - pub net_unrealized_pnl_rel_to_own_market_cap: PercentFromHeight, + pub unrealized_profit_rel_to_own_market_cap: PercentPerBlock, + pub unrealized_loss_rel_to_own_market_cap: PercentPerBlock, + pub net_unrealized_pnl_rel_to_own_market_cap: PercentPerBlock, } impl RelativeExtendedOwnMarketCap { 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 134713464..9c70fbc20 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 @@ -3,16 +3,16 @@ use brk_traversable::Traversable; use brk_types::{BasisPoints16, BasisPointsSigned32, Dollars, Height, Version}; use vecdb::{Exit, ReadableVec, Rw, StorageMode}; -use crate::internal::{PercentFromHeight, RatioDollarsBp16, RatioDollarsBps32}; +use crate::internal::{PercentPerBlock, RatioDollarsBp16, RatioDollarsBps32}; use crate::distribution::metrics::{ImportConfig, UnrealizedCore}; /// Extended relative metrics for own total unrealized PnL (extended only). #[derive(Traversable)] pub struct RelativeExtendedOwnPnl { - pub unrealized_profit_rel_to_own_gross_pnl: PercentFromHeight, - pub unrealized_loss_rel_to_own_gross_pnl: PercentFromHeight, - pub net_unrealized_pnl_rel_to_own_gross_pnl: PercentFromHeight, + pub unrealized_profit_rel_to_own_gross_pnl: PercentPerBlock, + pub unrealized_loss_rel_to_own_gross_pnl: PercentPerBlock, + pub net_unrealized_pnl_rel_to_own_gross_pnl: PercentPerBlock, } impl RelativeExtendedOwnPnl { diff --git a/crates/brk_computer/src/distribution/metrics/relative/full.rs b/crates/brk_computer/src/distribution/metrics/relative/full.rs index e499e1695..3eb809f9e 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/full.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/full.rs @@ -6,7 +6,7 @@ use brk_types::{ use vecdb::{Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode}; use crate::internal::{ - Bps32ToFloat, LazyFromHeight, PercentFromHeight, RatioDollarsBp16, RatioDollarsBps32, + Bps32ToFloat, LazyPerBlock, PercentPerBlock, RatioDollarsBp16, RatioDollarsBps32, RatioSatsBp16, }; @@ -15,13 +15,13 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedCore}; /// Full relative metrics (sth/lth/all tier). #[derive(Traversable)] pub struct RelativeFull { - pub supply_in_profit_rel_to_own_supply: PercentFromHeight, - pub supply_in_loss_rel_to_own_supply: PercentFromHeight, + pub supply_in_profit_rel_to_own_supply: PercentPerBlock, + pub supply_in_loss_rel_to_own_supply: PercentPerBlock, - pub unrealized_profit_rel_to_market_cap: PercentFromHeight, - pub unrealized_loss_rel_to_market_cap: PercentFromHeight, - pub net_unrealized_pnl_rel_to_market_cap: PercentFromHeight, - pub nupl: LazyFromHeight, + pub unrealized_profit_rel_to_market_cap: PercentPerBlock, + pub unrealized_loss_rel_to_market_cap: PercentPerBlock, + pub net_unrealized_pnl_rel_to_market_cap: PercentPerBlock, + pub nupl: LazyPerBlock, } impl RelativeFull { @@ -30,10 +30,10 @@ impl RelativeFull { let v2 = Version::new(2); let v3 = Version::new(3); - let net_unrealized_pnl_rel_to_market_cap: PercentFromHeight = + let net_unrealized_pnl_rel_to_market_cap: PercentPerBlock = cfg.import("net_unrealized_pnl_rel_to_market_cap", v3)?; - let nupl = LazyFromHeight::from_computed::( + let nupl = LazyPerBlock::from_computed::( &cfg.name("nupl"), cfg.version + v3, net_unrealized_pnl_rel_to_market_cap diff --git a/crates/brk_computer/src/distribution/metrics/relative/to_all.rs b/crates/brk_computer/src/distribution/metrics/relative/to_all.rs index c4116c2e6..e9a4ea96f 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/to_all.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/to_all.rs @@ -3,16 +3,16 @@ use brk_traversable::Traversable; use brk_types::{BasisPoints16, Height, Sats, Version}; use vecdb::{Exit, ReadableVec, Rw, StorageMode}; -use crate::internal::{PercentFromHeight, RatioSatsBp16}; +use crate::internal::{PercentPerBlock, RatioSatsBp16}; use crate::distribution::metrics::ImportConfig; /// Relative-to-all metrics (not present for the "all" cohort itself). #[derive(Traversable)] pub struct RelativeToAll { - pub supply_rel_to_circulating_supply: PercentFromHeight, - pub supply_in_profit_rel_to_circulating_supply: PercentFromHeight, - pub supply_in_loss_rel_to_circulating_supply: PercentFromHeight, + pub supply_rel_to_circulating_supply: PercentPerBlock, + pub supply_in_profit_rel_to_circulating_supply: PercentPerBlock, + pub supply_in_loss_rel_to_circulating_supply: PercentPerBlock, } impl RelativeToAll { diff --git a/crates/brk_computer/src/distribution/metrics/supply.rs b/crates/brk_computer/src/distribution/metrics/supply.rs index 78bbc4079..0637b1685 100644 --- a/crates/brk_computer/src/distribution/metrics/supply.rs +++ b/crates/brk_computer/src/distribution/metrics/supply.rs @@ -6,8 +6,8 @@ use crate::{blocks, prices}; use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec}; use crate::internal::{ - AmountFromHeight, HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin, - LazyAmountFromHeight, RollingDelta1m, + AmountPerBlock, HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin, + LazyAmountPerBlock, RollingDelta1m, }; use super::ImportConfig; @@ -15,8 +15,8 @@ use super::ImportConfig; /// Supply metrics for a cohort. #[derive(Traversable)] pub struct SupplyMetrics { - pub total: AmountFromHeight, - pub halved: LazyAmountFromHeight, + pub total: AmountPerBlock, + pub halved: LazyAmountPerBlock, pub delta: RollingDelta1m, } @@ -25,7 +25,7 @@ impl SupplyMetrics { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { let supply = cfg.import("supply", Version::ZERO)?; - let supply_halved = LazyAmountFromHeight::from_block_source::< + let supply_halved = LazyAmountPerBlock::from_block_source::< HalveSats, HalveSatsToBitcoin, HalveCents, diff --git a/crates/brk_computer/src/distribution/metrics/unrealized/core.rs b/crates/brk_computer/src/distribution/metrics/unrealized/core.rs index bedd726ad..47da18d69 100644 --- a/crates/brk_computer/src/distribution/metrics/unrealized/core.rs +++ b/crates/brk_computer/src/distribution/metrics/unrealized/core.rs @@ -10,7 +10,7 @@ use crate::{ state::UnrealizedState, }, internal::{ - CentsSubtractToCentsSigned, FiatFromHeight, LazyFromHeight, NegCentsUnsignedToDollars, + CentsSubtractToCentsSigned, FiatPerBlock, LazyPerBlock, NegCentsUnsignedToDollars, }, prices, }; @@ -24,12 +24,12 @@ pub struct UnrealizedCore { #[traversable(flatten)] pub minimal: UnrealizedMinimal, - pub unrealized_profit: FiatFromHeight, - pub unrealized_loss: FiatFromHeight, + pub unrealized_profit: FiatPerBlock, + pub unrealized_loss: FiatPerBlock, - pub neg_unrealized_loss: LazyFromHeight, + pub neg_unrealized_loss: LazyPerBlock, - pub net_unrealized_pnl: FiatFromHeight, + pub net_unrealized_pnl: FiatPerBlock, } impl UnrealizedCore { @@ -39,9 +39,9 @@ impl UnrealizedCore { let minimal = UnrealizedMinimal::forced_import(cfg)?; let unrealized_profit = cfg.import("unrealized_profit", v0)?; - let unrealized_loss: FiatFromHeight = cfg.import("unrealized_loss", v0)?; + let unrealized_loss: FiatPerBlock = cfg.import("unrealized_loss", v0)?; - let neg_unrealized_loss = LazyFromHeight::from_computed::( + let neg_unrealized_loss = LazyPerBlock::from_computed::( &cfg.name("neg_unrealized_loss"), cfg.version, unrealized_loss.cents.height.read_only_boxed_clone(), diff --git a/crates/brk_computer/src/distribution/metrics/unrealized/full.rs b/crates/brk_computer/src/distribution/metrics/unrealized/full.rs index 92e097d56..5fc36dbac 100644 --- a/crates/brk_computer/src/distribution/metrics/unrealized/full.rs +++ b/crates/brk_computer/src/distribution/metrics/unrealized/full.rs @@ -5,7 +5,7 @@ use derive_more::{Deref, DerefMut}; use vecdb::{AnyStoredVec, Exit, Rw, StorageMode, WritableVec}; use crate::distribution::state::UnrealizedState; -use crate::internal::{CentsSubtractToCentsSigned, FiatFromHeight}; +use crate::internal::{CentsSubtractToCentsSigned, FiatPerBlock}; use crate::{distribution::metrics::ImportConfig, prices}; use super::UnrealizedBase; @@ -17,13 +17,13 @@ pub struct UnrealizedFull { #[traversable(flatten)] pub inner: UnrealizedBase, - pub gross_pnl: FiatFromHeight, - pub invested_capital_in_profit: FiatFromHeight, - pub invested_capital_in_loss: FiatFromHeight, + pub gross_pnl: FiatPerBlock, + pub invested_capital_in_profit: FiatPerBlock, + pub invested_capital_in_loss: FiatPerBlock, - pub pain_index: FiatFromHeight, - pub greed_index: FiatFromHeight, - pub net_sentiment: FiatFromHeight, + pub pain_index: FiatPerBlock, + pub greed_index: FiatPerBlock, + pub net_sentiment: FiatPerBlock, } impl UnrealizedFull { diff --git a/crates/brk_computer/src/distribution/metrics/unrealized/minimal.rs b/crates/brk_computer/src/distribution/metrics/unrealized/minimal.rs index c60b06850..68f27e99b 100644 --- a/crates/brk_computer/src/distribution/metrics/unrealized/minimal.rs +++ b/crates/brk_computer/src/distribution/metrics/unrealized/minimal.rs @@ -5,15 +5,15 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec}; use crate::prices; -use crate::internal::AmountFromHeight; +use crate::internal::AmountPerBlock; use crate::distribution::{metrics::ImportConfig, state::UnrealizedState}; /// Minimal unrealized metrics: supply in profit/loss only. #[derive(Traversable)] pub struct UnrealizedMinimal { - pub supply_in_profit: AmountFromHeight, - pub supply_in_loss: AmountFromHeight, + pub supply_in_profit: AmountPerBlock, + pub supply_in_loss: AmountPerBlock, } impl UnrealizedMinimal { diff --git a/crates/brk_computer/src/indexes/difficultyepoch.rs b/crates/brk_computer/src/indexes/difficulty.rs similarity index 100% rename from crates/brk_computer/src/indexes/difficultyepoch.rs rename to crates/brk_computer/src/indexes/difficulty.rs diff --git a/crates/brk_computer/src/indexes/halvingepoch.rs b/crates/brk_computer/src/indexes/halving.rs similarity index 100% rename from crates/brk_computer/src/indexes/halvingepoch.rs rename to crates/brk_computer/src/indexes/halving.rs diff --git a/crates/brk_computer/src/indexes/height.rs b/crates/brk_computer/src/indexes/height.rs index db6ce8eab..e3843d973 100644 --- a/crates/brk_computer/src/indexes/height.rs +++ b/crates/brk_computer/src/indexes/height.rs @@ -17,8 +17,8 @@ pub struct Vecs { pub hour12: M::Stored>>, pub day1: M::Stored>>, pub day3: M::Stored>>, - pub difficultyepoch: M::Stored>>, - pub halvingepoch: M::Stored>>, + pub difficulty: M::Stored>>, + pub halving: M::Stored>>, pub week1: M::Stored>>, pub month1: M::Stored>>, pub month3: M::Stored>>, @@ -39,8 +39,8 @@ impl Vecs { hour12: EagerVec::forced_import(db, "hour12", version)?, day1: EagerVec::forced_import(db, "day1", version)?, day3: EagerVec::forced_import(db, "day3", version)?, - difficultyepoch: EagerVec::forced_import(db, "difficultyepoch", version)?, - halvingepoch: EagerVec::forced_import(db, "halvingepoch", version)?, + difficulty: EagerVec::forced_import(db, "difficulty", version)?, + halving: EagerVec::forced_import(db, "halving", version)?, week1: EagerVec::forced_import(db, "week1", version)?, month1: EagerVec::forced_import(db, "month1", version)?, month3: EagerVec::forced_import(db, "month3", version)?, diff --git a/crates/brk_computer/src/indexes/mod.rs b/crates/brk_computer/src/indexes/mod.rs index 0318640e4..4f578127b 100644 --- a/crates/brk_computer/src/indexes/mod.rs +++ b/crates/brk_computer/src/indexes/mod.rs @@ -1,8 +1,8 @@ mod address; mod day1; mod day3; -mod difficultyepoch; -mod halvingepoch; +mod difficulty; +mod halving; mod height; mod hour1; mod hour12; @@ -38,8 +38,8 @@ use crate::{ pub use address::Vecs as AddressVecs; pub use day1::Vecs as Day1Vecs; pub use day3::Vecs as Day3Vecs; -pub use difficultyepoch::Vecs as DifficultyEpochVecs; -pub use halvingepoch::Vecs as HalvingEpochVecs; +pub use difficulty::Vecs as DifficultyVecs; +pub use halving::Vecs as HalvingVecs; pub use height::Vecs as HeightVecs; pub use hour1::Vecs as Hour1Vecs; pub use hour4::Vecs as Hour4Vecs; @@ -63,8 +63,8 @@ pub struct Vecs { db: Database, pub address: AddressVecs, pub height: HeightVecs, - pub difficultyepoch: DifficultyEpochVecs, - pub halvingepoch: HalvingEpochVecs, + pub difficulty: DifficultyVecs, + pub halving: HalvingVecs, pub minute10: Minute10Vecs, pub minute30: Minute30Vecs, pub hour1: Hour1Vecs, @@ -96,8 +96,8 @@ impl Vecs { let this = Self { address: AddressVecs::forced_import(version, indexer), height: HeightVecs::forced_import(&db, version)?, - difficultyepoch: DifficultyEpochVecs::forced_import(&db, version)?, - halvingepoch: HalvingEpochVecs::forced_import(&db, version)?, + difficulty: DifficultyVecs::forced_import(&db, version)?, + halving: HalvingVecs::forced_import(&db, version)?, minute10: Minute10Vecs::forced_import(&db, version)?, minute30: Minute30Vecs::forced_import(&db, version)?, hour1: Hour1Vecs::forced_import(&db, version)?, @@ -316,55 +316,55 @@ impl Vecs { prev_height: Height, exit: &Exit, ) -> Result<()> { - let starting_difficultyepoch = self + let starting_difficulty = self .height - .difficultyepoch + .difficulty .collect_one(prev_height) .unwrap_or_default(); - self.height.difficultyepoch.compute_from_index( + self.height.difficulty.compute_from_index( starting_indexes.height, &indexer.vecs.blocks.weight, exit, )?; - self.difficultyepoch.first_height.compute_first_per_index( + self.difficulty.first_height.compute_first_per_index( starting_indexes.height, - &self.height.difficultyepoch, + &self.height.difficulty, exit, )?; - self.difficultyepoch.identity.compute_from_index( - starting_difficultyepoch, - &self.difficultyepoch.first_height, + self.difficulty.identity.compute_from_index( + starting_difficulty, + &self.difficulty.first_height, exit, )?; - self.difficultyepoch + self.difficulty .height_count .compute_count_from_indexes( - starting_difficultyepoch, - &self.difficultyepoch.first_height, + starting_difficulty, + &self.difficulty.first_height, &blocks_time.date, exit, )?; - let starting_halvingepoch = self + let starting_halving = self .height - .halvingepoch + .halving .collect_one(prev_height) .unwrap_or_default(); - self.height.halvingepoch.compute_from_index( + self.height.halving.compute_from_index( starting_indexes.height, &indexer.vecs.blocks.weight, exit, )?; - self.halvingepoch.first_height.compute_first_per_index( + self.halving.first_height.compute_first_per_index( starting_indexes.height, - &self.height.halvingepoch, + &self.height.halving, exit, )?; - self.halvingepoch.identity.compute_from_index( - starting_halvingepoch, - &self.halvingepoch.first_height, + self.halving.identity.compute_from_index( + starting_halving, + &self.halving.first_height, exit, )?; diff --git a/crates/brk_computer/src/inputs/count/import.rs b/crates/brk_computer/src/inputs/count/import.rs index afce995c0..a0aba57de 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::ComputedFromHeightAggregated}; +use crate::{indexes, internal::ComputedPerBlockAggregated}; impl Vecs { pub(crate) fn forced_import( @@ -11,7 +11,7 @@ impl Vecs { version: Version, indexes: &indexes::Vecs, ) -> Result { - Ok(Self(ComputedFromHeightAggregated::forced_import( + Ok(Self(ComputedPerBlockAggregated::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 b6f1786a6..900143b30 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::ComputedFromHeightAggregated; +use crate::internal::ComputedPerBlockAggregated; #[derive(Deref, DerefMut, Traversable)] pub struct Vecs( - #[traversable(flatten)] pub ComputedFromHeightAggregated, + #[traversable(flatten)] pub ComputedPerBlockAggregated, ); diff --git a/crates/brk_computer/src/internal/amount/base.rs b/crates/brk_computer/src/internal/amount/base.rs index 124282164..eb6f6132b 100644 --- a/crates/brk_computer/src/internal/amount/base.rs +++ b/crates/brk_computer/src/internal/amount/base.rs @@ -16,7 +16,7 @@ use crate::{ prices, }; -const VERSION: Version = Version::TWO; // Match AmountFromHeight versioning +const VERSION: Version = Version::TWO; // Match AmountPerBlock versioning #[derive(Traversable)] pub struct Amount { diff --git a/crates/brk_computer/src/internal/amount/lazy.rs b/crates/brk_computer/src/internal/amount/lazy.rs index 87676bef8..f07cdaad1 100644 --- a/crates/brk_computer/src/internal/amount/lazy.rs +++ b/crates/brk_computer/src/internal/amount/lazy.rs @@ -2,7 +2,7 @@ use brk_traversable::Traversable; use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version}; use vecdb::{LazyVecFrom1, ReadableCloneableVec, UnaryTransform, VecIndex}; -use crate::internal::AmountFromHeight; +use crate::internal::AmountPerBlock; /// Fully lazy value type at height level. /// @@ -23,7 +23,7 @@ impl LazyAmount { DollarsTransform, >( name: &str, - source: &AmountFromHeight, + source: &AmountPerBlock, version: Version, ) -> Self where diff --git a/crates/brk_computer/src/internal/containers/mod.rs b/crates/brk_computer/src/internal/containers/mod.rs index d7168714e..fb9deb2d8 100644 --- a/crates/brk_computer/src/internal/containers/mod.rs +++ b/crates/brk_computer/src/internal/containers/mod.rs @@ -1,7 +1,7 @@ mod distribution_stats; -mod per_period; +mod per_resolution; mod windows; pub use distribution_stats::*; -pub use per_period::*; +pub use per_resolution::*; pub use windows::*; diff --git a/crates/brk_computer/src/internal/containers/per_period.rs b/crates/brk_computer/src/internal/containers/per_resolution.rs similarity index 70% rename from crates/brk_computer/src/internal/containers/per_period.rs rename to crates/brk_computer/src/internal/containers/per_resolution.rs index 038a93566..d1242da9b 100644 --- a/crates/brk_computer/src/internal/containers/per_period.rs +++ b/crates/brk_computer/src/internal/containers/per_resolution.rs @@ -2,7 +2,7 @@ use brk_traversable::Traversable; #[derive(Clone, Traversable)] #[traversable(merge)] -pub struct PerPeriod { +pub struct PerResolution { pub minute10: M10, pub minute30: M30, pub hour1: H1, @@ -16,6 +16,6 @@ pub struct PerPeriod( #[allow(clippy::type_complexity)] - pub PerPeriod< + pub PerResolution< ::Stored>>, ::Stored>>, ::Stored>>, @@ -53,7 +53,7 @@ where }; } - Ok(Self(PerPeriod { + Ok(Self(PerResolution { minute10: per_period!(), minute30: per_period!(), hour1: per_period!(), @@ -67,8 +67,8 @@ where month6: per_period!(), year1: per_period!(), year10: per_period!(), - halvingepoch: per_period!(), - difficultyepoch: per_period!(), + halving: per_period!(), + difficulty: per_period!(), })) } @@ -109,8 +109,8 @@ where period!(month6); period!(year1); period!(year10); - period!(halvingepoch); - period!(difficultyepoch); + period!(halving); + period!(difficulty); Ok(()) } @@ -156,8 +156,8 @@ where period!(month6); period!(year1); period!(year10); - period!(halvingepoch); - period!(difficultyepoch); + period!(halving); + period!(difficulty); Ok(()) } @@ -203,8 +203,8 @@ where period!(month6); period!(year1); period!(year10); - period!(halvingepoch); - period!(difficultyepoch); + period!(halving); + period!(difficulty); Ok(()) } diff --git a/crates/brk_computer/src/internal/indexes/lazy.rs b/crates/brk_computer/src/internal/indexes/lazy.rs index 3f673ba29..f25b64ea0 100644 --- a/crates/brk_computer/src/internal/indexes/lazy.rs +++ b/crates/brk_computer/src/internal/indexes/lazy.rs @@ -7,13 +7,13 @@ use derive_more::{Deref, DerefMut}; use schemars::JsonSchema; use vecdb::{LazyVecFrom1, ReadableCloneableVec, UnaryTransform}; -use crate::internal::{ComputedVecValue, EagerIndexes, PerPeriod}; +use crate::internal::{ComputedVecValue, EagerIndexes, PerResolution}; #[derive(Clone, Deref, DerefMut, Traversable)] #[traversable(transparent)] pub struct LazyEagerIndexes( #[allow(clippy::type_complexity)] - pub PerPeriod< + pub PerResolution< LazyVecFrom1, LazyVecFrom1, LazyVecFrom1, @@ -55,7 +55,7 @@ where }; } - Self(PerPeriod { + Self(PerResolution { minute10: period!(minute10), minute30: period!(minute30), hour1: period!(hour1), @@ -69,8 +69,8 @@ where month6: period!(month6), year1: period!(year1), year10: period!(year10), - halvingepoch: period!(halvingepoch), - difficultyepoch: period!(difficultyepoch), + halving: period!(halving), + difficulty: period!(difficulty), }) } } diff --git a/crates/brk_computer/src/internal/mod.rs b/crates/brk_computer/src/internal/mod.rs index 3d3681814..a82aafdf7 100644 --- a/crates/brk_computer/src/internal/mod.rs +++ b/crates/brk_computer/src/internal/mod.rs @@ -3,8 +3,8 @@ mod algo; mod amount; mod containers; mod db_utils; -mod from_height; -mod from_tx; +mod per_block; +mod per_tx; mod indexes; mod traits; mod transform; @@ -14,8 +14,8 @@ pub(crate) use algo::*; pub(crate) use amount::*; pub(crate) use containers::*; pub(crate) use db_utils::*; -pub(crate) use from_height::*; -pub(crate) use from_tx::*; +pub(crate) use per_block::*; +pub(crate) use per_tx::*; pub(crate) use indexes::*; pub(crate) use traits::*; pub use transform::*; diff --git a/crates/brk_computer/src/internal/from_height/amount/base.rs b/crates/brk_computer/src/internal/per_block/amount/base.rs similarity index 72% rename from crates/brk_computer/src/internal/from_height/amount/base.rs rename to crates/brk_computer/src/internal/per_block/amount/base.rs index 8a542afdb..3f501282e 100644 --- a/crates/brk_computer/src/internal/from_height/amount/base.rs +++ b/crates/brk_computer/src/internal/per_block/amount/base.rs @@ -6,21 +6,21 @@ use vecdb::{AnyVec, Database, Exit, ReadableCloneableVec, ReadableVec, Rw, Stora use crate::{ indexes, internal::{ - CentsUnsignedToDollars, ComputedFromHeight, LazyFromHeight, SatsToBitcoin, SatsToCents, + CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock, SatsToBitcoin, SatsToCents, Windows, }, prices, }; #[derive(Traversable)] -pub struct AmountFromHeight { - pub sats: ComputedFromHeight, - pub btc: LazyFromHeight, - pub cents: ComputedFromHeight, - pub usd: LazyFromHeight, +pub struct AmountPerBlock { + pub sats: ComputedPerBlock, + pub btc: LazyPerBlock, + pub cents: ComputedPerBlock, + pub usd: LazyPerBlock, } -impl AmountFromHeight { +impl AmountPerBlock { pub(crate) fn forced_import( db: &Database, name: &str, @@ -28,9 +28,9 @@ impl AmountFromHeight { indexes: &indexes::Vecs, ) -> Result { let sats = - ComputedFromHeight::forced_import(db, &format!("{name}_sats"), version, indexes)?; + ComputedPerBlock::forced_import(db, &format!("{name}_sats"), version, indexes)?; - let btc = LazyFromHeight::from_computed::( + let btc = LazyPerBlock::from_computed::( name, version, sats.height.read_only_boxed_clone(), @@ -38,9 +38,9 @@ impl AmountFromHeight { ); let cents = - ComputedFromHeight::forced_import(db, &format!("{name}_cents"), version, indexes)?; + ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?; - let usd = LazyFromHeight::from_computed::( + let usd = LazyPerBlock::from_computed::( &format!("{name}_usd"), version, cents.height.read_only_boxed_clone(), @@ -92,7 +92,7 @@ impl AmountFromHeight { } } -impl Windows { +impl Windows { pub(crate) fn forced_import( db: &Database, name: &str, @@ -100,7 +100,7 @@ impl Windows { indexes: &indexes::Vecs, ) -> Result { Windows::try_from_fn(|suffix| { - AmountFromHeight::forced_import(db, &format!("{name}_{suffix}"), version, indexes) + AmountPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes) }) } } diff --git a/crates/brk_computer/src/internal/from_height/amount/cumulative.rs b/crates/brk_computer/src/internal/per_block/amount/cumulative.rs similarity index 82% rename from crates/brk_computer/src/internal/from_height/amount/cumulative.rs rename to crates/brk_computer/src/internal/per_block/amount/cumulative.rs index 159279eb9..269570d67 100644 --- a/crates/brk_computer/src/internal/from_height/amount/cumulative.rs +++ b/crates/brk_computer/src/internal/per_block/amount/cumulative.rs @@ -5,19 +5,19 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{AmountFromHeight, SatsToCents}, + internal::{AmountPerBlock, SatsToCents}, prices, }; #[derive(Traversable)] -pub struct AmountFromHeightCumulative { - pub base: AmountFromHeight, - pub cumulative: AmountFromHeight, +pub struct AmountPerBlockCumulative { + pub base: AmountPerBlock, + pub cumulative: AmountPerBlock, } const VERSION: Version = Version::ONE; -impl AmountFromHeightCumulative { +impl AmountPerBlockCumulative { pub(crate) fn forced_import( db: &Database, name: &str, @@ -27,8 +27,8 @@ impl AmountFromHeightCumulative { let v = version + VERSION; Ok(Self { - base: AmountFromHeight::forced_import(db, name, v, indexes)?, - cumulative: AmountFromHeight::forced_import( + base: AmountPerBlock::forced_import(db, name, v, indexes)?, + cumulative: AmountPerBlock::forced_import( db, &format!("{name}_cumulative"), v, diff --git a/crates/brk_computer/src/internal/from_height/amount/cumulative_sum.rs b/crates/brk_computer/src/internal/per_block/amount/cumulative_sum.rs similarity index 78% rename from crates/brk_computer/src/internal/from_height/amount/cumulative_sum.rs rename to crates/brk_computer/src/internal/per_block/amount/cumulative_sum.rs index bb4ca5b78..db732e23d 100644 --- a/crates/brk_computer/src/internal/from_height/amount/cumulative_sum.rs +++ b/crates/brk_computer/src/internal/per_block/amount/cumulative_sum.rs @@ -5,20 +5,20 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{AmountFromHeight, RollingSumAmountFromHeight, SatsToCents, WindowStarts}, + internal::{AmountPerBlock, RollingSumAmountPerBlock, SatsToCents, WindowStarts}, prices, }; #[derive(Traversable)] -pub struct AmountFromHeightCumulativeSum { - pub base: AmountFromHeight, - pub cumulative: AmountFromHeight, - pub sum: RollingSumAmountFromHeight, +pub struct AmountPerBlockCumulativeSum { + pub base: AmountPerBlock, + pub cumulative: AmountPerBlock, + pub sum: RollingSumAmountPerBlock, } const VERSION: Version = Version::TWO; -impl AmountFromHeightCumulativeSum { +impl AmountPerBlockCumulativeSum { pub(crate) fn forced_import( db: &Database, name: &str, @@ -28,14 +28,14 @@ impl AmountFromHeightCumulativeSum { let v = version + VERSION; Ok(Self { - base: AmountFromHeight::forced_import(db, name, v, indexes)?, - cumulative: AmountFromHeight::forced_import( + base: AmountPerBlock::forced_import(db, name, v, indexes)?, + cumulative: AmountPerBlock::forced_import( db, &format!("{name}_cumulative"), v, indexes, )?, - sum: RollingSumAmountFromHeight::forced_import(db, name, v, indexes)?, + sum: RollingSumAmountPerBlock::forced_import(db, name, v, indexes)?, }) } diff --git a/crates/brk_computer/src/internal/from_height/amount/full.rs b/crates/brk_computer/src/internal/per_block/amount/full.rs similarity index 76% rename from crates/brk_computer/src/internal/from_height/amount/full.rs rename to crates/brk_computer/src/internal/per_block/amount/full.rs index 7bd783b3d..2c38d421c 100644 --- a/crates/brk_computer/src/internal/from_height/amount/full.rs +++ b/crates/brk_computer/src/internal/per_block/amount/full.rs @@ -5,21 +5,21 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{AmountFromHeight, RollingFullAmountFromHeight, SatsToCents, WindowStarts}, + internal::{AmountPerBlock, RollingFullAmountPerBlock, SatsToCents, WindowStarts}, prices, }; #[derive(Traversable)] -pub struct AmountFromHeightFull { - pub base: AmountFromHeight, - pub cumulative: AmountFromHeight, +pub struct AmountPerBlockFull { + pub base: AmountPerBlock, + pub cumulative: AmountPerBlock, #[traversable(flatten)] - pub rolling: RollingFullAmountFromHeight, + pub rolling: RollingFullAmountPerBlock, } const VERSION: Version = Version::TWO; -impl AmountFromHeightFull { +impl AmountPerBlockFull { pub(crate) fn forced_import( db: &Database, name: &str, @@ -29,14 +29,14 @@ impl AmountFromHeightFull { let v = version + VERSION; Ok(Self { - base: AmountFromHeight::forced_import(db, name, v, indexes)?, - cumulative: AmountFromHeight::forced_import( + base: AmountPerBlock::forced_import(db, name, v, indexes)?, + cumulative: AmountPerBlock::forced_import( db, &format!("{name}_cumulative"), v, indexes, )?, - rolling: RollingFullAmountFromHeight::forced_import(db, name, v, indexes)?, + rolling: RollingFullAmountPerBlock::forced_import(db, name, v, indexes)?, }) } diff --git a/crates/brk_computer/src/internal/from_height/amount/lazy.rs b/crates/brk_computer/src/internal/per_block/amount/lazy.rs similarity index 74% rename from crates/brk_computer/src/internal/from_height/amount/lazy.rs rename to crates/brk_computer/src/internal/per_block/amount/lazy.rs index 82b0827a2..5bc904cb9 100644 --- a/crates/brk_computer/src/internal/from_height/amount/lazy.rs +++ b/crates/brk_computer/src/internal/per_block/amount/lazy.rs @@ -1,25 +1,25 @@ -//! Lazy value wrapper for AmountFromHeight - all transforms are lazy. +//! Lazy value wrapper for AmountPerBlock - all transforms are lazy. use brk_traversable::Traversable; use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version}; use derive_more::{Deref, DerefMut}; use vecdb::UnaryTransform; -use crate::internal::{AmountFromHeight, LazyAmount, LazyAmountHeightDerived}; +use crate::internal::{AmountPerBlock, LazyAmount, LazyAmountDerivedResolutions}; -/// Lazy value wrapper with height + all derived last transforms from AmountFromHeight. +/// Lazy value wrapper with height + all derived last transforms from AmountPerBlock. #[derive(Clone, Deref, DerefMut, Traversable)] #[traversable(merge)] -pub struct LazyAmountFromHeight { +pub struct LazyAmountPerBlock { #[traversable(flatten)] pub height: LazyAmount, #[deref] #[deref_mut] #[traversable(flatten)] - pub rest: Box, + pub resolutions: Box, } -impl LazyAmountFromHeight { +impl LazyAmountPerBlock { pub(crate) fn from_block_source< SatsTransform, BitcoinTransform, @@ -27,7 +27,7 @@ impl LazyAmountFromHeight { DollarsTransform, >( name: &str, - source: &AmountFromHeight, + source: &AmountPerBlock, version: Version, ) -> Self where @@ -43,7 +43,7 @@ impl LazyAmountFromHeight { DollarsTransform, >(name, source, version); - let rest = LazyAmountHeightDerived::from_block_source::< + let resolutions = LazyAmountDerivedResolutions::from_block_source::< SatsTransform, BitcoinTransform, CentsTransform, @@ -52,7 +52,7 @@ impl LazyAmountFromHeight { Self { height, - rest: Box::new(rest), + resolutions: Box::new(resolutions), } } } diff --git a/crates/brk_computer/src/internal/from_height/amount/lazy_derived.rs b/crates/brk_computer/src/internal/per_block/amount/lazy_derived_resolutions.rs similarity index 53% rename from crates/brk_computer/src/internal/from_height/amount/lazy_derived.rs rename to crates/brk_computer/src/internal/per_block/amount/lazy_derived_resolutions.rs index e1337c041..8a8b74864 100644 --- a/crates/brk_computer/src/internal/from_height/amount/lazy_derived.rs +++ b/crates/brk_computer/src/internal/per_block/amount/lazy_derived_resolutions.rs @@ -2,17 +2,17 @@ use brk_traversable::Traversable; use brk_types::{Bitcoin, Cents, Dollars, Sats, Version}; use vecdb::UnaryTransform; -use crate::internal::{AmountFromHeight, LazyHeightDerived}; +use crate::internal::{AmountPerBlock, DerivedResolutions}; #[derive(Clone, Traversable)] -pub struct LazyAmountHeightDerived { - pub sats: LazyHeightDerived, - pub btc: LazyHeightDerived, - pub cents: LazyHeightDerived, - pub usd: LazyHeightDerived, +pub struct LazyAmountDerivedResolutions { + pub sats: DerivedResolutions, + pub btc: DerivedResolutions, + pub cents: DerivedResolutions, + pub usd: DerivedResolutions, } -impl LazyAmountHeightDerived { +impl LazyAmountDerivedResolutions { pub(crate) fn from_block_source< SatsTransform, BitcoinTransform, @@ -20,7 +20,7 @@ impl LazyAmountHeightDerived { DollarsTransform, >( name: &str, - source: &AmountFromHeight, + source: &AmountPerBlock, version: Version, ) -> Self where @@ -29,28 +29,28 @@ impl LazyAmountHeightDerived { CentsTransform: UnaryTransform, DollarsTransform: UnaryTransform, { - let sats = LazyHeightDerived::from_derived_computed::( + let sats = DerivedResolutions::from_derived_computed::( &format!("{name}_sats"), version, - &source.sats.rest, + &source.sats.resolutions, ); - let btc = LazyHeightDerived::from_derived_computed::( + let btc = DerivedResolutions::from_derived_computed::( name, version, - &source.sats.rest, + &source.sats.resolutions, ); - let cents = LazyHeightDerived::from_derived_computed::( + let cents = DerivedResolutions::from_derived_computed::( &format!("{name}_cents"), version, - &source.cents.rest, + &source.cents.resolutions, ); - let usd = LazyHeightDerived::from_lazy::( + let usd = DerivedResolutions::from_lazy::( &format!("{name}_usd"), version, - &source.usd.rest, + &source.usd.resolutions, ); Self { diff --git a/crates/brk_computer/src/internal/from_height/amount/mod.rs b/crates/brk_computer/src/internal/per_block/amount/mod.rs similarity index 82% rename from crates/brk_computer/src/internal/from_height/amount/mod.rs rename to crates/brk_computer/src/internal/per_block/amount/mod.rs index 61eb8b807..c89f89a44 100644 --- a/crates/brk_computer/src/internal/from_height/amount/mod.rs +++ b/crates/brk_computer/src/internal/per_block/amount/mod.rs @@ -3,7 +3,7 @@ mod cumulative; mod cumulative_sum; mod full; mod lazy; -mod lazy_derived; +mod lazy_derived_resolutions; mod rolling; mod rolling_full; mod rolling_sum; @@ -14,7 +14,7 @@ pub use cumulative::*; pub use cumulative_sum::*; pub use full::*; pub use lazy::*; -pub use lazy_derived::*; +pub use lazy_derived_resolutions::*; pub use rolling::*; pub use rolling_full::*; pub use rolling_sum::*; diff --git a/crates/brk_computer/src/internal/from_height/amount/rolling.rs b/crates/brk_computer/src/internal/per_block/amount/rolling.rs similarity index 80% rename from crates/brk_computer/src/internal/from_height/amount/rolling.rs rename to crates/brk_computer/src/internal/per_block/amount/rolling.rs index a315cbcd6..82a2e3b5a 100644 --- a/crates/brk_computer/src/internal/from_height/amount/rolling.rs +++ b/crates/brk_computer/src/internal/per_block/amount/rolling.rs @@ -1,7 +1,7 @@ //! Value type for Height + Rolling pattern. //! //! Combines Value (sats/btc/usd per height, no period views) with -//! AmountFromHeightWindows (rolling sums across 4 windows). +//! AmountPerBlockWindows (rolling sums across 4 windows). use brk_error::Result; use brk_traversable::Traversable; @@ -11,21 +11,21 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{Amount, AmountFromHeightWindows, WindowStarts}, + internal::{Amount, AmountPerBlockWindows, WindowStarts}, prices, }; #[derive(Deref, DerefMut, Traversable)] -pub struct AmountFromHeightRolling { +pub struct AmountPerBlockRolling { #[deref] #[deref_mut] #[traversable(flatten)] pub amount: Amount, #[traversable(flatten)] - pub rolling: AmountFromHeightWindows, + pub rolling: AmountPerBlockWindows, } -impl AmountFromHeightRolling { +impl AmountPerBlockRolling { pub(crate) fn forced_import( db: &Database, name: &str, @@ -34,7 +34,7 @@ impl AmountFromHeightRolling { ) -> Result { Ok(Self { amount: Amount::forced_import(db, name, version)?, - rolling: AmountFromHeightWindows::forced_import(db, name, version, indexes)?, + rolling: AmountPerBlockWindows::forced_import(db, name, version, indexes)?, }) } diff --git a/crates/brk_computer/src/internal/from_height/amount/rolling_full.rs b/crates/brk_computer/src/internal/per_block/amount/rolling_full.rs similarity index 83% rename from crates/brk_computer/src/internal/from_height/amount/rolling_full.rs rename to crates/brk_computer/src/internal/per_block/amount/rolling_full.rs index 62f2b3896..cfc1acf57 100644 --- a/crates/brk_computer/src/internal/from_height/amount/rolling_full.rs +++ b/crates/brk_computer/src/internal/per_block/amount/rolling_full.rs @@ -7,18 +7,18 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; use crate::{ indexes, internal::{ - AmountFromHeight, DistributionStats, WindowStarts, Windows, compute_rolling_distribution_from_starts, + AmountPerBlock, DistributionStats, WindowStarts, Windows, compute_rolling_distribution_from_starts, }, }; -/// One window slot: sum + 8 distribution stats, each a AmountFromHeight. +/// One window slot: sum + 8 distribution stats, each a AmountPerBlock. /// /// Tree: `sum.sats.height`, `average.sats.height`, etc. #[derive(Traversable)] pub struct RollingFullSlot { - pub sum: AmountFromHeight, + pub sum: AmountPerBlock, #[traversable(flatten)] - pub distribution: DistributionStats>, + pub distribution: DistributionStats>, } impl RollingFullSlot { @@ -29,9 +29,9 @@ impl RollingFullSlot { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - sum: AmountFromHeight::forced_import(db, &format!("{name}_sum"), version, indexes)?, + sum: AmountPerBlock::forced_import(db, &format!("{name}_sum"), version, indexes)?, distribution: DistributionStats::try_from_fn(|suffix| { - AmountFromHeight::forced_import(db, &format!("{name}_{suffix}"), version, indexes) + AmountPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes) })?, }) } @@ -85,9 +85,9 @@ impl RollingFullSlot { /// Tree: `_24h.sum.sats.height`, `_24h.average.sats.height`, etc. #[derive(Deref, DerefMut, Traversable)] #[traversable(transparent)] -pub struct RollingFullAmountFromHeight(pub Windows>); +pub struct RollingFullAmountPerBlock(pub Windows>); -impl RollingFullAmountFromHeight { +impl RollingFullAmountPerBlock { pub(crate) fn forced_import( db: &Database, name: &str, diff --git a/crates/brk_computer/src/internal/from_height/amount/rolling_sum.rs b/crates/brk_computer/src/internal/per_block/amount/rolling_sum.rs similarity index 84% rename from crates/brk_computer/src/internal/from_height/amount/rolling_sum.rs rename to crates/brk_computer/src/internal/per_block/amount/rolling_sum.rs index b0db48985..abf5a210d 100644 --- a/crates/brk_computer/src/internal/from_height/amount/rolling_sum.rs +++ b/crates/brk_computer/src/internal/per_block/amount/rolling_sum.rs @@ -6,7 +6,7 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; use crate::{ indexes, - internal::{AmountFromHeight, WindowStarts, Windows}, + internal::{AmountPerBlock, WindowStarts, Windows}, }; /// Rolling sum only, window-first then unit. @@ -14,16 +14,16 @@ use crate::{ /// Tree: `_24h.sats.height`, `_24h.btc.height`, etc. #[derive(Deref, DerefMut, Traversable)] #[traversable(transparent)] -pub struct RollingSumAmountFromHeight(pub Windows>); +pub struct RollingSumAmountPerBlock(pub Windows>); -impl RollingSumAmountFromHeight { +impl RollingSumAmountPerBlock { pub(crate) fn forced_import( db: &Database, name: &str, version: Version, indexes: &indexes::Vecs, ) -> Result { - Ok(Self(Windows::::forced_import( + Ok(Self(Windows::::forced_import( db, &format!("{name}_sum"), version, diff --git a/crates/brk_computer/src/internal/from_height/amount/windows.rs b/crates/brk_computer/src/internal/per_block/amount/windows.rs similarity index 75% rename from crates/brk_computer/src/internal/from_height/amount/windows.rs rename to crates/brk_computer/src/internal/per_block/amount/windows.rs index 02b8800c4..0f555ec5a 100644 --- a/crates/brk_computer/src/internal/from_height/amount/windows.rs +++ b/crates/brk_computer/src/internal/per_block/amount/windows.rs @@ -1,4 +1,4 @@ -//! AmountFromHeightWindows - window-first ordering. +//! AmountPerBlockWindows - window-first ordering. //! //! Access pattern: `coinbase_sum._24h.sats.height` //! Each window (24h, 7d, 30d, 1y) contains sats (stored) + btc (lazy) + usd (stored). @@ -14,17 +14,17 @@ use brk_types::{Cents, Sats}; use crate::{ indexes, - internal::{AmountFromHeight, WindowStarts, Windows}, + internal::{AmountPerBlock, WindowStarts, Windows}, }; /// Value rolling windows — window-first, currency-last. /// -/// Each window contains `AmountFromHeight` (sats + btc lazy + usd). +/// Each window contains `AmountPerBlock` (sats + btc lazy + usd). #[derive(Deref, DerefMut, Traversable)] #[traversable(transparent)] -pub struct AmountFromHeightWindows(pub Windows>); +pub struct AmountPerBlockWindows(pub Windows>); -impl AmountFromHeightWindows { +impl AmountPerBlockWindows { pub(crate) fn forced_import( db: &Database, name: &str, @@ -32,7 +32,7 @@ impl AmountFromHeightWindows { indexes: &indexes::Vecs, ) -> Result { Ok(Self(Windows::try_from_fn(|suffix| { - AmountFromHeight::forced_import(db, &format!("{name}_{suffix}"), version, indexes) + AmountPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes) })?)) } diff --git a/crates/brk_computer/src/internal/from_height/computed/aggregated.rs b/crates/brk_computer/src/internal/per_block/computed/aggregated.rs similarity index 89% rename from crates/brk_computer/src/internal/from_height/computed/aggregated.rs rename to crates/brk_computer/src/internal/per_block/computed/aggregated.rs index e69b49c1a..dd0178ecc 100644 --- a/crates/brk_computer/src/internal/from_height/computed/aggregated.rs +++ b/crates/brk_computer/src/internal/per_block/computed/aggregated.rs @@ -1,4 +1,4 @@ -//! ComputedFromHeightAggregated - Full (distribution + sum + cumulative) + RollingFull. +//! ComputedPerBlockAggregated - Full (distribution + sum + cumulative) + RollingFull. //! //! 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. @@ -17,7 +17,7 @@ use crate::{ }; #[derive(Traversable)] -pub struct ComputedFromHeightAggregated +pub struct ComputedPerBlockAggregated where T: NumericValue + JsonSchema, { @@ -26,7 +26,7 @@ where pub rolling: RollingFull, } -impl ComputedFromHeightAggregated +impl ComputedPerBlockAggregated where T: NumericValue + JsonSchema, { diff --git a/crates/brk_computer/src/internal/from_height/computed/base.rs b/crates/brk_computer/src/internal/per_block/computed/base.rs similarity index 83% rename from crates/brk_computer/src/internal/from_height/computed/base.rs rename to crates/brk_computer/src/internal/per_block/computed/base.rs index f5b764c7b..8b4351e02 100644 --- a/crates/brk_computer/src/internal/from_height/computed/base.rs +++ b/crates/brk_computer/src/internal/per_block/computed/base.rs @@ -11,11 +11,11 @@ use vecdb::{ use crate::indexes; -use crate::internal::{ComputedHeightDerived, ComputedVecValue, NumericValue}; +use crate::internal::{Resolutions, ComputedVecValue, NumericValue}; #[derive(Deref, DerefMut, Traversable)] #[traversable(merge)] -pub struct ComputedFromHeight +pub struct ComputedPerBlock where T: ComputedVecValue + PartialOrd + JsonSchema, { @@ -23,10 +23,10 @@ where #[deref] #[deref_mut] #[traversable(flatten)] - pub rest: Box>, + pub resolutions: Box>, } -impl ComputedFromHeight +impl ComputedPerBlock where T: NumericValue + JsonSchema, { @@ -38,7 +38,7 @@ where ) -> Result { let height: EagerVec> = EagerVec::forced_import(db, name, version)?; - let rest = ComputedHeightDerived::forced_import( + let resolutions = Resolutions::forced_import( name, height.read_only_boxed_clone(), version, @@ -47,7 +47,7 @@ where Ok(Self { height, - rest: Box::new(rest), + resolutions: Box::new(resolutions), }) } diff --git a/crates/brk_computer/src/internal/from_height/computed/constant.rs b/crates/brk_computer/src/internal/per_block/computed/constant.rs similarity index 91% rename from crates/brk_computer/src/internal/from_height/computed/constant.rs rename to crates/brk_computer/src/internal/per_block/computed/constant.rs index 5a95b4bc4..ee352f457 100644 --- a/crates/brk_computer/src/internal/from_height/computed/constant.rs +++ b/crates/brk_computer/src/internal/per_block/computed/constant.rs @@ -29,8 +29,8 @@ where pub month6: LazyVecFrom1, pub year1: LazyVecFrom1, pub year10: LazyVecFrom1, - pub halvingepoch: LazyVecFrom1, - pub difficultyepoch: LazyVecFrom1, + pub halving: LazyVecFrom1, + pub difficulty: LazyVecFrom1, } impl ConstantVecs { @@ -78,8 +78,8 @@ impl ConstantVecs { month6: period!(month6), year1: period!(year1), year10: period!(year10), - halvingepoch: period!(halvingepoch), - difficultyepoch: period!(difficultyepoch), + halving: period!(halving), + difficulty: period!(difficulty), } } } diff --git a/crates/brk_computer/src/internal/from_height/computed/cumulative.rs b/crates/brk_computer/src/internal/per_block/computed/cumulative.rs similarity index 73% rename from crates/brk_computer/src/internal/from_height/computed/cumulative.rs rename to crates/brk_computer/src/internal/per_block/computed/cumulative.rs index 6fb70fb61..6d91232c7 100644 --- a/crates/brk_computer/src/internal/from_height/computed/cumulative.rs +++ b/crates/brk_computer/src/internal/per_block/computed/cumulative.rs @@ -1,8 +1,8 @@ -//! ComputedFromHeightCumulative - stored height + LazyAggVec + cumulative (from height). +//! ComputedPerBlockCumulative - stored height + LazyAggVec + cumulative (from height). //! -//! Like ComputedFromHeightCumulativeSum but without RollingWindows. +//! Like ComputedPerBlockCumulativeSum but without RollingWindows. //! Used for distribution metrics where rolling is optional per cohort. -//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views. +//! Cumulative gets its own ComputedPerBlock so it has LazyAggVec index views. use brk_error::Result; use brk_traversable::Traversable; @@ -12,19 +12,19 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{ComputedFromHeight, NumericValue}, + internal::{ComputedPerBlock, NumericValue}, }; #[derive(Traversable)] -pub struct ComputedFromHeightCumulative +pub struct ComputedPerBlockCumulative where T: NumericValue + JsonSchema, { pub height: M::Stored>>, - pub cumulative: ComputedFromHeight, + pub cumulative: ComputedPerBlock, } -impl ComputedFromHeightCumulative +impl ComputedPerBlockCumulative where T: NumericValue + JsonSchema, { @@ -36,7 +36,7 @@ where ) -> Result { let height: EagerVec> = EagerVec::forced_import(db, name, version)?; let cumulative = - ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; + ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; Ok(Self { height, cumulative }) } diff --git a/crates/brk_computer/src/internal/from_height/computed/cumulative_sum.rs b/crates/brk_computer/src/internal/per_block/computed/cumulative_sum.rs similarity index 76% rename from crates/brk_computer/src/internal/from_height/computed/cumulative_sum.rs rename to crates/brk_computer/src/internal/per_block/computed/cumulative_sum.rs index 3e6d8686a..c2fddd134 100644 --- a/crates/brk_computer/src/internal/from_height/computed/cumulative_sum.rs +++ b/crates/brk_computer/src/internal/per_block/computed/cumulative_sum.rs @@ -1,8 +1,8 @@ -//! ComputedFromHeightCumulativeSum - stored height + LazyAggVec + cumulative (from height) + RollingWindows (sum). +//! ComputedPerBlockCumulativeSum - stored height + LazyAggVec + cumulative (from height) + RollingWindows (sum). //! -//! Like ComputedFromHeightFull but with rolling sum only (no distribution). +//! Like ComputedPerBlockFull but with rolling sum only (no distribution). //! Used for count metrics where distribution stats aren't meaningful. -//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too. +//! Cumulative gets its own ComputedPerBlock so it has LazyAggVec index views too. use std::ops::SubAssign; @@ -14,20 +14,20 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{ComputedFromHeight, NumericValue, RollingWindows, WindowStarts}, + internal::{ComputedPerBlock, NumericValue, RollingWindows, WindowStarts}, }; #[derive(Traversable)] -pub struct ComputedFromHeightCumulativeSum +pub struct ComputedPerBlockCumulativeSum where T: NumericValue + JsonSchema, { pub height: M::Stored>>, - pub cumulative: ComputedFromHeight, + pub cumulative: ComputedPerBlock, pub sum: RollingWindows, } -impl ComputedFromHeightCumulativeSum +impl ComputedPerBlockCumulativeSum where T: NumericValue + JsonSchema, { @@ -39,7 +39,7 @@ where ) -> Result { let height: EagerVec> = EagerVec::forced_import(db, name, version)?; let cumulative = - ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; + ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; let rolling = RollingWindows::forced_import(db, name, version, indexes)?; Ok(Self { diff --git a/crates/brk_computer/src/internal/from_height/computed/delta.rs b/crates/brk_computer/src/internal/per_block/computed/delta.rs similarity index 89% rename from crates/brk_computer/src/internal/from_height/computed/delta.rs rename to crates/brk_computer/src/internal/per_block/computed/delta.rs index 96d336d8b..43fc27639 100644 --- a/crates/brk_computer/src/internal/from_height/computed/delta.rs +++ b/crates/brk_computer/src/internal/per_block/computed/delta.rs @@ -18,7 +18,7 @@ use vecdb::{AnyVec, Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMo use crate::{ indexes, internal::{ - ComputedFromHeight, NumericValue, PercentFromHeight, PercentRollingWindows, + ComputedPerBlock, NumericValue, PercentPerBlock, PercentRollingWindows, RollingWindows, WindowStarts, }, }; @@ -168,8 +168,8 @@ where S: NumericValue + JsonSchema, C: NumericValue + JsonSchema, { - pub change_1m: ComputedFromHeight, - pub rate_1m: PercentFromHeight, + pub change_1m: ComputedPerBlock, + pub rate_1m: PercentPerBlock, _phantom: std::marker::PhantomData, } @@ -185,13 +185,13 @@ where indexes: &indexes::Vecs, ) -> Result { Ok(Self { - change_1m: ComputedFromHeight::forced_import( + change_1m: ComputedPerBlock::forced_import( db, &format!("{name}_change_1m"), version, indexes, )?, - rate_1m: PercentFromHeight::forced_import( + rate_1m: PercentPerBlock::forced_import( db, &format!("{name}_rate_1m"), version, @@ -228,13 +228,13 @@ where C: NumericValue + JsonSchema, { #[traversable(rename = "24h")] - pub change_24h: ComputedFromHeight, - pub change_1w: ComputedFromHeight, - pub change_1y: ComputedFromHeight, + pub change_24h: ComputedPerBlock, + pub change_1w: ComputedPerBlock, + pub change_1y: ComputedPerBlock, #[traversable(rename = "24h")] - pub rate_24h: PercentFromHeight, - pub rate_1w: PercentFromHeight, - pub rate_1y: PercentFromHeight, + pub rate_24h: PercentPerBlock, + pub rate_1w: PercentPerBlock, + pub rate_1y: PercentPerBlock, _phantom: std::marker::PhantomData, } @@ -250,37 +250,37 @@ where indexes: &indexes::Vecs, ) -> Result { Ok(Self { - change_24h: ComputedFromHeight::forced_import( + change_24h: ComputedPerBlock::forced_import( db, &format!("{name}_change_24h"), version, indexes, )?, - change_1w: ComputedFromHeight::forced_import( + change_1w: ComputedPerBlock::forced_import( db, &format!("{name}_change_1w"), version, indexes, )?, - change_1y: ComputedFromHeight::forced_import( + change_1y: ComputedPerBlock::forced_import( db, &format!("{name}_change_1y"), version, indexes, )?, - rate_24h: PercentFromHeight::forced_import( + rate_24h: PercentPerBlock::forced_import( db, &format!("{name}_rate_24h"), version, indexes, )?, - rate_1w: PercentFromHeight::forced_import( + rate_1w: PercentPerBlock::forced_import( db, &format!("{name}_rate_1w"), version, indexes, )?, - rate_1y: PercentFromHeight::forced_import( + rate_1y: PercentPerBlock::forced_import( db, &format!("{name}_rate_1y"), version, diff --git a/crates/brk_computer/src/internal/from_height/computed/fiat_delta.rs b/crates/brk_computer/src/internal/per_block/computed/fiat_delta.rs similarity index 80% rename from crates/brk_computer/src/internal/from_height/computed/fiat_delta.rs rename to crates/brk_computer/src/internal/per_block/computed/fiat_delta.rs index 689ce29ea..e31b7a1bd 100644 --- a/crates/brk_computer/src/internal/from_height/computed/fiat_delta.rs +++ b/crates/brk_computer/src/internal/per_block/computed/fiat_delta.rs @@ -1,5 +1,5 @@ -//! Fiat delta variants — same as RollingDelta* but change is FiatFromHeight -//! (stored cents + lazy USD) instead of ComputedFromHeight (stored cents only). +//! Fiat delta variants — same as RollingDelta* but change is FiatPerBlock +//! (stored cents + lazy USD) instead of ComputedPerBlock (stored cents only). use brk_error::Result; use brk_traversable::Traversable; @@ -10,7 +10,7 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; use crate::{ indexes, internal::{ - CentsType, FiatFromHeight, NumericValue, PercentFromHeight, PercentRollingWindows, + CentsType, FiatPerBlock, NumericValue, PercentPerBlock, PercentRollingWindows, WindowStarts, }, }; @@ -24,8 +24,8 @@ where S: NumericValue + JsonSchema, C: CentsType, { - pub change_1m: FiatFromHeight, - pub rate_1m: PercentFromHeight, + pub change_1m: FiatPerBlock, + pub rate_1m: PercentPerBlock, _phantom: std::marker::PhantomData, } @@ -41,13 +41,13 @@ where indexes: &indexes::Vecs, ) -> Result { Ok(Self { - change_1m: FiatFromHeight::forced_import( + change_1m: FiatPerBlock::forced_import( db, &format!("{name}_change_1m"), version, indexes, )?, - rate_1m: PercentFromHeight::forced_import( + rate_1m: PercentPerBlock::forced_import( db, &format!("{name}_rate_1m"), version, @@ -83,13 +83,13 @@ where C: CentsType, { #[traversable(rename = "24h")] - pub change_24h: FiatFromHeight, - pub change_1w: FiatFromHeight, - pub change_1y: FiatFromHeight, + pub change_24h: FiatPerBlock, + pub change_1w: FiatPerBlock, + pub change_1y: FiatPerBlock, #[traversable(rename = "24h")] - pub rate_24h: PercentFromHeight, - pub rate_1w: PercentFromHeight, - pub rate_1y: PercentFromHeight, + pub rate_24h: PercentPerBlock, + pub rate_1w: PercentPerBlock, + pub rate_1y: PercentPerBlock, _phantom: std::marker::PhantomData, } @@ -105,37 +105,37 @@ where indexes: &indexes::Vecs, ) -> Result { Ok(Self { - change_24h: FiatFromHeight::forced_import( + change_24h: FiatPerBlock::forced_import( db, &format!("{name}_change_24h"), version, indexes, )?, - change_1w: FiatFromHeight::forced_import( + change_1w: FiatPerBlock::forced_import( db, &format!("{name}_change_1w"), version, indexes, )?, - change_1y: FiatFromHeight::forced_import( + change_1y: FiatPerBlock::forced_import( db, &format!("{name}_change_1y"), version, indexes, )?, - rate_24h: PercentFromHeight::forced_import( + rate_24h: PercentPerBlock::forced_import( db, &format!("{name}_rate_24h"), version, indexes, )?, - rate_1w: PercentFromHeight::forced_import( + rate_1w: PercentPerBlock::forced_import( db, &format!("{name}_rate_1w"), version, indexes, )?, - rate_1y: PercentFromHeight::forced_import( + rate_1y: PercentPerBlock::forced_import( db, &format!("{name}_rate_1y"), version, @@ -152,7 +152,7 @@ where source: &impl ReadableVec, exit: &Exit, ) -> Result<()> { - let changes: [&mut FiatFromHeight; 3] = [ + let changes: [&mut FiatPerBlock; 3] = [ &mut self.change_24h, &mut self.change_1w, &mut self.change_1y, @@ -181,10 +181,10 @@ where S: NumericValue + JsonSchema, C: CentsType, { - pub change_24h: FiatFromHeight, - pub change_1w: FiatFromHeight, - pub change_1m: FiatFromHeight, - pub change_1y: FiatFromHeight, + pub change_24h: FiatPerBlock, + pub change_1w: FiatPerBlock, + pub change_1m: FiatPerBlock, + pub change_1y: FiatPerBlock, pub rate: PercentRollingWindows, _phantom: std::marker::PhantomData, } @@ -201,25 +201,25 @@ where indexes: &indexes::Vecs, ) -> Result { Ok(Self { - change_24h: FiatFromHeight::forced_import( + change_24h: FiatPerBlock::forced_import( db, &format!("{name}_change_24h"), version, indexes, )?, - change_1w: FiatFromHeight::forced_import( + change_1w: FiatPerBlock::forced_import( db, &format!("{name}_change_1w"), version, indexes, )?, - change_1m: FiatFromHeight::forced_import( + change_1m: FiatPerBlock::forced_import( db, &format!("{name}_change_1m"), version, indexes, )?, - change_1y: FiatFromHeight::forced_import( + change_1y: FiatPerBlock::forced_import( db, &format!("{name}_change_1y"), version, @@ -242,7 +242,7 @@ where source: &impl ReadableVec, exit: &Exit, ) -> Result<()> { - let changes: [&mut FiatFromHeight; 4] = [ + let changes: [&mut FiatPerBlock; 4] = [ &mut self.change_24h, &mut self.change_1w, &mut self.change_1m, diff --git a/crates/brk_computer/src/internal/from_height/computed/full.rs b/crates/brk_computer/src/internal/per_block/computed/full.rs similarity index 77% rename from crates/brk_computer/src/internal/from_height/computed/full.rs rename to crates/brk_computer/src/internal/per_block/computed/full.rs index 88c7bb247..bef02487a 100644 --- a/crates/brk_computer/src/internal/from_height/computed/full.rs +++ b/crates/brk_computer/src/internal/per_block/computed/full.rs @@ -1,7 +1,7 @@ -//! ComputedFromHeightFull - stored height + LazyAggVec + cumulative (from height) + RollingFull. +//! ComputedPerBlockFull - stored height + LazyAggVec + cumulative (from height) + RollingFull. //! //! For metrics with stored per-block data, cumulative sums, and rolling windows. -//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too. +//! Cumulative gets its own ComputedPerBlock so it has LazyAggVec index views too. use std::ops::SubAssign; @@ -13,21 +13,21 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{ComputedFromHeight, NumericValue, RollingFull, WindowStarts}, + internal::{ComputedPerBlock, NumericValue, RollingFull, WindowStarts}, }; #[derive(Traversable)] -pub struct ComputedFromHeightFull +pub struct ComputedPerBlockFull where T: NumericValue + JsonSchema, { pub height: M::Stored>>, - pub cumulative: ComputedFromHeight, + pub cumulative: ComputedPerBlock, #[traversable(flatten)] pub rolling: RollingFull, } -impl ComputedFromHeightFull +impl ComputedPerBlockFull where T: NumericValue + JsonSchema, { @@ -39,7 +39,7 @@ where ) -> Result { let height: EagerVec> = EagerVec::forced_import(db, name, version)?; let cumulative = - ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; + ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; let rolling = RollingFull::forced_import(db, name, version, indexes)?; Ok(Self { diff --git a/crates/brk_computer/src/internal/from_height/computed/mod.rs b/crates/brk_computer/src/internal/per_block/computed/mod.rs similarity index 79% rename from crates/brk_computer/src/internal/from_height/computed/mod.rs rename to crates/brk_computer/src/internal/per_block/computed/mod.rs index 9ff8be601..314a444c0 100644 --- a/crates/brk_computer/src/internal/from_height/computed/mod.rs +++ b/crates/brk_computer/src/internal/per_block/computed/mod.rs @@ -4,8 +4,8 @@ mod constant; mod cumulative; mod cumulative_sum; mod delta; -mod derived; -mod derived_full; +mod resolutions; +mod resolutions_full; mod fiat_delta; mod full; mod rolling_average; @@ -17,8 +17,8 @@ pub use constant::*; pub use cumulative::*; pub use cumulative_sum::*; pub use delta::*; -pub use derived::*; -pub use derived_full::*; +pub use resolutions::*; +pub use resolutions_full::*; pub use fiat_delta::*; pub use full::*; pub use rolling_average::*; diff --git a/crates/brk_computer/src/internal/from_height/computed/derived.rs b/crates/brk_computer/src/internal/per_block/computed/resolutions.rs similarity index 92% rename from crates/brk_computer/src/internal/from_height/computed/derived.rs rename to crates/brk_computer/src/internal/per_block/computed/resolutions.rs index 1356e450f..25703e303 100644 --- a/crates/brk_computer/src/internal/from_height/computed/derived.rs +++ b/crates/brk_computer/src/internal/per_block/computed/resolutions.rs @@ -11,14 +11,14 @@ use vecdb::{ use crate::{ indexes, - internal::{ComputedVecValue, NumericValue, PerPeriod}, + internal::{ComputedVecValue, NumericValue, PerResolution}, }; #[derive(Clone, Deref, DerefMut, Traversable)] #[traversable(transparent)] -pub struct ComputedHeightDerived( +pub struct Resolutions( #[allow(clippy::type_complexity)] - pub PerPeriod< + pub PerResolution< LazyAggVec, Height, Height, T>, LazyAggVec, Height, Height, T>, LazyAggVec, Height, Height, T>, @@ -39,7 +39,7 @@ pub struct ComputedHeightDerived( where T: ComputedVecValue + PartialOrd + JsonSchema; -impl ReadOnlyClone for ComputedHeightDerived +impl ReadOnlyClone for Resolutions where T: ComputedVecValue + PartialOrd + JsonSchema, { @@ -49,7 +49,7 @@ where } } -impl ComputedHeightDerived +impl Resolutions where T: NumericValue + JsonSchema, { @@ -113,7 +113,7 @@ where }; } - Self(PerPeriod { + Self(PerResolution { minute10: period!(minute10), minute30: period!(minute30), hour1: period!(hour1), @@ -127,8 +127,8 @@ where month6: period!(month6), year1: period!(year1), year10: period!(year10), - halvingepoch: epoch!(halvingepoch), - difficultyepoch: epoch!(difficultyepoch), + halving: epoch!(halving), + difficulty: epoch!(difficulty), }) } } diff --git a/crates/brk_computer/src/internal/from_height/computed/derived_full.rs b/crates/brk_computer/src/internal/per_block/computed/resolutions_full.rs similarity index 72% rename from crates/brk_computer/src/internal/from_height/computed/derived_full.rs rename to crates/brk_computer/src/internal/per_block/computed/resolutions_full.rs index 0c18d8935..61d3aef17 100644 --- a/crates/brk_computer/src/internal/from_height/computed/derived_full.rs +++ b/crates/brk_computer/src/internal/per_block/computed/resolutions_full.rs @@ -1,7 +1,7 @@ -//! ComputedHeightDerivedFull - LazyAggVec index views + cumulative (from height) + RollingFull. +//! ResolutionsFull - LazyAggVec index views + cumulative (from height) + RollingFull. //! //! For metrics derived from indexer sources (no stored height vec). -//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too. +//! Cumulative gets its own ComputedPerBlock so it has LazyAggVec index views too. use std::ops::SubAssign; @@ -13,20 +13,20 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; use crate::{ indexes, - internal::{ComputedFromHeight, NumericValue, RollingFull, WindowStarts}, + internal::{ComputedPerBlock, NumericValue, RollingFull, WindowStarts}, }; #[derive(Traversable)] -pub struct ComputedHeightDerivedFull +pub struct ResolutionsFull where T: NumericValue + JsonSchema, { - pub cumulative: ComputedFromHeight, + pub cumulative: ComputedPerBlock, #[traversable(flatten)] pub rolling: RollingFull, } -impl ComputedHeightDerivedFull +impl ResolutionsFull where T: NumericValue + JsonSchema, { @@ -37,7 +37,7 @@ where indexes: &indexes::Vecs, ) -> Result { let cumulative = - ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; + ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?; let rolling = RollingFull::forced_import(db, name, version, indexes)?; Ok(Self { diff --git a/crates/brk_computer/src/internal/from_height/computed/rolling_average.rs b/crates/brk_computer/src/internal/per_block/computed/rolling_average.rs similarity index 89% rename from crates/brk_computer/src/internal/from_height/computed/rolling_average.rs rename to crates/brk_computer/src/internal/per_block/computed/rolling_average.rs index f7e472a51..4c5b08089 100644 --- a/crates/brk_computer/src/internal/from_height/computed/rolling_average.rs +++ b/crates/brk_computer/src/internal/per_block/computed/rolling_average.rs @@ -1,7 +1,7 @@ -//! ComputedFromHeight with rolling average (no distribution stats). +//! ComputedPerBlock with rolling average (no distribution stats). //! //! Stored height data + 4-window rolling averages (24h, 1w, 1m, 1y). -//! Use instead of ComputedFromHeightDistribution when only the average +//! Use instead of ComputedPerBlockDistribution when only the average //! is analytically useful (e.g., block interval, activity counts). use brk_error::Result; @@ -16,7 +16,7 @@ use crate::indexes; use crate::internal::{NumericValue, RollingWindows, WindowStarts}; #[derive(Traversable)] -pub struct ComputedFromHeightRollingAverage +pub struct ComputedPerBlockRollingAverage where T: NumericValue + JsonSchema, { @@ -25,7 +25,7 @@ where pub average: RollingWindows, } -impl ComputedFromHeightRollingAverage +impl ComputedPerBlockRollingAverage where T: NumericValue + JsonSchema, { diff --git a/crates/brk_computer/src/internal/from_height/computed/sum.rs b/crates/brk_computer/src/internal/per_block/computed/sum.rs similarity index 85% rename from crates/brk_computer/src/internal/from_height/computed/sum.rs rename to crates/brk_computer/src/internal/per_block/computed/sum.rs index 0257f3793..2c2920d51 100644 --- a/crates/brk_computer/src/internal/from_height/computed/sum.rs +++ b/crates/brk_computer/src/internal/per_block/computed/sum.rs @@ -1,6 +1,6 @@ -//! ComputedFromHeightSum - stored height + RollingWindows (sum only). +//! ComputedPerBlockSum - stored height + RollingWindows (sum only). //! -//! Like ComputedFromHeightCumulativeSum but without the cumulative vec. +//! Like ComputedPerBlockCumulativeSum but without the cumulative vec. use std::ops::SubAssign; @@ -16,7 +16,7 @@ use crate::{ }; #[derive(Traversable)] -pub struct ComputedFromHeightSum +pub struct ComputedPerBlockSum where T: NumericValue + JsonSchema, { @@ -24,7 +24,7 @@ where pub sum: RollingWindows, } -impl ComputedFromHeightSum +impl ComputedPerBlockSum where T: NumericValue + JsonSchema, { diff --git a/crates/brk_computer/src/internal/from_height/fiat/base.rs b/crates/brk_computer/src/internal/per_block/fiat/base.rs similarity index 72% rename from crates/brk_computer/src/internal/from_height/fiat/base.rs rename to crates/brk_computer/src/internal/per_block/fiat/base.rs index 4b76d3589..1da01a0aa 100644 --- a/crates/brk_computer/src/internal/from_height/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, ComputedFromHeight, LazyFromHeight, + CentsSignedToDollars, CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock, NumericValue, }, }; @@ -28,12 +28,12 @@ impl CentsType for CentsSigned { /// Height-indexed fiat monetary value: cents (eager, integer) + usd (lazy, float). /// Generic over `C` to support both `Cents` (unsigned) and `CentsSigned` (signed). #[derive(Traversable)] -pub struct FiatFromHeight { - pub cents: ComputedFromHeight, - pub usd: LazyFromHeight, +pub struct FiatPerBlock { + pub cents: ComputedPerBlock, + pub usd: LazyPerBlock, } -impl FiatFromHeight { +impl FiatPerBlock { pub(crate) fn forced_import( db: &Database, name: &str, @@ -41,8 +41,8 @@ impl FiatFromHeight { indexes: &indexes::Vecs, ) -> Result { let cents = - ComputedFromHeight::forced_import(db, &format!("{name}_cents"), version, indexes)?; - let usd = LazyFromHeight::from_computed::( + ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?; + let usd = LazyPerBlock::from_computed::( name, version, cents.height.read_only_boxed_clone(), diff --git a/crates/brk_computer/src/internal/from_height/fiat/lazy.rs b/crates/brk_computer/src/internal/per_block/fiat/lazy.rs similarity index 60% rename from crates/brk_computer/src/internal/from_height/fiat/lazy.rs rename to crates/brk_computer/src/internal/per_block/fiat/lazy.rs index 14cc28d6f..a7c6bf6cf 100644 --- a/crates/brk_computer/src/internal/from_height/fiat/lazy.rs +++ b/crates/brk_computer/src/internal/per_block/fiat/lazy.rs @@ -2,32 +2,32 @@ use brk_traversable::Traversable; use brk_types::{Dollars, Version}; use vecdb::ReadableCloneableVec; -use crate::internal::{CentsType, ComputedFromHeight, Identity, LazyFromHeight, NumericValue}; +use crate::internal::{CentsType, ComputedPerBlock, Identity, LazyPerBlock, NumericValue}; /// Lazy fiat: both cents and usd are lazy views of a stored source. /// Zero extra stored vecs. #[derive(Clone, Traversable)] -pub struct LazyFiatFromHeight { - pub cents: LazyFromHeight, - pub usd: LazyFromHeight, +pub struct LazyFiatPerBlock { + pub cents: LazyPerBlock, + pub usd: LazyPerBlock, } -impl LazyFiatFromHeight { +impl LazyFiatPerBlock { pub(crate) fn from_computed( name: &str, version: Version, - source: &ComputedFromHeight, + source: &ComputedPerBlock, ) -> Self where C: NumericValue, { - let cents = LazyFromHeight::from_computed::>( + let cents = LazyPerBlock::from_computed::>( &format!("{name}_cents"), version, source.height.read_only_boxed_clone(), source, ); - let usd = LazyFromHeight::from_computed::( + let usd = LazyPerBlock::from_computed::( name, version, source.height.read_only_boxed_clone(), diff --git a/crates/brk_computer/src/internal/from_height/fiat/mod.rs b/crates/brk_computer/src/internal/per_block/fiat/mod.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/fiat/mod.rs rename to crates/brk_computer/src/internal/per_block/fiat/mod.rs diff --git a/crates/brk_computer/src/internal/from_height/lazy/base.rs b/crates/brk_computer/src/internal/per_block/lazy/base.rs similarity index 74% rename from crates/brk_computer/src/internal/from_height/lazy/base.rs rename to crates/brk_computer/src/internal/per_block/lazy/base.rs index f2f3f341a..113f26f21 100644 --- a/crates/brk_computer/src/internal/from_height/lazy/base.rs +++ b/crates/brk_computer/src/internal/per_block/lazy/base.rs @@ -6,11 +6,11 @@ use vecdb::{LazyVecFrom1, ReadableBoxedVec, ReadableCloneableVec, UnaryTransform use crate::{ indexes, - internal::{ComputedFromHeight, ComputedVecValue, LazyHeightDerived, NumericValue}, + internal::{ComputedPerBlock, ComputedVecValue, DerivedResolutions, NumericValue}, }; #[derive(Clone, Deref, DerefMut, Traversable)] #[traversable(merge)] -pub struct LazyFromHeight +pub struct LazyPerBlock where T: ComputedVecValue + PartialOrd + JsonSchema, S1T: ComputedVecValue, @@ -19,10 +19,10 @@ where #[deref] #[deref_mut] #[traversable(flatten)] - pub rest: Box>, + pub resolutions: Box>, } -impl LazyFromHeight +impl LazyPerBlock where T: ComputedVecValue + JsonSchema + 'static, S1T: ComputedVecValue + JsonSchema, @@ -31,14 +31,14 @@ where name: &str, version: Version, height_source: ReadableBoxedVec, - source: &ComputedFromHeight, + source: &ComputedPerBlock, ) -> Self where S1T: NumericValue, { Self { height: LazyVecFrom1::transformed::(name, version, height_source), - rest: Box::new(LazyHeightDerived::from_computed::(name, version, source)), + resolutions: Box::new(DerivedResolutions::from_computed::(name, version, source)), } } @@ -53,7 +53,7 @@ where { Self { height: LazyVecFrom1::transformed::(name, version, height_source.clone()), - rest: Box::new(LazyHeightDerived::from_height_source::( + resolutions: Box::new(DerivedResolutions::from_height_source::( name, version, height_source, @@ -62,11 +62,11 @@ where } } - /// Create by unary-transforming a LazyFromHeight source (chaining lazy vecs). + /// Create by unary-transforming a LazyPerBlock source (chaining lazy vecs). pub(crate) fn from_lazy( name: &str, version: Version, - source: &LazyFromHeight, + source: &LazyPerBlock, ) -> Self where F: UnaryTransform, @@ -78,10 +78,10 @@ where version, source.height.read_only_boxed_clone(), ), - rest: Box::new(LazyHeightDerived::from_lazy::( + resolutions: Box::new(DerivedResolutions::from_lazy::( name, version, - &source.rest, + &source.resolutions, )), } } diff --git a/crates/brk_computer/src/internal/from_height/lazy/derived.rs b/crates/brk_computer/src/internal/per_block/lazy/derived_resolutions.rs similarity index 86% rename from crates/brk_computer/src/internal/from_height/lazy/derived.rs rename to crates/brk_computer/src/internal/per_block/lazy/derived_resolutions.rs index 0298f8d38..086832694 100644 --- a/crates/brk_computer/src/internal/from_height/lazy/derived.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::{ - ComputedFromHeight, ComputedHeightDerived, ComputedVecValue, NumericValue, PerPeriod, + ComputedPerBlock, Resolutions, ComputedVecValue, NumericValue, PerResolution, }, }; @@ -18,9 +18,9 @@ use super::{LazyTransformLast, MapOption}; #[derive(Clone, Deref, DerefMut, Traversable)] #[traversable(transparent)] -pub struct LazyHeightDerived( +pub struct DerivedResolutions( #[allow(clippy::type_complexity)] - pub PerPeriod< + pub PerResolution< LazyTransformLast, Option>, LazyTransformLast, Option>, LazyTransformLast, Option>, @@ -42,7 +42,7 @@ where T: VecValue + PartialOrd + JsonSchema, S1T: VecValue; -impl LazyHeightDerived +impl DerivedResolutions where T: VecValue + PartialOrd + JsonSchema + 'static, S1T: VecValue + PartialOrd + JsonSchema, @@ -50,12 +50,12 @@ where pub(crate) fn from_computed>( name: &str, version: Version, - source: &ComputedFromHeight, + source: &ComputedPerBlock, ) -> Self where S1T: NumericValue, { - Self::from_derived_computed::(name, version, &source.rest) + Self::from_derived_computed::(name, version, &source.resolutions) } pub(crate) fn from_height_source>( @@ -67,14 +67,14 @@ where where S1T: NumericValue, { - let derived = ComputedHeightDerived::forced_import(name, height_source, version, indexes); + let derived = Resolutions::forced_import(name, height_source, version, indexes); Self::from_derived_computed::(name, version, &derived) } pub(crate) fn from_derived_computed>( name: &str, version: Version, - source: &ComputedHeightDerived, + source: &Resolutions, ) -> Self where S1T: NumericValue, @@ -95,7 +95,7 @@ where }; } - Self(PerPeriod { + Self(PerResolution { minute10: period!(minute10), minute30: period!(minute30), hour1: period!(hour1), @@ -109,15 +109,15 @@ where month6: period!(month6), year1: period!(year1), year10: period!(year10), - halvingepoch: epoch!(halvingepoch), - difficultyepoch: epoch!(difficultyepoch), + halving: epoch!(halving), + difficulty: epoch!(difficulty), }) } pub(crate) fn from_lazy( name: &str, version: Version, - source: &LazyHeightDerived, + source: &DerivedResolutions, ) -> Self where F: UnaryTransform, @@ -139,7 +139,7 @@ where }; } - Self(PerPeriod { + Self(PerResolution { minute10: period!(minute10), minute30: period!(minute30), hour1: period!(hour1), @@ -153,8 +153,8 @@ where month6: period!(month6), year1: period!(year1), year10: period!(year10), - halvingepoch: epoch!(halvingepoch), - difficultyepoch: epoch!(difficultyepoch), + halving: epoch!(halving), + difficulty: epoch!(difficulty), }) } } diff --git a/crates/brk_computer/src/internal/from_height/lazy/map_option.rs b/crates/brk_computer/src/internal/per_block/lazy/map_option.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/lazy/map_option.rs rename to crates/brk_computer/src/internal/per_block/lazy/map_option.rs diff --git a/crates/brk_computer/src/internal/from_height/lazy/mod.rs b/crates/brk_computer/src/internal/per_block/lazy/mod.rs similarity index 66% rename from crates/brk_computer/src/internal/from_height/lazy/mod.rs rename to crates/brk_computer/src/internal/per_block/lazy/mod.rs index e3f25d977..c91b78bb4 100644 --- a/crates/brk_computer/src/internal/from_height/lazy/mod.rs +++ b/crates/brk_computer/src/internal/per_block/lazy/mod.rs @@ -1,9 +1,9 @@ mod base; -mod derived; +mod derived_resolutions; mod map_option; mod transform_last; pub use base::*; -pub use derived::*; +pub use derived_resolutions::*; pub use map_option::*; pub use transform_last::*; diff --git a/crates/brk_computer/src/internal/from_height/lazy/transform_last.rs b/crates/brk_computer/src/internal/per_block/lazy/transform_last.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/lazy/transform_last.rs rename to crates/brk_computer/src/internal/per_block/lazy/transform_last.rs diff --git a/crates/brk_computer/src/internal/from_height/mod.rs b/crates/brk_computer/src/internal/per_block/mod.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/mod.rs rename to crates/brk_computer/src/internal/per_block/mod.rs diff --git a/crates/brk_computer/src/internal/from_height/percent/base.rs b/crates/brk_computer/src/internal/per_block/percent/base.rs similarity index 77% rename from crates/brk_computer/src/internal/from_height/percent/base.rs rename to crates/brk_computer/src/internal/per_block/percent/base.rs index 4d64bf25c..d5d30d1d7 100644 --- a/crates/brk_computer/src/internal/from_height/percent/base.rs +++ b/crates/brk_computer/src/internal/per_block/percent/base.rs @@ -10,7 +10,7 @@ use crate::{ internal::{BpsType, ComputeDrawdown}, }; -use crate::internal::{ComputedFromHeight, LazyFromHeight}; +use crate::internal::{ComputedPerBlock, LazyPerBlock}; /// Basis-point storage with both ratio and percentage float views. /// @@ -19,30 +19,30 @@ use crate::internal::{ComputedFromHeight, LazyFromHeight}; /// - `ratio`: bps / 10000 (e.g., 4523 bps -> 0.4523) /// - `percent`: bps / 100 (e.g., 4523 bps -> 45.23%) #[derive(Traversable)] -pub struct PercentFromHeight { - pub bps: ComputedFromHeight, - pub ratio: LazyFromHeight, - pub percent: LazyFromHeight, +pub struct PercentPerBlock { + pub bps: ComputedPerBlock, + pub ratio: LazyPerBlock, + pub percent: LazyPerBlock, } -impl PercentFromHeight { +impl PercentPerBlock { pub(crate) fn forced_import( db: &Database, name: &str, version: Version, indexes: &indexes::Vecs, ) -> Result { - let bps = ComputedFromHeight::forced_import(db, &format!("{name}_bps"), version, indexes)?; + let bps = ComputedPerBlock::forced_import(db, &format!("{name}_bps"), version, indexes)?; let bps_clone = bps.height.read_only_boxed_clone(); - let ratio = LazyFromHeight::from_computed::( + let ratio = LazyPerBlock::from_computed::( &format!("{name}_ratio"), version, bps_clone.clone(), &bps, ); - let percent = LazyFromHeight::from_computed::(name, version, bps_clone, &bps); + let percent = LazyPerBlock::from_computed::(name, version, bps_clone, &bps); Ok(Self { bps, diff --git a/crates/brk_computer/src/internal/from_height/percent/mod.rs b/crates/brk_computer/src/internal/per_block/percent/mod.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/percent/mod.rs rename to crates/brk_computer/src/internal/per_block/percent/mod.rs diff --git a/crates/brk_computer/src/internal/from_height/percent/rolling_average.rs b/crates/brk_computer/src/internal/per_block/percent/rolling_average.rs similarity index 66% rename from crates/brk_computer/src/internal/from_height/percent/rolling_average.rs rename to crates/brk_computer/src/internal/per_block/percent/rolling_average.rs index a02a62c45..ab1de5cff 100644 --- a/crates/brk_computer/src/internal/from_height/percent/rolling_average.rs +++ b/crates/brk_computer/src/internal/per_block/percent/rolling_average.rs @@ -8,38 +8,38 @@ use crate::{ internal::{BpsType, WindowStarts}, }; -use crate::internal::{ComputedFromHeightRollingAverage, LazyFromHeight}; +use crate::internal::{ComputedPerBlockRollingAverage, LazyPerBlock}; -/// Like PercentFromHeight but with rolling average stats on the bps data. +/// Like PercentPerBlock but with rolling average stats on the bps data. #[derive(Traversable)] -pub struct PercentFromHeightRollingAverage { - pub bps: ComputedFromHeightRollingAverage, - pub ratio: LazyFromHeight, - pub percent: LazyFromHeight, +pub struct PercentPerBlockRollingAverage { + pub bps: ComputedPerBlockRollingAverage, + pub ratio: LazyPerBlock, + pub percent: LazyPerBlock, } -impl PercentFromHeightRollingAverage { +impl PercentPerBlockRollingAverage { pub(crate) fn forced_import( db: &Database, name: &str, version: Version, indexes: &indexes::Vecs, ) -> Result { - let bps = ComputedFromHeightRollingAverage::forced_import( + let bps = ComputedPerBlockRollingAverage::forced_import( db, &format!("{name}_bps"), version, indexes, )?; - let ratio = LazyFromHeight::from_height_source::( + let ratio = LazyPerBlock::from_height_source::( &format!("{name}_ratio"), version, bps.height.read_only_boxed_clone(), indexes, ); - let percent = LazyFromHeight::from_height_source::( + let percent = LazyPerBlock::from_height_source::( name, version, bps.height.read_only_boxed_clone(), diff --git a/crates/brk_computer/src/internal/from_height/percent/windows.rs b/crates/brk_computer/src/internal/per_block/percent/windows.rs similarity index 78% rename from crates/brk_computer/src/internal/from_height/percent/windows.rs rename to crates/brk_computer/src/internal/per_block/percent/windows.rs index 58e7ee69d..40d236830 100644 --- a/crates/brk_computer/src/internal/from_height/percent/windows.rs +++ b/crates/brk_computer/src/internal/per_block/percent/windows.rs @@ -6,7 +6,7 @@ use vecdb::{Database, Rw, StorageMode}; use crate::{ indexes, - internal::{BpsType, PercentFromHeight, Windows}, + internal::{BpsType, PercentPerBlock, Windows}, }; /// 4 rolling window vecs (24h, 1w, 1m, 1y), each storing basis points @@ -14,7 +14,7 @@ use crate::{ #[derive(Deref, DerefMut, Traversable)] #[traversable(transparent)] pub struct PercentRollingWindows( - pub Windows>, + pub Windows>, ); impl PercentRollingWindows { @@ -25,7 +25,7 @@ impl PercentRollingWindows { indexes: &indexes::Vecs, ) -> Result { Ok(Self(Windows::try_from_fn(|suffix| { - PercentFromHeight::forced_import(db, &format!("{name}_{suffix}"), version, indexes) + PercentPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes) })?)) } } diff --git a/crates/brk_computer/src/internal/from_height/percentiles.rs b/crates/brk_computer/src/internal/per_block/percentiles.rs similarity index 93% rename from crates/brk_computer/src/internal/from_height/percentiles.rs rename to crates/brk_computer/src/internal/per_block/percentiles.rs index f0157c3ef..33db180b5 100644 --- a/crates/brk_computer/src/internal/from_height/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::{ComputedFromHeight, Price}; +use crate::internal::{ComputedPerBlock, 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/from_height/price.rs b/crates/brk_computer/src/internal/per_block/price.rs similarity index 72% rename from crates/brk_computer/src/internal/from_height/price.rs rename to crates/brk_computer/src/internal/per_block/price.rs index 1771ed72c..47ce01f07 100644 --- a/crates/brk_computer/src/internal/from_height/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::{ComputedFromHeight, LazyFromHeight}; +use super::{ComputedPerBlock, LazyPerBlock}; use crate::{ indexes, internal::{CentsUnsignedToDollars, ComputedVecValue, DollarsToSatsFract, NumericValue}, @@ -20,11 +20,11 @@ use crate::{ #[derive(Clone, Traversable)] pub struct Price { pub cents: C, - pub usd: LazyFromHeight, - pub sats: LazyFromHeight, + pub usd: LazyPerBlock, + pub sats: LazyPerBlock, } -impl Price> { +impl Price> { /// Import from database: stored cents, lazy USD + sats. pub(crate) fn forced_import( db: &Database, @@ -33,14 +33,14 @@ impl Price> { indexes: &indexes::Vecs, ) -> Result { let cents = - ComputedFromHeight::forced_import(db, &format!("{name}_cents"), version, indexes)?; - let usd = LazyFromHeight::from_computed::( + ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?; + let usd = LazyPerBlock::from_computed::( &format!("{name}_usd"), version, cents.height.read_only_boxed_clone(), ¢s, ); - let sats = LazyFromHeight::from_lazy::( + let sats = LazyPerBlock::from_lazy::( &format!("{name}_sats"), version, &usd, @@ -49,7 +49,7 @@ impl Price> { } } -impl Price> +impl Price> where ST: ComputedVecValue + NumericValue + JsonSchema + 'static, { @@ -57,20 +57,20 @@ where pub(crate) fn from_cents_source>( name: &str, version: Version, - source: &ComputedFromHeight, + source: &ComputedPerBlock, ) -> Self { - let cents = LazyFromHeight::from_computed::( + let cents = LazyPerBlock::from_computed::( &format!("{name}_cents"), version, source.height.read_only_boxed_clone(), source, ); - let usd = LazyFromHeight::from_lazy::( + let usd = LazyPerBlock::from_lazy::( &format!("{name}_usd"), version, ¢s, ); - let sats = LazyFromHeight::from_lazy::( + let sats = LazyPerBlock::from_lazy::( &format!("{name}_sats"), version, &usd, diff --git a/crates/brk_computer/src/internal/from_height/ratio/base.rs b/crates/brk_computer/src/internal/per_block/ratio/base.rs similarity index 79% rename from crates/brk_computer/src/internal/from_height/ratio/base.rs rename to crates/brk_computer/src/internal/per_block/ratio/base.rs index 0d738c034..0bd400c4f 100644 --- a/crates/brk_computer/src/internal/from_height/ratio/base.rs +++ b/crates/brk_computer/src/internal/per_block/ratio/base.rs @@ -5,18 +5,18 @@ use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode}; use crate::{ indexes, - internal::{Bp32ToFloat, ComputedFromHeight, LazyFromHeight}, + internal::{Bp32ToFloat, ComputedPerBlock, LazyPerBlock}, }; #[derive(Traversable)] -pub struct ComputedFromHeightRatio { - pub bps: ComputedFromHeight, - pub ratio: LazyFromHeight, +pub struct RatioPerBlock { + pub bps: ComputedPerBlock, + pub ratio: LazyPerBlock, } const VERSION: Version = Version::TWO; -impl ComputedFromHeightRatio { +impl RatioPerBlock { pub(crate) fn forced_import( db: &Database, name: &str, @@ -34,9 +34,9 @@ impl ComputedFromHeightRatio { ) -> Result { let v = version + VERSION; - let bps = ComputedFromHeight::forced_import(db, &format!("{name}_bps"), v, indexes)?; + let bps = ComputedPerBlock::forced_import(db, &format!("{name}_bps"), v, indexes)?; - let ratio = LazyFromHeight::from_computed::( + let ratio = LazyPerBlock::from_computed::( name, v, bps.height.read_only_boxed_clone(), diff --git a/crates/brk_computer/src/internal/from_height/ratio/extended.rs b/crates/brk_computer/src/internal/per_block/ratio/extended.rs similarity index 74% rename from crates/brk_computer/src/internal/from_height/ratio/extended.rs rename to crates/brk_computer/src/internal/per_block/ratio/extended.rs index 73ec23ddd..c3262639d 100644 --- a/crates/brk_computer/src/internal/from_height/ratio/extended.rs +++ b/crates/brk_computer/src/internal/per_block/ratio/extended.rs @@ -6,19 +6,19 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; use crate::{blocks, indexes, prices}; -use super::{ComputedFromHeightRatio, ComputedFromHeightRatioPercentiles}; +use super::{RatioPerBlock, RatioPerBlockPercentiles}; #[derive(Deref, DerefMut, Traversable)] -pub struct ComputedFromHeightRatioExtended { +pub struct RatioPerBlockExtended { #[deref] #[deref_mut] #[traversable(flatten)] - pub base: ComputedFromHeightRatio, + pub base: RatioPerBlock, #[traversable(flatten)] - pub percentiles: ComputedFromHeightRatioPercentiles, + pub percentiles: RatioPerBlockPercentiles, } -impl ComputedFromHeightRatioExtended { +impl RatioPerBlockExtended { pub(crate) fn forced_import( db: &Database, name: &str, @@ -26,8 +26,8 @@ impl ComputedFromHeightRatioExtended { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - base: ComputedFromHeightRatio::forced_import(db, name, version, indexes)?, - percentiles: ComputedFromHeightRatioPercentiles::forced_import( + base: RatioPerBlock::forced_import(db, name, version, indexes)?, + percentiles: RatioPerBlockPercentiles::forced_import( db, name, version, indexes, )?, }) diff --git a/crates/brk_computer/src/internal/from_height/ratio/mod.rs b/crates/brk_computer/src/internal/per_block/ratio/mod.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/ratio/mod.rs rename to crates/brk_computer/src/internal/per_block/ratio/mod.rs diff --git a/crates/brk_computer/src/internal/from_height/ratio/percentiles.rs b/crates/brk_computer/src/internal/per_block/ratio/percentiles.rs similarity index 85% rename from crates/brk_computer/src/internal/from_height/ratio/percentiles.rs rename to crates/brk_computer/src/internal/per_block/ratio/percentiles.rs index c8affef01..6f1a093a1 100644 --- a/crates/brk_computer/src/internal/from_height/ratio/percentiles.rs +++ b/crates/brk_computer/src/internal/per_block/ratio/percentiles.rs @@ -11,24 +11,24 @@ use crate::{ internal::{ExpandingPercentiles, Price, PriceTimesRatioBp32Cents}, }; -use super::{super::ComputedFromHeight, ComputedFromHeightRatio}; +use super::{super::ComputedPerBlock, RatioPerBlock}; #[derive(Traversable)] -pub struct ComputedFromHeightRatioPercentiles { - pub ratio_sma_1w: ComputedFromHeightRatio, - pub ratio_sma_1m: ComputedFromHeightRatio, - pub ratio_pct99: ComputedFromHeightRatio, - pub ratio_pct98: ComputedFromHeightRatio, - pub ratio_pct95: ComputedFromHeightRatio, - pub ratio_pct5: ComputedFromHeightRatio, - pub ratio_pct2: ComputedFromHeightRatio, - pub ratio_pct1: ComputedFromHeightRatio, - pub ratio_pct99_price: Price>, - pub ratio_pct98_price: Price>, - pub ratio_pct95_price: Price>, - pub ratio_pct5_price: Price>, - pub ratio_pct2_price: Price>, - pub ratio_pct1_price: Price>, +pub struct RatioPerBlockPercentiles { + pub ratio_sma_1w: RatioPerBlock, + pub ratio_sma_1m: RatioPerBlock, + pub ratio_pct99: RatioPerBlock, + pub ratio_pct98: RatioPerBlock, + pub ratio_pct95: RatioPerBlock, + pub ratio_pct5: RatioPerBlock, + pub ratio_pct2: RatioPerBlock, + pub ratio_pct1: RatioPerBlock, + pub ratio_pct99_price: Price>, + pub ratio_pct98_price: Price>, + pub ratio_pct95_price: Price>, + pub ratio_pct5_price: Price>, + pub ratio_pct2_price: Price>, + pub ratio_pct1_price: Price>, #[traversable(skip)] expanding_pct: ExpandingPercentiles, @@ -36,7 +36,7 @@ pub struct ComputedFromHeightRatioPercentiles { const VERSION: Version = Version::new(4); -impl ComputedFromHeightRatioPercentiles { +impl RatioPerBlockPercentiles { pub(crate) fn forced_import( db: &Database, name: &str, @@ -47,7 +47,7 @@ impl ComputedFromHeightRatioPercentiles { macro_rules! import_ratio { ($suffix:expr) => { - ComputedFromHeightRatio::forced_import_raw( + RatioPerBlock::forced_import_raw( db, &format!("{name}_{}", $suffix), v, diff --git a/crates/brk_computer/src/internal/from_height/ratio/price_extended.rs b/crates/brk_computer/src/internal/per_block/ratio/price_extended.rs similarity index 76% rename from crates/brk_computer/src/internal/from_height/ratio/price_extended.rs rename to crates/brk_computer/src/internal/per_block/ratio/price_extended.rs index 71fb36575..4aa14e805 100644 --- a/crates/brk_computer/src/internal/from_height/ratio/price_extended.rs +++ b/crates/brk_computer/src/internal/per_block/ratio/price_extended.rs @@ -4,21 +4,21 @@ use brk_types::{Cents, Height, Indexes, Version}; use derive_more::{Deref, DerefMut}; use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode}; -use crate::internal::{ComputedFromHeight, Price}; +use crate::internal::{ComputedPerBlock, Price}; use crate::{indexes, prices}; -use super::ComputedFromHeightRatio; +use super::RatioPerBlock; #[derive(Deref, DerefMut, Traversable)] -pub struct ComputedFromHeightPriceWithRatio { +pub struct PriceWithRatioPerBlock { #[deref] #[deref_mut] #[traversable(flatten)] - pub inner: ComputedFromHeightRatio, - pub price: Price>, + pub inner: RatioPerBlock, + pub price: Price>, } -impl ComputedFromHeightPriceWithRatio { +impl PriceWithRatioPerBlock { pub(crate) fn forced_import( db: &Database, name: &str, @@ -27,7 +27,7 @@ impl ComputedFromHeightPriceWithRatio { ) -> Result { let v = version + Version::TWO; Ok(Self { - inner: ComputedFromHeightRatio::forced_import(db, name, version, indexes)?, + inner: RatioPerBlock::forced_import(db, name, version, indexes)?, price: Price::forced_import(db, name, v, indexes)?, }) } diff --git a/crates/brk_computer/src/internal/from_height/ratio/std_dev_bands.rs b/crates/brk_computer/src/internal/per_block/ratio/std_dev_bands.rs similarity index 77% rename from crates/brk_computer/src/internal/from_height/ratio/std_dev_bands.rs rename to crates/brk_computer/src/internal/per_block/ratio/std_dev_bands.rs index 645a76b03..c57471c9a 100644 --- a/crates/brk_computer/src/internal/from_height/ratio/std_dev_bands.rs +++ b/crates/brk_computer/src/internal/per_block/ratio/std_dev_bands.rs @@ -3,19 +3,19 @@ use brk_traversable::Traversable; use brk_types::{Cents, Height, Indexes, StoredF32, Version}; use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; -use crate::{blocks, indexes, internal::ComputedFromHeightStdDevExtended}; +use crate::{blocks, indexes, internal::StdDevPerBlockExtended}; #[derive(Traversable)] -pub struct ComputedFromHeightRatioStdDevBands { - pub ratio_sd: ComputedFromHeightStdDevExtended, - pub ratio_sd_4y: ComputedFromHeightStdDevExtended, - pub ratio_sd_2y: ComputedFromHeightStdDevExtended, - pub ratio_sd_1y: ComputedFromHeightStdDevExtended, +pub struct RatioPerBlockStdDevBands { + pub ratio_sd: StdDevPerBlockExtended, + pub ratio_sd_4y: StdDevPerBlockExtended, + pub ratio_sd_2y: StdDevPerBlockExtended, + pub ratio_sd_1y: StdDevPerBlockExtended, } const VERSION: Version = Version::new(4); -impl ComputedFromHeightRatioStdDevBands { +impl RatioPerBlockStdDevBands { pub(crate) fn forced_import( db: &Database, name: &str, @@ -26,7 +26,7 @@ impl ComputedFromHeightRatioStdDevBands { macro_rules! import_sd { ($suffix:expr, $period:expr, $days:expr) => { - ComputedFromHeightStdDevExtended::forced_import( + StdDevPerBlockExtended::forced_import( db, &format!("{name}_{}", $suffix), $period, diff --git a/crates/brk_computer/src/internal/from_height/rolling/distribution.rs b/crates/brk_computer/src/internal/per_block/rolling/distribution.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/rolling/distribution.rs rename to crates/brk_computer/src/internal/per_block/rolling/distribution.rs diff --git a/crates/brk_computer/src/internal/from_height/rolling/full.rs b/crates/brk_computer/src/internal/per_block/rolling/full.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/rolling/full.rs rename to crates/brk_computer/src/internal/per_block/rolling/full.rs diff --git a/crates/brk_computer/src/internal/from_height/rolling/mod.rs b/crates/brk_computer/src/internal/per_block/rolling/mod.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/rolling/mod.rs rename to crates/brk_computer/src/internal/per_block/rolling/mod.rs diff --git a/crates/brk_computer/src/internal/from_height/rolling/windows.rs b/crates/brk_computer/src/internal/per_block/rolling/windows.rs similarity index 84% rename from crates/brk_computer/src/internal/from_height/rolling/windows.rs rename to crates/brk_computer/src/internal/per_block/rolling/windows.rs index 7e2a6577a..9ccca1b96 100644 --- a/crates/brk_computer/src/internal/from_height/rolling/windows.rs +++ b/crates/brk_computer/src/internal/per_block/rolling/windows.rs @@ -1,4 +1,4 @@ -//! RollingWindows - newtype on Windows with ComputedFromHeight per window duration. +//! RollingWindows - newtype on Windows with ComputedPerBlock per window duration. //! //! Each of the 4 windows (24h, 1w, 1m, 1y) contains a height-level stored vec //! plus all 17 LazyAggVec index views. @@ -15,7 +15,7 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode}; use crate::{ indexes, - internal::{ComputedFromHeight, ComputedVecValue, NumericValue, Windows}, + internal::{ComputedPerBlock, ComputedVecValue, NumericValue, Windows}, }; /// Rolling window start heights — the 4 height-ago vecs (24h, 1w, 1m, 1y). @@ -24,7 +24,7 @@ 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; @@ -39,7 +39,7 @@ where indexes: &indexes::Vecs, ) -> Result { Ok(Self(Windows::try_from_fn(|suffix| { - ComputedFromHeight::forced_import(db, &format!("{name}_{suffix}"), version, indexes) + ComputedPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes) })?)) } @@ -68,7 +68,7 @@ where T: ComputedVecValue + PartialOrd + JsonSchema, { #[traversable(rename = "24h")] - pub _24h: ComputedFromHeight, + pub _24h: ComputedPerBlock, } impl RollingWindow24h @@ -82,7 +82,7 @@ where indexes: &indexes::Vecs, ) -> Result { Ok(Self { - _24h: ComputedFromHeight::forced_import( + _24h: ComputedPerBlock::forced_import( db, &format!("{name}_24h"), version, @@ -115,11 +115,11 @@ where T: ComputedVecValue + PartialOrd + JsonSchema, { #[traversable(rename = "1w")] - pub _1w: ComputedFromHeight, + pub _1w: ComputedPerBlock, #[traversable(rename = "1m")] - pub _1m: ComputedFromHeight, + pub _1m: ComputedPerBlock, #[traversable(rename = "1y")] - pub _1y: ComputedFromHeight, + pub _1y: ComputedPerBlock, } impl RollingWindowsFrom1w @@ -133,19 +133,19 @@ where indexes: &indexes::Vecs, ) -> Result { Ok(Self { - _1w: ComputedFromHeight::forced_import( + _1w: ComputedPerBlock::forced_import( db, &format!("{name}_1w"), version, indexes, )?, - _1m: ComputedFromHeight::forced_import( + _1m: ComputedPerBlock::forced_import( db, &format!("{name}_1m"), version, indexes, )?, - _1y: ComputedFromHeight::forced_import( + _1y: ComputedPerBlock::forced_import( db, &format!("{name}_1y"), version, @@ -154,11 +154,11 @@ where }) } - pub fn as_array(&self) -> [&ComputedFromHeight; 3] { + pub fn as_array(&self) -> [&ComputedPerBlock; 3] { [&self._1w, &self._1m, &self._1y] } - pub fn as_mut_array(&mut self) -> [&mut ComputedFromHeight; 3] { + pub fn as_mut_array(&mut self) -> [&mut ComputedPerBlock; 3] { [&mut self._1w, &mut self._1m, &mut self._1y] } diff --git a/crates/brk_computer/src/internal/from_height/stddev/base.rs b/crates/brk_computer/src/internal/per_block/stddev/base.rs similarity index 78% rename from crates/brk_computer/src/internal/from_height/stddev/base.rs rename to crates/brk_computer/src/internal/per_block/stddev/base.rs index fca17d7e7..30ffa8e0b 100644 --- a/crates/brk_computer/src/internal/from_height/stddev/base.rs +++ b/crates/brk_computer/src/internal/per_block/stddev/base.rs @@ -3,18 +3,18 @@ use brk_traversable::Traversable; use brk_types::{Height, Indexes, StoredF32, Version}; use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; -use crate::{blocks, indexes, internal::ComputedFromHeight}; +use crate::{blocks, indexes, internal::ComputedPerBlock}; use super::period_suffix; #[derive(Traversable)] -pub struct ComputedFromHeightStdDev { +pub struct StdDevPerBlock { days: usize, - pub sma: ComputedFromHeight, - pub sd: ComputedFromHeight, + pub sma: ComputedPerBlock, + pub sd: ComputedPerBlock, } -impl ComputedFromHeightStdDev { +impl StdDevPerBlock { pub(crate) fn forced_import( db: &Database, name: &str, @@ -27,8 +27,8 @@ impl ComputedFromHeightStdDev { let p = period_suffix(period); let sma = - ComputedFromHeight::forced_import(db, &format!("{name}_sma{p}"), version, indexes)?; - let sd = ComputedFromHeight::forced_import(db, &format!("{name}_sd{p}"), version, indexes)?; + ComputedPerBlock::forced_import(db, &format!("{name}_sma{p}"), version, indexes)?; + let sd = ComputedPerBlock::forced_import(db, &format!("{name}_sd{p}"), version, indexes)?; Ok(Self { days, sma, sd }) } diff --git a/crates/brk_computer/src/internal/from_height/stddev/extended.rs b/crates/brk_computer/src/internal/per_block/stddev/extended.rs similarity index 80% rename from crates/brk_computer/src/internal/from_height/stddev/extended.rs rename to crates/brk_computer/src/internal/per_block/stddev/extended.rs index 4828c74b3..86df1f4a7 100644 --- a/crates/brk_computer/src/internal/from_height/stddev/extended.rs +++ b/crates/brk_computer/src/internal/per_block/stddev/extended.rs @@ -8,47 +8,47 @@ use vecdb::{ use crate::{ blocks, indexes, - internal::{ComputedFromHeight, Price, PriceTimesRatioCents}, + internal::{ComputedPerBlock, Price, PriceTimesRatioCents}, }; -use super::ComputedFromHeightStdDev; +use super::StdDevPerBlock; #[derive(Traversable)] -pub struct ComputedFromHeightStdDevExtended { +pub struct StdDevPerBlockExtended { #[traversable(flatten)] - pub base: ComputedFromHeightStdDev, + pub base: StdDevPerBlock, - pub zscore: ComputedFromHeight, + pub zscore: ComputedPerBlock, - pub p0_5sd: ComputedFromHeight, - pub p1sd: ComputedFromHeight, - pub p1_5sd: ComputedFromHeight, - pub p2sd: ComputedFromHeight, - pub p2_5sd: ComputedFromHeight, - pub p3sd: ComputedFromHeight, - pub m0_5sd: ComputedFromHeight, - pub m1sd: ComputedFromHeight, - pub m1_5sd: ComputedFromHeight, - pub m2sd: ComputedFromHeight, - pub m2_5sd: ComputedFromHeight, - pub m3sd: ComputedFromHeight, + pub p0_5sd: ComputedPerBlock, + pub p1sd: ComputedPerBlock, + pub p1_5sd: ComputedPerBlock, + pub p2sd: ComputedPerBlock, + pub p2_5sd: ComputedPerBlock, + pub p3sd: ComputedPerBlock, + pub m0_5sd: ComputedPerBlock, + pub m1sd: ComputedPerBlock, + pub m1_5sd: ComputedPerBlock, + pub m2sd: ComputedPerBlock, + pub m2_5sd: ComputedPerBlock, + pub m3sd: ComputedPerBlock, - pub _0sd_price: Price>, - pub p0_5sd_price: Price>, - pub p1sd_price: Price>, - pub p1_5sd_price: Price>, - pub p2sd_price: Price>, - pub p2_5sd_price: Price>, - pub p3sd_price: Price>, - pub m0_5sd_price: Price>, - pub m1sd_price: Price>, - pub m1_5sd_price: Price>, - pub m2sd_price: Price>, - pub m2_5sd_price: Price>, - pub m3sd_price: Price>, + pub _0sd_price: Price>, + pub p0_5sd_price: Price>, + pub p1sd_price: Price>, + pub p1_5sd_price: Price>, + pub p2sd_price: Price>, + pub p2_5sd_price: Price>, + pub p3sd_price: Price>, + pub m0_5sd_price: Price>, + pub m1sd_price: Price>, + pub m1_5sd_price: Price>, + pub m2sd_price: Price>, + pub m2_5sd_price: Price>, + pub m3sd_price: Price>, } -impl ComputedFromHeightStdDevExtended { +impl StdDevPerBlockExtended { pub(crate) fn forced_import( db: &Database, name: &str, @@ -62,7 +62,7 @@ impl ComputedFromHeightStdDevExtended { macro_rules! import { ($suffix:expr) => { - ComputedFromHeight::forced_import( + ComputedPerBlock::forced_import( db, &format!("{name}_{}{p}", $suffix), version, @@ -78,7 +78,7 @@ impl ComputedFromHeightStdDevExtended { } Ok(Self { - base: ComputedFromHeightStdDev::forced_import( + base: StdDevPerBlock::forced_import( db, name, period, diff --git a/crates/brk_computer/src/internal/from_height/stddev/mod.rs b/crates/brk_computer/src/internal/per_block/stddev/mod.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/stddev/mod.rs rename to crates/brk_computer/src/internal/per_block/stddev/mod.rs diff --git a/crates/brk_computer/src/internal/from_tx/derived.rs b/crates/brk_computer/src/internal/per_tx/derived.rs similarity index 100% rename from crates/brk_computer/src/internal/from_tx/derived.rs rename to crates/brk_computer/src/internal/per_tx/derived.rs diff --git a/crates/brk_computer/src/internal/from_tx/distribution.rs b/crates/brk_computer/src/internal/per_tx/distribution.rs similarity index 89% rename from crates/brk_computer/src/internal/from_tx/distribution.rs rename to crates/brk_computer/src/internal/per_tx/distribution.rs index 5e00e2952..6554110cc 100644 --- a/crates/brk_computer/src/internal/from_tx/distribution.rs +++ b/crates/brk_computer/src/internal/per_tx/distribution.rs @@ -1,4 +1,4 @@ -//! ComputedFromTxDistribution - stored per-tx EagerVec + computed distribution. +//! ComputedPerTxDistribution - 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 ComputedFromTxDistribution +pub struct ComputedPerTxDistribution where T: ComputedVecValue + PartialOrd + JsonSchema, { @@ -25,7 +25,7 @@ where pub distribution: TxDerivedDistribution, } -impl ComputedFromTxDistribution +impl ComputedPerTxDistribution where T: NumericValue + JsonSchema, { diff --git a/crates/brk_computer/src/internal/from_tx/lazy_distribution.rs b/crates/brk_computer/src/internal/per_tx/lazy_distribution.rs similarity index 93% rename from crates/brk_computer/src/internal/from_tx/lazy_distribution.rs rename to crates/brk_computer/src/internal/per_tx/lazy_distribution.rs index 1ca6357f6..f01f3f516 100644 --- a/crates/brk_computer/src/internal/from_tx/lazy_distribution.rs +++ b/crates/brk_computer/src/internal/per_tx/lazy_distribution.rs @@ -11,7 +11,7 @@ use crate::{ }; #[derive(Traversable)] -pub struct LazyFromTxDistribution +pub struct LazyPerTxDistribution where T: ComputedVecValue + PartialOrd + JsonSchema, S1: ComputedVecValue, @@ -22,7 +22,7 @@ where pub distribution: TxDerivedDistribution, } -impl LazyFromTxDistribution +impl LazyPerTxDistribution where T: NumericValue + JsonSchema, S1: ComputedVecValue + JsonSchema, diff --git a/crates/brk_computer/src/internal/from_tx/mod.rs b/crates/brk_computer/src/internal/per_tx/mod.rs similarity index 100% rename from crates/brk_computer/src/internal/from_tx/mod.rs rename to crates/brk_computer/src/internal/per_tx/mod.rs diff --git a/crates/brk_computer/src/market/ath/import.rs b/crates/brk_computer/src/market/ath/import.rs index 4e13e0037..85cc7116c 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::{ComputedFromHeight, DaysToYears, LazyHeightDerived, PercentFromHeight, Price}, + internal::{ComputedPerBlock, DaysToYears, DerivedResolutions, PercentPerBlock, Price}, }; const VERSION: Version = Version::ONE; @@ -21,24 +21,24 @@ impl Vecs { let price_ath = Price::forced_import(db, "price_ath", v, indexes)?; let max_days_between_price_ath = - ComputedFromHeight::forced_import(db, "max_days_between_price_ath", v, indexes)?; + ComputedPerBlock::forced_import(db, "max_days_between_price_ath", v, indexes)?; - let max_years_between_price_ath = LazyHeightDerived::from_computed::( + let max_years_between_price_ath = DerivedResolutions::from_computed::( "max_years_between_price_ath", v, &max_days_between_price_ath, ); let days_since_price_ath = - ComputedFromHeight::forced_import(db, "days_since_price_ath", v, indexes)?; + ComputedPerBlock::forced_import(db, "days_since_price_ath", v, indexes)?; - let years_since_price_ath = LazyHeightDerived::from_computed::( + let years_since_price_ath = DerivedResolutions::from_computed::( "years_since_price_ath", v, &days_since_price_ath, ); - let price_drawdown = PercentFromHeight::forced_import(db, "price_drawdown", v, indexes)?; + let price_drawdown = PercentPerBlock::forced_import(db, "price_drawdown", v, indexes)?; Ok(Self { price_ath, diff --git a/crates/brk_computer/src/market/ath/vecs.rs b/crates/brk_computer/src/market/ath/vecs.rs index 603ed27a7..1c5e44399 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::{ComputedFromHeight, LazyHeightDerived, PercentFromHeight, Price}; +use crate::internal::{ComputedPerBlock, DerivedResolutions, PercentPerBlock, Price}; #[derive(Traversable)] pub struct Vecs { - pub price_ath: Price>, - pub price_drawdown: PercentFromHeight, - pub days_since_price_ath: ComputedFromHeight, - pub years_since_price_ath: LazyHeightDerived, - pub max_days_between_price_ath: ComputedFromHeight, - pub max_years_between_price_ath: LazyHeightDerived, + pub price_ath: Price>, + pub price_drawdown: PercentPerBlock, + pub days_since_price_ath: ComputedPerBlock, + pub years_since_price_ath: DerivedResolutions, + pub max_days_between_price_ath: ComputedPerBlock, + pub max_years_between_price_ath: DerivedResolutions, } diff --git a/crates/brk_computer/src/market/dca/import.rs b/crates/brk_computer/src/market/dca/import.rs index 55a26281e..87b5275ee 100644 --- a/crates/brk_computer/src/market/dca/import.rs +++ b/crates/brk_computer/src/market/dca/import.rs @@ -5,7 +5,7 @@ use vecdb::{Database, ImportableVec}; use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod, Vecs}; use crate::{ indexes, - internal::{AmountFromHeight, PercentFromHeight, Price}, + internal::{AmountPerBlock, PercentPerBlock, Price}, }; impl Vecs { @@ -15,7 +15,7 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { let period_stack = ByDcaPeriod::try_new(|name, _days| { - AmountFromHeight::forced_import(db, &format!("dca_stack_{name}"), version, indexes) + AmountPerBlock::forced_import(db, &format!("dca_stack_{name}"), version, indexes) })?; let period_cost_basis = ByDcaPeriod::try_new(|name, _days| { @@ -23,19 +23,19 @@ impl Vecs { })?; let period_return = ByDcaPeriod::try_new(|name, _days| { - PercentFromHeight::forced_import(db, &format!("dca_return_{name}"), version, indexes) + PercentPerBlock::forced_import(db, &format!("dca_return_{name}"), version, indexes) })?; let period_cagr = ByDcaCagr::try_new(|name, _days| { - PercentFromHeight::forced_import(db, &format!("dca_cagr_{name}"), version, indexes) + PercentPerBlock::forced_import(db, &format!("dca_cagr_{name}"), version, indexes) })?; let period_lump_sum_stack = ByDcaPeriod::try_new(|name, _days| { - AmountFromHeight::forced_import(db, &format!("lump_sum_stack_{name}"), version, indexes) + AmountPerBlock::forced_import(db, &format!("lump_sum_stack_{name}"), version, indexes) })?; let period_lump_sum_return = ByDcaPeriod::try_new(|name, _days| { - PercentFromHeight::forced_import( + PercentPerBlock::forced_import( db, &format!("lump_sum_return_{name}"), version, @@ -44,7 +44,7 @@ impl Vecs { })?; let class_stack = ByDcaClass::try_new(|name, _year, _day1| { - AmountFromHeight::forced_import(db, &format!("dca_stack_{name}"), version, indexes) + AmountPerBlock::forced_import(db, &format!("dca_stack_{name}"), version, indexes) })?; let class_cost_basis = ByDcaClass::try_new(|name, _year, _day1| { @@ -52,7 +52,7 @@ impl Vecs { })?; let class_return = ByDcaClass::try_new(|name, _year, _day1| { - PercentFromHeight::forced_import(db, &format!("dca_return_{name}"), version, indexes) + PercentPerBlock::forced_import(db, &format!("dca_return_{name}"), version, indexes) })?; Ok(Self { diff --git a/crates/brk_computer/src/market/dca/vecs.rs b/crates/brk_computer/src/market/dca/vecs.rs index 012f61975..fffea582e 100644 --- a/crates/brk_computer/src/market/dca/vecs.rs +++ b/crates/brk_computer/src/market/dca/vecs.rs @@ -3,7 +3,7 @@ use brk_types::{BasisPointsSigned32, Cents, Height, Sats}; use vecdb::{EagerVec, PcoVec, Rw, StorageMode}; use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod}; -use crate::internal::{AmountFromHeight, ComputedFromHeight, PercentFromHeight, Price}; +use crate::internal::{AmountPerBlock, ComputedPerBlock, PercentPerBlock, Price}; #[derive(Traversable)] pub struct Vecs { /// Per-height DCA sats contribution: sats_from_dca(close) on day boundaries, 0 otherwise. @@ -11,17 +11,17 @@ pub struct Vecs { pub dca_sats_per_day: M::Stored>>, // DCA by period - pub period_stack: ByDcaPeriod>, - pub period_cost_basis: ByDcaPeriod>>, - pub period_return: ByDcaPeriod>, - pub period_cagr: ByDcaCagr>, + pub period_stack: ByDcaPeriod>, + pub period_cost_basis: ByDcaPeriod>>, + pub period_return: ByDcaPeriod>, + pub period_cagr: ByDcaCagr>, // Lump sum by period (for comparison with DCA) - pub period_lump_sum_stack: ByDcaPeriod>, - pub period_lump_sum_return: ByDcaPeriod>, + pub period_lump_sum_stack: ByDcaPeriod>, + pub period_lump_sum_return: ByDcaPeriod>, // DCA by year class - pub class_stack: ByDcaClass>, - pub class_cost_basis: ByDcaClass>>, - pub class_return: ByDcaClass>, + pub class_stack: ByDcaClass>, + pub class_cost_basis: ByDcaClass>>, + pub class_return: ByDcaClass>, } diff --git a/crates/brk_computer/src/market/indicators/gini.rs b/crates/brk_computer/src/market/indicators/gini.rs index 952680a5d..af5a439b4 100644 --- a/crates/brk_computer/src/market/indicators/gini.rs +++ b/crates/brk_computer/src/market/indicators/gini.rs @@ -2,10 +2,10 @@ use brk_error::Result; use brk_types::{BasisPoints16, Indexes, Sats, StoredU64, Version}; use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, VecIndex, WritableVec}; -use crate::{distribution, internal::PercentFromHeight}; +use crate::{distribution, internal::PercentPerBlock}; pub(super) fn compute( - gini: &mut PercentFromHeight, + gini: &mut PercentPerBlock, distribution: &distribution::Vecs, starting_indexes: &Indexes, exit: &Exit, diff --git a/crates/brk_computer/src/market/indicators/import.rs b/crates/brk_computer/src/market/indicators/import.rs index 62886f606..c2fba3cd9 100644 --- a/crates/brk_computer/src/market/indicators/import.rs +++ b/crates/brk_computer/src/market/indicators/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::{MacdChain, RsiChain, Vecs}; use crate::{ indexes, - internal::{ComputedFromHeight, ComputedFromHeightRatio, PercentFromHeight, Windows}, + internal::{ComputedPerBlock, RatioPerBlock, PercentPerBlock, Windows}, }; const VERSION: Version = Version::ONE; @@ -19,7 +19,7 @@ impl RsiChain { ) -> Result { macro_rules! import { ($name:expr) => { - ComputedFromHeight::forced_import( + ComputedPerBlock::forced_import( db, &format!("rsi_{}_{}", $name, tf), version, @@ -30,7 +30,7 @@ impl RsiChain { macro_rules! percent_import { ($name:expr) => { - PercentFromHeight::forced_import( + PercentPerBlock::forced_import( db, &format!("rsi_{}_{}", $name, tf), version, @@ -42,7 +42,7 @@ impl RsiChain { let average_gain = import!("average_gain"); let average_loss = import!("average_loss"); - let rsi = PercentFromHeight::forced_import(db, &format!("rsi_{tf}"), version, indexes)?; + let rsi = PercentPerBlock::forced_import(db, &format!("rsi_{tf}"), version, indexes)?; Ok(Self { gains: import!("gains"), @@ -67,11 +67,11 @@ impl MacdChain { indexes: &indexes::Vecs, ) -> Result { let line = - ComputedFromHeight::forced_import(db, &format!("macd_line_{tf}"), version, indexes)?; + ComputedPerBlock::forced_import(db, &format!("macd_line_{tf}"), version, indexes)?; let signal = - ComputedFromHeight::forced_import(db, &format!("macd_signal_{tf}"), version, indexes)?; + ComputedPerBlock::forced_import(db, &format!("macd_signal_{tf}"), version, indexes)?; - let histogram = ComputedFromHeight::forced_import( + let histogram = ComputedPerBlock::forced_import( db, &format!("macd_histogram_{tf}"), version, @@ -79,13 +79,13 @@ impl MacdChain { )?; Ok(Self { - ema_fast: ComputedFromHeight::forced_import( + ema_fast: ComputedPerBlock::forced_import( db, &format!("macd_ema_fast_{tf}"), version, indexes, )?, - ema_slow: ComputedFromHeight::forced_import( + ema_slow: ComputedPerBlock::forced_import( db, &format!("macd_ema_slow_{tf}"), version, @@ -106,19 +106,19 @@ impl Vecs { ) -> Result { let v = version + VERSION; - let nvt = ComputedFromHeightRatio::forced_import_raw(db, "nvt", v, indexes)?; + let nvt = RatioPerBlock::forced_import_raw(db, "nvt", v, indexes)?; let rsi = Windows::try_from_fn(|tf| RsiChain::forced_import(db, tf, v, indexes))?; let macd = Windows::try_from_fn(|tf| MacdChain::forced_import(db, tf, v, indexes))?; - let stoch_k = PercentFromHeight::forced_import(db, "stoch_k", v, indexes)?; - let stoch_d = PercentFromHeight::forced_import(db, "stoch_d", v, indexes)?; - let gini = PercentFromHeight::forced_import(db, "gini", v, indexes)?; + let stoch_k = PercentPerBlock::forced_import(db, "stoch_k", v, indexes)?; + let stoch_d = PercentPerBlock::forced_import(db, "stoch_d", v, indexes)?; + let gini = PercentPerBlock::forced_import(db, "gini", v, indexes)?; - let pi_cycle = ComputedFromHeightRatio::forced_import_raw(db, "pi_cycle", v, indexes)?; + let pi_cycle = RatioPerBlock::forced_import_raw(db, "pi_cycle", v, indexes)?; Ok(Self { - puell_multiple: ComputedFromHeightRatio::forced_import_raw( + puell_multiple: RatioPerBlock::forced_import_raw( db, "puell_multiple", v, diff --git a/crates/brk_computer/src/market/indicators/vecs.rs b/crates/brk_computer/src/market/indicators/vecs.rs index e56f44287..177026f64 100644 --- a/crates/brk_computer/src/market/indicators/vecs.rs +++ b/crates/brk_computer/src/market/indicators/vecs.rs @@ -2,44 +2,44 @@ use brk_traversable::Traversable; use brk_types::{BasisPoints16, StoredF32}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeight, ComputedFromHeightRatio, PercentFromHeight, Windows}; +use crate::internal::{ComputedPerBlock, RatioPerBlock, PercentPerBlock, Windows}; #[derive(Traversable)] pub struct RsiChain { - pub gains: ComputedFromHeight, - pub losses: ComputedFromHeight, - pub average_gain: ComputedFromHeight, - pub average_loss: ComputedFromHeight, - pub rsi: PercentFromHeight, - pub rsi_min: PercentFromHeight, - pub rsi_max: PercentFromHeight, - pub stoch_rsi: PercentFromHeight, - pub stoch_rsi_k: PercentFromHeight, - pub stoch_rsi_d: PercentFromHeight, + pub gains: ComputedPerBlock, + pub losses: ComputedPerBlock, + pub average_gain: ComputedPerBlock, + pub average_loss: ComputedPerBlock, + pub rsi: PercentPerBlock, + pub rsi_min: PercentPerBlock, + pub rsi_max: PercentPerBlock, + pub stoch_rsi: PercentPerBlock, + pub stoch_rsi_k: PercentPerBlock, + pub stoch_rsi_d: PercentPerBlock, } #[derive(Traversable)] pub struct MacdChain { - pub ema_fast: ComputedFromHeight, - pub ema_slow: ComputedFromHeight, - pub line: ComputedFromHeight, - pub signal: ComputedFromHeight, - pub histogram: ComputedFromHeight, + pub ema_fast: ComputedPerBlock, + pub ema_slow: ComputedPerBlock, + pub line: ComputedPerBlock, + pub signal: ComputedPerBlock, + pub histogram: ComputedPerBlock, } #[derive(Traversable)] pub struct Vecs { - pub puell_multiple: ComputedFromHeightRatio, - pub nvt: ComputedFromHeightRatio, + pub puell_multiple: RatioPerBlock, + pub nvt: RatioPerBlock, pub rsi: Windows>, - pub stoch_k: PercentFromHeight, - pub stoch_d: PercentFromHeight, + pub stoch_k: PercentPerBlock, + pub stoch_d: PercentPerBlock, - pub pi_cycle: ComputedFromHeightRatio, + pub pi_cycle: RatioPerBlock, pub macd: Windows>, - pub gini: PercentFromHeight, + pub gini: PercentPerBlock, } diff --git a/crates/brk_computer/src/market/lookback/vecs.rs b/crates/brk_computer/src/market/lookback/vecs.rs index b92d17138..3498cc921 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::{ComputedFromHeight, Price}; +use crate::internal::{ComputedPerBlock, Price}; #[derive(Traversable)] pub struct Vecs { #[traversable(flatten)] - pub price_lookback: ByLookbackPeriod>>, + pub price_lookback: ByLookbackPeriod>>, } diff --git a/crates/brk_computer/src/market/moving_average/import.rs b/crates/brk_computer/src/market/moving_average/import.rs index 3a3cdaf85..40e72b4c3 100644 --- a/crates/brk_computer/src/market/moving_average/import.rs +++ b/crates/brk_computer/src/market/moving_average/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{CentsTimesTenths, ComputedFromHeightPriceWithRatio, Price}, + internal::{CentsTimesTenths, PriceWithRatioPerBlock, Price}, }; impl Vecs { @@ -16,7 +16,7 @@ impl Vecs { ) -> Result { macro_rules! import { ($name:expr) => { - ComputedFromHeightPriceWithRatio::forced_import( + PriceWithRatioPerBlock::forced_import( db, $name, version, indexes, )? }; diff --git a/crates/brk_computer/src/market/moving_average/vecs.rs b/crates/brk_computer/src/market/moving_average/vecs.rs index 84ff5a465..b11ab043b 100644 --- a/crates/brk_computer/src/market/moving_average/vecs.rs +++ b/crates/brk_computer/src/market/moving_average/vecs.rs @@ -2,44 +2,44 @@ use brk_traversable::Traversable; use brk_types::Cents; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeightPriceWithRatio, LazyFromHeight, Price}; +use crate::internal::{PriceWithRatioPerBlock, LazyPerBlock, Price}; #[derive(Traversable)] pub struct Vecs { - pub price_sma_1w: ComputedFromHeightPriceWithRatio, - pub price_sma_8d: ComputedFromHeightPriceWithRatio, - pub price_sma_13d: ComputedFromHeightPriceWithRatio, - pub price_sma_21d: ComputedFromHeightPriceWithRatio, - pub price_sma_1m: ComputedFromHeightPriceWithRatio, - pub price_sma_34d: ComputedFromHeightPriceWithRatio, - pub price_sma_55d: ComputedFromHeightPriceWithRatio, - pub price_sma_89d: ComputedFromHeightPriceWithRatio, - pub price_sma_111d: ComputedFromHeightPriceWithRatio, - pub price_sma_144d: ComputedFromHeightPriceWithRatio, - pub price_sma_200d: ComputedFromHeightPriceWithRatio, - pub price_sma_350d: ComputedFromHeightPriceWithRatio, - pub price_sma_1y: ComputedFromHeightPriceWithRatio, - pub price_sma_2y: ComputedFromHeightPriceWithRatio, - pub price_sma_200w: ComputedFromHeightPriceWithRatio, - pub price_sma_4y: ComputedFromHeightPriceWithRatio, + pub price_sma_1w: PriceWithRatioPerBlock, + pub price_sma_8d: PriceWithRatioPerBlock, + pub price_sma_13d: PriceWithRatioPerBlock, + pub price_sma_21d: PriceWithRatioPerBlock, + pub price_sma_1m: PriceWithRatioPerBlock, + pub price_sma_34d: PriceWithRatioPerBlock, + pub price_sma_55d: PriceWithRatioPerBlock, + pub price_sma_89d: PriceWithRatioPerBlock, + pub price_sma_111d: PriceWithRatioPerBlock, + pub price_sma_144d: PriceWithRatioPerBlock, + pub price_sma_200d: PriceWithRatioPerBlock, + pub price_sma_350d: PriceWithRatioPerBlock, + pub price_sma_1y: PriceWithRatioPerBlock, + pub price_sma_2y: PriceWithRatioPerBlock, + pub price_sma_200w: PriceWithRatioPerBlock, + pub price_sma_4y: PriceWithRatioPerBlock, - pub price_ema_1w: ComputedFromHeightPriceWithRatio, - pub price_ema_8d: ComputedFromHeightPriceWithRatio, - pub price_ema_12d: ComputedFromHeightPriceWithRatio, - pub price_ema_13d: ComputedFromHeightPriceWithRatio, - pub price_ema_21d: ComputedFromHeightPriceWithRatio, - pub price_ema_26d: ComputedFromHeightPriceWithRatio, - pub price_ema_1m: ComputedFromHeightPriceWithRatio, - pub price_ema_34d: ComputedFromHeightPriceWithRatio, - pub price_ema_55d: ComputedFromHeightPriceWithRatio, - pub price_ema_89d: ComputedFromHeightPriceWithRatio, - pub price_ema_144d: ComputedFromHeightPriceWithRatio, - pub price_ema_200d: ComputedFromHeightPriceWithRatio, - pub price_ema_1y: ComputedFromHeightPriceWithRatio, - pub price_ema_2y: ComputedFromHeightPriceWithRatio, - pub price_ema_200w: ComputedFromHeightPriceWithRatio, - pub price_ema_4y: ComputedFromHeightPriceWithRatio, + pub price_ema_1w: PriceWithRatioPerBlock, + pub price_ema_8d: PriceWithRatioPerBlock, + pub price_ema_12d: PriceWithRatioPerBlock, + pub price_ema_13d: PriceWithRatioPerBlock, + pub price_ema_21d: PriceWithRatioPerBlock, + pub price_ema_26d: PriceWithRatioPerBlock, + pub price_ema_1m: PriceWithRatioPerBlock, + pub price_ema_34d: PriceWithRatioPerBlock, + pub price_ema_55d: PriceWithRatioPerBlock, + pub price_ema_89d: PriceWithRatioPerBlock, + pub price_ema_144d: PriceWithRatioPerBlock, + pub price_ema_200d: PriceWithRatioPerBlock, + pub price_ema_1y: PriceWithRatioPerBlock, + pub price_ema_2y: PriceWithRatioPerBlock, + pub price_ema_200w: PriceWithRatioPerBlock, + pub price_ema_4y: PriceWithRatioPerBlock, - pub price_sma_200d_x2_4: Price>, - pub price_sma_200d_x0_8: Price>, - pub price_sma_350d_x2: Price>, + pub price_sma_200d_x2_4: Price>, + pub price_sma_200d_x0_8: Price>, + pub price_sma_350d_x2: Price>, } diff --git a/crates/brk_computer/src/market/range/import.rs b/crates/brk_computer/src/market/range/import.rs index ab7e6e4aa..40d2a6794 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; use crate::{ indexes, - internal::{ComputedFromHeight, PercentFromHeight, Price}, + internal::{ComputedPerBlock, PercentPerBlock, Price}, }; impl Vecs { @@ -25,19 +25,19 @@ impl Vecs { price_max_1m: Price::forced_import(db, "price_max_1m", version + v1, indexes)?, price_min_1y: Price::forced_import(db, "price_min_1y", version + v1, indexes)?, price_max_1y: Price::forced_import(db, "price_max_1y", version + v1, indexes)?, - price_true_range: ComputedFromHeight::forced_import( + price_true_range: ComputedPerBlock::forced_import( db, "price_true_range", version + v1, indexes, )?, - price_true_range_sum_2w: ComputedFromHeight::forced_import( + price_true_range_sum_2w: ComputedPerBlock::forced_import( db, "price_true_range_sum_2w", version + v1, indexes, )?, - price_choppiness_index_2w: PercentFromHeight::forced_import( + price_choppiness_index_2w: PercentPerBlock::forced_import( db, "price_choppiness_index_2w", version + v1, diff --git a/crates/brk_computer/src/market/range/vecs.rs b/crates/brk_computer/src/market/range/vecs.rs index 1a847f7c3..1a02a7bfb 100644 --- a/crates/brk_computer/src/market/range/vecs.rs +++ b/crates/brk_computer/src/market/range/vecs.rs @@ -2,18 +2,18 @@ use brk_traversable::Traversable; use brk_types::{BasisPoints16, Cents, StoredF32}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeight, PercentFromHeight, Price}; +use crate::internal::{ComputedPerBlock, PercentPerBlock, Price}; #[derive(Traversable)] pub struct Vecs { - pub price_min_1w: Price>, - pub price_max_1w: Price>, - pub price_min_2w: Price>, - pub price_max_2w: Price>, - pub price_min_1m: Price>, - pub price_max_1m: Price>, - pub price_min_1y: Price>, - pub price_max_1y: Price>, - pub price_true_range: ComputedFromHeight, - pub price_true_range_sum_2w: ComputedFromHeight, - pub price_choppiness_index_2w: PercentFromHeight, + pub price_min_1w: Price>, + pub price_max_1w: Price>, + pub price_min_2w: Price>, + pub price_max_2w: Price>, + pub price_min_1m: Price>, + pub price_max_1m: Price>, + pub price_min_1y: Price>, + pub price_max_1y: Price>, + pub price_true_range: ComputedPerBlock, + pub price_true_range_sum_2w: ComputedPerBlock, + pub price_choppiness_index_2w: PercentPerBlock, } diff --git a/crates/brk_computer/src/market/returns/import.rs b/crates/brk_computer/src/market/returns/import.rs index 2d9747c5f..cecbe44d7 100644 --- a/crates/brk_computer/src/market/returns/import.rs +++ b/crates/brk_computer/src/market/returns/import.rs @@ -6,7 +6,7 @@ use super::super::lookback::ByLookbackPeriod; use super::Vecs; use crate::{ indexes, - internal::{ComputedFromHeightStdDev, PercentFromHeight}, + internal::{StdDevPerBlock, PercentPerBlock}, market::dca::ByDcaCagr, }; @@ -19,15 +19,15 @@ impl Vecs { let v1 = Version::ONE; let price_return = ByLookbackPeriod::try_new(|name, _days| { - PercentFromHeight::forced_import(db, &format!("price_return_{name}"), version, indexes) + PercentPerBlock::forced_import(db, &format!("price_return_{name}"), version, indexes) })?; // CAGR (computed, 2y+ only) let price_cagr = ByDcaCagr::try_new(|name, _days| { - PercentFromHeight::forced_import(db, &format!("price_cagr_{name}"), version, indexes) + PercentPerBlock::forced_import(db, &format!("price_cagr_{name}"), version, indexes) })?; - let price_return_24h_sd_1w = ComputedFromHeightStdDev::forced_import( + let price_return_24h_sd_1w = StdDevPerBlock::forced_import( db, "price_return_24h", "1w", @@ -35,7 +35,7 @@ impl Vecs { version + v1, indexes, )?; - let price_return_24h_sd_1m = ComputedFromHeightStdDev::forced_import( + let price_return_24h_sd_1m = StdDevPerBlock::forced_import( db, "price_return_24h", "1m", @@ -43,7 +43,7 @@ impl Vecs { version + v1, indexes, )?; - let price_return_24h_sd_1y = ComputedFromHeightStdDev::forced_import( + let price_return_24h_sd_1y = StdDevPerBlock::forced_import( db, "price_return_24h", "1y", diff --git a/crates/brk_computer/src/market/returns/vecs.rs b/crates/brk_computer/src/market/returns/vecs.rs index 843f8872c..0a7e69408 100644 --- a/crates/brk_computer/src/market/returns/vecs.rs +++ b/crates/brk_computer/src/market/returns/vecs.rs @@ -3,19 +3,19 @@ use brk_types::BasisPointsSigned32; use vecdb::{Rw, StorageMode}; use crate::{ - internal::{ComputedFromHeightStdDev, PercentFromHeight}, + internal::{StdDevPerBlock, PercentPerBlock}, market::{dca::ByDcaCagr, lookback::ByLookbackPeriod}, }; #[derive(Traversable)] pub struct Vecs { - pub price_return: ByLookbackPeriod>, + pub price_return: ByLookbackPeriod>, // CAGR (computed from returns, 2y+ only) - pub price_cagr: ByDcaCagr>, + pub price_cagr: ByDcaCagr>, // Returns standard deviation (computed from 24h returns) - pub price_return_24h_sd_1w: ComputedFromHeightStdDev, - pub price_return_24h_sd_1m: ComputedFromHeightStdDev, - pub price_return_24h_sd_1y: ComputedFromHeightStdDev, + pub price_return_24h_sd_1w: StdDevPerBlock, + pub price_return_24h_sd_1m: StdDevPerBlock, + pub price_return_24h_sd_1y: StdDevPerBlock, } diff --git a/crates/brk_computer/src/market/volatility/import.rs b/crates/brk_computer/src/market/volatility/import.rs index 6e7d83626..1bd764287 100644 --- a/crates/brk_computer/src/market/volatility/import.rs +++ b/crates/brk_computer/src/market/volatility/import.rs @@ -4,13 +4,13 @@ use vecdb::ReadableCloneableVec; use super::super::returns; use super::Vecs; -use crate::internal::{Days30, Days365, Days7, LazyFromHeight, TimesSqrt}; +use crate::internal::{Days30, Days365, Days7, LazyPerBlock, TimesSqrt}; impl Vecs { pub(crate) fn forced_import(version: Version, returns: &returns::Vecs) -> Result { let v2 = Version::TWO; - let price_volatility_1w = LazyFromHeight::from_computed::>( + let price_volatility_1w = LazyPerBlock::from_computed::>( "price_volatility_1w", version + v2, returns @@ -21,7 +21,7 @@ impl Vecs { &returns.price_return_24h_sd_1w.sd, ); - let price_volatility_1m = LazyFromHeight::from_computed::>( + let price_volatility_1m = LazyPerBlock::from_computed::>( "price_volatility_1m", version + v2, returns @@ -32,7 +32,7 @@ impl Vecs { &returns.price_return_24h_sd_1m.sd, ); - let price_volatility_1y = LazyFromHeight::from_computed::>( + let price_volatility_1y = LazyPerBlock::from_computed::>( "price_volatility_1y", version + v2, returns diff --git a/crates/brk_computer/src/market/volatility/vecs.rs b/crates/brk_computer/src/market/volatility/vecs.rs index e85473a8c..4d5716bca 100644 --- a/crates/brk_computer/src/market/volatility/vecs.rs +++ b/crates/brk_computer/src/market/volatility/vecs.rs @@ -1,11 +1,11 @@ use brk_traversable::Traversable; -use crate::internal::LazyFromHeight; +use crate::internal::LazyPerBlock; use brk_types::StoredF32; #[derive(Clone, Traversable)] pub struct Vecs { - pub price_volatility_1w: LazyFromHeight, - pub price_volatility_1m: LazyFromHeight, - pub price_volatility_1y: LazyFromHeight, + pub price_volatility_1w: LazyPerBlock, + pub price_volatility_1m: LazyPerBlock, + pub price_volatility_1y: LazyPerBlock, } diff --git a/crates/brk_computer/src/mining/hashrate/import.rs b/crates/brk_computer/src/mining/hashrate/import.rs index 8f4e1c8e7..a529f8b00 100644 --- a/crates/brk_computer/src/mining/hashrate/import.rs +++ b/crates/brk_computer/src/mining/hashrate/import.rs @@ -5,7 +5,7 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{ComputedFromHeight, PercentFromHeight}, + internal::{ComputedPerBlock, PercentPerBlock}, }; impl Vecs { @@ -18,98 +18,98 @@ impl Vecs { let v5 = Version::new(5); Ok(Self { - hash_rate: ComputedFromHeight::forced_import(db, "hash_rate", version + v5, indexes)?, - hash_rate_sma_1w: ComputedFromHeight::forced_import( + hash_rate: ComputedPerBlock::forced_import(db, "hash_rate", version + v5, indexes)?, + hash_rate_sma_1w: ComputedPerBlock::forced_import( db, "hash_rate_sma_1w", version, indexes, )?, - hash_rate_sma_1m: ComputedFromHeight::forced_import( + hash_rate_sma_1m: ComputedPerBlock::forced_import( db, "hash_rate_sma_1m", version, indexes, )?, - hash_rate_sma_2m: ComputedFromHeight::forced_import( + hash_rate_sma_2m: ComputedPerBlock::forced_import( db, "hash_rate_sma_2m", version, indexes, )?, - hash_rate_sma_1y: ComputedFromHeight::forced_import( + hash_rate_sma_1y: ComputedPerBlock::forced_import( db, "hash_rate_sma_1y", version, indexes, )?, - hash_rate_ath: ComputedFromHeight::forced_import( + hash_rate_ath: ComputedPerBlock::forced_import( db, "hash_rate_ath", version, indexes, )?, - hash_rate_drawdown: PercentFromHeight::forced_import( + hash_rate_drawdown: PercentPerBlock::forced_import( db, "hash_rate_drawdown", version, indexes, )?, - hash_price_ths: ComputedFromHeight::forced_import( + hash_price_ths: ComputedPerBlock::forced_import( db, "hash_price_ths", version + v4, indexes, )?, - hash_price_ths_min: ComputedFromHeight::forced_import( + hash_price_ths_min: ComputedPerBlock::forced_import( db, "hash_price_ths_min", version + v4, indexes, )?, - hash_price_phs: ComputedFromHeight::forced_import( + hash_price_phs: ComputedPerBlock::forced_import( db, "hash_price_phs", version + v4, indexes, )?, - hash_price_phs_min: ComputedFromHeight::forced_import( + hash_price_phs_min: ComputedPerBlock::forced_import( db, "hash_price_phs_min", version + v4, indexes, )?, - hash_price_rebound: PercentFromHeight::forced_import( + hash_price_rebound: PercentPerBlock::forced_import( db, "hash_price_rebound", version + v4, indexes, )?, - hash_value_ths: ComputedFromHeight::forced_import( + hash_value_ths: ComputedPerBlock::forced_import( db, "hash_value_ths", version + v4, indexes, )?, - hash_value_ths_min: ComputedFromHeight::forced_import( + hash_value_ths_min: ComputedPerBlock::forced_import( db, "hash_value_ths_min", version + v4, indexes, )?, - hash_value_phs: ComputedFromHeight::forced_import( + hash_value_phs: ComputedPerBlock::forced_import( db, "hash_value_phs", version + v4, indexes, )?, - hash_value_phs_min: ComputedFromHeight::forced_import( + hash_value_phs_min: ComputedPerBlock::forced_import( db, "hash_value_phs_min", version + v4, indexes, )?, - hash_value_rebound: PercentFromHeight::forced_import( + hash_value_rebound: PercentPerBlock::forced_import( db, "hash_value_rebound", version + v4, diff --git a/crates/brk_computer/src/mining/hashrate/vecs.rs b/crates/brk_computer/src/mining/hashrate/vecs.rs index 8f7b6afc4..445d00554 100644 --- a/crates/brk_computer/src/mining/hashrate/vecs.rs +++ b/crates/brk_computer/src/mining/hashrate/vecs.rs @@ -2,25 +2,25 @@ use brk_traversable::Traversable; use brk_types::{BasisPointsSigned16, BasisPointsSigned32, StoredF32, StoredF64}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeight, PercentFromHeight}; +use crate::internal::{ComputedPerBlock, PercentPerBlock}; #[derive(Traversable)] pub struct Vecs { - pub hash_rate: ComputedFromHeight, - pub hash_rate_sma_1w: ComputedFromHeight, - pub hash_rate_sma_1m: ComputedFromHeight, - pub hash_rate_sma_2m: ComputedFromHeight, - pub hash_rate_sma_1y: ComputedFromHeight, - pub hash_rate_ath: ComputedFromHeight, - pub hash_rate_drawdown: PercentFromHeight, - pub hash_price_ths: ComputedFromHeight, - pub hash_price_ths_min: ComputedFromHeight, - pub hash_price_phs: ComputedFromHeight, - pub hash_price_phs_min: ComputedFromHeight, - pub hash_price_rebound: PercentFromHeight, - pub hash_value_ths: ComputedFromHeight, - pub hash_value_ths_min: ComputedFromHeight, - pub hash_value_phs: ComputedFromHeight, - pub hash_value_phs_min: ComputedFromHeight, - pub hash_value_rebound: PercentFromHeight, + pub hash_rate: ComputedPerBlock, + pub hash_rate_sma_1w: ComputedPerBlock, + pub hash_rate_sma_1m: ComputedPerBlock, + pub hash_rate_sma_2m: ComputedPerBlock, + pub hash_rate_sma_1y: ComputedPerBlock, + pub hash_rate_ath: ComputedPerBlock, + pub hash_rate_drawdown: PercentPerBlock, + pub hash_price_ths: ComputedPerBlock, + pub hash_price_ths_min: ComputedPerBlock, + pub hash_price_phs: ComputedPerBlock, + pub hash_price_phs_min: ComputedPerBlock, + pub hash_price_rebound: PercentPerBlock, + pub hash_value_ths: ComputedPerBlock, + pub hash_value_ths_min: ComputedPerBlock, + pub hash_value_phs: ComputedPerBlock, + pub hash_value_phs_min: ComputedPerBlock, + pub hash_value_rebound: PercentPerBlock, } diff --git a/crates/brk_computer/src/mining/rewards/import.rs b/crates/brk_computer/src/mining/rewards/import.rs index e64bb059a..376cd52f7 100644 --- a/crates/brk_computer/src/mining/rewards/import.rs +++ b/crates/brk_computer/src/mining/rewards/import.rs @@ -6,8 +6,8 @@ use super::Vecs; use crate::{ indexes, internal::{ - AmountFromHeightCumulative, AmountFromHeightCumulativeSum, AmountFromHeightFull, - FiatFromHeight, PercentFromHeight, PercentRollingWindows, + AmountPerBlockCumulative, AmountPerBlockCumulativeSum, AmountPerBlockFull, + FiatPerBlock, PercentPerBlock, PercentRollingWindows, }, }; @@ -18,25 +18,25 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - coinbase: AmountFromHeightCumulativeSum::forced_import( + coinbase: AmountPerBlockCumulativeSum::forced_import( db, "coinbase", version, indexes, )?, - subsidy: AmountFromHeightCumulative::forced_import(db, "subsidy", version, indexes)?, - fees: AmountFromHeightFull::forced_import(db, "fees", version, indexes)?, - unclaimed_rewards: AmountFromHeightCumulativeSum::forced_import( + subsidy: AmountPerBlockCumulative::forced_import(db, "subsidy", version, indexes)?, + fees: AmountPerBlockFull::forced_import(db, "fees", version, indexes)?, + unclaimed_rewards: AmountPerBlockCumulativeSum::forced_import( db, "unclaimed_rewards", version, indexes, )?, - fee_dominance: PercentFromHeight::forced_import(db, "fee_dominance", version, indexes)?, + fee_dominance: PercentPerBlock::forced_import(db, "fee_dominance", version, indexes)?, fee_dominance_rolling: PercentRollingWindows::forced_import( db, "fee_dominance", version, indexes, )?, - subsidy_dominance: PercentFromHeight::forced_import( + subsidy_dominance: PercentPerBlock::forced_import( db, "subsidy_dominance", version, @@ -48,7 +48,7 @@ impl Vecs { version, indexes, )?, - subsidy_sma_1y: FiatFromHeight::forced_import(db, "subsidy_sma_1y", version, indexes)?, + subsidy_sma_1y: FiatPerBlock::forced_import(db, "subsidy_sma_1y", version, indexes)?, }) } } diff --git a/crates/brk_computer/src/mining/rewards/vecs.rs b/crates/brk_computer/src/mining/rewards/vecs.rs index 6f7870806..cd8d80f60 100644 --- a/crates/brk_computer/src/mining/rewards/vecs.rs +++ b/crates/brk_computer/src/mining/rewards/vecs.rs @@ -3,19 +3,19 @@ use brk_types::{BasisPoints16, Cents}; use vecdb::{Rw, StorageMode}; use crate::internal::{ - AmountFromHeightCumulative, AmountFromHeightCumulativeSum, AmountFromHeightFull, - FiatFromHeight, PercentFromHeight, PercentRollingWindows, + AmountPerBlockCumulative, AmountPerBlockCumulativeSum, AmountPerBlockFull, + FiatPerBlock, PercentPerBlock, PercentRollingWindows, }; #[derive(Traversable)] pub struct Vecs { - pub coinbase: AmountFromHeightCumulativeSum, - pub subsidy: AmountFromHeightCumulative, - pub fees: AmountFromHeightFull, - pub unclaimed_rewards: AmountFromHeightCumulativeSum, - pub fee_dominance: PercentFromHeight, + pub coinbase: AmountPerBlockCumulativeSum, + pub subsidy: AmountPerBlockCumulative, + pub fees: AmountPerBlockFull, + pub unclaimed_rewards: AmountPerBlockCumulativeSum, + pub fee_dominance: PercentPerBlock, pub fee_dominance_rolling: PercentRollingWindows, - pub subsidy_dominance: PercentFromHeight, + pub subsidy_dominance: PercentPerBlock, pub subsidy_dominance_rolling: PercentRollingWindows, - pub subsidy_sma_1y: FiatFromHeight, + pub subsidy_sma_1y: FiatPerBlock, } diff --git a/crates/brk_computer/src/outputs/count/import.rs b/crates/brk_computer/src/outputs/count/import.rs index 3452c0941..93ee409a3 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::{ComputedFromHeight, ComputedFromHeightAggregated}, + internal::{ComputedPerBlock, ComputedPerBlockAggregated}, }; impl Vecs { @@ -15,13 +15,13 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - total_count: ComputedFromHeightAggregated::forced_import( + total_count: ComputedPerBlockAggregated::forced_import( db, "output_count", version, indexes, )?, - utxo_count: ComputedFromHeight::forced_import( + utxo_count: ComputedPerBlock::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 e2bc72c62..71a013279 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::{ComputedFromHeight, ComputedFromHeightAggregated}; +use crate::internal::{ComputedPerBlock, ComputedPerBlockAggregated}; #[derive(Traversable)] pub struct Vecs { - pub total_count: ComputedFromHeightAggregated, - pub utxo_count: ComputedFromHeight, + pub total_count: ComputedPerBlockAggregated, + pub utxo_count: ComputedPerBlock, } diff --git a/crates/brk_computer/src/pools/major.rs b/crates/brk_computer/src/pools/major.rs index 0cce4fcc6..674a68b8a 100644 --- a/crates/brk_computer/src/pools/major.rs +++ b/crates/brk_computer/src/pools/major.rs @@ -7,7 +7,7 @@ use vecdb::{BinaryTransform, Database, Exit, ReadableVec, Rw, StorageMode, Versi use crate::{ blocks, indexes, internal::{ - AmountFromHeightCumulativeSum, MaskSats, PercentRollingWindows, RatioU32Bp16, + AmountPerBlockCumulativeSum, MaskSats, PercentRollingWindows, RatioU32Bp16, RollingWindows, }, mining, prices, @@ -25,7 +25,7 @@ pub struct Vecs { #[traversable(wrap = "blocks_mined", rename = "sum")] pub blocks_mined_sum: RollingWindows, - pub rewards: AmountFromHeightCumulativeSum, + pub rewards: AmountPerBlockCumulativeSum, pub dominance_rolling: PercentRollingWindows, } @@ -44,7 +44,7 @@ impl Vecs { RollingWindows::forced_import(db, &suffix("blocks_mined"), version, indexes)?; let rewards = - AmountFromHeightCumulativeSum::forced_import(db, &suffix("rewards"), version, indexes)?; + AmountPerBlockCumulativeSum::forced_import(db, &suffix("rewards"), version, indexes)?; let dominance_rolling = PercentRollingWindows::forced_import(db, &suffix("dominance"), version, indexes)?; diff --git a/crates/brk_computer/src/pools/minor.rs b/crates/brk_computer/src/pools/minor.rs index 5416adfa2..da07c8bc7 100644 --- a/crates/brk_computer/src/pools/minor.rs +++ b/crates/brk_computer/src/pools/minor.rs @@ -7,7 +7,7 @@ use vecdb::{ use crate::{ blocks, indexes, - internal::{ComputedFromHeightCumulative, PercentFromHeight, RatioU32Bp16}, + internal::{ComputedPerBlockCumulative, PercentPerBlock, RatioU32Bp16}, }; #[derive(Traversable)] @@ -15,8 +15,8 @@ pub struct Vecs { #[traversable(skip)] slug: PoolSlug, - pub blocks_mined: ComputedFromHeightCumulative, - pub dominance: PercentFromHeight, + pub blocks_mined: ComputedPerBlockCumulative, + pub dominance: PercentPerBlock, } impl Vecs { @@ -28,7 +28,7 @@ impl Vecs { ) -> Result { let suffix = |s: &str| format!("{}_{s}", slug); - let blocks_mined = ComputedFromHeightCumulative::forced_import( + let blocks_mined = ComputedPerBlockCumulative::forced_import( db, &suffix("blocks_mined"), version, @@ -36,7 +36,7 @@ impl Vecs { )?; let dominance = - PercentFromHeight::forced_import(db, &suffix("dominance"), version, indexes)?; + PercentPerBlock::forced_import(db, &suffix("dominance"), version, indexes)?; Ok(Self { slug, diff --git a/crates/brk_computer/src/prices/by_unit.rs b/crates/brk_computer/src/prices/by_unit.rs index d006ebc6b..8a3411283 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::{ - ComputedFromHeight, ComputedHeightDerived, EagerIndexes, LazyEagerIndexes, LazyFromHeight, + ComputedPerBlock, Resolutions, EagerIndexes, LazyEagerIndexes, LazyPerBlock, }; use super::ohlcs::{LazyOhlcVecs, OhlcVecs}; @@ -25,9 +25,9 @@ pub struct SplitIndexesByUnit { #[derive(Clone, Traversable)] pub struct SplitCloseByUnit { - pub cents: ComputedHeightDerived, - pub usd: ComputedHeightDerived, - pub sats: ComputedHeightDerived, + pub cents: Resolutions, + pub usd: Resolutions, + pub sats: Resolutions, } #[derive(Traversable)] @@ -39,7 +39,7 @@ pub struct OhlcByUnit { #[derive(Traversable)] pub struct PriceByUnit { - pub cents: ComputedFromHeight, - pub usd: LazyFromHeight, - pub sats: LazyFromHeight, + pub cents: ComputedPerBlock, + 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 daefb5c72..08fc8a357 100644 --- a/crates/brk_computer/src/prices/mod.rs +++ b/crates/brk_computer/src/prices/mod.rs @@ -11,8 +11,8 @@ use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode}; use crate::{ indexes, internal::{ - CentsUnsignedToDollars, CentsUnsignedToSats, ComputedFromHeight, ComputedHeightDerived, - EagerIndexes, LazyEagerIndexes, LazyFromHeight, OhlcCentsToDollars, OhlcCentsToSats, + CentsUnsignedToDollars, CentsUnsignedToSats, ComputedPerBlock, Resolutions, + EagerIndexes, LazyEagerIndexes, LazyPerBlock, OhlcCentsToDollars, OhlcCentsToSats, finalize_db, open_db, }, }; @@ -51,13 +51,13 @@ impl Vecs { ) -> brk_error::Result { let version = version + Version::new(11); - let price_cents = ComputedFromHeight::forced_import(db, "price_cents", version, indexes)?; + let price_cents = ComputedPerBlock::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)?; let low_cents = EagerIndexes::forced_import(db, "price_low_cents", version)?; - let close_cents = ComputedHeightDerived::forced_import( + let close_cents = Resolutions::forced_import( "price_close_cents", price_cents.height.read_only_boxed_clone(), version, @@ -66,7 +66,7 @@ impl Vecs { let ohlc_cents = OhlcVecs::forced_import(db, "price_ohlc_cents", version)?; - let price_usd = LazyFromHeight::from_computed::( + let price_usd = LazyPerBlock::from_computed::( "price", version, price_cents.height.read_only_boxed_clone(), @@ -89,7 +89,7 @@ impl Vecs { &low_cents, ); - let close_usd = ComputedHeightDerived::forced_import( + let close_usd = Resolutions::forced_import( "price_close", price_usd.height.read_only_boxed_clone(), version, @@ -102,7 +102,7 @@ impl Vecs { &ohlc_cents, ); - let price_sats = LazyFromHeight::from_computed::( + let price_sats = LazyPerBlock::from_computed::( "price_sats", version, price_cents.height.read_only_boxed_clone(), @@ -126,7 +126,7 @@ impl Vecs { &high_cents, ); - let close_sats = ComputedHeightDerived::forced_import( + let close_sats = Resolutions::forced_import( "price_close_sats", price_sats.height.read_only_boxed_clone(), version, diff --git a/crates/brk_computer/src/prices/ohlcs.rs b/crates/brk_computer/src/prices/ohlcs.rs index 2be84b8d1..bd75d33e6 100644 --- a/crates/brk_computer/src/prices/ohlcs.rs +++ b/crates/brk_computer/src/prices/ohlcs.rs @@ -15,14 +15,14 @@ use vecdb::{ use crate::{ indexes, - internal::{ComputedHeightDerived, EagerIndexes, PerPeriod}, + internal::{Resolutions, EagerIndexes, PerResolution}, }; #[derive(Deref, DerefMut, Traversable)] #[traversable(merge)] pub struct OhlcVecs( #[allow(clippy::type_complexity)] - pub PerPeriod< + pub PerResolution< ::Stored>>, ::Stored>>, ::Stored>>, @@ -58,7 +58,7 @@ where }; } - Ok(Self(PerPeriod { + Ok(Self(PerResolution { minute10: per_period!(), minute30: per_period!(), hour1: per_period!(), @@ -72,8 +72,8 @@ where month6: per_period!(), year1: per_period!(), year10: per_period!(), - halvingepoch: per_period!(), - difficultyepoch: per_period!(), + halving: per_period!(), + difficulty: per_period!(), })) } } @@ -87,7 +87,7 @@ impl OhlcVecs { open: &EagerIndexes, high: &EagerIndexes, low: &EagerIndexes, - close: &ComputedHeightDerived, + close: &Resolutions, exit: &Exit, ) -> Result<()> { let prev_height = starting_indexes.height.decremented().unwrap_or_default(); @@ -168,8 +168,8 @@ impl OhlcVecs { period!(month6); period!(year1); period!(year10); - epoch!(halvingepoch); - epoch!(difficultyepoch); + epoch!(halving); + epoch!(difficulty); Ok(()) } @@ -179,7 +179,7 @@ impl OhlcVecs { #[traversable(merge)] pub struct LazyOhlcVecs( #[allow(clippy::type_complexity)] - pub PerPeriod< + pub PerResolution< LazyVecFrom1, LazyVecFrom1, LazyVecFrom1, @@ -221,7 +221,7 @@ where }; } - Self(PerPeriod { + Self(PerResolution { minute10: period!(minute10), minute30: period!(minute30), hour1: period!(hour1), @@ -235,8 +235,8 @@ where month6: period!(month6), year1: period!(year1), year10: period!(year10), - halvingepoch: period!(halvingepoch), - difficultyepoch: period!(difficultyepoch), + halving: period!(halving), + difficulty: period!(difficulty), }) } } diff --git a/crates/brk_computer/src/scripts/adoption.rs b/crates/brk_computer/src/scripts/adoption.rs index d58f87f50..b4f966b36 100644 --- a/crates/brk_computer/src/scripts/adoption.rs +++ b/crates/brk_computer/src/scripts/adoption.rs @@ -5,7 +5,7 @@ use vecdb::{Database, Exit, Rw, StorageMode}; use crate::{ indexes, - internal::{PercentFromHeight, RatioU64Bp16}, + internal::{PercentPerBlock, RatioU64Bp16}, outputs, }; @@ -13,8 +13,8 @@ use super::count::Vecs as CountVecs; #[derive(Traversable)] pub struct Vecs { - pub taproot: PercentFromHeight, - pub segwit: PercentFromHeight, + pub taproot: PercentPerBlock, + pub segwit: PercentPerBlock, } impl Vecs { @@ -24,8 +24,8 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - taproot: PercentFromHeight::forced_import(db, "taproot_adoption", version, indexes)?, - segwit: PercentFromHeight::forced_import(db, "segwit_adoption", version, indexes)?, + taproot: PercentPerBlock::forced_import(db, "taproot_adoption", version, indexes)?, + segwit: PercentPerBlock::forced_import(db, "segwit_adoption", version, indexes)?, }) } diff --git a/crates/brk_computer/src/scripts/count/import.rs b/crates/brk_computer/src/scripts/count/import.rs index b5003ee1d..12514ada8 100644 --- a/crates/brk_computer/src/scripts/count/import.rs +++ b/crates/brk_computer/src/scripts/count/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::ComputedFromHeightCumulativeSum}; +use crate::{indexes, internal::ComputedPerBlockCumulativeSum}; impl Vecs { pub(crate) fn forced_import( @@ -12,25 +12,25 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { let p2a = - ComputedFromHeightCumulativeSum::forced_import(db, "p2a_count", version, indexes)?; + ComputedPerBlockCumulativeSum::forced_import(db, "p2a_count", version, indexes)?; let p2ms = - ComputedFromHeightCumulativeSum::forced_import(db, "p2ms_count", version, indexes)?; + ComputedPerBlockCumulativeSum::forced_import(db, "p2ms_count", version, indexes)?; let p2pk33 = - ComputedFromHeightCumulativeSum::forced_import(db, "p2pk33_count", version, indexes)?; + ComputedPerBlockCumulativeSum::forced_import(db, "p2pk33_count", version, indexes)?; let p2pk65 = - ComputedFromHeightCumulativeSum::forced_import(db, "p2pk65_count", version, indexes)?; + ComputedPerBlockCumulativeSum::forced_import(db, "p2pk65_count", version, indexes)?; let p2pkh = - ComputedFromHeightCumulativeSum::forced_import(db, "p2pkh_count", version, indexes)?; + ComputedPerBlockCumulativeSum::forced_import(db, "p2pkh_count", version, indexes)?; let p2sh = - ComputedFromHeightCumulativeSum::forced_import(db, "p2sh_count", version, indexes)?; + ComputedPerBlockCumulativeSum::forced_import(db, "p2sh_count", version, indexes)?; let p2tr = - ComputedFromHeightCumulativeSum::forced_import(db, "p2tr_count", version, indexes)?; + ComputedPerBlockCumulativeSum::forced_import(db, "p2tr_count", version, indexes)?; let p2wpkh = - ComputedFromHeightCumulativeSum::forced_import(db, "p2wpkh_count", version, indexes)?; + ComputedPerBlockCumulativeSum::forced_import(db, "p2wpkh_count", version, indexes)?; let p2wsh = - ComputedFromHeightCumulativeSum::forced_import(db, "p2wsh_count", version, indexes)?; + ComputedPerBlockCumulativeSum::forced_import(db, "p2wsh_count", version, indexes)?; let segwit = - ComputedFromHeightCumulativeSum::forced_import(db, "segwit_count", version, indexes)?; + ComputedPerBlockCumulativeSum::forced_import(db, "segwit_count", version, indexes)?; Ok(Self { p2a, @@ -42,19 +42,19 @@ impl Vecs { p2tr, p2wpkh, p2wsh, - opreturn: ComputedFromHeightCumulativeSum::forced_import( + opreturn: ComputedPerBlockCumulativeSum::forced_import( db, "opreturn_count", version, indexes, )?, - emptyoutput: ComputedFromHeightCumulativeSum::forced_import( + emptyoutput: ComputedPerBlockCumulativeSum::forced_import( db, "emptyoutput_count", version, indexes, )?, - unknownoutput: ComputedFromHeightCumulativeSum::forced_import( + unknownoutput: ComputedPerBlockCumulativeSum::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 15aaccec5..3d61e3d71 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::ComputedFromHeightCumulativeSum; +use crate::internal::ComputedPerBlockCumulativeSum; #[derive(Traversable)] pub struct Vecs { - pub p2a: ComputedFromHeightCumulativeSum, - pub p2ms: ComputedFromHeightCumulativeSum, - pub p2pk33: ComputedFromHeightCumulativeSum, - pub p2pk65: ComputedFromHeightCumulativeSum, - pub p2pkh: ComputedFromHeightCumulativeSum, - pub p2sh: ComputedFromHeightCumulativeSum, - pub p2tr: ComputedFromHeightCumulativeSum, - pub p2wpkh: ComputedFromHeightCumulativeSum, - pub p2wsh: ComputedFromHeightCumulativeSum, - pub opreturn: ComputedFromHeightCumulativeSum, - pub emptyoutput: ComputedFromHeightCumulativeSum, - pub unknownoutput: ComputedFromHeightCumulativeSum, + pub p2a: ComputedPerBlockCumulativeSum, + pub p2ms: ComputedPerBlockCumulativeSum, + pub p2pk33: ComputedPerBlockCumulativeSum, + pub p2pk65: ComputedPerBlockCumulativeSum, + pub p2pkh: ComputedPerBlockCumulativeSum, + pub p2sh: ComputedPerBlockCumulativeSum, + pub p2tr: ComputedPerBlockCumulativeSum, + pub p2wpkh: ComputedPerBlockCumulativeSum, + pub p2wsh: ComputedPerBlockCumulativeSum, + pub opreturn: ComputedPerBlockCumulativeSum, + pub emptyoutput: ComputedPerBlockCumulativeSum, + pub unknownoutput: ComputedPerBlockCumulativeSum, - pub segwit: ComputedFromHeightCumulativeSum, + pub segwit: ComputedPerBlockCumulativeSum, } diff --git a/crates/brk_computer/src/scripts/value/import.rs b/crates/brk_computer/src/scripts/value/import.rs index d7aa70865..927026f54 100644 --- a/crates/brk_computer/src/scripts/value/import.rs +++ b/crates/brk_computer/src/scripts/value/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::AmountFromHeightCumulative}; +use crate::{indexes, internal::AmountPerBlockCumulative}; impl Vecs { pub(crate) fn forced_import( @@ -12,7 +12,7 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - opreturn: AmountFromHeightCumulative::forced_import( + opreturn: AmountPerBlockCumulative::forced_import( db, "opreturn_value", version, diff --git a/crates/brk_computer/src/scripts/value/vecs.rs b/crates/brk_computer/src/scripts/value/vecs.rs index 3fed2eccd..6db747bcf 100644 --- a/crates/brk_computer/src/scripts/value/vecs.rs +++ b/crates/brk_computer/src/scripts/value/vecs.rs @@ -1,9 +1,9 @@ use brk_traversable::Traversable; use vecdb::{Rw, StorageMode}; -use crate::internal::AmountFromHeightCumulative; +use crate::internal::AmountPerBlockCumulative; #[derive(Traversable)] pub struct Vecs { - pub opreturn: AmountFromHeightCumulative, + pub opreturn: AmountPerBlockCumulative, } diff --git a/crates/brk_computer/src/supply/burned/import.rs b/crates/brk_computer/src/supply/burned/import.rs index e96a03669..47f67143a 100644 --- a/crates/brk_computer/src/supply/burned/import.rs +++ b/crates/brk_computer/src/supply/burned/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::AmountFromHeightCumulativeSum}; +use crate::{indexes, internal::AmountPerBlockCumulativeSum}; impl Vecs { pub(crate) fn forced_import( @@ -12,13 +12,13 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - opreturn: AmountFromHeightCumulativeSum::forced_import( + opreturn: AmountPerBlockCumulativeSum::forced_import( db, "opreturn_supply", version, indexes, )?, - unspendable: AmountFromHeightCumulativeSum::forced_import( + unspendable: AmountPerBlockCumulativeSum::forced_import( db, "unspendable_supply", version, diff --git a/crates/brk_computer/src/supply/burned/vecs.rs b/crates/brk_computer/src/supply/burned/vecs.rs index b055f639d..c0c8d1670 100644 --- a/crates/brk_computer/src/supply/burned/vecs.rs +++ b/crates/brk_computer/src/supply/burned/vecs.rs @@ -1,10 +1,10 @@ use brk_traversable::Traversable; use vecdb::{Rw, StorageMode}; -use crate::internal::AmountFromHeightCumulativeSum; +use crate::internal::AmountPerBlockCumulativeSum; #[derive(Traversable)] pub struct Vecs { - pub opreturn: AmountFromHeightCumulativeSum, - pub unspendable: AmountFromHeightCumulativeSum, + pub opreturn: AmountPerBlockCumulativeSum, + pub unspendable: AmountPerBlockCumulativeSum, } diff --git a/crates/brk_computer/src/supply/import.rs b/crates/brk_computer/src/supply/import.rs index 9c538a017..c7148f740 100644 --- a/crates/brk_computer/src/supply/import.rs +++ b/crates/brk_computer/src/supply/import.rs @@ -6,7 +6,7 @@ use brk_types::{Cents, Dollars, Sats, Version}; use crate::{ distribution, indexes, internal::{ - FiatRollingDelta, Identity, LazyFiatFromHeight, LazyAmountFromHeight, PercentFromHeight, + FiatRollingDelta, Identity, LazyFiatPerBlock, LazyAmountPerBlock, PercentPerBlock, RollingWindows, SatsToBitcoin, finalize_db, open_db, }, }; @@ -28,7 +28,7 @@ impl Vecs { let supply_metrics = &distribution.utxo_cohorts.all.metrics.supply; // Circulating supply - lazy refs to distribution - let circulating = LazyAmountFromHeight::from_block_source::< + let circulating = LazyAmountPerBlock::from_block_source::< Identity, SatsToBitcoin, Identity, @@ -40,14 +40,14 @@ impl Vecs { // Inflation rate let inflation_rate = - PercentFromHeight::forced_import(&db, "inflation_rate", version, indexes)?; + PercentPerBlock::forced_import(&db, "inflation_rate", version, indexes)?; // Velocity let velocity = super::velocity::Vecs::forced_import(&db, version, indexes)?; // Market cap - lazy fiat (cents + usd) from distribution supply let market_cap = - LazyFiatFromHeight::from_computed("market_cap", version, &supply_metrics.total.cents); + LazyFiatPerBlock::from_computed("market_cap", version, &supply_metrics.total.cents); // Market cap delta (change + rate across 4 windows) let market_cap_delta = FiatRollingDelta::forced_import( diff --git a/crates/brk_computer/src/supply/vecs.rs b/crates/brk_computer/src/supply/vecs.rs index a32ab25cb..e5d077046 100644 --- a/crates/brk_computer/src/supply/vecs.rs +++ b/crates/brk_computer/src/supply/vecs.rs @@ -4,7 +4,7 @@ use vecdb::{Database, Rw, StorageMode}; use super::{burned, velocity}; use crate::internal::{ - FiatRollingDelta, LazyFiatFromHeight, LazyAmountFromHeight, PercentFromHeight, RollingWindows, + FiatRollingDelta, LazyFiatPerBlock, LazyAmountPerBlock, PercentPerBlock, RollingWindows, }; #[derive(Traversable)] @@ -12,11 +12,11 @@ pub struct Vecs { #[traversable(skip)] pub(crate) db: Database, - pub circulating: LazyAmountFromHeight, + pub circulating: LazyAmountPerBlock, pub burned: burned::Vecs, - pub inflation_rate: PercentFromHeight, + pub inflation_rate: PercentPerBlock, pub velocity: velocity::Vecs, - pub market_cap: LazyFiatFromHeight, + pub market_cap: LazyFiatPerBlock, pub market_cap_delta: FiatRollingDelta, pub market_minus_realized_cap_growth_rate: RollingWindows, } diff --git a/crates/brk_computer/src/supply/velocity/import.rs b/crates/brk_computer/src/supply/velocity/import.rs index 5ccf0b6a1..4d6bbd14d 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::ComputedFromHeight}; +use crate::{indexes, internal::ComputedPerBlock}; impl Vecs { pub(crate) fn forced_import( @@ -12,8 +12,8 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - btc: ComputedFromHeight::forced_import(db, "velocity_btc", version, indexes)?, - usd: ComputedFromHeight::forced_import(db, "velocity_usd", version, indexes)?, + btc: ComputedPerBlock::forced_import(db, "velocity_btc", version, indexes)?, + usd: ComputedPerBlock::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 20412f8aa..70e59ef9d 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::ComputedFromHeight; +use crate::internal::ComputedPerBlock; #[derive(Traversable)] pub struct Vecs { - pub btc: ComputedFromHeight, - pub usd: ComputedFromHeight, + pub btc: ComputedPerBlock, + pub usd: ComputedPerBlock, } diff --git a/crates/brk_computer/src/transactions/count/import.rs b/crates/brk_computer/src/transactions/count/import.rs index cb8e81706..32b37ab1f 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::ComputedFromHeightFull}; +use crate::{indexes, internal::ComputedPerBlockFull}; impl Vecs { pub(crate) fn forced_import( @@ -26,7 +26,7 @@ impl Vecs { ); Ok(Self { - tx_count: ComputedFromHeightFull::forced_import(db, "tx_count", version, indexes)?, + tx_count: ComputedPerBlockFull::forced_import(db, "tx_count", version, indexes)?, is_coinbase: txindex_to_is_coinbase, }) } diff --git a/crates/brk_computer/src/transactions/count/vecs.rs b/crates/brk_computer/src/transactions/count/vecs.rs index d1291f7cc..38d87e831 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::ComputedFromHeightFull; +use crate::internal::ComputedPerBlockFull; #[derive(Traversable)] pub struct Vecs { - pub tx_count: ComputedFromHeightFull, + pub tx_count: ComputedPerBlockFull, 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 6ac5d50fc..b764f25fb 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::ComputedFromTxDistribution; +use crate::internal::ComputedPerTxDistribution; /// 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: ComputedFromTxDistribution::forced_import(db, "fee", v)?, - fee_rate: ComputedFromTxDistribution::forced_import(db, "fee_rate", v)?, + fee: ComputedPerTxDistribution::forced_import(db, "fee", v)?, + fee_rate: ComputedPerTxDistribution::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 126bb7033..7668adf08 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::ComputedFromTxDistribution; +use crate::internal::ComputedPerTxDistribution; #[derive(Traversable)] pub struct Vecs { pub input_value: M::Stored>>, pub output_value: M::Stored>>, - pub fee: ComputedFromTxDistribution, - pub fee_rate: ComputedFromTxDistribution, + pub fee: ComputedPerTxDistribution, + pub fee_rate: ComputedPerTxDistribution, } diff --git a/crates/brk_computer/src/transactions/size/import.rs b/crates/brk_computer/src/transactions/size/import.rs index 476780532..e3b3015ad 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::LazyFromTxDistribution; +use crate::internal::LazyPerTxDistribution; impl Vecs { pub(crate) fn forced_import( @@ -31,13 +31,13 @@ impl Vecs { ); Ok(Self { - vsize: LazyFromTxDistribution::forced_import( + vsize: LazyPerTxDistribution::forced_import( db, "tx_vsize", version, txindex_to_vsize, )?, - weight: LazyFromTxDistribution::forced_import( + weight: LazyPerTxDistribution::forced_import( db, "tx_weight", version, diff --git a/crates/brk_computer/src/transactions/size/vecs.rs b/crates/brk_computer/src/transactions/size/vecs.rs index c96049b51..a63782c66 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::LazyFromTxDistribution; +use crate::internal::LazyPerTxDistribution; #[derive(Traversable)] pub struct Vecs { - pub vsize: LazyFromTxDistribution, - pub weight: LazyFromTxDistribution, + pub vsize: LazyPerTxDistribution, + pub weight: LazyPerTxDistribution, } diff --git a/crates/brk_computer/src/transactions/versions/compute.rs b/crates/brk_computer/src/transactions/versions/compute.rs index 890608ff8..00475f91a 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::{blocks, internal::ComputedFromHeightCumulativeSum}; +use crate::{blocks, internal::ComputedPerBlockCumulativeSum}; impl Vecs { pub(crate) fn compute( @@ -16,7 +16,7 @@ impl Vecs { ) -> Result<()> { let window_starts = lookback.window_starts(); - let tx_vany = |tx_vany: &mut ComputedFromHeightCumulativeSum, + let tx_vany = |tx_vany: &mut ComputedPerBlockCumulativeSum, 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 d5b33cfd1..9b34023c3 100644 --- a/crates/brk_computer/src/transactions/versions/import.rs +++ b/crates/brk_computer/src/transactions/versions/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::ComputedFromHeightCumulativeSum}; +use crate::{indexes, internal::ComputedPerBlockCumulativeSum}; impl Vecs { pub(crate) fn forced_import( @@ -12,9 +12,9 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - v1: ComputedFromHeightCumulativeSum::forced_import(db, "tx_v1", version, indexes)?, - v2: ComputedFromHeightCumulativeSum::forced_import(db, "tx_v2", version, indexes)?, - v3: ComputedFromHeightCumulativeSum::forced_import(db, "tx_v3", version, indexes)?, + v1: ComputedPerBlockCumulativeSum::forced_import(db, "tx_v1", version, indexes)?, + v2: ComputedPerBlockCumulativeSum::forced_import(db, "tx_v2", version, indexes)?, + v3: ComputedPerBlockCumulativeSum::forced_import(db, "tx_v3", version, indexes)?, }) } } diff --git a/crates/brk_computer/src/transactions/versions/vecs.rs b/crates/brk_computer/src/transactions/versions/vecs.rs index e9a2448a5..58ea16bd6 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::ComputedFromHeightCumulativeSum; +use crate::internal::ComputedPerBlockCumulativeSum; #[derive(Traversable)] pub struct Vecs { - pub v1: ComputedFromHeightCumulativeSum, - pub v2: ComputedFromHeightCumulativeSum, - pub v3: ComputedFromHeightCumulativeSum, + pub v1: ComputedPerBlockCumulativeSum, + pub v2: ComputedPerBlockCumulativeSum, + pub v3: ComputedPerBlockCumulativeSum, } diff --git a/crates/brk_computer/src/transactions/volume/import.rs b/crates/brk_computer/src/transactions/volume/import.rs index f09f483b6..4095ed580 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::{AmountFromHeight, AmountFromHeightRolling, ComputedFromHeight}, + internal::{AmountPerBlock, AmountPerBlockRolling, ComputedPerBlock}, }; impl Vecs { @@ -16,27 +16,27 @@ impl Vecs { ) -> Result { let v2 = Version::TWO; Ok(Self { - sent_sum: AmountFromHeightRolling::forced_import(db, "sent_sum", version, indexes)?, - received_sum: AmountFromHeightRolling::forced_import( + sent_sum: AmountPerBlockRolling::forced_import(db, "sent_sum", version, indexes)?, + received_sum: AmountPerBlockRolling::forced_import( db, "received_sum", version, indexes, )?, - annualized_volume: AmountFromHeight::forced_import( + annualized_volume: AmountPerBlock::forced_import( db, "annualized_volume", version, indexes, )?, - tx_per_sec: ComputedFromHeight::forced_import(db, "tx_per_sec", version + v2, indexes)?, - outputs_per_sec: ComputedFromHeight::forced_import( + tx_per_sec: ComputedPerBlock::forced_import(db, "tx_per_sec", version + v2, indexes)?, + outputs_per_sec: ComputedPerBlock::forced_import( db, "outputs_per_sec", version + v2, indexes, )?, - inputs_per_sec: ComputedFromHeight::forced_import( + inputs_per_sec: ComputedPerBlock::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 582034b0b..f2c286f25 100644 --- a/crates/brk_computer/src/transactions/volume/vecs.rs +++ b/crates/brk_computer/src/transactions/volume/vecs.rs @@ -2,14 +2,14 @@ use brk_traversable::Traversable; use brk_types::StoredF32; use vecdb::{Rw, StorageMode}; -use crate::internal::{AmountFromHeight, AmountFromHeightRolling, ComputedFromHeight}; +use crate::internal::{AmountPerBlock, AmountPerBlockRolling, ComputedPerBlock}; #[derive(Traversable)] pub struct Vecs { - pub sent_sum: AmountFromHeightRolling, - pub received_sum: AmountFromHeightRolling, - pub annualized_volume: AmountFromHeight, - pub tx_per_sec: ComputedFromHeight, - pub outputs_per_sec: ComputedFromHeight, - pub inputs_per_sec: ComputedFromHeight, + pub sent_sum: AmountPerBlockRolling, + pub received_sum: AmountPerBlockRolling, + pub annualized_volume: AmountPerBlock, + pub tx_per_sec: ComputedPerBlock, + pub outputs_per_sec: ComputedPerBlock, + pub inputs_per_sec: ComputedPerBlock, } diff --git a/crates/brk_query/src/impl/mining/difficulty.rs b/crates/brk_query/src/impl/mining/difficulty.rs index 9b87b09a5..518c79711 100644 --- a/crates/brk_query/src/impl/mining/difficulty.rs +++ b/crates/brk_query/src/impl/mining/difficulty.rs @@ -23,7 +23,7 @@ impl Query { let current_epoch = computer .indexes .height - .difficultyepoch + .difficulty .collect_one(current_height) .unwrap(); let current_epoch_usize: usize = current_epoch.into(); @@ -31,7 +31,7 @@ impl Query { // Get epoch start height let epoch_start_height = computer .indexes - .difficultyepoch + .difficulty .first_height .collect_one(current_epoch) .unwrap(); @@ -43,12 +43,12 @@ impl Query { let remaining_blocks = next_retarget_height - current_height_u32; let progress_percent = (blocks_into_epoch as f64 / BLOCKS_PER_EPOCH as f64) * 100.0; - // Get timestamps using difficultyepoch_to_timestamp for epoch start + // Get timestamps using difficulty_to_timestamp for epoch start let epoch_start_timestamp = computer .blocks .time .timestamp - .difficultyepoch + .difficulty .collect_one(current_epoch) .unwrap(); let current_timestamp = indexer @@ -90,7 +90,7 @@ impl Query { let prev_epoch = DifficultyEpoch::from(current_epoch_usize - 1); let prev_epoch_start = computer .indexes - .difficultyepoch + .difficulty .first_height .collect_one(prev_epoch) .unwrap(); diff --git a/crates/brk_query/src/impl/mining/epochs.rs b/crates/brk_query/src/impl/mining/epochs.rs index 68e174161..cbded9414 100644 --- a/crates/brk_query/src/impl/mining/epochs.rs +++ b/crates/brk_query/src/impl/mining/epochs.rs @@ -11,19 +11,19 @@ pub fn iter_difficulty_epochs( let start_epoch = computer .indexes .height - .difficultyepoch + .difficulty .collect_one(Height::from(start_height)) .unwrap_or_default(); let end_epoch = computer .indexes .height - .difficultyepoch + .difficulty .collect_one(Height::from(end_height)) .unwrap_or_default(); - let epoch_to_height = &computer.indexes.difficultyepoch.first_height; - let epoch_to_timestamp = &computer.blocks.time.timestamp.difficultyepoch; - let epoch_to_difficulty = &computer.blocks.difficulty.raw.difficultyepoch; + let epoch_to_height = &computer.indexes.difficulty.first_height; + let epoch_to_timestamp = &computer.blocks.time.timestamp.difficulty; + let epoch_to_difficulty = &computer.blocks.difficulty.raw.difficulty; let mut results = Vec::with_capacity(end_epoch.to_usize() - start_epoch.to_usize() + 1); let mut prev_difficulty: Option = None;