diff --git a/crates/brk_client/src/lib.rs b/crates/brk_client/src/lib.rs index a064418b2..dea3fce40 100644 --- a/crates/brk_client/src/lib.rs +++ b/crates/brk_client/src/lib.rs @@ -2015,90 +2015,90 @@ impl RatioPattern3 { /// Pattern struct for repeated tree structure. pub struct GreedInvestedInvestorNegNetPainPeakSupplyTotalUnrealizedPattern { - pub greed_index: MetricPattern1, - pub invested_capital_in_loss: MetricPattern1, + pub greed_index: CentsUsdPattern, + pub invested_capital_in_loss: CentsUsdPattern, pub invested_capital_in_loss_raw: MetricPattern18, - pub invested_capital_in_profit: MetricPattern1, + pub invested_capital_in_profit: CentsUsdPattern, pub invested_capital_in_profit_raw: MetricPattern18, pub investor_cap_in_loss_raw: MetricPattern18, pub investor_cap_in_profit_raw: MetricPattern18, pub neg_unrealized_loss: MetricPattern1, - pub net_sentiment: MetricPattern1, - pub net_unrealized_pnl: MetricPattern1, - pub pain_index: MetricPattern1, - pub peak_regret: MetricPattern1, + pub net_sentiment: CentsUsdPattern, + pub net_unrealized_pnl: CentsUsdPattern, + pub pain_index: CentsUsdPattern, + pub peak_regret: CentsUsdPattern, pub supply_in_loss: BtcCentsSatsUsdPattern, pub supply_in_profit: BtcCentsSatsUsdPattern, - pub total_unrealized_pnl: MetricPattern1, - pub unrealized_loss: MetricPattern1, - pub unrealized_profit: MetricPattern1, + pub total_unrealized_pnl: CentsUsdPattern, + pub unrealized_loss: CentsUsdPattern, + pub unrealized_profit: CentsUsdPattern, } impl GreedInvestedInvestorNegNetPainPeakSupplyTotalUnrealizedPattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { - greed_index: MetricPattern1::new(client.clone(), _m(&acc, "greed_index")), - invested_capital_in_loss: MetricPattern1::new(client.clone(), _m(&acc, "invested_capital_in_loss")), + greed_index: CentsUsdPattern::new(client.clone(), _m(&acc, "greed_index")), + invested_capital_in_loss: CentsUsdPattern::new(client.clone(), _m(&acc, "invested_capital_in_loss")), invested_capital_in_loss_raw: MetricPattern18::new(client.clone(), _m(&acc, "invested_capital_in_loss_raw")), - invested_capital_in_profit: MetricPattern1::new(client.clone(), _m(&acc, "invested_capital_in_profit")), + invested_capital_in_profit: CentsUsdPattern::new(client.clone(), _m(&acc, "invested_capital_in_profit")), invested_capital_in_profit_raw: MetricPattern18::new(client.clone(), _m(&acc, "invested_capital_in_profit_raw")), investor_cap_in_loss_raw: MetricPattern18::new(client.clone(), _m(&acc, "investor_cap_in_loss_raw")), investor_cap_in_profit_raw: MetricPattern18::new(client.clone(), _m(&acc, "investor_cap_in_profit_raw")), neg_unrealized_loss: MetricPattern1::new(client.clone(), _m(&acc, "neg_unrealized_loss")), - net_sentiment: MetricPattern1::new(client.clone(), _m(&acc, "net_sentiment")), - net_unrealized_pnl: MetricPattern1::new(client.clone(), _m(&acc, "net_unrealized_pnl")), - pain_index: MetricPattern1::new(client.clone(), _m(&acc, "pain_index")), - peak_regret: MetricPattern1::new(client.clone(), _m(&acc, "unrealized_peak_regret")), + net_sentiment: CentsUsdPattern::new(client.clone(), _m(&acc, "net_sentiment")), + net_unrealized_pnl: CentsUsdPattern::new(client.clone(), _m(&acc, "net_unrealized_pnl")), + pain_index: CentsUsdPattern::new(client.clone(), _m(&acc, "pain_index")), + peak_regret: CentsUsdPattern::new(client.clone(), _m(&acc, "unrealized_peak_regret")), supply_in_loss: BtcCentsSatsUsdPattern::new(client.clone(), _m(&acc, "supply_in_loss")), supply_in_profit: BtcCentsSatsUsdPattern::new(client.clone(), _m(&acc, "supply_in_profit")), - total_unrealized_pnl: MetricPattern1::new(client.clone(), _m(&acc, "total_unrealized_pnl")), - unrealized_loss: MetricPattern1::new(client.clone(), _m(&acc, "unrealized_loss")), - unrealized_profit: MetricPattern1::new(client.clone(), _m(&acc, "unrealized_profit")), + total_unrealized_pnl: CentsUsdPattern::new(client.clone(), _m(&acc, "total_unrealized_pnl")), + unrealized_loss: CentsUsdPattern::new(client.clone(), _m(&acc, "unrealized_loss")), + unrealized_profit: CentsUsdPattern::new(client.clone(), _m(&acc, "unrealized_profit")), } } } /// Pattern struct for repeated tree structure. pub struct GreedInvestedInvestorNegNetPainSupplyTotalUnrealizedPattern { - pub greed_index: MetricPattern1, - pub invested_capital_in_loss: MetricPattern1, + pub greed_index: CentsUsdPattern, + pub invested_capital_in_loss: CentsUsdPattern, pub invested_capital_in_loss_raw: MetricPattern18, - pub invested_capital_in_profit: MetricPattern1, + pub invested_capital_in_profit: CentsUsdPattern, pub invested_capital_in_profit_raw: MetricPattern18, pub investor_cap_in_loss_raw: MetricPattern18, pub investor_cap_in_profit_raw: MetricPattern18, pub neg_unrealized_loss: MetricPattern1, - pub net_sentiment: MetricPattern1, - pub net_unrealized_pnl: MetricPattern1, - pub pain_index: MetricPattern1, + pub net_sentiment: CentsUsdPattern, + pub net_unrealized_pnl: CentsUsdPattern, + pub pain_index: CentsUsdPattern, pub supply_in_loss: BtcCentsSatsUsdPattern, pub supply_in_profit: BtcCentsSatsUsdPattern, - pub total_unrealized_pnl: MetricPattern1, - pub unrealized_loss: MetricPattern1, - pub unrealized_profit: MetricPattern1, + pub total_unrealized_pnl: CentsUsdPattern, + pub unrealized_loss: CentsUsdPattern, + pub unrealized_profit: CentsUsdPattern, } impl GreedInvestedInvestorNegNetPainSupplyTotalUnrealizedPattern { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { - greed_index: MetricPattern1::new(client.clone(), _m(&acc, "greed_index")), - invested_capital_in_loss: MetricPattern1::new(client.clone(), _m(&acc, "invested_capital_in_loss")), + greed_index: CentsUsdPattern::new(client.clone(), _m(&acc, "greed_index")), + invested_capital_in_loss: CentsUsdPattern::new(client.clone(), _m(&acc, "invested_capital_in_loss")), invested_capital_in_loss_raw: MetricPattern18::new(client.clone(), _m(&acc, "invested_capital_in_loss_raw")), - invested_capital_in_profit: MetricPattern1::new(client.clone(), _m(&acc, "invested_capital_in_profit")), + invested_capital_in_profit: CentsUsdPattern::new(client.clone(), _m(&acc, "invested_capital_in_profit")), invested_capital_in_profit_raw: MetricPattern18::new(client.clone(), _m(&acc, "invested_capital_in_profit_raw")), investor_cap_in_loss_raw: MetricPattern18::new(client.clone(), _m(&acc, "investor_cap_in_loss_raw")), investor_cap_in_profit_raw: MetricPattern18::new(client.clone(), _m(&acc, "investor_cap_in_profit_raw")), neg_unrealized_loss: MetricPattern1::new(client.clone(), _m(&acc, "neg_unrealized_loss")), - net_sentiment: MetricPattern1::new(client.clone(), _m(&acc, "net_sentiment")), - net_unrealized_pnl: MetricPattern1::new(client.clone(), _m(&acc, "net_unrealized_pnl")), - pain_index: MetricPattern1::new(client.clone(), _m(&acc, "pain_index")), + net_sentiment: CentsUsdPattern::new(client.clone(), _m(&acc, "net_sentiment")), + net_unrealized_pnl: CentsUsdPattern::new(client.clone(), _m(&acc, "net_unrealized_pnl")), + pain_index: CentsUsdPattern::new(client.clone(), _m(&acc, "pain_index")), supply_in_loss: BtcCentsSatsUsdPattern::new(client.clone(), _m(&acc, "supply_in_loss")), supply_in_profit: BtcCentsSatsUsdPattern::new(client.clone(), _m(&acc, "supply_in_profit")), - total_unrealized_pnl: MetricPattern1::new(client.clone(), _m(&acc, "total_unrealized_pnl")), - unrealized_loss: MetricPattern1::new(client.clone(), _m(&acc, "unrealized_loss")), - unrealized_profit: MetricPattern1::new(client.clone(), _m(&acc, "unrealized_profit")), + total_unrealized_pnl: CentsUsdPattern::new(client.clone(), _m(&acc, "total_unrealized_pnl")), + unrealized_loss: CentsUsdPattern::new(client.clone(), _m(&acc, "unrealized_loss")), + unrealized_profit: CentsUsdPattern::new(client.clone(), _m(&acc, "unrealized_profit")), } } } @@ -2922,7 +2922,7 @@ impl _1y24h30d7dPattern { /// Pattern struct for repeated tree structure. pub struct _30dHalvedTotalPattern { pub _30d_change: BtcCentsSatsUsdPattern, - pub halved: BtcSatsUsdPattern, + pub halved: BtcCentsSatsUsdPattern, pub total: BtcCentsSatsUsdPattern, } @@ -2931,7 +2931,7 @@ impl _30dHalvedTotalPattern { pub fn new(client: Arc, acc: String) -> Self { Self { _30d_change: BtcCentsSatsUsdPattern::new(client.clone(), _m(&acc, "_30d_change")), - halved: BtcSatsUsdPattern::new(client.clone(), _m(&acc, "supply_halved")), + halved: BtcCentsSatsUsdPattern::new(client.clone(), _m(&acc, "supply_halved")), total: BtcCentsSatsUsdPattern::new(client.clone(), _m(&acc, "supply")), } } @@ -2955,24 +2955,6 @@ impl BaseCumulativeSumPattern { } } -/// Pattern struct for repeated tree structure. -pub struct BtcSatsUsdPattern { - pub btc: MetricPattern1, - pub sats: MetricPattern1, - pub usd: MetricPattern1, -} - -impl BtcSatsUsdPattern { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - btc: MetricPattern1::new(client.clone(), _m(&acc, "btc")), - sats: MetricPattern1::new(client.clone(), acc.clone()), - usd: MetricPattern1::new(client.clone(), _m(&acc, "usd")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct CentsSatsUsdPattern2 { pub cents: MetricPattern2, @@ -3095,6 +3077,22 @@ impl BaseCumulativePattern { } } +/// Pattern struct for repeated tree structure. +pub struct CentsUsdPattern { + pub cents: MetricPattern1, + pub usd: MetricPattern1, +} + +impl CentsUsdPattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + cents: MetricPattern1::new(client.clone(), _m(&acc, "cents")), + usd: MetricPattern1::new(client.clone(), _m(&acc, "usd")), + } + } +} + /// Pattern struct for repeated tree structure. pub struct MaxMinPattern { pub max: CentsSatsUsdPattern, @@ -3846,7 +3844,7 @@ pub struct MetricsTree_Mining_Rewards { pub subsidy_dominance_7d: MetricPattern1, pub subsidy_dominance_30d: MetricPattern1, pub subsidy_dominance_1y: MetricPattern1, - pub subsidy_usd_1y_sma: MetricPattern1, + pub subsidy_usd_1y_sma: CentsUsdPattern, } impl MetricsTree_Mining_Rewards { @@ -3866,7 +3864,7 @@ impl MetricsTree_Mining_Rewards { subsidy_dominance_7d: MetricPattern1::new(client.clone(), "subsidy_dominance_7d".to_string()), subsidy_dominance_30d: MetricPattern1::new(client.clone(), "subsidy_dominance_30d".to_string()), subsidy_dominance_1y: MetricPattern1::new(client.clone(), "subsidy_dominance_1y".to_string()), - subsidy_usd_1y_sma: MetricPattern1::new(client.clone(), "subsidy_usd_1y_sma".to_string()), + subsidy_usd_1y_sma: CentsUsdPattern::new(client.clone(), "subsidy_usd_1y_sma".to_string()), } } } @@ -4013,21 +4011,21 @@ impl MetricsTree_Cointime_Value { /// Metrics tree node. pub struct MetricsTree_Cointime_Cap { - pub thermo_cap: MetricPattern1, - pub investor_cap: MetricPattern1, - pub vaulted_cap: MetricPattern1, - pub active_cap: MetricPattern1, - pub cointime_cap: MetricPattern1, + pub thermo_cap: CentsUsdPattern, + pub investor_cap: CentsUsdPattern, + pub vaulted_cap: CentsUsdPattern, + pub active_cap: CentsUsdPattern, + pub cointime_cap: CentsUsdPattern, } impl MetricsTree_Cointime_Cap { pub fn new(client: Arc, base_path: String) -> Self { Self { - thermo_cap: MetricPattern1::new(client.clone(), "thermo_cap".to_string()), - investor_cap: MetricPattern1::new(client.clone(), "investor_cap".to_string()), - vaulted_cap: MetricPattern1::new(client.clone(), "vaulted_cap".to_string()), - active_cap: MetricPattern1::new(client.clone(), "active_cap".to_string()), - cointime_cap: MetricPattern1::new(client.clone(), "cointime_cap".to_string()), + thermo_cap: CentsUsdPattern::new(client.clone(), "thermo_cap".to_string()), + investor_cap: CentsUsdPattern::new(client.clone(), "investor_cap".to_string()), + vaulted_cap: CentsUsdPattern::new(client.clone(), "vaulted_cap".to_string()), + active_cap: CentsUsdPattern::new(client.clone(), "active_cap".to_string()), + cointime_cap: CentsUsdPattern::new(client.clone(), "cointime_cap".to_string()), } } } @@ -6771,7 +6769,7 @@ impl MetricsTree_Distribution_GrowthRate { /// Metrics tree node. pub struct MetricsTree_Supply { - pub circulating: BtcSatsUsdPattern, + pub circulating: BtcCentsSatsUsdPattern, pub burned: MetricsTree_Supply_Burned, pub inflation: MetricPattern1, pub velocity: MetricsTree_Supply_Velocity, @@ -6784,7 +6782,7 @@ pub struct MetricsTree_Supply { impl MetricsTree_Supply { pub fn new(client: Arc, base_path: String) -> Self { Self { - circulating: BtcSatsUsdPattern::new(client.clone(), "circulating_supply".to_string()), + circulating: BtcCentsSatsUsdPattern::new(client.clone(), "circulating_supply".to_string()), burned: MetricsTree_Supply_Burned::new(client.clone(), format!("{base_path}_burned")), inflation: MetricPattern1::new(client.clone(), "inflation_rate".to_string()), velocity: MetricsTree_Supply_Velocity::new(client.clone(), format!("{base_path}_velocity")), diff --git a/crates/brk_computer/src/blocks/difficulty/import.rs b/crates/brk_computer/src/blocks/difficulty/import.rs index 71dad4baf..3adad5daa 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::{ComputedFromHeightLast, ComputedHeightDerivedLast}, + internal::{ComputedFromHeight, ComputedHeightDerived}, }; impl Vecs { @@ -19,22 +19,22 @@ impl Vecs { let v2 = Version::TWO; Ok(Self { - raw: ComputedHeightDerivedLast::forced_import( + raw: ComputedHeightDerived::forced_import( "difficulty", indexer.vecs.blocks.difficulty.read_only_boxed_clone(), version, indexes, ), - as_hash: ComputedFromHeightLast::forced_import(db, "difficulty_as_hash", version, indexes)?, - adjustment: ComputedFromHeightLast::forced_import(db, "difficulty_adjustment", version, indexes)?, - epoch: ComputedFromHeightLast::forced_import(db, "difficulty_epoch", version, indexes)?, - blocks_before_next_adjustment: ComputedFromHeightLast::forced_import( + as_hash: ComputedFromHeight::forced_import(db, "difficulty_as_hash", version, indexes)?, + adjustment: ComputedFromHeight::forced_import(db, "difficulty_adjustment", version, indexes)?, + epoch: ComputedFromHeight::forced_import(db, "difficulty_epoch", version, indexes)?, + blocks_before_next_adjustment: ComputedFromHeight::forced_import( db, "blocks_before_next_difficulty_adjustment", version + v2, indexes, )?, - days_before_next_adjustment: ComputedFromHeightLast::forced_import( + days_before_next_adjustment: ComputedFromHeight::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 c7a74b8c8..d96682bc3 100644 --- a/crates/brk_computer/src/blocks/difficulty/vecs.rs +++ b/crates/brk_computer/src/blocks/difficulty/vecs.rs @@ -2,15 +2,15 @@ use brk_traversable::Traversable; use brk_types::{DifficultyEpoch, StoredF32, StoredF64, StoredU32}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeightLast, ComputedHeightDerivedLast}; +use crate::internal::{ComputedFromHeight, ComputedHeightDerived}; /// Difficulty metrics: raw difficulty, derived stats, adjustment, and countdown #[derive(Traversable)] pub struct Vecs { - pub raw: ComputedHeightDerivedLast, - pub as_hash: ComputedFromHeightLast, - pub adjustment: ComputedFromHeightLast, - pub epoch: ComputedFromHeightLast, - pub blocks_before_next_adjustment: ComputedFromHeightLast, - pub days_before_next_adjustment: ComputedFromHeightLast, + pub raw: ComputedHeightDerived, + pub as_hash: ComputedFromHeight, + pub adjustment: ComputedFromHeight, + pub epoch: ComputedFromHeight, + pub blocks_before_next_adjustment: ComputedFromHeight, + pub days_before_next_adjustment: ComputedFromHeight, } diff --git a/crates/brk_computer/src/blocks/halving/import.rs b/crates/brk_computer/src/blocks/halving/import.rs index 33ad67f2e..1087051ec 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::ComputedFromHeightLast}; +use crate::{indexes, internal::ComputedFromHeight}; impl Vecs { pub(crate) fn forced_import( @@ -14,14 +14,14 @@ impl Vecs { let v2 = Version::TWO; Ok(Self { - epoch: ComputedFromHeightLast::forced_import(db, "halving_epoch", version, indexes)?, - blocks_before_next_halving: ComputedFromHeightLast::forced_import( + epoch: ComputedFromHeight::forced_import(db, "halving_epoch", version, indexes)?, + blocks_before_next_halving: ComputedFromHeight::forced_import( db, "blocks_before_next_halving", version + v2, indexes, )?, - days_before_next_halving: ComputedFromHeightLast::forced_import( + days_before_next_halving: ComputedFromHeight::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 e6e288be6..60e6dcdb4 100644 --- a/crates/brk_computer/src/blocks/halving/vecs.rs +++ b/crates/brk_computer/src/blocks/halving/vecs.rs @@ -2,12 +2,12 @@ use brk_traversable::Traversable; use brk_types::{HalvingEpoch, StoredF32, StoredU32}; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedFromHeightLast; +use crate::internal::ComputedFromHeight; /// Halving epoch metrics and countdown #[derive(Traversable)] pub struct Vecs { - pub epoch: ComputedFromHeightLast, - pub blocks_before_next_halving: ComputedFromHeightLast, - pub days_before_next_halving: ComputedFromHeightLast, + pub epoch: ComputedFromHeight, + pub blocks_before_next_halving: ComputedFromHeight, + pub days_before_next_halving: ComputedFromHeight, } diff --git a/crates/brk_computer/src/blocks/size/import.rs b/crates/brk_computer/src/blocks/size/import.rs index 86f79b145..4557fb0ff 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::{ComputedFromHeightCumulativeFull, ComputedHeightDerivedCumulativeFull}, + internal::{ComputedFromHeightFull, ComputedHeightDerivedFull}, }; impl Vecs { @@ -15,13 +15,13 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - vbytes: ComputedFromHeightCumulativeFull::forced_import( + vbytes: ComputedFromHeightFull::forced_import( db, "block_vbytes", version, indexes, )?, - size: ComputedHeightDerivedCumulativeFull::forced_import( + size: ComputedHeightDerivedFull::forced_import( db, "block_size", version, diff --git a/crates/brk_computer/src/blocks/size/vecs.rs b/crates/brk_computer/src/blocks/size/vecs.rs index 4de52b37d..d2ae9a51c 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::{ComputedFromHeightCumulativeFull, ComputedHeightDerivedCumulativeFull}; +use crate::internal::{ComputedFromHeightFull, ComputedHeightDerivedFull}; #[derive(Traversable)] pub struct Vecs { - pub vbytes: ComputedFromHeightCumulativeFull, - pub size: ComputedHeightDerivedCumulativeFull, + pub vbytes: ComputedFromHeightFull, + pub size: ComputedHeightDerivedFull, } diff --git a/crates/brk_computer/src/blocks/weight/import.rs b/crates/brk_computer/src/blocks/weight/import.rs index 1a1d9b0fc..b43cf2a54 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::{ComputedFromHeightDistribution, ComputedHeightDerivedCumulativeFull}, + internal::{ComputedFromHeightDistribution, ComputedHeightDerivedFull}, }; impl Vecs { @@ -14,7 +14,7 @@ impl Vecs { version: Version, indexes: &indexes::Vecs, ) -> Result { - let weight = ComputedHeightDerivedCumulativeFull::forced_import( + let weight = ComputedHeightDerivedFull::forced_import( db, "block_weight", version, diff --git a/crates/brk_computer/src/blocks/weight/vecs.rs b/crates/brk_computer/src/blocks/weight/vecs.rs index 7cf7ca942..08328c229 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::{StoredF32, Weight}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeightDistribution, ComputedHeightDerivedCumulativeFull}; +use crate::internal::{ComputedFromHeightDistribution, ComputedHeightDerivedFull}; #[derive(Traversable)] pub struct Vecs { - pub weight: ComputedHeightDerivedCumulativeFull, + pub weight: ComputedHeightDerivedFull, pub fullness: ComputedFromHeightDistribution, } diff --git a/crates/brk_computer/src/cointime/activity/import.rs b/crates/brk_computer/src/cointime/activity/import.rs index 3eca49bfe..cafb00fad 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::{ComputedFromHeightCumulativeSum, ComputedFromHeightLast}, + internal::{ComputedFromHeightCumulativeSum, ComputedFromHeight}, }; impl Vecs { @@ -23,9 +23,9 @@ impl Vecs { version, indexes, )?, - liveliness: ComputedFromHeightLast::forced_import(db, "liveliness", version, indexes)?, - vaultedness: ComputedFromHeightLast::forced_import(db, "vaultedness", version, indexes)?, - activity_to_vaultedness_ratio: ComputedFromHeightLast::forced_import( + liveliness: ComputedFromHeight::forced_import(db, "liveliness", version, indexes)?, + vaultedness: ComputedFromHeight::forced_import(db, "vaultedness", version, indexes)?, + activity_to_vaultedness_ratio: ComputedFromHeight::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 2282aed54..bd2dd4d24 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::{ComputedFromHeightCumulativeSum, ComputedFromHeightLast}; +use crate::internal::{ComputedFromHeightCumulativeSum, ComputedFromHeight}; #[derive(Traversable)] pub struct Vecs { pub coinblocks_created: ComputedFromHeightCumulativeSum, pub coinblocks_stored: ComputedFromHeightCumulativeSum, - pub liveliness: ComputedFromHeightLast, - pub vaultedness: ComputedFromHeightLast, - pub activity_to_vaultedness_ratio: ComputedFromHeightLast, + pub liveliness: ComputedFromHeight, + pub vaultedness: ComputedFromHeight, + pub activity_to_vaultedness_ratio: ComputedFromHeight, } diff --git a/crates/brk_computer/src/cointime/adjusted/import.rs b/crates/brk_computer/src/cointime/adjusted/import.rs index 3e1859069..6443eae49 100644 --- a/crates/brk_computer/src/cointime/adjusted/import.rs +++ b/crates/brk_computer/src/cointime/adjusted/import.rs @@ -3,24 +3,24 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::ComputedFromHeightLast}; +use crate::{indexes, internal::ComputedFromHeight}; impl Vecs { pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result { Ok(Self { - cointime_adj_inflation_rate: ComputedFromHeightLast::forced_import( + cointime_adj_inflation_rate: ComputedFromHeight::forced_import( db, "cointime_adj_inflation_rate", version, indexes, )?, - cointime_adj_tx_btc_velocity: ComputedFromHeightLast::forced_import( + cointime_adj_tx_btc_velocity: ComputedFromHeight::forced_import( db, "cointime_adj_tx_btc_velocity", version, indexes, )?, - cointime_adj_tx_usd_velocity: ComputedFromHeightLast::forced_import( + cointime_adj_tx_usd_velocity: ComputedFromHeight::forced_import( db, "cointime_adj_tx_usd_velocity", version, diff --git a/crates/brk_computer/src/cointime/adjusted/vecs.rs b/crates/brk_computer/src/cointime/adjusted/vecs.rs index 3be5ab394..1e61e898f 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::{StoredF32, StoredF64}; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedFromHeightLast; +use crate::internal::ComputedFromHeight; #[derive(Traversable)] pub struct Vecs { - pub cointime_adj_inflation_rate: ComputedFromHeightLast, - pub cointime_adj_tx_btc_velocity: ComputedFromHeightLast, - pub cointime_adj_tx_usd_velocity: ComputedFromHeightLast, + pub cointime_adj_inflation_rate: ComputedFromHeight, + pub cointime_adj_tx_btc_velocity: ComputedFromHeight, + pub cointime_adj_tx_usd_velocity: ComputedFromHeight, } diff --git a/crates/brk_computer/src/cointime/cap/import.rs b/crates/brk_computer/src/cointime/cap/import.rs index 348836ebb..f3fcc1275 100644 --- a/crates/brk_computer/src/cointime/cap/import.rs +++ b/crates/brk_computer/src/cointime/cap/import.rs @@ -3,16 +3,16 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::FiatFromHeightLast}; +use crate::{indexes, internal::FiatFromHeight}; impl Vecs { pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result { Ok(Self { - thermo_cap: FiatFromHeightLast::forced_import(db, "thermo_cap", version, indexes)?, - investor_cap: FiatFromHeightLast::forced_import(db, "investor_cap", version, indexes)?, - vaulted_cap: FiatFromHeightLast::forced_import(db, "vaulted_cap", version, indexes)?, - active_cap: FiatFromHeightLast::forced_import(db, "active_cap", version, indexes)?, - cointime_cap: FiatFromHeightLast::forced_import(db, "cointime_cap", version, indexes)?, + 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)?, }) } } diff --git a/crates/brk_computer/src/cointime/cap/vecs.rs b/crates/brk_computer/src/cointime/cap/vecs.rs index 5607cf419..fda6b31ab 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::FiatFromHeightLast; +use crate::internal::FiatFromHeight; #[derive(Traversable)] pub struct Vecs { - pub thermo_cap: FiatFromHeightLast, - pub investor_cap: FiatFromHeightLast, - pub vaulted_cap: FiatFromHeightLast, - pub active_cap: FiatFromHeightLast, - pub cointime_cap: FiatFromHeightLast, + pub thermo_cap: FiatFromHeight, + pub investor_cap: FiatFromHeight, + pub vaulted_cap: FiatFromHeight, + pub active_cap: FiatFromHeight, + pub cointime_cap: FiatFromHeight, } diff --git a/crates/brk_computer/src/cointime/pricing/vecs.rs b/crates/brk_computer/src/cointime/pricing/vecs.rs index a8853ebb1..c44aa0a5c 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::{ComputedFromHeightLast, ComputedFromHeightRatioExtended, Price}; +use crate::internal::{ComputedFromHeight, ComputedFromHeightRatioExtended, Price}; #[derive(Traversable)] pub struct Vecs { - pub vaulted_price: Price>, + pub vaulted_price: Price>, pub vaulted_price_ratio: ComputedFromHeightRatioExtended, - pub active_price: Price>, + pub active_price: Price>, pub active_price_ratio: ComputedFromHeightRatioExtended, - pub true_market_mean: Price>, + pub true_market_mean: Price>, pub true_market_mean_ratio: ComputedFromHeightRatioExtended, - pub cointime_price: Price>, + pub cointime_price: Price>, pub cointime_price_ratio: ComputedFromHeightRatioExtended, } diff --git a/crates/brk_computer/src/cointime/reserve_risk/import.rs b/crates/brk_computer/src/cointime/reserve_risk/import.rs index 5545f8df7..55dcc9161 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::ComputedFromHeightLast}; +use crate::{indexes, internal::ComputedFromHeight}; impl Vecs { pub(crate) fn forced_import( @@ -15,7 +15,7 @@ impl Vecs { Ok(Self { vocdd_365d_median: EagerVec::forced_import(db, "vocdd_365d_median", v1)?, hodl_bank: EagerVec::forced_import(db, "hodl_bank", v1)?, - reserve_risk: ComputedFromHeightLast::forced_import(db, "reserve_risk", v1, indexes)?, + reserve_risk: ComputedFromHeight::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 c47b1d372..520841739 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::ComputedFromHeightLast; +use crate::internal::ComputedFromHeight; #[derive(Traversable)] pub struct Vecs { pub vocdd_365d_median: M::Stored>>, pub hodl_bank: M::Stored>>, - pub reserve_risk: ComputedFromHeightLast, + pub reserve_risk: ComputedFromHeight, } diff --git a/crates/brk_computer/src/cointime/supply/import.rs b/crates/brk_computer/src/cointime/supply/import.rs index 66032e405..7b9e3900f 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::ValueFromHeightLast}; +use crate::{indexes, internal::ValueFromHeight}; impl Vecs { pub(crate) fn forced_import( @@ -12,13 +12,13 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - vaulted_supply: ValueFromHeightLast::forced_import( + vaulted_supply: ValueFromHeight::forced_import( db, "vaulted_supply", version, indexes, )?, - active_supply: ValueFromHeightLast::forced_import( + active_supply: ValueFromHeight::forced_import( db, "active_supply", version, diff --git a/crates/brk_computer/src/cointime/supply/vecs.rs b/crates/brk_computer/src/cointime/supply/vecs.rs index 55ed82df7..2e6d37b7d 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::ValueFromHeightLast; +use crate::internal::ValueFromHeight; #[derive(Traversable)] pub struct Vecs { - pub vaulted_supply: ValueFromHeightLast, - pub active_supply: ValueFromHeightLast, + pub vaulted_supply: ValueFromHeight, + pub active_supply: ValueFromHeight, } diff --git a/crates/brk_computer/src/distribution/address/address_count.rs b/crates/brk_computer/src/distribution/address/address_count.rs index cf7c9be8c..e7f05d7a8 100644 --- a/crates/brk_computer/src/distribution/address/address_count.rs +++ b/crates/brk_computer/src/distribution/address/address_count.rs @@ -9,14 +9,14 @@ use vecdb::{ WritableVec, }; -use crate::{ComputeIndexes, blocks, indexes, internal::ComputedFromHeightLast}; +use crate::{ComputeIndexes, blocks, indexes, internal::ComputedFromHeight}; /// Address count with 30d change metric for a single type. #[derive(Traversable)] pub struct AddrCountVecs { #[traversable(flatten)] - pub count: ComputedFromHeightLast, - pub _30d_change: ComputedFromHeightLast, + pub count: ComputedFromHeight, + pub _30d_change: ComputedFromHeight, } impl AddrCountVecs { @@ -27,8 +27,8 @@ impl AddrCountVecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - count: ComputedFromHeightLast::forced_import(db, name, version, indexes)?, - _30d_change: ComputedFromHeightLast::forced_import( + count: ComputedFromHeight::forced_import(db, name, version, indexes)?, + _30d_change: ComputedFromHeight::forced_import( db, &format!("{name}_30d_change"), version, 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 4e3f4e37c..86f44b224 100644 --- a/crates/brk_computer/src/distribution/address/new_addr_count.rs +++ b/crates/brk_computer/src/distribution/address/new_addr_count.rs @@ -6,16 +6,16 @@ use brk_traversable::Traversable; use brk_types::{Height, StoredU64, Version}; use vecdb::{Database, Exit, Rw, StorageMode}; -use crate::{indexes, internal::{ComputedFromHeightCumulativeFull, WindowStarts}}; +use crate::{indexes, internal::{ComputedFromHeightFull, WindowStarts}}; use super::TotalAddrCountVecs; /// New address count per block (global + per-type) #[derive(Traversable)] pub struct NewAddrCountVecs { - pub all: ComputedFromHeightCumulativeFull, + pub all: ComputedFromHeightFull, #[traversable(flatten)] - pub by_addresstype: ByAddressType>, + pub by_addresstype: ByAddressType>, } impl NewAddrCountVecs { @@ -24,16 +24,16 @@ impl NewAddrCountVecs { version: Version, indexes: &indexes::Vecs, ) -> Result { - let all = ComputedFromHeightCumulativeFull::forced_import( + let all = ComputedFromHeightFull::forced_import( db, "new_addr_count", version, indexes, )?; - let by_addresstype: ByAddressType> = + let by_addresstype: ByAddressType> = ByAddressType::new_with_name(|name| { - ComputedFromHeightCumulativeFull::forced_import( + ComputedFromHeightFull::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 4c984056b..9078cb3c2 100644 --- a/crates/brk_computer/src/distribution/address/total_addr_count.rs +++ b/crates/brk_computer/src/distribution/address/total_addr_count.rs @@ -6,16 +6,16 @@ use brk_traversable::Traversable; use brk_types::{Height, StoredU64, Version}; use vecdb::{Database, Exit, Rw, StorageMode}; -use crate::{indexes, internal::ComputedFromHeightLast}; +use crate::{indexes, internal::ComputedFromHeight}; use super::AddrCountsVecs; /// Total address count (global + per-type) with all derived indexes #[derive(Traversable)] pub struct TotalAddrCountVecs { - pub all: ComputedFromHeightLast, + pub all: ComputedFromHeight, #[traversable(flatten)] - pub by_addresstype: ByAddressType>, + pub by_addresstype: ByAddressType>, } impl TotalAddrCountVecs { @@ -24,16 +24,16 @@ impl TotalAddrCountVecs { version: Version, indexes: &indexes::Vecs, ) -> Result { - let all = ComputedFromHeightLast::forced_import( + let all = ComputedFromHeight::forced_import( db, "total_addr_count", version, indexes, )?; - let by_addresstype: ByAddressType> = ByAddressType::new_with_name( + let by_addresstype: ByAddressType> = ByAddressType::new_with_name( |name| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::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 56e2a2f58..54ebf880b 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::{ ComputeIndexes, blocks, distribution::state::AddressCohortState, indexes, - internal::ComputedFromHeightLast, + internal::ComputedFromHeight, prices, }; @@ -35,8 +35,8 @@ pub struct AddressCohortVecs { #[traversable(flatten)] pub metrics: BasicCohortMetrics, - pub addr_count: ComputedFromHeightLast, - pub addr_count_30d_change: ComputedFromHeightLast, + pub addr_count: ComputedFromHeight, + pub addr_count_30d_change: ComputedFromHeight, } impl AddressCohortVecs { @@ -67,13 +67,13 @@ impl AddressCohortVecs { metrics: BasicCohortMetrics::forced_import(&cfg)?, - addr_count: ComputedFromHeightLast::forced_import( + addr_count: ComputedFromHeight::forced_import( db, &cfg.name("addr_count"), version + VERSION, indexes, )?, - addr_count_30d_change: ComputedFromHeightLast::forced_import( + addr_count_30d_change: ComputedFromHeight::forced_import( db, &cfg.name("addr_count_30d_change"), version + VERSION, diff --git a/crates/brk_computer/src/distribution/metrics/activity.rs b/crates/brk_computer/src/distribution/metrics/activity.rs index 2719056c3..ec7116c0c 100644 --- a/crates/brk_computer/src/distribution/metrics/activity.rs +++ b/crates/brk_computer/src/distribution/metrics/activity.rs @@ -6,7 +6,7 @@ use vecdb::{AnyStoredVec, AnyVec, EagerVec, Exit, ImportableVec, PcoVec, Rw, Sto use crate::{ ComputeIndexes, blocks, - internal::{ComputedFromHeightCumulativeSum, ValueFromHeightCumulative, ValueFromHeightLast}, + internal::{ComputedFromHeightCumulativeSum, ValueFromHeightCumulative, ValueFromHeight}, }; use super::ImportConfig; @@ -18,7 +18,7 @@ pub struct ActivityMetrics { pub sent: ValueFromHeightCumulative, /// 14-day EMA of sent supply (sats, btc, usd) - pub sent_14d_ema: ValueFromHeightLast, + pub sent_14d_ema: ValueFromHeight, /// Satoshi-blocks destroyed (supply * blocks_old when spent) pub satblocks_destroyed: M::Stored>>, @@ -44,7 +44,7 @@ impl ActivityMetrics { cfg.indexes, )?, - sent_14d_ema: ValueFromHeightLast::forced_import( + sent_14d_ema: ValueFromHeight::forced_import( cfg.db, &cfg.name("sent_14d_ema"), cfg.version, diff --git a/crates/brk_computer/src/distribution/metrics/cost_basis/base.rs b/crates/brk_computer/src/distribution/metrics/cost_basis/base.rs index d71534b79..13a58a07d 100644 --- a/crates/brk_computer/src/distribution/metrics/cost_basis/base.rs +++ b/crates/brk_computer/src/distribution/metrics/cost_basis/base.rs @@ -6,7 +6,7 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec}; use crate::{ ComputeIndexes, distribution::state::CohortState, - internal::{ComputedFromHeightLast, Price}, + internal::{ComputedFromHeight, Price}, }; use crate::distribution::metrics::ImportConfig; @@ -15,10 +15,10 @@ use crate::distribution::metrics::ImportConfig; #[derive(Traversable)] pub struct CostBasisBase { /// Minimum cost basis for any UTXO at this height - pub min: Price>, + pub min: Price>, /// Maximum cost basis for any UTXO at this height - pub max: Price>, + pub max: Price>, } impl CostBasisBase { diff --git a/crates/brk_computer/src/distribution/metrics/cost_basis/extended.rs b/crates/brk_computer/src/distribution/metrics/cost_basis/extended.rs index e2471d2a8..6661712fa 100644 --- a/crates/brk_computer/src/distribution/metrics/cost_basis/extended.rs +++ b/crates/brk_computer/src/distribution/metrics/cost_basis/extended.rs @@ -6,7 +6,7 @@ use vecdb::{AnyStoredVec, Rw, StorageMode, WritableVec}; use crate::{ distribution::state::CohortState, internal::{ - ComputedFromHeightLast, PERCENTILES_LEN, PercentilesVecs, compute_spot_percentile_rank, + ComputedFromHeight, PERCENTILES_LEN, PercentilesVecs, compute_spot_percentile_rank, }, }; @@ -22,10 +22,10 @@ pub struct CostBasisExtended { pub invested_capital: PercentilesVecs, /// What percentile of cost basis is below spot (sat-weighted) - pub spot_cost_basis_percentile: ComputedFromHeightLast, + pub spot_cost_basis_percentile: ComputedFromHeight, /// What percentile of invested capital is below spot (USD-weighted) - pub spot_invested_capital_percentile: ComputedFromHeightLast, + pub spot_invested_capital_percentile: ComputedFromHeight, } impl CostBasisExtended { @@ -43,13 +43,13 @@ impl CostBasisExtended { cfg.version, cfg.indexes, )?, - spot_cost_basis_percentile: ComputedFromHeightLast::forced_import( + spot_cost_basis_percentile: ComputedFromHeight::forced_import( cfg.db, &cfg.name("spot_cost_basis_percentile"), cfg.version, cfg.indexes, )?, - spot_invested_capital_percentile: ComputedFromHeightLast::forced_import( + spot_invested_capital_percentile: ComputedFromHeight::forced_import( cfg.db, &cfg.name("spot_invested_capital_percentile"), cfg.version, diff --git a/crates/brk_computer/src/distribution/metrics/outputs.rs b/crates/brk_computer/src/distribution/metrics/outputs.rs index 57fda31d0..d8b8b76af 100644 --- a/crates/brk_computer/src/distribution/metrics/outputs.rs +++ b/crates/brk_computer/src/distribution/metrics/outputs.rs @@ -4,28 +4,28 @@ use brk_types::{Height, StoredF64, StoredU64}; use rayon::prelude::*; use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec}; -use crate::{ComputeIndexes, blocks, internal::ComputedFromHeightLast}; +use crate::{ComputeIndexes, blocks, internal::ComputedFromHeight}; use super::ImportConfig; /// Output metrics for a cohort. #[derive(Traversable)] pub struct OutputsMetrics { - pub utxo_count: ComputedFromHeightLast, - pub utxo_count_30d_change: ComputedFromHeightLast, + pub utxo_count: ComputedFromHeight, + pub utxo_count_30d_change: ComputedFromHeight, } impl OutputsMetrics { /// Import output metrics from database. pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { Ok(Self { - utxo_count: ComputedFromHeightLast::forced_import( + utxo_count: ComputedFromHeight::forced_import( cfg.db, &cfg.name("utxo_count"), cfg.version, cfg.indexes, )?, - utxo_count_30d_change: ComputedFromHeightLast::forced_import( + utxo_count_30d_change: ComputedFromHeight::forced_import( cfg.db, &cfg.name("utxo_count_30d_change"), cfg.version, diff --git a/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs b/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs index af439fe70..2f15fa292 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/adjusted.rs @@ -5,7 +5,7 @@ use vecdb::{Exit, Ident, ReadableCloneableVec, ReadableVec, Rw, StorageMode}; use crate::{ ComputeIndexes, blocks, - internal::{ComputedFromHeightLast, LazyFromHeightLast, RatioCents64}, + internal::{ComputedFromHeight, LazyFromHeight, RatioCents64}, }; use crate::distribution::metrics::ImportConfig; @@ -14,29 +14,29 @@ use crate::distribution::metrics::ImportConfig; #[derive(Traversable)] pub struct RealizedAdjusted { // === Adjusted Value (computed: cohort - up_to_1h) === - pub adjusted_value_created: ComputedFromHeightLast, - pub adjusted_value_destroyed: ComputedFromHeightLast, + pub adjusted_value_created: ComputedFromHeight, + pub adjusted_value_destroyed: ComputedFromHeight, // === Adjusted Value Created/Destroyed Rolling Sums === - pub adjusted_value_created_24h: ComputedFromHeightLast, - pub adjusted_value_created_7d: ComputedFromHeightLast, - pub adjusted_value_created_30d: ComputedFromHeightLast, - pub adjusted_value_created_1y: ComputedFromHeightLast, - pub adjusted_value_destroyed_24h: ComputedFromHeightLast, - pub adjusted_value_destroyed_7d: ComputedFromHeightLast, - pub adjusted_value_destroyed_30d: ComputedFromHeightLast, - pub adjusted_value_destroyed_1y: ComputedFromHeightLast, + pub adjusted_value_created_24h: ComputedFromHeight, + pub adjusted_value_created_7d: ComputedFromHeight, + pub adjusted_value_created_30d: ComputedFromHeight, + pub adjusted_value_created_1y: ComputedFromHeight, + pub adjusted_value_destroyed_24h: ComputedFromHeight, + pub adjusted_value_destroyed_7d: ComputedFromHeight, + pub adjusted_value_destroyed_30d: ComputedFromHeight, + pub adjusted_value_destroyed_1y: ComputedFromHeight, // === Adjusted SOPR (rolling window ratios) === - pub adjusted_sopr: LazyFromHeightLast, - pub adjusted_sopr_24h: ComputedFromHeightLast, - pub adjusted_sopr_7d: ComputedFromHeightLast, - pub adjusted_sopr_30d: ComputedFromHeightLast, - pub adjusted_sopr_1y: ComputedFromHeightLast, - pub adjusted_sopr_24h_7d_ema: ComputedFromHeightLast, - pub adjusted_sopr_7d_ema: LazyFromHeightLast, - pub adjusted_sopr_24h_30d_ema: ComputedFromHeightLast, - pub adjusted_sopr_30d_ema: LazyFromHeightLast, + pub adjusted_sopr: LazyFromHeight, + pub adjusted_sopr_24h: ComputedFromHeight, + pub adjusted_sopr_7d: ComputedFromHeight, + pub adjusted_sopr_30d: ComputedFromHeight, + pub adjusted_sopr_1y: ComputedFromHeight, + pub adjusted_sopr_24h_7d_ema: ComputedFromHeight, + pub adjusted_sopr_7d_ema: LazyFromHeight, + pub adjusted_sopr_24h_30d_ema: ComputedFromHeight, + pub adjusted_sopr_30d_ema: LazyFromHeight, } impl RealizedAdjusted { @@ -45,7 +45,7 @@ impl RealizedAdjusted { macro_rules! import_rolling { ($name:expr) => { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name($name), cfg.version + v1, @@ -54,13 +54,13 @@ impl RealizedAdjusted { }; } - let adjusted_value_created = ComputedFromHeightLast::forced_import( + let adjusted_value_created = ComputedFromHeight::forced_import( cfg.db, &cfg.name("adjusted_value_created"), cfg.version, cfg.indexes, )?; - let adjusted_value_destroyed = ComputedFromHeightLast::forced_import( + let adjusted_value_destroyed = ComputedFromHeight::forced_import( cfg.db, &cfg.name("adjusted_value_destroyed"), cfg.version, @@ -76,31 +76,31 @@ impl RealizedAdjusted { let adjusted_value_destroyed_30d = import_rolling!("adjusted_value_destroyed_30d"); let adjusted_value_destroyed_1y = import_rolling!("adjusted_value_destroyed_1y"); - let adjusted_sopr_24h = ComputedFromHeightLast::forced_import( + let adjusted_sopr_24h = ComputedFromHeight::forced_import( cfg.db, &cfg.name("adjusted_sopr_24h"), cfg.version + v1, cfg.indexes, )?; - let adjusted_sopr_7d = ComputedFromHeightLast::forced_import( + let adjusted_sopr_7d = ComputedFromHeight::forced_import( cfg.db, &cfg.name("adjusted_sopr_7d"), cfg.version + v1, cfg.indexes, )?; - let adjusted_sopr_30d = ComputedFromHeightLast::forced_import( + let adjusted_sopr_30d = ComputedFromHeight::forced_import( cfg.db, &cfg.name("adjusted_sopr_30d"), cfg.version + v1, cfg.indexes, )?; - let adjusted_sopr_1y = ComputedFromHeightLast::forced_import( + let adjusted_sopr_1y = ComputedFromHeight::forced_import( cfg.db, &cfg.name("adjusted_sopr_1y"), cfg.version + v1, cfg.indexes, )?; - let adjusted_sopr = LazyFromHeightLast::from_computed::( + let adjusted_sopr = LazyFromHeight::from_computed::( &cfg.name("adjusted_sopr"), cfg.version + v1, adjusted_sopr_24h.height.read_only_boxed_clone(), @@ -108,14 +108,14 @@ impl RealizedAdjusted { ); let adjusted_sopr_24h_7d_ema = import_rolling!("adjusted_sopr_24h_7d_ema"); - let adjusted_sopr_7d_ema = LazyFromHeightLast::from_computed::( + let adjusted_sopr_7d_ema = LazyFromHeight::from_computed::( &cfg.name("adjusted_sopr_7d_ema"), cfg.version + v1, adjusted_sopr_24h_7d_ema.height.read_only_boxed_clone(), &adjusted_sopr_24h_7d_ema, ); let adjusted_sopr_24h_30d_ema = import_rolling!("adjusted_sopr_24h_30d_ema"); - let adjusted_sopr_30d_ema = LazyFromHeightLast::from_computed::( + let adjusted_sopr_30d_ema = LazyFromHeight::from_computed::( &cfg.name("adjusted_sopr_30d_ema"), cfg.version + v1, adjusted_sopr_24h_30d_ema.height.read_only_boxed_clone(), diff --git a/crates/brk_computer/src/distribution/metrics/realized/base.rs b/crates/brk_computer/src/distribution/metrics/realized/base.rs index b55739169..709c45f9b 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/base.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/base.rs @@ -12,10 +12,10 @@ use crate::{ ComputeIndexes, blocks, distribution::state::RealizedState, internal::{ - CentsPlus, CentsUnsignedToDollars, ComputedFromHeightCumulative, ComputedFromHeightLast, - ComputedFromHeightRatio, NegCentsUnsignedToDollars, ValueFromHeightCumulative, LazyFromHeightLast, + CentsPlus, CentsUnsignedToDollars, ComputedFromHeightCumulative, ComputedFromHeight, + ComputedFromHeightRatio, NegCentsUnsignedToDollars, ValueFromHeightCumulative, LazyFromHeight, PercentageCentsF32, PercentageCentsSignedCentsF32, PercentageCentsSignedDollarsF32, Price, RatioCents64, - StoredF32Identity, ValueFromHeightLast, + StoredF32Identity, ValueFromHeight, }, prices, }; @@ -26,113 +26,113 @@ use crate::distribution::metrics::ImportConfig; #[derive(Traversable)] pub struct RealizedBase { // === Realized Cap === - pub realized_cap_cents: ComputedFromHeightLast, - pub realized_cap: LazyFromHeightLast, - pub realized_price: Price>, + pub realized_cap_cents: ComputedFromHeight, + pub realized_cap: LazyFromHeight, + pub realized_price: Price>, pub realized_price_extra: ComputedFromHeightRatio, - pub realized_cap_30d_delta: ComputedFromHeightLast, + pub realized_cap_30d_delta: ComputedFromHeight, // === Investor Price === - pub investor_price: Price>, + pub investor_price: Price>, pub investor_price_extra: ComputedFromHeightRatio, // === Floor/Ceiling Price Bands === - pub lower_price_band: Price>, - pub upper_price_band: Price>, + pub lower_price_band: Price>, + pub upper_price_band: Price>, // === Raw values for aggregation === pub cap_raw: M::Stored>, pub investor_cap_raw: M::Stored>, // === MVRV === - pub mvrv: LazyFromHeightLast, + pub mvrv: LazyFromHeight, // === Realized Profit/Loss === pub realized_profit: ComputedFromHeightCumulative, - pub realized_profit_7d_ema: ComputedFromHeightLast, + pub realized_profit_7d_ema: ComputedFromHeight, pub realized_loss: ComputedFromHeightCumulative, - pub realized_loss_7d_ema: ComputedFromHeightLast, - pub neg_realized_loss: LazyFromHeightLast, + pub realized_loss_7d_ema: ComputedFromHeight, + pub neg_realized_loss: LazyFromHeight, pub net_realized_pnl: ComputedFromHeightCumulative, - pub net_realized_pnl_7d_ema: ComputedFromHeightLast, - pub realized_value: ComputedFromHeightLast, + pub net_realized_pnl_7d_ema: ComputedFromHeight, + pub realized_value: ComputedFromHeight, // === Realized vs Realized Cap Ratios === - pub realized_profit_rel_to_realized_cap: ComputedFromHeightLast, - pub realized_loss_rel_to_realized_cap: ComputedFromHeightLast, - pub net_realized_pnl_rel_to_realized_cap: ComputedFromHeightLast, + pub realized_profit_rel_to_realized_cap: ComputedFromHeight, + pub realized_loss_rel_to_realized_cap: ComputedFromHeight, + pub net_realized_pnl_rel_to_realized_cap: ComputedFromHeight, // === Total Realized PnL === - pub total_realized_pnl: LazyFromHeightLast, + pub total_realized_pnl: LazyFromHeight, // === Value Created/Destroyed Splits (stored) === - pub profit_value_created: ComputedFromHeightLast, - pub profit_value_destroyed: ComputedFromHeightLast, - pub loss_value_created: ComputedFromHeightLast, - pub loss_value_destroyed: ComputedFromHeightLast, + pub profit_value_created: ComputedFromHeight, + pub profit_value_destroyed: ComputedFromHeight, + pub loss_value_created: ComputedFromHeight, + pub loss_value_destroyed: ComputedFromHeight, // === Value Created/Destroyed Totals === - pub value_created: ComputedFromHeightLast, - pub value_destroyed: ComputedFromHeightLast, + pub value_created: ComputedFromHeight, + pub value_destroyed: ComputedFromHeight, // === Capitulation/Profit Flow (lazy aliases) === - pub capitulation_flow: LazyFromHeightLast, - pub profit_flow: LazyFromHeightLast, + pub capitulation_flow: LazyFromHeight, + pub profit_flow: LazyFromHeight, // === Value Created/Destroyed Rolling Sums === - pub value_created_24h: ComputedFromHeightLast, - pub value_created_7d: ComputedFromHeightLast, - pub value_created_30d: ComputedFromHeightLast, - pub value_created_1y: ComputedFromHeightLast, - pub value_destroyed_24h: ComputedFromHeightLast, - pub value_destroyed_7d: ComputedFromHeightLast, - pub value_destroyed_30d: ComputedFromHeightLast, - pub value_destroyed_1y: ComputedFromHeightLast, + pub value_created_24h: ComputedFromHeight, + pub value_created_7d: ComputedFromHeight, + pub value_created_30d: ComputedFromHeight, + pub value_created_1y: ComputedFromHeight, + pub value_destroyed_24h: ComputedFromHeight, + pub value_destroyed_7d: ComputedFromHeight, + pub value_destroyed_30d: ComputedFromHeight, + pub value_destroyed_1y: ComputedFromHeight, // === SOPR (rolling window ratios) === - pub sopr: LazyFromHeightLast, - pub sopr_24h: ComputedFromHeightLast, - pub sopr_7d: ComputedFromHeightLast, - pub sopr_30d: ComputedFromHeightLast, - pub sopr_1y: ComputedFromHeightLast, - pub sopr_24h_7d_ema: ComputedFromHeightLast, - pub sopr_7d_ema: LazyFromHeightLast, - pub sopr_24h_30d_ema: ComputedFromHeightLast, - pub sopr_30d_ema: LazyFromHeightLast, + pub sopr: LazyFromHeight, + pub sopr_24h: ComputedFromHeight, + pub sopr_7d: ComputedFromHeight, + pub sopr_30d: ComputedFromHeight, + pub sopr_1y: ComputedFromHeight, + pub sopr_24h_7d_ema: ComputedFromHeight, + pub sopr_7d_ema: LazyFromHeight, + pub sopr_24h_30d_ema: ComputedFromHeight, + pub sopr_30d_ema: LazyFromHeight, // === Sell Side Risk Rolling Sum Intermediates === - pub realized_value_24h: ComputedFromHeightLast, - pub realized_value_7d: ComputedFromHeightLast, - pub realized_value_30d: ComputedFromHeightLast, - pub realized_value_1y: ComputedFromHeightLast, + pub realized_value_24h: ComputedFromHeight, + pub realized_value_7d: ComputedFromHeight, + pub realized_value_30d: ComputedFromHeight, + pub realized_value_1y: ComputedFromHeight, // === Sell Side Risk (rolling window ratios) === - pub sell_side_risk_ratio: LazyFromHeightLast, - pub sell_side_risk_ratio_24h: ComputedFromHeightLast, - pub sell_side_risk_ratio_7d: ComputedFromHeightLast, - pub sell_side_risk_ratio_30d: ComputedFromHeightLast, - pub sell_side_risk_ratio_1y: ComputedFromHeightLast, - pub sell_side_risk_ratio_24h_7d_ema: ComputedFromHeightLast, - pub sell_side_risk_ratio_7d_ema: LazyFromHeightLast, - pub sell_side_risk_ratio_24h_30d_ema: ComputedFromHeightLast, - pub sell_side_risk_ratio_30d_ema: LazyFromHeightLast, + pub sell_side_risk_ratio: LazyFromHeight, + pub sell_side_risk_ratio_24h: ComputedFromHeight, + pub sell_side_risk_ratio_7d: ComputedFromHeight, + pub sell_side_risk_ratio_30d: ComputedFromHeight, + pub sell_side_risk_ratio_1y: ComputedFromHeight, + pub sell_side_risk_ratio_24h_7d_ema: ComputedFromHeight, + pub sell_side_risk_ratio_7d_ema: LazyFromHeight, + pub sell_side_risk_ratio_24h_30d_ema: ComputedFromHeight, + pub sell_side_risk_ratio_30d_ema: LazyFromHeight, // === Net Realized PnL Deltas === - pub net_realized_pnl_cumulative_30d_delta: ComputedFromHeightLast, + pub net_realized_pnl_cumulative_30d_delta: ComputedFromHeight, pub net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap: - ComputedFromHeightLast, + ComputedFromHeight, pub net_realized_pnl_cumulative_30d_delta_rel_to_market_cap: - ComputedFromHeightLast, + ComputedFromHeight, // === Peak Regret === pub peak_regret: ComputedFromHeightCumulative, - pub peak_regret_rel_to_realized_cap: ComputedFromHeightLast, + pub peak_regret_rel_to_realized_cap: ComputedFromHeight, // === Sent in Profit/Loss === pub sent_in_profit: ValueFromHeightCumulative, - pub sent_in_profit_14d_ema: ValueFromHeightLast, + pub sent_in_profit_14d_ema: ValueFromHeight, pub sent_in_loss: ValueFromHeightCumulative, - pub sent_in_loss_14d_ema: ValueFromHeightLast, + pub sent_in_loss_14d_ema: ValueFromHeight, } impl RealizedBase { @@ -142,14 +142,14 @@ impl RealizedBase { let v2 = Version::new(2); let v3 = Version::new(3); // Import combined types using forced_import which handles height + derived - let realized_cap_cents = ComputedFromHeightLast::forced_import( + let realized_cap_cents = ComputedFromHeight::forced_import( cfg.db, &cfg.name("realized_cap_cents"), cfg.version, cfg.indexes, )?; - let realized_cap = LazyFromHeightLast::from_computed::( + let realized_cap = LazyFromHeight::from_computed::( &cfg.name("realized_cap"), cfg.version, realized_cap_cents.height.read_only_boxed_clone(), @@ -163,7 +163,7 @@ impl RealizedBase { cfg.indexes, )?; - let realized_profit_7d_ema = ComputedFromHeightLast::forced_import( + let realized_profit_7d_ema = ComputedFromHeight::forced_import( cfg.db, &cfg.name("realized_profit_7d_ema"), cfg.version, @@ -177,14 +177,14 @@ impl RealizedBase { cfg.indexes, )?; - let realized_loss_7d_ema = ComputedFromHeightLast::forced_import( + let realized_loss_7d_ema = ComputedFromHeight::forced_import( cfg.db, &cfg.name("realized_loss_7d_ema"), cfg.version, cfg.indexes, )?; - let neg_realized_loss = LazyFromHeightLast::from_height_source::( + let neg_realized_loss = LazyFromHeight::from_height_source::( &cfg.name("neg_realized_loss"), cfg.version + v1, realized_loss.height.read_only_boxed_clone(), @@ -198,7 +198,7 @@ impl RealizedBase { cfg.indexes, )?; - let net_realized_pnl_7d_ema = ComputedFromHeightLast::forced_import( + let net_realized_pnl_7d_ema = ComputedFromHeight::forced_import( cfg.db, &cfg.name("net_realized_pnl_7d_ema"), cfg.version, @@ -212,35 +212,35 @@ impl RealizedBase { cfg.indexes, )?; - let realized_value = ComputedFromHeightLast::forced_import( + let realized_value = ComputedFromHeight::forced_import( cfg.db, &cfg.name("realized_value"), cfg.version, cfg.indexes, )?; - let total_realized_pnl = LazyFromHeightLast::from_computed::( + let total_realized_pnl = LazyFromHeight::from_computed::( &cfg.name("total_realized_pnl"), cfg.version + v1, realized_value.height.read_only_boxed_clone(), &realized_value, ); - let realized_profit_rel_to_realized_cap = ComputedFromHeightLast::forced_import( + let realized_profit_rel_to_realized_cap = ComputedFromHeight::forced_import( cfg.db, &cfg.name("realized_profit_rel_to_realized_cap"), cfg.version + v1, cfg.indexes, )?; - let realized_loss_rel_to_realized_cap = ComputedFromHeightLast::forced_import( + let realized_loss_rel_to_realized_cap = ComputedFromHeight::forced_import( cfg.db, &cfg.name("realized_loss_rel_to_realized_cap"), cfg.version + v1, cfg.indexes, )?; - let net_realized_pnl_rel_to_realized_cap = ComputedFromHeightLast::forced_import( + let net_realized_pnl_rel_to_realized_cap = ComputedFromHeight::forced_import( cfg.db, &cfg.name("net_realized_pnl_rel_to_realized_cap"), cfg.version + v1, @@ -286,51 +286,51 @@ impl RealizedBase { let investor_cap_raw = BytesVec::forced_import(cfg.db, &cfg.name("investor_cap_raw"), cfg.version)?; - let profit_value_created = ComputedFromHeightLast::forced_import( + let profit_value_created = ComputedFromHeight::forced_import( cfg.db, &cfg.name("profit_value_created"), cfg.version, cfg.indexes, )?; - let profit_value_destroyed = ComputedFromHeightLast::forced_import( + let profit_value_destroyed = ComputedFromHeight::forced_import( cfg.db, &cfg.name("profit_value_destroyed"), cfg.version, cfg.indexes, )?; - let loss_value_created = ComputedFromHeightLast::forced_import( + let loss_value_created = ComputedFromHeight::forced_import( cfg.db, &cfg.name("loss_value_created"), cfg.version, cfg.indexes, )?; - let loss_value_destroyed = ComputedFromHeightLast::forced_import( + let loss_value_destroyed = ComputedFromHeight::forced_import( cfg.db, &cfg.name("loss_value_destroyed"), cfg.version, cfg.indexes, )?; - let value_created = ComputedFromHeightLast::forced_import( + let value_created = ComputedFromHeight::forced_import( cfg.db, &cfg.name("value_created"), cfg.version, cfg.indexes, )?; - let value_destroyed = ComputedFromHeightLast::forced_import( + let value_destroyed = ComputedFromHeight::forced_import( cfg.db, &cfg.name("value_destroyed"), cfg.version, cfg.indexes, )?; - let capitulation_flow = LazyFromHeightLast::from_computed::( + let capitulation_flow = LazyFromHeight::from_computed::( &cfg.name("capitulation_flow"), cfg.version, loss_value_destroyed.height.read_only_boxed_clone(), &loss_value_destroyed, ); - let profit_flow = LazyFromHeightLast::from_computed::( + let profit_flow = LazyFromHeight::from_computed::( &cfg.name("profit_flow"), cfg.version, profit_value_destroyed.height.read_only_boxed_clone(), @@ -344,7 +344,7 @@ impl RealizedBase { cfg.indexes, )?; - let mvrv = LazyFromHeightLast::from_computed::( + let mvrv = LazyFromHeight::from_computed::( &cfg.name("mvrv"), cfg.version, realized_price_extra.ratio.height.read_only_boxed_clone(), @@ -354,7 +354,7 @@ impl RealizedBase { // === Rolling sum intermediates === macro_rules! import_rolling { ($name:expr) => { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name($name), cfg.version + v1, @@ -382,7 +382,7 @@ impl RealizedBase { let sopr_7d = import_rolling!("sopr_7d"); let sopr_30d = import_rolling!("sopr_30d"); let sopr_1y = import_rolling!("sopr_1y"); - let sopr = LazyFromHeightLast::from_computed::( + let sopr = LazyFromHeight::from_computed::( &cfg.name("sopr"), cfg.version + v1, sopr_24h.height.read_only_boxed_clone(), @@ -393,7 +393,7 @@ impl RealizedBase { let sell_side_risk_ratio_7d = import_rolling!("sell_side_risk_ratio_7d"); let sell_side_risk_ratio_30d = import_rolling!("sell_side_risk_ratio_30d"); let sell_side_risk_ratio_1y = import_rolling!("sell_side_risk_ratio_1y"); - let sell_side_risk_ratio = LazyFromHeightLast::from_computed::( + let sell_side_risk_ratio = LazyFromHeight::from_computed::( &cfg.name("sell_side_risk_ratio"), cfg.version + v1, sell_side_risk_ratio_24h.height.read_only_boxed_clone(), @@ -402,14 +402,14 @@ impl RealizedBase { // === EMA imports + identity aliases === let sopr_24h_7d_ema = import_rolling!("sopr_24h_7d_ema"); - let sopr_7d_ema = LazyFromHeightLast::from_computed::( + let sopr_7d_ema = LazyFromHeight::from_computed::( &cfg.name("sopr_7d_ema"), cfg.version + v1, sopr_24h_7d_ema.height.read_only_boxed_clone(), &sopr_24h_7d_ema, ); let sopr_24h_30d_ema = import_rolling!("sopr_24h_30d_ema"); - let sopr_30d_ema = LazyFromHeightLast::from_computed::( + let sopr_30d_ema = LazyFromHeight::from_computed::( &cfg.name("sopr_30d_ema"), cfg.version + v1, sopr_24h_30d_ema.height.read_only_boxed_clone(), @@ -417,7 +417,7 @@ impl RealizedBase { ); let sell_side_risk_ratio_24h_7d_ema = import_rolling!("sell_side_risk_ratio_24h_7d_ema"); - let sell_side_risk_ratio_7d_ema = LazyFromHeightLast::from_computed::( + let sell_side_risk_ratio_7d_ema = LazyFromHeight::from_computed::( &cfg.name("sell_side_risk_ratio_7d_ema"), cfg.version + v1, sell_side_risk_ratio_24h_7d_ema @@ -426,7 +426,7 @@ impl RealizedBase { &sell_side_risk_ratio_24h_7d_ema, ); let sell_side_risk_ratio_24h_30d_ema = import_rolling!("sell_side_risk_ratio_24h_30d_ema"); - let sell_side_risk_ratio_30d_ema = LazyFromHeightLast::from_computed::( + let sell_side_risk_ratio_30d_ema = LazyFromHeight::from_computed::( &cfg.name("sell_side_risk_ratio_30d_ema"), cfg.version + v1, sell_side_risk_ratio_24h_30d_ema @@ -435,7 +435,7 @@ impl RealizedBase { &sell_side_risk_ratio_24h_30d_ema, ); - let peak_regret_rel_to_realized_cap = ComputedFromHeightLast::forced_import( + let peak_regret_rel_to_realized_cap = ComputedFromHeight::forced_import( cfg.db, &cfg.name("peak_regret_rel_to_realized_cap"), cfg.version + v1, @@ -447,7 +447,7 @@ impl RealizedBase { realized_cap, realized_price, realized_price_extra, - realized_cap_30d_delta: ComputedFromHeightLast::forced_import( + realized_cap_30d_delta: ComputedFromHeight::forced_import( cfg.db, &cfg.name("realized_cap_30d_delta"), cfg.version, @@ -510,21 +510,21 @@ impl RealizedBase { sell_side_risk_ratio_7d_ema, sell_side_risk_ratio_24h_30d_ema, sell_side_risk_ratio_30d_ema, - net_realized_pnl_cumulative_30d_delta: ComputedFromHeightLast::forced_import( + net_realized_pnl_cumulative_30d_delta: ComputedFromHeight::forced_import( cfg.db, &cfg.name("net_realized_pnl_cumulative_30d_delta"), cfg.version + v3, cfg.indexes, )?, net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap"), cfg.version + v3, cfg.indexes, )?, net_realized_pnl_cumulative_30d_delta_rel_to_market_cap: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("net_realized_pnl_cumulative_30d_delta_rel_to_market_cap"), cfg.version + v3, @@ -538,7 +538,7 @@ impl RealizedBase { cfg.version, cfg.indexes, )?, - sent_in_profit_14d_ema: ValueFromHeightLast::forced_import( + sent_in_profit_14d_ema: ValueFromHeight::forced_import( cfg.db, &cfg.name("sent_in_profit_14d_ema"), cfg.version, @@ -550,7 +550,7 @@ impl RealizedBase { cfg.version, cfg.indexes, )?, - sent_in_loss_14d_ema: ValueFromHeightLast::forced_import( + sent_in_loss_14d_ema: ValueFromHeight::forced_import( cfg.db, &cfg.name("sent_in_loss_14d_ema"), cfg.version, diff --git a/crates/brk_computer/src/distribution/metrics/realized/extended.rs b/crates/brk_computer/src/distribution/metrics/realized/extended.rs index 3cea06104..e3c39a991 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/extended.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/extended.rs @@ -5,7 +5,7 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode}; use crate::{ ComputeIndexes, blocks, - internal::{ComputedFromHeightLast, ComputedFromHeightRatioExtension, RatioCents64}, + internal::{ComputedFromHeight, ComputedFromHeightRatioExtension, RatioCents64}, }; use crate::distribution::metrics::ImportConfig; @@ -15,23 +15,23 @@ use super::RealizedBase; /// Extended realized metrics (only for extended cohorts: all, sth, lth, age_range). #[derive(Traversable)] pub struct RealizedExtended { - pub realized_cap_rel_to_own_market_cap: ComputedFromHeightLast, + pub realized_cap_rel_to_own_market_cap: ComputedFromHeight, // === Realized Profit/Loss Rolling Sums === - pub realized_profit_24h: ComputedFromHeightLast, - pub realized_profit_7d: ComputedFromHeightLast, - pub realized_profit_30d: ComputedFromHeightLast, - pub realized_profit_1y: ComputedFromHeightLast, - pub realized_loss_24h: ComputedFromHeightLast, - pub realized_loss_7d: ComputedFromHeightLast, - pub realized_loss_30d: ComputedFromHeightLast, - pub realized_loss_1y: ComputedFromHeightLast, + pub realized_profit_24h: ComputedFromHeight, + pub realized_profit_7d: ComputedFromHeight, + pub realized_profit_30d: ComputedFromHeight, + pub realized_profit_1y: ComputedFromHeight, + pub realized_loss_24h: ComputedFromHeight, + pub realized_loss_7d: ComputedFromHeight, + pub realized_loss_30d: ComputedFromHeight, + pub realized_loss_1y: ComputedFromHeight, // === Realized Profit to Loss Ratio (from rolling sums) === - pub realized_profit_to_loss_ratio_24h: ComputedFromHeightLast, - pub realized_profit_to_loss_ratio_7d: ComputedFromHeightLast, - pub realized_profit_to_loss_ratio_30d: ComputedFromHeightLast, - pub realized_profit_to_loss_ratio_1y: ComputedFromHeightLast, + pub realized_profit_to_loss_ratio_24h: ComputedFromHeight, + pub realized_profit_to_loss_ratio_7d: ComputedFromHeight, + pub realized_profit_to_loss_ratio_30d: ComputedFromHeight, + pub realized_profit_to_loss_ratio_1y: ComputedFromHeight, // === Extended ratio metrics for realized/investor price === pub realized_price_ratio_ext: ComputedFromHeightRatioExtension, @@ -44,7 +44,7 @@ impl RealizedExtended { macro_rules! import_rolling { ($name:expr) => { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name($name), cfg.version + v1, @@ -54,7 +54,7 @@ impl RealizedExtended { } Ok(RealizedExtended { - realized_cap_rel_to_own_market_cap: ComputedFromHeightLast::forced_import( + realized_cap_rel_to_own_market_cap: ComputedFromHeight::forced_import( cfg.db, &cfg.name("realized_cap_rel_to_own_market_cap"), cfg.version, diff --git a/crates/brk_computer/src/distribution/metrics/relative/base.rs b/crates/brk_computer/src/distribution/metrics/relative/base.rs index cee7ebc26..51bb858ba 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/base.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/base.rs @@ -4,7 +4,7 @@ use brk_types::{Dollars, Height, Sats, StoredF32, StoredF64, Version}; use vecdb::{Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode}; use crate::internal::{ - ComputedFromHeightLast, LazyFromHeightLast, + ComputedFromHeight, LazyFromHeight, NegPercentageDollarsF32, PercentageDollarsF32, PercentageSatsF64, StoredF32Identity, }; @@ -17,19 +17,19 @@ use crate::distribution::metrics::{ImportConfig, RealizedBase, UnrealizedBase}; #[derive(Traversable)] pub struct RelativeBase { // === Supply in Profit/Loss Relative to Own Supply === - pub supply_in_profit_rel_to_own_supply: ComputedFromHeightLast, - pub supply_in_loss_rel_to_own_supply: ComputedFromHeightLast, + pub supply_in_profit_rel_to_own_supply: ComputedFromHeight, + pub supply_in_loss_rel_to_own_supply: ComputedFromHeight, // === Unrealized vs Market Cap === - pub unrealized_profit_rel_to_market_cap: ComputedFromHeightLast, - pub unrealized_loss_rel_to_market_cap: ComputedFromHeightLast, - pub neg_unrealized_loss_rel_to_market_cap: ComputedFromHeightLast, - pub net_unrealized_pnl_rel_to_market_cap: ComputedFromHeightLast, - pub nupl: LazyFromHeightLast, + pub unrealized_profit_rel_to_market_cap: ComputedFromHeight, + pub unrealized_loss_rel_to_market_cap: ComputedFromHeight, + pub neg_unrealized_loss_rel_to_market_cap: ComputedFromHeight, + pub net_unrealized_pnl_rel_to_market_cap: ComputedFromHeight, + pub nupl: LazyFromHeight, // === Invested Capital in Profit/Loss as % of Realized Cap === - pub invested_capital_in_profit_pct: ComputedFromHeightLast, - pub invested_capital_in_loss_pct: ComputedFromHeightLast, + pub invested_capital_in_profit_pct: ComputedFromHeight, + pub invested_capital_in_loss_pct: ComputedFromHeight, } impl RelativeBase { @@ -37,11 +37,11 @@ impl RelativeBase { let v1 = Version::ONE; let v2 = Version::new(2); - let net_unrealized_pnl_rel_to_market_cap = ComputedFromHeightLast::forced_import( + let net_unrealized_pnl_rel_to_market_cap = ComputedFromHeight::forced_import( cfg.db, &cfg.name("net_unrealized_pnl_rel_to_market_cap"), cfg.version + v2, cfg.indexes, )?; - let nupl = LazyFromHeightLast::from_computed::( + let nupl = LazyFromHeight::from_computed::( &cfg.name("nupl"), cfg.version + v2, net_unrealized_pnl_rel_to_market_cap.height.read_only_boxed_clone(), @@ -49,27 +49,27 @@ impl RelativeBase { ); Ok(Self { - supply_in_profit_rel_to_own_supply: ComputedFromHeightLast::forced_import( + supply_in_profit_rel_to_own_supply: ComputedFromHeight::forced_import( cfg.db, &cfg.name("supply_in_profit_rel_to_own_supply"), cfg.version + v1, cfg.indexes, )?, - supply_in_loss_rel_to_own_supply: ComputedFromHeightLast::forced_import( + supply_in_loss_rel_to_own_supply: ComputedFromHeight::forced_import( cfg.db, &cfg.name("supply_in_loss_rel_to_own_supply"), cfg.version + v1, cfg.indexes, )?, - unrealized_profit_rel_to_market_cap: ComputedFromHeightLast::forced_import( + unrealized_profit_rel_to_market_cap: ComputedFromHeight::forced_import( cfg.db, &cfg.name("unrealized_profit_rel_to_market_cap"), cfg.version + v2, cfg.indexes, )?, - unrealized_loss_rel_to_market_cap: ComputedFromHeightLast::forced_import( + unrealized_loss_rel_to_market_cap: ComputedFromHeight::forced_import( cfg.db, &cfg.name("unrealized_loss_rel_to_market_cap"), cfg.version + v2, cfg.indexes, )?, - neg_unrealized_loss_rel_to_market_cap: ComputedFromHeightLast::forced_import( + neg_unrealized_loss_rel_to_market_cap: ComputedFromHeight::forced_import( cfg.db, &cfg.name("neg_unrealized_loss_rel_to_market_cap"), cfg.version + v2, cfg.indexes, )?, net_unrealized_pnl_rel_to_market_cap, nupl, - invested_capital_in_profit_pct: ComputedFromHeightLast::forced_import( + invested_capital_in_profit_pct: ComputedFromHeight::forced_import( cfg.db, &cfg.name("invested_capital_in_profit_pct"), cfg.version, cfg.indexes, )?, - invested_capital_in_loss_pct: ComputedFromHeightLast::forced_import( + invested_capital_in_loss_pct: ComputedFromHeight::forced_import( cfg.db, &cfg.name("invested_capital_in_loss_pct"), cfg.version, cfg.indexes, )?, }) 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 f0e5a408a..e3dd68d09 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 @@ -4,7 +4,7 @@ use brk_types::{Dollars, Height, StoredF32}; use vecdb::{Exit, ReadableVec, Rw, StorageMode}; use crate::internal::{ - ComputedFromHeightLast, NegPercentageDollarsF32, PercentageDollarsF32, + ComputedFromHeight, NegPercentageDollarsF32, PercentageDollarsF32, }; use crate::distribution::metrics::{ImportConfig, UnrealizedBase}; @@ -13,13 +13,13 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedBase}; #[derive(Traversable)] pub struct RelativeExtendedOwnMarketCap { pub unrealized_profit_rel_to_own_market_cap: - ComputedFromHeightLast, + ComputedFromHeight, pub unrealized_loss_rel_to_own_market_cap: - ComputedFromHeightLast, + ComputedFromHeight, pub neg_unrealized_loss_rel_to_own_market_cap: - ComputedFromHeightLast, + ComputedFromHeight, pub net_unrealized_pnl_rel_to_own_market_cap: - ComputedFromHeightLast, + ComputedFromHeight, } impl RelativeExtendedOwnMarketCap { @@ -30,28 +30,28 @@ impl RelativeExtendedOwnMarketCap { Ok(Self { unrealized_profit_rel_to_own_market_cap: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("unrealized_profit_rel_to_own_market_cap"), cfg.version + v2, cfg.indexes, )?, unrealized_loss_rel_to_own_market_cap: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("unrealized_loss_rel_to_own_market_cap"), cfg.version + v2, cfg.indexes, )?, neg_unrealized_loss_rel_to_own_market_cap: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("neg_unrealized_loss_rel_to_own_market_cap"), cfg.version + v2, cfg.indexes, )?, net_unrealized_pnl_rel_to_own_market_cap: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("net_unrealized_pnl_rel_to_own_market_cap"), cfg.version + v2, 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 85baaecce..f96ec3806 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 @@ -4,7 +4,7 @@ use brk_types::{Dollars, Height, StoredF32}; use vecdb::{Exit, Rw, StorageMode}; use crate::internal::{ - ComputedFromHeightLast, NegPercentageDollarsF32, PercentageDollarsF32, + ComputedFromHeight, NegPercentageDollarsF32, PercentageDollarsF32, }; use crate::distribution::metrics::{ImportConfig, UnrealizedBase}; @@ -13,13 +13,13 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedBase}; #[derive(Traversable)] pub struct RelativeExtendedOwnPnl { pub unrealized_profit_rel_to_own_total_unrealized_pnl: - ComputedFromHeightLast, + ComputedFromHeight, pub unrealized_loss_rel_to_own_total_unrealized_pnl: - ComputedFromHeightLast, + ComputedFromHeight, pub neg_unrealized_loss_rel_to_own_total_unrealized_pnl: - ComputedFromHeightLast, + ComputedFromHeight, pub net_unrealized_pnl_rel_to_own_total_unrealized_pnl: - ComputedFromHeightLast, + ComputedFromHeight, } impl RelativeExtendedOwnPnl { @@ -31,28 +31,28 @@ impl RelativeExtendedOwnPnl { Ok(Self { unrealized_profit_rel_to_own_total_unrealized_pnl: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("unrealized_profit_rel_to_own_total_unrealized_pnl"), cfg.version + v1, cfg.indexes, )?, unrealized_loss_rel_to_own_total_unrealized_pnl: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("unrealized_loss_rel_to_own_total_unrealized_pnl"), cfg.version + v1, cfg.indexes, )?, neg_unrealized_loss_rel_to_own_total_unrealized_pnl: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("neg_unrealized_loss_rel_to_own_total_unrealized_pnl"), cfg.version + v1, cfg.indexes, )?, net_unrealized_pnl_rel_to_own_total_unrealized_pnl: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("net_unrealized_pnl_rel_to_own_total_unrealized_pnl"), cfg.version + v2, diff --git a/crates/brk_computer/src/distribution/metrics/relative/peak_regret.rs b/crates/brk_computer/src/distribution/metrics/relative/peak_regret.rs index 84752e335..caae0e539 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/peak_regret.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/peak_regret.rs @@ -4,7 +4,7 @@ use brk_types::{Dollars, Height, StoredF32}; use vecdb::{Exit, ReadableVec, Rw, StorageMode}; use crate::internal::{ - ComputedFromHeightLast, PercentageDollarsF32, + ComputedFromHeight, PercentageDollarsF32, }; use crate::distribution::metrics::ImportConfig; @@ -13,7 +13,7 @@ use crate::distribution::metrics::ImportConfig; #[derive(Traversable)] pub struct RelativePeakRegret { pub unrealized_peak_regret_rel_to_market_cap: - ComputedFromHeightLast, + ComputedFromHeight, } impl RelativePeakRegret { @@ -22,7 +22,7 @@ impl RelativePeakRegret { ) -> Result { Ok(Self { unrealized_peak_regret_rel_to_market_cap: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("unrealized_peak_regret_rel_to_market_cap"), cfg.version, 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 f6487c011..edb9d83f3 100644 --- a/crates/brk_computer/src/distribution/metrics/relative/to_all.rs +++ b/crates/brk_computer/src/distribution/metrics/relative/to_all.rs @@ -3,7 +3,7 @@ use brk_traversable::Traversable; use brk_types::{Height, Sats, StoredF64}; use vecdb::{Exit, ReadableVec, Rw, StorageMode}; -use crate::internal::{ComputedFromHeightLast, PercentageSatsF64}; +use crate::internal::{ComputedFromHeight, PercentageSatsF64}; use crate::distribution::metrics::{ImportConfig, UnrealizedBase}; @@ -11,11 +11,11 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedBase}; #[derive(Traversable)] pub struct RelativeToAll { pub supply_rel_to_circulating_supply: - ComputedFromHeightLast, + ComputedFromHeight, pub supply_in_profit_rel_to_circulating_supply: - ComputedFromHeightLast, + ComputedFromHeight, pub supply_in_loss_rel_to_circulating_supply: - ComputedFromHeightLast, + ComputedFromHeight, } impl RelativeToAll { @@ -24,21 +24,21 @@ impl RelativeToAll { ) -> Result { Ok(Self { supply_rel_to_circulating_supply: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("supply_rel_to_circulating_supply"), cfg.version + brk_types::Version::ONE, cfg.indexes, )?, supply_in_profit_rel_to_circulating_supply: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("supply_in_profit_rel_to_circulating_supply"), cfg.version + brk_types::Version::ONE, cfg.indexes, )?, supply_in_loss_rel_to_circulating_supply: - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( cfg.db, &cfg.name("supply_in_loss_rel_to_circulating_supply"), cfg.version + brk_types::Version::ONE, diff --git a/crates/brk_computer/src/distribution/metrics/supply.rs b/crates/brk_computer/src/distribution/metrics/supply.rs index 3887110aa..53c0c7e2d 100644 --- a/crates/brk_computer/src/distribution/metrics/supply.rs +++ b/crates/brk_computer/src/distribution/metrics/supply.rs @@ -7,8 +7,8 @@ use rayon::prelude::*; use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec}; use crate::internal::{ - HalveDollars, HalveSats, HalveSatsToBitcoin, - LazyValueFromHeightLast, ValueFromHeightChange, ValueFromHeightLast, + HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin, + LazyValueFromHeight, ValueFromHeightChange, ValueFromHeight, }; use super::ImportConfig; @@ -16,8 +16,8 @@ use super::ImportConfig; /// Supply metrics for a cohort. #[derive(Traversable)] pub struct SupplyMetrics { - pub total: ValueFromHeightLast, - pub halved: LazyValueFromHeightLast, + pub total: ValueFromHeight, + pub halved: LazyValueFromHeight, /// 30-day change in supply (net position change) - sats, btc, usd pub _30d_change: ValueFromHeightChange, } @@ -25,16 +25,17 @@ pub struct SupplyMetrics { impl SupplyMetrics { /// Import supply metrics from database. pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { - let supply = ValueFromHeightLast::forced_import( + let supply = ValueFromHeight::forced_import( cfg.db, &cfg.name("supply"), cfg.version, cfg.indexes, )?; - let supply_halved = LazyValueFromHeightLast::from_block_source::< + let supply_halved = LazyValueFromHeight::from_block_source::< HalveSats, HalveSatsToBitcoin, + HalveCents, HalveDollars, >(&cfg.name("supply_halved"), &supply, cfg.version); diff --git a/crates/brk_computer/src/distribution/metrics/unrealized/base.rs b/crates/brk_computer/src/distribution/metrics/unrealized/base.rs index 26e8e701d..fa773e6de 100644 --- a/crates/brk_computer/src/distribution/metrics/unrealized/base.rs +++ b/crates/brk_computer/src/distribution/metrics/unrealized/base.rs @@ -10,8 +10,8 @@ use crate::{ ComputeIndexes, distribution::state::UnrealizedState, internal::{ - CentsSubtractToCentsSigned, FiatFromHeightLast, LazyFromHeightLast, NegCentsUnsignedToDollars, - ValueFromHeightLast, + CentsSubtractToCentsSigned, FiatFromHeight, LazyFromHeight, NegCentsUnsignedToDollars, + ValueFromHeight, }, prices, }; @@ -24,16 +24,16 @@ use crate::distribution::metrics::ImportConfig; #[derive(Traversable)] pub struct UnrealizedBase { // === Supply in Profit/Loss === - pub supply_in_profit: ValueFromHeightLast, - pub supply_in_loss: ValueFromHeightLast, + pub supply_in_profit: ValueFromHeight, + pub supply_in_loss: ValueFromHeight, // === Unrealized Profit/Loss === - pub unrealized_profit: FiatFromHeightLast, - pub unrealized_loss: FiatFromHeightLast, + pub unrealized_profit: FiatFromHeight, + pub unrealized_loss: FiatFromHeight, // === Invested Capital in Profit/Loss === - pub invested_capital_in_profit: FiatFromHeightLast, - pub invested_capital_in_loss: FiatFromHeightLast, + pub invested_capital_in_profit: FiatFromHeight, + pub invested_capital_in_loss: FiatFromHeight, // === Raw values for precise aggregation (used to compute pain/greed indices) === pub invested_capital_in_profit_raw: M::Stored>, @@ -42,53 +42,53 @@ pub struct UnrealizedBase { pub investor_cap_in_loss_raw: M::Stored>, // === Pain/Greed Indices === - pub pain_index: FiatFromHeightLast, - pub greed_index: FiatFromHeightLast, - pub net_sentiment: FiatFromHeightLast, + pub pain_index: FiatFromHeight, + pub greed_index: FiatFromHeight, + pub net_sentiment: FiatFromHeight, // === Negated === - pub neg_unrealized_loss: LazyFromHeightLast, + pub neg_unrealized_loss: LazyFromHeight, // === Net and Total === - pub net_unrealized_pnl: FiatFromHeightLast, - pub total_unrealized_pnl: FiatFromHeightLast, + pub net_unrealized_pnl: FiatFromHeight, + pub total_unrealized_pnl: FiatFromHeight, } impl UnrealizedBase { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { - let supply_in_profit = ValueFromHeightLast::forced_import( + let supply_in_profit = ValueFromHeight::forced_import( cfg.db, &cfg.name("supply_in_profit"), cfg.version, cfg.indexes, )?; - let supply_in_loss = ValueFromHeightLast::forced_import( + let supply_in_loss = ValueFromHeight::forced_import( cfg.db, &cfg.name("supply_in_loss"), cfg.version, cfg.indexes, )?; - let unrealized_profit = FiatFromHeightLast::forced_import( + let unrealized_profit = FiatFromHeight::forced_import( cfg.db, &cfg.name("unrealized_profit"), cfg.version, cfg.indexes, )?; - let unrealized_loss = FiatFromHeightLast::forced_import( + let unrealized_loss = FiatFromHeight::forced_import( cfg.db, &cfg.name("unrealized_loss"), cfg.version, cfg.indexes, )?; - let invested_capital_in_profit = FiatFromHeightLast::forced_import( + let invested_capital_in_profit = FiatFromHeight::forced_import( cfg.db, &cfg.name("invested_capital_in_profit"), cfg.version, cfg.indexes, )?; - let invested_capital_in_loss = FiatFromHeightLast::forced_import( + let invested_capital_in_loss = FiatFromHeight::forced_import( cfg.db, &cfg.name("invested_capital_in_loss"), cfg.version, @@ -116,39 +116,39 @@ impl UnrealizedBase { cfg.version, )?; - let pain_index = FiatFromHeightLast::forced_import( + let pain_index = FiatFromHeight::forced_import( cfg.db, &cfg.name("pain_index"), cfg.version, cfg.indexes, )?; - let greed_index = FiatFromHeightLast::forced_import( + let greed_index = FiatFromHeight::forced_import( cfg.db, &cfg.name("greed_index"), cfg.version, cfg.indexes, )?; - let net_sentiment = FiatFromHeightLast::forced_import( + let net_sentiment = FiatFromHeight::forced_import( cfg.db, &cfg.name("net_sentiment"), cfg.version + Version::ONE, cfg.indexes, )?; - let neg_unrealized_loss = LazyFromHeightLast::from_computed::( + let neg_unrealized_loss = LazyFromHeight::from_computed::( &cfg.name("neg_unrealized_loss"), cfg.version, unrealized_loss.cents.height.read_only_boxed_clone(), &unrealized_loss.cents, ); - let net_unrealized_pnl = FiatFromHeightLast::forced_import( + let net_unrealized_pnl = FiatFromHeight::forced_import( cfg.db, &cfg.name("net_unrealized_pnl"), cfg.version, cfg.indexes, )?; - let total_unrealized_pnl = FiatFromHeightLast::forced_import( + let total_unrealized_pnl = FiatFromHeight::forced_import( cfg.db, &cfg.name("total_unrealized_pnl"), cfg.version, diff --git a/crates/brk_computer/src/distribution/metrics/unrealized/peak_regret.rs b/crates/brk_computer/src/distribution/metrics/unrealized/peak_regret.rs index a8a848f4f..5c97b2448 100644 --- a/crates/brk_computer/src/distribution/metrics/unrealized/peak_regret.rs +++ b/crates/brk_computer/src/distribution/metrics/unrealized/peak_regret.rs @@ -3,7 +3,7 @@ use brk_traversable::Traversable; use brk_types::Cents; use vecdb::{AnyStoredVec, Exit, Rw, StorageMode}; -use crate::{ComputeIndexes, internal::FiatFromHeightLast}; +use crate::{ComputeIndexes, internal::FiatFromHeight}; use crate::distribution::metrics::ImportConfig; @@ -11,13 +11,13 @@ use crate::distribution::metrics::ImportConfig; #[derive(Traversable)] pub struct UnrealizedPeakRegret { /// Unrealized peak regret: sum of (peak_price - reference_price) x supply - pub peak_regret: FiatFromHeightLast, + pub peak_regret: FiatFromHeight, } impl UnrealizedPeakRegret { pub(crate) fn forced_import(cfg: &ImportConfig) -> Result { Ok(Self { - peak_regret: FiatFromHeightLast::forced_import( + peak_regret: FiatFromHeight::forced_import( cfg.db, &cfg.name("unrealized_peak_regret"), cfg.version, diff --git a/crates/brk_computer/src/inputs/count/import.rs b/crates/brk_computer/src/inputs/count/import.rs index 97a8b5ed9..afce995c0 100644 --- a/crates/brk_computer/src/inputs/count/import.rs +++ b/crates/brk_computer/src/inputs/count/import.rs @@ -3,11 +3,15 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::ComputedFromHeightFull}; +use crate::{indexes, internal::ComputedFromHeightAggregated}; impl Vecs { - pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result { - Ok(Self(ComputedFromHeightFull::forced_import( + pub(crate) fn forced_import( + db: &Database, + version: Version, + indexes: &indexes::Vecs, + ) -> Result { + Ok(Self(ComputedFromHeightAggregated::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 05a1cc9af..b6f1786a6 100644 --- a/crates/brk_computer/src/inputs/count/vecs.rs +++ b/crates/brk_computer/src/inputs/count/vecs.rs @@ -4,10 +4,9 @@ use brk_traversable::Traversable; use brk_types::StoredU64; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedFromHeightFull; +use crate::internal::ComputedFromHeightAggregated; #[derive(Deref, DerefMut, Traversable)] pub struct Vecs( - #[traversable(flatten)] - pub ComputedFromHeightFull, + #[traversable(flatten)] pub ComputedFromHeightAggregated, ); diff --git a/crates/brk_computer/src/internal/from_height/aggregated.rs b/crates/brk_computer/src/internal/from_height/aggregated.rs new file mode 100644 index 000000000..a8d956b0c --- /dev/null +++ b/crates/brk_computer/src/internal/from_height/aggregated.rs @@ -0,0 +1,73 @@ +//! ComputedFromHeightAggregated - 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. + +use std::ops::SubAssign; + +use brk_error::Result; +use brk_traversable::Traversable; +use brk_types::{Height, Version}; +use schemars::JsonSchema; +use vecdb::{Database, Exit, Rw, StorageMode}; + +use crate::{ + indexes, + internal::{Full, NumericValue, RollingFull, WindowStarts}, +}; + +#[derive(Traversable)] +pub struct ComputedFromHeightAggregated +where + T: NumericValue + JsonSchema, +{ + #[traversable(flatten)] + pub full: Full, + pub rolling: RollingFull, +} + +const VERSION: Version = Version::ZERO; + +impl ComputedFromHeightAggregated +where + T: NumericValue + JsonSchema, +{ + pub(crate) fn forced_import( + db: &Database, + name: &str, + version: Version, + indexes: &indexes::Vecs, + ) -> Result { + let v = version + VERSION; + + let height = Full::forced_import(db, name, v)?; + let rolling = RollingFull::forced_import(db, name, v, indexes)?; + + Ok(Self { + full: height, + rolling, + }) + } + + /// Compute Full stats via closure, then rolling windows from the per-block sum. + pub(crate) fn compute( + &mut self, + max_from: Height, + windows: &WindowStarts<'_>, + exit: &Exit, + compute_full: impl FnOnce(&mut Full) -> Result<()>, + ) -> Result<()> + where + T: From + Default + SubAssign + Copy + Ord, + f64: From, + { + compute_full(&mut self.full)?; + self.rolling.compute( + max_from, + windows, + self.full.sum_cumulative.sum.inner(), + exit, + )?; + Ok(()) + } +} diff --git a/crates/brk_computer/src/internal/from_height/last.rs b/crates/brk_computer/src/internal/from_height/base.rs similarity index 86% rename from crates/brk_computer/src/internal/from_height/last.rs rename to crates/brk_computer/src/internal/from_height/base.rs index f1c4ba8f9..6e88709aa 100644 --- a/crates/brk_computer/src/internal/from_height/last.rs +++ b/crates/brk_computer/src/internal/from_height/base.rs @@ -13,11 +13,11 @@ use vecdb::{ use crate::indexes; -use crate::internal::{ComputedHeightDerivedLast, ComputedVecValue, NumericValue}; +use crate::internal::{ComputedHeightDerived, ComputedVecValue, NumericValue}; #[derive(Deref, DerefMut, Traversable)] #[traversable(merge)] -pub struct ComputedFromHeightLast +pub struct ComputedFromHeight where T: ComputedVecValue + PartialOrd + JsonSchema, { @@ -25,12 +25,12 @@ where #[deref] #[deref_mut] #[traversable(flatten)] - pub rest: Box>, + pub rest: Box>, } const VERSION: Version = Version::ZERO; -impl ComputedFromHeightLast +impl ComputedFromHeight where T: NumericValue + JsonSchema, { @@ -44,7 +44,7 @@ where let height: EagerVec> = EagerVec::forced_import(db, name, v)?; - let rest = ComputedHeightDerivedLast::forced_import( + let rest = ComputedHeightDerived::forced_import( name, height.read_only_boxed_clone(), v, diff --git a/crates/brk_computer/src/internal/from_height/by_unit/mod.rs b/crates/brk_computer/src/internal/from_height/by_unit/mod.rs index 05f5a5662..8c9ee1243 100644 --- a/crates/brk_computer/src/internal/from_height/by_unit/mod.rs +++ b/crates/brk_computer/src/internal/from_height/by_unit/mod.rs @@ -10,7 +10,7 @@ use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode}; use crate::{ indexes, internal::{ - CentsUnsignedToDollars, ComputedFromHeightLast, LazyFromHeightLast, SatsToBitcoin, + CentsUnsignedToDollars, ComputedFromHeight, LazyFromHeight, SatsToBitcoin, }, }; @@ -19,10 +19,10 @@ pub use rolling_sum::*; #[derive(Traversable)] pub struct ByUnit { - pub sats: ComputedFromHeightLast, - pub btc: LazyFromHeightLast, - pub cents: ComputedFromHeightLast, - pub usd: LazyFromHeightLast, + pub sats: ComputedFromHeight, + pub btc: LazyFromHeight, + pub cents: ComputedFromHeight, + pub usd: LazyFromHeight, } impl ByUnit { @@ -32,23 +32,23 @@ impl ByUnit { version: Version, indexes: &indexes::Vecs, ) -> Result { - let sats = ComputedFromHeightLast::forced_import(db, name, version, indexes)?; + let sats = ComputedFromHeight::forced_import(db, name, version, indexes)?; - let btc = LazyFromHeightLast::from_computed::( + let btc = LazyFromHeight::from_computed::( &format!("{name}_btc"), version, sats.height.read_only_boxed_clone(), &sats, ); - let cents = ComputedFromHeightLast::forced_import( + let cents = ComputedFromHeight::forced_import( db, &format!("{name}_cents"), version, indexes, )?; - let usd = LazyFromHeightLast::from_computed::( + let usd = LazyFromHeight::from_computed::( &format!("{name}_usd"), version, cents.height.read_only_boxed_clone(), diff --git a/crates/brk_computer/src/internal/from_height/cumulative.rs b/crates/brk_computer/src/internal/from_height/cumulative.rs index 71b1ca83d..7421579b6 100644 --- a/crates/brk_computer/src/internal/from_height/cumulative.rs +++ b/crates/brk_computer/src/internal/from_height/cumulative.rs @@ -2,7 +2,7 @@ //! //! Like ComputedFromHeightCumulativeSum but without RollingWindows. //! Used for distribution metrics where rolling is optional per cohort. -//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views. +//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views. use brk_error::Result; use brk_traversable::Traversable; @@ -12,7 +12,7 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{ComputedFromHeightLast, NumericValue}, + internal::{ComputedFromHeight, NumericValue}, }; #[derive(Traversable)] @@ -21,7 +21,7 @@ where T: NumericValue + JsonSchema, { pub height: M::Stored>>, - pub cumulative: ComputedFromHeightLast, + pub cumulative: ComputedFromHeight, } const VERSION: Version = Version::ZERO; @@ -40,7 +40,7 @@ where let height: EagerVec> = EagerVec::forced_import(db, name, v)?; let cumulative = - ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?; + ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?; Ok(Self { height, cumulative }) } diff --git a/crates/brk_computer/src/internal/from_height/cumulative_full.rs b/crates/brk_computer/src/internal/from_height/cumulative_full.rs deleted file mode 100644 index 7e8d1e4f2..000000000 --- a/crates/brk_computer/src/internal/from_height/cumulative_full.rs +++ /dev/null @@ -1,76 +0,0 @@ -//! ComputedFromHeightCumulativeFull - stored height + LazyAggVec + cumulative (from height) + RollingFull. -//! -//! For metrics with stored per-block data, cumulative sums, and rolling windows. -//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views too. - -use std::ops::SubAssign; - -use brk_error::Result; -use brk_traversable::Traversable; -use brk_types::{Height, Version}; -use schemars::JsonSchema; -use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode}; - -use crate::{ - indexes, - internal::{ComputedFromHeightLast, NumericValue, RollingFull, WindowStarts}, -}; - -#[derive(Traversable)] -pub struct ComputedFromHeightCumulativeFull -where - T: NumericValue + JsonSchema, -{ - pub height: M::Stored>>, - pub cumulative: ComputedFromHeightLast, - #[traversable(flatten)] - pub rolling: RollingFull, -} - -const VERSION: Version = Version::ZERO; - -impl ComputedFromHeightCumulativeFull -where - T: NumericValue + JsonSchema, -{ - pub(crate) fn forced_import( - db: &Database, - name: &str, - version: Version, - indexes: &indexes::Vecs, - ) -> Result { - let v = version + VERSION; - - let height: EagerVec> = EagerVec::forced_import(db, name, v)?; - let cumulative = - ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?; - let rolling = RollingFull::forced_import(db, name, v, indexes)?; - - Ok(Self { - height, - cumulative, - rolling, - }) - } - - /// Compute height data via closure, then cumulative + rolling. - pub(crate) fn compute( - &mut self, - max_from: Height, - windows: &WindowStarts<'_>, - exit: &Exit, - compute_height: impl FnOnce(&mut EagerVec>) -> Result<()>, - ) -> Result<()> - where - T: From + Default + SubAssign + Copy + Ord, - f64: From, - { - compute_height(&mut self.height)?; - self.cumulative - .height - .compute_cumulative(max_from, &self.height, exit)?; - self.rolling - .compute(max_from, windows, &self.height, exit)?; - Ok(()) - } -} diff --git a/crates/brk_computer/src/internal/from_height/cumulative_sum.rs b/crates/brk_computer/src/internal/from_height/cumulative_sum.rs index 748307cdf..0dace89d2 100644 --- a/crates/brk_computer/src/internal/from_height/cumulative_sum.rs +++ b/crates/brk_computer/src/internal/from_height/cumulative_sum.rs @@ -1,8 +1,8 @@ //! ComputedFromHeightCumulativeSum - stored height + LazyAggVec + cumulative (from height) + RollingWindows (sum). //! -//! Like ComputedFromHeightCumulativeFull but with rolling sum only (no distribution). +//! Like ComputedFromHeightFull but with rolling sum only (no distribution). //! Used for count metrics where distribution stats aren't meaningful. -//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views too. +//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too. use std::ops::SubAssign; @@ -14,7 +14,7 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{ComputedFromHeightLast, NumericValue, RollingWindows, WindowStarts}, + internal::{ComputedFromHeight, NumericValue, RollingWindows, WindowStarts}, }; #[derive(Traversable)] @@ -23,7 +23,7 @@ where T: NumericValue + JsonSchema, { pub height: M::Stored>>, - pub cumulative: ComputedFromHeightLast, + pub cumulative: ComputedFromHeight, pub sum: RollingWindows, } @@ -43,7 +43,7 @@ where let height: EagerVec> = EagerVec::forced_import(db, name, v)?; let cumulative = - ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?; + ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?; let rolling = RollingWindows::forced_import(db, name, v, indexes)?; Ok(Self { diff --git a/crates/brk_computer/src/internal/from_height/fiat.rs b/crates/brk_computer/src/internal/from_height/fiat.rs index 668caa7db..cfbcfaa3e 100644 --- a/crates/brk_computer/src/internal/from_height/fiat.rs +++ b/crates/brk_computer/src/internal/from_height/fiat.rs @@ -4,7 +4,7 @@ use brk_types::{Cents, CentsSigned, Dollars, Version}; use schemars::JsonSchema; use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode, UnaryTransform}; -use super::{ComputedFromHeightLast, LazyFromHeightLast}; +use super::{ComputedFromHeight, LazyFromHeight}; use crate::{ indexes, internal::{CentsSignedToDollars, CentsUnsignedToDollars, NumericValue}, @@ -26,25 +26,25 @@ 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 FiatFromHeightLast { - pub cents: ComputedFromHeightLast, - pub usd: LazyFromHeightLast, +pub struct FiatFromHeight { + pub cents: ComputedFromHeight, + pub usd: LazyFromHeight, } -impl FiatFromHeightLast { +impl FiatFromHeight { pub(crate) fn forced_import( db: &Database, name: &str, version: Version, indexes: &indexes::Vecs, ) -> Result { - let cents = ComputedFromHeightLast::forced_import( + let cents = ComputedFromHeight::forced_import( db, &format!("{name}_cents"), version, indexes, )?; - let usd = LazyFromHeightLast::from_computed::( + let usd = LazyFromHeight::from_computed::( &format!("{name}_usd"), version, cents.height.read_only_boxed_clone(), diff --git a/crates/brk_computer/src/internal/from_height/full.rs b/crates/brk_computer/src/internal/from_height/full.rs index 3de520081..778a8f06d 100644 --- a/crates/brk_computer/src/internal/from_height/full.rs +++ b/crates/brk_computer/src/internal/from_height/full.rs @@ -1,7 +1,7 @@ -//! ComputedFromHeightFull - Full (distribution + sum + cumulative) + RollingFull. +//! ComputedFromHeightFull - stored height + LazyAggVec + cumulative (from height) + 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. +//! For metrics with stored per-block data, cumulative sums, and rolling windows. +//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too. use std::ops::SubAssign; @@ -9,11 +9,11 @@ use brk_error::Result; use brk_traversable::Traversable; use brk_types::{Height, Version}; use schemars::JsonSchema; -use vecdb::{Database, Exit, Rw, StorageMode}; +use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{Full, NumericValue, RollingFull, WindowStarts}, + internal::{ComputedFromHeight, NumericValue, RollingFull, WindowStarts}, }; #[derive(Traversable)] @@ -21,8 +21,9 @@ pub struct ComputedFromHeightFull where T: NumericValue + JsonSchema, { + pub height: M::Stored>>, + pub cumulative: ComputedFromHeight, #[traversable(flatten)] - pub full: Full, pub rolling: RollingFull, } @@ -40,34 +41,36 @@ where ) -> Result { let v = version + VERSION; - let height = Full::forced_import(db, name, v)?; + let height: EagerVec> = EagerVec::forced_import(db, name, v)?; + let cumulative = + ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?; let rolling = RollingFull::forced_import(db, name, v, indexes)?; Ok(Self { - full: height, + height, + cumulative, rolling, }) } - /// Compute Full stats via closure, then rolling windows from the per-block sum. + /// Compute height data via closure, then cumulative + rolling. pub(crate) fn compute( &mut self, max_from: Height, windows: &WindowStarts<'_>, exit: &Exit, - compute_full: impl FnOnce(&mut Full) -> Result<()>, + compute_height: impl FnOnce(&mut EagerVec>) -> Result<()>, ) -> Result<()> where T: From + Default + SubAssign + Copy + Ord, f64: From, { - compute_full(&mut self.full)?; - self.rolling.compute( - max_from, - windows, - self.full.sum_cumulative.sum.inner(), - exit, - )?; + compute_height(&mut self.height)?; + self.cumulative + .height + .compute_cumulative(max_from, &self.height, exit)?; + self.rolling + .compute(max_from, windows, &self.height, exit)?; Ok(()) } } diff --git a/crates/brk_computer/src/internal/from_height/lazy_last.rs b/crates/brk_computer/src/internal/from_height/lazy_base.rs similarity index 76% rename from crates/brk_computer/src/internal/from_height/lazy_last.rs rename to crates/brk_computer/src/internal/from_height/lazy_base.rs index 9acf3ab66..a36354113 100644 --- a/crates/brk_computer/src/internal/from_height/lazy_last.rs +++ b/crates/brk_computer/src/internal/from_height/lazy_base.rs @@ -8,11 +8,11 @@ use vecdb::{LazyVecFrom1, ReadableBoxedVec, ReadableCloneableVec, UnaryTransform use crate::{ indexes, - internal::{ComputedFromHeightLast, ComputedVecValue, LazyHeightDerivedLast, NumericValue}, + internal::{ComputedFromHeight, ComputedVecValue, LazyHeightDerived, NumericValue}, }; #[derive(Clone, Deref, DerefMut, Traversable)] #[traversable(merge)] -pub struct LazyFromHeightLast +pub struct LazyFromHeight where T: ComputedVecValue + PartialOrd + JsonSchema, S1T: ComputedVecValue, @@ -21,12 +21,12 @@ where #[deref] #[deref_mut] #[traversable(flatten)] - pub rest: Box>, + pub rest: Box>, } const VERSION: Version = Version::ZERO; -impl LazyFromHeightLast +impl LazyFromHeight where T: ComputedVecValue + JsonSchema + 'static, S1T: ComputedVecValue + JsonSchema, @@ -35,7 +35,7 @@ where name: &str, version: Version, height_source: ReadableBoxedVec, - source: &ComputedFromHeightLast, + source: &ComputedFromHeight, ) -> Self where S1T: NumericValue, @@ -43,7 +43,7 @@ where let v = version + VERSION; Self { height: LazyVecFrom1::transformed::(name, v, height_source), - rest: Box::new(LazyHeightDerivedLast::from_computed::(name, v, source)), + rest: Box::new(LazyHeightDerived::from_computed::(name, v, source)), } } @@ -59,7 +59,7 @@ where let v = version + VERSION; Self { height: LazyVecFrom1::transformed::(name, v, height_source.clone()), - rest: Box::new(LazyHeightDerivedLast::from_height_source::( + rest: Box::new(LazyHeightDerived::from_height_source::( name, v, height_source, @@ -68,11 +68,11 @@ where } } - /// Create by unary-transforming a LazyFromHeightLast source (chaining lazy vecs). + /// Create by unary-transforming a LazyFromHeight source (chaining lazy vecs). pub(crate) fn from_lazy( name: &str, version: Version, - source: &LazyFromHeightLast, + source: &LazyFromHeight, ) -> Self where F: UnaryTransform, @@ -81,7 +81,7 @@ where let v = version + VERSION; Self { height: LazyVecFrom1::transformed::(name, v, source.height.read_only_boxed_clone()), - rest: Box::new(LazyHeightDerivedLast::from_lazy::( + rest: Box::new(LazyHeightDerived::from_lazy::( name, v, &source.rest, diff --git a/crates/brk_computer/src/internal/from_height/mod.rs b/crates/brk_computer/src/internal/from_height/mod.rs index 7e8beb393..34b750254 100644 --- a/crates/brk_computer/src/internal/from_height/mod.rs +++ b/crates/brk_computer/src/internal/from_height/mod.rs @@ -1,43 +1,31 @@ +mod aggregated; +mod base; mod by_unit; mod constant; mod cumulative; -mod fiat; -mod cumulative_full; mod cumulative_sum; mod distribution; +mod fiat; mod full; -mod last; -mod value_cumulative; -mod lazy_last; -mod lazy_value_last; +mod lazy_base; mod percentiles; mod price; mod ratio; mod stddev; -mod value_change; -mod value_full; -mod value_last; -mod value_last_rolling; -mod value_sum_cumulative; +mod value; +pub use aggregated::*; +pub use base::*; pub use by_unit::*; pub use constant::*; pub use cumulative::*; -pub use cumulative_full::*; -pub use fiat::*; pub use cumulative_sum::*; pub use distribution::*; +pub use fiat::*; pub use full::*; -pub use last::*; -pub use value_cumulative::*; -pub use lazy_last::*; -pub use lazy_value_last::*; +pub use lazy_base::*; pub use percentiles::*; pub use price::*; pub use ratio::*; pub use stddev::*; -pub use value_change::*; -pub use value_full::*; -pub use value_last::*; -pub use value_last_rolling::*; -pub use value_sum_cumulative::*; +pub use value::*; diff --git a/crates/brk_computer/src/internal/from_height/percentiles.rs b/crates/brk_computer/src/internal/from_height/percentiles.rs index da66e223d..581e57410 100644 --- a/crates/brk_computer/src/internal/from_height/percentiles.rs +++ b/crates/brk_computer/src/internal/from_height/percentiles.rs @@ -4,7 +4,7 @@ use brk_types::{Cents, Height, StoredF32, Version}; use vecdb::{AnyExportableVec, Database, ReadOnlyClone, Ro, Rw, StorageMode, WritableVec}; use crate::indexes; -use crate::internal::{ComputedFromHeightLast, Price}; +use crate::internal::{ComputedFromHeight, 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, @@ -68,7 +68,7 @@ pub(crate) fn compute_spot_percentile_rank( } pub struct PercentilesVecs { - pub vecs: [Price>; PERCENTILES_LEN], + pub vecs: [Price>; PERCENTILES_LEN], } const VERSION: Version = Version::ONE; @@ -130,7 +130,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/from_height/price.rs index 386b2cec9..1771ed72c 100644 --- a/crates/brk_computer/src/internal/from_height/price.rs +++ b/crates/brk_computer/src/internal/from_height/price.rs @@ -10,7 +10,7 @@ use brk_types::{Cents, Dollars, SatsFract, Version}; use schemars::JsonSchema; use vecdb::{Database, ReadableCloneableVec, UnaryTransform}; -use super::{ComputedFromHeightLast, LazyFromHeightLast}; +use super::{ComputedFromHeight, LazyFromHeight}; 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: LazyFromHeightLast, - pub sats: LazyFromHeightLast, + pub usd: LazyFromHeight, + pub sats: LazyFromHeight, } -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 = - ComputedFromHeightLast::forced_import(db, &format!("{name}_cents"), version, indexes)?; - let usd = LazyFromHeightLast::from_computed::( + ComputedFromHeight::forced_import(db, &format!("{name}_cents"), version, indexes)?; + let usd = LazyFromHeight::from_computed::( &format!("{name}_usd"), version, cents.height.read_only_boxed_clone(), ¢s, ); - let sats = LazyFromHeightLast::from_lazy::( + let sats = LazyFromHeight::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: &ComputedFromHeightLast, + source: &ComputedFromHeight, ) -> Self { - let cents = LazyFromHeightLast::from_computed::( + let cents = LazyFromHeight::from_computed::( &format!("{name}_cents"), version, source.height.read_only_boxed_clone(), source, ); - let usd = LazyFromHeightLast::from_lazy::( + let usd = LazyFromHeight::from_lazy::( &format!("{name}_usd"), version, ¢s, ); - let sats = LazyFromHeightLast::from_lazy::( + let sats = LazyFromHeight::from_lazy::( &format!("{name}_sats"), version, &usd, diff --git a/crates/brk_computer/src/internal/from_height/ratio/extension.rs b/crates/brk_computer/src/internal/from_height/ratio/extension.rs index 515704e34..57c9ae1b7 100644 --- a/crates/brk_computer/src/internal/from_height/ratio/extension.rs +++ b/crates/brk_computer/src/internal/from_height/ratio/extension.rs @@ -9,24 +9,24 @@ use crate::{ }; use brk_types::get_percentile; -use super::super::ComputedFromHeightLast; +use super::super::ComputedFromHeight; #[derive(Traversable)] pub struct ComputedFromHeightRatioExtension { - pub ratio_1w_sma: ComputedFromHeightLast, - pub ratio_1m_sma: ComputedFromHeightLast, - pub ratio_pct99: ComputedFromHeightLast, - pub ratio_pct98: ComputedFromHeightLast, - pub ratio_pct95: ComputedFromHeightLast, - pub ratio_pct5: ComputedFromHeightLast, - pub ratio_pct2: ComputedFromHeightLast, - pub ratio_pct1: ComputedFromHeightLast, - 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 ratio_1w_sma: ComputedFromHeight, + pub ratio_1m_sma: ComputedFromHeight, + pub ratio_pct99: ComputedFromHeight, + pub ratio_pct98: ComputedFromHeight, + pub ratio_pct95: ComputedFromHeight, + pub ratio_pct5: ComputedFromHeight, + pub ratio_pct2: ComputedFromHeight, + pub ratio_pct1: ComputedFromHeight, + 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 ratio_sd: ComputedFromHeightStdDevExtended, pub ratio_4y_sd: ComputedFromHeightStdDevExtended, @@ -47,7 +47,7 @@ impl ComputedFromHeightRatioExtension { macro_rules! import { ($suffix:expr) => { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_{}", $suffix), v, diff --git a/crates/brk_computer/src/internal/from_height/ratio/mod.rs b/crates/brk_computer/src/internal/from_height/ratio/mod.rs index 3c99f6274..0f81a61dc 100644 --- a/crates/brk_computer/src/internal/from_height/ratio/mod.rs +++ b/crates/brk_computer/src/internal/from_height/ratio/mod.rs @@ -13,11 +13,11 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; use crate::{ComputeIndexes, indexes}; -use super::ComputedFromHeightLast; +use super::ComputedFromHeight; #[derive(Traversable)] pub struct ComputedFromHeightRatio { - pub ratio: ComputedFromHeightLast, + pub ratio: ComputedFromHeight, } const VERSION: Version = Version::TWO; @@ -32,7 +32,7 @@ impl ComputedFromHeightRatio { let v = version + VERSION; Ok(Self { - ratio: ComputedFromHeightLast::forced_import(db, &format!("{name}_ratio"), v, indexes)?, + ratio: ComputedFromHeight::forced_import(db, &format!("{name}_ratio"), v, indexes)?, }) } diff --git a/crates/brk_computer/src/internal/from_height/ratio/price_extended.rs b/crates/brk_computer/src/internal/from_height/ratio/price_extended.rs index 14f02878a..05d6909c9 100644 --- a/crates/brk_computer/src/internal/from_height/ratio/price_extended.rs +++ b/crates/brk_computer/src/internal/from_height/ratio/price_extended.rs @@ -4,7 +4,7 @@ use brk_types::{Cents, Height, Version}; use derive_more::{Deref, DerefMut}; use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode}; -use crate::internal::{ComputedFromHeightLast, Price}; +use crate::internal::{ComputedFromHeight, Price}; use crate::{ComputeIndexes, blocks, indexes, prices}; use super::ComputedFromHeightRatioExtended; @@ -15,7 +15,7 @@ pub struct ComputedFromHeightPriceWithRatioExtended { #[deref_mut] #[traversable(flatten)] pub inner: ComputedFromHeightRatioExtended, - pub price: Price>, + pub price: Price>, } impl ComputedFromHeightPriceWithRatioExtended { diff --git a/crates/brk_computer/src/internal/from_height/stddev/extended.rs b/crates/brk_computer/src/internal/from_height/stddev/extended.rs index 0f97ab614..1109354cc 100644 --- a/crates/brk_computer/src/internal/from_height/stddev/extended.rs +++ b/crates/brk_computer/src/internal/from_height/stddev/extended.rs @@ -8,7 +8,7 @@ use vecdb::{ use crate::{ComputeIndexes, blocks, indexes}; -use crate::internal::{ComputedFromHeightLast, Price}; +use crate::internal::{ComputedFromHeight, Price}; use super::ComputedFromHeightStdDev; @@ -17,34 +17,34 @@ pub struct ComputedFromHeightStdDevExtended { #[traversable(flatten)] pub base: ComputedFromHeightStdDev, - pub zscore: ComputedFromHeightLast, + pub zscore: ComputedFromHeight, - pub p0_5sd: ComputedFromHeightLast, - pub p1sd: ComputedFromHeightLast, - pub p1_5sd: ComputedFromHeightLast, - pub p2sd: ComputedFromHeightLast, - pub p2_5sd: ComputedFromHeightLast, - pub p3sd: ComputedFromHeightLast, - pub m0_5sd: ComputedFromHeightLast, - pub m1sd: ComputedFromHeightLast, - pub m1_5sd: ComputedFromHeightLast, - pub m2sd: ComputedFromHeightLast, - pub m2_5sd: ComputedFromHeightLast, - pub m3sd: ComputedFromHeightLast, + 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 _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 { @@ -59,7 +59,7 @@ impl ComputedFromHeightStdDevExtended { macro_rules! import { ($suffix:expr) => { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_{}", $suffix), version, diff --git a/crates/brk_computer/src/internal/from_height/stddev/mod.rs b/crates/brk_computer/src/internal/from_height/stddev/mod.rs index aa5517feb..39d79b40f 100644 --- a/crates/brk_computer/src/internal/from_height/stddev/mod.rs +++ b/crates/brk_computer/src/internal/from_height/stddev/mod.rs @@ -9,13 +9,13 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Rw, StorageMode, use crate::{ComputeIndexes, blocks, indexes}; -use crate::internal::ComputedFromHeightLast; +use crate::internal::ComputedFromHeight; #[derive(Traversable)] pub struct ComputedFromHeightStdDev { days: usize, - pub sma: ComputedFromHeightLast, - pub sd: ComputedFromHeightLast, + pub sma: ComputedFromHeight, + pub sd: ComputedFromHeight, } impl ComputedFromHeightStdDev { @@ -28,13 +28,13 @@ impl ComputedFromHeightStdDev { ) -> Result { let version = parent_version + Version::TWO; - let sma = ComputedFromHeightLast::forced_import( + let sma = ComputedFromHeight::forced_import( db, &format!("{name}_sma"), version, indexes, )?; - let sd = ComputedFromHeightLast::forced_import( + let sd = ComputedFromHeight::forced_import( db, &format!("{name}_sd"), version, @@ -84,7 +84,7 @@ impl ComputedFromHeightStdDev { } fn compute_sd( - sd: &mut ComputedFromHeightLast, + sd: &mut ComputedFromHeight, blocks: &blocks::Vecs, starting_indexes: &ComputeIndexes, exit: &Exit, diff --git a/crates/brk_computer/src/internal/from_height/value_last.rs b/crates/brk_computer/src/internal/from_height/value/base.rs similarity index 96% rename from crates/brk_computer/src/internal/from_height/value_last.rs rename to crates/brk_computer/src/internal/from_height/value/base.rs index 25541b3fe..bd2874dc3 100644 --- a/crates/brk_computer/src/internal/from_height/value_last.rs +++ b/crates/brk_computer/src/internal/from_height/value/base.rs @@ -11,7 +11,7 @@ use crate::{ #[derive(Deref, DerefMut, Traversable)] #[traversable(transparent)] -pub struct ValueFromHeightLast { +pub struct ValueFromHeight { #[deref] #[deref_mut] pub base: ByUnit, @@ -19,7 +19,7 @@ pub struct ValueFromHeightLast { const VERSION: Version = Version::TWO; -impl ValueFromHeightLast { +impl ValueFromHeight { pub(crate) fn forced_import( db: &Database, name: &str, diff --git a/crates/brk_computer/src/internal/from_height/value_change.rs b/crates/brk_computer/src/internal/from_height/value/change.rs similarity index 75% rename from crates/brk_computer/src/internal/from_height/value_change.rs rename to crates/brk_computer/src/internal/from_height/value/change.rs index 9e6aabfbd..d085449a7 100644 --- a/crates/brk_computer/src/internal/from_height/value_change.rs +++ b/crates/brk_computer/src/internal/from_height/value/change.rs @@ -8,7 +8,7 @@ use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode}; use crate::{ indexes, internal::{ - CentsSignedToDollars, ComputedFromHeightLast, LazyFromHeightLast, SatsSignedToBitcoin, + CentsSignedToDollars, ComputedFromHeight, LazyFromHeight, SatsSignedToBitcoin, }, }; @@ -17,10 +17,10 @@ const VERSION: Version = Version::ZERO; /// Change values indexed by height - sats (stored), btc (lazy), cents (stored), usd (lazy). #[derive(Traversable)] pub struct ValueFromHeightChange { - pub sats: ComputedFromHeightLast, - pub btc: LazyFromHeightLast, - pub cents: ComputedFromHeightLast, - pub usd: LazyFromHeightLast, + pub sats: ComputedFromHeight, + pub btc: LazyFromHeight, + pub cents: ComputedFromHeight, + pub usd: LazyFromHeight, } impl ValueFromHeightChange { @@ -32,23 +32,23 @@ impl ValueFromHeightChange { ) -> Result { let v = version + VERSION; - let sats = ComputedFromHeightLast::forced_import(db, name, v, indexes)?; + let sats = ComputedFromHeight::forced_import(db, name, v, indexes)?; - let btc = LazyFromHeightLast::from_computed::( + let btc = LazyFromHeight::from_computed::( &format!("{name}_btc"), v, sats.height.read_only_boxed_clone(), &sats, ); - let cents = ComputedFromHeightLast::forced_import( + let cents = ComputedFromHeight::forced_import( db, &format!("{name}_cents"), v, indexes, )?; - let usd = LazyFromHeightLast::from_computed::( + let usd = LazyFromHeight::from_computed::( &format!("{name}_usd"), v, cents.height.read_only_boxed_clone(), diff --git a/crates/brk_computer/src/internal/from_height/value_cumulative.rs b/crates/brk_computer/src/internal/from_height/value/cumulative.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/value_cumulative.rs rename to crates/brk_computer/src/internal/from_height/value/cumulative.rs diff --git a/crates/brk_computer/src/internal/from_height/value_sum_cumulative.rs b/crates/brk_computer/src/internal/from_height/value/cumulative_sum.rs similarity index 95% rename from crates/brk_computer/src/internal/from_height/value_sum_cumulative.rs rename to crates/brk_computer/src/internal/from_height/value/cumulative_sum.rs index 6cf5b8a95..faab7a7b2 100644 --- a/crates/brk_computer/src/internal/from_height/value_sum_cumulative.rs +++ b/crates/brk_computer/src/internal/from_height/value/cumulative_sum.rs @@ -10,7 +10,7 @@ use crate::{ }; #[derive(Traversable)] -pub struct ValueFromHeightSumCumulative { +pub struct ValueFromHeightCumulativeSum { pub base: ByUnit, pub cumulative: ByUnit, pub sum: RollingSumByUnit, @@ -18,7 +18,7 @@ pub struct ValueFromHeightSumCumulative { const VERSION: Version = Version::TWO; -impl ValueFromHeightSumCumulative { +impl ValueFromHeightCumulativeSum { pub(crate) fn forced_import( db: &Database, name: &str, diff --git a/crates/brk_computer/src/internal/from_height/value_full.rs b/crates/brk_computer/src/internal/from_height/value/full.rs similarity index 100% rename from crates/brk_computer/src/internal/from_height/value_full.rs rename to crates/brk_computer/src/internal/from_height/value/full.rs diff --git a/crates/brk_computer/src/internal/from_height/lazy_value_last.rs b/crates/brk_computer/src/internal/from_height/value/lazy.rs similarity index 53% rename from crates/brk_computer/src/internal/from_height/lazy_value_last.rs rename to crates/brk_computer/src/internal/from_height/value/lazy.rs index 86af294d5..d04808970 100644 --- a/crates/brk_computer/src/internal/from_height/lazy_value_last.rs +++ b/crates/brk_computer/src/internal/from_height/value/lazy.rs @@ -1,44 +1,45 @@ -//! Lazy value wrapper for ValueFromHeightLast - all transforms are lazy. +//! Lazy value wrapper for ValueFromHeight - all transforms are lazy. use brk_traversable::Traversable; -use brk_types::{Bitcoin, Dollars, Sats, Version}; +use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version}; use derive_more::{Deref, DerefMut}; use vecdb::UnaryTransform; -use crate::internal::{LazyValueFromHeight, LazyValueHeightDerivedLast, ValueFromHeightLast}; +use crate::internal::{LazyValue, LazyValueHeightDerived, ValueFromHeight}; const VERSION: Version = Version::ZERO; -/// Lazy value wrapper with height + all derived last transforms from ValueFromHeightLast. +/// Lazy value wrapper with height + all derived last transforms from ValueFromHeight. #[derive(Clone, Deref, DerefMut, Traversable)] #[traversable(merge)] -pub struct LazyValueFromHeightLast { +pub struct LazyValueFromHeight { #[traversable(flatten)] - pub height: LazyValueFromHeight, + pub height: LazyValue, #[deref] #[deref_mut] #[traversable(flatten)] - pub rest: Box, + pub rest: Box, } -impl LazyValueFromHeightLast { - pub(crate) fn from_block_source( +impl LazyValueFromHeight { + pub(crate) fn from_block_source( name: &str, - source: &ValueFromHeightLast, + source: &ValueFromHeight, version: Version, ) -> Self where SatsTransform: UnaryTransform, BitcoinTransform: UnaryTransform, + CentsTransform: UnaryTransform, DollarsTransform: UnaryTransform, { let v = version + VERSION; let height = - LazyValueFromHeight::from_block_source::(name, source, v); + LazyValue::from_block_source::(name, source, v); let rest = - LazyValueHeightDerivedLast::from_block_source::( + LazyValueHeightDerived::from_block_source::( name, source, v, ); diff --git a/crates/brk_computer/src/internal/from_height/value/mod.rs b/crates/brk_computer/src/internal/from_height/value/mod.rs new file mode 100644 index 000000000..afd73770e --- /dev/null +++ b/crates/brk_computer/src/internal/from_height/value/mod.rs @@ -0,0 +1,15 @@ +mod base; +mod change; +mod cumulative; +mod cumulative_sum; +mod full; +mod lazy; +mod rolling; + +pub use base::*; +pub use change::*; +pub use cumulative::*; +pub use cumulative_sum::*; +pub use full::*; +pub use lazy::*; +pub use rolling::*; diff --git a/crates/brk_computer/src/internal/from_height/value_last_rolling.rs b/crates/brk_computer/src/internal/from_height/value/rolling.rs similarity index 71% rename from crates/brk_computer/src/internal/from_height/value_last_rolling.rs rename to crates/brk_computer/src/internal/from_height/value/rolling.rs index 6e4d6c967..2b92f16ee 100644 --- a/crates/brk_computer/src/internal/from_height/value_last_rolling.rs +++ b/crates/brk_computer/src/internal/from_height/value/rolling.rs @@ -1,7 +1,7 @@ //! Value type for Height + Rolling pattern. //! -//! Combines ValueFromHeight (sats/btc/usd per height, no period views) with -//! ValueFromHeightLastWindows (rolling sums across 4 windows). +//! Combines Value (sats/btc/usd per height, no period views) with +//! ValueFromHeightWindows (rolling sums across 4 windows). use brk_error::Result; use brk_traversable::Traversable; @@ -11,23 +11,23 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode}; use crate::{ indexes, - internal::{ValueFromHeightLastWindows, ValueFromHeight, WindowStarts}, + internal::{ValueFromHeightWindows, Value, WindowStarts}, prices, }; #[derive(Deref, DerefMut, Traversable)] -pub struct ValueFromHeightLastRolling { +pub struct ValueFromHeightRolling { #[deref] #[deref_mut] #[traversable(flatten)] - pub value: ValueFromHeight, + pub value: Value, #[traversable(flatten)] - pub rolling: ValueFromHeightLastWindows, + pub rolling: ValueFromHeightWindows, } const VERSION: Version = Version::ZERO; -impl ValueFromHeightLastRolling { +impl ValueFromHeightRolling { pub(crate) fn forced_import( db: &Database, name: &str, @@ -36,8 +36,8 @@ impl ValueFromHeightLastRolling { ) -> Result { let v = version + VERSION; Ok(Self { - value: ValueFromHeight::forced_import(db, name, v)?, - rolling: ValueFromHeightLastWindows::forced_import(db, name, v, indexes)?, + value: Value::forced_import(db, name, v)?, + rolling: ValueFromHeightWindows::forced_import(db, name, v, indexes)?, }) } diff --git a/crates/brk_computer/src/internal/height/mod.rs b/crates/brk_computer/src/internal/height/mod.rs deleted file mode 100644 index 4b0dae125..000000000 --- a/crates/brk_computer/src/internal/height/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod lazy_value; -mod value; - -pub use lazy_value::*; -pub use value::*; diff --git a/crates/brk_computer/src/internal/height_derived/cumulative_full.rs b/crates/brk_computer/src/internal/height_derived/full.rs similarity index 72% rename from crates/brk_computer/src/internal/height_derived/cumulative_full.rs rename to crates/brk_computer/src/internal/height_derived/full.rs index 42f378e28..a3f1e814b 100644 --- a/crates/brk_computer/src/internal/height_derived/cumulative_full.rs +++ b/crates/brk_computer/src/internal/height_derived/full.rs @@ -1,7 +1,7 @@ -//! ComputedHeightDerivedCumulativeFull - LazyAggVec index views + cumulative (from height) + RollingFull. +//! ComputedHeightDerivedFull - LazyAggVec index views + cumulative (from height) + RollingFull. //! //! For metrics derived from indexer sources (no stored height vec). -//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views too. +//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too. use std::ops::SubAssign; @@ -13,22 +13,22 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; use crate::{ indexes, - internal::{ComputedFromHeightLast, NumericValue, RollingFull, WindowStarts}, + internal::{ComputedFromHeight, NumericValue, RollingFull, WindowStarts}, }; #[derive(Traversable)] -pub struct ComputedHeightDerivedCumulativeFull +pub struct ComputedHeightDerivedFull where T: NumericValue + JsonSchema, { - pub cumulative: ComputedFromHeightLast, + pub cumulative: ComputedFromHeight, #[traversable(flatten)] pub rolling: RollingFull, } const VERSION: Version = Version::ZERO; -impl ComputedHeightDerivedCumulativeFull +impl ComputedHeightDerivedFull where T: NumericValue + JsonSchema, { @@ -41,7 +41,7 @@ where let v = version + VERSION; let cumulative = - ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?; + ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?; let rolling = RollingFull::forced_import(db, name, v, indexes)?; Ok(Self { diff --git a/crates/brk_computer/src/internal/height_derived/last.rs b/crates/brk_computer/src/internal/height_derived/last.rs index 70a9f47ed..8e7666965 100644 --- a/crates/brk_computer/src/internal/height_derived/last.rs +++ b/crates/brk_computer/src/internal/height_derived/last.rs @@ -1,4 +1,4 @@ -//! ComputedHeightDerivedLast — sparse time periods + dense epochs (last value). +//! ComputedHeightDerived — sparse time periods + dense epochs (last value). use brk_traversable::Traversable; use brk_types::{ @@ -18,7 +18,7 @@ use crate::{ #[derive(Clone, Deref, DerefMut, Traversable)] #[traversable(transparent)] -pub struct ComputedHeightDerivedLast( +pub struct ComputedHeightDerived( #[allow(clippy::type_complexity)] pub Indexes< LazyAggVec, Height, Height, T>, @@ -42,7 +42,7 @@ where T: ComputedVecValue + PartialOrd + JsonSchema; /// Already read-only (no StorageMode); cloning is sufficient. -impl ReadOnlyClone for ComputedHeightDerivedLast +impl ReadOnlyClone for ComputedHeightDerived where T: ComputedVecValue + PartialOrd + JsonSchema, { @@ -54,7 +54,7 @@ where const VERSION: Version = Version::ZERO; -impl ComputedHeightDerivedLast +impl ComputedHeightDerived where T: NumericValue + JsonSchema, { diff --git a/crates/brk_computer/src/internal/height_derived/lazy_last.rs b/crates/brk_computer/src/internal/height_derived/lazy_last.rs index 7d774defa..a88ea31de 100644 --- a/crates/brk_computer/src/internal/height_derived/lazy_last.rs +++ b/crates/brk_computer/src/internal/height_derived/lazy_last.rs @@ -1,4 +1,4 @@ -//! LazyHeightDerivedLast — unary transform of height-derived last values. +//! LazyHeightDerived — unary transform of height-derived last values. use std::marker::PhantomData; @@ -16,7 +16,7 @@ use vecdb::{ use crate::{ indexes, indexes_from, internal::{ - ComputedFromHeightLast, ComputedHeightDerivedLast, ComputedVecValue, Indexes, NumericValue, + ComputedFromHeight, ComputedHeightDerived, ComputedVecValue, Indexes, NumericValue, }, }; @@ -57,7 +57,7 @@ where #[derive(Clone, Deref, DerefMut, Traversable)] #[traversable(transparent)] -pub struct LazyHeightDerivedLast( +pub struct LazyHeightDerived( #[allow(clippy::type_complexity)] pub Indexes< LazyTransformLast, Option>, @@ -83,7 +83,7 @@ where const VERSION: Version = Version::ZERO; -impl LazyHeightDerivedLast +impl LazyHeightDerived where T: VecValue + PartialOrd + JsonSchema + 'static, S1T: VecValue + PartialOrd + JsonSchema, @@ -91,7 +91,7 @@ where pub(crate) fn from_computed>( name: &str, version: Version, - source: &ComputedFromHeightLast, + source: &ComputedFromHeight, ) -> Self where S1T: NumericValue, @@ -109,14 +109,14 @@ where S1T: NumericValue, { let derived = - ComputedHeightDerivedLast::forced_import(name, height_source, version, indexes); + ComputedHeightDerived::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: &ComputedHeightDerivedLast, + source: &ComputedHeightDerived, ) -> Self where S1T: NumericValue, @@ -145,7 +145,7 @@ where pub(crate) fn from_lazy( name: &str, version: Version, - source: &LazyHeightDerivedLast, + source: &LazyHeightDerived, ) -> Self where F: UnaryTransform, diff --git a/crates/brk_computer/src/internal/height_derived/lazy_value_last.rs b/crates/brk_computer/src/internal/height_derived/lazy_value_last.rs index 98083d40c..56452bd89 100644 --- a/crates/brk_computer/src/internal/height_derived/lazy_value_last.rs +++ b/crates/brk_computer/src/internal/height_derived/lazy_value_last.rs @@ -4,48 +4,56 @@ use brk_traversable::Traversable; use brk_types::{Bitcoin, Cents, Dollars, Sats, Version}; use vecdb::UnaryTransform; -use crate::internal::{LazyHeightDerivedLast, ValueFromHeightLast}; +use crate::internal::{LazyHeightDerived, ValueFromHeight}; const VERSION: Version = Version::ZERO; #[derive(Clone, Traversable)] -pub struct LazyValueHeightDerivedLast { - pub sats: LazyHeightDerivedLast, - pub btc: LazyHeightDerivedLast, - pub usd: LazyHeightDerivedLast, +pub struct LazyValueHeightDerived { + pub sats: LazyHeightDerived, + pub btc: LazyHeightDerived, + pub cents: LazyHeightDerived, + pub usd: LazyHeightDerived, } -impl LazyValueHeightDerivedLast { - pub(crate) fn from_block_source( +impl LazyValueHeightDerived { + pub(crate) fn from_block_source( name: &str, - source: &ValueFromHeightLast, + source: &ValueFromHeight, version: Version, ) -> Self where SatsTransform: UnaryTransform, BitcoinTransform: UnaryTransform, + CentsTransform: UnaryTransform, DollarsTransform: UnaryTransform, { let v = version + VERSION; - let sats = LazyHeightDerivedLast::from_derived_computed::( + let sats = LazyHeightDerived::from_derived_computed::( name, v, &source.sats.rest, ); - let btc = LazyHeightDerivedLast::from_derived_computed::( + let btc = LazyHeightDerived::from_derived_computed::( &format!("{name}_btc"), v, &source.sats.rest, ); - let usd = LazyHeightDerivedLast::from_lazy::( + let cents = LazyHeightDerived::from_derived_computed::( + &format!("{name}_cents"), + v, + &source.cents.rest, + ); + + let usd = LazyHeightDerived::from_lazy::( &format!("{name}_usd"), v, &source.usd.rest, ); - Self { sats, btc, usd } + Self { sats, btc, cents, usd } } } diff --git a/crates/brk_computer/src/internal/height_derived/mod.rs b/crates/brk_computer/src/internal/height_derived/mod.rs index 6da4c3752..ded64d29d 100644 --- a/crates/brk_computer/src/internal/height_derived/mod.rs +++ b/crates/brk_computer/src/internal/height_derived/mod.rs @@ -1,9 +1,9 @@ -mod cumulative_full; +mod full; mod last; mod lazy_last; mod lazy_value_last; -pub use cumulative_full::*; +pub use full::*; pub use last::*; pub use lazy_last::*; pub use lazy_value_last::*; diff --git a/crates/brk_computer/src/internal/height/lazy_value.rs b/crates/brk_computer/src/internal/lazy_value.rs similarity index 57% rename from crates/brk_computer/src/internal/height/lazy_value.rs rename to crates/brk_computer/src/internal/lazy_value.rs index 4002641a9..6e5925fd0 100644 --- a/crates/brk_computer/src/internal/height/lazy_value.rs +++ b/crates/brk_computer/src/internal/lazy_value.rs @@ -1,10 +1,10 @@ -//! Fully lazy value type for Height indexing. +//! Fully lazy value type. use brk_traversable::Traversable; -use brk_types::{Bitcoin, Dollars, Height, Sats, Version}; -use vecdb::{ReadableCloneableVec, LazyVecFrom1, UnaryTransform}; +use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version}; +use vecdb::{ReadableCloneableVec, LazyVecFrom1, UnaryTransform, VecIndex}; -use crate::internal::ValueFromHeightLast; +use crate::internal::ValueFromHeight; const VERSION: Version = Version::ZERO; @@ -12,21 +12,23 @@ const VERSION: Version = Version::ZERO; /// /// All fields are lazy transforms from existing sources - no storage. #[derive(Clone, Traversable)] -pub struct LazyValueFromHeight { - pub sats: LazyVecFrom1, - pub btc: LazyVecFrom1, - pub usd: LazyVecFrom1, +pub struct LazyValue { + pub sats: LazyVecFrom1, + pub btc: LazyVecFrom1, + pub cents: LazyVecFrom1, + pub usd: LazyVecFrom1, } -impl LazyValueFromHeight { - pub(crate) fn from_block_source( +impl LazyValue { + pub(crate) fn from_block_source( name: &str, - source: &ValueFromHeightLast, + source: &ValueFromHeight, version: Version, ) -> Self where SatsTransform: UnaryTransform, BitcoinTransform: UnaryTransform, + CentsTransform: UnaryTransform, DollarsTransform: UnaryTransform, { let v = version + VERSION; @@ -40,12 +42,18 @@ impl LazyValueFromHeight { source.sats.height.read_only_boxed_clone(), ); + let cents = LazyVecFrom1::transformed::( + &format!("{name}_cents"), + v, + source.cents.height.read_only_boxed_clone(), + ); + let usd = LazyVecFrom1::transformed::( &format!("{name}_usd"), v, source.usd.height.read_only_boxed_clone(), ); - Self { sats, btc, usd } + Self { sats, btc, cents, usd } } } diff --git a/crates/brk_computer/src/internal/mod.rs b/crates/brk_computer/src/internal/mod.rs index f0b0ff69a..d315ef771 100644 --- a/crates/brk_computer/src/internal/mod.rs +++ b/crates/brk_computer/src/internal/mod.rs @@ -4,15 +4,16 @@ mod eager_indexes; mod from_height; mod from_tx; mod group; -mod height; mod height_derived; mod indexes; mod lazy_eager_indexes; +mod lazy_value; mod rolling; pub(crate) mod sliding_window; mod traits; mod transform; mod tx_derived; +mod value; mod vec; mod windows; @@ -22,13 +23,14 @@ pub(crate) use eager_indexes::*; pub(crate) use from_height::*; pub(crate) use from_tx::*; pub(crate) use group::*; -pub(crate) use height::*; pub(crate) use height_derived::*; pub(crate) use indexes::*; pub(crate) use lazy_eager_indexes::*; +pub(crate) use lazy_value::*; pub(crate) use rolling::*; pub(crate) use traits::*; pub use transform::*; pub(crate) use tx_derived::*; +pub(crate) use value::*; pub(crate) use vec::*; pub(crate) use windows::*; diff --git a/crates/brk_computer/src/internal/rolling/value_windows.rs b/crates/brk_computer/src/internal/rolling/value_windows.rs index dd8865cef..91c21251f 100644 --- a/crates/brk_computer/src/internal/rolling/value_windows.rs +++ b/crates/brk_computer/src/internal/rolling/value_windows.rs @@ -1,4 +1,4 @@ -//! ValueFromHeightLastWindows - window-first ordering. +//! ValueFromHeightWindows - window-first ordering. //! //! Access pattern: `coinbase_sum._24h.sats.height` //! Each window (24h, 7d, 30d, 1y) contains sats (stored) + btc (lazy) + usd (stored). @@ -14,21 +14,21 @@ use brk_types::{Cents, Sats}; use crate::{ indexes, - internal::{ValueFromHeightLast, WindowStarts, Windows}, + internal::{ValueFromHeight, WindowStarts, Windows}, }; const VERSION: Version = Version::ZERO; /// Value rolling windows — window-first, currency-last. /// -/// Each window contains `ValueFromHeightLast` (sats + btc lazy + usd). +/// Each window contains `ValueFromHeight` (sats + btc lazy + usd). #[derive(Deref, DerefMut, Traversable)] #[traversable(transparent)] -pub struct ValueFromHeightLastWindows( - pub Windows>, +pub struct ValueFromHeightWindows( + pub Windows>, ); -impl ValueFromHeightLastWindows { +impl ValueFromHeightWindows { pub(crate) fn forced_import( db: &Database, name: &str, @@ -37,25 +37,25 @@ impl ValueFromHeightLastWindows { ) -> Result { let v = version + VERSION; Ok(Self(Windows { - _24h: ValueFromHeightLast::forced_import( + _24h: ValueFromHeight::forced_import( db, &format!("{name}_24h"), v, indexes, )?, - _7d: ValueFromHeightLast::forced_import( + _7d: ValueFromHeight::forced_import( db, &format!("{name}_7d"), v, indexes, )?, - _30d: ValueFromHeightLast::forced_import( + _30d: ValueFromHeight::forced_import( db, &format!("{name}_30d"), v, indexes, )?, - _1y: ValueFromHeightLast::forced_import( + _1y: ValueFromHeight::forced_import( db, &format!("{name}_1y"), v, diff --git a/crates/brk_computer/src/internal/rolling/windows.rs b/crates/brk_computer/src/internal/rolling/windows.rs index c502a82fe..1beb5535c 100644 --- a/crates/brk_computer/src/internal/rolling/windows.rs +++ b/crates/brk_computer/src/internal/rolling/windows.rs @@ -1,4 +1,4 @@ -//! RollingWindows - newtype on Windows with ComputedFromHeightLast per window duration. +//! RollingWindows - newtype on Windows with ComputedFromHeight per window duration. //! //! Each of the 4 windows (24h, 7d, 30d, 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::{ComputedFromHeightLast, ComputedVecValue, NumericValue, Windows}, + internal::{ComputedFromHeight, ComputedVecValue, NumericValue, Windows}, }; /// Rolling window start heights — references to the 4 height-ago vecs. @@ -35,7 +35,7 @@ impl<'a> WindowStarts<'a> { /// 4 rolling window vecs (24h, 7d, 30d, 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; @@ -53,10 +53,10 @@ where ) -> Result { let v = version + VERSION; Ok(Self(Windows { - _24h: ComputedFromHeightLast::forced_import(db, &format!("{name}_24h"), v, indexes)?, - _7d: ComputedFromHeightLast::forced_import(db, &format!("{name}_7d"), v, indexes)?, - _30d: ComputedFromHeightLast::forced_import(db, &format!("{name}_30d"), v, indexes)?, - _1y: ComputedFromHeightLast::forced_import(db, &format!("{name}_1y"), v, indexes)?, + _24h: ComputedFromHeight::forced_import(db, &format!("{name}_24h"), v, indexes)?, + _7d: ComputedFromHeight::forced_import(db, &format!("{name}_7d"), v, indexes)?, + _30d: ComputedFromHeight::forced_import(db, &format!("{name}_30d"), v, indexes)?, + _1y: ComputedFromHeight::forced_import(db, &format!("{name}_1y"), v, indexes)?, })) } diff --git a/crates/brk_computer/src/internal/transform/cents_halve.rs b/crates/brk_computer/src/internal/transform/cents_halve.rs new file mode 100644 index 000000000..f5a204428 --- /dev/null +++ b/crates/brk_computer/src/internal/transform/cents_halve.rs @@ -0,0 +1,12 @@ +use brk_types::Cents; +use vecdb::UnaryTransform; + +/// Cents -> Cents/2 (for supply_halved_cents) +pub struct HalveCents; + +impl UnaryTransform for HalveCents { + #[inline(always)] + fn apply(cents: Cents) -> Cents { + cents / 2u64 + } +} diff --git a/crates/brk_computer/src/internal/transform/cents_identity.rs b/crates/brk_computer/src/internal/transform/cents_identity.rs new file mode 100644 index 000000000..f4c799fd1 --- /dev/null +++ b/crates/brk_computer/src/internal/transform/cents_identity.rs @@ -0,0 +1,12 @@ +use brk_types::Cents; +use vecdb::UnaryTransform; + +/// Cents -> Cents (identity transform for lazy references) +pub struct CentsIdentity; + +impl UnaryTransform for CentsIdentity { + #[inline(always)] + fn apply(cents: Cents) -> Cents { + cents + } +} diff --git a/crates/brk_computer/src/internal/transform/mod.rs b/crates/brk_computer/src/internal/transform/mod.rs index c4a60bd99..14fbf8840 100644 --- a/crates/brk_computer/src/internal/transform/mod.rs +++ b/crates/brk_computer/src/internal/transform/mod.rs @@ -1,4 +1,6 @@ mod block_count_target; +mod cents_halve; +mod cents_identity; mod cents_plus; mod cents_signed_to_dollars; mod cents_subtract_to_cents_signed; @@ -41,6 +43,8 @@ mod volatility_sqrt365; mod volatility_sqrt7; pub use block_count_target::*; +pub use cents_halve::*; +pub use cents_identity::*; pub use cents_plus::*; pub use cents_signed_to_dollars::*; pub use cents_subtract_to_cents_signed::*; diff --git a/crates/brk_computer/src/internal/height/value.rs b/crates/brk_computer/src/internal/value.rs similarity index 78% rename from crates/brk_computer/src/internal/height/value.rs rename to crates/brk_computer/src/internal/value.rs index e92d01728..7466ad9cf 100644 --- a/crates/brk_computer/src/internal/height/value.rs +++ b/crates/brk_computer/src/internal/value.rs @@ -1,6 +1,6 @@ //! Value type with height-level data only (no period-derived views). //! -//! Stores sats and cents per height, plus lazy btc and usd transforms. +//! Stores sats and cents per index, plus lazy btc and usd transforms. //! Use when period views are unnecessary (e.g., rolling windows provide windowed data). use brk_error::Result; @@ -8,22 +8,22 @@ use brk_traversable::Traversable; use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version}; use vecdb::{ Database, EagerVec, Exit, ImportableVec, LazyVecFrom1, PcoVec, ReadableCloneableVec, Rw, - StorageMode, + StorageMode, VecIndex, }; use crate::{internal::{CentsUnsignedToDollars, SatsToBitcoin, SatsToCents}, prices}; -const VERSION: Version = Version::TWO; // Match ValueFromHeightLast versioning +const VERSION: Version = Version::TWO; // Match ValueFromHeight versioning #[derive(Traversable)] -pub struct ValueFromHeight { - pub sats: M::Stored>>, - pub btc: LazyVecFrom1, - pub cents: M::Stored>>, - pub usd: LazyVecFrom1, +pub struct Value { + pub sats: M::Stored>>, + pub btc: LazyVecFrom1, + pub cents: M::Stored>>, + pub usd: LazyVecFrom1, } -impl ValueFromHeight { +impl Value { pub(crate) fn forced_import( db: &Database, name: &str, diff --git a/crates/brk_computer/src/market/ath/import.rs b/crates/brk_computer/src/market/ath/import.rs index a486217a0..c8d205eac 100644 --- a/crates/brk_computer/src/market/ath/import.rs +++ b/crates/brk_computer/src/market/ath/import.rs @@ -6,7 +6,7 @@ use super::Vecs; use crate::{ indexes, internal::{ - ComputedFromHeightLast, LazyHeightDerivedLast, + ComputedFromHeight, LazyHeightDerived, Price, StoredU16ToYears, }, }; @@ -19,7 +19,7 @@ impl Vecs { ) -> Result { let price_ath = Price::forced_import(db, "price_ath", version, indexes)?; - let max_days_between_price_aths = ComputedFromHeightLast::forced_import( + let max_days_between_price_aths = ComputedFromHeight::forced_import( db, "max_days_between_price_aths", version, @@ -27,23 +27,23 @@ impl Vecs { )?; let max_years_between_price_aths = - LazyHeightDerivedLast::from_computed::( + LazyHeightDerived::from_computed::( "max_years_between_price_aths", version, &max_days_between_price_aths, ); let days_since_price_ath = - ComputedFromHeightLast::forced_import(db, "days_since_price_ath", version, indexes)?; + ComputedFromHeight::forced_import(db, "days_since_price_ath", version, indexes)?; - let years_since_price_ath = LazyHeightDerivedLast::from_computed::( + let years_since_price_ath = LazyHeightDerived::from_computed::( "years_since_price_ath", version, &days_since_price_ath, ); let price_drawdown = - ComputedFromHeightLast::forced_import(db, "price_drawdown", version, indexes)?; + ComputedFromHeight::forced_import(db, "price_drawdown", version, 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 845115495..7c69bd681 100644 --- a/crates/brk_computer/src/market/ath/vecs.rs +++ b/crates/brk_computer/src/market/ath/vecs.rs @@ -2,15 +2,15 @@ use brk_traversable::Traversable; use brk_types::{Cents, StoredF32, StoredU16}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeightLast, LazyHeightDerivedLast, Price}; +use crate::internal::{ComputedFromHeight, LazyHeightDerived, Price}; /// All-time high related metrics #[derive(Traversable)] pub struct Vecs { - pub price_ath: Price>, - pub price_drawdown: ComputedFromHeightLast, - pub days_since_price_ath: ComputedFromHeightLast, - pub years_since_price_ath: LazyHeightDerivedLast, - pub max_days_between_price_aths: ComputedFromHeightLast, - pub max_years_between_price_aths: LazyHeightDerivedLast, + pub price_ath: Price>, + pub price_drawdown: ComputedFromHeight, + pub days_since_price_ath: ComputedFromHeight, + pub years_since_price_ath: LazyHeightDerived, + pub max_days_between_price_aths: ComputedFromHeight, + pub max_years_between_price_aths: LazyHeightDerived, } diff --git a/crates/brk_computer/src/market/dca/compute.rs b/crates/brk_computer/src/market/dca/compute.rs index 26c78fb0b..54aea1ac3 100644 --- a/crates/brk_computer/src/market/dca/compute.rs +++ b/crates/brk_computer/src/market/dca/compute.rs @@ -5,7 +5,7 @@ use vecdb::{AnyVec, EagerVec, Exit, ReadableOptionVec, ReadableVec, PcoVec, PcoV use super::{ByDcaClass, ByDcaPeriod, Vecs}; use crate::{ ComputeIndexes, blocks, indexes, - internal::{ComputedFromHeightLast, PercentageDiffCents}, + internal::{ComputedFromHeight, PercentageDiffCents}, market::lookback, prices, }; @@ -300,11 +300,11 @@ fn sats_from_dca(price: Dollars) -> Sats { #[allow(clippy::too_many_arguments)] fn compute_period_rolling( - days_in_profit: &mut ByDcaPeriod>, - days_in_loss: &mut ByDcaPeriod>, - min_return: &mut ByDcaPeriod>, - max_return: &mut ByDcaPeriod>, - returns: &ByDcaPeriod>, + days_in_profit: &mut ByDcaPeriod>, + days_in_loss: &mut ByDcaPeriod>, + min_return: &mut ByDcaPeriod>, + max_return: &mut ByDcaPeriod>, + returns: &ByDcaPeriod>, blocks: &blocks::Vecs, h2d: &EagerVec>, starting_indexes: &ComputeIndexes, @@ -355,11 +355,11 @@ fn compute_period_rolling( #[allow(clippy::too_many_arguments)] fn compute_class_cumulative( - days_in_profit: &mut ByDcaClass>, - days_in_loss: &mut ByDcaClass>, - min_return: &mut ByDcaClass>, - max_return: &mut ByDcaClass>, - returns: &ByDcaClass>, + days_in_profit: &mut ByDcaClass>, + days_in_loss: &mut ByDcaClass>, + min_return: &mut ByDcaClass>, + max_return: &mut ByDcaClass>, + returns: &ByDcaClass>, h2d: &EagerVec>, starting_indexes: &ComputeIndexes, exit: &Exit, diff --git a/crates/brk_computer/src/market/dca/import.rs b/crates/brk_computer/src/market/dca/import.rs index a3879d81b..6b3f82b16 100644 --- a/crates/brk_computer/src/market/dca/import.rs +++ b/crates/brk_computer/src/market/dca/import.rs @@ -6,8 +6,8 @@ use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod, Vecs}; use crate::{ indexes, internal::{ - ComputedFromHeightLast, Price, - ValueFromHeightLast, + ComputedFromHeight, Price, + ValueFromHeight, }, }; @@ -19,7 +19,7 @@ impl Vecs { ) -> Result { // DCA by period - stack (KISS) let period_stack = ByDcaPeriod::try_new(|name, _days| { - ValueFromHeightLast::forced_import( + ValueFromHeight::forced_import( db, &format!("{name}_dca_stack"), version, @@ -38,7 +38,7 @@ impl Vecs { })?; let period_returns = ByDcaPeriod::try_new(|name, _days| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_dca_returns"), version, @@ -48,12 +48,12 @@ impl Vecs { // DCA by period - CAGR let period_cagr = ByDcaCagr::try_new(|name, _days| { - ComputedFromHeightLast::forced_import(db, &format!("{name}_dca_cagr"), version, indexes) + ComputedFromHeight::forced_import(db, &format!("{name}_dca_cagr"), version, indexes) })?; // DCA by period - profitability let period_days_in_profit = ByDcaPeriod::try_new(|name, _days| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_dca_days_in_profit"), version + Version::ONE, @@ -62,7 +62,7 @@ impl Vecs { })?; let period_days_in_loss = ByDcaPeriod::try_new(|name, _days| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_dca_days_in_loss"), version + Version::ONE, @@ -71,7 +71,7 @@ impl Vecs { })?; let period_min_return = ByDcaPeriod::try_new(|name, _days| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_dca_min_return"), version, @@ -80,7 +80,7 @@ impl Vecs { })?; let period_max_return = ByDcaPeriod::try_new(|name, _days| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_dca_max_return"), version, @@ -90,7 +90,7 @@ impl Vecs { // Lump sum by period - stack (KISS) let period_lump_sum_stack = ByDcaPeriod::try_new(|name, _days| { - ValueFromHeightLast::forced_import( + ValueFromHeight::forced_import( db, &format!("{name}_lump_sum_stack"), version, @@ -100,7 +100,7 @@ impl Vecs { // Lump sum by period - returns let period_lump_sum_returns = ByDcaPeriod::try_new(|name, _days| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_lump_sum_returns"), version, @@ -110,7 +110,7 @@ impl Vecs { // Lump sum by period - profitability let period_lump_sum_days_in_profit = ByDcaPeriod::try_new(|name, _days| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_lump_sum_days_in_profit"), version + Version::ONE, @@ -119,7 +119,7 @@ impl Vecs { })?; let period_lump_sum_days_in_loss = ByDcaPeriod::try_new(|name, _days| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_lump_sum_days_in_loss"), version + Version::ONE, @@ -128,7 +128,7 @@ impl Vecs { })?; let period_lump_sum_min_return = ByDcaPeriod::try_new(|name, _days| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_lump_sum_min_return"), version, @@ -137,7 +137,7 @@ impl Vecs { })?; let period_lump_sum_max_return = ByDcaPeriod::try_new(|name, _days| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_lump_sum_max_return"), version, @@ -147,7 +147,7 @@ impl Vecs { // DCA by year class - stack (KISS) let class_stack = ByDcaClass::try_new(|name, _year, _day1| { - ValueFromHeightLast::forced_import( + ValueFromHeight::forced_import( db, &format!("{name}_stack"), version, @@ -161,7 +161,7 @@ impl Vecs { })?; let class_returns = ByDcaClass::try_new(|name, _year, _day1| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_returns"), version, @@ -171,7 +171,7 @@ impl Vecs { // DCA by year class - profitability let class_days_in_profit = ByDcaClass::try_new(|name, _year, _day1| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_days_in_profit"), version, @@ -180,7 +180,7 @@ impl Vecs { })?; let class_days_in_loss = ByDcaClass::try_new(|name, _year, _day1| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_days_in_loss"), version, @@ -189,11 +189,11 @@ impl Vecs { })?; let class_min_return = ByDcaClass::try_new(|name, _year, _day1| { - ComputedFromHeightLast::forced_import(db, &format!("{name}_min_return"), version, indexes) + ComputedFromHeight::forced_import(db, &format!("{name}_min_return"), version, indexes) })?; let class_max_return = ByDcaClass::try_new(|name, _year, _day1| { - ComputedFromHeightLast::forced_import(db, &format!("{name}_max_return"), version, indexes) + ComputedFromHeight::forced_import(db, &format!("{name}_max_return"), 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 50919b932..5e6ab962c 100644 --- a/crates/brk_computer/src/market/dca/vecs.rs +++ b/crates/brk_computer/src/market/dca/vecs.rs @@ -4,7 +4,7 @@ use vecdb::{EagerVec, PcoVec, Rw, StorageMode}; use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod}; use crate::internal::{ - ComputedFromHeightLast, Price, ValueFromHeightLast, + ComputedFromHeight, Price, ValueFromHeight, }; /// Dollar-cost averaging metrics by time period and year class @@ -15,35 +15,35 @@ pub struct Vecs { pub dca_sats_per_day: M::Stored>>, // DCA by period - KISS types - pub period_stack: ByDcaPeriod>, - pub period_average_price: ByDcaPeriod>>, - pub period_returns: ByDcaPeriod>, - pub period_cagr: ByDcaCagr>, + pub period_stack: ByDcaPeriod>, + pub period_average_price: ByDcaPeriod>>, + pub period_returns: ByDcaPeriod>, + pub period_cagr: ByDcaCagr>, // DCA by period - profitability - pub period_days_in_profit: ByDcaPeriod>, - pub period_days_in_loss: ByDcaPeriod>, - pub period_min_return: ByDcaPeriod>, - pub period_max_return: ByDcaPeriod>, + pub period_days_in_profit: ByDcaPeriod>, + pub period_days_in_loss: ByDcaPeriod>, + pub period_min_return: ByDcaPeriod>, + pub period_max_return: ByDcaPeriod>, // Lump sum by period (for comparison with DCA) - KISS types - pub period_lump_sum_stack: ByDcaPeriod>, - pub period_lump_sum_returns: ByDcaPeriod>, + pub period_lump_sum_stack: ByDcaPeriod>, + pub period_lump_sum_returns: ByDcaPeriod>, // Lump sum by period - profitability - pub period_lump_sum_days_in_profit: ByDcaPeriod>, - pub period_lump_sum_days_in_loss: ByDcaPeriod>, - pub period_lump_sum_min_return: ByDcaPeriod>, - pub period_lump_sum_max_return: ByDcaPeriod>, + pub period_lump_sum_days_in_profit: ByDcaPeriod>, + pub period_lump_sum_days_in_loss: ByDcaPeriod>, + pub period_lump_sum_min_return: ByDcaPeriod>, + pub period_lump_sum_max_return: ByDcaPeriod>, // DCA by year class - KISS types - pub class_stack: ByDcaClass>, - pub class_average_price: ByDcaClass>>, - pub class_returns: ByDcaClass>, + pub class_stack: ByDcaClass>, + pub class_average_price: ByDcaClass>>, + pub class_returns: ByDcaClass>, // DCA by year class - profitability - pub class_days_in_profit: ByDcaClass>, - pub class_days_in_loss: ByDcaClass>, - pub class_min_return: ByDcaClass>, - pub class_max_return: ByDcaClass>, + pub class_days_in_profit: ByDcaClass>, + pub class_days_in_loss: ByDcaClass>, + pub class_min_return: ByDcaClass>, + pub class_max_return: ByDcaClass>, } diff --git a/crates/brk_computer/src/market/indicators/gini.rs b/crates/brk_computer/src/market/indicators/gini.rs index 2d456a4fc..075fc8fb8 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::{Day1, Sats, StoredF32, StoredU64, Version}; use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableOptionVec, VecIndex, WritableVec}; -use crate::{ComputeIndexes, distribution, internal::ComputedFromHeightLast}; +use crate::{ComputeIndexes, distribution, internal::ComputedFromHeight}; pub(super) fn compute( - gini: &mut ComputedFromHeightLast, + gini: &mut ComputedFromHeight, distribution: &distribution::Vecs, h2d: &[Day1], total_heights: usize, diff --git a/crates/brk_computer/src/market/indicators/import.rs b/crates/brk_computer/src/market/indicators/import.rs index d81fa1dc1..2f0f7fe47 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::{ByIndicatorTimeframe, MacdChain, RsiChain, Vecs}; use crate::{ indexes, - internal::ComputedFromHeightLast, + internal::ComputedFromHeight, }; const VERSION: Version = Version::ONE; @@ -19,7 +19,7 @@ impl RsiChain { ) -> Result { macro_rules! import { ($name:expr) => { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("rsi_{}_{}", $name, tf), version, @@ -31,7 +31,7 @@ impl RsiChain { let average_gain = import!("avg_gain"); let average_loss = import!("avg_loss"); - let rsi = ComputedFromHeightLast::forced_import( + let rsi = ComputedFromHeight::forced_import( db, &format!("rsi_{tf}"), version, @@ -60,20 +60,20 @@ impl MacdChain { version: Version, indexes: &indexes::Vecs, ) -> Result { - let line = ComputedFromHeightLast::forced_import( + let line = ComputedFromHeight::forced_import( db, &format!("macd_line_{tf}"), version, indexes, )?; - let signal = ComputedFromHeightLast::forced_import( + let signal = ComputedFromHeight::forced_import( db, &format!("macd_signal_{tf}"), version, indexes, )?; - let histogram = ComputedFromHeightLast::forced_import( + let histogram = ComputedFromHeight::forced_import( db, &format!("macd_histogram_{tf}"), version, @@ -96,19 +96,19 @@ impl Vecs { ) -> Result { let v = version + VERSION; - let nvt = ComputedFromHeightLast::forced_import(db, "nvt", v, indexes)?; + let nvt = ComputedFromHeight::forced_import(db, "nvt", v, indexes)?; let rsi = ByIndicatorTimeframe::try_new(|tf| RsiChain::forced_import(db, tf, v, indexes))?; let macd = ByIndicatorTimeframe::try_new(|tf| MacdChain::forced_import(db, tf, v, indexes))?; - let stoch_k = ComputedFromHeightLast::forced_import(db, "stoch_k", v, indexes)?; - let stoch_d = ComputedFromHeightLast::forced_import(db, "stoch_d", v, indexes)?; - let gini = ComputedFromHeightLast::forced_import(db, "gini", v, indexes)?; + let stoch_k = ComputedFromHeight::forced_import(db, "stoch_k", v, indexes)?; + let stoch_d = ComputedFromHeight::forced_import(db, "stoch_d", v, indexes)?; + let gini = ComputedFromHeight::forced_import(db, "gini", v, indexes)?; - let pi_cycle = ComputedFromHeightLast::forced_import(db, "pi_cycle", v, indexes)?; + let pi_cycle = ComputedFromHeight::forced_import(db, "pi_cycle", v, indexes)?; Ok(Self { - puell_multiple: ComputedFromHeightLast::forced_import(db, "puell_multiple", v, indexes)?, + puell_multiple: ComputedFromHeight::forced_import(db, "puell_multiple", v, indexes)?, nvt, rsi, stoch_k, diff --git a/crates/brk_computer/src/market/indicators/vecs.rs b/crates/brk_computer/src/market/indicators/vecs.rs index 18ae0d535..c7292db7b 100644 --- a/crates/brk_computer/src/market/indicators/vecs.rs +++ b/crates/brk_computer/src/market/indicators/vecs.rs @@ -2,7 +2,7 @@ use brk_traversable::Traversable; use brk_types::StoredF32; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedFromHeightLast; +use crate::internal::ComputedFromHeight; pub const TIMEFRAME_NAMES: [&str; 4] = ["1d", "1w", "1m", "1y"]; @@ -37,38 +37,38 @@ impl ByIndicatorTimeframe { #[derive(Traversable)] pub struct RsiChain { - pub gains: ComputedFromHeightLast, - pub losses: ComputedFromHeightLast, - pub average_gain: ComputedFromHeightLast, - pub average_loss: ComputedFromHeightLast, - pub rsi: ComputedFromHeightLast, - pub rsi_min: ComputedFromHeightLast, - pub rsi_max: ComputedFromHeightLast, - pub stoch_rsi: ComputedFromHeightLast, - pub stoch_rsi_k: ComputedFromHeightLast, - pub stoch_rsi_d: ComputedFromHeightLast, + pub gains: ComputedFromHeight, + pub losses: ComputedFromHeight, + pub average_gain: ComputedFromHeight, + pub average_loss: ComputedFromHeight, + pub rsi: ComputedFromHeight, + pub rsi_min: ComputedFromHeight, + pub rsi_max: ComputedFromHeight, + pub stoch_rsi: ComputedFromHeight, + pub stoch_rsi_k: ComputedFromHeight, + pub stoch_rsi_d: ComputedFromHeight, } #[derive(Traversable)] pub struct MacdChain { - pub line: ComputedFromHeightLast, - pub signal: ComputedFromHeightLast, - pub histogram: ComputedFromHeightLast, + pub line: ComputedFromHeight, + pub signal: ComputedFromHeight, + pub histogram: ComputedFromHeight, } #[derive(Traversable)] pub struct Vecs { - pub puell_multiple: ComputedFromHeightLast, - pub nvt: ComputedFromHeightLast, + pub puell_multiple: ComputedFromHeight, + pub nvt: ComputedFromHeight, pub rsi: ByIndicatorTimeframe>, - pub stoch_k: ComputedFromHeightLast, - pub stoch_d: ComputedFromHeightLast, + pub stoch_k: ComputedFromHeight, + pub stoch_d: ComputedFromHeight, - pub pi_cycle: ComputedFromHeightLast, + pub pi_cycle: ComputedFromHeight, pub macd: ByIndicatorTimeframe>, - pub gini: ComputedFromHeightLast, + pub gini: ComputedFromHeight, } diff --git a/crates/brk_computer/src/market/lookback/vecs.rs b/crates/brk_computer/src/market/lookback/vecs.rs index 4db2a476c..b90794df3 100644 --- a/crates/brk_computer/src/market/lookback/vecs.rs +++ b/crates/brk_computer/src/market/lookback/vecs.rs @@ -3,11 +3,11 @@ use brk_types::Cents; use vecdb::{Rw, StorageMode}; use super::ByLookbackPeriod; -use crate::internal::{ComputedFromHeightLast, Price}; +use crate::internal::{ComputedFromHeight, Price}; /// Price lookback metrics #[derive(Traversable)] pub struct Vecs { #[traversable(flatten)] - pub price_ago: ByLookbackPeriod>>, + pub price_ago: ByLookbackPeriod>>, } diff --git a/crates/brk_computer/src/market/moving_average/vecs.rs b/crates/brk_computer/src/market/moving_average/vecs.rs index fc3e9726d..46e35a0ac 100644 --- a/crates/brk_computer/src/market/moving_average/vecs.rs +++ b/crates/brk_computer/src/market/moving_average/vecs.rs @@ -2,7 +2,7 @@ use brk_traversable::Traversable; use brk_types::Cents; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeightPriceWithRatioExtended, LazyFromHeightLast, Price}; +use crate::internal::{ComputedFromHeightPriceWithRatioExtended, LazyFromHeight, Price}; /// Simple and exponential moving average metrics #[derive(Traversable)] @@ -41,7 +41,7 @@ pub struct Vecs { pub price_200w_ema: ComputedFromHeightPriceWithRatioExtended, pub price_4y_ema: ComputedFromHeightPriceWithRatioExtended, - pub price_200d_sma_x2_4: Price>, - pub price_200d_sma_x0_8: Price>, - pub price_350d_sma_x2: Price>, + pub price_200d_sma_x2_4: Price>, + pub price_200d_sma_x0_8: Price>, + pub price_350d_sma_x2: Price>, } diff --git a/crates/brk_computer/src/market/range/import.rs b/crates/brk_computer/src/market/range/import.rs index 169001f25..ebae058e8 100644 --- a/crates/brk_computer/src/market/range/import.rs +++ b/crates/brk_computer/src/market/range/import.rs @@ -3,7 +3,7 @@ use brk_types::Version; use vecdb::Database; use super::Vecs; -use crate::{indexes, internal::{ComputedFromHeightLast, Price}}; +use crate::{indexes, internal::{ComputedFromHeight, Price}}; impl Vecs { pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result { @@ -18,13 +18,13 @@ impl Vecs { price_1m_max: Price::forced_import(db, "price_1m_max", version + v1, indexes)?, price_1y_min: Price::forced_import(db, "price_1y_min", version + v1, indexes)?, price_1y_max: Price::forced_import(db, "price_1y_max", version + v1, indexes)?, - price_true_range: ComputedFromHeightLast::forced_import( + price_true_range: ComputedFromHeight::forced_import( db, "price_true_range", version + v1, indexes, )?, - price_true_range_2w_sum: ComputedFromHeightLast::forced_import( + price_true_range_2w_sum: ComputedFromHeight::forced_import( db, "price_true_range_2w_sum", version + v1, indexes, )?, - price_2w_choppiness_index: ComputedFromHeightLast::forced_import( + price_2w_choppiness_index: ComputedFromHeight::forced_import( db, "price_2w_choppiness_index", version + v1, indexes, )?, }) diff --git a/crates/brk_computer/src/market/range/vecs.rs b/crates/brk_computer/src/market/range/vecs.rs index c221402f0..bcaf330dd 100644 --- a/crates/brk_computer/src/market/range/vecs.rs +++ b/crates/brk_computer/src/market/range/vecs.rs @@ -2,20 +2,20 @@ use brk_traversable::Traversable; use brk_types::{Cents, StoredF32}; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeightLast, Price}; +use crate::internal::{ComputedFromHeight, Price}; /// Price range and choppiness metrics #[derive(Traversable)] pub struct Vecs { - pub price_1w_min: Price>, - pub price_1w_max: Price>, - pub price_2w_min: Price>, - pub price_2w_max: Price>, - pub price_1m_min: Price>, - pub price_1m_max: Price>, - pub price_1y_min: Price>, - pub price_1y_max: Price>, - pub price_true_range: ComputedFromHeightLast, - pub price_true_range_2w_sum: ComputedFromHeightLast, - pub price_2w_choppiness_index: ComputedFromHeightLast, + pub price_1w_min: Price>, + pub price_1w_max: Price>, + pub price_2w_min: Price>, + pub price_2w_max: Price>, + pub price_1m_min: Price>, + pub price_1m_max: Price>, + pub price_1y_min: Price>, + pub price_1y_max: Price>, + pub price_true_range: ComputedFromHeight, + pub price_true_range_2w_sum: ComputedFromHeight, + pub price_2w_choppiness_index: ComputedFromHeight, } diff --git a/crates/brk_computer/src/market/returns/import.rs b/crates/brk_computer/src/market/returns/import.rs index 4573ab7f4..2363a2dfb 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::ComputedFromHeightLast, + internal::ComputedFromHeight, internal::ComputedFromHeightStdDev, market::dca::ByDcaCagr, }; @@ -20,7 +20,7 @@ impl Vecs { let v1 = Version::ONE; let price_returns = ByLookbackPeriod::try_new(|name, _days| { - ComputedFromHeightLast::forced_import( + ComputedFromHeight::forced_import( db, &format!("{name}_price_returns"), version, @@ -30,7 +30,7 @@ impl Vecs { // CAGR (computed, 2y+ only) let cagr = ByDcaCagr::try_new(|name, _days| { - ComputedFromHeightLast::forced_import(db, &format!("{name}_cagr"), version, indexes) + ComputedFromHeight::forced_import(db, &format!("{name}_cagr"), version, indexes) })?; let _1d_returns_1w_sd = ComputedFromHeightStdDev::forced_import( diff --git a/crates/brk_computer/src/market/returns/vecs.rs b/crates/brk_computer/src/market/returns/vecs.rs index 272a5ddee..9ba9a11de 100644 --- a/crates/brk_computer/src/market/returns/vecs.rs +++ b/crates/brk_computer/src/market/returns/vecs.rs @@ -3,17 +3,17 @@ use brk_types::{Height, StoredF32}; use vecdb::{EagerVec, PcoVec, Rw, StorageMode}; use crate::{ - internal::{ComputedFromHeightLast, ComputedFromHeightStdDev}, + internal::{ComputedFromHeight, ComputedFromHeightStdDev}, market::{dca::ByDcaCagr, lookback::ByLookbackPeriod}, }; /// Price returns, CAGR, and returns standard deviation metrics #[derive(Traversable)] pub struct Vecs { - pub price_returns: ByLookbackPeriod>, + pub price_returns: ByLookbackPeriod>, // CAGR (computed from returns, 2y+ only) - pub cagr: ByDcaCagr>, + pub cagr: ByDcaCagr>, // Returns standard deviation (computed from 1d returns) pub _1d_returns_1w_sd: ComputedFromHeightStdDev, diff --git a/crates/brk_computer/src/market/volatility/import.rs b/crates/brk_computer/src/market/volatility/import.rs index a2554028f..c10bcbda1 100644 --- a/crates/brk_computer/src/market/volatility/import.rs +++ b/crates/brk_computer/src/market/volatility/import.rs @@ -6,7 +6,7 @@ use super::super::returns; use super::Vecs; use crate::indexes; use crate::internal::{ - ComputedFromHeightLast, LazyFromHeightLast, StoredF32TimesSqrt7, StoredF32TimesSqrt30, + ComputedFromHeight, LazyFromHeight, StoredF32TimesSqrt7, StoredF32TimesSqrt30, StoredF32TimesSqrt365, }; @@ -19,21 +19,21 @@ impl Vecs { ) -> Result { let v2 = Version::TWO; - let price_1w_volatility = LazyFromHeightLast::from_computed::( + let price_1w_volatility = LazyFromHeight::from_computed::( "price_1w_volatility", version + v2, returns._1d_returns_1w_sd.sd.height.read_only_boxed_clone(), &returns._1d_returns_1w_sd.sd, ); - let price_1m_volatility = LazyFromHeightLast::from_computed::( + let price_1m_volatility = LazyFromHeight::from_computed::( "price_1m_volatility", version + v2, returns._1d_returns_1m_sd.sd.height.read_only_boxed_clone(), &returns._1d_returns_1m_sd.sd, ); - let price_1y_volatility = LazyFromHeightLast::from_computed::( + let price_1y_volatility = LazyFromHeight::from_computed::( "price_1y_volatility", version + v2, returns._1d_returns_1y_sd.sd.height.read_only_boxed_clone(), @@ -41,18 +41,18 @@ impl Vecs { ); let sharpe_1w = - ComputedFromHeightLast::forced_import(db, "sharpe_1w", version + v2, indexes)?; + ComputedFromHeight::forced_import(db, "sharpe_1w", version + v2, indexes)?; let sharpe_1m = - ComputedFromHeightLast::forced_import(db, "sharpe_1m", version + v2, indexes)?; + ComputedFromHeight::forced_import(db, "sharpe_1m", version + v2, indexes)?; let sharpe_1y = - ComputedFromHeightLast::forced_import(db, "sharpe_1y", version + v2, indexes)?; + ComputedFromHeight::forced_import(db, "sharpe_1y", version + v2, indexes)?; let sortino_1w = - ComputedFromHeightLast::forced_import(db, "sortino_1w", version + v2, indexes)?; + ComputedFromHeight::forced_import(db, "sortino_1w", version + v2, indexes)?; let sortino_1m = - ComputedFromHeightLast::forced_import(db, "sortino_1m", version + v2, indexes)?; + ComputedFromHeight::forced_import(db, "sortino_1m", version + v2, indexes)?; let sortino_1y = - ComputedFromHeightLast::forced_import(db, "sortino_1y", version + v2, indexes)?; + ComputedFromHeight::forced_import(db, "sortino_1y", version + v2, indexes)?; Ok(Self { price_1w_volatility, diff --git a/crates/brk_computer/src/market/volatility/vecs.rs b/crates/brk_computer/src/market/volatility/vecs.rs index b5e5100c2..2b2ba6bd5 100644 --- a/crates/brk_computer/src/market/volatility/vecs.rs +++ b/crates/brk_computer/src/market/volatility/vecs.rs @@ -1,22 +1,22 @@ use brk_traversable::Traversable; use vecdb::{Rw, StorageMode}; -use crate::internal::{ComputedFromHeightLast, LazyFromHeightLast}; +use crate::internal::{ComputedFromHeight, LazyFromHeight}; use brk_types::StoredF32; /// Price volatility metrics (derived from returns standard deviation) #[derive(Traversable)] pub struct Vecs { - pub price_1w_volatility: LazyFromHeightLast, - pub price_1m_volatility: LazyFromHeightLast, - pub price_1y_volatility: LazyFromHeightLast, + pub price_1w_volatility: LazyFromHeight, + pub price_1m_volatility: LazyFromHeight, + pub price_1y_volatility: LazyFromHeight, - pub sharpe_1w: ComputedFromHeightLast, - pub sharpe_1m: ComputedFromHeightLast, - pub sharpe_1y: ComputedFromHeightLast, + pub sharpe_1w: ComputedFromHeight, + pub sharpe_1m: ComputedFromHeight, + pub sharpe_1y: ComputedFromHeight, - pub sortino_1w: ComputedFromHeightLast, - pub sortino_1m: ComputedFromHeightLast, - pub sortino_1y: ComputedFromHeightLast, + pub sortino_1w: ComputedFromHeight, + pub sortino_1m: ComputedFromHeight, + pub sortino_1y: ComputedFromHeight, } diff --git a/crates/brk_computer/src/mining/hashrate/import.rs b/crates/brk_computer/src/mining/hashrate/import.rs index f2e785736..f1c8a941e 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::ComputedFromHeightLast, + internal::ComputedFromHeight, }; impl Vecs { @@ -18,98 +18,98 @@ impl Vecs { let v5 = Version::new(5); Ok(Self { - hash_rate: ComputedFromHeightLast::forced_import(db, "hash_rate", version + v5, indexes)?, - hash_rate_1w_sma: ComputedFromHeightLast::forced_import( + hash_rate: ComputedFromHeight::forced_import(db, "hash_rate", version + v5, indexes)?, + hash_rate_1w_sma: ComputedFromHeight::forced_import( db, "hash_rate_1w_sma", version, indexes, )?, - hash_rate_1m_sma: ComputedFromHeightLast::forced_import( + hash_rate_1m_sma: ComputedFromHeight::forced_import( db, "hash_rate_1m_sma", version, indexes, )?, - hash_rate_2m_sma: ComputedFromHeightLast::forced_import( + hash_rate_2m_sma: ComputedFromHeight::forced_import( db, "hash_rate_2m_sma", version, indexes, )?, - hash_rate_1y_sma: ComputedFromHeightLast::forced_import( + hash_rate_1y_sma: ComputedFromHeight::forced_import( db, "hash_rate_1y_sma", version, indexes, )?, - hash_rate_ath: ComputedFromHeightLast::forced_import( + hash_rate_ath: ComputedFromHeight::forced_import( db, "hash_rate_ath", version, indexes, )?, - hash_rate_drawdown: ComputedFromHeightLast::forced_import( + hash_rate_drawdown: ComputedFromHeight::forced_import( db, "hash_rate_drawdown", version, indexes, )?, - hash_price_ths: ComputedFromHeightLast::forced_import( + hash_price_ths: ComputedFromHeight::forced_import( db, "hash_price_ths", version + v4, indexes, )?, - hash_price_ths_min: ComputedFromHeightLast::forced_import( + hash_price_ths_min: ComputedFromHeight::forced_import( db, "hash_price_ths_min", version + v4, indexes, )?, - hash_price_phs: ComputedFromHeightLast::forced_import( + hash_price_phs: ComputedFromHeight::forced_import( db, "hash_price_phs", version + v4, indexes, )?, - hash_price_phs_min: ComputedFromHeightLast::forced_import( + hash_price_phs_min: ComputedFromHeight::forced_import( db, "hash_price_phs_min", version + v4, indexes, )?, - hash_price_rebound: ComputedFromHeightLast::forced_import( + hash_price_rebound: ComputedFromHeight::forced_import( db, "hash_price_rebound", version + v4, indexes, )?, - hash_value_ths: ComputedFromHeightLast::forced_import( + hash_value_ths: ComputedFromHeight::forced_import( db, "hash_value_ths", version + v4, indexes, )?, - hash_value_ths_min: ComputedFromHeightLast::forced_import( + hash_value_ths_min: ComputedFromHeight::forced_import( db, "hash_value_ths_min", version + v4, indexes, )?, - hash_value_phs: ComputedFromHeightLast::forced_import( + hash_value_phs: ComputedFromHeight::forced_import( db, "hash_value_phs", version + v4, indexes, )?, - hash_value_phs_min: ComputedFromHeightLast::forced_import( + hash_value_phs_min: ComputedFromHeight::forced_import( db, "hash_value_phs_min", version + v4, indexes, )?, - hash_value_rebound: ComputedFromHeightLast::forced_import( + hash_value_rebound: ComputedFromHeight::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 f5249962b..1c5de513c 100644 --- a/crates/brk_computer/src/mining/hashrate/vecs.rs +++ b/crates/brk_computer/src/mining/hashrate/vecs.rs @@ -2,26 +2,26 @@ use brk_traversable::Traversable; use brk_types::{StoredF32, StoredF64}; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedFromHeightLast; +use crate::internal::ComputedFromHeight; /// Mining-related metrics: hash rate, hash price, hash value #[derive(Traversable)] pub struct Vecs { - pub hash_rate: ComputedFromHeightLast, - pub hash_rate_1w_sma: ComputedFromHeightLast, - pub hash_rate_1m_sma: ComputedFromHeightLast, - pub hash_rate_2m_sma: ComputedFromHeightLast, - pub hash_rate_1y_sma: ComputedFromHeightLast, - pub hash_rate_ath: ComputedFromHeightLast, - pub hash_rate_drawdown: ComputedFromHeightLast, - pub hash_price_ths: ComputedFromHeightLast, - pub hash_price_ths_min: ComputedFromHeightLast, - pub hash_price_phs: ComputedFromHeightLast, - pub hash_price_phs_min: ComputedFromHeightLast, - pub hash_price_rebound: ComputedFromHeightLast, - pub hash_value_ths: ComputedFromHeightLast, - pub hash_value_ths_min: ComputedFromHeightLast, - pub hash_value_phs: ComputedFromHeightLast, - pub hash_value_phs_min: ComputedFromHeightLast, - pub hash_value_rebound: ComputedFromHeightLast, + pub hash_rate: ComputedFromHeight, + pub hash_rate_1w_sma: ComputedFromHeight, + pub hash_rate_1m_sma: ComputedFromHeight, + pub hash_rate_2m_sma: ComputedFromHeight, + pub hash_rate_1y_sma: ComputedFromHeight, + pub hash_rate_ath: ComputedFromHeight, + pub hash_rate_drawdown: ComputedFromHeight, + 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: ComputedFromHeight, + 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: ComputedFromHeight, } diff --git a/crates/brk_computer/src/mining/rewards/import.rs b/crates/brk_computer/src/mining/rewards/import.rs index 5f2923131..4322b222f 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::{ - ComputedFromHeightLast, FiatFromHeightLast, ValueFromHeightFull, - ValueFromHeightSumCumulative, + ComputedFromHeight, FiatFromHeight, ValueFromHeightFull, + ValueFromHeightCumulativeSum, }, }; @@ -21,73 +21,73 @@ impl Vecs { coinbase: ValueFromHeightFull::forced_import(db, "coinbase", version, indexes)?, subsidy: ValueFromHeightFull::forced_import(db, "subsidy", version, indexes)?, fees: ValueFromHeightFull::forced_import(db, "fees", version, indexes)?, - unclaimed_rewards: ValueFromHeightSumCumulative::forced_import( + unclaimed_rewards: ValueFromHeightCumulativeSum::forced_import( db, "unclaimed_rewards", version, indexes, )?, - fee_dominance: ComputedFromHeightLast::forced_import( + fee_dominance: ComputedFromHeight::forced_import( db, "fee_dominance", version, indexes, )?, - fee_dominance_24h: ComputedFromHeightLast::forced_import( + fee_dominance_24h: ComputedFromHeight::forced_import( db, "fee_dominance_24h", version, indexes, )?, - fee_dominance_7d: ComputedFromHeightLast::forced_import( + fee_dominance_7d: ComputedFromHeight::forced_import( db, "fee_dominance_7d", version, indexes, )?, - fee_dominance_30d: ComputedFromHeightLast::forced_import( + fee_dominance_30d: ComputedFromHeight::forced_import( db, "fee_dominance_30d", version, indexes, )?, - fee_dominance_1y: ComputedFromHeightLast::forced_import( + fee_dominance_1y: ComputedFromHeight::forced_import( db, "fee_dominance_1y", version, indexes, )?, - subsidy_dominance: ComputedFromHeightLast::forced_import( + subsidy_dominance: ComputedFromHeight::forced_import( db, "subsidy_dominance", version, indexes, )?, - subsidy_dominance_24h: ComputedFromHeightLast::forced_import( + subsidy_dominance_24h: ComputedFromHeight::forced_import( db, "subsidy_dominance_24h", version, indexes, )?, - subsidy_dominance_7d: ComputedFromHeightLast::forced_import( + subsidy_dominance_7d: ComputedFromHeight::forced_import( db, "subsidy_dominance_7d", version, indexes, )?, - subsidy_dominance_30d: ComputedFromHeightLast::forced_import( + subsidy_dominance_30d: ComputedFromHeight::forced_import( db, "subsidy_dominance_30d", version, indexes, )?, - subsidy_dominance_1y: ComputedFromHeightLast::forced_import( + subsidy_dominance_1y: ComputedFromHeight::forced_import( db, "subsidy_dominance_1y", version, indexes, )?, - subsidy_usd_1y_sma: FiatFromHeightLast::forced_import( + subsidy_usd_1y_sma: FiatFromHeight::forced_import( db, "subsidy_usd_1y_sma", version, diff --git a/crates/brk_computer/src/mining/rewards/vecs.rs b/crates/brk_computer/src/mining/rewards/vecs.rs index 4849e18b1..3f204919d 100644 --- a/crates/brk_computer/src/mining/rewards/vecs.rs +++ b/crates/brk_computer/src/mining/rewards/vecs.rs @@ -3,8 +3,8 @@ use brk_types::{Cents, StoredF32}; use vecdb::{Rw, StorageMode}; use crate::internal::{ - ComputedFromHeightLast, FiatFromHeightLast, ValueFromHeightFull, - ValueFromHeightSumCumulative, + ComputedFromHeight, FiatFromHeight, ValueFromHeightFull, + ValueFromHeightCumulativeSum, }; /// Coinbase/subsidy/rewards metrics @@ -13,16 +13,16 @@ pub struct Vecs { pub coinbase: ValueFromHeightFull, pub subsidy: ValueFromHeightFull, pub fees: ValueFromHeightFull, - pub unclaimed_rewards: ValueFromHeightSumCumulative, - pub fee_dominance: ComputedFromHeightLast, - pub fee_dominance_24h: ComputedFromHeightLast, - pub fee_dominance_7d: ComputedFromHeightLast, - pub fee_dominance_30d: ComputedFromHeightLast, - pub fee_dominance_1y: ComputedFromHeightLast, - pub subsidy_dominance: ComputedFromHeightLast, - pub subsidy_dominance_24h: ComputedFromHeightLast, - pub subsidy_dominance_7d: ComputedFromHeightLast, - pub subsidy_dominance_30d: ComputedFromHeightLast, - pub subsidy_dominance_1y: ComputedFromHeightLast, - pub subsidy_usd_1y_sma: FiatFromHeightLast, + pub unclaimed_rewards: ValueFromHeightCumulativeSum, + pub fee_dominance: ComputedFromHeight, + pub fee_dominance_24h: ComputedFromHeight, + pub fee_dominance_7d: ComputedFromHeight, + pub fee_dominance_30d: ComputedFromHeight, + pub fee_dominance_1y: ComputedFromHeight, + pub subsidy_dominance: ComputedFromHeight, + pub subsidy_dominance_24h: ComputedFromHeight, + pub subsidy_dominance_7d: ComputedFromHeight, + pub subsidy_dominance_30d: ComputedFromHeight, + pub subsidy_dominance_1y: ComputedFromHeight, + pub subsidy_usd_1y_sma: FiatFromHeight, } diff --git a/crates/brk_computer/src/outputs/count/import.rs b/crates/brk_computer/src/outputs/count/import.rs index 6de78e46f..e9b36e7fe 100644 --- a/crates/brk_computer/src/outputs/count/import.rs +++ b/crates/brk_computer/src/outputs/count/import.rs @@ -5,14 +5,28 @@ use vecdb::Database; use super::Vecs; use crate::{ indexes, - internal::{ComputedFromHeightFull, ComputedFromHeightLast}, + internal::{ComputedFromHeightAggregated, ComputedFromHeight}, }; impl Vecs { - pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result { + pub(crate) fn forced_import( + db: &Database, + version: Version, + indexes: &indexes::Vecs, + ) -> Result { Ok(Self { - total_count: ComputedFromHeightFull::forced_import(db, "output_count", version, indexes)?, - utxo_count: ComputedFromHeightLast::forced_import(db, "exact_utxo_count", version, indexes)?, + total_count: ComputedFromHeightAggregated::forced_import( + db, + "output_count", + version, + indexes, + )?, + utxo_count: ComputedFromHeight::forced_import( + db, + "exact_utxo_count", + version, + indexes, + )?, }) } } diff --git a/crates/brk_computer/src/outputs/count/vecs.rs b/crates/brk_computer/src/outputs/count/vecs.rs index a27d2256f..c3807d151 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::{ComputedFromHeightFull, ComputedFromHeightLast}; +use crate::internal::{ComputedFromHeightAggregated, ComputedFromHeight}; #[derive(Traversable)] pub struct Vecs { - pub total_count: ComputedFromHeightFull, - pub utxo_count: ComputedFromHeightLast, + pub total_count: ComputedFromHeightAggregated, + pub utxo_count: ComputedFromHeight, } diff --git a/crates/brk_computer/src/pools/vecs.rs b/crates/brk_computer/src/pools/vecs.rs index f93d6d140..613af96ae 100644 --- a/crates/brk_computer/src/pools/vecs.rs +++ b/crates/brk_computer/src/pools/vecs.rs @@ -7,8 +7,8 @@ use crate::{ blocks, indexes::{self, ComputeIndexes}, internal::{ - ComputedFromHeightCumulativeSum, ComputedFromHeightLast, MaskSats, PercentageU32F32, - ValueFromHeightSumCumulative, + ComputedFromHeightCumulativeSum, ComputedFromHeight, MaskSats, PercentageU32F32, + ValueFromHeightCumulativeSum, }, mining, prices, }; @@ -18,21 +18,21 @@ pub struct Vecs { slug: PoolSlug, pub blocks_mined: ComputedFromHeightCumulativeSum, - pub blocks_mined_24h_sum: ComputedFromHeightLast, - pub blocks_mined_1w_sum: ComputedFromHeightLast, - pub blocks_mined_1m_sum: ComputedFromHeightLast, - pub blocks_mined_1y_sum: ComputedFromHeightLast, - pub subsidy: ValueFromHeightSumCumulative, - pub fee: ValueFromHeightSumCumulative, - pub coinbase: ValueFromHeightSumCumulative, - pub dominance: ComputedFromHeightLast, + pub blocks_mined_24h_sum: ComputedFromHeight, + pub blocks_mined_1w_sum: ComputedFromHeight, + pub blocks_mined_1m_sum: ComputedFromHeight, + pub blocks_mined_1y_sum: ComputedFromHeight, + pub subsidy: ValueFromHeightCumulativeSum, + pub fee: ValueFromHeightCumulativeSum, + pub coinbase: ValueFromHeightCumulativeSum, + pub dominance: ComputedFromHeight, - pub dominance_24h: ComputedFromHeightLast, - pub dominance_1w: ComputedFromHeightLast, - pub dominance_1m: ComputedFromHeightLast, - pub dominance_1y: ComputedFromHeightLast, - pub blocks_since_block: ComputedFromHeightLast, - pub days_since_block: ComputedFromHeightLast, + pub dominance_24h: ComputedFromHeight, + pub dominance_1w: ComputedFromHeight, + pub dominance_1m: ComputedFromHeight, + pub dominance_1y: ComputedFromHeight, + pub blocks_since_block: ComputedFromHeight, + pub days_since_block: ComputedFromHeight, } impl Vecs { @@ -52,25 +52,25 @@ impl Vecs { indexes, )?; - let blocks_mined_24h_sum = ComputedFromHeightLast::forced_import( + let blocks_mined_24h_sum = ComputedFromHeight::forced_import( db, &suffix("blocks_mined_24h_sum"), version, indexes, )?; - let blocks_mined_1w_sum = ComputedFromHeightLast::forced_import( + let blocks_mined_1w_sum = ComputedFromHeight::forced_import( db, &suffix("blocks_mined_1w_sum"), version, indexes, )?; - let blocks_mined_1m_sum = ComputedFromHeightLast::forced_import( + let blocks_mined_1m_sum = ComputedFromHeight::forced_import( db, &suffix("blocks_mined_1m_sum"), version, indexes, )?; - let blocks_mined_1y_sum = ComputedFromHeightLast::forced_import( + let blocks_mined_1y_sum = ComputedFromHeight::forced_import( db, &suffix("blocks_mined_1y_sum"), version, @@ -78,24 +78,24 @@ impl Vecs { )?; let subsidy = - ValueFromHeightSumCumulative::forced_import(db, &suffix("subsidy"), version, indexes)?; + ValueFromHeightCumulativeSum::forced_import(db, &suffix("subsidy"), version, indexes)?; let fee = - ValueFromHeightSumCumulative::forced_import(db, &suffix("fee"), version, indexes)?; + ValueFromHeightCumulativeSum::forced_import(db, &suffix("fee"), version, indexes)?; let coinbase = - ValueFromHeightSumCumulative::forced_import(db, &suffix("coinbase"), version, indexes)?; + ValueFromHeightCumulativeSum::forced_import(db, &suffix("coinbase"), version, indexes)?; let dominance = - ComputedFromHeightLast::forced_import(db, &suffix("dominance"), version, indexes)?; + ComputedFromHeight::forced_import(db, &suffix("dominance"), version, indexes)?; let dominance_24h = - ComputedFromHeightLast::forced_import(db, &suffix("dominance_24h"), version, indexes)?; + ComputedFromHeight::forced_import(db, &suffix("dominance_24h"), version, indexes)?; let dominance_1w = - ComputedFromHeightLast::forced_import(db, &suffix("dominance_1w"), version, indexes)?; + ComputedFromHeight::forced_import(db, &suffix("dominance_1w"), version, indexes)?; let dominance_1m = - ComputedFromHeightLast::forced_import(db, &suffix("dominance_1m"), version, indexes)?; + ComputedFromHeight::forced_import(db, &suffix("dominance_1m"), version, indexes)?; let dominance_1y = - ComputedFromHeightLast::forced_import(db, &suffix("dominance_1y"), version, indexes)?; + ComputedFromHeight::forced_import(db, &suffix("dominance_1y"), version, indexes)?; Ok(Self { dominance, @@ -112,13 +112,13 @@ impl Vecs { coinbase, subsidy, fee, - blocks_since_block: ComputedFromHeightLast::forced_import( + blocks_since_block: ComputedFromHeight::forced_import( db, &suffix("blocks_since_block"), version, indexes, )?, - days_since_block: ComputedFromHeightLast::forced_import( + days_since_block: ComputedFromHeight::forced_import( db, &suffix("days_since_block"), version, diff --git a/crates/brk_computer/src/prices/by_unit.rs b/crates/brk_computer/src/prices/by_unit.rs index a60044a4c..f257f15d4 100644 --- a/crates/brk_computer/src/prices/by_unit.rs +++ b/crates/brk_computer/src/prices/by_unit.rs @@ -3,8 +3,8 @@ use brk_types::{Cents, Dollars, OHLCCents, OHLCDollars, OHLCSats, Sats}; use vecdb::{Rw, StorageMode}; use crate::internal::{ - ComputedFromHeightLast, ComputedHeightDerivedLast, EagerIndexes, LazyEagerIndexes, - LazyFromHeightLast, + ComputedFromHeight, ComputedHeightDerived, EagerIndexes, LazyEagerIndexes, + LazyFromHeight, }; use super::ohlcs::{LazyOhlcVecs, OhlcVecs}; @@ -28,9 +28,9 @@ pub struct SplitIndexesByUnit { #[derive(Clone, Traversable)] pub struct SplitCloseByUnit { - pub cents: ComputedHeightDerivedLast, - pub usd: ComputedHeightDerivedLast, - pub sats: ComputedHeightDerivedLast, + pub cents: ComputedHeightDerived, + pub usd: ComputedHeightDerived, + pub sats: ComputedHeightDerived, } // ── OhlcByUnit ────────────────────────────────────────────────────── @@ -46,7 +46,7 @@ pub struct OhlcByUnit { #[derive(Traversable)] pub struct PriceByUnit { - pub cents: ComputedFromHeightLast, - pub usd: LazyFromHeightLast, - pub sats: LazyFromHeightLast, + pub cents: ComputedFromHeight, + pub usd: LazyFromHeight, + pub sats: LazyFromHeight, } diff --git a/crates/brk_computer/src/prices/mod.rs b/crates/brk_computer/src/prices/mod.rs index 63f9c03ff..d6c16e13d 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, PAGE_SIZE}; use crate::{ indexes, internal::{ - CentsUnsignedToDollars, CentsUnsignedToSats, ComputedFromHeightLast, - ComputedHeightDerivedLast, EagerIndexes, LazyEagerIndexes, LazyFromHeightLast, + CentsUnsignedToDollars, CentsUnsignedToSats, ComputedFromHeight, + ComputedHeightDerived, EagerIndexes, LazyEagerIndexes, LazyFromHeight, OhlcCentsToDollars, OhlcCentsToSats, }, }; @@ -65,13 +65,13 @@ impl Vecs { // ── Cents (eager, stored) ─────────────────────────────────── let price_cents = - ComputedFromHeightLast::forced_import(db, "price_cents", version, indexes)?; + ComputedFromHeight::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 = ComputedHeightDerivedLast::forced_import( + let close_cents = ComputedHeightDerived::forced_import( "price_close_cents", price_cents.height.read_only_boxed_clone(), version, @@ -82,7 +82,7 @@ impl Vecs { // ── USD (lazy from cents) ─────────────────────────────────── - let price_usd = LazyFromHeightLast::from_computed::( + let price_usd = LazyFromHeight::from_computed::( "price", version, price_cents.height.read_only_boxed_clone(), @@ -105,7 +105,7 @@ impl Vecs { &low_cents, ); - let close_usd = ComputedHeightDerivedLast::forced_import( + let close_usd = ComputedHeightDerived::forced_import( "price_close", price_usd.height.read_only_boxed_clone(), version, @@ -120,7 +120,7 @@ impl Vecs { // ── Sats (lazy from cents, high↔low swapped) ─────────────── - let price_sats = LazyFromHeightLast::from_computed::( + let price_sats = LazyFromHeight::from_computed::( "price_sats", version, price_cents.height.read_only_boxed_clone(), @@ -144,7 +144,7 @@ impl Vecs { &high_cents, ); - let close_sats = ComputedHeightDerivedLast::forced_import( + let close_sats = ComputedHeightDerived::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 62d6fbc72..bd99f951a 100644 --- a/crates/brk_computer/src/prices/ohlcs.rs +++ b/crates/brk_computer/src/prices/ohlcs.rs @@ -15,7 +15,7 @@ use vecdb::{ use crate::{ ComputeIndexes, indexes_apply, indexes_from, - internal::{ComputedHeightDerivedLast, EagerIndexes, Indexes}, + internal::{ComputedHeightDerived, EagerIndexes, Indexes}, }; // ── EagerOhlcIndexes ───────────────────────────────────────────────── @@ -71,7 +71,7 @@ impl OhlcVecs { open: &EagerIndexes, high: &EagerIndexes, low: &EagerIndexes, - close: &ComputedHeightDerivedLast, + close: &ComputedHeightDerived, exit: &Exit, ) -> Result<()> { macro_rules! period { diff --git a/crates/brk_computer/src/scripts/adoption.rs b/crates/brk_computer/src/scripts/adoption.rs index f7f468c99..43aea878d 100644 --- a/crates/brk_computer/src/scripts/adoption.rs +++ b/crates/brk_computer/src/scripts/adoption.rs @@ -3,14 +3,14 @@ use brk_traversable::Traversable; use brk_types::{StoredF32, Version}; use vecdb::{Database, Exit, Rw, StorageMode}; -use crate::{ComputeIndexes, indexes, internal::{ComputedFromHeightLast, RatioU64F32}, outputs}; +use crate::{ComputeIndexes, indexes, internal::{ComputedFromHeight, RatioU64F32}, outputs}; use super::count::Vecs as CountVecs; #[derive(Traversable)] pub struct Vecs { - pub taproot: ComputedFromHeightLast, - pub segwit: ComputedFromHeightLast, + pub taproot: ComputedFromHeight, + pub segwit: ComputedFromHeight, } impl Vecs { @@ -20,13 +20,13 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - taproot: ComputedFromHeightLast::forced_import( + taproot: ComputedFromHeight::forced_import( db, "taproot_adoption", version, indexes, )?, - segwit: ComputedFromHeightLast::forced_import(db, "segwit_adoption", version, indexes)?, + segwit: ComputedFromHeight::forced_import(db, "segwit_adoption", version, indexes)?, }) } diff --git a/crates/brk_computer/src/supply/burned/import.rs b/crates/brk_computer/src/supply/burned/import.rs index 43e5f5f79..d884c5795 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::ValueFromHeightSumCumulative}; +use crate::{indexes, internal::ValueFromHeightCumulativeSum}; impl Vecs { pub(crate) fn forced_import( @@ -12,13 +12,13 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - opreturn: ValueFromHeightSumCumulative::forced_import( + opreturn: ValueFromHeightCumulativeSum::forced_import( db, "opreturn_supply", version, indexes, )?, - unspendable: ValueFromHeightSumCumulative::forced_import( + unspendable: ValueFromHeightCumulativeSum::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 120a32d8b..3f21fff21 100644 --- a/crates/brk_computer/src/supply/burned/vecs.rs +++ b/crates/brk_computer/src/supply/burned/vecs.rs @@ -1,11 +1,11 @@ use brk_traversable::Traversable; use vecdb::{Rw, StorageMode}; -use crate::internal::ValueFromHeightSumCumulative; +use crate::internal::ValueFromHeightCumulativeSum; /// Burned/unspendable supply metrics #[derive(Traversable)] pub struct Vecs { - pub opreturn: ValueFromHeightSumCumulative, - pub unspendable: ValueFromHeightSumCumulative, + pub opreturn: ValueFromHeightCumulativeSum, + pub unspendable: ValueFromHeightCumulativeSum, } diff --git a/crates/brk_computer/src/supply/import.rs b/crates/brk_computer/src/supply/import.rs index 98e4e76f7..8118829cf 100644 --- a/crates/brk_computer/src/supply/import.rs +++ b/crates/brk_computer/src/supply/import.rs @@ -9,7 +9,7 @@ use super::Vecs; use crate::{ distribution, indexes, internal::{ - ComputedFromHeightLast, DollarsIdentity, LazyFromHeightLast, LazyValueFromHeightLast, + CentsIdentity, ComputedFromHeight, DollarsIdentity, LazyFromHeight, LazyValueFromHeight, SatsIdentity, SatsToBitcoin, }, }; @@ -30,9 +30,10 @@ impl Vecs { let supply_metrics = &distribution.utxo_cohorts.all.metrics.supply; // Circulating supply - lazy refs to distribution - let circulating = LazyValueFromHeightLast::from_block_source::< + let circulating = LazyValueFromHeight::from_block_source::< SatsIdentity, SatsToBitcoin, + CentsIdentity, DollarsIdentity, >("circulating_supply", &supply_metrics.total, version); @@ -41,33 +42,33 @@ impl Vecs { // Inflation rate let inflation = - ComputedFromHeightLast::forced_import(&db, "inflation_rate", version, indexes)?; + ComputedFromHeight::forced_import(&db, "inflation_rate", version, indexes)?; // Velocity let velocity = super::velocity::Vecs::forced_import(&db, version, indexes)?; // Market cap - lazy identity from distribution supply in USD - let market_cap = LazyFromHeightLast::from_lazy::( + let market_cap = LazyFromHeight::from_lazy::( "market_cap", version, &supply_metrics.total.usd, ); // Growth rates - let market_cap_growth_rate = ComputedFromHeightLast::forced_import( + let market_cap_growth_rate = ComputedFromHeight::forced_import( &db, "market_cap_growth_rate", version + Version::ONE, indexes, )?; - let realized_cap_growth_rate = ComputedFromHeightLast::forced_import( + let realized_cap_growth_rate = ComputedFromHeight::forced_import( &db, "realized_cap_growth_rate", version + Version::ONE, indexes, )?; let cap_growth_rate_diff = - ComputedFromHeightLast::forced_import(&db, "cap_growth_rate_diff", version, indexes)?; + ComputedFromHeight::forced_import(&db, "cap_growth_rate_diff", version, indexes)?; let this = Self { db, diff --git a/crates/brk_computer/src/supply/vecs.rs b/crates/brk_computer/src/supply/vecs.rs index d1ce42640..fe405cdc3 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::{ - ComputedFromHeightLast, LazyFromHeightLast, LazyValueFromHeightLast, + ComputedFromHeight, LazyFromHeight, LazyValueFromHeight, }; #[derive(Traversable)] @@ -12,12 +12,12 @@ pub struct Vecs { #[traversable(skip)] pub(crate) db: Database, - pub circulating: LazyValueFromHeightLast, + pub circulating: LazyValueFromHeight, pub burned: burned::Vecs, - pub inflation: ComputedFromHeightLast, + pub inflation: ComputedFromHeight, pub velocity: velocity::Vecs, - pub market_cap: LazyFromHeightLast, - pub market_cap_growth_rate: ComputedFromHeightLast, - pub realized_cap_growth_rate: ComputedFromHeightLast, - pub cap_growth_rate_diff: ComputedFromHeightLast, + pub market_cap: LazyFromHeight, + pub market_cap_growth_rate: ComputedFromHeight, + pub realized_cap_growth_rate: ComputedFromHeight, + pub cap_growth_rate_diff: ComputedFromHeight, } diff --git a/crates/brk_computer/src/supply/velocity/import.rs b/crates/brk_computer/src/supply/velocity/import.rs index 4b09d7edb..c8d1e78d2 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::ComputedFromHeightLast}; +use crate::{indexes, internal::ComputedFromHeight}; impl Vecs { pub(crate) fn forced_import( @@ -12,8 +12,8 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - btc: ComputedFromHeightLast::forced_import(db, "btc_velocity", version, indexes)?, - usd: ComputedFromHeightLast::forced_import(db, "usd_velocity", version, indexes)?, + btc: ComputedFromHeight::forced_import(db, "btc_velocity", version, indexes)?, + usd: ComputedFromHeight::forced_import(db, "usd_velocity", version, indexes)?, }) } } diff --git a/crates/brk_computer/src/supply/velocity/vecs.rs b/crates/brk_computer/src/supply/velocity/vecs.rs index 96a49609b..46b1d87eb 100644 --- a/crates/brk_computer/src/supply/velocity/vecs.rs +++ b/crates/brk_computer/src/supply/velocity/vecs.rs @@ -2,11 +2,11 @@ use brk_traversable::Traversable; use brk_types::StoredF64; use vecdb::{Rw, StorageMode}; -use crate::internal::ComputedFromHeightLast; +use crate::internal::ComputedFromHeight; /// Velocity metrics (annualized volume / circulating supply) #[derive(Traversable)] pub struct Vecs { - pub btc: ComputedFromHeightLast, - pub usd: ComputedFromHeightLast, + pub btc: ComputedFromHeight, + pub usd: ComputedFromHeight, } diff --git a/crates/brk_computer/src/transactions/count/import.rs b/crates/brk_computer/src/transactions/count/import.rs index dfef04947..936519573 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::ComputedFromHeightCumulativeFull}; +use crate::{indexes, internal::ComputedFromHeightFull}; impl Vecs { pub(crate) fn forced_import( @@ -24,7 +24,7 @@ impl Vecs { ); Ok(Self { - tx_count: ComputedFromHeightCumulativeFull::forced_import( + tx_count: ComputedFromHeightFull::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 c20c29d87..d1291f7cc 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::ComputedFromHeightCumulativeFull; +use crate::internal::ComputedFromHeightFull; #[derive(Traversable)] pub struct Vecs { - pub tx_count: ComputedFromHeightCumulativeFull, + pub tx_count: ComputedFromHeightFull, pub is_coinbase: LazyVecFrom2, } diff --git a/crates/brk_computer/src/transactions/volume/import.rs b/crates/brk_computer/src/transactions/volume/import.rs index 856b6f900..bc5a5d588 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::{ComputedFromHeightLast, ValueFromHeightLast, ValueFromHeightLastRolling}, + internal::{ComputedFromHeight, ValueFromHeight, ValueFromHeightRolling}, }; impl Vecs { @@ -16,31 +16,31 @@ impl Vecs { ) -> Result { let v2 = Version::TWO; Ok(Self { - sent_sum: ValueFromHeightLastRolling::forced_import( + sent_sum: ValueFromHeightRolling::forced_import( db, "sent_sum", version, indexes, )?, - received_sum: ValueFromHeightLastRolling::forced_import( + received_sum: ValueFromHeightRolling::forced_import( db, "received_sum", version, indexes, )?, - annualized_volume: ValueFromHeightLast::forced_import( + annualized_volume: ValueFromHeight::forced_import( db, "annualized_volume", version, indexes, )?, - tx_per_sec: ComputedFromHeightLast::forced_import( + tx_per_sec: ComputedFromHeight::forced_import( db, "tx_per_sec", version + v2, indexes, )?, - outputs_per_sec: ComputedFromHeightLast::forced_import( + outputs_per_sec: ComputedFromHeight::forced_import( db, "outputs_per_sec", version + v2, indexes, )?, - inputs_per_sec: ComputedFromHeightLast::forced_import( + inputs_per_sec: ComputedFromHeight::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 fbda9f1b9..4bb4218b2 100644 --- a/crates/brk_computer/src/transactions/volume/vecs.rs +++ b/crates/brk_computer/src/transactions/volume/vecs.rs @@ -3,16 +3,16 @@ use brk_types::StoredF32; use vecdb::{Rw, StorageMode}; use crate::internal::{ - ComputedFromHeightLast, ValueFromHeightLast, ValueFromHeightLastRolling, + ComputedFromHeight, ValueFromHeight, ValueFromHeightRolling, }; /// Volume metrics #[derive(Traversable)] pub struct Vecs { - pub sent_sum: ValueFromHeightLastRolling, - pub received_sum: ValueFromHeightLastRolling, - pub annualized_volume: ValueFromHeightLast, - pub tx_per_sec: ComputedFromHeightLast, - pub outputs_per_sec: ComputedFromHeightLast, - pub inputs_per_sec: ComputedFromHeightLast, + pub sent_sum: ValueFromHeightRolling, + pub received_sum: ValueFromHeightRolling, + pub annualized_volume: ValueFromHeight, + pub tx_per_sec: ComputedFromHeight, + pub outputs_per_sec: ComputedFromHeight, + pub inputs_per_sec: ComputedFromHeight, } diff --git a/modules/brk-client/index.js b/modules/brk-client/index.js index d4be4bc78..e6ace7d53 100644 --- a/modules/brk-client/index.js +++ b/modules/brk-client/index.js @@ -2647,23 +2647,23 @@ function createRatioPattern3(client, acc) { /** * @typedef {Object} GreedInvestedInvestorNegNetPainPeakSupplyTotalUnrealizedPattern - * @property {MetricPattern1} greedIndex - * @property {MetricPattern1} investedCapitalInLoss + * @property {CentsUsdPattern} greedIndex + * @property {CentsUsdPattern} investedCapitalInLoss * @property {MetricPattern18} investedCapitalInLossRaw - * @property {MetricPattern1} investedCapitalInProfit + * @property {CentsUsdPattern} investedCapitalInProfit * @property {MetricPattern18} investedCapitalInProfitRaw * @property {MetricPattern18} investorCapInLossRaw * @property {MetricPattern18} investorCapInProfitRaw * @property {MetricPattern1} negUnrealizedLoss - * @property {MetricPattern1} netSentiment - * @property {MetricPattern1} netUnrealizedPnl - * @property {MetricPattern1} painIndex - * @property {MetricPattern1} peakRegret + * @property {CentsUsdPattern} netSentiment + * @property {CentsUsdPattern} netUnrealizedPnl + * @property {CentsUsdPattern} painIndex + * @property {CentsUsdPattern} peakRegret * @property {BtcCentsSatsUsdPattern} supplyInLoss * @property {BtcCentsSatsUsdPattern} supplyInProfit - * @property {MetricPattern1} totalUnrealizedPnl - * @property {MetricPattern1} unrealizedLoss - * @property {MetricPattern1} unrealizedProfit + * @property {CentsUsdPattern} totalUnrealizedPnl + * @property {CentsUsdPattern} unrealizedLoss + * @property {CentsUsdPattern} unrealizedProfit */ /** @@ -2674,44 +2674,44 @@ function createRatioPattern3(client, acc) { */ function createGreedInvestedInvestorNegNetPainPeakSupplyTotalUnrealizedPattern(client, acc) { return { - greedIndex: createMetricPattern1(client, _m(acc, 'greed_index')), - investedCapitalInLoss: createMetricPattern1(client, _m(acc, 'invested_capital_in_loss')), + greedIndex: createCentsUsdPattern(client, _m(acc, 'greed_index')), + investedCapitalInLoss: createCentsUsdPattern(client, _m(acc, 'invested_capital_in_loss')), investedCapitalInLossRaw: createMetricPattern18(client, _m(acc, 'invested_capital_in_loss_raw')), - investedCapitalInProfit: createMetricPattern1(client, _m(acc, 'invested_capital_in_profit')), + investedCapitalInProfit: createCentsUsdPattern(client, _m(acc, 'invested_capital_in_profit')), investedCapitalInProfitRaw: createMetricPattern18(client, _m(acc, 'invested_capital_in_profit_raw')), investorCapInLossRaw: createMetricPattern18(client, _m(acc, 'investor_cap_in_loss_raw')), investorCapInProfitRaw: createMetricPattern18(client, _m(acc, 'investor_cap_in_profit_raw')), negUnrealizedLoss: createMetricPattern1(client, _m(acc, 'neg_unrealized_loss')), - netSentiment: createMetricPattern1(client, _m(acc, 'net_sentiment')), - netUnrealizedPnl: createMetricPattern1(client, _m(acc, 'net_unrealized_pnl')), - painIndex: createMetricPattern1(client, _m(acc, 'pain_index')), - peakRegret: createMetricPattern1(client, _m(acc, 'unrealized_peak_regret')), + netSentiment: createCentsUsdPattern(client, _m(acc, 'net_sentiment')), + netUnrealizedPnl: createCentsUsdPattern(client, _m(acc, 'net_unrealized_pnl')), + painIndex: createCentsUsdPattern(client, _m(acc, 'pain_index')), + peakRegret: createCentsUsdPattern(client, _m(acc, 'unrealized_peak_regret')), supplyInLoss: createBtcCentsSatsUsdPattern(client, _m(acc, 'supply_in_loss')), supplyInProfit: createBtcCentsSatsUsdPattern(client, _m(acc, 'supply_in_profit')), - totalUnrealizedPnl: createMetricPattern1(client, _m(acc, 'total_unrealized_pnl')), - unrealizedLoss: createMetricPattern1(client, _m(acc, 'unrealized_loss')), - unrealizedProfit: createMetricPattern1(client, _m(acc, 'unrealized_profit')), + totalUnrealizedPnl: createCentsUsdPattern(client, _m(acc, 'total_unrealized_pnl')), + unrealizedLoss: createCentsUsdPattern(client, _m(acc, 'unrealized_loss')), + unrealizedProfit: createCentsUsdPattern(client, _m(acc, 'unrealized_profit')), }; } /** * @typedef {Object} GreedInvestedInvestorNegNetPainSupplyTotalUnrealizedPattern - * @property {MetricPattern1} greedIndex - * @property {MetricPattern1} investedCapitalInLoss + * @property {CentsUsdPattern} greedIndex + * @property {CentsUsdPattern} investedCapitalInLoss * @property {MetricPattern18} investedCapitalInLossRaw - * @property {MetricPattern1} investedCapitalInProfit + * @property {CentsUsdPattern} investedCapitalInProfit * @property {MetricPattern18} investedCapitalInProfitRaw * @property {MetricPattern18} investorCapInLossRaw * @property {MetricPattern18} investorCapInProfitRaw * @property {MetricPattern1} negUnrealizedLoss - * @property {MetricPattern1} netSentiment - * @property {MetricPattern1} netUnrealizedPnl - * @property {MetricPattern1} painIndex + * @property {CentsUsdPattern} netSentiment + * @property {CentsUsdPattern} netUnrealizedPnl + * @property {CentsUsdPattern} painIndex * @property {BtcCentsSatsUsdPattern} supplyInLoss * @property {BtcCentsSatsUsdPattern} supplyInProfit - * @property {MetricPattern1} totalUnrealizedPnl - * @property {MetricPattern1} unrealizedLoss - * @property {MetricPattern1} unrealizedProfit + * @property {CentsUsdPattern} totalUnrealizedPnl + * @property {CentsUsdPattern} unrealizedLoss + * @property {CentsUsdPattern} unrealizedProfit */ /** @@ -2722,22 +2722,22 @@ function createGreedInvestedInvestorNegNetPainPeakSupplyTotalUnrealizedPattern(c */ function createGreedInvestedInvestorNegNetPainSupplyTotalUnrealizedPattern(client, acc) { return { - greedIndex: createMetricPattern1(client, _m(acc, 'greed_index')), - investedCapitalInLoss: createMetricPattern1(client, _m(acc, 'invested_capital_in_loss')), + greedIndex: createCentsUsdPattern(client, _m(acc, 'greed_index')), + investedCapitalInLoss: createCentsUsdPattern(client, _m(acc, 'invested_capital_in_loss')), investedCapitalInLossRaw: createMetricPattern18(client, _m(acc, 'invested_capital_in_loss_raw')), - investedCapitalInProfit: createMetricPattern1(client, _m(acc, 'invested_capital_in_profit')), + investedCapitalInProfit: createCentsUsdPattern(client, _m(acc, 'invested_capital_in_profit')), investedCapitalInProfitRaw: createMetricPattern18(client, _m(acc, 'invested_capital_in_profit_raw')), investorCapInLossRaw: createMetricPattern18(client, _m(acc, 'investor_cap_in_loss_raw')), investorCapInProfitRaw: createMetricPattern18(client, _m(acc, 'investor_cap_in_profit_raw')), negUnrealizedLoss: createMetricPattern1(client, _m(acc, 'neg_unrealized_loss')), - netSentiment: createMetricPattern1(client, _m(acc, 'net_sentiment')), - netUnrealizedPnl: createMetricPattern1(client, _m(acc, 'net_unrealized_pnl')), - painIndex: createMetricPattern1(client, _m(acc, 'pain_index')), + netSentiment: createCentsUsdPattern(client, _m(acc, 'net_sentiment')), + netUnrealizedPnl: createCentsUsdPattern(client, _m(acc, 'net_unrealized_pnl')), + painIndex: createCentsUsdPattern(client, _m(acc, 'pain_index')), supplyInLoss: createBtcCentsSatsUsdPattern(client, _m(acc, 'supply_in_loss')), supplyInProfit: createBtcCentsSatsUsdPattern(client, _m(acc, 'supply_in_profit')), - totalUnrealizedPnl: createMetricPattern1(client, _m(acc, 'total_unrealized_pnl')), - unrealizedLoss: createMetricPattern1(client, _m(acc, 'unrealized_loss')), - unrealizedProfit: createMetricPattern1(client, _m(acc, 'unrealized_profit')), + totalUnrealizedPnl: createCentsUsdPattern(client, _m(acc, 'total_unrealized_pnl')), + unrealizedLoss: createCentsUsdPattern(client, _m(acc, 'unrealized_loss')), + unrealizedProfit: createCentsUsdPattern(client, _m(acc, 'unrealized_profit')), }; } @@ -3654,7 +3654,7 @@ function create_1y24h30d7dPattern(client, acc) { /** * @typedef {Object} _30dHalvedTotalPattern * @property {BtcCentsSatsUsdPattern} _30dChange - * @property {BtcSatsUsdPattern} halved + * @property {BtcCentsSatsUsdPattern} halved * @property {BtcCentsSatsUsdPattern} total */ @@ -3667,7 +3667,7 @@ function create_1y24h30d7dPattern(client, acc) { function create_30dHalvedTotalPattern(client, acc) { return { _30dChange: createBtcCentsSatsUsdPattern(client, _m(acc, '_30d_change')), - halved: createBtcSatsUsdPattern(client, _m(acc, 'supply_halved')), + halved: createBtcCentsSatsUsdPattern(client, _m(acc, 'supply_halved')), total: createBtcCentsSatsUsdPattern(client, _m(acc, 'supply')), }; } @@ -3693,27 +3693,6 @@ function createBaseCumulativeSumPattern(client, acc) { }; } -/** - * @typedef {Object} BtcSatsUsdPattern - * @property {MetricPattern1} btc - * @property {MetricPattern1} sats - * @property {MetricPattern1} usd - */ - -/** - * Create a BtcSatsUsdPattern pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {BtcSatsUsdPattern} - */ -function createBtcSatsUsdPattern(client, acc) { - return { - btc: createMetricPattern1(client, _m(acc, 'btc')), - sats: createMetricPattern1(client, acc), - usd: createMetricPattern1(client, _m(acc, 'usd')), - }; -} - /** * @typedef {Object} CentsSatsUsdPattern2 * @property {MetricPattern2} cents @@ -3861,6 +3840,25 @@ function createBaseCumulativePattern(client, acc) { }; } +/** + * @typedef {Object} CentsUsdPattern + * @property {MetricPattern1} cents + * @property {MetricPattern1} usd + */ + +/** + * Create a CentsUsdPattern pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {CentsUsdPattern} + */ +function createCentsUsdPattern(client, acc) { + return { + cents: createMetricPattern1(client, _m(acc, 'cents')), + usd: createMetricPattern1(client, _m(acc, 'usd')), + }; +} + /** * @typedef {Object} MaxMinPattern * @property {CentsSatsUsdPattern} max @@ -4264,7 +4262,7 @@ function createRatioPattern2(client, acc) { * @property {MetricPattern1} subsidyDominance7d * @property {MetricPattern1} subsidyDominance30d * @property {MetricPattern1} subsidyDominance1y - * @property {MetricPattern1} subsidyUsd1ySma + * @property {CentsUsdPattern} subsidyUsd1ySma */ /** @@ -4330,11 +4328,11 @@ function createRatioPattern2(client, acc) { /** * @typedef {Object} MetricsTree_Cointime_Cap - * @property {MetricPattern1} thermoCap - * @property {MetricPattern1} investorCap - * @property {MetricPattern1} vaultedCap - * @property {MetricPattern1} activeCap - * @property {MetricPattern1} cointimeCap + * @property {CentsUsdPattern} thermoCap + * @property {CentsUsdPattern} investorCap + * @property {CentsUsdPattern} vaultedCap + * @property {CentsUsdPattern} activeCap + * @property {CentsUsdPattern} cointimeCap */ /** @@ -5568,7 +5566,7 @@ function createRatioPattern2(client, acc) { /** * @typedef {Object} MetricsTree_Supply - * @property {BtcSatsUsdPattern} circulating + * @property {BtcCentsSatsUsdPattern} circulating * @property {MetricsTree_Supply_Burned} burned * @property {MetricPattern1} inflation * @property {MetricsTree_Supply_Velocity} velocity @@ -6753,7 +6751,7 @@ class BrkClient extends BrkClientBase { subsidyDominance7d: createMetricPattern1(this, 'subsidy_dominance_7d'), subsidyDominance30d: createMetricPattern1(this, 'subsidy_dominance_30d'), subsidyDominance1y: createMetricPattern1(this, 'subsidy_dominance_1y'), - subsidyUsd1ySma: createMetricPattern1(this, 'subsidy_usd_1y_sma'), + subsidyUsd1ySma: createCentsUsdPattern(this, 'subsidy_usd_1y_sma'), }, hashrate: { hashRate: createMetricPattern1(this, 'hash_rate'), @@ -6798,11 +6796,11 @@ class BrkClient extends BrkClientBase { vocdd: createCumulativeHeightSumPattern(this, 'vocdd'), }, cap: { - thermoCap: createMetricPattern1(this, 'thermo_cap'), - investorCap: createMetricPattern1(this, 'investor_cap'), - vaultedCap: createMetricPattern1(this, 'vaulted_cap'), - activeCap: createMetricPattern1(this, 'active_cap'), - cointimeCap: createMetricPattern1(this, 'cointime_cap'), + thermoCap: createCentsUsdPattern(this, 'thermo_cap'), + investorCap: createCentsUsdPattern(this, 'investor_cap'), + vaultedCap: createCentsUsdPattern(this, 'vaulted_cap'), + activeCap: createCentsUsdPattern(this, 'active_cap'), + cointimeCap: createCentsUsdPattern(this, 'cointime_cap'), }, pricing: { vaultedPrice: createCentsSatsUsdPattern(this, 'vaulted_price'), @@ -7765,7 +7763,7 @@ class BrkClient extends BrkClientBase { emptyaddressindex: createMetricPattern35(this, 'emptyaddressindex'), }, supply: { - circulating: createBtcSatsUsdPattern(this, 'circulating_supply'), + circulating: createBtcCentsSatsUsdPattern(this, 'circulating_supply'), burned: { opreturn: createBaseCumulativeSumPattern(this, 'opreturn_supply'), unspendable: createBaseCumulativeSumPattern(this, 'unspendable_supply'), diff --git a/packages/brk_client/brk_client/__init__.py b/packages/brk_client/brk_client/__init__.py index 737effd18..a35db6ca3 100644 --- a/packages/brk_client/brk_client/__init__.py +++ b/packages/brk_client/brk_client/__init__.py @@ -2590,45 +2590,45 @@ class GreedInvestedInvestorNegNetPainPeakSupplyTotalUnrealizedPattern: def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" - self.greed_index: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'greed_index')) - self.invested_capital_in_loss: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'invested_capital_in_loss')) + self.greed_index: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'greed_index')) + self.invested_capital_in_loss: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'invested_capital_in_loss')) self.invested_capital_in_loss_raw: MetricPattern18[CentsSats] = MetricPattern18(client, _m(acc, 'invested_capital_in_loss_raw')) - self.invested_capital_in_profit: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'invested_capital_in_profit')) + self.invested_capital_in_profit: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'invested_capital_in_profit')) self.invested_capital_in_profit_raw: MetricPattern18[CentsSats] = MetricPattern18(client, _m(acc, 'invested_capital_in_profit_raw')) self.investor_cap_in_loss_raw: MetricPattern18[CentsSquaredSats] = MetricPattern18(client, _m(acc, 'investor_cap_in_loss_raw')) self.investor_cap_in_profit_raw: MetricPattern18[CentsSquaredSats] = MetricPattern18(client, _m(acc, 'investor_cap_in_profit_raw')) self.neg_unrealized_loss: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'neg_unrealized_loss')) - self.net_sentiment: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'net_sentiment')) - self.net_unrealized_pnl: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'net_unrealized_pnl')) - self.pain_index: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'pain_index')) - self.peak_regret: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'unrealized_peak_regret')) + self.net_sentiment: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'net_sentiment')) + self.net_unrealized_pnl: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'net_unrealized_pnl')) + self.pain_index: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'pain_index')) + self.peak_regret: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'unrealized_peak_regret')) self.supply_in_loss: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'supply_in_loss')) self.supply_in_profit: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'supply_in_profit')) - self.total_unrealized_pnl: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'total_unrealized_pnl')) - self.unrealized_loss: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'unrealized_loss')) - self.unrealized_profit: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'unrealized_profit')) + self.total_unrealized_pnl: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'total_unrealized_pnl')) + self.unrealized_loss: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'unrealized_loss')) + self.unrealized_profit: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'unrealized_profit')) class GreedInvestedInvestorNegNetPainSupplyTotalUnrealizedPattern: """Pattern struct for repeated tree structure.""" def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" - self.greed_index: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'greed_index')) - self.invested_capital_in_loss: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'invested_capital_in_loss')) + self.greed_index: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'greed_index')) + self.invested_capital_in_loss: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'invested_capital_in_loss')) self.invested_capital_in_loss_raw: MetricPattern18[CentsSats] = MetricPattern18(client, _m(acc, 'invested_capital_in_loss_raw')) - self.invested_capital_in_profit: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'invested_capital_in_profit')) + self.invested_capital_in_profit: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'invested_capital_in_profit')) self.invested_capital_in_profit_raw: MetricPattern18[CentsSats] = MetricPattern18(client, _m(acc, 'invested_capital_in_profit_raw')) self.investor_cap_in_loss_raw: MetricPattern18[CentsSquaredSats] = MetricPattern18(client, _m(acc, 'investor_cap_in_loss_raw')) self.investor_cap_in_profit_raw: MetricPattern18[CentsSquaredSats] = MetricPattern18(client, _m(acc, 'investor_cap_in_profit_raw')) self.neg_unrealized_loss: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'neg_unrealized_loss')) - self.net_sentiment: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'net_sentiment')) - self.net_unrealized_pnl: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'net_unrealized_pnl')) - self.pain_index: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'pain_index')) + self.net_sentiment: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'net_sentiment')) + self.net_unrealized_pnl: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'net_unrealized_pnl')) + self.pain_index: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'pain_index')) self.supply_in_loss: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'supply_in_loss')) self.supply_in_profit: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'supply_in_profit')) - self.total_unrealized_pnl: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'total_unrealized_pnl')) - self.unrealized_loss: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'unrealized_loss')) - self.unrealized_profit: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'unrealized_profit')) + self.total_unrealized_pnl: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'total_unrealized_pnl')) + self.unrealized_loss: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'unrealized_loss')) + self.unrealized_profit: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'unrealized_profit')) class BlocksCoinbaseDaysDominanceFeeSubsidyPattern: """Pattern struct for repeated tree structure.""" @@ -3044,7 +3044,7 @@ class _30dHalvedTotalPattern: def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" self._30d_change: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, '_30d_change')) - self.halved: BtcSatsUsdPattern = BtcSatsUsdPattern(client, _m(acc, 'supply_halved')) + self.halved: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'supply_halved')) self.total: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'supply')) class BaseCumulativeSumPattern: @@ -3056,15 +3056,6 @@ class BaseCumulativeSumPattern: self.cumulative: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'cumulative')) self.sum: _1y24h30d7dPattern2 = _1y24h30d7dPattern2(client, _m(acc, 'sum')) -class BtcSatsUsdPattern: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.btc: MetricPattern1[Bitcoin] = MetricPattern1(client, _m(acc, 'btc')) - self.sats: MetricPattern1[Sats] = MetricPattern1(client, acc) - self.usd: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'usd')) - class CentsSatsUsdPattern2: """Pattern struct for repeated tree structure.""" @@ -3126,6 +3117,14 @@ class BaseCumulativePattern: self.base: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, acc) self.cumulative: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, _m(acc, 'cumulative')) +class CentsUsdPattern: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.cents: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'cents')) + self.usd: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'usd')) + class MaxMinPattern: """Pattern struct for repeated tree structure.""" @@ -3472,7 +3471,7 @@ class MetricsTree_Mining_Rewards: self.subsidy_dominance_7d: MetricPattern1[StoredF32] = MetricPattern1(client, 'subsidy_dominance_7d') self.subsidy_dominance_30d: MetricPattern1[StoredF32] = MetricPattern1(client, 'subsidy_dominance_30d') self.subsidy_dominance_1y: MetricPattern1[StoredF32] = MetricPattern1(client, 'subsidy_dominance_1y') - self.subsidy_usd_1y_sma: MetricPattern1[Dollars] = MetricPattern1(client, 'subsidy_usd_1y_sma') + self.subsidy_usd_1y_sma: CentsUsdPattern = CentsUsdPattern(client, 'subsidy_usd_1y_sma') class MetricsTree_Mining_Hashrate: """Metrics tree node.""" @@ -3540,11 +3539,11 @@ class MetricsTree_Cointime_Cap: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.thermo_cap: MetricPattern1[Dollars] = MetricPattern1(client, 'thermo_cap') - self.investor_cap: MetricPattern1[Dollars] = MetricPattern1(client, 'investor_cap') - self.vaulted_cap: MetricPattern1[Dollars] = MetricPattern1(client, 'vaulted_cap') - self.active_cap: MetricPattern1[Dollars] = MetricPattern1(client, 'active_cap') - self.cointime_cap: MetricPattern1[Dollars] = MetricPattern1(client, 'cointime_cap') + self.thermo_cap: CentsUsdPattern = CentsUsdPattern(client, 'thermo_cap') + self.investor_cap: CentsUsdPattern = CentsUsdPattern(client, 'investor_cap') + self.vaulted_cap: CentsUsdPattern = CentsUsdPattern(client, 'vaulted_cap') + self.active_cap: CentsUsdPattern = CentsUsdPattern(client, 'active_cap') + self.cointime_cap: CentsUsdPattern = CentsUsdPattern(client, 'cointime_cap') class MetricsTree_Cointime_Pricing: """Metrics tree node.""" @@ -4898,7 +4897,7 @@ class MetricsTree_Supply: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.circulating: BtcSatsUsdPattern = BtcSatsUsdPattern(client, 'circulating_supply') + self.circulating: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, 'circulating_supply') self.burned: MetricsTree_Supply_Burned = MetricsTree_Supply_Burned(client) self.inflation: MetricPattern1[StoredF32] = MetricPattern1(client, 'inflation_rate') self.velocity: MetricsTree_Supply_Velocity = MetricsTree_Supply_Velocity(client)