mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-28 16:49:58 -07:00
global: MASSIVE snapshot
This commit is contained in:
134
crates/brk_computer/src/transactions/volume/compute.rs
Normal file
134
crates/brk_computer/src/transactions/volume/compute.rs
Normal file
@@ -0,0 +1,134 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{StoredF32, ONE_DAY_IN_SEC_F64};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use super::super::{count, fees};
|
||||
use crate::{indexes, inputs, outputs, price, ComputeIndexes};
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
count_vecs: &count::Vecs,
|
||||
fees_vecs: &fees::Vecs,
|
||||
inputs_count: &inputs::CountVecs,
|
||||
outputs_count: &outputs::CountVecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_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,
|
||||
|sats| !sats.is_max(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_annualized_volume
|
||||
.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_sum(
|
||||
starting_indexes.dateindex,
|
||||
self.indexes_to_sent_sum.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_sum.bitcoin.dateindex.unwrap_sum(),
|
||||
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.unwrap_sum(),
|
||||
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.unwrap_sum(),
|
||||
&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.indexes_to_inputs_per_sec
|
||||
.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.dateindex,
|
||||
inputs_count.indexes_to_count.dateindex.unwrap_sum(),
|
||||
&indexes.time.dateindex_to_date,
|
||||
|(i, input_count, date, ..)| {
|
||||
let completion = date.completion();
|
||||
let per_sec = if completion == 0.0 {
|
||||
StoredF32::NAN
|
||||
} else {
|
||||
StoredF32::from(*input_count as f64 / (completion * ONE_DAY_IN_SEC_F64))
|
||||
};
|
||||
(i, per_sec)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_outputs_per_sec
|
||||
.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.dateindex,
|
||||
outputs_count.indexes_to_count.dateindex.unwrap_sum(),
|
||||
&indexes.time.dateindex_to_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))
|
||||
};
|
||||
(i, per_sec)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
82
crates/brk_computer/src/transactions/volume/import.rs
Normal file
82
crates/brk_computer/src/transactions/volume/import.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
internal::{ComputedValueVecsFromHeight, ComputedVecsFromDateIndex, Source, VecBuilderOptions},
|
||||
indexes,
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
compute_dollars: bool,
|
||||
) -> Result<Self> {
|
||||
let v0 = Version::ZERO;
|
||||
let v2 = Version::TWO;
|
||||
let last = || VecBuilderOptions::default().add_last();
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_sent_sum: ComputedValueVecsFromHeight::forced_import(
|
||||
db,
|
||||
"sent_sum",
|
||||
Source::Compute,
|
||||
version + v0,
|
||||
VecBuilderOptions::default().add_sum(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_annualized_volume: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
"annualized_volume",
|
||||
Source::Compute,
|
||||
version + v0,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
indexes_to_annualized_volume_btc: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
"annualized_volume_btc",
|
||||
Source::Compute,
|
||||
version + v0,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
indexes_to_annualized_volume_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
"annualized_volume_usd",
|
||||
Source::Compute,
|
||||
version + v0,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
indexes_to_tx_per_sec: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
"tx_per_sec",
|
||||
Source::Compute,
|
||||
version + v2,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
indexes_to_outputs_per_sec: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
"outputs_per_sec",
|
||||
Source::Compute,
|
||||
version + v2,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
indexes_to_inputs_per_sec: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
"inputs_per_sec",
|
||||
Source::Compute,
|
||||
version + v2,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
5
crates/brk_computer/src/transactions/volume/mod.rs
Normal file
5
crates/brk_computer/src/transactions/volume/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
mod compute;
|
||||
mod import;
|
||||
mod vecs;
|
||||
|
||||
pub use vecs::Vecs;
|
||||
16
crates/brk_computer/src/transactions/volume/vecs.rs
Normal file
16
crates/brk_computer/src/transactions/volume/vecs.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Sats, StoredF32};
|
||||
|
||||
use crate::internal::{ComputedValueVecsFromHeight, ComputedVecsFromDateIndex};
|
||||
|
||||
/// Volume metrics
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub indexes_to_sent_sum: ComputedValueVecsFromHeight,
|
||||
pub indexes_to_annualized_volume: ComputedVecsFromDateIndex<Sats>,
|
||||
pub indexes_to_annualized_volume_btc: ComputedVecsFromDateIndex<Bitcoin>,
|
||||
pub indexes_to_annualized_volume_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub indexes_to_tx_per_sec: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub indexes_to_outputs_per_sec: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub indexes_to_inputs_per_sec: ComputedVecsFromDateIndex<StoredF32>,
|
||||
}
|
||||
Reference in New Issue
Block a user