mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-29 17:19:57 -07:00
global: big snapshot
This commit is contained in:
@@ -3,7 +3,7 @@ use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -13,12 +13,12 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_tx_count
|
||||
self.tx_count
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.tx.height_to_first_txindex,
|
||||
&indexer.vecs.tx.txindex_to_txid,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexer.vecs.transactions.txid,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
|
||||
@@ -4,10 +4,7 @@ use brk_types::{StoredBool, TxIndex, Version};
|
||||
use vecdb::{Database, IterableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::ComputedBlockFull,
|
||||
};
|
||||
use crate::{indexes, internal::ComputedBlockFull};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -19,8 +16,8 @@ impl Vecs {
|
||||
let txindex_to_is_coinbase = LazyVecFrom2::init(
|
||||
"is_coinbase",
|
||||
version,
|
||||
indexer.vecs.tx.txindex_to_height.boxed_clone(),
|
||||
indexer.vecs.tx.height_to_first_txindex.boxed_clone(),
|
||||
indexer.vecs.transactions.height.boxed_clone(),
|
||||
indexer.vecs.transactions.first_txindex.boxed_clone(),
|
||||
|index: TxIndex, txindex_to_height_iter, height_to_first_txindex_iter| {
|
||||
txindex_to_height_iter.get(index).map(|height| {
|
||||
let txindex = height_to_first_txindex_iter.get_unwrap(height);
|
||||
@@ -30,13 +27,8 @@ impl Vecs {
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_tx_count: ComputedBlockFull::forced_import(
|
||||
db,
|
||||
"tx_count",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
txindex_to_is_coinbase,
|
||||
tx_count: ComputedBlockFull::forced_import(db, "tx_count", version, indexes)?,
|
||||
is_coinbase: txindex_to_is_coinbase,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ use crate::internal::ComputedBlockFull;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub indexes_to_tx_count: ComputedBlockFull<StoredU64>,
|
||||
pub txindex_to_is_coinbase: LazyVecFrom2<TxIndex, StoredBool, TxIndex, Height, Height, TxIndex>,
|
||||
pub tx_count: ComputedBlockFull<StoredU64>,
|
||||
pub is_coinbase: LazyVecFrom2<TxIndex, StoredBool, TxIndex, Height, Height, TxIndex>,
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ use brk_indexer::Indexer;
|
||||
use brk_types::{FeeRate, Sats};
|
||||
use vecdb::{Exit, unlikely};
|
||||
|
||||
use super::Vecs;
|
||||
use super::super::size;
|
||||
use crate::{indexes, inputs, ComputeIndexes};
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, indexes, inputs};
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -18,26 +18,26 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.txindex_to_input_value.compute_sum_from_indexes(
|
||||
self.input_value.compute_sum_from_indexes(
|
||||
starting_indexes.txindex,
|
||||
&indexer.vecs.tx.txindex_to_first_txinindex,
|
||||
&indexes.transaction.txindex_to_input_count,
|
||||
&txins.spent.txinindex_to_value,
|
||||
&indexer.vecs.transactions.first_txinindex,
|
||||
&indexes.txindex.input_count,
|
||||
&txins.spent.value,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.txindex_to_output_value.compute_sum_from_indexes(
|
||||
self.output_value.compute_sum_from_indexes(
|
||||
starting_indexes.txindex,
|
||||
&indexer.vecs.tx.txindex_to_first_txoutindex,
|
||||
&indexes.transaction.txindex_to_output_count,
|
||||
&indexer.vecs.txout.txoutindex_to_value,
|
||||
&indexer.vecs.transactions.first_txoutindex,
|
||||
&indexes.txindex.output_count,
|
||||
&indexer.vecs.outputs.value,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.txindex_to_fee.compute_transform2(
|
||||
self.fee.base.compute_transform2(
|
||||
starting_indexes.txindex,
|
||||
&self.txindex_to_input_value,
|
||||
&self.txindex_to_output_value,
|
||||
&self.input_value,
|
||||
&self.output_value,
|
||||
|(i, input, output, ..)| {
|
||||
let fee = if unlikely(input.is_max()) {
|
||||
Sats::ZERO
|
||||
@@ -49,29 +49,19 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.txindex_to_fee_rate.compute_transform2(
|
||||
self.fee_rate.txindex.compute_transform2(
|
||||
starting_indexes.txindex,
|
||||
&self.txindex_to_fee,
|
||||
&size_vecs.txindex_to_vsize,
|
||||
&self.fee.base,
|
||||
&size_vecs.vsize.txindex,
|
||||
|(txindex, fee, vsize, ..)| (txindex, FeeRate::from((fee, vsize))),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.indexes_to_fee.derive_from(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&self.txindex_to_fee,
|
||||
exit,
|
||||
)?;
|
||||
self.fee
|
||||
.derive_from(indexer, indexes, starting_indexes, exit)?;
|
||||
|
||||
self.indexes_to_fee_rate.derive_from(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&self.txindex_to_fee_rate,
|
||||
exit,
|
||||
)?;
|
||||
self.fee_rate
|
||||
.derive_from(indexer, indexes, starting_indexes, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,11 +4,7 @@ use brk_types::Version;
|
||||
use vecdb::{Database, EagerVec, ImportableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedTxDistribution, ValueDerivedTxFull},
|
||||
price,
|
||||
};
|
||||
use crate::{indexes, internal::{ComputedTxDistribution, ValueTxFull}, price};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -18,31 +14,11 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
) -> Result<Self> {
|
||||
let txindex_to_input_value = EagerVec::forced_import(db, "input_value", version)?;
|
||||
let txindex_to_output_value = EagerVec::forced_import(db, "output_value", version)?;
|
||||
let txindex_to_fee = EagerVec::forced_import(db, "fee", version)?;
|
||||
let txindex_to_fee_rate = EagerVec::forced_import(db, "fee_rate", version)?;
|
||||
|
||||
Ok(Self {
|
||||
txindex_to_input_value,
|
||||
txindex_to_output_value,
|
||||
txindex_to_fee: txindex_to_fee.clone(),
|
||||
txindex_to_fee_rate: txindex_to_fee_rate.clone(),
|
||||
indexes_to_fee: ValueDerivedTxFull::forced_import(
|
||||
db,
|
||||
"fee",
|
||||
version,
|
||||
indexes,
|
||||
indexer,
|
||||
price,
|
||||
&txindex_to_fee,
|
||||
)?,
|
||||
indexes_to_fee_rate: ComputedTxDistribution::forced_import(
|
||||
db,
|
||||
"fee_rate",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
input_value: EagerVec::forced_import(db, "input_value", version)?,
|
||||
output_value: EagerVec::forced_import(db, "output_value", version)?,
|
||||
fee: ValueTxFull::forced_import(db, "fee", version, indexes, indexer, price)?,
|
||||
fee_rate: ComputedTxDistribution::forced_import(db, "fee_rate", version, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,12 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{FeeRate, Sats, TxIndex};
|
||||
use vecdb::{EagerVec, PcoVec};
|
||||
|
||||
use crate::internal::{ComputedTxDistribution, ValueDerivedTxFull};
|
||||
use crate::internal::{ComputedTxDistribution, ValueTxFull};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub txindex_to_input_value: EagerVec<PcoVec<TxIndex, Sats>>,
|
||||
pub txindex_to_output_value: EagerVec<PcoVec<TxIndex, Sats>>,
|
||||
pub txindex_to_fee: EagerVec<PcoVec<TxIndex, Sats>>,
|
||||
pub txindex_to_fee_rate: EagerVec<PcoVec<TxIndex, FeeRate>>,
|
||||
pub indexes_to_fee: ValueDerivedTxFull,
|
||||
pub indexes_to_fee_rate: ComputedTxDistribution<FeeRate>,
|
||||
pub input_value: EagerVec<PcoVec<TxIndex, Sats>>,
|
||||
pub output_value: EagerVec<PcoVec<TxIndex, Sats>>,
|
||||
pub fee: ValueTxFull,
|
||||
pub fee_rate: ComputedTxDistribution<FeeRate>,
|
||||
}
|
||||
|
||||
@@ -13,21 +13,11 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_tx_weight.derive_from(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&self.txindex_to_weight,
|
||||
exit,
|
||||
)?;
|
||||
self.weight
|
||||
.derive_from(indexer, indexes, starting_indexes, exit)?;
|
||||
|
||||
self.indexes_to_tx_vsize.derive_from(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&self.txindex_to_vsize,
|
||||
exit,
|
||||
)?;
|
||||
self.vsize
|
||||
.derive_from(indexer, indexes, starting_indexes, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{TxIndex, VSize, Version, Weight};
|
||||
use vecdb::{Database, IterableCloneableVec, LazyVecFrom2, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedTxDistribution};
|
||||
use crate::{indexes, internal::LazyTxDistribution};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -16,43 +16,46 @@ impl Vecs {
|
||||
let txindex_to_weight = LazyVecFrom2::init(
|
||||
"weight",
|
||||
version,
|
||||
indexer.vecs.tx.txindex_to_base_size.boxed_clone(),
|
||||
indexer.vecs.tx.txindex_to_total_size.boxed_clone(),
|
||||
|index: TxIndex, txindex_to_base_size_iter, txindex_to_total_size_iter| {
|
||||
indexer.vecs.transactions.base_size.boxed_clone(),
|
||||
indexer.vecs.transactions.total_size.boxed_clone(),
|
||||
|index: TxIndex, base_size_iter, total_size_iter| {
|
||||
let index = index.to_usize();
|
||||
txindex_to_base_size_iter.get_at(index).map(|base_size| {
|
||||
let total_size = txindex_to_total_size_iter.get_at_unwrap(index);
|
||||
base_size_iter.get_at(index).map(|base_size| {
|
||||
let total_size = total_size_iter.get_at_unwrap(index);
|
||||
Weight::from_sizes(*base_size, *total_size)
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
// Derive directly from eager sources to avoid Lazy <- Lazy
|
||||
let txindex_to_vsize = LazyVecFrom2::init(
|
||||
"vsize",
|
||||
version,
|
||||
indexer.vecs.tx.txindex_to_base_size.boxed_clone(),
|
||||
indexer.vecs.tx.txindex_to_total_size.boxed_clone(),
|
||||
|index: TxIndex, txindex_to_base_size_iter, txindex_to_total_size_iter| {
|
||||
indexer.vecs.transactions.base_size.boxed_clone(),
|
||||
indexer.vecs.transactions.total_size.boxed_clone(),
|
||||
|index: TxIndex, base_size_iter, total_size_iter| {
|
||||
let index = index.to_usize();
|
||||
txindex_to_base_size_iter.get_at(index).map(|base_size| {
|
||||
let total_size = txindex_to_total_size_iter.get_at_unwrap(index);
|
||||
base_size_iter.get_at(index).map(|base_size| {
|
||||
let total_size = total_size_iter.get_at_unwrap(index);
|
||||
VSize::from(Weight::from_sizes(*base_size, *total_size))
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
let indexes_to_tx_vsize =
|
||||
ComputedTxDistribution::forced_import(db, "tx_vsize", version, indexes)?;
|
||||
|
||||
let indexes_to_tx_weight =
|
||||
ComputedTxDistribution::forced_import(db, "tx_weight", version, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_tx_vsize,
|
||||
indexes_to_tx_weight,
|
||||
txindex_to_vsize,
|
||||
txindex_to_weight,
|
||||
vsize: LazyTxDistribution::forced_import(
|
||||
db,
|
||||
"tx_vsize",
|
||||
version,
|
||||
txindex_to_vsize,
|
||||
indexes,
|
||||
)?,
|
||||
weight: LazyTxDistribution::forced_import(
|
||||
db,
|
||||
"tx_weight",
|
||||
version,
|
||||
txindex_to_weight,
|
||||
indexes,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{StoredU32, TxIndex, VSize, Weight};
|
||||
use vecdb::LazyVecFrom2;
|
||||
use brk_types::{StoredU32, VSize, Weight};
|
||||
|
||||
use crate::internal::ComputedTxDistribution;
|
||||
use crate::internal::LazyTxDistribution;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub indexes_to_tx_vsize: ComputedTxDistribution<VSize>,
|
||||
pub indexes_to_tx_weight: ComputedTxDistribution<Weight>,
|
||||
// Both derive directly from eager sources (base_size, total_size) to avoid Lazy <- Lazy
|
||||
pub txindex_to_vsize: LazyVecFrom2<TxIndex, VSize, TxIndex, StoredU32, TxIndex, StoredU32>,
|
||||
pub txindex_to_weight: LazyVecFrom2<TxIndex, Weight, TxIndex, StoredU32, TxIndex, StoredU32>,
|
||||
pub vsize: LazyTxDistribution<VSize, StoredU32, StoredU32>,
|
||||
pub weight: LazyTxDistribution<Weight, StoredU32, StoredU32>,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{StoredU64, TxVersion};
|
||||
use vecdb::{Exit, TypedVecIterator};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedBlockSumCum, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, indexes, internal::ComputedBlockSumCum};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -14,26 +14,25 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let compute_indexes_to_tx_vany =
|
||||
|indexes_to_tx_vany: &mut ComputedBlockSumCum<StoredU64>, txversion: TxVersion| {
|
||||
let mut txindex_to_txversion_iter = indexer.vecs.tx.txindex_to_txversion.iter()?;
|
||||
indexes_to_tx_vany.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
vec.compute_filtered_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.tx.height_to_first_txindex,
|
||||
&indexer.vecs.tx.txindex_to_txid,
|
||||
|txindex| {
|
||||
let v = txindex_to_txversion_iter.get_unwrap(txindex);
|
||||
v == txversion
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})
|
||||
};
|
||||
compute_indexes_to_tx_vany(&mut self.indexes_to_tx_v1, TxVersion::ONE)?;
|
||||
compute_indexes_to_tx_vany(&mut self.indexes_to_tx_v2, TxVersion::TWO)?;
|
||||
compute_indexes_to_tx_vany(&mut self.indexes_to_tx_v3, TxVersion::THREE)?;
|
||||
let tx_vany = |tx_vany: &mut ComputedBlockSumCum<StoredU64>, txversion: TxVersion| {
|
||||
let mut txversion_iter = indexer.vecs.transactions.txversion.iter()?;
|
||||
tx_vany.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
vec.compute_filtered_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexer.vecs.transactions.txid,
|
||||
|txindex| {
|
||||
let v = txversion_iter.get_unwrap(txindex);
|
||||
v == txversion
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})
|
||||
};
|
||||
tx_vany(&mut self.v1, TxVersion::ONE)?;
|
||||
tx_vany(&mut self.v2, TxVersion::TWO)?;
|
||||
tx_vany(&mut self.v3, TxVersion::THREE)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -8,24 +8,9 @@ use crate::{indexes, internal::ComputedBlockSumCum};
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
Ok(Self {
|
||||
indexes_to_tx_v1: ComputedBlockSumCum::forced_import(
|
||||
db,
|
||||
"tx_v1",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_tx_v2: ComputedBlockSumCum::forced_import(
|
||||
db,
|
||||
"tx_v2",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_tx_v3: ComputedBlockSumCum::forced_import(
|
||||
db,
|
||||
"tx_v3",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
v1: ComputedBlockSumCum::forced_import(db, "tx_v1", version, indexes)?,
|
||||
v2: ComputedBlockSumCum::forced_import(db, "tx_v2", version, indexes)?,
|
||||
v3: ComputedBlockSumCum::forced_import(db, "tx_v3", version, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::internal::ComputedBlockSumCum;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub indexes_to_tx_v1: ComputedBlockSumCum<StoredU64>,
|
||||
pub indexes_to_tx_v2: ComputedBlockSumCum<StoredU64>,
|
||||
pub indexes_to_tx_v3: ComputedBlockSumCum<StoredU64>,
|
||||
pub v1: ComputedBlockSumCum<StoredU64>,
|
||||
pub v2: ComputedBlockSumCum<StoredU64>,
|
||||
pub v3: ComputedBlockSumCum<StoredU64>,
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{StoredF32, ONE_DAY_IN_SEC_F64};
|
||||
use brk_types::{ONE_DAY_IN_SEC_F64, StoredF32};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use super::super::{count, fees};
|
||||
use crate::{indexes, inputs, outputs, price, ComputeIndexes};
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, indexes, inputs, outputs, price};
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -21,75 +21,68 @@ impl Vecs {
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_sent_sum
|
||||
self.sent_sum
|
||||
.compute_all(indexes, price, starting_indexes, exit, |v| {
|
||||
v.compute_filtered_sum_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.tx.height_to_first_txindex,
|
||||
&indexes.block.height_to_txindex_count,
|
||||
&fees_vecs.txindex_to_input_value,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexes.height.txindex_count,
|
||||
&fees_vecs.input_value,
|
||||
|sats| !sats.is_max(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_annualized_volume.compute_all(starting_indexes, exit, |v| {
|
||||
self.annualized_volume.compute_sats(|v| {
|
||||
v.compute_sum(
|
||||
starting_indexes.dateindex,
|
||||
&self.indexes_to_sent_sum.sats.dateindex.0,
|
||||
&self.sent_sum.sats.dateindex.0,
|
||||
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_sum.bitcoin.dateindex,
|
||||
365,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
if let Some(indexes_to_sent_sum) = self.indexes_to_sent_sum.dollars.as_ref() {
|
||||
self.indexes_to_annualized_volume_usd.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_sum(
|
||||
starting_indexes.dateindex,
|
||||
&indexes_to_sent_sum.dateindex.0,
|
||||
365,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
if let Some(sent_sum_dollars) = self.sent_sum.dollars.as_ref() {
|
||||
self.annualized_volume.compute_dollars(|dollars| {
|
||||
dollars.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_sum(
|
||||
starting_indexes.dateindex,
|
||||
&sent_sum_dollars.dateindex.0,
|
||||
365,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})
|
||||
})?;
|
||||
}
|
||||
|
||||
self.indexes_to_tx_per_sec.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.dateindex,
|
||||
&count_vecs.indexes_to_tx_count.dateindex.sum_cum.sum.0,
|
||||
&indexes.time.dateindex_to_date,
|
||||
|(i, tx_count, date, ..)| {
|
||||
let completion = date.completion();
|
||||
let per_sec = if completion == 0.0 {
|
||||
StoredF32::NAN
|
||||
} else {
|
||||
StoredF32::from(*tx_count as f64 / (completion * ONE_DAY_IN_SEC_F64))
|
||||
};
|
||||
(i, per_sec)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
self.tx_per_sec.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.dateindex,
|
||||
&count_vecs.tx_count.dateindex.sum_cum.sum.0,
|
||||
&indexes.dateindex.date,
|
||||
|(i, tx_count, date, ..)| {
|
||||
let completion = date.completion();
|
||||
let per_sec = if completion == 0.0 {
|
||||
StoredF32::NAN
|
||||
} else {
|
||||
StoredF32::from(*tx_count as f64 / (completion * ONE_DAY_IN_SEC_F64))
|
||||
};
|
||||
(i, per_sec)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_inputs_per_sec.compute_all(starting_indexes, exit, |v| {
|
||||
self.inputs_per_sec
|
||||
.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.dateindex,
|
||||
&inputs_count.indexes_to_count.dateindex.sum_cum.sum.0,
|
||||
&indexes.time.dateindex_to_date,
|
||||
&inputs_count.dateindex.sum_cum.sum.0,
|
||||
&indexes.dateindex.date,
|
||||
|(i, input_count, date, ..)| {
|
||||
let completion = date.completion();
|
||||
let per_sec = if completion == 0.0 {
|
||||
@@ -104,17 +97,20 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_outputs_per_sec.compute_all(starting_indexes, exit, |v| {
|
||||
self.outputs_per_sec
|
||||
.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.dateindex,
|
||||
&outputs_count.indexes_to_count.dateindex.sum_cum.sum.0,
|
||||
&indexes.time.dateindex_to_date,
|
||||
&outputs_count.total_count.dateindex.sum_cum.sum.0,
|
||||
&indexes.dateindex.date,
|
||||
|(i, output_count, date, ..)| {
|
||||
let completion = date.completion();
|
||||
let per_sec = if completion == 0.0 {
|
||||
StoredF32::NAN
|
||||
} else {
|
||||
StoredF32::from(*output_count as f64 / (completion * ONE_DAY_IN_SEC_F64))
|
||||
StoredF32::from(
|
||||
*output_count as f64 / (completion * ONE_DAY_IN_SEC_F64),
|
||||
)
|
||||
};
|
||||
(i, per_sec)
|
||||
},
|
||||
|
||||
@@ -3,10 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedDateLast, ValueBlockSum},
|
||||
};
|
||||
use crate::{indexes, internal::{ComputedDateLast, ValueBlockSum, ValueDateLast}};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -18,44 +15,28 @@ impl Vecs {
|
||||
let v2 = Version::TWO;
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_sent_sum: ValueBlockSum::forced_import(
|
||||
sent_sum: ValueBlockSum::forced_import(
|
||||
db,
|
||||
"sent_sum",
|
||||
version,
|
||||
indexes,
|
||||
compute_dollars,
|
||||
)?,
|
||||
indexes_to_annualized_volume: ComputedDateLast::forced_import(
|
||||
annualized_volume: ValueDateLast::forced_import(
|
||||
db,
|
||||
"annualized_volume",
|
||||
version,
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_annualized_volume_btc: ComputedDateLast::forced_import(
|
||||
db,
|
||||
"annualized_volume_btc",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_annualized_volume_usd: ComputedDateLast::forced_import(
|
||||
db,
|
||||
"annualized_volume_usd",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_tx_per_sec: ComputedDateLast::forced_import(
|
||||
db,
|
||||
"tx_per_sec",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_outputs_per_sec: ComputedDateLast::forced_import(
|
||||
tx_per_sec: ComputedDateLast::forced_import(db, "tx_per_sec", version + v2, indexes)?,
|
||||
outputs_per_sec: ComputedDateLast::forced_import(
|
||||
db,
|
||||
"outputs_per_sec",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_inputs_per_sec: ComputedDateLast::forced_import(
|
||||
inputs_per_sec: ComputedDateLast::forced_import(
|
||||
db,
|
||||
"inputs_per_sec",
|
||||
version + v2,
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Sats, StoredF32};
|
||||
use brk_types::StoredF32;
|
||||
|
||||
use crate::internal::{ComputedDateLast, ValueBlockSum};
|
||||
use crate::internal::{ComputedDateLast, ValueBlockSum, ValueDateLast};
|
||||
|
||||
/// Volume metrics
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub indexes_to_sent_sum: ValueBlockSum,
|
||||
pub indexes_to_annualized_volume: ComputedDateLast<Sats>,
|
||||
pub indexes_to_annualized_volume_btc: ComputedDateLast<Bitcoin>,
|
||||
pub indexes_to_annualized_volume_usd: ComputedDateLast<Dollars>,
|
||||
pub indexes_to_tx_per_sec: ComputedDateLast<StoredF32>,
|
||||
pub indexes_to_outputs_per_sec: ComputedDateLast<StoredF32>,
|
||||
pub indexes_to_inputs_per_sec: ComputedDateLast<StoredF32>,
|
||||
pub sent_sum: ValueBlockSum,
|
||||
pub annualized_volume: ValueDateLast,
|
||||
pub tx_per_sec: ComputedDateLast<StoredF32>,
|
||||
pub outputs_per_sec: ComputedDateLast<StoredF32>,
|
||||
pub inputs_per_sec: ComputedDateLast<StoredF32>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user