diff --git a/crates/brk_computer/src/chain.rs b/crates/brk_computer/src/chain.rs index 7cf001e48..f17e8cedc 100644 --- a/crates/brk_computer/src/chain.rs +++ b/crates/brk_computer/src/chain.rs @@ -4,13 +4,13 @@ use allocative::Allocative; use brk_error::Result; use brk_indexer::Indexer; use brk_structs::{ - CheckedSub, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, FeeRate, HalvingEpoch, Height, - InputIndex, MonthIndex, OutputIndex, QuarterIndex, Sats, SemesterIndex, StoredBool, StoredF32, - StoredF64, StoredU32, StoredU64, Timestamp, TxIndex, TxVersion, Version, WeekIndex, Weight, - YearIndex, + Bitcoin, CheckedSub, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, FeeRate, HalvingEpoch, + Height, InputIndex, MonthIndex, OutputIndex, QuarterIndex, Sats, SemesterIndex, StoredBool, + StoredF32, StoredF64, StoredU32, StoredU64, Timestamp, TxIndex, TxVersion, Version, WeekIndex, + Weight, YearIndex, }; use vecdb::{ - AnyCloneableIterableVec, AnyCollectableVec, AnyIterableVec, AnyVec, Database, EagerVec, Exit, + AnyCloneableIterableVec, AnyCollectableVec, AnyIterableVec, Database, EagerVec, Exit, LazyVecFrom1, LazyVecFrom2, LazyVecFrom3, PAGE_SIZE, StoredIndex, VecIterator, }; @@ -21,7 +21,6 @@ use crate::grouped::{ use super::{Indexes, indexes, price}; -const VERSION: Version = Version::ZERO; const TARGET_BLOCKS_PER_DAY_F64: f64 = 144.0; const TARGET_BLOCKS_PER_DAY_F32: f32 = 144.0; const TARGET_BLOCKS_PER_DAY: u64 = 144; @@ -51,7 +50,7 @@ pub struct Vecs { pub height_to_interval: EagerVec, pub height_to_24h_block_count: EagerVec, pub height_to_24h_coinbase_sum: EagerVec, - pub height_to_24h_coinbase_in_usd_sum: EagerVec, + pub height_to_24h_coinbase_usd_sum: EagerVec, pub height_to_vbytes: EagerVec, pub difficultyepoch_to_timestamp: EagerVec, pub halvingepoch_to_timestamp: EagerVec, @@ -134,24 +133,31 @@ pub struct Vecs { pub indexes_to_blocks_before_next_halving: ComputedVecsFromHeight, pub indexes_to_days_before_next_halving: ComputedVecsFromHeight, pub indexes_to_inflation_rate: ComputedVecsFromDateIndex, + pub indexes_to_annualized_volume: ComputedVecsFromDateIndex, + pub indexes_to_annualized_volume_btc: ComputedVecsFromDateIndex, + pub indexes_to_annualized_volume_usd: ComputedVecsFromDateIndex, + pub indexes_to_velocity_btc: ComputedVecsFromDateIndex, + pub indexes_to_velocity_usd: ComputedVecsFromDateIndex, } impl Vecs { pub fn forced_import( - parent: &Path, - version: Version, + parent_path: &Path, + parent_version: Version, indexer: &Indexer, indexes: &indexes::Vecs, price: Option<&price::Vecs>, ) -> Result { - let db = Database::open(&parent.join("chain"))?; + let db = Database::open(&parent_path.join("chain"))?; db.set_min_len(PAGE_SIZE * 10_000_000)?; + let version = parent_version + Version::ZERO; + let compute_dollars = price.is_some(); let inputindex_to_value = LazyVecFrom2::init( "value", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexer.vecs.inputindex_to_outputindex.boxed_clone(), indexer.vecs.outputindex_to_value.boxed_clone(), |index: InputIndex, inputindex_to_outputindex_iter, outputindex_to_value_iter| { @@ -175,7 +181,7 @@ impl Vecs { let txindex_to_weight = LazyVecFrom2::init( "weight", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexer.vecs.txindex_to_base_size.boxed_clone(), indexer.vecs.txindex_to_total_size.boxed_clone(), |index: TxIndex, txindex_to_base_size_iter, txindex_to_total_size_iter| { @@ -200,7 +206,7 @@ impl Vecs { let txindex_to_vsize = LazyVecFrom1::init( "vsize", - version + VERSION + Version::ZERO, + version + Version::ZERO, txindex_to_weight.boxed_clone(), |index: TxIndex, iter| { let index = index.unwrap_to_usize(); @@ -214,7 +220,7 @@ impl Vecs { let txindex_to_is_coinbase = LazyVecFrom2::init( "is_coinbase", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes.txindex_to_height.boxed_clone(), indexer.vecs.height_to_first_txindex.boxed_clone(), |index: TxIndex, txindex_to_height_iter, height_to_first_txindex_iter| { @@ -234,7 +240,7 @@ impl Vecs { let txindex_to_input_value = LazyVecFrom3::init( "input_value", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexer.vecs.txindex_to_first_inputindex.boxed_clone(), indexes.txindex_to_input_count.boxed_clone(), inputindex_to_value.boxed_clone(), @@ -270,7 +276,7 @@ impl Vecs { // db, // "input_value", // true, - // version + VERSION + Version::ZERO, + // version + Version::ZERO, // format, // computation, // StorableVecGeneatorOptions::default() @@ -281,7 +287,7 @@ impl Vecs { let txindex_to_output_value = LazyVecFrom3::init( "output_value", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexer.vecs.txindex_to_first_outputindex.boxed_clone(), indexes.txindex_to_output_count.boxed_clone(), indexer.vecs.outputindex_to_value.boxed_clone(), @@ -317,7 +323,7 @@ impl Vecs { // db, // "output_value", // true, - // version + VERSION + Version::ZERO, + // version + Version::ZERO, // format, // computation, // StorableVecGeneatorOptions::default() @@ -327,50 +333,50 @@ impl Vecs { // )?; let txindex_to_fee = - EagerVec::forced_import_compressed(&db, "fee", version + VERSION + Version::ZERO)?; + EagerVec::forced_import_compressed(&db, "fee", version + Version::ZERO)?; let txindex_to_fee_rate = - EagerVec::forced_import_compressed(&db, "fee_rate", version + VERSION + Version::ZERO)?; + EagerVec::forced_import_compressed(&db, "fee_rate", version + Version::ZERO)?; let dateindex_to_block_count_target = LazyVecFrom1::init( "block_count_target", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes.dateindex_to_dateindex.boxed_clone(), |_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_DAY)), ); let weekindex_to_block_count_target = LazyVecFrom1::init( "block_count_target", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes.weekindex_to_weekindex.boxed_clone(), |_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_WEEK)), ); let monthindex_to_block_count_target = LazyVecFrom1::init( "block_count_target", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes.monthindex_to_monthindex.boxed_clone(), |_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_MONTH)), ); let quarterindex_to_block_count_target = LazyVecFrom1::init( "block_count_target", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes.quarterindex_to_quarterindex.boxed_clone(), |_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_QUARTER)), ); let semesterindex_to_block_count_target = LazyVecFrom1::init( "block_count_target", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes.semesterindex_to_semesterindex.boxed_clone(), |_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_SEMESTER)), ); let yearindex_to_block_count_target = LazyVecFrom1::init( "block_count_target", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes.yearindex_to_yearindex.boxed_clone(), |_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_YEAR)), ); let decadeindex_to_block_count_target = LazyVecFrom1::init( "block_count_target", - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes.decadeindex_to_decadeindex.boxed_clone(), |_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_DECADE)), ); @@ -386,13 +392,13 @@ impl Vecs { height_to_interval: EagerVec::forced_import_compressed( &db, "interval", - version + VERSION + Version::ZERO, + version + Version::ZERO, )?, timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import( &db, "timestamp", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_first(), )?, @@ -400,7 +406,7 @@ impl Vecs { &db, "block_interval", Source::None, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_percentiles() @@ -411,7 +417,7 @@ impl Vecs { &db, "block_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_sum().add_cumulative(), )?, @@ -419,7 +425,7 @@ impl Vecs { &db, "1w_block_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -427,7 +433,7 @@ impl Vecs { &db, "1m_block_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -435,7 +441,7 @@ impl Vecs { &db, "1y_block_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -443,7 +449,7 @@ impl Vecs { &db, "block_weight", Source::None, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_sum() @@ -456,7 +462,7 @@ impl Vecs { &db, "block_size", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_sum() @@ -468,28 +474,28 @@ impl Vecs { height_to_vbytes: EagerVec::forced_import_compressed( &db, "vbytes", - version + VERSION + Version::ZERO, + version + Version::ZERO, )?, height_to_24h_block_count: EagerVec::forced_import_compressed( &db, "24h_block_count", - version + VERSION + Version::ZERO, + version + Version::ZERO, )?, height_to_24h_coinbase_sum: EagerVec::forced_import_compressed( &db, "24h_coinbase_sum", - version + VERSION + Version::ZERO, + version + Version::ZERO, )?, - height_to_24h_coinbase_in_usd_sum: EagerVec::forced_import_compressed( + height_to_24h_coinbase_usd_sum: EagerVec::forced_import_compressed( &db, - "24h_coinbase_in_usd_sum", - version + VERSION + Version::ZERO, + "24h_coinbase_usd_sum", + version + Version::ZERO, )?, indexes_to_block_vbytes: ComputedVecsFromHeight::forced_import( &db, "block_vbytes", Source::None, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_sum() @@ -501,29 +507,29 @@ impl Vecs { difficultyepoch_to_timestamp: EagerVec::forced_import_compressed( &db, "timestamp", - version + VERSION + Version::ZERO, + version + Version::ZERO, )?, halvingepoch_to_timestamp: EagerVec::forced_import_compressed( &db, "timestamp", - version + VERSION + Version::ZERO, + version + Version::ZERO, )?, dateindex_to_fee_dominance: EagerVec::forced_import_compressed( &db, "fee_dominance", - version + VERSION + Version::ZERO, + version + Version::ZERO, )?, dateindex_to_subsidy_dominance: EagerVec::forced_import_compressed( &db, "subsidy_dominance", - version + VERSION + Version::ZERO, + version + Version::ZERO, )?, indexes_to_difficulty: ComputedVecsFromHeight::forced_import( &db, "difficulty", Source::None, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -531,7 +537,7 @@ impl Vecs { &db, "difficultyepoch", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -539,7 +545,7 @@ impl Vecs { &db, "halvingepoch", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -547,7 +553,7 @@ impl Vecs { &db, "tx_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -560,7 +566,7 @@ impl Vecs { &db, "input_count", Source::None, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -573,7 +579,7 @@ impl Vecs { &db, "output_count", Source::None, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -586,7 +592,7 @@ impl Vecs { &db, "tx_v1", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_sum().add_cumulative(), )?, @@ -594,7 +600,7 @@ impl Vecs { &db, "tx_v2", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_sum().add_cumulative(), )?, @@ -602,7 +608,7 @@ impl Vecs { &db, "tx_v3", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_sum().add_cumulative(), )?, @@ -610,7 +616,7 @@ impl Vecs { &db, "sent", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, VecBuilderOptions::default().add_sum(), compute_dollars, indexes, @@ -620,7 +626,7 @@ impl Vecs { "fee", indexes, Source::Vec(txindex_to_fee.boxed_clone()), - version + VERSION + Version::ZERO, + version + Version::ZERO, price, VecBuilderOptions::default() .add_sum() @@ -633,7 +639,7 @@ impl Vecs { &db, "fee_rate", Source::None, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_percentiles() @@ -644,7 +650,7 @@ impl Vecs { &db, "tx_vsize", Source::None, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_percentiles() @@ -655,7 +661,7 @@ impl Vecs { &db, "tx_weight", Source::None, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_percentiles() @@ -666,7 +672,7 @@ impl Vecs { &db, "subsidy", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, VecBuilderOptions::default() .add_percentiles() .add_sum() @@ -680,7 +686,7 @@ impl Vecs { &db, "coinbase", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, VecBuilderOptions::default() .add_sum() .add_cumulative() @@ -694,7 +700,7 @@ impl Vecs { &db, "unclaimed_rewards", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, VecBuilderOptions::default().add_sum().add_cumulative(), compute_dollars, indexes, @@ -703,7 +709,7 @@ impl Vecs { &db, "p2a_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -716,7 +722,7 @@ impl Vecs { &db, "p2ms_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -729,7 +735,7 @@ impl Vecs { &db, "p2pk33_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -742,7 +748,7 @@ impl Vecs { &db, "p2pk65_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -755,7 +761,7 @@ impl Vecs { &db, "p2pkh_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -768,7 +774,7 @@ impl Vecs { &db, "p2sh_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -781,7 +787,7 @@ impl Vecs { &db, "p2tr_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -794,7 +800,7 @@ impl Vecs { &db, "p2wpkh_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -807,7 +813,7 @@ impl Vecs { &db, "p2wsh_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -820,7 +826,7 @@ impl Vecs { &db, "opreturn_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -833,7 +839,7 @@ impl Vecs { &db, "unknownoutput_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -846,7 +852,7 @@ impl Vecs { &db, "emptyoutput_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default() .add_average() @@ -859,7 +865,7 @@ impl Vecs { &db, "exact_utxo_count", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -868,7 +874,7 @@ impl Vecs { &db, "subsidy_usd_1y_sma", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), ) @@ -879,7 +885,7 @@ impl Vecs { &db, "puell_multiple", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), ) @@ -889,7 +895,7 @@ impl Vecs { &db, "hash_rate", Source::Compute, - version + VERSION + Version::new(5), + version + Version::new(5), indexes, VecBuilderOptions::default().add_last(), )?, @@ -897,7 +903,7 @@ impl Vecs { &db, "hash_rate_1w_sma", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -905,7 +911,7 @@ impl Vecs { &db, "hash_rate_1m_sma", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -913,7 +919,7 @@ impl Vecs { &db, "hash_rate_2m_sma", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -921,7 +927,7 @@ impl Vecs { &db, "hash_rate_1y_sma", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -929,7 +935,7 @@ impl Vecs { &db, "difficulty_as_hash", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -937,7 +943,7 @@ impl Vecs { &db, "difficulty_adjustment", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_sum(), )?, @@ -946,7 +952,7 @@ impl Vecs { &db, "blocks_before_next_difficulty_adjustment", Source::Compute, - version + VERSION + Version::TWO, + version + Version::TWO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -955,7 +961,7 @@ impl Vecs { &db, "days_before_next_difficulty_adjustment", Source::Compute, - version + VERSION + Version::TWO, + version + Version::TWO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -963,7 +969,7 @@ impl Vecs { &db, "blocks_before_next_halving", Source::Compute, - version + VERSION + Version::TWO, + version + Version::TWO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -971,7 +977,7 @@ impl Vecs { &db, "days_before_next_halving", Source::Compute, - version + VERSION + Version::TWO, + version + Version::TWO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -979,7 +985,7 @@ impl Vecs { &db, "hash_price_ths", Source::Compute, - version + VERSION + Version::new(4), + version + Version::new(4), indexes, VecBuilderOptions::default().add_last(), )?, @@ -987,7 +993,7 @@ impl Vecs { &db, "hash_price_phs", Source::Compute, - version + VERSION + Version::new(4), + version + Version::new(4), indexes, VecBuilderOptions::default().add_last(), )?, @@ -995,7 +1001,7 @@ impl Vecs { &db, "hash_value_ths", Source::Compute, - version + VERSION + Version::new(4), + version + Version::new(4), indexes, VecBuilderOptions::default().add_last(), )?, @@ -1003,7 +1009,7 @@ impl Vecs { &db, "hash_value_phs", Source::Compute, - version + VERSION + Version::new(4), + version + Version::new(4), indexes, VecBuilderOptions::default().add_last(), )?, @@ -1011,7 +1017,7 @@ impl Vecs { &db, "hash_price_ths_min", Source::Compute, - version + VERSION + Version::new(4), + version + Version::new(4), indexes, VecBuilderOptions::default().add_last(), )?, @@ -1019,7 +1025,7 @@ impl Vecs { &db, "hash_price_phs_min", Source::Compute, - version + VERSION + Version::new(4), + version + Version::new(4), indexes, VecBuilderOptions::default().add_last(), )?, @@ -1027,7 +1033,7 @@ impl Vecs { &db, "hash_price_rebound", Source::Compute, - version + VERSION + Version::new(4), + version + Version::new(4), indexes, VecBuilderOptions::default().add_last(), )?, @@ -1035,7 +1041,7 @@ impl Vecs { &db, "hash_value_ths_min", Source::Compute, - version + VERSION + Version::new(4), + version + Version::new(4), indexes, VecBuilderOptions::default().add_last(), )?, @@ -1043,7 +1049,7 @@ impl Vecs { &db, "hash_value_phs_min", Source::Compute, - version + VERSION + Version::new(4), + version + Version::new(4), indexes, VecBuilderOptions::default().add_last(), )?, @@ -1051,7 +1057,7 @@ impl Vecs { &db, "hash_value_rebound", Source::Compute, - version + VERSION + Version::new(4), + version + Version::new(4), indexes, VecBuilderOptions::default().add_last(), )?, @@ -1059,7 +1065,47 @@ impl Vecs { &db, "inflation_rate", Source::Compute, - version + VERSION + Version::ZERO, + version + Version::ZERO, + indexes, + VecBuilderOptions::default().add_last(), + )?, + indexes_to_annualized_volume: ComputedVecsFromDateIndex::forced_import( + &db, + "annualized_volume", + Source::Compute, + version + Version::ZERO, + indexes, + VecBuilderOptions::default().add_last(), + )?, + indexes_to_annualized_volume_btc: ComputedVecsFromDateIndex::forced_import( + &db, + "annualized_volume_btc", + Source::Compute, + version + Version::ZERO, + indexes, + VecBuilderOptions::default().add_last(), + )?, + indexes_to_annualized_volume_usd: ComputedVecsFromDateIndex::forced_import( + &db, + "annualized_volume_usd", + Source::Compute, + version + Version::ZERO, + indexes, + VecBuilderOptions::default().add_last(), + )?, + indexes_to_velocity_btc: ComputedVecsFromDateIndex::forced_import( + &db, + "velocity_btc", + Source::Compute, + version + Version::ZERO, + indexes, + VecBuilderOptions::default().add_last(), + )?, + indexes_to_velocity_usd: ComputedVecsFromDateIndex::forced_import( + &db, + "velocity_usd", + Source::Compute, + version + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, @@ -1506,7 +1552,7 @@ impl Vecs { .as_ref() .map(|c| c.height.as_ref().unwrap().into_iter()) { - self.height_to_24h_coinbase_in_usd_sum.compute_transform( + self.height_to_24h_coinbase_usd_sum.compute_transform( starting_indexes.height, &self.height_to_24h_block_count, |(h, count, ..)| { @@ -1977,7 +2023,7 @@ impl Vecs { .compute_all(indexes, starting_indexes, exit, |v| { v.compute_transform2( starting_indexes.height, - &self.height_to_24h_coinbase_in_usd_sum, + &self.height_to_24h_coinbase_usd_sum, self.indexes_to_hash_rate.height.as_ref().unwrap(), |(i, coinbase_sum, hashrate, ..)| { (i, (*coinbase_sum / (*hashrate / ONE_TERA_HASH)).into()) @@ -2092,6 +2138,77 @@ impl Vecs { Ok(()) })?; + self.indexes_to_annualized_volume + .compute_all(starting_indexes, exit, |v| { + v.compute_sum( + starting_indexes.dateindex, + self.indexes_to_sent.sats.dateindex.unwrap_sum(), + 365, + exit, + )?; + Ok(()) + })?; + + self.indexes_to_annualized_volume_btc + .compute_all(starting_indexes, exit, |v| { + v.compute_sum( + starting_indexes.dateindex, + self.indexes_to_sent.bitcoin.dateindex.unwrap_sum(), + 365, + exit, + )?; + Ok(()) + })?; + + self.indexes_to_velocity_btc + .compute_all(starting_indexes, exit, |v| { + v.compute_divide( + starting_indexes.dateindex, + self.indexes_to_annualized_volume_btc + .dateindex + .as_ref() + .unwrap(), + self.indexes_to_subsidy + .bitcoin + .dateindex + .unwrap_cumulative(), + exit, + )?; + Ok(()) + })?; + + if let Some(indexes_to_sent) = self.indexes_to_sent.dollars.as_ref() { + self.indexes_to_annualized_volume_usd + .compute_all(starting_indexes, exit, |v| { + v.compute_sum( + starting_indexes.dateindex, + indexes_to_sent.dateindex.unwrap_sum(), + 365, + exit, + )?; + Ok(()) + })?; + + self.indexes_to_velocity_usd + .compute_all(starting_indexes, exit, |v| { + v.compute_divide( + starting_indexes.dateindex, + self.indexes_to_annualized_volume_usd + .dateindex + .as_ref() + .unwrap(), + self.indexes_to_subsidy + .dollars + .as_ref() + .unwrap() + .dateindex + .unwrap_cumulative(), + exit, + )?; + Ok(()) + })?; + } + Ok(()) } @@ -2121,7 +2238,7 @@ impl Vecs { &self.decadeindex_to_block_count_target, &self.height_to_24h_block_count, &self.height_to_24h_coinbase_sum, - &self.height_to_24h_coinbase_in_usd_sum, + &self.height_to_24h_coinbase_usd_sum, ] .into_iter(), ); @@ -2206,6 +2323,11 @@ impl Vecs { iter = Box::new(iter.chain(self.indexes_to_subsidy.iter_any_collectable())); iter = Box::new(iter.chain(self.indexes_to_exact_utxo_count.iter_any_collectable())); iter = Box::new(iter.chain(self.indexes_to_unclaimed_rewards.iter_any_collectable())); + iter = Box::new(iter.chain(self.indexes_to_annualized_volume.iter_any_collectable())); + iter = Box::new(iter.chain(self.indexes_to_annualized_volume_btc.iter_any_collectable())); + iter = Box::new(iter.chain(self.indexes_to_annualized_volume_usd.iter_any_collectable())); + iter = Box::new(iter.chain(self.indexes_to_velocity_btc.iter_any_collectable())); + iter = Box::new(iter.chain(self.indexes_to_velocity_usd.iter_any_collectable())); iter = Box::new( iter.chain( self.indexes_to_subsidy_usd_1y_sma diff --git a/crates/brk_computer/src/grouped/ratio_from_dateindex.rs b/crates/brk_computer/src/grouped/ratio_from_dateindex.rs index 397fc2eb5..786094bd6 100644 --- a/crates/brk_computer/src/grouped/ratio_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/ratio_from_dateindex.rs @@ -29,12 +29,12 @@ pub struct ComputedRatioVecsFromDateIndex { pub ratio_pct5: Option>, pub ratio_pct2: Option>, pub ratio_pct1: Option>, - pub ratio_pct99_in_usd: Option>, - pub ratio_pct98_in_usd: Option>, - pub ratio_pct95_in_usd: Option>, - pub ratio_pct5_in_usd: Option>, - pub ratio_pct2_in_usd: Option>, - pub ratio_pct1_in_usd: Option>, + pub ratio_pct99_usd: Option>, + pub ratio_pct98_usd: Option>, + pub ratio_pct95_usd: Option>, + pub ratio_pct5_usd: Option>, + pub ratio_pct2_usd: Option>, + pub ratio_pct1_usd: Option>, pub ratio_sd: Option, pub ratio_4y_sd: Option, @@ -212,10 +212,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_pct99_in_usd: extended.then(|| { + ratio_pct99_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_pct99_in_usd"), + &format!("{name}_ratio_pct99_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -223,10 +223,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_pct98_in_usd: extended.then(|| { + ratio_pct98_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_pct98_in_usd"), + &format!("{name}_ratio_pct98_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -234,10 +234,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_pct95_in_usd: extended.then(|| { + ratio_pct95_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_pct95_in_usd"), + &format!("{name}_ratio_pct95_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -245,10 +245,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_pct5_in_usd: extended.then(|| { + ratio_pct5_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_pct5_in_usd"), + &format!("{name}_ratio_pct5_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -256,10 +256,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_pct2_in_usd: extended.then(|| { + ratio_pct2_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_pct2_in_usd"), + &format!("{name}_ratio_pct2_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -267,10 +267,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_pct1_in_usd: extended.then(|| { + ratio_pct1_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_pct1_in_usd"), + &format!("{name}_ratio_pct1_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -529,7 +529,7 @@ impl ComputedRatioVecsFromDateIndex { std::mem::transmute(&self.price.as_ref().unwrap().dateindex) }); - self.ratio_pct99_in_usd + self.ratio_pct99_usd .as_mut() .unwrap() .compute_all(starting_indexes, exit, |vec| { @@ -553,10 +553,10 @@ impl ComputedRatioVecsFromDateIndex { Ok(()) })?; - let compute_in_usd = - |in_usd: Option<&mut ComputedVecsFromDateIndex>, + let compute_usd = + |usd: Option<&mut ComputedVecsFromDateIndex>, source: Option<&ComputedVecsFromDateIndex>| { - in_usd.unwrap().compute_all(starting_indexes, exit, |vec| { + usd.unwrap().compute_all(starting_indexes, exit, |vec| { let mut iter = source.unwrap().dateindex.as_ref().unwrap().into_iter(); vec.compute_transform( starting_indexes.dateindex, @@ -571,12 +571,12 @@ impl ComputedRatioVecsFromDateIndex { }) }; - compute_in_usd(self.ratio_pct1_in_usd.as_mut(), self.ratio_pct1.as_ref())?; - compute_in_usd(self.ratio_pct2_in_usd.as_mut(), self.ratio_pct2.as_ref())?; - compute_in_usd(self.ratio_pct5_in_usd.as_mut(), self.ratio_pct5.as_ref())?; - compute_in_usd(self.ratio_pct95_in_usd.as_mut(), self.ratio_pct95.as_ref())?; - compute_in_usd(self.ratio_pct98_in_usd.as_mut(), self.ratio_pct98.as_ref())?; - compute_in_usd(self.ratio_pct99_in_usd.as_mut(), self.ratio_pct99.as_ref())?; + compute_usd(self.ratio_pct1_usd.as_mut(), self.ratio_pct1.as_ref())?; + compute_usd(self.ratio_pct2_usd.as_mut(), self.ratio_pct2.as_ref())?; + compute_usd(self.ratio_pct5_usd.as_mut(), self.ratio_pct5.as_ref())?; + compute_usd(self.ratio_pct95_usd.as_mut(), self.ratio_pct95.as_ref())?; + compute_usd(self.ratio_pct98_usd.as_mut(), self.ratio_pct98.as_ref())?; + compute_usd(self.ratio_pct99_usd.as_mut(), self.ratio_pct99.as_ref())?; self.ratio_sd.as_mut().unwrap().compute_all( starting_indexes, @@ -717,42 +717,42 @@ impl ComputedRatioVecsFromDateIndex { ); iter = Box::new( iter.chain( - self.ratio_pct1_in_usd + self.ratio_pct1_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), ); iter = Box::new( iter.chain( - self.ratio_pct2_in_usd + self.ratio_pct2_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), ); iter = Box::new( iter.chain( - self.ratio_pct5_in_usd + self.ratio_pct5_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), ); iter = Box::new( iter.chain( - self.ratio_pct95_in_usd + self.ratio_pct95_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), ); iter = Box::new( iter.chain( - self.ratio_pct98_in_usd + self.ratio_pct98_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), ); iter = Box::new( iter.chain( - self.ratio_pct99_in_usd + self.ratio_pct99_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), diff --git a/crates/brk_computer/src/grouped/sd_from_dateindex.rs b/crates/brk_computer/src/grouped/sd_from_dateindex.rs index cdd7c1630..5ff7b99ed 100644 --- a/crates/brk_computer/src/grouped/sd_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/sd_from_dateindex.rs @@ -32,19 +32,19 @@ pub struct ComputedStandardDeviationVecsFromDateIndex { pub m2_5sd: Option>, pub m3sd: Option>, - pub _0sd_in_usd: Option>, - pub p0_5sd_in_usd: Option>, - pub p1sd_in_usd: Option>, - pub p1_5sd_in_usd: Option>, - pub p2sd_in_usd: Option>, - pub p2_5sd_in_usd: Option>, - pub p3sd_in_usd: Option>, - pub m0_5sd_in_usd: Option>, - pub m1sd_in_usd: Option>, - pub m1_5sd_in_usd: Option>, - pub m2sd_in_usd: Option>, - pub m2_5sd_in_usd: Option>, - pub m3sd_in_usd: Option>, + pub _0sd_usd: Option>, + pub p0_5sd_usd: Option>, + pub p1sd_usd: Option>, + pub p1_5sd_usd: Option>, + pub p2sd_usd: Option>, + pub p2_5sd_usd: Option>, + pub p3sd_usd: Option>, + pub m0_5sd_usd: Option>, + pub m1sd_usd: Option>, + pub m1_5sd_usd: Option>, + pub m2sd_usd: Option>, + pub m2_5sd_usd: Option>, + pub m3sd_usd: Option>, } #[derive(Debug, Default)] @@ -259,10 +259,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - _0sd_in_usd: options.price_bands().then(|| { + _0sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_0sd_in_usd"), + &format!("{name}_0sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -270,10 +270,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - p0_5sd_in_usd: options.price_bands().then(|| { + p0_5sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p0_5sd_in_usd"), + &format!("{name}_p0_5sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -281,10 +281,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - p1sd_in_usd: options.price_bands().then(|| { + p1sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p1sd_in_usd"), + &format!("{name}_p1sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -292,10 +292,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - p1_5sd_in_usd: options.price_bands().then(|| { + p1_5sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p1_5sd_in_usd"), + &format!("{name}_p1_5sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -303,10 +303,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - p2sd_in_usd: options.price_bands().then(|| { + p2sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p2sd_in_usd"), + &format!("{name}_p2sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -314,10 +314,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - p2_5sd_in_usd: options.price_bands().then(|| { + p2_5sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p2_5sd_in_usd"), + &format!("{name}_p2_5sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -325,10 +325,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - p3sd_in_usd: options.price_bands().then(|| { + p3sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p3sd_in_usd"), + &format!("{name}_p3sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -336,10 +336,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - m0_5sd_in_usd: options.price_bands().then(|| { + m0_5sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m0_5sd_in_usd"), + &format!("{name}_m0_5sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -347,10 +347,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - m1sd_in_usd: options.price_bands().then(|| { + m1sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m1sd_in_usd"), + &format!("{name}_m1sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -358,10 +358,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - m1_5sd_in_usd: options.price_bands().then(|| { + m1_5sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m1_5sd_in_usd"), + &format!("{name}_m1_5sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -369,10 +369,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - m2sd_in_usd: options.price_bands().then(|| { + m2sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m2sd_in_usd"), + &format!("{name}_m2sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -380,10 +380,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - m2_5sd_in_usd: options.price_bands().then(|| { + m2_5sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m2_5sd_in_usd"), + &format!("{name}_m2_5sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -391,10 +391,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) .unwrap() }), - m3sd_in_usd: options.price_bands().then(|| { + m3sd_usd: options.price_bands().then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m3sd_in_usd"), + &format!("{name}_m3sd_usd"), Source::Compute, version + Version::ZERO, indexes, @@ -630,10 +630,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { return Ok(()); }; - let compute_in_usd = - |in_usd: &mut ComputedVecsFromDateIndex, + let compute_usd = + |usd: &mut ComputedVecsFromDateIndex, mut iter: BoxedVecIterator| { - in_usd.compute_all(starting_indexes, exit, |vec| { + usd.compute_all(starting_indexes, exit, |vec| { vec.compute_transform( starting_indexes.dateindex, price, @@ -647,13 +647,13 @@ impl ComputedStandardDeviationVecsFromDateIndex { }) }; - if self._0sd_in_usd.is_none() { + if self._0sd_usd.is_none() { return Ok(()); } - compute_in_usd(self._0sd_in_usd.as_mut().unwrap(), sma.iter())?; - compute_in_usd( - self.p0_5sd_in_usd.as_mut().unwrap(), + compute_usd(self._0sd_usd.as_mut().unwrap(), sma.iter())?; + compute_usd( + self.p0_5sd_usd.as_mut().unwrap(), self.p0_5sd .as_ref() .unwrap() @@ -662,8 +662,8 @@ impl ComputedStandardDeviationVecsFromDateIndex { .unwrap() .iter(), )?; - compute_in_usd( - self.p1sd_in_usd.as_mut().unwrap(), + compute_usd( + self.p1sd_usd.as_mut().unwrap(), self.p1sd .as_ref() .unwrap() @@ -672,8 +672,8 @@ impl ComputedStandardDeviationVecsFromDateIndex { .unwrap() .iter(), )?; - compute_in_usd( - self.p1_5sd_in_usd.as_mut().unwrap(), + compute_usd( + self.p1_5sd_usd.as_mut().unwrap(), self.p1_5sd .as_ref() .unwrap() @@ -682,8 +682,8 @@ impl ComputedStandardDeviationVecsFromDateIndex { .unwrap() .iter(), )?; - compute_in_usd( - self.p2sd_in_usd.as_mut().unwrap(), + compute_usd( + self.p2sd_usd.as_mut().unwrap(), self.p2sd .as_ref() .unwrap() @@ -692,8 +692,8 @@ impl ComputedStandardDeviationVecsFromDateIndex { .unwrap() .iter(), )?; - compute_in_usd( - self.p2_5sd_in_usd.as_mut().unwrap(), + compute_usd( + self.p2_5sd_usd.as_mut().unwrap(), self.p2_5sd .as_ref() .unwrap() @@ -702,8 +702,8 @@ impl ComputedStandardDeviationVecsFromDateIndex { .unwrap() .iter(), )?; - compute_in_usd( - self.p3sd_in_usd.as_mut().unwrap(), + compute_usd( + self.p3sd_usd.as_mut().unwrap(), self.p3sd .as_ref() .unwrap() @@ -712,8 +712,8 @@ impl ComputedStandardDeviationVecsFromDateIndex { .unwrap() .iter(), )?; - compute_in_usd( - self.m0_5sd_in_usd.as_mut().unwrap(), + compute_usd( + self.m0_5sd_usd.as_mut().unwrap(), self.m0_5sd .as_ref() .unwrap() @@ -722,8 +722,8 @@ impl ComputedStandardDeviationVecsFromDateIndex { .unwrap() .iter(), )?; - compute_in_usd( - self.m1sd_in_usd.as_mut().unwrap(), + compute_usd( + self.m1sd_usd.as_mut().unwrap(), self.m1sd .as_ref() .unwrap() @@ -732,8 +732,8 @@ impl ComputedStandardDeviationVecsFromDateIndex { .unwrap() .iter(), )?; - compute_in_usd( - self.m1_5sd_in_usd.as_mut().unwrap(), + compute_usd( + self.m1_5sd_usd.as_mut().unwrap(), self.m1_5sd .as_ref() .unwrap() @@ -742,8 +742,8 @@ impl ComputedStandardDeviationVecsFromDateIndex { .unwrap() .iter(), )?; - compute_in_usd( - self.m2sd_in_usd.as_mut().unwrap(), + compute_usd( + self.m2sd_usd.as_mut().unwrap(), self.m2sd .as_ref() .unwrap() @@ -752,8 +752,8 @@ impl ComputedStandardDeviationVecsFromDateIndex { .unwrap() .iter(), )?; - compute_in_usd( - self.m2_5sd_in_usd.as_mut().unwrap(), + compute_usd( + self.m2_5sd_usd.as_mut().unwrap(), self.m2_5sd .as_ref() .unwrap() @@ -762,8 +762,8 @@ impl ComputedStandardDeviationVecsFromDateIndex { .unwrap() .iter(), )?; - compute_in_usd( - self.m3sd_in_usd.as_mut().unwrap(), + compute_usd( + self.m3sd_usd.as_mut().unwrap(), self.m3sd .as_ref() .unwrap() @@ -822,97 +822,55 @@ impl ComputedStandardDeviationVecsFromDateIndex { iter = Box::new(iter.chain(self.m2sd.iter().flat_map(|v| v.iter_any_collectable()))); iter = Box::new(iter.chain(self.m2_5sd.iter().flat_map(|v| v.iter_any_collectable()))); iter = Box::new(iter.chain(self.m3sd.iter().flat_map(|v| v.iter_any_collectable()))); + iter = Box::new(iter.chain(self._0sd_usd.iter().flat_map(|v| v.iter_any_collectable()))); iter = Box::new( iter.chain( - self._0sd_in_usd + self.p0_5sd_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), ); + iter = Box::new(iter.chain(self.p1sd_usd.iter().flat_map(|v| v.iter_any_collectable()))); iter = Box::new( iter.chain( - self.p0_5sd_in_usd + self.p1_5sd_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), ); + iter = Box::new(iter.chain(self.p2sd_usd.iter().flat_map(|v| v.iter_any_collectable()))); iter = Box::new( iter.chain( - self.p1sd_in_usd + self.p2_5sd_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), ); + iter = Box::new(iter.chain(self.p3sd_usd.iter().flat_map(|v| v.iter_any_collectable()))); iter = Box::new( iter.chain( - self.p1_5sd_in_usd + self.m0_5sd_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), ); + iter = Box::new(iter.chain(self.m1sd_usd.iter().flat_map(|v| v.iter_any_collectable()))); iter = Box::new( iter.chain( - self.p2sd_in_usd + self.m1_5sd_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), ); + iter = Box::new(iter.chain(self.m2sd_usd.iter().flat_map(|v| v.iter_any_collectable()))); iter = Box::new( iter.chain( - self.p2_5sd_in_usd - .iter() - .flat_map(|v| v.iter_any_collectable()), - ), - ); - iter = Box::new( - iter.chain( - self.p3sd_in_usd - .iter() - .flat_map(|v| v.iter_any_collectable()), - ), - ); - iter = Box::new( - iter.chain( - self.m0_5sd_in_usd - .iter() - .flat_map(|v| v.iter_any_collectable()), - ), - ); - iter = Box::new( - iter.chain( - self.m1sd_in_usd - .iter() - .flat_map(|v| v.iter_any_collectable()), - ), - ); - iter = Box::new( - iter.chain( - self.m1_5sd_in_usd - .iter() - .flat_map(|v| v.iter_any_collectable()), - ), - ); - iter = Box::new( - iter.chain( - self.m2sd_in_usd - .iter() - .flat_map(|v| v.iter_any_collectable()), - ), - ); - iter = Box::new( - iter.chain( - self.m2_5sd_in_usd - .iter() - .flat_map(|v| v.iter_any_collectable()), - ), - ); - iter = Box::new( - iter.chain( - self.m3sd_in_usd + self.m2_5sd_usd .iter() .flat_map(|v| v.iter_any_collectable()), ), ); + iter = Box::new(iter.chain(self.m3sd_usd.iter().flat_map(|v| v.iter_any_collectable()))); iter = Box::new(iter.chain(self.zscore.iter().flat_map(|v| v.iter_any_collectable()))); iter diff --git a/crates/brk_computer/src/grouped/value_from_dateindex.rs b/crates/brk_computer/src/grouped/value_from_dateindex.rs index aaa93c3e5..2325f7627 100644 --- a/crates/brk_computer/src/grouped/value_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/value_from_dateindex.rs @@ -42,7 +42,7 @@ impl ComputedValueVecsFromDateIndex { )?, bitcoin: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_in_btc"), + &format!("{name}_btc"), Source::Compute, version + VERSION, indexes, @@ -51,7 +51,7 @@ impl ComputedValueVecsFromDateIndex { dollars: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_in_usd"), + &format!("{name}_usd"), Source::Compute, version + VERSION, indexes, diff --git a/crates/brk_computer/src/grouped/value_from_height.rs b/crates/brk_computer/src/grouped/value_from_height.rs index da250799f..20baae0d6 100644 --- a/crates/brk_computer/src/grouped/value_from_height.rs +++ b/crates/brk_computer/src/grouped/value_from_height.rs @@ -43,7 +43,7 @@ impl ComputedValueVecsFromHeight { )?, bitcoin: ComputedVecsFromHeight::forced_import( db, - &format!("{name}_in_btc"), + &format!("{name}_btc"), Source::Compute, version + VERSION, indexes, @@ -52,7 +52,7 @@ impl ComputedValueVecsFromHeight { dollars: compute_dollars.then(|| { ComputedVecsFromHeight::forced_import( db, - &format!("{name}_in_usd"), + &format!("{name}_usd"), Source::Compute, version + VERSION, indexes, diff --git a/crates/brk_computer/src/grouped/value_from_txindex.rs b/crates/brk_computer/src/grouped/value_from_txindex.rs index aed536721..448dd9581 100644 --- a/crates/brk_computer/src/grouped/value_from_txindex.rs +++ b/crates/brk_computer/src/grouped/value_from_txindex.rs @@ -38,8 +38,8 @@ impl ComputedValueVecsFromTxindex { ) -> Result { let compute_dollars = price.is_some(); - let name_in_btc = format!("{name}_in_btc"); - let name_in_usd = format!("{name}_in_usd"); + let name_btc = format!("{name}_btc"); + let name_usd = format!("{name}_usd"); let sats = ComputedVecsFromTxindex::forced_import( db, @@ -53,7 +53,7 @@ impl ComputedValueVecsFromTxindex { let source_vec = source.vec(); let bitcoin_txindex = LazyVecFrom1::init( - &name_in_btc, + &name_btc, version + VERSION, source_vec.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s), |txindex: TxIndex, iter| { @@ -66,7 +66,7 @@ impl ComputedValueVecsFromTxindex { let bitcoin = ComputedVecsFromTxindex::forced_import( db, - &name_in_btc, + &name_btc, Source::None, version + VERSION, indexes, @@ -75,29 +75,27 @@ impl ComputedValueVecsFromTxindex { let dollars_txindex = price.map(|price| { LazyVecFrom3::init( - &name_in_usd, + &name_usd, version + VERSION, bitcoin_txindex.boxed_clone(), indexes.txindex_to_height.boxed_clone(), price.chainindexes_to_price_close.height.boxed_clone(), |txindex: TxIndex, - txindex_to_in_btc_iter, + txindex_to_btc_iter, txindex_to_height_iter, height_to_price_close_iter| { let txindex = txindex.unwrap_to_usize(); - txindex_to_in_btc_iter - .next_at(txindex) - .and_then(|(_, value)| { - let btc = value.into_owned(); - txindex_to_height_iter - .next_at(txindex) - .and_then(|(_, value)| { - let height = value.into_owned(); - height_to_price_close_iter - .next_at(height.unwrap_to_usize()) - .map(|(_, close)| *close.into_owned() * btc) - }) - }) + txindex_to_btc_iter.next_at(txindex).and_then(|(_, value)| { + let btc = value.into_owned(); + txindex_to_height_iter + .next_at(txindex) + .and_then(|(_, value)| { + let height = value.into_owned(); + height_to_price_close_iter + .next_at(height.unwrap_to_usize()) + .map(|(_, close)| *close.into_owned() * btc) + }) + }) }, ) }); @@ -110,7 +108,7 @@ impl ComputedValueVecsFromTxindex { dollars: compute_dollars.then(|| { ComputedVecsFromTxindex::forced_import( db, - &name_in_usd, + &name_usd, Source::None, version + VERSION, indexes, diff --git a/crates/brk_computer/src/grouped/value_height.rs b/crates/brk_computer/src/grouped/value_height.rs index 953d269d0..6c6d87a5c 100644 --- a/crates/brk_computer/src/grouped/value_height.rs +++ b/crates/brk_computer/src/grouped/value_height.rs @@ -34,14 +34,14 @@ impl ComputedHeightValueVecs { }), bitcoin: EagerVec::forced_import( db, - &format!("{name}_in_btc"), + &format!("{name}_btc"), version + VERSION + Version::ZERO, format, )?, dollars: compute_dollars.then(|| { EagerVec::forced_import( db, - &format!("{name}_in_usd"), + &format!("{name}_usd"), version + VERSION + Version::ZERO, format, ) diff --git a/crates/brk_structs/src/structs/bitcoin.rs b/crates/brk_structs/src/structs/bitcoin.rs index e0961e750..85980b53b 100644 --- a/crates/brk_structs/src/structs/bitcoin.rs +++ b/crates/brk_structs/src/structs/bitcoin.rs @@ -134,3 +134,8 @@ impl CheckedSub for Bitcoin { Some(Self(self.0 - rhs as f64)) } } +impl CheckedSub for Bitcoin { + fn checked_sub(self, rhs: Bitcoin) -> Option { + Some(Self(self.0 - rhs.0)) + } +} diff --git a/crates/brk_structs/src/structs/stored_f64.rs b/crates/brk_structs/src/structs/stored_f64.rs index 044013949..bf38181be 100644 --- a/crates/brk_structs/src/structs/stored_f64.rs +++ b/crates/brk_structs/src/structs/stored_f64.rs @@ -175,3 +175,10 @@ impl Sum for StoredF64 { Self(iter.map(|v| v.0).sum::()) } } + +impl Div for StoredF64 { + type Output = Self; + fn div(self, rhs: Bitcoin) -> Self::Output { + Self(self.0 / f64::from(rhs)) + } +} diff --git a/websites/bitview/scripts/main.js b/websites/bitview/scripts/main.js index 9b868f252..a0c7ffbb3 100644 --- a/websites/bitview/scripts/main.js +++ b/websites/bitview/scripts/main.js @@ -746,6 +746,7 @@ function createUtils() { (id.endsWith("supply") && !(id.endsWith("circulating_supply") || id.endsWith("_own_supply"))) || id === "sent" || + id === "annualized_volume" || id.endsWith("supply_half") || id.endsWith("supply_breakeven") || id.endsWith("supply_in_profit") || @@ -766,7 +767,13 @@ function createUtils() { ) { setUnit("Sats"); } - if ((!unit || thoroughUnitCheck) && id.includes("in_btc")) { + if ( + (!unit || thoroughUnitCheck) && + !id.startsWith("velocity") && + ((id.includes("_btc") && + !(id.includes("0k_btc") || id.includes("1k_btc"))) || + id.endsWith("_btc")) + ) { setUnit("BTC"); } if ((!unit || thoroughUnitCheck) && id === "chain") { @@ -791,7 +798,7 @@ function createUtils() { id === "price_ath" || id === "market_cap" || id.startsWith("price_true_range") || - id.includes("_usd") || + (id.includes("_usd") && !id.startsWith("velocity")) || id.includes("cointime_value") || id.endsWith("_ago") || id.endsWith("price_paid") || @@ -835,7 +842,8 @@ function createUtils() { id.endsWith("pct99"))) || id.includes("liveliness") || id.includes("vaultedness") || - id == "puell_multiple" + id == "puell_multiple" || + id.startsWith("velocity") ) { setUnit("Ratio"); } diff --git a/websites/bitview/scripts/options.js b/websites/bitview/scripts/options.js index e34a848fa..015652bfa 100644 --- a/websites/bitview/scripts/options.js +++ b/websites/bitview/scripts/options.js @@ -1417,10 +1417,10 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { name: legend, color, }), - ...(`${key}_ratio_p1sd_in_usd` in vecIdToIndexes + ...(`${key}_ratio_p1sd_usd` in vecIdToIndexes ? percentiles.map(({ name, color }) => createBaseSeries({ - key: `${key}_ratio_${name}_in_usd`, + key: `${key}_ratio_${name}_usd`, name, color, defaultActive: false, @@ -1487,25 +1487,25 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { color, }), createBaseSeries({ - key: `${key}_ratio_1y_0sd_in_usd`, + key: `${key}_ratio_1y_0sd_usd`, name: "1y 0sd", color: colors.fuchsia, defaultActive: false, }), createBaseSeries({ - key: `${key}_ratio_2y_0sd_in_usd`, + key: `${key}_ratio_2y_0sd_usd`, name: "2y 0sd", color: colors.purple, defaultActive: false, }), createBaseSeries({ - key: `${key}_ratio_4y_0sd_in_usd`, + key: `${key}_ratio_4y_0sd_usd`, name: "4y 0sd", color: colors.violet, defaultActive: false, }), createBaseSeries({ - key: `${key}_ratio_0sd_in_usd`, + key: `${key}_ratio_0sd_usd`, name: "0sd", color: colors.indigo, defaultActive: false, @@ -1635,7 +1635,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { }, ].map(({ sdKey, name, color }) => createBaseSeries({ - key: `${key}_ratio_${keyAddon}${sdKey}_in_usd`, + key: `${key}_ratio_${keyAddon}${sdKey}_usd`, name, color, defaultActive: false, @@ -1721,12 +1721,12 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { color: colors.default, }), createBaseSeries({ - key: `${key}supply_in_btc`, + key: `${key}supply_btc`, name: "Supply", color: colors.default, }), createBaseSeries({ - key: `${key}supply_in_usd`, + key: `${key}supply_usd`, name: "Supply", color: colors.default, }), @@ -1745,12 +1745,12 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { color: colors.green, }), createBaseSeries({ - key: `${key}supply_in_profit_in_btc`, + key: `${key}supply_in_profit_btc`, name: "In Profit", color: colors.green, }), createBaseSeries({ - key: `${key}supply_in_profit_in_usd`, + key: `${key}supply_in_profit_usd`, name: "In Profit", color: colors.green, }), @@ -1760,12 +1760,12 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { color: colors.red, }), createBaseSeries({ - key: `${key}supply_in_loss_in_btc`, + key: `${key}supply_in_loss_btc`, name: "In Loss", color: colors.red, }), createBaseSeries({ - key: `${key}supply_in_loss_in_usd`, + key: `${key}supply_in_loss_usd`, name: "In Loss", color: colors.red, }), @@ -1775,12 +1775,12 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { color: colors.yellow, }), createBaseSeries({ - key: `${key}supply_breakeven_in_btc`, + key: `${key}supply_breakeven_btc`, name: useGroupName ? name : "breakeven", color: colors.yellow, }), createBaseSeries({ - key: `${key}supply_breakeven_in_usd`, + key: `${key}supply_breakeven_usd`, name: useGroupName ? name : "breakeven", color: colors.yellow, }), @@ -1793,7 +1793,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { }, }), createBaseSeries({ - key: `${key}supply_half_in_btc`, + key: `${key}supply_half_btc`, name: useGroupName ? name : "half", color: "list" in args ? color : colors.gray, options: { @@ -1801,7 +1801,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { }, }), createBaseSeries({ - key: `${key}supply_half_in_usd`, + key: `${key}supply_half_usd`, name: useGroupName ? name : "half", color: "list" in args ? color : colors.gray, options: { @@ -1870,12 +1870,12 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { color, }), createBaseSeries({ - key: `${key}supply_in_btc`, + key: `${key}supply_btc`, name, color, }), createBaseSeries({ - key: `${key}supply_in_usd`, + key: `${key}supply_usd`, name, color, }), @@ -1906,12 +1906,12 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { color, }), createBaseSeries({ - key: `${key}supply_in_profit_in_btc`, + key: `${key}supply_in_profit_btc`, name, color, }), createBaseSeries({ - key: `${key}supply_in_profit_in_usd`, + key: `${key}supply_in_profit_usd`, name, color, }), @@ -1939,12 +1939,12 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { color, }), createBaseSeries({ - key: `${key}supply_in_loss_in_btc`, + key: `${key}supply_in_loss_btc`, name, color, }), createBaseSeries({ - key: `${key}supply_in_loss_in_usd`, + key: `${key}supply_in_loss_usd`, name, color, }), @@ -1972,12 +1972,12 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { color, }), createBaseSeries({ - key: `${key}supply_breakeven_in_btc`, + key: `${key}supply_breakeven_btc`, name, color, }), createBaseSeries({ - key: `${key}supply_breakeven_in_usd`, + key: `${key}supply_breakeven_usd`, name, color, }), @@ -3528,13 +3528,31 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { name: "Sent", }), createBaseSeries({ - key: "sent_in_btc", + key: "sent_btc", name: "Sent", }), createBaseSeries({ - key: "sent_in_usd", + key: "sent_usd", name: "Sent", }), + createBaseSeries({ + key: "annualized_volume", + name: "annualized", + color: colors.red, + defaultActive: false, + }), + createBaseSeries({ + key: "annualized_volume_btc", + name: "annualized", + color: colors.red, + defaultActive: false, + }), + createBaseSeries({ + key: "annualized_volume_usd", + name: "annualized", + color: colors.lime, + defaultActive: false, + }), ], }, { @@ -3569,6 +3587,21 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { }), ), }, + { + name: "Velocity", + title: "Transaction Velocity", + bottom: [ + createBaseSeries({ + key: "velocity_btc", + name: "bitcoin", + }), + createBaseSeries({ + key: "velocity_usd", + name: "dollars", + color: colors.emerald, + }), + ], + }, ], }, { @@ -3635,11 +3668,11 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { name: "Mined", }), createBaseSeries({ - key: "supply_in_btc", + key: "supply_btc", name: "Mined", }), createBaseSeries({ - key: "supply_in_usd", + key: "supply_usd", name: "Mined", }), ], @@ -3659,13 +3692,13 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { ), ...createBaseAverageSumCumulativeMinMaxPercentilesSeries( { - key: "coinbase_in_btc", + key: "coinbase_btc", name: "Coinbase", }, ), ...createBaseAverageSumCumulativeMinMaxPercentilesSeries( { - key: "coinbase_in_usd", + key: "coinbase_usd", name: "Coinbase", }, ), @@ -3687,13 +3720,13 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { }), ...createBaseAverageSumCumulativeMinMaxPercentilesSeries( { - key: "subsidy_in_btc", + key: "subsidy_btc", name: "Subsidy", }, ), ...createBaseAverageSumCumulativeMinMaxPercentilesSeries( { - key: "subsidy_in_usd", + key: "subsidy_usd", name: "Subsidy", }, ), @@ -3707,10 +3740,10 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { "fee", ), ...createAverageSumCumulativeMinMaxPercentilesSeries( - "fee_in_btc", + "fee_btc", ), ...createAverageSumCumulativeMinMaxPercentilesSeries( - "fee_in_usd", + "fee_usd", ), ], }, @@ -3738,10 +3771,10 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { concat: "unclaimed_rewards", }), ...createSumCumulativeSeries({ - concat: "unclaimed_rewards_in_btc", + concat: "unclaimed_rewards_btc", }), ...createSumCumulativeSeries({ - concat: "unclaimed_rewards_in_usd", + concat: "unclaimed_rewards_usd", }), ], }, @@ -4051,13 +4084,13 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { cumulativeColor, }), ...createSumCumulativeSeries({ - concat: `${key}_${keyAddon}_in_btc`, + concat: `${key}_${keyAddon}_btc`, common: keyAddon, sumColor, cumulativeColor, }), ...createSumCumulativeSeries({ - concat: `${key}_${keyAddon}_in_usd`, + concat: `${key}_${keyAddon}_usd`, common: keyAddon, sumColor, cumulativeColor, @@ -4093,11 +4126,11 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { name: "Supply", }), createBaseSeries({ - key: "unspendable_supply_in_btc", + key: "unspendable_supply_btc", name: "Supply", }), createBaseSeries({ - key: "unspendable_supply_in_usd", + key: "unspendable_supply_usd", name: "Supply", }), ], @@ -4133,11 +4166,11 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { name: "Supply", }), createBaseSeries({ - key: "opreturn_supply_in_btc", + key: "opreturn_supply_btc", name: "Supply", }), createBaseSeries({ - key: "opreturn_supply_in_usd", + key: "opreturn_supply_usd", name: "Supply", }), ], @@ -4392,14 +4425,14 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) { createBaseSeries({ key: `${ name !== "all" ? /** @type {const} */ (`${name}_`) : "" - }supply_in_btc`, + }supply_btc`, name, color, }), createBaseSeries({ key: `${ name !== "all" ? /** @type {const} */ (`${name}_`) : "" - }supply_in_usd`, + }supply_usd`, name, color, }),