mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-28 16:49:58 -07:00
global: big snapshot
This commit is contained in:
@@ -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