mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 22:59:58 -07:00
global: snapshot
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{Bitcoin, CheckedSub, Indexes, StoredF64};
|
||||
use brk_types::{Bitcoin, Indexes, StoredF64};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
@@ -30,8 +30,8 @@ impl Vecs {
|
||||
.compute(starting_indexes.height, exit, |vec| {
|
||||
vec.compute_subtract(
|
||||
starting_indexes.height,
|
||||
&self.coinblocks_created.raw.height,
|
||||
&distribution.coinblocks_destroyed.raw.height,
|
||||
&self.coinblocks_created.base.height,
|
||||
&distribution.coinblocks_destroyed.base.height,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
@@ -44,13 +44,6 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.vaultedness.height.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.liveliness.height,
|
||||
|(i, v, ..)| (i, StoredF64::from(1.0).checked_sub(v).unwrap()),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.ratio.height.compute_divide(
|
||||
starting_indexes.height,
|
||||
&self.liveliness.height,
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
use vecdb::{Database, ReadableCloneableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, ComputedPerBlock, ComputedPerBlockCumulativeWithSums},
|
||||
internal::{
|
||||
CachedWindowStarts, LazyPerBlock, OneMinusF64, PerBlock, PerBlockCumulativeWithSums,
|
||||
},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -15,29 +17,25 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let liveliness = PerBlock::forced_import(db, "liveliness", version, indexes)?;
|
||||
|
||||
let vaultedness = LazyPerBlock::from_computed::<OneMinusF64>(
|
||||
"vaultedness",
|
||||
version,
|
||||
liveliness.height.read_only_boxed_clone(),
|
||||
&liveliness,
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
coinblocks_created: ComputedPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"coinblocks_created",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
coinblocks_created: PerBlockCumulativeWithSums::forced_import(
|
||||
db, "coinblocks_created", version, indexes, cached_starts,
|
||||
)?,
|
||||
coinblocks_stored: ComputedPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"coinblocks_stored",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
liveliness: ComputedPerBlock::forced_import(db, "liveliness", version, indexes)?,
|
||||
vaultedness: ComputedPerBlock::forced_import(db, "vaultedness", version, indexes)?,
|
||||
ratio: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"activity_to_vaultedness_ratio",
|
||||
version,
|
||||
indexes,
|
||||
coinblocks_stored: PerBlockCumulativeWithSums::forced_import(
|
||||
db, "coinblocks_stored", version, indexes, cached_starts,
|
||||
)?,
|
||||
liveliness,
|
||||
vaultedness,
|
||||
ratio: PerBlock::forced_import(db, "activity_to_vaultedness_ratio", version, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredF64;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedPerBlock, ComputedPerBlockCumulativeWithSums};
|
||||
use crate::internal::{LazyPerBlock, PerBlock, PerBlockCumulativeWithSums};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub coinblocks_created: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub coinblocks_stored: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub liveliness: ComputedPerBlock<StoredF64, M>,
|
||||
pub vaultedness: ComputedPerBlock<StoredF64, M>,
|
||||
pub ratio: ComputedPerBlock<StoredF64, M>,
|
||||
pub coinblocks_created: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub coinblocks_stored: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub liveliness: PerBlock<StoredF64, M>,
|
||||
pub vaultedness: LazyPerBlock<StoredF64>,
|
||||
pub ratio: PerBlock<StoredF64, M>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedPerBlock, PercentPerBlock},
|
||||
internal::{PerBlock, PercentPerBlock},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -21,13 +21,13 @@ impl Vecs {
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
tx_velocity_btc: ComputedPerBlock::forced_import(
|
||||
tx_velocity_btc: PerBlock::forced_import(
|
||||
db,
|
||||
"cointime_adj_tx_velocity_btc",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
tx_velocity_usd: ComputedPerBlock::forced_import(
|
||||
tx_velocity_usd: PerBlock::forced_import(
|
||||
db,
|
||||
"cointime_adj_tx_velocity_usd",
|
||||
version,
|
||||
|
||||
@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPointsSigned32, StoredF64};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedPerBlock, PercentPerBlock};
|
||||
use crate::internal::{PerBlock, PercentPerBlock};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub inflation_rate: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
pub tx_velocity_btc: ComputedPerBlock<StoredF64, M>,
|
||||
pub tx_velocity_usd: ComputedPerBlock<StoredF64, M>,
|
||||
pub tx_velocity_btc: PerBlock<StoredF64, M>,
|
||||
pub tx_velocity_usd: PerBlock<StoredF64, M>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use brk_types::Version;
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{finalize_db, open_db},
|
||||
internal::db_utils::{finalize_db, open_db},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedPerBlock, PriceWithRatioExtendedPerBlock},
|
||||
internal::{PerBlock, PriceWithRatioExtendedPerBlock},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -29,7 +29,7 @@ impl Vecs {
|
||||
balanced: import!("balanced_price"),
|
||||
terminal: import!("terminal_price"),
|
||||
delta: import!("delta_price"),
|
||||
cumulative_market_cap: ComputedPerBlock::forced_import(
|
||||
cumulative_market_cap: PerBlock::forced_import(
|
||||
db,
|
||||
"cumulative_market_cap",
|
||||
version,
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::Dollars;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedPerBlock, PriceWithRatioExtendedPerBlock};
|
||||
use crate::internal::{PerBlock, PriceWithRatioExtendedPerBlock};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
@@ -15,5 +15,5 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub terminal: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub delta: PriceWithRatioExtendedPerBlock<M>,
|
||||
|
||||
pub cumulative_market_cap: ComputedPerBlock<Dollars, M>,
|
||||
pub cumulative_market_cap: PerBlock<Dollars, M>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::{Indexes, StoredF64};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::{super::value, Vecs};
|
||||
use crate::{blocks, internal::ComputeRollingMedianFromStarts, prices};
|
||||
use crate::{blocks, internal::algo::ComputeRollingMedianFromStarts, prices};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
@@ -17,7 +17,7 @@ impl Vecs {
|
||||
self.vocdd_median_1y.compute_rolling_median_from_starts(
|
||||
starting_indexes.height,
|
||||
&blocks.lookback._1y,
|
||||
&value.vocdd.raw.height,
|
||||
&value.vocdd.base.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::{Database, EagerVec, ImportableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedPerBlock};
|
||||
use crate::{indexes, internal::PerBlock};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -15,7 +15,7 @@ impl Vecs {
|
||||
Ok(Self {
|
||||
vocdd_median_1y: EagerVec::forced_import(db, "vocdd_median_1y", v1)?,
|
||||
hodl_bank: EagerVec::forced_import(db, "hodl_bank", v1)?,
|
||||
value: ComputedPerBlock::forced_import(db, "reserve_risk", v1, indexes)?,
|
||||
value: PerBlock::forced_import(db, "reserve_risk", v1, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredF64};
|
||||
use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedPerBlock;
|
||||
use crate::internal::PerBlock;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub value: ComputedPerBlock<StoredF64, M>,
|
||||
pub value: PerBlock<StoredF64, M>,
|
||||
pub vocdd_median_1y: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
|
||||
pub hodl_bank: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ impl Vecs {
|
||||
vec.compute_multiply(
|
||||
starting_indexes.height,
|
||||
&prices.spot.usd.height,
|
||||
&coinblocks_destroyed.raw.height,
|
||||
&coinblocks_destroyed.base.height,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
@@ -36,7 +36,7 @@ impl Vecs {
|
||||
vec.compute_multiply(
|
||||
starting_indexes.height,
|
||||
&prices.spot.usd.height,
|
||||
&activity.coinblocks_created.raw.height,
|
||||
&activity.coinblocks_created.base.height,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
@@ -47,7 +47,7 @@ impl Vecs {
|
||||
vec.compute_multiply(
|
||||
starting_indexes.height,
|
||||
&prices.spot.usd.height,
|
||||
&activity.coinblocks_stored.raw.height,
|
||||
&activity.coinblocks_stored.base.height,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
@@ -61,7 +61,7 @@ impl Vecs {
|
||||
vec.compute_transform3(
|
||||
starting_indexes.height,
|
||||
&prices.spot.usd.height,
|
||||
&coindays_destroyed.raw.height,
|
||||
&coindays_destroyed.base.height,
|
||||
circulating_supply,
|
||||
|(i, price, cdd, supply, _): (_, Dollars, StoredF64, Bitcoin, _)| {
|
||||
let supply_f64 = f64::from(supply);
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, ComputedPerBlockCumulativeWithSums},
|
||||
internal::{CachedWindowStarts, PerBlockCumulativeWithSums},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -16,28 +16,28 @@ impl Vecs {
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
destroyed: ComputedPerBlockCumulativeWithSums::forced_import(
|
||||
destroyed: PerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"cointime_value_destroyed",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
created: ComputedPerBlockCumulativeWithSums::forced_import(
|
||||
created: PerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"cointime_value_created",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
stored: ComputedPerBlockCumulativeWithSums::forced_import(
|
||||
stored: PerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"cointime_value_stored",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
vocdd: ComputedPerBlockCumulativeWithSums::forced_import(
|
||||
vocdd: PerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"vocdd",
|
||||
version + Version::ONE,
|
||||
|
||||
@@ -2,12 +2,12 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredF64;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedPerBlockCumulativeWithSums;
|
||||
use crate::internal::PerBlockCumulativeWithSums;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub destroyed: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub created: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub stored: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub vocdd: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub created: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub stored: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub vocdd: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user