mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
computer: snapshot
This commit is contained in:
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{BlockCountTarget, ComputedFromHeightCumulativeSum, ConstantVecs},
|
||||
internal::{BlockCountTarget, ComputedPerBlockCumulativeSum, ConstantVecs},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -20,7 +20,7 @@ impl Vecs {
|
||||
version,
|
||||
indexes,
|
||||
),
|
||||
block_count: ComputedFromHeightCumulativeSum::forced_import(
|
||||
block_count: ComputedPerBlockCumulativeSum::forced_import(
|
||||
db,
|
||||
"block_count",
|
||||
version,
|
||||
|
||||
@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{StoredU32, StoredU64};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightCumulativeSum, ConstantVecs};
|
||||
use crate::internal::{ComputedPerBlockCumulativeSum, ConstantVecs};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub block_count_target: ConstantVecs<StoredU64>,
|
||||
pub block_count: ComputedFromHeightCumulativeSum<StoredU32, M>,
|
||||
pub block_count: ComputedPerBlockCumulativeSum<StoredU32, M>,
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ impl Vecs {
|
||||
// Compute epoch by height
|
||||
self.epoch.height.compute_transform(
|
||||
starting_indexes.height,
|
||||
&indexes.height.difficultyepoch,
|
||||
&indexes.height.difficulty,
|
||||
|(h, epoch, ..)| (h, epoch),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{Database, ReadableCloneableVec};
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeight, ComputedHeightDerived, PercentFromHeight},
|
||||
internal::{ComputedPerBlock, Resolutions, PercentPerBlock},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -19,27 +19,27 @@ impl Vecs {
|
||||
let v2 = Version::TWO;
|
||||
|
||||
Ok(Self {
|
||||
raw: ComputedHeightDerived::forced_import(
|
||||
raw: Resolutions::forced_import(
|
||||
"difficulty",
|
||||
indexer.vecs.blocks.difficulty.read_only_boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
),
|
||||
as_hash: ComputedFromHeight::forced_import(db, "difficulty_as_hash", version, indexes)?,
|
||||
adjustment: PercentFromHeight::forced_import(
|
||||
as_hash: ComputedPerBlock::forced_import(db, "difficulty_as_hash", version, indexes)?,
|
||||
adjustment: PercentPerBlock::forced_import(
|
||||
db,
|
||||
"difficulty_adjustment",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
epoch: ComputedFromHeight::forced_import(db, "difficulty_epoch", version, indexes)?,
|
||||
blocks_before_next_adjustment: ComputedFromHeight::forced_import(
|
||||
epoch: ComputedPerBlock::forced_import(db, "difficulty_epoch", version, indexes)?,
|
||||
blocks_before_next_adjustment: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"blocks_before_next_difficulty_adjustment",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
days_before_next_adjustment: ComputedFromHeight::forced_import(
|
||||
days_before_next_adjustment: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"days_before_next_difficulty_adjustment",
|
||||
version + v2,
|
||||
|
||||
@@ -2,13 +2,13 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPointsSigned32, DifficultyEpoch, StoredF32, StoredF64, StoredU32};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeight, ComputedHeightDerived, PercentFromHeight};
|
||||
use crate::internal::{ComputedPerBlock, Resolutions, PercentPerBlock};
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub raw: ComputedHeightDerived<StoredF64>,
|
||||
pub as_hash: ComputedFromHeight<StoredF64, M>,
|
||||
pub adjustment: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub epoch: ComputedFromHeight<DifficultyEpoch, M>,
|
||||
pub blocks_before_next_adjustment: ComputedFromHeight<StoredU32, M>,
|
||||
pub days_before_next_adjustment: ComputedFromHeight<StoredF32, M>,
|
||||
pub raw: Resolutions<StoredF64>,
|
||||
pub as_hash: ComputedPerBlock<StoredF64, M>,
|
||||
pub adjustment: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
pub epoch: ComputedPerBlock<DifficultyEpoch, M>,
|
||||
pub blocks_before_next_adjustment: ComputedPerBlock<StoredU32, M>,
|
||||
pub days_before_next_adjustment: ComputedPerBlock<StoredF32, M>,
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ impl Vecs {
|
||||
) -> Result<()> {
|
||||
self.epoch.height.compute_transform(
|
||||
starting_indexes.height,
|
||||
&indexes.height.halvingepoch,
|
||||
&indexes.height.halving,
|
||||
|(h, epoch, ..)| (h, epoch),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromHeight};
|
||||
use crate::{indexes, internal::ComputedPerBlock};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -14,14 +14,14 @@ impl Vecs {
|
||||
let v2 = Version::TWO;
|
||||
|
||||
Ok(Self {
|
||||
epoch: ComputedFromHeight::forced_import(db, "halving_epoch", version, indexes)?,
|
||||
blocks_before_next_halving: ComputedFromHeight::forced_import(
|
||||
epoch: ComputedPerBlock::forced_import(db, "halving_epoch", version, indexes)?,
|
||||
blocks_before_next_halving: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"blocks_before_next_halving",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
days_before_next_halving: ComputedFromHeight::forced_import(
|
||||
days_before_next_halving: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"days_before_next_halving",
|
||||
version + v2,
|
||||
|
||||
@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{HalvingEpoch, StoredF32, StoredU32};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedFromHeight;
|
||||
use crate::internal::ComputedPerBlock;
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub epoch: ComputedFromHeight<HalvingEpoch, M>,
|
||||
pub blocks_before_next_halving: ComputedFromHeight<StoredU32, M>,
|
||||
pub days_before_next_halving: ComputedFromHeight<StoredF32, M>,
|
||||
pub epoch: ComputedPerBlock<HalvingEpoch, M>,
|
||||
pub blocks_before_next_halving: ComputedPerBlock<StoredU32, M>,
|
||||
pub days_before_next_halving: ComputedPerBlock<StoredF32, M>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromHeightRollingAverage};
|
||||
use crate::{indexes, internal::ComputedPerBlockRollingAverage};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -11,7 +11,7 @@ impl Vecs {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let interval = ComputedFromHeightRollingAverage::forced_import(
|
||||
let interval = ComputedPerBlockRollingAverage::forced_import(
|
||||
db,
|
||||
"block_interval",
|
||||
version,
|
||||
|
||||
@@ -4,9 +4,9 @@ use brk_traversable::Traversable;
|
||||
use brk_types::Timestamp;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedFromHeightRollingAverage;
|
||||
use crate::internal::ComputedPerBlockRollingAverage;
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw>(
|
||||
#[traversable(flatten)] pub ComputedFromHeightRollingAverage<Timestamp, M>,
|
||||
#[traversable(flatten)] pub ComputedPerBlockRollingAverage<Timestamp, M>,
|
||||
);
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightFull, ComputedHeightDerivedFull},
|
||||
internal::{ComputedPerBlockFull, ResolutionsFull},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -15,8 +15,8 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
vbytes: ComputedFromHeightFull::forced_import(db, "block_vbytes", version, indexes)?,
|
||||
size: ComputedHeightDerivedFull::forced_import(db, "block_size", version, indexes)?,
|
||||
vbytes: ComputedPerBlockFull::forced_import(db, "block_vbytes", version, indexes)?,
|
||||
size: ResolutionsFull::forced_import(db, "block_size", version, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredU64;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightFull, ComputedHeightDerivedFull};
|
||||
use crate::internal::{ComputedPerBlockFull, ResolutionsFull};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub vbytes: ComputedFromHeightFull<StoredU64, M>,
|
||||
pub size: ComputedHeightDerivedFull<StoredU64, M>,
|
||||
pub vbytes: ComputedPerBlockFull<StoredU64, M>,
|
||||
pub size: ResolutionsFull<StoredU64, M>,
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ impl TimestampIndexes {
|
||||
};
|
||||
}
|
||||
|
||||
Ok(Self(crate::internal::PerPeriod {
|
||||
Ok(Self(crate::internal::PerResolution {
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
@@ -59,8 +59,8 @@ impl TimestampIndexes {
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: epoch!(halvingepoch),
|
||||
difficultyepoch: epoch!(difficultyepoch),
|
||||
halving: epoch!(halving),
|
||||
difficulty: epoch!(difficulty),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use brk_types::{
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{EagerVec, Exit, LazyVecFrom1, PcoVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{indexes, internal::PerPeriod};
|
||||
use crate::{indexes, internal::PerResolution};
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub date: LazyVecFrom1<Height, Date, Height, Timestamp>,
|
||||
@@ -19,13 +19,13 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
///
|
||||
/// Time-based periods (minute10–year10) are lazy: `idx.to_timestamp()` is a pure
|
||||
/// function of the index, so no storage or decompression is needed.
|
||||
/// Epoch-based periods (halvingepoch, difficultyepoch) are eager: their timestamps
|
||||
/// Epoch-based periods (halving, difficulty) are eager: their timestamps
|
||||
/// come from block data via `compute_indirect_sequential`.
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct TimestampIndexes<M: StorageMode = Rw>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub PerPeriod<
|
||||
pub PerResolution<
|
||||
LazyVecFrom1<Minute10, Timestamp, Minute10, Height>,
|
||||
LazyVecFrom1<Minute30, Timestamp, Minute30, Height>,
|
||||
LazyVecFrom1<Hour1, Timestamp, Hour1, Height>,
|
||||
@@ -55,23 +55,23 @@ impl TimestampIndexes {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let prev_height = starting_indexes.height.decremented().unwrap_or_default();
|
||||
self.halvingepoch.compute_indirect_sequential(
|
||||
self.halving.compute_indirect_sequential(
|
||||
indexes
|
||||
.height
|
||||
.halvingepoch
|
||||
.halving
|
||||
.collect_one(prev_height)
|
||||
.unwrap_or_default(),
|
||||
&indexes.halvingepoch.first_height,
|
||||
&indexes.halving.first_height,
|
||||
&indexer.vecs.blocks.timestamp,
|
||||
exit,
|
||||
)?;
|
||||
self.difficultyepoch.compute_indirect_sequential(
|
||||
self.difficulty.compute_indirect_sequential(
|
||||
indexes
|
||||
.height
|
||||
.difficultyepoch
|
||||
.difficulty
|
||||
.collect_one(prev_height)
|
||||
.unwrap_or_default(),
|
||||
&indexes.difficultyepoch.first_height,
|
||||
&indexes.difficulty.first_height,
|
||||
&indexer.vecs.blocks.timestamp,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedHeightDerivedFull, PercentFromHeightRollingAverage},
|
||||
internal::{ResolutionsFull, PercentPerBlockRollingAverage},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -15,9 +15,9 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let weight =
|
||||
ComputedHeightDerivedFull::forced_import(db, "block_weight", version, indexes)?;
|
||||
ResolutionsFull::forced_import(db, "block_weight", version, indexes)?;
|
||||
|
||||
let fullness = PercentFromHeightRollingAverage::forced_import(
|
||||
let fullness = PercentPerBlockRollingAverage::forced_import(
|
||||
db,
|
||||
"block_fullness",
|
||||
version,
|
||||
|
||||
@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPoints16, Weight};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedHeightDerivedFull, PercentFromHeightRollingAverage};
|
||||
use crate::internal::{ResolutionsFull, PercentPerBlockRollingAverage};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub weight: ComputedHeightDerivedFull<Weight, M>,
|
||||
pub fullness: PercentFromHeightRollingAverage<BasisPoints16, M>,
|
||||
pub weight: ResolutionsFull<Weight, M>,
|
||||
pub fullness: PercentPerBlockRollingAverage<BasisPoints16, M>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeight, ComputedFromHeightCumulativeSum},
|
||||
internal::{ComputedPerBlock, ComputedPerBlockCumulativeSum},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -15,21 +15,21 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
coinblocks_created: ComputedFromHeightCumulativeSum::forced_import(
|
||||
coinblocks_created: ComputedPerBlockCumulativeSum::forced_import(
|
||||
db,
|
||||
"coinblocks_created",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
coinblocks_stored: ComputedFromHeightCumulativeSum::forced_import(
|
||||
coinblocks_stored: ComputedPerBlockCumulativeSum::forced_import(
|
||||
db,
|
||||
"coinblocks_stored",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
liveliness: ComputedFromHeight::forced_import(db, "liveliness", version, indexes)?,
|
||||
vaultedness: ComputedFromHeight::forced_import(db, "vaultedness", version, indexes)?,
|
||||
activity_to_vaultedness_ratio: ComputedFromHeight::forced_import(
|
||||
liveliness: ComputedPerBlock::forced_import(db, "liveliness", version, indexes)?,
|
||||
vaultedness: ComputedPerBlock::forced_import(db, "vaultedness", version, indexes)?,
|
||||
activity_to_vaultedness_ratio: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"activity_to_vaultedness_ratio",
|
||||
version,
|
||||
|
||||
@@ -2,13 +2,13 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredF64;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeight, ComputedFromHeightCumulativeSum};
|
||||
use crate::internal::{ComputedPerBlock, ComputedPerBlockCumulativeSum};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub coinblocks_created: ComputedFromHeightCumulativeSum<StoredF64, M>,
|
||||
pub coinblocks_stored: ComputedFromHeightCumulativeSum<StoredF64, M>,
|
||||
pub liveliness: ComputedFromHeight<StoredF64, M>,
|
||||
pub vaultedness: ComputedFromHeight<StoredF64, M>,
|
||||
pub activity_to_vaultedness_ratio: ComputedFromHeight<StoredF64, M>,
|
||||
pub coinblocks_created: ComputedPerBlockCumulativeSum<StoredF64, M>,
|
||||
pub coinblocks_stored: ComputedPerBlockCumulativeSum<StoredF64, M>,
|
||||
pub liveliness: ComputedPerBlock<StoredF64, M>,
|
||||
pub vaultedness: ComputedPerBlock<StoredF64, M>,
|
||||
pub activity_to_vaultedness_ratio: ComputedPerBlock<StoredF64, M>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeight, PercentFromHeight},
|
||||
internal::{ComputedPerBlock, PercentPerBlock},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -15,19 +15,19 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
cointime_adj_inflation_rate: PercentFromHeight::forced_import(
|
||||
cointime_adj_inflation_rate: PercentPerBlock::forced_import(
|
||||
db,
|
||||
"cointime_adj_inflation_rate",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
cointime_adj_tx_velocity_btc: ComputedFromHeight::forced_import(
|
||||
cointime_adj_tx_velocity_btc: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"cointime_adj_tx_velocity_btc",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
cointime_adj_tx_velocity_usd: ComputedFromHeight::forced_import(
|
||||
cointime_adj_tx_velocity_usd: ComputedPerBlock::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::{ComputedFromHeight, PercentFromHeight};
|
||||
use crate::internal::{ComputedPerBlock, PercentPerBlock};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub cointime_adj_inflation_rate: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub cointime_adj_tx_velocity_btc: ComputedFromHeight<StoredF64, M>,
|
||||
pub cointime_adj_tx_velocity_usd: ComputedFromHeight<StoredF64, M>,
|
||||
pub cointime_adj_inflation_rate: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
pub cointime_adj_tx_velocity_btc: ComputedPerBlock<StoredF64, M>,
|
||||
pub cointime_adj_tx_velocity_usd: ComputedPerBlock<StoredF64, M>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::FiatFromHeight};
|
||||
use crate::{indexes, internal::FiatPerBlock};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -12,11 +12,11 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
thermo_cap: FiatFromHeight::forced_import(db, "thermo_cap", version, indexes)?,
|
||||
investor_cap: FiatFromHeight::forced_import(db, "investor_cap", version, indexes)?,
|
||||
vaulted_cap: FiatFromHeight::forced_import(db, "vaulted_cap", version, indexes)?,
|
||||
active_cap: FiatFromHeight::forced_import(db, "active_cap", version, indexes)?,
|
||||
cointime_cap: FiatFromHeight::forced_import(db, "cointime_cap", version, indexes)?,
|
||||
thermo_cap: FiatPerBlock::forced_import(db, "thermo_cap", version, indexes)?,
|
||||
investor_cap: FiatPerBlock::forced_import(db, "investor_cap", version, indexes)?,
|
||||
vaulted_cap: FiatPerBlock::forced_import(db, "vaulted_cap", version, indexes)?,
|
||||
active_cap: FiatPerBlock::forced_import(db, "active_cap", version, indexes)?,
|
||||
cointime_cap: FiatPerBlock::forced_import(db, "cointime_cap", version, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ use brk_traversable::Traversable;
|
||||
use brk_types::Cents;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::FiatFromHeight;
|
||||
use crate::internal::FiatPerBlock;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub thermo_cap: FiatFromHeight<Cents, M>,
|
||||
pub investor_cap: FiatFromHeight<Cents, M>,
|
||||
pub vaulted_cap: FiatFromHeight<Cents, M>,
|
||||
pub active_cap: FiatFromHeight<Cents, M>,
|
||||
pub cointime_cap: FiatFromHeight<Cents, M>,
|
||||
pub thermo_cap: FiatPerBlock<Cents, M>,
|
||||
pub investor_cap: FiatPerBlock<Cents, M>,
|
||||
pub vaulted_cap: FiatPerBlock<Cents, M>,
|
||||
pub active_cap: FiatPerBlock<Cents, M>,
|
||||
pub cointime_cap: FiatPerBlock<Cents, M>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightRatioExtended, Price},
|
||||
internal::{RatioPerBlockExtended, Price},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -16,14 +16,14 @@ impl Vecs {
|
||||
) -> Result<Self> {
|
||||
let vaulted_price = Price::forced_import(db, "vaulted_price", version, indexes)?;
|
||||
let vaulted_price_ratio =
|
||||
ComputedFromHeightRatioExtended::forced_import(db, "vaulted_price", version, indexes)?;
|
||||
RatioPerBlockExtended::forced_import(db, "vaulted_price", version, indexes)?;
|
||||
|
||||
let active_price = Price::forced_import(db, "active_price", version, indexes)?;
|
||||
let active_price_ratio =
|
||||
ComputedFromHeightRatioExtended::forced_import(db, "active_price", version, indexes)?;
|
||||
RatioPerBlockExtended::forced_import(db, "active_price", version, indexes)?;
|
||||
|
||||
let true_market_mean = Price::forced_import(db, "true_market_mean", version, indexes)?;
|
||||
let true_market_mean_ratio = ComputedFromHeightRatioExtended::forced_import(
|
||||
let true_market_mean_ratio = RatioPerBlockExtended::forced_import(
|
||||
db,
|
||||
"true_market_mean",
|
||||
version,
|
||||
@@ -32,7 +32,7 @@ impl Vecs {
|
||||
|
||||
let cointime_price = Price::forced_import(db, "cointime_price", version, indexes)?;
|
||||
let cointime_price_ratio =
|
||||
ComputedFromHeightRatioExtended::forced_import(db, "cointime_price", version, indexes)?;
|
||||
RatioPerBlockExtended::forced_import(db, "cointime_price", version, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
vaulted_price,
|
||||
|
||||
@@ -2,16 +2,16 @@ use brk_traversable::Traversable;
|
||||
use brk_types::Cents;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeight, ComputedFromHeightRatioExtended, Price};
|
||||
use crate::internal::{ComputedPerBlock, RatioPerBlockExtended, Price};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub vaulted_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub vaulted_price_ratio: ComputedFromHeightRatioExtended<M>,
|
||||
pub active_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub active_price_ratio: ComputedFromHeightRatioExtended<M>,
|
||||
pub true_market_mean: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub true_market_mean_ratio: ComputedFromHeightRatioExtended<M>,
|
||||
pub cointime_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub cointime_price_ratio: ComputedFromHeightRatioExtended<M>,
|
||||
pub vaulted_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub vaulted_price_ratio: RatioPerBlockExtended<M>,
|
||||
pub active_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub active_price_ratio: RatioPerBlockExtended<M>,
|
||||
pub true_market_mean: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub true_market_mean_ratio: RatioPerBlockExtended<M>,
|
||||
pub cointime_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub cointime_price_ratio: RatioPerBlockExtended<M>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::{Database, EagerVec, ImportableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromHeight};
|
||||
use crate::{indexes, internal::ComputedPerBlock};
|
||||
|
||||
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)?,
|
||||
reserve_risk: ComputedFromHeight::forced_import(db, "reserve_risk", v1, indexes)?,
|
||||
reserve_risk: ComputedPerBlock::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::ComputedFromHeight;
|
||||
use crate::internal::ComputedPerBlock;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub vocdd_median_1y: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
|
||||
pub hodl_bank: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
|
||||
pub reserve_risk: ComputedFromHeight<StoredF64, M>,
|
||||
pub reserve_risk: ComputedPerBlock<StoredF64, M>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::AmountFromHeight};
|
||||
use crate::{indexes, internal::AmountPerBlock};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -12,13 +12,13 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
vaulted_supply: AmountFromHeight::forced_import(
|
||||
vaulted_supply: AmountPerBlock::forced_import(
|
||||
db,
|
||||
"vaulted_supply",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
active_supply: AmountFromHeight::forced_import(db, "active_supply", version, indexes)?,
|
||||
active_supply: AmountPerBlock::forced_import(db, "active_supply", version, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::AmountFromHeight;
|
||||
use crate::internal::AmountPerBlock;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub vaulted_supply: AmountFromHeight<M>,
|
||||
pub active_supply: AmountFromHeight<M>,
|
||||
pub vaulted_supply: AmountPerBlock<M>,
|
||||
pub active_supply: AmountPerBlock<M>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromHeightCumulativeSum};
|
||||
use crate::{indexes, internal::ComputedPerBlockCumulativeSum};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -12,25 +12,25 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
cointime_value_destroyed: ComputedFromHeightCumulativeSum::forced_import(
|
||||
cointime_value_destroyed: ComputedPerBlockCumulativeSum::forced_import(
|
||||
db,
|
||||
"cointime_value_destroyed",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
cointime_value_created: ComputedFromHeightCumulativeSum::forced_import(
|
||||
cointime_value_created: ComputedPerBlockCumulativeSum::forced_import(
|
||||
db,
|
||||
"cointime_value_created",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
cointime_value_stored: ComputedFromHeightCumulativeSum::forced_import(
|
||||
cointime_value_stored: ComputedPerBlockCumulativeSum::forced_import(
|
||||
db,
|
||||
"cointime_value_stored",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
vocdd: ComputedFromHeightCumulativeSum::forced_import(
|
||||
vocdd: ComputedPerBlockCumulativeSum::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::ComputedFromHeightCumulativeSum;
|
||||
use crate::internal::ComputedPerBlockCumulativeSum;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub cointime_value_destroyed: ComputedFromHeightCumulativeSum<StoredF64, M>,
|
||||
pub cointime_value_created: ComputedFromHeightCumulativeSum<StoredF64, M>,
|
||||
pub cointime_value_stored: ComputedFromHeightCumulativeSum<StoredF64, M>,
|
||||
pub vocdd: ComputedFromHeightCumulativeSum<StoredF64, M>,
|
||||
pub cointime_value_destroyed: ComputedPerBlockCumulativeSum<StoredF64, M>,
|
||||
pub cointime_value_created: ComputedPerBlockCumulativeSum<StoredF64, M>,
|
||||
pub cointime_value_stored: ComputedPerBlockCumulativeSum<StoredF64, M>,
|
||||
pub vocdd: ComputedPerBlockCumulativeSum<StoredF64, M>,
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightRollingAverage, WindowStarts},
|
||||
internal::{ComputedPerBlockRollingAverage, WindowStarts},
|
||||
};
|
||||
|
||||
/// Per-block activity counts - reset each block.
|
||||
@@ -65,10 +65,10 @@ impl AddressTypeToActivityCounts {
|
||||
/// Activity count vectors for a single category (e.g., one address type or "all").
|
||||
#[derive(Traversable)]
|
||||
pub struct ActivityCountVecs<M: StorageMode = Rw> {
|
||||
pub reactivated: ComputedFromHeightRollingAverage<StoredU32, M>,
|
||||
pub sending: ComputedFromHeightRollingAverage<StoredU32, M>,
|
||||
pub receiving: ComputedFromHeightRollingAverage<StoredU32, M>,
|
||||
pub both: ComputedFromHeightRollingAverage<StoredU32, M>,
|
||||
pub reactivated: ComputedPerBlockRollingAverage<StoredU32, M>,
|
||||
pub sending: ComputedPerBlockRollingAverage<StoredU32, M>,
|
||||
pub receiving: ComputedPerBlockRollingAverage<StoredU32, M>,
|
||||
pub both: ComputedPerBlockRollingAverage<StoredU32, M>,
|
||||
}
|
||||
|
||||
impl ActivityCountVecs {
|
||||
@@ -79,25 +79,25 @@ impl ActivityCountVecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
reactivated: ComputedFromHeightRollingAverage::forced_import(
|
||||
reactivated: ComputedPerBlockRollingAverage::forced_import(
|
||||
db,
|
||||
&format!("{name}_reactivated"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
sending: ComputedFromHeightRollingAverage::forced_import(
|
||||
sending: ComputedPerBlockRollingAverage::forced_import(
|
||||
db,
|
||||
&format!("{name}_sending"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
receiving: ComputedFromHeightRollingAverage::forced_import(
|
||||
receiving: ComputedPerBlockRollingAverage::forced_import(
|
||||
db,
|
||||
&format!("{name}_receiving"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
both: ComputedFromHeightRollingAverage::forced_import(
|
||||
both: ComputedPerBlockRollingAverage::forced_import(
|
||||
db,
|
||||
&format!("{name}_both"),
|
||||
version,
|
||||
|
||||
@@ -9,11 +9,11 @@ use vecdb::{
|
||||
WritableVec,
|
||||
};
|
||||
|
||||
use crate::{indexes, internal::ComputedFromHeight};
|
||||
use crate::{indexes, internal::ComputedPerBlock};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct AddrCountVecs<M: StorageMode = Rw>(
|
||||
#[traversable(flatten)] pub ComputedFromHeight<StoredU64, M>,
|
||||
#[traversable(flatten)] pub ComputedPerBlock<StoredU64, M>,
|
||||
);
|
||||
|
||||
impl AddrCountVecs {
|
||||
@@ -23,7 +23,7 @@ impl AddrCountVecs {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self(ComputedFromHeight::forced_import(
|
||||
Ok(Self(ComputedPerBlock::forced_import(
|
||||
db, name, version, indexes,
|
||||
)?))
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightSum, WindowStarts},
|
||||
internal::{ComputedPerBlockSum, WindowStarts},
|
||||
};
|
||||
|
||||
use super::TotalAddrCountVecs;
|
||||
@@ -14,9 +14,9 @@ use super::TotalAddrCountVecs;
|
||||
/// New address count per block (global + per-type)
|
||||
#[derive(Traversable)]
|
||||
pub struct NewAddrCountVecs<M: StorageMode = Rw> {
|
||||
pub all: ComputedFromHeightSum<StoredU64, M>,
|
||||
pub all: ComputedPerBlockSum<StoredU64, M>,
|
||||
#[traversable(flatten)]
|
||||
pub by_addresstype: ByAddressType<ComputedFromHeightSum<StoredU64, M>>,
|
||||
pub by_addresstype: ByAddressType<ComputedPerBlockSum<StoredU64, M>>,
|
||||
}
|
||||
|
||||
impl NewAddrCountVecs {
|
||||
@@ -25,11 +25,11 @@ impl NewAddrCountVecs {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let all = ComputedFromHeightSum::forced_import(db, "new_addr_count", version, indexes)?;
|
||||
let all = ComputedPerBlockSum::forced_import(db, "new_addr_count", version, indexes)?;
|
||||
|
||||
let by_addresstype: ByAddressType<ComputedFromHeightSum<StoredU64>> =
|
||||
let by_addresstype: ByAddressType<ComputedPerBlockSum<StoredU64>> =
|
||||
ByAddressType::new_with_name(|name| {
|
||||
ComputedFromHeightSum::forced_import(
|
||||
ComputedPerBlockSum::forced_import(
|
||||
db,
|
||||
&format!("{name}_new_addr_count"),
|
||||
version,
|
||||
|
||||
@@ -4,16 +4,16 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredU64, Version};
|
||||
use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
|
||||
use crate::{indexes, internal::ComputedFromHeight};
|
||||
use crate::{indexes, internal::ComputedPerBlock};
|
||||
|
||||
use super::AddrCountsVecs;
|
||||
|
||||
/// Total address count (global + per-type) with all derived indexes
|
||||
#[derive(Traversable)]
|
||||
pub struct TotalAddrCountVecs<M: StorageMode = Rw> {
|
||||
pub all: ComputedFromHeight<StoredU64, M>,
|
||||
pub all: ComputedPerBlock<StoredU64, M>,
|
||||
#[traversable(flatten)]
|
||||
pub by_addresstype: ByAddressType<ComputedFromHeight<StoredU64, M>>,
|
||||
pub by_addresstype: ByAddressType<ComputedPerBlock<StoredU64, M>>,
|
||||
}
|
||||
|
||||
impl TotalAddrCountVecs {
|
||||
@@ -22,11 +22,11 @@ impl TotalAddrCountVecs {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let all = ComputedFromHeight::forced_import(db, "total_addr_count", version, indexes)?;
|
||||
let all = ComputedPerBlock::forced_import(db, "total_addr_count", version, indexes)?;
|
||||
|
||||
let by_addresstype: ByAddressType<ComputedFromHeight<StoredU64>> =
|
||||
let by_addresstype: ByAddressType<ComputedPerBlock<StoredU64>> =
|
||||
ByAddressType::new_with_name(|name| {
|
||||
ComputedFromHeight::forced_import(
|
||||
ComputedPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_total_addr_count"),
|
||||
version,
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
blocks,
|
||||
distribution::state::{AddressCohortState, MinimalRealizedState},
|
||||
indexes,
|
||||
internal::{ComputedFromHeight, RollingDelta1m},
|
||||
internal::{ComputedPerBlock, RollingDelta1m},
|
||||
prices,
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ pub struct AddressCohortVecs<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub metrics: MinimalCohortMetrics<M>,
|
||||
|
||||
pub addr_count: ComputedFromHeight<StoredU64, M>,
|
||||
pub addr_count: ComputedPerBlock<StoredU64, M>,
|
||||
pub addr_count_delta: RollingDelta1m<StoredU64, StoredI64, M>,
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ impl AddressCohortVecs {
|
||||
|
||||
metrics: MinimalCohortMetrics::forced_import(&cfg)?,
|
||||
|
||||
addr_count: ComputedFromHeight::forced_import(
|
||||
addr_count: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
&cfg.name("addr_count"),
|
||||
version,
|
||||
|
||||
@@ -24,7 +24,7 @@ use crate::{
|
||||
state::UTXOCohortState,
|
||||
},
|
||||
indexes,
|
||||
internal::AmountFromHeight,
|
||||
internal::AmountPerBlock,
|
||||
prices,
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ pub struct UTXOCohorts<M: StorageMode = Rw> {
|
||||
#[traversable(rename = "type")]
|
||||
pub type_: BySpendableType<UTXOCohortVecs<MinimalCohortMetrics<M>>>,
|
||||
pub profitability: ProfitabilityMetrics<M>,
|
||||
pub matured: ByAgeRange<AmountFromHeight<M>>,
|
||||
pub matured: ByAgeRange<AmountPerBlock<M>>,
|
||||
#[traversable(skip)]
|
||||
pub(super) fenwick: CostBasisFenwick,
|
||||
/// Cached partition_point positions for tick_tock boundary searches.
|
||||
@@ -230,8 +230,8 @@ impl UTXOCohorts<Rw> {
|
||||
|
||||
let matured = ByAgeRange::try_new(&|_f: Filter,
|
||||
name: &'static str|
|
||||
-> Result<AmountFromHeight> {
|
||||
AmountFromHeight::forced_import(db, &format!("utxo_{name}_matured"), v, indexes)
|
||||
-> Result<AmountPerBlock> {
|
||||
AmountPerBlock::forced_import(db, &format!("utxo_{name}_matured"), v, indexes)
|
||||
})?;
|
||||
|
||||
Ok(Self {
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Bitcoin, Height, Indexes, Sats, StoredF64, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::internal::ComputedFromHeight;
|
||||
use crate::internal::ComputedPerBlock;
|
||||
|
||||
use crate::{blocks, distribution::metrics::ImportConfig};
|
||||
|
||||
@@ -17,8 +17,8 @@ pub struct ActivityBase<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub core: ActivityCore<M>,
|
||||
|
||||
pub coinblocks_destroyed: ComputedFromHeight<StoredF64, M>,
|
||||
pub coindays_destroyed: ComputedFromHeight<StoredF64, M>,
|
||||
pub coinblocks_destroyed: ComputedPerBlock<StoredF64, M>,
|
||||
pub coindays_destroyed: ComputedPerBlock<StoredF64, M>,
|
||||
}
|
||||
|
||||
impl ActivityBase {
|
||||
|
||||
@@ -3,13 +3,13 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Indexes, Sats, Version};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::internal::{ComputedFromHeight, RollingWindow24h};
|
||||
use crate::internal::{ComputedPerBlock, RollingWindow24h};
|
||||
|
||||
use crate::{blocks, distribution::metrics::ImportConfig};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ActivityCore<M: StorageMode = Rw> {
|
||||
pub sent: ComputedFromHeight<Sats, M>,
|
||||
pub sent: ComputedPerBlock<Sats, M>,
|
||||
pub sent_sum: RollingWindow24h<Sats, M>,
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Indexes, Sats, StoredF64, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Exit, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeight, RollingWindows, RollingWindowsFrom1w};
|
||||
use crate::internal::{ComputedPerBlock, RollingWindows, RollingWindowsFrom1w};
|
||||
|
||||
use crate::{blocks, distribution::metrics::ImportConfig};
|
||||
|
||||
@@ -17,8 +17,8 @@ pub struct ActivityFull<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub inner: ActivityBase<M>,
|
||||
|
||||
pub coinblocks_destroyed_cumulative: ComputedFromHeight<StoredF64, M>,
|
||||
pub coindays_destroyed_cumulative: ComputedFromHeight<StoredF64, M>,
|
||||
pub coinblocks_destroyed_cumulative: ComputedPerBlock<StoredF64, M>,
|
||||
pub coindays_destroyed_cumulative: ComputedPerBlock<StoredF64, M>,
|
||||
pub coindays_destroyed_sum: RollingWindows<StoredF64, M>,
|
||||
|
||||
#[traversable(rename = "sent_sum")]
|
||||
|
||||
@@ -10,7 +10,7 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, prices};
|
||||
|
||||
use crate::internal::{ComputedFromHeight, RollingDeltaExcept1m};
|
||||
use crate::internal::{ComputedPerBlock, RollingDeltaExcept1m};
|
||||
|
||||
use crate::distribution::metrics::{
|
||||
ActivityFull, CohortMetricsBase, CostBasis, ImportConfig, OutputsMetrics,
|
||||
@@ -32,8 +32,8 @@ pub struct AllCohortMetrics<M: StorageMode = Rw> {
|
||||
pub unrealized: Box<UnrealizedFull<M>>,
|
||||
pub adjusted: Box<RealizedAdjusted<M>>,
|
||||
pub relative: Box<RelativeForAll<M>>,
|
||||
pub dormancy: ComputedFromHeight<StoredF32, M>,
|
||||
pub velocity: ComputedFromHeight<StoredF32, M>,
|
||||
pub dormancy: ComputedPerBlock<StoredF32, M>,
|
||||
pub velocity: ComputedPerBlock<StoredF32, M>,
|
||||
|
||||
#[traversable(wrap = "supply", rename = "delta")]
|
||||
pub supply_delta_extended: RollingDeltaExcept1m<Sats, SatsSigned, M>,
|
||||
|
||||
@@ -9,7 +9,7 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, prices};
|
||||
|
||||
use crate::internal::{ComputedFromHeight, RollingDeltaExcept1m};
|
||||
use crate::internal::{ComputedPerBlock, RollingDeltaExcept1m};
|
||||
|
||||
use crate::distribution::metrics::{
|
||||
ActivityFull, CohortMetricsBase, CostBasis, ImportConfig, OutputsMetrics,
|
||||
@@ -29,8 +29,8 @@ pub struct ExtendedCohortMetrics<M: StorageMode = Rw> {
|
||||
pub cost_basis: Box<CostBasis<M>>,
|
||||
pub unrealized: Box<UnrealizedFull<M>>,
|
||||
pub relative: Box<RelativeWithExtended<M>>,
|
||||
pub dormancy: ComputedFromHeight<StoredF32, M>,
|
||||
pub velocity: ComputedFromHeight<StoredF32, M>,
|
||||
pub dormancy: ComputedPerBlock<StoredF32, M>,
|
||||
pub velocity: ComputedPerBlock<StoredF32, M>,
|
||||
|
||||
#[traversable(wrap = "supply", rename = "delta")]
|
||||
pub supply_delta_extended: RollingDeltaExcept1m<Sats, SatsSigned, M>,
|
||||
|
||||
@@ -7,10 +7,10 @@ use vecdb::{BytesVec, BytesVecValue, Database, ImportableVec};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
AmountFromHeight, AmountFromHeightCumulative, CentsType, ComputedFromHeight,
|
||||
ComputedFromHeightCumulative, ComputedFromHeightCumulativeSum, ComputedFromHeightRatio,
|
||||
FiatFromHeight, FiatRollingDelta1m, FiatRollingDeltaExcept1m, NumericValue,
|
||||
PercentFromHeight, PercentRollingWindows, Price, RollingDelta1m, RollingDeltaExcept1m,
|
||||
AmountPerBlock, AmountPerBlockCumulative, CentsType, ComputedPerBlock,
|
||||
ComputedPerBlockCumulative, ComputedPerBlockCumulativeSum, RatioPerBlock,
|
||||
FiatPerBlock, FiatRollingDelta1m, FiatRollingDeltaExcept1m, NumericValue,
|
||||
PercentPerBlock, PercentRollingWindows, Price, RollingDelta1m, RollingDeltaExcept1m,
|
||||
RollingWindow24h, RollingWindows, RollingWindowsFrom1w,
|
||||
},
|
||||
};
|
||||
@@ -35,28 +35,28 @@ macro_rules! impl_config_import {
|
||||
|
||||
// Non-generic types
|
||||
impl_config_import!(
|
||||
AmountFromHeight,
|
||||
AmountFromHeightCumulative,
|
||||
ComputedFromHeightRatio,
|
||||
PercentFromHeight<BasisPoints16>,
|
||||
PercentFromHeight<BasisPoints32>,
|
||||
PercentFromHeight<BasisPointsSigned32>,
|
||||
AmountPerBlock,
|
||||
AmountPerBlockCumulative,
|
||||
RatioPerBlock,
|
||||
PercentPerBlock<BasisPoints16>,
|
||||
PercentPerBlock<BasisPoints32>,
|
||||
PercentPerBlock<BasisPointsSigned32>,
|
||||
PercentRollingWindows<BasisPoints32>,
|
||||
Price<ComputedFromHeight<Cents>>,
|
||||
Price<ComputedPerBlock<Cents>>,
|
||||
);
|
||||
|
||||
// Generic types (macro_rules can't parse generic bounds, so written out)
|
||||
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedFromHeight<T> {
|
||||
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedPerBlock<T> {
|
||||
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||
}
|
||||
}
|
||||
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedFromHeightCumulative<T> {
|
||||
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedPerBlockCumulative<T> {
|
||||
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||
}
|
||||
}
|
||||
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedFromHeightCumulativeSum<T> {
|
||||
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedPerBlockCumulativeSum<T> {
|
||||
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||
}
|
||||
@@ -76,7 +76,7 @@ impl<T: NumericValue + JsonSchema> ConfigImport for RollingWindowsFrom1w<T> {
|
||||
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||
}
|
||||
}
|
||||
impl<C: CentsType> ConfigImport for FiatFromHeight<C> {
|
||||
impl<C: CentsType> ConfigImport for FiatPerBlock<C> {
|
||||
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, Height, Version};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::internal::{ComputedFromHeight, PercentilesVecs, Price, PERCENTILES_LEN};
|
||||
use crate::internal::{ComputedPerBlock, PercentilesVecs, Price, PERCENTILES_LEN};
|
||||
|
||||
use super::ImportConfig;
|
||||
|
||||
@@ -11,8 +11,8 @@ use super::ImportConfig;
|
||||
/// Used by all/sth/lth cohorts only.
|
||||
#[derive(Traversable)]
|
||||
pub struct CostBasis<M: StorageMode = Rw> {
|
||||
pub min: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub max: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub min: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub max: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub percentiles: PercentilesVecs<M>,
|
||||
pub invested_capital: PercentilesVecs<M>,
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Indexes, StoredI64, StoredU64, Version};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::{blocks, internal::{ComputedFromHeight, RollingDelta1m}};
|
||||
use crate::{blocks, internal::{ComputedPerBlock, RollingDelta1m}};
|
||||
|
||||
use super::ImportConfig;
|
||||
|
||||
/// Output metrics for a cohort.
|
||||
#[derive(Traversable)]
|
||||
pub struct OutputsMetrics<M: StorageMode = Rw> {
|
||||
pub utxo_count: ComputedFromHeight<StoredU64, M>,
|
||||
pub utxo_count: ComputedPerBlock<StoredU64, M>,
|
||||
pub utxo_count_delta: RollingDelta1m<StoredU64, StoredI64, M>,
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Height, Sats, Version};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Database, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::{indexes, internal::ComputedFromHeight};
|
||||
use crate::{indexes, internal::ComputedPerBlock};
|
||||
|
||||
/// Supply + realized cap for a single profitability bucket.
|
||||
#[derive(Traversable)]
|
||||
pub struct ProfitabilityBucket<M: StorageMode = Rw> {
|
||||
pub supply: ComputedFromHeight<Sats, M>,
|
||||
pub realized_cap: ComputedFromHeight<Dollars, M>,
|
||||
pub supply: ComputedPerBlock<Sats, M>,
|
||||
pub realized_cap: ComputedPerBlock<Dollars, M>,
|
||||
}
|
||||
|
||||
impl<M: StorageMode> ProfitabilityBucket<M> {
|
||||
@@ -27,13 +27,13 @@ impl ProfitabilityBucket {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
supply: ComputedFromHeight::forced_import(
|
||||
supply: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_supply"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
realized_cap: ComputedFromHeight::forced_import(
|
||||
realized_cap: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_realized_cap"),
|
||||
version,
|
||||
|
||||
@@ -5,15 +5,15 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
blocks,
|
||||
internal::{ComputedFromHeight, RatioCents64, RollingWindows},
|
||||
internal::{ComputedPerBlock, RatioCents64, RollingWindows},
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedAdjusted<M: StorageMode = Rw> {
|
||||
pub value_created: ComputedFromHeight<Cents, M>,
|
||||
pub value_destroyed: ComputedFromHeight<Cents, M>,
|
||||
pub value_created: ComputedPerBlock<Cents, M>,
|
||||
pub value_destroyed: ComputedPerBlock<Cents, M>,
|
||||
pub value_created_sum: RollingWindows<Cents, M>,
|
||||
pub value_destroyed_sum: RollingWindows<Cents, M>,
|
||||
pub sopr: RollingWindows<StoredF64, M>,
|
||||
|
||||
@@ -7,7 +7,7 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
use crate::{
|
||||
blocks,
|
||||
distribution::state::RealizedOps,
|
||||
internal::{ComputedFromHeight, RollingWindow24h},
|
||||
internal::{ComputedPerBlock, RollingWindow24h},
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
@@ -21,8 +21,8 @@ pub struct RealizedBase<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub core: RealizedCore<M>,
|
||||
|
||||
pub sent_in_profit: ComputedFromHeight<Sats, M>,
|
||||
pub sent_in_loss: ComputedFromHeight<Sats, M>,
|
||||
pub sent_in_profit: ComputedPerBlock<Sats, M>,
|
||||
pub sent_in_loss: ComputedPerBlock<Sats, M>,
|
||||
|
||||
pub sent_in_profit_sum: RollingWindow24h<Sats, M>,
|
||||
pub sent_in_loss_sum: RollingWindow24h<Sats, M>,
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
blocks,
|
||||
distribution::state::RealizedOps,
|
||||
internal::{
|
||||
ComputedFromHeight, FiatRollingDelta1m, LazyFromHeight, NegCentsUnsignedToDollars,
|
||||
ComputedPerBlock, FiatRollingDelta1m, LazyPerBlock, NegCentsUnsignedToDollars,
|
||||
RatioCents64, RollingWindow24h,
|
||||
},
|
||||
prices,
|
||||
@@ -29,12 +29,12 @@ pub struct RealizedCore<M: StorageMode = Rw> {
|
||||
|
||||
pub realized_cap_delta: FiatRollingDelta1m<Cents, CentsSigned, M>,
|
||||
|
||||
pub neg_realized_loss: LazyFromHeight<Dollars, Cents>,
|
||||
pub net_realized_pnl: ComputedFromHeight<CentsSigned, M>,
|
||||
pub neg_realized_loss: LazyPerBlock<Dollars, Cents>,
|
||||
pub net_realized_pnl: ComputedPerBlock<CentsSigned, M>,
|
||||
pub net_realized_pnl_sum: RollingWindow24h<CentsSigned, M>,
|
||||
|
||||
pub value_created: ComputedFromHeight<Cents, M>,
|
||||
pub value_destroyed: ComputedFromHeight<Cents, M>,
|
||||
pub value_created: ComputedPerBlock<Cents, M>,
|
||||
pub value_destroyed: ComputedPerBlock<Cents, M>,
|
||||
pub value_created_sum: RollingWindow24h<Cents, M>,
|
||||
pub value_destroyed_sum: RollingWindow24h<Cents, M>,
|
||||
pub sopr: RollingWindow24h<StoredF64, M>,
|
||||
@@ -47,7 +47,7 @@ impl RealizedCore {
|
||||
|
||||
let minimal = RealizedMinimal::forced_import(cfg)?;
|
||||
|
||||
let neg_realized_loss = LazyFromHeight::from_height_source::<NegCentsUnsignedToDollars>(
|
||||
let neg_realized_loss = LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
|
||||
&cfg.name("neg_realized_loss"),
|
||||
cfg.version + Version::ONE,
|
||||
minimal.realized_loss.height.read_only_boxed_clone(),
|
||||
|
||||
@@ -14,10 +14,10 @@ use crate::{
|
||||
blocks,
|
||||
distribution::state::RealizedState,
|
||||
internal::{
|
||||
CentsUnsignedToDollars, ComputedFromHeight, ComputedFromHeightCumulative,
|
||||
ComputedFromHeightRatio, ComputedFromHeightRatioPercentiles,
|
||||
ComputedFromHeightRatioStdDevBands, FiatFromHeight, FiatRollingDelta1m,
|
||||
FiatRollingDeltaExcept1m, LazyFromHeight, PercentFromHeight, PercentRollingWindows, Price,
|
||||
CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative,
|
||||
RatioPerBlock, RatioPerBlockPercentiles,
|
||||
RatioPerBlockStdDevBands, FiatPerBlock, FiatRollingDelta1m,
|
||||
FiatRollingDeltaExcept1m, LazyPerBlock, PercentPerBlock, PercentRollingWindows, Price,
|
||||
RatioCents64, RatioCentsBp32, RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32,
|
||||
RatioDollarsBp32, RollingWindows, RollingWindowsFrom1w,
|
||||
},
|
||||
@@ -35,55 +35,55 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub base: RealizedBase<M>,
|
||||
|
||||
pub gross_pnl: FiatFromHeight<Cents, M>,
|
||||
pub gross_pnl: FiatPerBlock<Cents, M>,
|
||||
|
||||
pub realized_profit_rel_to_realized_cap: PercentFromHeight<BasisPoints32, M>,
|
||||
pub realized_loss_rel_to_realized_cap: PercentFromHeight<BasisPoints32, M>,
|
||||
pub net_realized_pnl_rel_to_realized_cap: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub realized_profit_rel_to_realized_cap: PercentPerBlock<BasisPoints32, M>,
|
||||
pub realized_loss_rel_to_realized_cap: PercentPerBlock<BasisPoints32, M>,
|
||||
pub net_realized_pnl_rel_to_realized_cap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
|
||||
pub profit_value_created: ComputedFromHeight<Cents, M>,
|
||||
pub profit_value_destroyed: ComputedFromHeight<Cents, M>,
|
||||
pub loss_value_created: ComputedFromHeight<Cents, M>,
|
||||
pub loss_value_destroyed: ComputedFromHeight<Cents, M>,
|
||||
pub profit_value_created: ComputedPerBlock<Cents, M>,
|
||||
pub profit_value_destroyed: ComputedPerBlock<Cents, M>,
|
||||
pub loss_value_created: ComputedPerBlock<Cents, M>,
|
||||
pub loss_value_destroyed: ComputedPerBlock<Cents, M>,
|
||||
|
||||
pub profit_value_created_sum: RollingWindows<Cents, M>,
|
||||
pub profit_value_destroyed_sum: RollingWindows<Cents, M>,
|
||||
pub loss_value_created_sum: RollingWindows<Cents, M>,
|
||||
pub loss_value_destroyed_sum: RollingWindows<Cents, M>,
|
||||
|
||||
pub capitulation_flow: LazyFromHeight<Dollars, Cents>,
|
||||
pub profit_flow: LazyFromHeight<Dollars, Cents>,
|
||||
pub capitulation_flow: LazyPerBlock<Dollars, Cents>,
|
||||
pub profit_flow: LazyPerBlock<Dollars, Cents>,
|
||||
|
||||
pub gross_pnl_sum: RollingWindows<Cents, M>,
|
||||
|
||||
pub net_realized_pnl_cumulative: ComputedFromHeight<CentsSigned, M>,
|
||||
pub net_realized_pnl_cumulative: ComputedPerBlock<CentsSigned, M>,
|
||||
#[traversable(rename = "net_realized_pnl_sum")]
|
||||
pub net_realized_pnl_sum_extended: RollingWindowsFrom1w<CentsSigned, M>,
|
||||
|
||||
pub net_pnl_delta: FiatRollingDelta1m<CentsSigned, CentsSigned, M>,
|
||||
#[traversable(rename = "net_pnl_delta")]
|
||||
pub net_pnl_delta_extended: FiatRollingDeltaExcept1m<CentsSigned, CentsSigned, M>,
|
||||
pub net_pnl_change_1m_rel_to_realized_cap: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub net_pnl_change_1m_rel_to_market_cap: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub net_pnl_change_1m_rel_to_realized_cap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
pub net_pnl_change_1m_rel_to_market_cap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
|
||||
#[traversable(rename = "realized_cap_delta")]
|
||||
pub realized_cap_delta_extended: FiatRollingDeltaExcept1m<Cents, CentsSigned, M>,
|
||||
|
||||
pub investor_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub investor_price_ratio: ComputedFromHeightRatio<M>,
|
||||
pub investor_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub investor_price_ratio: RatioPerBlock<M>,
|
||||
|
||||
pub lower_price_band: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub upper_price_band: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub lower_price_band: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub upper_price_band: Price<ComputedPerBlock<Cents, M>>,
|
||||
|
||||
pub cap_raw: M::Stored<BytesVec<Height, CentsSats>>,
|
||||
pub investor_cap_raw: M::Stored<BytesVec<Height, CentsSquaredSats>>,
|
||||
|
||||
pub sell_side_risk_ratio: PercentRollingWindows<BasisPoints32, M>,
|
||||
|
||||
pub peak_regret: ComputedFromHeightCumulative<Cents, M>,
|
||||
pub peak_regret_rel_to_realized_cap: PercentFromHeight<BasisPoints32, M>,
|
||||
pub peak_regret: ComputedPerBlockCumulative<Cents, M>,
|
||||
pub peak_regret_rel_to_realized_cap: PercentPerBlock<BasisPoints32, M>,
|
||||
|
||||
pub realized_cap_rel_to_own_market_cap: PercentFromHeight<BasisPoints32, M>,
|
||||
pub realized_cap_rel_to_own_market_cap: PercentPerBlock<BasisPoints32, M>,
|
||||
|
||||
#[traversable(rename = "realized_profit_sum")]
|
||||
pub realized_profit_sum_extended: RollingWindowsFrom1w<Cents, M>,
|
||||
@@ -103,9 +103,9 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
||||
#[traversable(rename = "sent_in_loss_sum")]
|
||||
pub sent_in_loss_sum_extended: RollingWindowsFrom1w<Sats, M>,
|
||||
|
||||
pub realized_price_ratio_percentiles: ComputedFromHeightRatioPercentiles<M>,
|
||||
pub realized_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands<M>,
|
||||
pub investor_price_ratio_percentiles: ComputedFromHeightRatioPercentiles<M>,
|
||||
pub realized_price_ratio_percentiles: RatioPerBlockPercentiles<M>,
|
||||
pub realized_price_ratio_std_dev: RatioPerBlockStdDevBands<M>,
|
||||
pub investor_price_ratio_percentiles: RatioPerBlockPercentiles<M>,
|
||||
}
|
||||
|
||||
impl RealizedFull {
|
||||
@@ -118,10 +118,10 @@ impl RealizedFull {
|
||||
let gross_pnl = cfg.import("realized_gross_pnl", v0)?;
|
||||
|
||||
let profit_value_created = cfg.import("profit_value_created", v0)?;
|
||||
let profit_value_destroyed: ComputedFromHeight<Cents> =
|
||||
let profit_value_destroyed: ComputedPerBlock<Cents> =
|
||||
cfg.import("profit_value_destroyed", v0)?;
|
||||
let loss_value_created = cfg.import("loss_value_created", v0)?;
|
||||
let loss_value_destroyed: ComputedFromHeight<Cents> =
|
||||
let loss_value_destroyed: ComputedPerBlock<Cents> =
|
||||
cfg.import("loss_value_destroyed", v0)?;
|
||||
|
||||
let profit_value_created_sum = cfg.import("profit_value_created", v1)?;
|
||||
@@ -129,13 +129,13 @@ impl RealizedFull {
|
||||
let loss_value_created_sum = cfg.import("loss_value_created", v1)?;
|
||||
let loss_value_destroyed_sum = cfg.import("loss_value_destroyed", v1)?;
|
||||
|
||||
let capitulation_flow = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
let capitulation_flow = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||
&cfg.name("capitulation_flow"),
|
||||
cfg.version,
|
||||
loss_value_destroyed.height.read_only_boxed_clone(),
|
||||
&loss_value_destroyed,
|
||||
);
|
||||
let profit_flow = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
let profit_flow = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||
&cfg.name("profit_flow"),
|
||||
cfg.version,
|
||||
profit_value_destroyed.height.read_only_boxed_clone(),
|
||||
@@ -221,19 +221,19 @@ impl RealizedFull {
|
||||
sopr_extended,
|
||||
sent_in_profit_sum_extended: cfg.import("sent_in_profit", v1)?,
|
||||
sent_in_loss_sum_extended: cfg.import("sent_in_loss", v1)?,
|
||||
realized_price_ratio_percentiles: ComputedFromHeightRatioPercentiles::forced_import(
|
||||
realized_price_ratio_percentiles: RatioPerBlockPercentiles::forced_import(
|
||||
cfg.db,
|
||||
&realized_price_name,
|
||||
realized_price_version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
realized_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands::forced_import(
|
||||
realized_price_ratio_std_dev: RatioPerBlockStdDevBands::forced_import(
|
||||
cfg.db,
|
||||
&realized_price_name,
|
||||
realized_price_version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
investor_price_ratio_percentiles: ComputedFromHeightRatioPercentiles::forced_import(
|
||||
investor_price_ratio_percentiles: RatioPerBlockPercentiles::forced_import(
|
||||
cfg.db,
|
||||
&investor_price_name,
|
||||
investor_price_version,
|
||||
|
||||
@@ -9,8 +9,8 @@ use crate::{
|
||||
blocks,
|
||||
distribution::state::RealizedOps,
|
||||
internal::{
|
||||
CentsUnsignedToDollars, ComputedFromHeight, ComputedFromHeightCumulative,
|
||||
ComputedFromHeightRatio, Identity, LazyFromHeight, Price, RollingWindow24h,
|
||||
CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative,
|
||||
RatioPerBlock, Identity, LazyPerBlock, Price, RollingWindow24h,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -19,13 +19,13 @@ use crate::distribution::metrics::ImportConfig;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedMinimal<M: StorageMode = Rw> {
|
||||
pub realized_cap_cents: ComputedFromHeight<Cents, M>,
|
||||
pub realized_profit: ComputedFromHeightCumulative<Cents, M>,
|
||||
pub realized_loss: ComputedFromHeightCumulative<Cents, M>,
|
||||
pub realized_cap: LazyFromHeight<Dollars, Cents>,
|
||||
pub realized_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub realized_price_ratio: ComputedFromHeightRatio<M>,
|
||||
pub mvrv: LazyFromHeight<StoredF32>,
|
||||
pub realized_cap_cents: ComputedPerBlock<Cents, M>,
|
||||
pub realized_profit: ComputedPerBlockCumulative<Cents, M>,
|
||||
pub realized_loss: ComputedPerBlockCumulative<Cents, M>,
|
||||
pub realized_cap: LazyPerBlock<Dollars, Cents>,
|
||||
pub realized_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub realized_price_ratio: RatioPerBlock<M>,
|
||||
pub mvrv: LazyPerBlock<StoredF32>,
|
||||
|
||||
pub realized_profit_sum: RollingWindow24h<Cents, M>,
|
||||
pub realized_loss_sum: RollingWindow24h<Cents, M>,
|
||||
@@ -33,9 +33,9 @@ pub struct RealizedMinimal<M: StorageMode = Rw> {
|
||||
|
||||
impl RealizedMinimal {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let realized_cap_cents: ComputedFromHeight<Cents> =
|
||||
let realized_cap_cents: ComputedPerBlock<Cents> =
|
||||
cfg.import("realized_cap_cents", Version::ZERO)?;
|
||||
let realized_cap = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
let realized_cap = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||
&cfg.name("realized_cap"),
|
||||
cfg.version,
|
||||
realized_cap_cents.height.read_only_boxed_clone(),
|
||||
@@ -46,9 +46,9 @@ impl RealizedMinimal {
|
||||
let realized_loss = cfg.import("realized_loss", Version::ZERO)?;
|
||||
|
||||
let realized_price = cfg.import("realized_price", Version::ONE)?;
|
||||
let realized_price_ratio: ComputedFromHeightRatio =
|
||||
let realized_price_ratio: RatioPerBlock =
|
||||
cfg.import("realized_price", Version::ONE)?;
|
||||
let mvrv = LazyFromHeight::from_lazy::<Identity<StoredF32>, BasisPoints32>(
|
||||
let mvrv = LazyPerBlock::from_lazy::<Identity<StoredF32>, BasisPoints32>(
|
||||
&cfg.name("mvrv"),
|
||||
cfg.version,
|
||||
&realized_price_ratio.ratio,
|
||||
|
||||
@@ -3,16 +3,16 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPoints16, BasisPoints32, BasisPointsSigned32, Dollars, Height, Version};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{PercentFromHeight, RatioDollarsBp16, RatioDollarsBp32, RatioDollarsBps32};
|
||||
use crate::internal::{PercentPerBlock, RatioDollarsBp16, RatioDollarsBp32, RatioDollarsBps32};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, UnrealizedCore};
|
||||
|
||||
/// Extended relative metrics for own market cap (extended && rel_to_all).
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeExtendedOwnMarketCap<M: StorageMode = Rw> {
|
||||
pub unrealized_profit_rel_to_own_market_cap: PercentFromHeight<BasisPoints16, M>,
|
||||
pub unrealized_loss_rel_to_own_market_cap: PercentFromHeight<BasisPoints32, M>,
|
||||
pub net_unrealized_pnl_rel_to_own_market_cap: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub unrealized_profit_rel_to_own_market_cap: PercentPerBlock<BasisPoints16, M>,
|
||||
pub unrealized_loss_rel_to_own_market_cap: PercentPerBlock<BasisPoints32, M>,
|
||||
pub net_unrealized_pnl_rel_to_own_market_cap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
}
|
||||
|
||||
impl RelativeExtendedOwnMarketCap {
|
||||
|
||||
@@ -3,16 +3,16 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPoints16, BasisPointsSigned32, Dollars, Height, Version};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{PercentFromHeight, RatioDollarsBp16, RatioDollarsBps32};
|
||||
use crate::internal::{PercentPerBlock, RatioDollarsBp16, RatioDollarsBps32};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, UnrealizedCore};
|
||||
|
||||
/// Extended relative metrics for own total unrealized PnL (extended only).
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeExtendedOwnPnl<M: StorageMode = Rw> {
|
||||
pub unrealized_profit_rel_to_own_gross_pnl: PercentFromHeight<BasisPoints16, M>,
|
||||
pub unrealized_loss_rel_to_own_gross_pnl: PercentFromHeight<BasisPoints16, M>,
|
||||
pub net_unrealized_pnl_rel_to_own_gross_pnl: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub unrealized_profit_rel_to_own_gross_pnl: PercentPerBlock<BasisPoints16, M>,
|
||||
pub unrealized_loss_rel_to_own_gross_pnl: PercentPerBlock<BasisPoints16, M>,
|
||||
pub net_unrealized_pnl_rel_to_own_gross_pnl: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
}
|
||||
|
||||
impl RelativeExtendedOwnPnl {
|
||||
|
||||
@@ -6,7 +6,7 @@ use brk_types::{
|
||||
use vecdb::{Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{
|
||||
Bps32ToFloat, LazyFromHeight, PercentFromHeight, RatioDollarsBp16, RatioDollarsBps32,
|
||||
Bps32ToFloat, LazyPerBlock, PercentPerBlock, RatioDollarsBp16, RatioDollarsBps32,
|
||||
RatioSatsBp16,
|
||||
};
|
||||
|
||||
@@ -15,13 +15,13 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedCore};
|
||||
/// Full relative metrics (sth/lth/all tier).
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeFull<M: StorageMode = Rw> {
|
||||
pub supply_in_profit_rel_to_own_supply: PercentFromHeight<BasisPoints16, M>,
|
||||
pub supply_in_loss_rel_to_own_supply: PercentFromHeight<BasisPoints16, M>,
|
||||
pub supply_in_profit_rel_to_own_supply: PercentPerBlock<BasisPoints16, M>,
|
||||
pub supply_in_loss_rel_to_own_supply: PercentPerBlock<BasisPoints16, M>,
|
||||
|
||||
pub unrealized_profit_rel_to_market_cap: PercentFromHeight<BasisPoints16, M>,
|
||||
pub unrealized_loss_rel_to_market_cap: PercentFromHeight<BasisPoints16, M>,
|
||||
pub net_unrealized_pnl_rel_to_market_cap: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub nupl: LazyFromHeight<StoredF32, BasisPointsSigned32>,
|
||||
pub unrealized_profit_rel_to_market_cap: PercentPerBlock<BasisPoints16, M>,
|
||||
pub unrealized_loss_rel_to_market_cap: PercentPerBlock<BasisPoints16, M>,
|
||||
pub net_unrealized_pnl_rel_to_market_cap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
pub nupl: LazyPerBlock<StoredF32, BasisPointsSigned32>,
|
||||
}
|
||||
|
||||
impl RelativeFull {
|
||||
@@ -30,10 +30,10 @@ impl RelativeFull {
|
||||
let v2 = Version::new(2);
|
||||
let v3 = Version::new(3);
|
||||
|
||||
let net_unrealized_pnl_rel_to_market_cap: PercentFromHeight<BasisPointsSigned32> =
|
||||
let net_unrealized_pnl_rel_to_market_cap: PercentPerBlock<BasisPointsSigned32> =
|
||||
cfg.import("net_unrealized_pnl_rel_to_market_cap", v3)?;
|
||||
|
||||
let nupl = LazyFromHeight::from_computed::<Bps32ToFloat>(
|
||||
let nupl = LazyPerBlock::from_computed::<Bps32ToFloat>(
|
||||
&cfg.name("nupl"),
|
||||
cfg.version + v3,
|
||||
net_unrealized_pnl_rel_to_market_cap
|
||||
|
||||
@@ -3,16 +3,16 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPoints16, Height, Sats, Version};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{PercentFromHeight, RatioSatsBp16};
|
||||
use crate::internal::{PercentPerBlock, RatioSatsBp16};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
|
||||
/// Relative-to-all metrics (not present for the "all" cohort itself).
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeToAll<M: StorageMode = Rw> {
|
||||
pub supply_rel_to_circulating_supply: PercentFromHeight<BasisPoints16, M>,
|
||||
pub supply_in_profit_rel_to_circulating_supply: PercentFromHeight<BasisPoints16, M>,
|
||||
pub supply_in_loss_rel_to_circulating_supply: PercentFromHeight<BasisPoints16, M>,
|
||||
pub supply_rel_to_circulating_supply: PercentPerBlock<BasisPoints16, M>,
|
||||
pub supply_in_profit_rel_to_circulating_supply: PercentPerBlock<BasisPoints16, M>,
|
||||
pub supply_in_loss_rel_to_circulating_supply: PercentPerBlock<BasisPoints16, M>,
|
||||
}
|
||||
|
||||
impl RelativeToAll {
|
||||
|
||||
@@ -6,8 +6,8 @@ use crate::{blocks, prices};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::internal::{
|
||||
AmountFromHeight, HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin,
|
||||
LazyAmountFromHeight, RollingDelta1m,
|
||||
AmountPerBlock, HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin,
|
||||
LazyAmountPerBlock, RollingDelta1m,
|
||||
};
|
||||
|
||||
use super::ImportConfig;
|
||||
@@ -15,8 +15,8 @@ use super::ImportConfig;
|
||||
/// Supply metrics for a cohort.
|
||||
#[derive(Traversable)]
|
||||
pub struct SupplyMetrics<M: StorageMode = Rw> {
|
||||
pub total: AmountFromHeight<M>,
|
||||
pub halved: LazyAmountFromHeight,
|
||||
pub total: AmountPerBlock<M>,
|
||||
pub halved: LazyAmountPerBlock,
|
||||
pub delta: RollingDelta1m<Sats, SatsSigned, M>,
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ impl SupplyMetrics {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let supply = cfg.import("supply", Version::ZERO)?;
|
||||
|
||||
let supply_halved = LazyAmountFromHeight::from_block_source::<
|
||||
let supply_halved = LazyAmountPerBlock::from_block_source::<
|
||||
HalveSats,
|
||||
HalveSatsToBitcoin,
|
||||
HalveCents,
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
state::UnrealizedState,
|
||||
},
|
||||
internal::{
|
||||
CentsSubtractToCentsSigned, FiatFromHeight, LazyFromHeight, NegCentsUnsignedToDollars,
|
||||
CentsSubtractToCentsSigned, FiatPerBlock, LazyPerBlock, NegCentsUnsignedToDollars,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -24,12 +24,12 @@ pub struct UnrealizedCore<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub minimal: UnrealizedMinimal<M>,
|
||||
|
||||
pub unrealized_profit: FiatFromHeight<Cents, M>,
|
||||
pub unrealized_loss: FiatFromHeight<Cents, M>,
|
||||
pub unrealized_profit: FiatPerBlock<Cents, M>,
|
||||
pub unrealized_loss: FiatPerBlock<Cents, M>,
|
||||
|
||||
pub neg_unrealized_loss: LazyFromHeight<Dollars, Cents>,
|
||||
pub neg_unrealized_loss: LazyPerBlock<Dollars, Cents>,
|
||||
|
||||
pub net_unrealized_pnl: FiatFromHeight<CentsSigned, M>,
|
||||
pub net_unrealized_pnl: FiatPerBlock<CentsSigned, M>,
|
||||
}
|
||||
|
||||
impl UnrealizedCore {
|
||||
@@ -39,9 +39,9 @@ impl UnrealizedCore {
|
||||
let minimal = UnrealizedMinimal::forced_import(cfg)?;
|
||||
|
||||
let unrealized_profit = cfg.import("unrealized_profit", v0)?;
|
||||
let unrealized_loss: FiatFromHeight<Cents> = cfg.import("unrealized_loss", v0)?;
|
||||
let unrealized_loss: FiatPerBlock<Cents> = cfg.import("unrealized_loss", v0)?;
|
||||
|
||||
let neg_unrealized_loss = LazyFromHeight::from_computed::<NegCentsUnsignedToDollars>(
|
||||
let neg_unrealized_loss = LazyPerBlock::from_computed::<NegCentsUnsignedToDollars>(
|
||||
&cfg.name("neg_unrealized_loss"),
|
||||
cfg.version,
|
||||
unrealized_loss.cents.height.read_only_boxed_clone(),
|
||||
|
||||
@@ -5,7 +5,7 @@ use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{AnyStoredVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::distribution::state::UnrealizedState;
|
||||
use crate::internal::{CentsSubtractToCentsSigned, FiatFromHeight};
|
||||
use crate::internal::{CentsSubtractToCentsSigned, FiatPerBlock};
|
||||
use crate::{distribution::metrics::ImportConfig, prices};
|
||||
|
||||
use super::UnrealizedBase;
|
||||
@@ -17,13 +17,13 @@ pub struct UnrealizedFull<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub inner: UnrealizedBase<M>,
|
||||
|
||||
pub gross_pnl: FiatFromHeight<Cents, M>,
|
||||
pub invested_capital_in_profit: FiatFromHeight<Cents, M>,
|
||||
pub invested_capital_in_loss: FiatFromHeight<Cents, M>,
|
||||
pub gross_pnl: FiatPerBlock<Cents, M>,
|
||||
pub invested_capital_in_profit: FiatPerBlock<Cents, M>,
|
||||
pub invested_capital_in_loss: FiatPerBlock<Cents, M>,
|
||||
|
||||
pub pain_index: FiatFromHeight<Cents, M>,
|
||||
pub greed_index: FiatFromHeight<Cents, M>,
|
||||
pub net_sentiment: FiatFromHeight<CentsSigned, M>,
|
||||
pub pain_index: FiatPerBlock<Cents, M>,
|
||||
pub greed_index: FiatPerBlock<Cents, M>,
|
||||
pub net_sentiment: FiatPerBlock<CentsSigned, M>,
|
||||
}
|
||||
|
||||
impl UnrealizedFull {
|
||||
|
||||
@@ -5,15 +5,15 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::prices;
|
||||
|
||||
use crate::internal::AmountFromHeight;
|
||||
use crate::internal::AmountPerBlock;
|
||||
|
||||
use crate::distribution::{metrics::ImportConfig, state::UnrealizedState};
|
||||
|
||||
/// Minimal unrealized metrics: supply in profit/loss only.
|
||||
#[derive(Traversable)]
|
||||
pub struct UnrealizedMinimal<M: StorageMode = Rw> {
|
||||
pub supply_in_profit: AmountFromHeight<M>,
|
||||
pub supply_in_loss: AmountFromHeight<M>,
|
||||
pub supply_in_profit: AmountPerBlock<M>,
|
||||
pub supply_in_loss: AmountPerBlock<M>,
|
||||
}
|
||||
|
||||
impl UnrealizedMinimal {
|
||||
|
||||
@@ -17,8 +17,8 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub hour12: M::Stored<EagerVec<PcoVec<Height, Hour12>>>,
|
||||
pub day1: M::Stored<EagerVec<PcoVec<Height, Day1>>>,
|
||||
pub day3: M::Stored<EagerVec<PcoVec<Height, Day3>>>,
|
||||
pub difficultyepoch: M::Stored<EagerVec<PcoVec<Height, DifficultyEpoch>>>,
|
||||
pub halvingepoch: M::Stored<EagerVec<PcoVec<Height, HalvingEpoch>>>,
|
||||
pub difficulty: M::Stored<EagerVec<PcoVec<Height, DifficultyEpoch>>>,
|
||||
pub halving: M::Stored<EagerVec<PcoVec<Height, HalvingEpoch>>>,
|
||||
pub week1: M::Stored<EagerVec<PcoVec<Height, Week1>>>,
|
||||
pub month1: M::Stored<EagerVec<PcoVec<Height, Month1>>>,
|
||||
pub month3: M::Stored<EagerVec<PcoVec<Height, Month3>>>,
|
||||
@@ -39,8 +39,8 @@ impl Vecs {
|
||||
hour12: EagerVec::forced_import(db, "hour12", version)?,
|
||||
day1: EagerVec::forced_import(db, "day1", version)?,
|
||||
day3: EagerVec::forced_import(db, "day3", version)?,
|
||||
difficultyepoch: EagerVec::forced_import(db, "difficultyepoch", version)?,
|
||||
halvingepoch: EagerVec::forced_import(db, "halvingepoch", version)?,
|
||||
difficulty: EagerVec::forced_import(db, "difficulty", version)?,
|
||||
halving: EagerVec::forced_import(db, "halving", version)?,
|
||||
week1: EagerVec::forced_import(db, "week1", version)?,
|
||||
month1: EagerVec::forced_import(db, "month1", version)?,
|
||||
month3: EagerVec::forced_import(db, "month3", version)?,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
mod address;
|
||||
mod day1;
|
||||
mod day3;
|
||||
mod difficultyepoch;
|
||||
mod halvingepoch;
|
||||
mod difficulty;
|
||||
mod halving;
|
||||
mod height;
|
||||
mod hour1;
|
||||
mod hour12;
|
||||
@@ -38,8 +38,8 @@ use crate::{
|
||||
pub use address::Vecs as AddressVecs;
|
||||
pub use day1::Vecs as Day1Vecs;
|
||||
pub use day3::Vecs as Day3Vecs;
|
||||
pub use difficultyepoch::Vecs as DifficultyEpochVecs;
|
||||
pub use halvingepoch::Vecs as HalvingEpochVecs;
|
||||
pub use difficulty::Vecs as DifficultyVecs;
|
||||
pub use halving::Vecs as HalvingVecs;
|
||||
pub use height::Vecs as HeightVecs;
|
||||
pub use hour1::Vecs as Hour1Vecs;
|
||||
pub use hour4::Vecs as Hour4Vecs;
|
||||
@@ -63,8 +63,8 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
db: Database,
|
||||
pub address: AddressVecs,
|
||||
pub height: HeightVecs<M>,
|
||||
pub difficultyepoch: DifficultyEpochVecs<M>,
|
||||
pub halvingepoch: HalvingEpochVecs<M>,
|
||||
pub difficulty: DifficultyVecs<M>,
|
||||
pub halving: HalvingVecs<M>,
|
||||
pub minute10: Minute10Vecs<M>,
|
||||
pub minute30: Minute30Vecs<M>,
|
||||
pub hour1: Hour1Vecs<M>,
|
||||
@@ -96,8 +96,8 @@ impl Vecs {
|
||||
let this = Self {
|
||||
address: AddressVecs::forced_import(version, indexer),
|
||||
height: HeightVecs::forced_import(&db, version)?,
|
||||
difficultyepoch: DifficultyEpochVecs::forced_import(&db, version)?,
|
||||
halvingepoch: HalvingEpochVecs::forced_import(&db, version)?,
|
||||
difficulty: DifficultyVecs::forced_import(&db, version)?,
|
||||
halving: HalvingVecs::forced_import(&db, version)?,
|
||||
minute10: Minute10Vecs::forced_import(&db, version)?,
|
||||
minute30: Minute30Vecs::forced_import(&db, version)?,
|
||||
hour1: Hour1Vecs::forced_import(&db, version)?,
|
||||
@@ -316,55 +316,55 @@ impl Vecs {
|
||||
prev_height: Height,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let starting_difficultyepoch = self
|
||||
let starting_difficulty = self
|
||||
.height
|
||||
.difficultyepoch
|
||||
.difficulty
|
||||
.collect_one(prev_height)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.height.difficultyepoch.compute_from_index(
|
||||
self.height.difficulty.compute_from_index(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.blocks.weight,
|
||||
exit,
|
||||
)?;
|
||||
self.difficultyepoch.first_height.compute_first_per_index(
|
||||
self.difficulty.first_height.compute_first_per_index(
|
||||
starting_indexes.height,
|
||||
&self.height.difficultyepoch,
|
||||
&self.height.difficulty,
|
||||
exit,
|
||||
)?;
|
||||
self.difficultyepoch.identity.compute_from_index(
|
||||
starting_difficultyepoch,
|
||||
&self.difficultyepoch.first_height,
|
||||
self.difficulty.identity.compute_from_index(
|
||||
starting_difficulty,
|
||||
&self.difficulty.first_height,
|
||||
exit,
|
||||
)?;
|
||||
self.difficultyepoch
|
||||
self.difficulty
|
||||
.height_count
|
||||
.compute_count_from_indexes(
|
||||
starting_difficultyepoch,
|
||||
&self.difficultyepoch.first_height,
|
||||
starting_difficulty,
|
||||
&self.difficulty.first_height,
|
||||
&blocks_time.date,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let starting_halvingepoch = self
|
||||
let starting_halving = self
|
||||
.height
|
||||
.halvingepoch
|
||||
.halving
|
||||
.collect_one(prev_height)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.height.halvingepoch.compute_from_index(
|
||||
self.height.halving.compute_from_index(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.blocks.weight,
|
||||
exit,
|
||||
)?;
|
||||
self.halvingepoch.first_height.compute_first_per_index(
|
||||
self.halving.first_height.compute_first_per_index(
|
||||
starting_indexes.height,
|
||||
&self.height.halvingepoch,
|
||||
&self.height.halving,
|
||||
exit,
|
||||
)?;
|
||||
self.halvingepoch.identity.compute_from_index(
|
||||
starting_halvingepoch,
|
||||
&self.halvingepoch.first_height,
|
||||
self.halving.identity.compute_from_index(
|
||||
starting_halving,
|
||||
&self.halving.first_height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromHeightAggregated};
|
||||
use crate::{indexes, internal::ComputedPerBlockAggregated};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -11,7 +11,7 @@ impl Vecs {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self(ComputedFromHeightAggregated::forced_import(
|
||||
Ok(Self(ComputedPerBlockAggregated::forced_import(
|
||||
db,
|
||||
"input_count",
|
||||
version,
|
||||
|
||||
@@ -4,9 +4,9 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredU64;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedFromHeightAggregated;
|
||||
use crate::internal::ComputedPerBlockAggregated;
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw>(
|
||||
#[traversable(flatten)] pub ComputedFromHeightAggregated<StoredU64, M>,
|
||||
#[traversable(flatten)] pub ComputedPerBlockAggregated<StoredU64, M>,
|
||||
);
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::{
|
||||
prices,
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::TWO; // Match AmountFromHeight versioning
|
||||
const VERSION: Version = Version::TWO; // Match AmountPerBlock versioning
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Amount<I: VecIndex, M: StorageMode = Rw> {
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
|
||||
use vecdb::{LazyVecFrom1, ReadableCloneableVec, UnaryTransform, VecIndex};
|
||||
|
||||
use crate::internal::AmountFromHeight;
|
||||
use crate::internal::AmountPerBlock;
|
||||
|
||||
/// Fully lazy value type at height level.
|
||||
///
|
||||
@@ -23,7 +23,7 @@ impl LazyAmount<Height> {
|
||||
DollarsTransform,
|
||||
>(
|
||||
name: &str,
|
||||
source: &AmountFromHeight,
|
||||
source: &AmountPerBlock,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
mod distribution_stats;
|
||||
mod per_period;
|
||||
mod per_resolution;
|
||||
mod windows;
|
||||
|
||||
pub use distribution_stats::*;
|
||||
pub use per_period::*;
|
||||
pub use per_resolution::*;
|
||||
pub use windows::*;
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct PerPeriod<M10, M30, H1, H4, H12, D1, D3, W1, Mo1, Mo3, Mo6, Y1, Y10, HE, DE> {
|
||||
pub struct PerResolution<M10, M30, H1, H4, H12, D1, D3, W1, Mo1, Mo3, Mo6, Y1, Y10, HE, DE> {
|
||||
pub minute10: M10,
|
||||
pub minute30: M30,
|
||||
pub hour1: H1,
|
||||
@@ -16,6 +16,6 @@ pub struct PerPeriod<M10, M30, H1, H4, H12, D1, D3, W1, Mo1, Mo3, Mo6, Y1, Y10,
|
||||
pub month6: Mo6,
|
||||
pub year1: Y1,
|
||||
pub year10: Y10,
|
||||
pub halvingepoch: HE,
|
||||
pub difficultyepoch: DE,
|
||||
pub halving: HE,
|
||||
pub difficulty: DE,
|
||||
}
|
||||
@@ -14,14 +14,14 @@ use vecdb::{
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecValue, NumericValue, PerPeriod},
|
||||
internal::{ComputedVecValue, NumericValue, PerResolution},
|
||||
};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct EagerIndexes<T, M: StorageMode = Rw>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub PerPeriod<
|
||||
pub PerResolution<
|
||||
<M as StorageMode>::Stored<EagerVec<PcoVec<Minute10, T>>>,
|
||||
<M as StorageMode>::Stored<EagerVec<PcoVec<Minute30, T>>>,
|
||||
<M as StorageMode>::Stored<EagerVec<PcoVec<Hour1, T>>>,
|
||||
@@ -53,7 +53,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Ok(Self(PerPeriod {
|
||||
Ok(Self(PerResolution {
|
||||
minute10: per_period!(),
|
||||
minute30: per_period!(),
|
||||
hour1: per_period!(),
|
||||
@@ -67,8 +67,8 @@ where
|
||||
month6: per_period!(),
|
||||
year1: per_period!(),
|
||||
year10: per_period!(),
|
||||
halvingepoch: per_period!(),
|
||||
difficultyepoch: per_period!(),
|
||||
halving: per_period!(),
|
||||
difficulty: per_period!(),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -109,8 +109,8 @@ where
|
||||
period!(month6);
|
||||
period!(year1);
|
||||
period!(year10);
|
||||
period!(halvingepoch);
|
||||
period!(difficultyepoch);
|
||||
period!(halving);
|
||||
period!(difficulty);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -156,8 +156,8 @@ where
|
||||
period!(month6);
|
||||
period!(year1);
|
||||
period!(year10);
|
||||
period!(halvingepoch);
|
||||
period!(difficultyepoch);
|
||||
period!(halving);
|
||||
period!(difficulty);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -203,8 +203,8 @@ where
|
||||
period!(month6);
|
||||
period!(year1);
|
||||
period!(year10);
|
||||
period!(halvingepoch);
|
||||
period!(difficultyepoch);
|
||||
period!(halving);
|
||||
period!(difficulty);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{LazyVecFrom1, ReadableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{ComputedVecValue, EagerIndexes, PerPeriod};
|
||||
use crate::internal::{ComputedVecValue, EagerIndexes, PerResolution};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct LazyEagerIndexes<T, S>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub PerPeriod<
|
||||
pub PerResolution<
|
||||
LazyVecFrom1<Minute10, T, Minute10, S>,
|
||||
LazyVecFrom1<Minute30, T, Minute30, S>,
|
||||
LazyVecFrom1<Hour1, T, Hour1, S>,
|
||||
@@ -55,7 +55,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self(PerPeriod {
|
||||
Self(PerResolution {
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
@@ -69,8 +69,8 @@ where
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
halving: period!(halving),
|
||||
difficulty: period!(difficulty),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ mod algo;
|
||||
mod amount;
|
||||
mod containers;
|
||||
mod db_utils;
|
||||
mod from_height;
|
||||
mod from_tx;
|
||||
mod per_block;
|
||||
mod per_tx;
|
||||
mod indexes;
|
||||
mod traits;
|
||||
mod transform;
|
||||
@@ -14,8 +14,8 @@ pub(crate) use algo::*;
|
||||
pub(crate) use amount::*;
|
||||
pub(crate) use containers::*;
|
||||
pub(crate) use db_utils::*;
|
||||
pub(crate) use from_height::*;
|
||||
pub(crate) use from_tx::*;
|
||||
pub(crate) use per_block::*;
|
||||
pub(crate) use per_tx::*;
|
||||
pub(crate) use indexes::*;
|
||||
pub(crate) use traits::*;
|
||||
pub use transform::*;
|
||||
|
||||
@@ -6,21 +6,21 @@ use vecdb::{AnyVec, Database, Exit, ReadableCloneableVec, ReadableVec, Rw, Stora
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CentsUnsignedToDollars, ComputedFromHeight, LazyFromHeight, SatsToBitcoin, SatsToCents,
|
||||
CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock, SatsToBitcoin, SatsToCents,
|
||||
Windows,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct AmountFromHeight<M: StorageMode = Rw> {
|
||||
pub sats: ComputedFromHeight<Sats, M>,
|
||||
pub btc: LazyFromHeight<Bitcoin, Sats>,
|
||||
pub cents: ComputedFromHeight<Cents, M>,
|
||||
pub usd: LazyFromHeight<Dollars, Cents>,
|
||||
pub struct AmountPerBlock<M: StorageMode = Rw> {
|
||||
pub sats: ComputedPerBlock<Sats, M>,
|
||||
pub btc: LazyPerBlock<Bitcoin, Sats>,
|
||||
pub cents: ComputedPerBlock<Cents, M>,
|
||||
pub usd: LazyPerBlock<Dollars, Cents>,
|
||||
}
|
||||
|
||||
impl AmountFromHeight {
|
||||
impl AmountPerBlock {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -28,9 +28,9 @@ impl AmountFromHeight {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let sats =
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_sats"), version, indexes)?;
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_sats"), version, indexes)?;
|
||||
|
||||
let btc = LazyFromHeight::from_computed::<SatsToBitcoin>(
|
||||
let btc = LazyPerBlock::from_computed::<SatsToBitcoin>(
|
||||
name,
|
||||
version,
|
||||
sats.height.read_only_boxed_clone(),
|
||||
@@ -38,9 +38,9 @@ impl AmountFromHeight {
|
||||
);
|
||||
|
||||
let cents =
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
|
||||
let usd = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
let usd = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
cents.height.read_only_boxed_clone(),
|
||||
@@ -92,7 +92,7 @@ impl AmountFromHeight {
|
||||
}
|
||||
}
|
||||
|
||||
impl Windows<AmountFromHeight> {
|
||||
impl Windows<AmountPerBlock> {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -100,7 +100,7 @@ impl Windows<AmountFromHeight> {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Windows::try_from_fn(|suffix| {
|
||||
AmountFromHeight::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||
AmountPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -5,19 +5,19 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{AmountFromHeight, SatsToCents},
|
||||
internal::{AmountPerBlock, SatsToCents},
|
||||
prices,
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct AmountFromHeightCumulative<M: StorageMode = Rw> {
|
||||
pub base: AmountFromHeight<M>,
|
||||
pub cumulative: AmountFromHeight<M>,
|
||||
pub struct AmountPerBlockCumulative<M: StorageMode = Rw> {
|
||||
pub base: AmountPerBlock<M>,
|
||||
pub cumulative: AmountPerBlock<M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE;
|
||||
|
||||
impl AmountFromHeightCumulative {
|
||||
impl AmountPerBlockCumulative {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -27,8 +27,8 @@ impl AmountFromHeightCumulative {
|
||||
let v = version + VERSION;
|
||||
|
||||
Ok(Self {
|
||||
base: AmountFromHeight::forced_import(db, name, v, indexes)?,
|
||||
cumulative: AmountFromHeight::forced_import(
|
||||
base: AmountPerBlock::forced_import(db, name, v, indexes)?,
|
||||
cumulative: AmountPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
@@ -5,20 +5,20 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{AmountFromHeight, RollingSumAmountFromHeight, SatsToCents, WindowStarts},
|
||||
internal::{AmountPerBlock, RollingSumAmountPerBlock, SatsToCents, WindowStarts},
|
||||
prices,
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct AmountFromHeightCumulativeSum<M: StorageMode = Rw> {
|
||||
pub base: AmountFromHeight<M>,
|
||||
pub cumulative: AmountFromHeight<M>,
|
||||
pub sum: RollingSumAmountFromHeight<M>,
|
||||
pub struct AmountPerBlockCumulativeSum<M: StorageMode = Rw> {
|
||||
pub base: AmountPerBlock<M>,
|
||||
pub cumulative: AmountPerBlock<M>,
|
||||
pub sum: RollingSumAmountPerBlock<M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::TWO;
|
||||
|
||||
impl AmountFromHeightCumulativeSum {
|
||||
impl AmountPerBlockCumulativeSum {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -28,14 +28,14 @@ impl AmountFromHeightCumulativeSum {
|
||||
let v = version + VERSION;
|
||||
|
||||
Ok(Self {
|
||||
base: AmountFromHeight::forced_import(db, name, v, indexes)?,
|
||||
cumulative: AmountFromHeight::forced_import(
|
||||
base: AmountPerBlock::forced_import(db, name, v, indexes)?,
|
||||
cumulative: AmountPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
indexes,
|
||||
)?,
|
||||
sum: RollingSumAmountFromHeight::forced_import(db, name, v, indexes)?,
|
||||
sum: RollingSumAmountPerBlock::forced_import(db, name, v, indexes)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,21 +5,21 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{AmountFromHeight, RollingFullAmountFromHeight, SatsToCents, WindowStarts},
|
||||
internal::{AmountPerBlock, RollingFullAmountPerBlock, SatsToCents, WindowStarts},
|
||||
prices,
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct AmountFromHeightFull<M: StorageMode = Rw> {
|
||||
pub base: AmountFromHeight<M>,
|
||||
pub cumulative: AmountFromHeight<M>,
|
||||
pub struct AmountPerBlockFull<M: StorageMode = Rw> {
|
||||
pub base: AmountPerBlock<M>,
|
||||
pub cumulative: AmountPerBlock<M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingFullAmountFromHeight<M>,
|
||||
pub rolling: RollingFullAmountPerBlock<M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::TWO;
|
||||
|
||||
impl AmountFromHeightFull {
|
||||
impl AmountPerBlockFull {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -29,14 +29,14 @@ impl AmountFromHeightFull {
|
||||
let v = version + VERSION;
|
||||
|
||||
Ok(Self {
|
||||
base: AmountFromHeight::forced_import(db, name, v, indexes)?,
|
||||
cumulative: AmountFromHeight::forced_import(
|
||||
base: AmountPerBlock::forced_import(db, name, v, indexes)?,
|
||||
cumulative: AmountPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
indexes,
|
||||
)?,
|
||||
rolling: RollingFullAmountFromHeight::forced_import(db, name, v, indexes)?,
|
||||
rolling: RollingFullAmountPerBlock::forced_import(db, name, v, indexes)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
//! Lazy value wrapper for AmountFromHeight - all transforms are lazy.
|
||||
//! Lazy value wrapper for AmountPerBlock - all transforms are lazy.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
use crate::internal::{AmountFromHeight, LazyAmount, LazyAmountHeightDerived};
|
||||
use crate::internal::{AmountPerBlock, LazyAmount, LazyAmountDerivedResolutions};
|
||||
|
||||
/// Lazy value wrapper with height + all derived last transforms from AmountFromHeight.
|
||||
/// Lazy value wrapper with height + all derived last transforms from AmountPerBlock.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyAmountFromHeight {
|
||||
pub struct LazyAmountPerBlock {
|
||||
#[traversable(flatten)]
|
||||
pub height: LazyAmount<Height>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<LazyAmountHeightDerived>,
|
||||
pub resolutions: Box<LazyAmountDerivedResolutions>,
|
||||
}
|
||||
|
||||
impl LazyAmountFromHeight {
|
||||
impl LazyAmountPerBlock {
|
||||
pub(crate) fn from_block_source<
|
||||
SatsTransform,
|
||||
BitcoinTransform,
|
||||
@@ -27,7 +27,7 @@ impl LazyAmountFromHeight {
|
||||
DollarsTransform,
|
||||
>(
|
||||
name: &str,
|
||||
source: &AmountFromHeight,
|
||||
source: &AmountPerBlock,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
@@ -43,7 +43,7 @@ impl LazyAmountFromHeight {
|
||||
DollarsTransform,
|
||||
>(name, source, version);
|
||||
|
||||
let rest = LazyAmountHeightDerived::from_block_source::<
|
||||
let resolutions = LazyAmountDerivedResolutions::from_block_source::<
|
||||
SatsTransform,
|
||||
BitcoinTransform,
|
||||
CentsTransform,
|
||||
@@ -52,7 +52,7 @@ impl LazyAmountFromHeight {
|
||||
|
||||
Self {
|
||||
height,
|
||||
rest: Box::new(rest),
|
||||
resolutions: Box::new(resolutions),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,17 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Sats, Version};
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
use crate::internal::{AmountFromHeight, LazyHeightDerived};
|
||||
use crate::internal::{AmountPerBlock, DerivedResolutions};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyAmountHeightDerived {
|
||||
pub sats: LazyHeightDerived<Sats, Sats>,
|
||||
pub btc: LazyHeightDerived<Bitcoin, Sats>,
|
||||
pub cents: LazyHeightDerived<Cents, Cents>,
|
||||
pub usd: LazyHeightDerived<Dollars, Dollars>,
|
||||
pub struct LazyAmountDerivedResolutions {
|
||||
pub sats: DerivedResolutions<Sats, Sats>,
|
||||
pub btc: DerivedResolutions<Bitcoin, Sats>,
|
||||
pub cents: DerivedResolutions<Cents, Cents>,
|
||||
pub usd: DerivedResolutions<Dollars, Dollars>,
|
||||
}
|
||||
|
||||
impl LazyAmountHeightDerived {
|
||||
impl LazyAmountDerivedResolutions {
|
||||
pub(crate) fn from_block_source<
|
||||
SatsTransform,
|
||||
BitcoinTransform,
|
||||
@@ -20,7 +20,7 @@ impl LazyAmountHeightDerived {
|
||||
DollarsTransform,
|
||||
>(
|
||||
name: &str,
|
||||
source: &AmountFromHeight,
|
||||
source: &AmountPerBlock,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
@@ -29,28 +29,28 @@ impl LazyAmountHeightDerived {
|
||||
CentsTransform: UnaryTransform<Cents, Cents>,
|
||||
DollarsTransform: UnaryTransform<Dollars, Dollars>,
|
||||
{
|
||||
let sats = LazyHeightDerived::from_derived_computed::<SatsTransform>(
|
||||
let sats = DerivedResolutions::from_derived_computed::<SatsTransform>(
|
||||
&format!("{name}_sats"),
|
||||
version,
|
||||
&source.sats.rest,
|
||||
&source.sats.resolutions,
|
||||
);
|
||||
|
||||
let btc = LazyHeightDerived::from_derived_computed::<BitcoinTransform>(
|
||||
let btc = DerivedResolutions::from_derived_computed::<BitcoinTransform>(
|
||||
name,
|
||||
version,
|
||||
&source.sats.rest,
|
||||
&source.sats.resolutions,
|
||||
);
|
||||
|
||||
let cents = LazyHeightDerived::from_derived_computed::<CentsTransform>(
|
||||
let cents = DerivedResolutions::from_derived_computed::<CentsTransform>(
|
||||
&format!("{name}_cents"),
|
||||
version,
|
||||
&source.cents.rest,
|
||||
&source.cents.resolutions,
|
||||
);
|
||||
|
||||
let usd = LazyHeightDerived::from_lazy::<DollarsTransform, Cents>(
|
||||
let usd = DerivedResolutions::from_lazy::<DollarsTransform, Cents>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
&source.usd.rest,
|
||||
&source.usd.resolutions,
|
||||
);
|
||||
|
||||
Self {
|
||||
@@ -3,7 +3,7 @@ mod cumulative;
|
||||
mod cumulative_sum;
|
||||
mod full;
|
||||
mod lazy;
|
||||
mod lazy_derived;
|
||||
mod lazy_derived_resolutions;
|
||||
mod rolling;
|
||||
mod rolling_full;
|
||||
mod rolling_sum;
|
||||
@@ -14,7 +14,7 @@ pub use cumulative::*;
|
||||
pub use cumulative_sum::*;
|
||||
pub use full::*;
|
||||
pub use lazy::*;
|
||||
pub use lazy_derived::*;
|
||||
pub use lazy_derived_resolutions::*;
|
||||
pub use rolling::*;
|
||||
pub use rolling_full::*;
|
||||
pub use rolling_sum::*;
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Value type for Height + Rolling pattern.
|
||||
//!
|
||||
//! Combines Value (sats/btc/usd per height, no period views) with
|
||||
//! AmountFromHeightWindows (rolling sums across 4 windows).
|
||||
//! AmountPerBlockWindows (rolling sums across 4 windows).
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -11,21 +11,21 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{Amount, AmountFromHeightWindows, WindowStarts},
|
||||
internal::{Amount, AmountPerBlockWindows, WindowStarts},
|
||||
prices,
|
||||
};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct AmountFromHeightRolling<M: StorageMode = Rw> {
|
||||
pub struct AmountPerBlockRolling<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub amount: Amount<Height, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: AmountFromHeightWindows<M>,
|
||||
pub rolling: AmountPerBlockWindows<M>,
|
||||
}
|
||||
|
||||
impl AmountFromHeightRolling {
|
||||
impl AmountPerBlockRolling {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -34,7 +34,7 @@ impl AmountFromHeightRolling {
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
amount: Amount::forced_import(db, name, version)?,
|
||||
rolling: AmountFromHeightWindows::forced_import(db, name, version, indexes)?,
|
||||
rolling: AmountPerBlockWindows::forced_import(db, name, version, indexes)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,18 +7,18 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
AmountFromHeight, DistributionStats, WindowStarts, Windows, compute_rolling_distribution_from_starts,
|
||||
AmountPerBlock, DistributionStats, WindowStarts, Windows, compute_rolling_distribution_from_starts,
|
||||
},
|
||||
};
|
||||
|
||||
/// One window slot: sum + 8 distribution stats, each a AmountFromHeight.
|
||||
/// One window slot: sum + 8 distribution stats, each a AmountPerBlock.
|
||||
///
|
||||
/// Tree: `sum.sats.height`, `average.sats.height`, etc.
|
||||
#[derive(Traversable)]
|
||||
pub struct RollingFullSlot<M: StorageMode = Rw> {
|
||||
pub sum: AmountFromHeight<M>,
|
||||
pub sum: AmountPerBlock<M>,
|
||||
#[traversable(flatten)]
|
||||
pub distribution: DistributionStats<AmountFromHeight<M>>,
|
||||
pub distribution: DistributionStats<AmountPerBlock<M>>,
|
||||
}
|
||||
|
||||
impl RollingFullSlot {
|
||||
@@ -29,9 +29,9 @@ impl RollingFullSlot {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
sum: AmountFromHeight::forced_import(db, &format!("{name}_sum"), version, indexes)?,
|
||||
sum: AmountPerBlock::forced_import(db, &format!("{name}_sum"), version, indexes)?,
|
||||
distribution: DistributionStats::try_from_fn(|suffix| {
|
||||
AmountFromHeight::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||
AmountPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||
})?,
|
||||
})
|
||||
}
|
||||
@@ -85,9 +85,9 @@ impl RollingFullSlot {
|
||||
/// Tree: `_24h.sum.sats.height`, `_24h.average.sats.height`, etc.
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct RollingFullAmountFromHeight<M: StorageMode = Rw>(pub Windows<RollingFullSlot<M>>);
|
||||
pub struct RollingFullAmountPerBlock<M: StorageMode = Rw>(pub Windows<RollingFullSlot<M>>);
|
||||
|
||||
impl RollingFullAmountFromHeight {
|
||||
impl RollingFullAmountPerBlock {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -6,7 +6,7 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{AmountFromHeight, WindowStarts, Windows},
|
||||
internal::{AmountPerBlock, WindowStarts, Windows},
|
||||
};
|
||||
|
||||
/// Rolling sum only, window-first then unit.
|
||||
@@ -14,16 +14,16 @@ use crate::{
|
||||
/// Tree: `_24h.sats.height`, `_24h.btc.height`, etc.
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct RollingSumAmountFromHeight<M: StorageMode = Rw>(pub Windows<AmountFromHeight<M>>);
|
||||
pub struct RollingSumAmountPerBlock<M: StorageMode = Rw>(pub Windows<AmountPerBlock<M>>);
|
||||
|
||||
impl RollingSumAmountFromHeight {
|
||||
impl RollingSumAmountPerBlock {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self(Windows::<AmountFromHeight>::forced_import(
|
||||
Ok(Self(Windows::<AmountPerBlock>::forced_import(
|
||||
db,
|
||||
&format!("{name}_sum"),
|
||||
version,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! AmountFromHeightWindows - window-first ordering.
|
||||
//! AmountPerBlockWindows - window-first ordering.
|
||||
//!
|
||||
//! Access pattern: `coinbase_sum._24h.sats.height`
|
||||
//! Each window (24h, 7d, 30d, 1y) contains sats (stored) + btc (lazy) + usd (stored).
|
||||
@@ -14,17 +14,17 @@ use brk_types::{Cents, Sats};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{AmountFromHeight, WindowStarts, Windows},
|
||||
internal::{AmountPerBlock, WindowStarts, Windows},
|
||||
};
|
||||
|
||||
/// Value rolling windows — window-first, currency-last.
|
||||
///
|
||||
/// Each window contains `AmountFromHeight` (sats + btc lazy + usd).
|
||||
/// Each window contains `AmountPerBlock` (sats + btc lazy + usd).
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct AmountFromHeightWindows<M: StorageMode = Rw>(pub Windows<AmountFromHeight<M>>);
|
||||
pub struct AmountPerBlockWindows<M: StorageMode = Rw>(pub Windows<AmountPerBlock<M>>);
|
||||
|
||||
impl AmountFromHeightWindows {
|
||||
impl AmountPerBlockWindows {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -32,7 +32,7 @@ impl AmountFromHeightWindows {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self(Windows::try_from_fn(|suffix| {
|
||||
AmountFromHeight::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||
AmountPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||
})?))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedFromHeightAggregated - Full (distribution + sum + cumulative) + RollingFull.
|
||||
//! ComputedPerBlockAggregated - Full (distribution + sum + cumulative) + RollingFull.
|
||||
//!
|
||||
//! For metrics aggregated per-block from finer-grained sources (e.g., per-tx data),
|
||||
//! where we want full per-block stats plus rolling window stats.
|
||||
@@ -17,7 +17,7 @@ use crate::{
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightAggregated<T, M: StorageMode = Rw>
|
||||
pub struct ComputedPerBlockAggregated<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -26,7 +26,7 @@ where
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ComputedFromHeightAggregated<T>
|
||||
impl<T> ComputedPerBlockAggregated<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -11,11 +11,11 @@ use vecdb::{
|
||||
|
||||
use crate::indexes;
|
||||
|
||||
use crate::internal::{ComputedHeightDerived, ComputedVecValue, NumericValue};
|
||||
use crate::internal::{Resolutions, ComputedVecValue, NumericValue};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedFromHeight<T, M: StorageMode = Rw>
|
||||
pub struct ComputedPerBlock<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -23,10 +23,10 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<ComputedHeightDerived<T>>,
|
||||
pub resolutions: Box<Resolutions<T>>,
|
||||
}
|
||||
|
||||
impl<T> ComputedFromHeight<T>
|
||||
impl<T> ComputedPerBlock<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -38,7 +38,7 @@ where
|
||||
) -> Result<Self> {
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, version)?;
|
||||
|
||||
let rest = ComputedHeightDerived::forced_import(
|
||||
let resolutions = Resolutions::forced_import(
|
||||
name,
|
||||
height.read_only_boxed_clone(),
|
||||
version,
|
||||
@@ -47,7 +47,7 @@ where
|
||||
|
||||
Ok(Self {
|
||||
height,
|
||||
rest: Box::new(rest),
|
||||
resolutions: Box::new(resolutions),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ where
|
||||
pub month6: LazyVecFrom1<Month6, T, Month6, Month6>,
|
||||
pub year1: LazyVecFrom1<Year1, T, Year1, Year1>,
|
||||
pub year10: LazyVecFrom1<Year10, T, Year10, Year10>,
|
||||
pub halvingepoch: LazyVecFrom1<HalvingEpoch, T, HalvingEpoch, HalvingEpoch>,
|
||||
pub difficultyepoch: LazyVecFrom1<DifficultyEpoch, T, DifficultyEpoch, DifficultyEpoch>,
|
||||
pub halving: LazyVecFrom1<HalvingEpoch, T, HalvingEpoch, HalvingEpoch>,
|
||||
pub difficulty: LazyVecFrom1<DifficultyEpoch, T, DifficultyEpoch, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
impl<T: VecValue + Formattable + Serialize + JsonSchema> ConstantVecs<T> {
|
||||
@@ -78,8 +78,8 @@ impl<T: VecValue + Formattable + Serialize + JsonSchema> ConstantVecs<T> {
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
halving: period!(halving),
|
||||
difficulty: period!(difficulty),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
//! ComputedFromHeightCumulative - stored height + LazyAggVec + cumulative (from height).
|
||||
//! ComputedPerBlockCumulative - stored height + LazyAggVec + cumulative (from height).
|
||||
//!
|
||||
//! Like ComputedFromHeightCumulativeSum but without RollingWindows.
|
||||
//! Like ComputedPerBlockCumulativeSum but without RollingWindows.
|
||||
//! Used for distribution metrics where rolling is optional per cohort.
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views.
|
||||
//! Cumulative gets its own ComputedPerBlock so it has LazyAggVec index views.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -12,19 +12,19 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeight, NumericValue},
|
||||
internal::{ComputedPerBlock, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightCumulative<T, M: StorageMode = Rw>
|
||||
pub struct ComputedPerBlockCumulative<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
pub cumulative: ComputedPerBlock<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ComputedFromHeightCumulative<T>
|
||||
impl<T> ComputedPerBlockCumulative<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -36,7 +36,7 @@ where
|
||||
) -> Result<Self> {
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, version)?;
|
||||
let cumulative =
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
|
||||
Ok(Self { height, cumulative })
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
//! ComputedFromHeightCumulativeSum - stored height + LazyAggVec + cumulative (from height) + RollingWindows (sum).
|
||||
//! ComputedPerBlockCumulativeSum - stored height + LazyAggVec + cumulative (from height) + RollingWindows (sum).
|
||||
//!
|
||||
//! Like ComputedFromHeightFull but with rolling sum only (no distribution).
|
||||
//! Like ComputedPerBlockFull but with rolling sum only (no distribution).
|
||||
//! Used for count metrics where distribution stats aren't meaningful.
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too.
|
||||
//! Cumulative gets its own ComputedPerBlock so it has LazyAggVec index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
@@ -14,20 +14,20 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeight, NumericValue, RollingWindows, WindowStarts},
|
||||
internal::{ComputedPerBlock, NumericValue, RollingWindows, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightCumulativeSum<T, M: StorageMode = Rw>
|
||||
pub struct ComputedPerBlockCumulativeSum<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
pub cumulative: ComputedPerBlock<T, M>,
|
||||
pub sum: RollingWindows<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ComputedFromHeightCumulativeSum<T>
|
||||
impl<T> ComputedPerBlockCumulativeSum<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -39,7 +39,7 @@ where
|
||||
) -> Result<Self> {
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, version)?;
|
||||
let cumulative =
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
let rolling = RollingWindows::forced_import(db, name, version, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
@@ -18,7 +18,7 @@ use vecdb::{AnyVec, Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMo
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedFromHeight, NumericValue, PercentFromHeight, PercentRollingWindows,
|
||||
ComputedPerBlock, NumericValue, PercentPerBlock, PercentRollingWindows,
|
||||
RollingWindows, WindowStarts,
|
||||
},
|
||||
};
|
||||
@@ -168,8 +168,8 @@ where
|
||||
S: NumericValue + JsonSchema,
|
||||
C: NumericValue + JsonSchema,
|
||||
{
|
||||
pub change_1m: ComputedFromHeight<C, M>,
|
||||
pub rate_1m: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub change_1m: ComputedPerBlock<C, M>,
|
||||
pub rate_1m: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
_phantom: std::marker::PhantomData<S>,
|
||||
}
|
||||
|
||||
@@ -185,13 +185,13 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
change_1m: ComputedFromHeight::forced_import(
|
||||
change_1m: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_1m"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
rate_1m: PercentFromHeight::forced_import(
|
||||
rate_1m: PercentPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_rate_1m"),
|
||||
version,
|
||||
@@ -228,13 +228,13 @@ where
|
||||
C: NumericValue + JsonSchema,
|
||||
{
|
||||
#[traversable(rename = "24h")]
|
||||
pub change_24h: ComputedFromHeight<C, M>,
|
||||
pub change_1w: ComputedFromHeight<C, M>,
|
||||
pub change_1y: ComputedFromHeight<C, M>,
|
||||
pub change_24h: ComputedPerBlock<C, M>,
|
||||
pub change_1w: ComputedPerBlock<C, M>,
|
||||
pub change_1y: ComputedPerBlock<C, M>,
|
||||
#[traversable(rename = "24h")]
|
||||
pub rate_24h: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub rate_1w: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub rate_1y: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub rate_24h: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
pub rate_1w: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
pub rate_1y: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
_phantom: std::marker::PhantomData<S>,
|
||||
}
|
||||
|
||||
@@ -250,37 +250,37 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
change_24h: ComputedFromHeight::forced_import(
|
||||
change_24h: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_24h"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
change_1w: ComputedFromHeight::forced_import(
|
||||
change_1w: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_1w"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
change_1y: ComputedFromHeight::forced_import(
|
||||
change_1y: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_1y"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
rate_24h: PercentFromHeight::forced_import(
|
||||
rate_24h: PercentPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_rate_24h"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
rate_1w: PercentFromHeight::forced_import(
|
||||
rate_1w: PercentPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_rate_1w"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
rate_1y: PercentFromHeight::forced_import(
|
||||
rate_1y: PercentPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_rate_1y"),
|
||||
version,
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Fiat delta variants — same as RollingDelta* but change is FiatFromHeight<C>
|
||||
//! (stored cents + lazy USD) instead of ComputedFromHeight<C> (stored cents only).
|
||||
//! Fiat delta variants — same as RollingDelta* but change is FiatPerBlock<C>
|
||||
//! (stored cents + lazy USD) instead of ComputedPerBlock<C> (stored cents only).
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -10,7 +10,7 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CentsType, FiatFromHeight, NumericValue, PercentFromHeight, PercentRollingWindows,
|
||||
CentsType, FiatPerBlock, NumericValue, PercentPerBlock, PercentRollingWindows,
|
||||
WindowStarts,
|
||||
},
|
||||
};
|
||||
@@ -24,8 +24,8 @@ where
|
||||
S: NumericValue + JsonSchema,
|
||||
C: CentsType,
|
||||
{
|
||||
pub change_1m: FiatFromHeight<C, M>,
|
||||
pub rate_1m: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub change_1m: FiatPerBlock<C, M>,
|
||||
pub rate_1m: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
_phantom: std::marker::PhantomData<S>,
|
||||
}
|
||||
|
||||
@@ -41,13 +41,13 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
change_1m: FiatFromHeight::forced_import(
|
||||
change_1m: FiatPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_1m"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
rate_1m: PercentFromHeight::forced_import(
|
||||
rate_1m: PercentPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_rate_1m"),
|
||||
version,
|
||||
@@ -83,13 +83,13 @@ where
|
||||
C: CentsType,
|
||||
{
|
||||
#[traversable(rename = "24h")]
|
||||
pub change_24h: FiatFromHeight<C, M>,
|
||||
pub change_1w: FiatFromHeight<C, M>,
|
||||
pub change_1y: FiatFromHeight<C, M>,
|
||||
pub change_24h: FiatPerBlock<C, M>,
|
||||
pub change_1w: FiatPerBlock<C, M>,
|
||||
pub change_1y: FiatPerBlock<C, M>,
|
||||
#[traversable(rename = "24h")]
|
||||
pub rate_24h: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub rate_1w: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub rate_1y: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
pub rate_24h: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
pub rate_1w: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
pub rate_1y: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
_phantom: std::marker::PhantomData<S>,
|
||||
}
|
||||
|
||||
@@ -105,37 +105,37 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
change_24h: FiatFromHeight::forced_import(
|
||||
change_24h: FiatPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_24h"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
change_1w: FiatFromHeight::forced_import(
|
||||
change_1w: FiatPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_1w"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
change_1y: FiatFromHeight::forced_import(
|
||||
change_1y: FiatPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_1y"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
rate_24h: PercentFromHeight::forced_import(
|
||||
rate_24h: PercentPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_rate_24h"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
rate_1w: PercentFromHeight::forced_import(
|
||||
rate_1w: PercentPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_rate_1w"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
rate_1y: PercentFromHeight::forced_import(
|
||||
rate_1y: PercentPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_rate_1y"),
|
||||
version,
|
||||
@@ -152,7 +152,7 @@ where
|
||||
source: &impl ReadableVec<Height, S>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let changes: [&mut FiatFromHeight<C>; 3] = [
|
||||
let changes: [&mut FiatPerBlock<C>; 3] = [
|
||||
&mut self.change_24h,
|
||||
&mut self.change_1w,
|
||||
&mut self.change_1y,
|
||||
@@ -181,10 +181,10 @@ where
|
||||
S: NumericValue + JsonSchema,
|
||||
C: CentsType,
|
||||
{
|
||||
pub change_24h: FiatFromHeight<C, M>,
|
||||
pub change_1w: FiatFromHeight<C, M>,
|
||||
pub change_1m: FiatFromHeight<C, M>,
|
||||
pub change_1y: FiatFromHeight<C, M>,
|
||||
pub change_24h: FiatPerBlock<C, M>,
|
||||
pub change_1w: FiatPerBlock<C, M>,
|
||||
pub change_1m: FiatPerBlock<C, M>,
|
||||
pub change_1y: FiatPerBlock<C, M>,
|
||||
pub rate: PercentRollingWindows<BasisPointsSigned32, M>,
|
||||
_phantom: std::marker::PhantomData<S>,
|
||||
}
|
||||
@@ -201,25 +201,25 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
change_24h: FiatFromHeight::forced_import(
|
||||
change_24h: FiatPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_24h"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
change_1w: FiatFromHeight::forced_import(
|
||||
change_1w: FiatPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_1w"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
change_1m: FiatFromHeight::forced_import(
|
||||
change_1m: FiatPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_1m"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
change_1y: FiatFromHeight::forced_import(
|
||||
change_1y: FiatPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_change_1y"),
|
||||
version,
|
||||
@@ -242,7 +242,7 @@ where
|
||||
source: &impl ReadableVec<Height, S>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let changes: [&mut FiatFromHeight<C>; 4] = [
|
||||
let changes: [&mut FiatPerBlock<C>; 4] = [
|
||||
&mut self.change_24h,
|
||||
&mut self.change_1w,
|
||||
&mut self.change_1m,
|
||||
@@ -1,7 +1,7 @@
|
||||
//! ComputedFromHeightFull - stored height + LazyAggVec + cumulative (from height) + RollingFull.
|
||||
//! ComputedPerBlockFull - stored height + LazyAggVec + cumulative (from height) + RollingFull.
|
||||
//!
|
||||
//! For metrics with stored per-block data, cumulative sums, and rolling windows.
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too.
|
||||
//! Cumulative gets its own ComputedPerBlock so it has LazyAggVec index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
@@ -13,21 +13,21 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeight, NumericValue, RollingFull, WindowStarts},
|
||||
internal::{ComputedPerBlock, NumericValue, RollingFull, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightFull<T, M: StorageMode = Rw>
|
||||
pub struct ComputedPerBlockFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
pub cumulative: ComputedPerBlock<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ComputedFromHeightFull<T>
|
||||
impl<T> ComputedPerBlockFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -39,7 +39,7 @@ where
|
||||
) -> Result<Self> {
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, version)?;
|
||||
let cumulative =
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
let rolling = RollingFull::forced_import(db, name, version, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
@@ -4,8 +4,8 @@ mod constant;
|
||||
mod cumulative;
|
||||
mod cumulative_sum;
|
||||
mod delta;
|
||||
mod derived;
|
||||
mod derived_full;
|
||||
mod resolutions;
|
||||
mod resolutions_full;
|
||||
mod fiat_delta;
|
||||
mod full;
|
||||
mod rolling_average;
|
||||
@@ -17,8 +17,8 @@ pub use constant::*;
|
||||
pub use cumulative::*;
|
||||
pub use cumulative_sum::*;
|
||||
pub use delta::*;
|
||||
pub use derived::*;
|
||||
pub use derived_full::*;
|
||||
pub use resolutions::*;
|
||||
pub use resolutions_full::*;
|
||||
pub use fiat_delta::*;
|
||||
pub use full::*;
|
||||
pub use rolling_average::*;
|
||||
@@ -11,14 +11,14 @@ use vecdb::{
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecValue, NumericValue, PerPeriod},
|
||||
internal::{ComputedVecValue, NumericValue, PerResolution},
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct ComputedHeightDerived<T>(
|
||||
pub struct Resolutions<T>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub PerPeriod<
|
||||
pub PerResolution<
|
||||
LazyAggVec<Minute10, Option<T>, Height, Height, T>,
|
||||
LazyAggVec<Minute30, Option<T>, Height, Height, T>,
|
||||
LazyAggVec<Hour1, Option<T>, Height, Height, T>,
|
||||
@@ -39,7 +39,7 @@ pub struct ComputedHeightDerived<T>(
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema;
|
||||
|
||||
impl<T> ReadOnlyClone for ComputedHeightDerived<T>
|
||||
impl<T> ReadOnlyClone for Resolutions<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -49,7 +49,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ComputedHeightDerived<T>
|
||||
impl<T> Resolutions<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -113,7 +113,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self(PerPeriod {
|
||||
Self(PerResolution {
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
@@ -127,8 +127,8 @@ where
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: epoch!(halvingepoch),
|
||||
difficultyepoch: epoch!(difficultyepoch),
|
||||
halving: epoch!(halving),
|
||||
difficulty: epoch!(difficulty),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
//! ComputedHeightDerivedFull - LazyAggVec index views + cumulative (from height) + RollingFull.
|
||||
//! ResolutionsFull - LazyAggVec index views + cumulative (from height) + RollingFull.
|
||||
//!
|
||||
//! For metrics derived from indexer sources (no stored height vec).
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too.
|
||||
//! Cumulative gets its own ComputedPerBlock so it has LazyAggVec index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
@@ -13,20 +13,20 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeight, NumericValue, RollingFull, WindowStarts},
|
||||
internal::{ComputedPerBlock, NumericValue, RollingFull, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedHeightDerivedFull<T, M: StorageMode = Rw>
|
||||
pub struct ResolutionsFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
pub cumulative: ComputedPerBlock<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ComputedHeightDerivedFull<T>
|
||||
impl<T> ResolutionsFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -37,7 +37,7 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let cumulative =
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
let rolling = RollingFull::forced_import(db, name, version, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
@@ -1,7 +1,7 @@
|
||||
//! ComputedFromHeight with rolling average (no distribution stats).
|
||||
//! ComputedPerBlock with rolling average (no distribution stats).
|
||||
//!
|
||||
//! Stored height data + 4-window rolling averages (24h, 1w, 1m, 1y).
|
||||
//! Use instead of ComputedFromHeightDistribution when only the average
|
||||
//! Use instead of ComputedPerBlockDistribution when only the average
|
||||
//! is analytically useful (e.g., block interval, activity counts).
|
||||
|
||||
use brk_error::Result;
|
||||
@@ -16,7 +16,7 @@ use crate::indexes;
|
||||
use crate::internal::{NumericValue, RollingWindows, WindowStarts};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightRollingAverage<T, M: StorageMode = Rw>
|
||||
pub struct ComputedPerBlockRollingAverage<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -25,7 +25,7 @@ where
|
||||
pub average: RollingWindows<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ComputedFromHeightRollingAverage<T>
|
||||
impl<T> ComputedPerBlockRollingAverage<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
//! ComputedFromHeightSum - stored height + RollingWindows (sum only).
|
||||
//! ComputedPerBlockSum - stored height + RollingWindows (sum only).
|
||||
//!
|
||||
//! Like ComputedFromHeightCumulativeSum but without the cumulative vec.
|
||||
//! Like ComputedPerBlockCumulativeSum but without the cumulative vec.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::{
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightSum<T, M: StorageMode = Rw>
|
||||
pub struct ComputedPerBlockSum<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -24,7 +24,7 @@ where
|
||||
pub sum: RollingWindows<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ComputedFromHeightSum<T>
|
||||
impl<T> ComputedPerBlockSum<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -7,7 +7,7 @@ use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode, UnaryTransform};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CentsSignedToDollars, CentsUnsignedToDollars, ComputedFromHeight, LazyFromHeight,
|
||||
CentsSignedToDollars, CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock,
|
||||
NumericValue,
|
||||
},
|
||||
};
|
||||
@@ -28,12 +28,12 @@ impl CentsType for CentsSigned {
|
||||
/// Height-indexed fiat monetary value: cents (eager, integer) + usd (lazy, float).
|
||||
/// Generic over `C` to support both `Cents` (unsigned) and `CentsSigned` (signed).
|
||||
#[derive(Traversable)]
|
||||
pub struct FiatFromHeight<C: CentsType, M: StorageMode = Rw> {
|
||||
pub cents: ComputedFromHeight<C, M>,
|
||||
pub usd: LazyFromHeight<Dollars, C>,
|
||||
pub struct FiatPerBlock<C: CentsType, M: StorageMode = Rw> {
|
||||
pub cents: ComputedPerBlock<C, M>,
|
||||
pub usd: LazyPerBlock<Dollars, C>,
|
||||
}
|
||||
|
||||
impl<C: CentsType> FiatFromHeight<C> {
|
||||
impl<C: CentsType> FiatPerBlock<C> {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -41,8 +41,8 @@ impl<C: CentsType> FiatFromHeight<C> {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let cents =
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let usd = LazyFromHeight::from_computed::<C::ToDollars>(
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let usd = LazyPerBlock::from_computed::<C::ToDollars>(
|
||||
name,
|
||||
version,
|
||||
cents.height.read_only_boxed_clone(),
|
||||
@@ -2,32 +2,32 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Version};
|
||||
use vecdb::ReadableCloneableVec;
|
||||
|
||||
use crate::internal::{CentsType, ComputedFromHeight, Identity, LazyFromHeight, NumericValue};
|
||||
use crate::internal::{CentsType, ComputedPerBlock, Identity, LazyPerBlock, NumericValue};
|
||||
|
||||
/// Lazy fiat: both cents and usd are lazy views of a stored source.
|
||||
/// Zero extra stored vecs.
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyFiatFromHeight<C: CentsType> {
|
||||
pub cents: LazyFromHeight<C, C>,
|
||||
pub usd: LazyFromHeight<Dollars, C>,
|
||||
pub struct LazyFiatPerBlock<C: CentsType> {
|
||||
pub cents: LazyPerBlock<C, C>,
|
||||
pub usd: LazyPerBlock<Dollars, C>,
|
||||
}
|
||||
|
||||
impl<C: CentsType> LazyFiatFromHeight<C> {
|
||||
impl<C: CentsType> LazyFiatPerBlock<C> {
|
||||
pub(crate) fn from_computed(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedFromHeight<C>,
|
||||
source: &ComputedPerBlock<C>,
|
||||
) -> Self
|
||||
where
|
||||
C: NumericValue,
|
||||
{
|
||||
let cents = LazyFromHeight::from_computed::<Identity<C>>(
|
||||
let cents = LazyPerBlock::from_computed::<Identity<C>>(
|
||||
&format!("{name}_cents"),
|
||||
version,
|
||||
source.height.read_only_boxed_clone(),
|
||||
source,
|
||||
);
|
||||
let usd = LazyFromHeight::from_computed::<C::ToDollars>(
|
||||
let usd = LazyPerBlock::from_computed::<C::ToDollars>(
|
||||
name,
|
||||
version,
|
||||
source.height.read_only_boxed_clone(),
|
||||
@@ -6,11 +6,11 @@ use vecdb::{LazyVecFrom1, ReadableBoxedVec, ReadableCloneableVec, UnaryTransform
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeight, ComputedVecValue, LazyHeightDerived, NumericValue},
|
||||
internal::{ComputedPerBlock, ComputedVecValue, DerivedResolutions, NumericValue},
|
||||
};
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyFromHeight<T, S1T = T>
|
||||
pub struct LazyPerBlock<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -19,10 +19,10 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<LazyHeightDerived<T, S1T>>,
|
||||
pub resolutions: Box<DerivedResolutions<T, S1T>>,
|
||||
}
|
||||
|
||||
impl<T, S1T> LazyFromHeight<T, S1T>
|
||||
impl<T, S1T> LazyPerBlock<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -31,14 +31,14 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: ReadableBoxedVec<Height, S1T>,
|
||||
source: &ComputedFromHeight<S1T>,
|
||||
source: &ComputedPerBlock<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, version, height_source),
|
||||
rest: Box::new(LazyHeightDerived::from_computed::<F>(name, version, source)),
|
||||
resolutions: Box::new(DerivedResolutions::from_computed::<F>(name, version, source)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ where
|
||||
{
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, version, height_source.clone()),
|
||||
rest: Box::new(LazyHeightDerived::from_height_source::<F>(
|
||||
resolutions: Box::new(DerivedResolutions::from_height_source::<F>(
|
||||
name,
|
||||
version,
|
||||
height_source,
|
||||
@@ -62,11 +62,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Create by unary-transforming a LazyFromHeight source (chaining lazy vecs).
|
||||
/// Create by unary-transforming a LazyPerBlock source (chaining lazy vecs).
|
||||
pub(crate) fn from_lazy<F, S2T>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &LazyFromHeight<S1T, S2T>,
|
||||
source: &LazyPerBlock<S1T, S2T>,
|
||||
) -> Self
|
||||
where
|
||||
F: UnaryTransform<S1T, T>,
|
||||
@@ -78,10 +78,10 @@ where
|
||||
version,
|
||||
source.height.read_only_boxed_clone(),
|
||||
),
|
||||
rest: Box::new(LazyHeightDerived::from_lazy::<F, S2T>(
|
||||
resolutions: Box::new(DerivedResolutions::from_lazy::<F, S2T>(
|
||||
name,
|
||||
version,
|
||||
&source.rest,
|
||||
&source.resolutions,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ use vecdb::{ReadableBoxedVec, ReadableCloneableVec, UnaryTransform, VecValue};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedFromHeight, ComputedHeightDerived, ComputedVecValue, NumericValue, PerPeriod,
|
||||
ComputedPerBlock, Resolutions, ComputedVecValue, NumericValue, PerResolution,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -18,9 +18,9 @@ use super::{LazyTransformLast, MapOption};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct LazyHeightDerived<T, S1T = T>(
|
||||
pub struct DerivedResolutions<T, S1T = T>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub PerPeriod<
|
||||
pub PerResolution<
|
||||
LazyTransformLast<Minute10, Option<T>, Option<S1T>>,
|
||||
LazyTransformLast<Minute30, Option<T>, Option<S1T>>,
|
||||
LazyTransformLast<Hour1, Option<T>, Option<S1T>>,
|
||||
@@ -42,7 +42,7 @@ where
|
||||
T: VecValue + PartialOrd + JsonSchema,
|
||||
S1T: VecValue;
|
||||
|
||||
impl<T, S1T> LazyHeightDerived<T, S1T>
|
||||
impl<T, S1T> DerivedResolutions<T, S1T>
|
||||
where
|
||||
T: VecValue + PartialOrd + JsonSchema + 'static,
|
||||
S1T: VecValue + PartialOrd + JsonSchema,
|
||||
@@ -50,12 +50,12 @@ where
|
||||
pub(crate) fn from_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedFromHeight<S1T>,
|
||||
source: &ComputedPerBlock<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
Self::from_derived_computed::<F>(name, version, &source.rest)
|
||||
Self::from_derived_computed::<F>(name, version, &source.resolutions)
|
||||
}
|
||||
|
||||
pub(crate) fn from_height_source<F: UnaryTransform<S1T, T>>(
|
||||
@@ -67,14 +67,14 @@ where
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
let derived = ComputedHeightDerived::forced_import(name, height_source, version, indexes);
|
||||
let derived = Resolutions::forced_import(name, height_source, version, indexes);
|
||||
Self::from_derived_computed::<F>(name, version, &derived)
|
||||
}
|
||||
|
||||
pub(crate) fn from_derived_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedHeightDerived<S1T>,
|
||||
source: &Resolutions<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -95,7 +95,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self(PerPeriod {
|
||||
Self(PerResolution {
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
@@ -109,15 +109,15 @@ where
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: epoch!(halvingepoch),
|
||||
difficultyepoch: epoch!(difficultyepoch),
|
||||
halving: epoch!(halving),
|
||||
difficulty: epoch!(difficulty),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn from_lazy<F, S2T>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &LazyHeightDerived<S1T, S2T>,
|
||||
source: &DerivedResolutions<S1T, S2T>,
|
||||
) -> Self
|
||||
where
|
||||
F: UnaryTransform<S1T, T>,
|
||||
@@ -139,7 +139,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self(PerPeriod {
|
||||
Self(PerResolution {
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
@@ -153,8 +153,8 @@ where
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: epoch!(halvingepoch),
|
||||
difficultyepoch: epoch!(difficultyepoch),
|
||||
halving: epoch!(halving),
|
||||
difficulty: epoch!(difficulty),
|
||||
})
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user