global: snapshot

This commit is contained in:
nym21
2026-03-13 16:27:10 +01:00
parent b2a1251774
commit 3709ceff8e
168 changed files with 2007 additions and 2008 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -13,7 +13,7 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
// Block count raw + cumulative
self.total.raw.height.compute_range(
self.total.base.height.compute_range(
starting_indexes.height,
&indexer.vecs.blocks.weight,
|h| (h, StoredU32::from(1_u32)),

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{BlockCountTarget, CachedWindowStarts, ComputedPerBlockCumulativeWithSums, ConstantVecs},
internal::{BlockCountTarget, CachedWindowStarts, PerBlockCumulativeWithSums, ConstantVecs},
};
impl Vecs {
@@ -21,7 +21,7 @@ impl Vecs {
version,
indexes,
),
total: ComputedPerBlockCumulativeWithSums::forced_import(
total: PerBlockCumulativeWithSums::forced_import(
db,
"block_count",
version + Version::ONE,

View File

@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
use brk_types::{StoredU32, StoredU64};
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedPerBlockCumulativeWithSums, ConstantVecs};
use crate::internal::{PerBlockCumulativeWithSums, ConstantVecs};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub target: ConstantVecs<StoredU64>,
pub total: ComputedPerBlockCumulativeWithSums<StoredU32, StoredU64, M>,
pub total: PerBlockCumulativeWithSums<StoredU32, StoredU64, M>,
}

View File

@@ -1,9 +1,8 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::{Indexes, StoredF64, StoredU32};
use brk_types::{Indexes, StoredU32};
use vecdb::Exit;
use super::super::TARGET_BLOCKS_PER_DAY_F32;
use super::Vecs;
use crate::indexes;
@@ -15,18 +14,6 @@ impl Vecs {
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
// raw is fully lazy from indexer height source — no compute needed
// Compute difficulty as hash rate equivalent
let multiplier = 2.0_f64.powi(32) / 600.0;
self.as_hash.height.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.difficulty,
|(i, v, ..)| (i, StoredF64::from(*v * multiplier)),
exit,
)?;
// Compute difficulty adjustment ratio: (current - previous) / previous
self.adjustment.bps.height.compute_ratio_change(
starting_indexes.height,
&indexer.vecs.blocks.difficulty,
@@ -34,7 +21,6 @@ impl Vecs {
exit,
)?;
// Compute epoch by height
self.epoch.height.compute_transform(
starting_indexes.height,
&indexes.height.epoch,
@@ -42,24 +28,13 @@ impl Vecs {
exit,
)?;
// Compute blocks before next adjustment
self.blocks_before_next
.height
.compute_transform(
self.blocks_before_next.height.compute_transform(
starting_indexes.height,
&indexes.height.identity,
|(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())),
exit,
)?;
// Compute days before next adjustment
self.days_before_next.height.compute_transform(
starting_indexes.height,
&self.blocks_before_next.height,
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
exit,
)?;
Ok(())
}
}

View File

@@ -6,7 +6,9 @@ use vecdb::{Database, ReadableCloneableVec};
use super::Vecs;
use crate::{
indexes,
internal::{ComputedPerBlock, Resolutions, PercentPerBlock},
internal::{
BlocksToDaysF32, DifficultyToHashF64, LazyPerBlock, PerBlock, PercentPerBlock, Resolutions,
},
};
impl Vecs {
@@ -18,33 +20,39 @@ impl Vecs {
) -> Result<Self> {
let v2 = Version::TWO;
let as_hash = LazyPerBlock::from_height_source::<DifficultyToHashF64>(
"difficulty_as_hash",
version,
indexer.vecs.blocks.difficulty.read_only_boxed_clone(),
indexes,
);
let blocks_before_next = PerBlock::forced_import(
db,
"blocks_before_next_difficulty_adjustment",
version + v2,
indexes,
)?;
let days_before_next = LazyPerBlock::from_computed::<BlocksToDaysF32>(
"days_before_next_difficulty_adjustment",
version + v2,
blocks_before_next.height.read_only_boxed_clone(),
&blocks_before_next,
);
Ok(Self {
raw: Resolutions::forced_import(
base: Resolutions::forced_import(
"difficulty",
indexer.vecs.blocks.difficulty.read_only_boxed_clone(),
version,
indexes,
),
as_hash: ComputedPerBlock::forced_import(db, "difficulty_as_hash", version, indexes)?,
adjustment: PercentPerBlock::forced_import(
db,
"difficulty_adjustment",
version,
indexes,
)?,
epoch: ComputedPerBlock::forced_import(db, "difficulty_epoch", version, indexes)?,
blocks_before_next: ComputedPerBlock::forced_import(
db,
"blocks_before_next_difficulty_adjustment",
version + v2,
indexes,
)?,
days_before_next: ComputedPerBlock::forced_import(
db,
"days_before_next_difficulty_adjustment",
version + v2,
indexes,
)?,
as_hash,
adjustment: PercentPerBlock::forced_import(db, "difficulty_adjustment", version, indexes)?,
epoch: PerBlock::forced_import(db, "difficulty_epoch", version, indexes)?,
blocks_before_next,
days_before_next,
})
}
}

View File

@@ -2,13 +2,13 @@ use brk_traversable::Traversable;
use brk_types::{BasisPointsSigned32, Epoch, StoredF32, StoredF64, StoredU32};
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedPerBlock, Resolutions, PercentPerBlock};
use crate::internal::{LazyPerBlock, PerBlock, Resolutions, PercentPerBlock};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub raw: Resolutions<StoredF64>,
pub as_hash: ComputedPerBlock<StoredF64, M>,
pub base: Resolutions<StoredF64>,
pub as_hash: LazyPerBlock<StoredF64>,
pub adjustment: PercentPerBlock<BasisPointsSigned32, M>,
pub epoch: ComputedPerBlock<Epoch, M>,
pub blocks_before_next: ComputedPerBlock<StoredU32, M>,
pub days_before_next: ComputedPerBlock<StoredF32, M>,
pub epoch: PerBlock<Epoch, M>,
pub blocks_before_next: PerBlock<StoredU32, M>,
pub days_before_next: LazyPerBlock<StoredF32, StoredU32>,
}

View File

@@ -2,7 +2,6 @@ use brk_error::Result;
use brk_types::{Indexes, StoredU32};
use vecdb::Exit;
use super::super::TARGET_BLOCKS_PER_DAY_F32;
use super::Vecs;
use crate::indexes;
@@ -27,13 +26,6 @@ impl Vecs {
exit,
)?;
self.days_before_next.height.compute_transform(
starting_indexes.height,
&self.blocks_before_next.height,
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
exit,
)?;
Ok(())
}
}

View File

@@ -1,9 +1,12 @@
use brk_error::Result;
use brk_types::Version;
use vecdb::Database;
use vecdb::{Database, ReadableCloneableVec};
use super::Vecs;
use crate::{indexes, internal::ComputedPerBlock};
use crate::{
indexes,
internal::{BlocksToDaysF32, LazyPerBlock, PerBlock},
};
impl Vecs {
pub(crate) fn forced_import(
@@ -13,20 +16,21 @@ impl Vecs {
) -> Result<Self> {
let v2 = Version::TWO;
Ok(Self {
epoch: ComputedPerBlock::forced_import(db, "halving_epoch", version, indexes)?,
blocks_before_next: ComputedPerBlock::forced_import(
db,
"blocks_before_next_halving",
version + v2,
indexes,
)?,
days_before_next: ComputedPerBlock::forced_import(
db,
let blocks_before_next = PerBlock::forced_import(
db, "blocks_before_next_halving", version + v2, indexes,
)?;
let days_before_next = LazyPerBlock::from_computed::<BlocksToDaysF32>(
"days_before_next_halving",
version + v2,
indexes,
)?,
blocks_before_next.height.read_only_boxed_clone(),
&blocks_before_next,
);
Ok(Self {
epoch: PerBlock::forced_import(db, "halving_epoch", version, indexes)?,
blocks_before_next,
days_before_next,
})
}
}

View File

@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
use brk_types::{Halving, StoredF32, StoredU32};
use vecdb::{Rw, StorageMode};
use crate::internal::ComputedPerBlock;
use crate::internal::{LazyPerBlock, PerBlock};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub epoch: ComputedPerBlock<Halving, M>,
pub blocks_before_next: ComputedPerBlock<StoredU32, M>,
pub days_before_next: ComputedPerBlock<StoredF32, M>,
pub epoch: PerBlock<Halving, M>,
pub blocks_before_next: PerBlock<StoredU32, M>,
pub days_before_next: LazyPerBlock<StoredF32, StoredU32>,
}

View File

@@ -6,7 +6,7 @@ use brk_types::Version;
use crate::{
indexes,
internal::{finalize_db, open_db},
internal::db_utils::{finalize_db, open_db},
};
use super::{

View File

@@ -3,7 +3,7 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::{CachedWindowStarts, ComputedPerBlockRollingAverage}};
use crate::{indexes, internal::{CachedWindowStarts, PerBlockRollingAverage}};
impl Vecs {
pub(crate) fn forced_import(
@@ -12,7 +12,7 @@ impl Vecs {
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let interval = ComputedPerBlockRollingAverage::forced_import(
let interval = PerBlockRollingAverage::forced_import(
db,
"block_interval",
version,

View File

@@ -4,9 +4,9 @@ use brk_traversable::Traversable;
use brk_types::Timestamp;
use vecdb::{Rw, StorageMode};
use crate::internal::ComputedPerBlockRollingAverage;
use crate::internal::PerBlockRollingAverage;
#[derive(Deref, DerefMut, Traversable)]
pub struct Vecs<M: StorageMode = Rw>(
#[traversable(flatten)] pub ComputedPerBlockRollingAverage<Timestamp, M>,
#[traversable(flatten)] pub PerBlockRollingAverage<Timestamp, M>,
);

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{CachedWindowStarts, ComputedPerBlockFull, ResolutionsFull},
internal::{CachedWindowStarts, PerBlockFull, PerBlockRolling},
};
impl Vecs {
@@ -16,14 +16,14 @@ impl Vecs {
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self {
vbytes: ComputedPerBlockFull::forced_import(
vbytes: PerBlockFull::forced_import(
db,
"block_vbytes",
version,
indexes,
cached_starts,
)?,
size: ResolutionsFull::forced_import(
size: PerBlockRolling::forced_import(
db,
"block_size",
version,

View File

@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
use brk_types::StoredU64;
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedPerBlockFull, ResolutionsFull};
use crate::internal::{PerBlockFull, PerBlockRolling};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub vbytes: ComputedPerBlockFull<StoredU64, M>,
pub size: ResolutionsFull<StoredU64, M>,
pub vbytes: PerBlockFull<StoredU64, M>,
pub size: PerBlockRolling<StoredU64, M>,
}

View File

@@ -6,7 +6,7 @@ use super::Vecs;
use crate::{
blocks::SizeVecs,
indexes,
internal::{CachedWindowStarts, LazyResolutionsFull, PercentPerBlockRollingAverage, VBytesToWeight},
internal::{CachedWindowStarts, LazyPerBlockRolling, PercentPerBlockRollingAverage, VBytesToWeight},
};
impl Vecs {
@@ -17,7 +17,7 @@ impl Vecs {
cached_starts: &CachedWindowStarts,
size: &SizeVecs,
) -> Result<Self> {
let weight = LazyResolutionsFull::from_computed_per_block_full::<VBytesToWeight>(
let weight = LazyPerBlockRolling::from_per_block_full::<VBytesToWeight>(
"block_weight",
version,
&size.vbytes,

View File

@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
use brk_types::{BasisPoints16, StoredU64, Weight};
use vecdb::{Rw, StorageMode};
use crate::internal::{LazyResolutionsFull, PercentPerBlockRollingAverage};
use crate::internal::{LazyPerBlockRolling, PercentPerBlockRollingAverage};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub weight: LazyResolutionsFull<Weight, StoredU64>,
pub weight: LazyPerBlockRolling<Weight, StoredU64>,
pub fullness: PercentPerBlockRollingAverage<BasisPoints16, M>,
}

View File

@@ -1,5 +1,5 @@
use brk_error::Result;
use brk_types::{Bitcoin, CheckedSub, Indexes, StoredF64};
use brk_types::{Bitcoin, Indexes, StoredF64};
use vecdb::Exit;
use super::Vecs;
@@ -30,8 +30,8 @@ impl Vecs {
.compute(starting_indexes.height, exit, |vec| {
vec.compute_subtract(
starting_indexes.height,
&self.coinblocks_created.raw.height,
&distribution.coinblocks_destroyed.raw.height,
&self.coinblocks_created.base.height,
&distribution.coinblocks_destroyed.base.height,
exit,
)?;
Ok(())
@@ -44,13 +44,6 @@ impl Vecs {
exit,
)?;
self.vaultedness.height.compute_transform(
starting_indexes.height,
&self.liveliness.height,
|(i, v, ..)| (i, StoredF64::from(1.0).checked_sub(v).unwrap()),
exit,
)?;
self.ratio.height.compute_divide(
starting_indexes.height,
&self.liveliness.height,

View File

@@ -1,11 +1,13 @@
use brk_error::Result;
use brk_types::Version;
use vecdb::Database;
use vecdb::{Database, ReadableCloneableVec};
use super::Vecs;
use crate::{
indexes,
internal::{CachedWindowStarts, ComputedPerBlock, ComputedPerBlockCumulativeWithSums},
internal::{
CachedWindowStarts, LazyPerBlock, OneMinusF64, PerBlock, PerBlockCumulativeWithSums,
},
};
impl Vecs {
@@ -15,29 +17,25 @@ impl Vecs {
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let liveliness = PerBlock::forced_import(db, "liveliness", version, indexes)?;
let vaultedness = LazyPerBlock::from_computed::<OneMinusF64>(
"vaultedness",
version,
liveliness.height.read_only_boxed_clone(),
&liveliness,
);
Ok(Self {
coinblocks_created: ComputedPerBlockCumulativeWithSums::forced_import(
db,
"coinblocks_created",
version,
indexes,
cached_starts,
coinblocks_created: PerBlockCumulativeWithSums::forced_import(
db, "coinblocks_created", version, indexes, cached_starts,
)?,
coinblocks_stored: ComputedPerBlockCumulativeWithSums::forced_import(
db,
"coinblocks_stored",
version,
indexes,
cached_starts,
)?,
liveliness: ComputedPerBlock::forced_import(db, "liveliness", version, indexes)?,
vaultedness: ComputedPerBlock::forced_import(db, "vaultedness", version, indexes)?,
ratio: ComputedPerBlock::forced_import(
db,
"activity_to_vaultedness_ratio",
version,
indexes,
coinblocks_stored: PerBlockCumulativeWithSums::forced_import(
db, "coinblocks_stored", version, indexes, cached_starts,
)?,
liveliness,
vaultedness,
ratio: PerBlock::forced_import(db, "activity_to_vaultedness_ratio", version, indexes)?,
})
}
}

View File

@@ -2,13 +2,13 @@ use brk_traversable::Traversable;
use brk_types::StoredF64;
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedPerBlock, ComputedPerBlockCumulativeWithSums};
use crate::internal::{LazyPerBlock, PerBlock, PerBlockCumulativeWithSums};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub coinblocks_created: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub coinblocks_stored: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub liveliness: ComputedPerBlock<StoredF64, M>,
pub vaultedness: ComputedPerBlock<StoredF64, M>,
pub ratio: ComputedPerBlock<StoredF64, M>,
pub coinblocks_created: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub coinblocks_stored: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub liveliness: PerBlock<StoredF64, M>,
pub vaultedness: LazyPerBlock<StoredF64>,
pub ratio: PerBlock<StoredF64, M>,
}

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedPerBlock, PercentPerBlock},
internal::{PerBlock, PercentPerBlock},
};
impl Vecs {
@@ -21,13 +21,13 @@ impl Vecs {
version,
indexes,
)?,
tx_velocity_btc: ComputedPerBlock::forced_import(
tx_velocity_btc: PerBlock::forced_import(
db,
"cointime_adj_tx_velocity_btc",
version,
indexes,
)?,
tx_velocity_usd: ComputedPerBlock::forced_import(
tx_velocity_usd: PerBlock::forced_import(
db,
"cointime_adj_tx_velocity_usd",
version,

View File

@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
use brk_types::{BasisPointsSigned32, StoredF64};
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedPerBlock, PercentPerBlock};
use crate::internal::{PerBlock, PercentPerBlock};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub inflation_rate: PercentPerBlock<BasisPointsSigned32, M>,
pub tx_velocity_btc: ComputedPerBlock<StoredF64, M>,
pub tx_velocity_usd: ComputedPerBlock<StoredF64, M>,
pub tx_velocity_btc: PerBlock<StoredF64, M>,
pub tx_velocity_usd: PerBlock<StoredF64, M>,
}

View File

@@ -5,7 +5,7 @@ use brk_types::Version;
use crate::{
indexes,
internal::{finalize_db, open_db},
internal::db_utils::{finalize_db, open_db},
};
use super::{

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedPerBlock, PriceWithRatioExtendedPerBlock},
internal::{PerBlock, PriceWithRatioExtendedPerBlock},
};
impl Vecs {
@@ -29,7 +29,7 @@ impl Vecs {
balanced: import!("balanced_price"),
terminal: import!("terminal_price"),
delta: import!("delta_price"),
cumulative_market_cap: ComputedPerBlock::forced_import(
cumulative_market_cap: PerBlock::forced_import(
db,
"cumulative_market_cap",
version,

View File

@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
use brk_types::Dollars;
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedPerBlock, PriceWithRatioExtendedPerBlock};
use crate::internal::{PerBlock, PriceWithRatioExtendedPerBlock};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
@@ -15,5 +15,5 @@ pub struct Vecs<M: StorageMode = Rw> {
pub terminal: PriceWithRatioExtendedPerBlock<M>,
pub delta: PriceWithRatioExtendedPerBlock<M>,
pub cumulative_market_cap: ComputedPerBlock<Dollars, M>,
pub cumulative_market_cap: PerBlock<Dollars, M>,
}

View File

@@ -3,7 +3,7 @@ use brk_types::{Indexes, StoredF64};
use vecdb::Exit;
use super::{super::value, Vecs};
use crate::{blocks, internal::ComputeRollingMedianFromStarts, prices};
use crate::{blocks, internal::algo::ComputeRollingMedianFromStarts, prices};
impl Vecs {
pub(crate) fn compute(
@@ -17,7 +17,7 @@ impl Vecs {
self.vocdd_median_1y.compute_rolling_median_from_starts(
starting_indexes.height,
&blocks.lookback._1y,
&value.vocdd.raw.height,
&value.vocdd.base.height,
exit,
)?;

View File

@@ -3,7 +3,7 @@ use brk_types::Version;
use vecdb::{Database, EagerVec, ImportableVec};
use super::Vecs;
use crate::{indexes, internal::ComputedPerBlock};
use crate::{indexes, internal::PerBlock};
impl Vecs {
pub(crate) fn forced_import(
@@ -15,7 +15,7 @@ impl Vecs {
Ok(Self {
vocdd_median_1y: EagerVec::forced_import(db, "vocdd_median_1y", v1)?,
hodl_bank: EagerVec::forced_import(db, "hodl_bank", v1)?,
value: ComputedPerBlock::forced_import(db, "reserve_risk", v1, indexes)?,
value: PerBlock::forced_import(db, "reserve_risk", v1, indexes)?,
})
}
}

View File

@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
use brk_types::{Height, StoredF64};
use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
use crate::internal::ComputedPerBlock;
use crate::internal::PerBlock;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub value: ComputedPerBlock<StoredF64, M>,
pub value: PerBlock<StoredF64, M>,
pub vocdd_median_1y: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
pub hodl_bank: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
}

View File

@@ -25,7 +25,7 @@ impl Vecs {
vec.compute_multiply(
starting_indexes.height,
&prices.spot.usd.height,
&coinblocks_destroyed.raw.height,
&coinblocks_destroyed.base.height,
exit,
)?;
Ok(())
@@ -36,7 +36,7 @@ impl Vecs {
vec.compute_multiply(
starting_indexes.height,
&prices.spot.usd.height,
&activity.coinblocks_created.raw.height,
&activity.coinblocks_created.base.height,
exit,
)?;
Ok(())
@@ -47,7 +47,7 @@ impl Vecs {
vec.compute_multiply(
starting_indexes.height,
&prices.spot.usd.height,
&activity.coinblocks_stored.raw.height,
&activity.coinblocks_stored.base.height,
exit,
)?;
Ok(())
@@ -61,7 +61,7 @@ impl Vecs {
vec.compute_transform3(
starting_indexes.height,
&prices.spot.usd.height,
&coindays_destroyed.raw.height,
&coindays_destroyed.base.height,
circulating_supply,
|(i, price, cdd, supply, _): (_, Dollars, StoredF64, Bitcoin, _)| {
let supply_f64 = f64::from(supply);

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{CachedWindowStarts, ComputedPerBlockCumulativeWithSums},
internal::{CachedWindowStarts, PerBlockCumulativeWithSums},
};
impl Vecs {
@@ -16,28 +16,28 @@ impl Vecs {
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self {
destroyed: ComputedPerBlockCumulativeWithSums::forced_import(
destroyed: PerBlockCumulativeWithSums::forced_import(
db,
"cointime_value_destroyed",
version,
indexes,
cached_starts,
)?,
created: ComputedPerBlockCumulativeWithSums::forced_import(
created: PerBlockCumulativeWithSums::forced_import(
db,
"cointime_value_created",
version,
indexes,
cached_starts,
)?,
stored: ComputedPerBlockCumulativeWithSums::forced_import(
stored: PerBlockCumulativeWithSums::forced_import(
db,
"cointime_value_stored",
version,
indexes,
cached_starts,
)?,
vocdd: ComputedPerBlockCumulativeWithSums::forced_import(
vocdd: PerBlockCumulativeWithSums::forced_import(
db,
"vocdd",
version + Version::ONE,

View File

@@ -2,12 +2,12 @@ use brk_traversable::Traversable;
use brk_types::StoredF64;
use vecdb::{Rw, StorageMode};
use crate::internal::ComputedPerBlockCumulativeWithSums;
use crate::internal::PerBlockCumulativeWithSums;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub destroyed: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub created: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub stored: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub vocdd: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub created: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub stored: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub vocdd: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
}

View File

@@ -19,7 +19,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec};
use crate::{
indexes,
internal::{CachedWindowStarts, ComputedPerBlockRollingAverage},
internal::{CachedWindowStarts, PerBlockRollingAverage},
};
/// 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: ComputedPerBlockRollingAverage<StoredU32, M>,
pub sending: ComputedPerBlockRollingAverage<StoredU32, M>,
pub receiving: ComputedPerBlockRollingAverage<StoredU32, M>,
pub both: ComputedPerBlockRollingAverage<StoredU32, M>,
pub reactivated: PerBlockRollingAverage<StoredU32, M>,
pub sending: PerBlockRollingAverage<StoredU32, M>,
pub receiving: PerBlockRollingAverage<StoredU32, M>,
pub both: PerBlockRollingAverage<StoredU32, M>,
}
impl ActivityCountVecs {
@@ -80,28 +80,28 @@ impl ActivityCountVecs {
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self {
reactivated: ComputedPerBlockRollingAverage::forced_import(
reactivated: PerBlockRollingAverage::forced_import(
db,
&format!("{name}_reactivated"),
version,
indexes,
cached_starts,
)?,
sending: ComputedPerBlockRollingAverage::forced_import(
sending: PerBlockRollingAverage::forced_import(
db,
&format!("{name}_sending"),
version,
indexes,
cached_starts,
)?,
receiving: ComputedPerBlockRollingAverage::forced_import(
receiving: PerBlockRollingAverage::forced_import(
db,
&format!("{name}_receiving"),
version,
indexes,
cached_starts,
)?,
both: ComputedPerBlockRollingAverage::forced_import(
both: PerBlockRollingAverage::forced_import(
db,
&format!("{name}_both"),
version,

View File

@@ -9,11 +9,11 @@ use vecdb::{
WritableVec,
};
use crate::{indexes, internal::ComputedPerBlock};
use crate::{indexes, internal::PerBlock};
#[derive(Deref, DerefMut, Traversable)]
pub struct AddressCountVecs<M: StorageMode = Rw>(
#[traversable(flatten)] pub ComputedPerBlock<StoredU64, M>,
#[traversable(flatten)] pub PerBlock<StoredU64, M>,
);
impl AddressCountVecs {
@@ -23,7 +23,7 @@ impl AddressCountVecs {
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self(ComputedPerBlock::forced_import(
Ok(Self(PerBlock::forced_import(
db, name, version, indexes,
)?))
}

View File

@@ -6,7 +6,7 @@ use vecdb::{Database, Exit, Rw, StorageMode};
use crate::{
indexes,
internal::{CachedWindowStarts, ComputedPerBlockCumulativeWithSums},
internal::{CachedWindowStarts, PerBlockCumulativeWithSums},
};
use super::TotalAddressCountVecs;
@@ -14,9 +14,9 @@ use super::TotalAddressCountVecs;
/// New address count per block (global + per-type)
#[derive(Traversable)]
pub struct NewAddressCountVecs<M: StorageMode = Rw> {
pub all: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub all: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
#[traversable(flatten)]
pub by_addresstype: ByAddressType<ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>>,
pub by_addresstype: ByAddressType<PerBlockCumulativeWithSums<StoredU64, StoredU64, M>>,
}
impl NewAddressCountVecs {
@@ -26,7 +26,7 @@ impl NewAddressCountVecs {
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let all = ComputedPerBlockCumulativeWithSums::forced_import(
let all = PerBlockCumulativeWithSums::forced_import(
db,
"new_address_count",
version,
@@ -35,7 +35,7 @@ impl NewAddressCountVecs {
)?;
let by_addresstype = ByAddressType::new_with_name(|name| {
ComputedPerBlockCumulativeWithSums::forced_import(
PerBlockCumulativeWithSums::forced_import(
db,
&format!("{name}_new_address_count"),
version,

View File

@@ -4,16 +4,16 @@ use brk_traversable::Traversable;
use brk_types::{Height, StoredU64, Version};
use vecdb::{Database, Exit, Rw, StorageMode};
use crate::{indexes, internal::ComputedPerBlock};
use crate::{indexes, internal::PerBlock};
use super::AddressCountsVecs;
/// Total address count (global + per-type) with all derived indexes
#[derive(Traversable)]
pub struct TotalAddressCountVecs<M: StorageMode = Rw> {
pub all: ComputedPerBlock<StoredU64, M>,
pub all: PerBlock<StoredU64, M>,
#[traversable(flatten)]
pub by_addresstype: ByAddressType<ComputedPerBlock<StoredU64, M>>,
pub by_addresstype: ByAddressType<PerBlock<StoredU64, M>>,
}
impl TotalAddressCountVecs {
@@ -22,11 +22,11 @@ impl TotalAddressCountVecs {
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
let all = ComputedPerBlock::forced_import(db, "total_address_count", version, indexes)?;
let all = PerBlock::forced_import(db, "total_address_count", version, indexes)?;
let by_addresstype: ByAddressType<ComputedPerBlock<StoredU64>> =
let by_addresstype: ByAddressType<PerBlock<StoredU64>> =
ByAddressType::new_with_name(|name| {
ComputedPerBlock::forced_import(
PerBlock::forced_import(
db,
&format!("{name}_total_address_count"),
version,

View File

@@ -10,7 +10,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Rw, StorageMode,
use crate::{
distribution::state::{AddressCohortState, MinimalRealizedState},
indexes,
internal::{CachedWindowStarts, ComputedPerBlockWithDeltas},
internal::{CachedWindowStarts, PerBlockWithDeltas},
prices,
};
@@ -27,7 +27,7 @@ pub struct AddressCohortVecs<M: StorageMode = Rw> {
#[traversable(flatten)]
pub metrics: MinimalCohortMetrics<M>,
pub address_count: ComputedPerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
pub address_count: PerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
}
impl AddressCohortVecs {
@@ -51,7 +51,7 @@ impl AddressCohortVecs {
cached_starts,
};
let address_count = ComputedPerBlockWithDeltas::forced_import(
let address_count = PerBlockWithDeltas::forced_import(
db,
&cfg.name("address_count"),
version,

View File

@@ -3,7 +3,7 @@ use brk_types::{Cents, CentsCompact, Sats};
use crate::{
distribution::state::PendingDelta,
internal::{FenwickNode, FenwickTree, PERCENTILES, PERCENTILES_LEN},
internal::{PERCENTILES, PERCENTILES_LEN, algo::{FenwickNode, FenwickTree}},
};
use super::COST_BASIS_PRICE_DIGITS;

View File

@@ -538,7 +538,7 @@ impl UTXOCohorts<Rw> {
.minimal
.sopr
.value_created
.raw
.base
.height
.read_only_clone();
let under_1h_value_destroyed = self
@@ -549,7 +549,7 @@ impl UTXOCohorts<Rw> {
.minimal
.sopr
.value_destroyed
.raw
.base
.height
.read_only_clone();

View File

@@ -66,7 +66,7 @@ pub(crate) fn process_blocks(
let height_to_first_txindex = &indexer.vecs.transactions.first_txindex;
let height_to_first_txoutindex = &indexer.vecs.outputs.first_txoutindex;
let height_to_first_txinindex = &indexer.vecs.inputs.first_txinindex;
let height_to_tx_count = &transactions.count.total.raw.height;
let height_to_tx_count = &transactions.count.total.base.height;
let height_to_output_count = &outputs.count.total.full.sum;
let height_to_input_count = &inputs.count.full.sum;
let txindex_to_output_count = &indexes.txindex.output_count;
@@ -364,7 +364,7 @@ pub(crate) fn process_blocks(
blocks_old as u128 * u64::from(sent.spendable_supply.value) as u128
})
.sum();
vecs.coinblocks_destroyed.raw.height.truncate_push(
vecs.coinblocks_destroyed.base.height.truncate_push(
height,
StoredF64::from(total_satblocks as f64 / Sats::ONE_BTC_U128 as f64),
)?;

View File

@@ -82,7 +82,7 @@ pub(crate) fn write(
.chain(
[
&mut vecs.supply_state as &mut dyn AnyStoredVec,
&mut vecs.coinblocks_destroyed.raw.height,
&mut vecs.coinblocks_destroyed.base.height,
]
.into_par_iter(),
)

View File

@@ -5,14 +5,14 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
use crate::{
distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}},
internal::{AmountPerBlockCumulativeWithSums, ComputedPerBlockCumulativeWithSums},
internal::{AmountPerBlockCumulativeWithSums, PerBlockCumulativeWithSums},
prices,
};
#[derive(Traversable)]
pub struct ActivityCore<M: StorageMode = Rw> {
pub sent: ComputedPerBlockCumulativeWithSums<Sats, Sats, M>,
pub coindays_destroyed: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub sent: PerBlockCumulativeWithSums<Sats, Sats, M>,
pub coindays_destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
#[traversable(wrap = "sent", rename = "in_profit")]
pub sent_in_profit: AmountPerBlockCumulativeWithSums<M>,
#[traversable(wrap = "sent", rename = "in_loss")]
@@ -32,12 +32,12 @@ impl ActivityCore {
pub(crate) fn min_len(&self) -> usize {
self.sent
.raw
.base
.height
.len()
.min(self.coindays_destroyed.raw.height.len())
.min(self.sent_in_profit.raw.sats.height.len())
.min(self.sent_in_loss.raw.sats.height.len())
.min(self.coindays_destroyed.base.height.len())
.min(self.sent_in_profit.base.sats.height.len())
.min(self.sent_in_loss.base.sats.height.len())
}
pub(crate) fn truncate_push(
@@ -45,18 +45,18 @@ impl ActivityCore {
height: Height,
state: &CohortState<impl RealizedOps, impl CostBasisOps>,
) -> Result<()> {
self.sent.raw.height.truncate_push(height, state.sent)?;
self.coindays_destroyed.raw.height.truncate_push(
self.sent.base.height.truncate_push(height, state.sent)?;
self.coindays_destroyed.base.height.truncate_push(
height,
StoredF64::from(Bitcoin::from(state.satdays_destroyed)),
)?;
self.sent_in_profit
.raw
.base
.sats
.height
.truncate_push(height, state.realized.sent_in_profit())?;
self.sent_in_loss
.raw
.base
.sats
.height
.truncate_push(height, state.realized.sent_in_loss())?;
@@ -65,12 +65,12 @@ impl ActivityCore {
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
vec![
&mut self.sent.raw.height as &mut dyn AnyStoredVec,
&mut self.coindays_destroyed.raw.height,
&mut self.sent_in_profit.raw.sats.height,
&mut self.sent_in_profit.raw.cents.height,
&mut self.sent_in_loss.raw.sats.height,
&mut self.sent_in_loss.raw.cents.height,
&mut self.sent.base.height as &mut dyn AnyStoredVec,
&mut self.coindays_destroyed.base.height,
&mut self.sent_in_profit.base.sats.height,
&mut self.sent_in_profit.base.cents.height,
&mut self.sent_in_loss.base.sats.height,
&mut self.sent_in_loss.base.cents.height,
]
}
@@ -84,18 +84,18 @@ impl ActivityCore {
others: &[&Self],
exit: &Exit,
) -> Result<()> {
self.sent.raw.height.compute_sum_of_others(
self.sent.base.height.compute_sum_of_others(
starting_indexes.height,
&others
.iter()
.map(|v| &v.sent.raw.height)
.map(|v| &v.sent.base.height)
.collect::<Vec<_>>(),
exit,
)?;
sum_others!(self, starting_indexes, others, exit; coindays_destroyed.raw.height);
sum_others!(self, starting_indexes, others, exit; sent_in_profit.raw.sats.height);
sum_others!(self, starting_indexes, others, exit; sent_in_loss.raw.sats.height);
sum_others!(self, starting_indexes, others, exit; coindays_destroyed.base.height);
sum_others!(self, starting_indexes, others, exit; sent_in_profit.base.sats.height);
sum_others!(self, starting_indexes, others, exit; sent_in_loss.base.sats.height);
Ok(())
}

View File

@@ -4,7 +4,7 @@ use brk_types::{Bitcoin, Height, Indexes, Sats, StoredF32, StoredF64, Version};
use derive_more::{Deref, DerefMut};
use vecdb::{AnyStoredVec, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
use crate::internal::{ComputedPerBlock, Identity, LazyPerBlock};
use crate::internal::{PerBlock, Identity, LazyPerBlock};
use crate::distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}};
@@ -19,8 +19,8 @@ pub struct ActivityFull<M: StorageMode = Rw> {
pub coinyears_destroyed: LazyPerBlock<StoredF64, StoredF64>,
pub dormancy: ComputedPerBlock<StoredF32, M>,
pub velocity: ComputedPerBlock<StoredF32, M>,
pub dormancy: PerBlock<StoredF32, M>,
pub velocity: PerBlock<StoredF32, M>,
}
impl ActivityFull {
@@ -88,8 +88,8 @@ impl ActivityFull {
) -> Result<()> {
self.dormancy.height.compute_transform2(
starting_indexes.height,
&self.inner.coindays_destroyed.raw.height,
&self.inner.sent.raw.height,
&self.inner.coindays_destroyed.base.height,
&self.inner.sent.base.height,
|(i, cdd, sent_sats, ..)| {
let sent_btc = f64::from(Bitcoin::from(sent_sats));
if sent_btc == 0.0 {
@@ -103,7 +103,7 @@ impl ActivityFull {
self.velocity.height.compute_transform2(
starting_indexes.height,
&self.inner.sent.raw.height,
&self.inner.sent.base.height,
supply_total_sats,
|(i, sent_sats, supply_sats, ..)| {
let supply = supply_sats.as_u128() as f64;

View File

@@ -128,8 +128,8 @@ impl AllCohortMetrics {
self.asopr.compute_rest_part2(
starting_indexes,
&self.realized.minimal.sopr.value_created.raw.height,
&self.realized.minimal.sopr.value_destroyed.raw.height,
&self.realized.minimal.sopr.value_created.base.height,
&self.realized.minimal.sopr.value_destroyed.base.height,
under_1h_value_created,
under_1h_value_destroyed,
exit,

View File

@@ -80,8 +80,8 @@ impl ExtendedAdjustedCohortMetrics {
self.asopr.compute_rest_part2(
starting_indexes,
&self.inner.realized.minimal.sopr.value_created.raw.height,
&self.inner.realized.minimal.sopr.value_destroyed.raw.height,
&self.inner.realized.minimal.sopr.value_created.base.height,
&self.inner.realized.minimal.sopr.value_destroyed.base.height,
under_1h_value_created,
under_1h_value_destroyed,
exit,

View File

@@ -8,8 +8,8 @@ use crate::{
indexes,
internal::{
AmountPerBlock, AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums,
CachedWindowStarts, CentsType, ComputedPerBlock,
ComputedPerBlockCumulative, ComputedPerBlockCumulativeWithSums,
CachedWindowStarts, CentsType, PerBlock,
PerBlockCumulative, PerBlockCumulativeWithSums,
FiatPerBlock, FiatPerBlockCumulativeWithSums, NumericValue,
PercentPerBlock, PercentRollingWindows, Price,
PriceWithRatioExtendedPerBlock, PriceWithRatioPerBlock, RatioPerBlock,
@@ -47,21 +47,21 @@ impl_config_import!(
PercentPerBlock<BasisPoints32>,
PercentPerBlock<BasisPointsSigned32>,
PercentRollingWindows<BasisPoints32>,
Price<ComputedPerBlock<Cents>>,
Price<PerBlock<Cents>>,
);
// Generic types (macro_rules can't parse generic bounds, so written out)
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedPerBlock<T> {
impl<T: NumericValue + JsonSchema> ConfigImport for PerBlock<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 ComputedPerBlockCumulative<T> {
impl<T: NumericValue + JsonSchema> ConfigImport for PerBlockCumulative<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, C> ConfigImport for ComputedPerBlockCumulativeWithSums<T, C>
impl<T, C> ConfigImport for PerBlockCumulativeWithSums<T, C>
where
T: NumericValue + JsonSchema + Into<C>,
C: NumericValue + JsonSchema,

View File

@@ -3,7 +3,7 @@ use brk_traversable::Traversable;
use brk_types::{BasisPoints16, Cents, Height, Version};
use vecdb::{AnyStoredVec, AnyVec, Rw, StorageMode, WritableVec};
use crate::internal::{ComputedPerBlock, PercentPerBlock, PercentilesVecs, Price, PERCENTILES_LEN};
use crate::internal::{PerBlock, PercentPerBlock, 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<ComputedPerBlock<Cents, M>>,
pub max: Price<ComputedPerBlock<Cents, M>>,
pub min: Price<PerBlock<Cents, M>>,
pub max: Price<PerBlock<Cents, M>>,
pub percentiles: PercentilesVecs<M>,
pub invested_capital: PercentilesVecs<M>,
pub supply_density: PercentPerBlock<BasisPoints16, M>,

View File

@@ -8,19 +8,19 @@ use crate::{
metrics::ImportConfig,
state::{CohortState, CostBasisOps, RealizedOps},
},
internal::ComputedPerBlockWithDeltas,
internal::PerBlockWithDeltas,
};
/// Base output metrics: utxo_count + delta.
#[derive(Traversable)]
pub struct OutputsBase<M: StorageMode = Rw> {
pub unspent_count: ComputedPerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
pub unspent_count: PerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
}
impl OutputsBase {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(Self {
unspent_count: ComputedPerBlockWithDeltas::forced_import(
unspent_count: PerBlockWithDeltas::forced_import(
cfg.db,
&cfg.name("utxo_count"),
cfg.version,

View File

@@ -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::ComputedPerBlock};
use crate::{indexes, internal::PerBlock};
/// Supply + realized cap for a single profitability bucket.
#[derive(Traversable)]
pub struct ProfitabilityBucket<M: StorageMode = Rw> {
pub supply: ComputedPerBlock<Sats, M>,
pub realized_cap: ComputedPerBlock<Dollars, M>,
pub supply: PerBlock<Sats, M>,
pub realized_cap: PerBlock<Dollars, M>,
}
impl<M: StorageMode> ProfitabilityBucket<M> {
@@ -27,13 +27,13 @@ impl ProfitabilityBucket {
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
supply: ComputedPerBlock::forced_import(
supply: PerBlock::forced_import(
db,
&format!("{name}_supply"),
version,
indexes,
)?,
realized_cap: ComputedPerBlock::forced_import(
realized_cap: PerBlock::forced_import(
db,
&format!("{name}_realized_cap"),
version,

View File

@@ -5,13 +5,13 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
use crate::{
distribution::metrics::ImportConfig,
internal::{ComputedPerBlockCumulativeWithSums, RatioCents64, RollingWindows},
internal::{PerBlockCumulativeWithSums, RatioCents64, RollingWindows},
};
#[derive(Traversable)]
pub struct AdjustedSopr<M: StorageMode = Rw> {
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub ratio: RollingWindows<StoredF64, M>,
}
@@ -35,13 +35,13 @@ impl AdjustedSopr {
exit: &Exit,
) -> Result<()> {
// Compute value_created = base.value_created - under_1h.value_created
self.value_created.raw.height.compute_subtract(
self.value_created.base.height.compute_subtract(
starting_indexes.height,
base_value_created,
under_1h_value_created,
exit,
)?;
self.value_destroyed.raw.height.compute_subtract(
self.value_destroyed.base.height.compute_subtract(
starting_indexes.height,
base_value_destroyed,
under_1h_value_destroyed,

View File

@@ -46,7 +46,7 @@ impl RealizedCore {
let neg_realized_loss = LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
&cfg.name("neg_realized_loss"),
cfg.version + Version::ONE,
minimal.loss.raw.cents.height.read_only_boxed_clone(),
minimal.loss.base.cents.height.read_only_boxed_clone(),
cfg.indexes,
);
@@ -103,10 +103,10 @@ impl RealizedCore {
self.minimal
.compute_rest_part1(starting_indexes, exit)?;
self.net_pnl.raw.cents.height.compute_transform2(
self.net_pnl.base.cents.height.compute_transform2(
starting_indexes.height,
&self.minimal.profit.raw.cents.height,
&self.minimal.loss.raw.cents.height,
&self.minimal.profit.base.cents.height,
&self.minimal.loss.base.cents.height,
|(i, profit, loss, ..)| {
(
i,

View File

@@ -14,8 +14,8 @@ use crate::{
blocks,
distribution::state::{WithCapital, CohortState, CostBasisData, RealizedState},
internal::{
CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative,
ComputedPerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
CentsUnsignedToDollars, PerBlock, PerBlockCumulative,
PerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
LazyPerBlock, PercentPerBlock, PercentRollingWindows, Price,
PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32,
RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32,
@@ -32,16 +32,16 @@ use super::RealizedCore;
#[derive(Traversable)]
pub struct RealizedProfit<M: StorageMode = Rw> {
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub distribution_flow: LazyPerBlock<Dollars, Cents>,
}
#[derive(Traversable)]
pub struct RealizedLoss<M: StorageMode = Rw> {
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub capitulation_flow: LazyPerBlock<Dollars, Cents>,
}
@@ -63,15 +63,15 @@ pub struct RealizedSopr<M: StorageMode = Rw> {
#[derive(Traversable)]
pub struct RealizedPeakRegret<M: StorageMode = Rw> {
#[traversable(flatten)]
pub value: ComputedPerBlockCumulative<Cents, M>,
pub value: PerBlockCumulative<Cents, M>,
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
}
#[derive(Traversable)]
pub struct RealizedInvestor<M: StorageMode = Rw> {
pub price: PriceWithRatioExtendedPerBlock<M>,
pub lower_price_band: Price<ComputedPerBlock<Cents, M>>,
pub upper_price_band: Price<ComputedPerBlock<Cents, M>>,
pub lower_price_band: Price<PerBlock<Cents, M>>,
pub upper_price_band: Price<PerBlock<Cents, M>>,
#[traversable(hidden)]
pub cap_raw: M::Stored<BytesVec<Height, CentsSquaredSats>>,
}
@@ -115,13 +115,13 @@ impl RealizedFull {
let core = RealizedCore::forced_import(cfg)?;
// Profit
let profit_value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents> =
let profit_value_destroyed: PerBlockCumulativeWithSums<Cents, Cents> =
cfg.import("profit_value_destroyed", v1)?;
let profit_flow = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
&cfg.name("distribution_flow"),
cfg.version,
profit_value_destroyed.raw.height.read_only_boxed_clone(),
&profit_value_destroyed.raw,
profit_value_destroyed.base.height.read_only_boxed_clone(),
&profit_value_destroyed.base,
);
let profit = RealizedProfit {
rel_to_rcap: cfg.import("realized_profit_rel_to_rcap", Version::new(2))?,
@@ -131,13 +131,13 @@ impl RealizedFull {
};
// Loss
let loss_value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents> =
let loss_value_destroyed: PerBlockCumulativeWithSums<Cents, Cents> =
cfg.import("loss_value_destroyed", v1)?;
let capitulation_flow = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
&cfg.name("capitulation_flow"),
cfg.version,
loss_value_destroyed.raw.height.read_only_boxed_clone(),
&loss_value_destroyed.raw,
loss_value_destroyed.base.height.read_only_boxed_clone(),
&loss_value_destroyed.base,
);
let loss = RealizedLoss {
rel_to_rcap: cfg.import("realized_loss_rel_to_rcap", Version::new(2))?,
@@ -222,16 +222,16 @@ impl RealizedFull {
pub(crate) fn min_stateful_len(&self) -> usize {
self.profit
.value_created
.raw
.base
.height
.len()
.min(self.profit.value_destroyed.raw.height.len())
.min(self.loss.value_created.raw.height.len())
.min(self.loss.value_destroyed.raw.height.len())
.min(self.profit.value_destroyed.base.height.len())
.min(self.loss.value_created.base.height.len())
.min(self.loss.value_destroyed.base.height.len())
.min(self.investor.price.cents.height.len())
.min(self.cap_raw.len())
.min(self.investor.cap_raw.len())
.min(self.peak_regret.value.raw.height.len())
.min(self.peak_regret.value.base.height.len())
}
pub(crate) fn truncate_push(
@@ -242,22 +242,22 @@ impl RealizedFull {
self.core.truncate_push(height, state)?;
self.profit
.value_created
.raw
.base
.height
.truncate_push(height, state.realized.profit_value_created())?;
self.profit
.value_destroyed
.raw
.base
.height
.truncate_push(height, state.realized.profit_value_destroyed())?;
self.loss
.value_created
.raw
.base
.height
.truncate_push(height, state.realized.loss_value_created())?;
self.loss
.value_destroyed
.raw
.base
.height
.truncate_push(height, state.realized.loss_value_destroyed())?;
self.investor
@@ -272,7 +272,7 @@ impl RealizedFull {
.truncate_push(height, state.realized.investor_cap_raw())?;
self.peak_regret
.value
.raw
.base
.height
.truncate_push(height, state.realized.peak_regret())?;
@@ -281,14 +281,14 @@ impl RealizedFull {
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
let mut vecs = self.core.collect_vecs_mut();
vecs.push(&mut self.profit.value_created.raw.height as &mut dyn AnyStoredVec);
vecs.push(&mut self.profit.value_destroyed.raw.height);
vecs.push(&mut self.loss.value_created.raw.height);
vecs.push(&mut self.loss.value_destroyed.raw.height);
vecs.push(&mut self.profit.value_created.base.height as &mut dyn AnyStoredVec);
vecs.push(&mut self.profit.value_destroyed.base.height);
vecs.push(&mut self.loss.value_created.base.height);
vecs.push(&mut self.loss.value_destroyed.base.height);
vecs.push(&mut self.investor.price.cents.height);
vecs.push(&mut self.cap_raw as &mut dyn AnyStoredVec);
vecs.push(&mut self.investor.cap_raw as &mut dyn AnyStoredVec);
vecs.push(&mut self.peak_regret.value.raw.height);
vecs.push(&mut self.peak_regret.value.base.height);
vecs
}
@@ -311,22 +311,22 @@ impl RealizedFull {
) -> Result<()> {
self.profit
.value_created
.raw
.base
.height
.truncate_push(height, accum.profit_value_created)?;
self.profit
.value_destroyed
.raw
.base
.height
.truncate_push(height, accum.profit_value_destroyed)?;
self.loss
.value_created
.raw
.base
.height
.truncate_push(height, accum.loss_value_created)?;
self.loss
.value_destroyed
.raw
.base
.height
.truncate_push(height, accum.loss_value_destroyed)?;
self.cap_raw
@@ -351,7 +351,7 @@ impl RealizedFull {
self.peak_regret
.value
.raw
.base
.height
.truncate_push(height, accum.peak_regret)?;
@@ -410,7 +410,7 @@ impl RealizedFull {
.rel_to_rcap
.compute_binary::<Cents, Cents, RatioCentsBp32>(
starting_indexes.height,
&self.core.minimal.profit.raw.cents.height,
&self.core.minimal.profit.base.cents.height,
&self.core.minimal.cap.cents.height,
exit,
)?;
@@ -418,7 +418,7 @@ impl RealizedFull {
.rel_to_rcap
.compute_binary::<Cents, Cents, RatioCentsBp32>(
starting_indexes.height,
&self.core.minimal.loss.raw.cents.height,
&self.core.minimal.loss.base.cents.height,
&self.core.minimal.cap.cents.height,
exit,
)?;
@@ -426,7 +426,7 @@ impl RealizedFull {
.rel_to_rcap
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
starting_indexes.height,
&self.core.net_pnl.raw.cents.height,
&self.core.net_pnl.base.cents.height,
&self.core.minimal.cap.cents.height,
exit,
)?;
@@ -446,10 +446,10 @@ impl RealizedFull {
.compute_rest(starting_indexes.height, exit)?;
// Gross PnL
self.gross_pnl.raw.cents.height.compute_add(
self.gross_pnl.base.cents.height.compute_add(
starting_indexes.height,
&self.core.minimal.profit.raw.cents.height,
&self.core.minimal.loss.raw.cents.height,
&self.core.minimal.profit.base.cents.height,
&self.core.minimal.loss.base.cents.height,
exit,
)?;
self.gross_pnl
@@ -478,7 +478,7 @@ impl RealizedFull {
.rel_to_rcap
.compute_binary::<Cents, Cents, RatioCentsBp32>(
starting_indexes.height,
&self.peak_regret.value.raw.height,
&self.peak_regret.value.base.height,
&self.core.minimal.cap.cents.height,
exit,
)?;

View File

@@ -11,7 +11,7 @@ use vecdb::{
use crate::{
distribution::state::{CohortState, CostBasisOps, RealizedOps},
internal::{
ComputedPerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
PerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
FiatPerBlockWithDeltas, Identity, LazyPerBlock, PriceWithRatioPerBlock,
},
prices,
@@ -21,8 +21,8 @@ use crate::distribution::metrics::ImportConfig;
#[derive(Traversable)]
pub struct RealizedSoprMinimal<M: StorageMode = Rw> {
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
}
#[derive(Traversable)]
@@ -74,24 +74,24 @@ impl RealizedMinimal {
.cents
.height
.len()
.min(self.profit.raw.cents.height.len())
.min(self.loss.raw.cents.height.len())
.min(self.sopr.value_created.raw.height.len())
.min(self.sopr.value_destroyed.raw.height.len())
.min(self.profit.base.cents.height.len())
.min(self.loss.base.cents.height.len())
.min(self.sopr.value_created.base.height.len())
.min(self.sopr.value_destroyed.base.height.len())
}
pub(crate) fn truncate_push(&mut self, height: Height, state: &CohortState<impl RealizedOps, impl CostBasisOps>) -> Result<()> {
self.cap.cents.height.truncate_push(height, state.realized.cap())?;
self.profit.raw.cents.height.truncate_push(height, state.realized.profit())?;
self.loss.raw.cents.height.truncate_push(height, state.realized.loss())?;
self.profit.base.cents.height.truncate_push(height, state.realized.profit())?;
self.loss.base.cents.height.truncate_push(height, state.realized.loss())?;
self.sopr
.value_created
.raw
.base
.height
.truncate_push(height, state.realized.value_created())?;
self.sopr
.value_destroyed
.raw
.base
.height
.truncate_push(height, state.realized.value_destroyed())?;
Ok(())
@@ -100,10 +100,10 @@ impl RealizedMinimal {
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
vec![
&mut self.cap.cents.height as &mut dyn AnyStoredVec,
&mut self.profit.raw.cents.height,
&mut self.loss.raw.cents.height,
&mut self.sopr.value_created.raw.height,
&mut self.sopr.value_destroyed.raw.height,
&mut self.profit.base.cents.height,
&mut self.loss.base.cents.height,
&mut self.sopr.value_created.base.height,
&mut self.sopr.value_destroyed.base.height,
]
}
@@ -114,10 +114,10 @@ impl RealizedMinimal {
exit: &Exit,
) -> Result<()> {
sum_others!(self, starting_indexes, others, exit; cap.cents.height);
sum_others!(self, starting_indexes, others, exit; profit.raw.cents.height);
sum_others!(self, starting_indexes, others, exit; loss.raw.cents.height);
sum_others!(self, starting_indexes, others, exit; sopr.value_created.raw.height);
sum_others!(self, starting_indexes, others, exit; sopr.value_destroyed.raw.height);
sum_others!(self, starting_indexes, others, exit; profit.base.cents.height);
sum_others!(self, starting_indexes, others, exit; loss.base.cents.height);
sum_others!(self, starting_indexes, others, exit; sopr.value_created.base.height);
sum_others!(self, starting_indexes, others, exit; sopr.value_destroyed.base.height);
Ok(())
}

View File

@@ -42,14 +42,14 @@ impl RelativeExtendedOwnMarketCap {
self.unrealized_profit_rel_to_own_mcap
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
max_from,
&unrealized.profit.raw.usd.height,
&unrealized.profit.base.usd.height,
own_market_cap,
exit,
)?;
self.unrealized_loss_rel_to_own_mcap
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
max_from,
&unrealized.loss.raw.usd.height,
&unrealized.loss.base.usd.height,
own_market_cap,
exit,
)?;

View File

@@ -43,14 +43,14 @@ impl RelativeExtendedOwnPnl {
self.unrealized_profit_rel_to_own_gross_pnl
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
max_from,
&unrealized.profit.raw.usd.height,
&unrealized.profit.base.usd.height,
gross_pnl_usd,
exit,
)?;
self.unrealized_loss_rel_to_own_gross_pnl
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
max_from,
&unrealized.loss.raw.usd.height,
&unrealized.loss.base.usd.height,
gross_pnl_usd,
exit,
)?;

View File

@@ -64,14 +64,14 @@ impl RelativeFull {
self.unrealized_profit_rel_to_mcap
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
max_from,
&unrealized.profit.raw.usd.height,
&unrealized.profit.base.usd.height,
market_cap,
exit,
)?;
self.unrealized_loss_rel_to_mcap
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
max_from,
&unrealized.loss.raw.usd.height,
&unrealized.loss.base.usd.height,
market_cap,
exit,
)?;

View File

@@ -34,21 +34,21 @@ impl UnrealizedBasic {
pub(crate) fn min_stateful_len(&self) -> usize {
self.profit
.raw
.base
.cents
.height
.len()
.min(self.loss.raw.cents.height.len())
.min(self.loss.base.cents.height.len())
}
pub(crate) fn truncate_push(&mut self, height: Height, state: &UnrealizedState) -> Result<()> {
self.profit
.raw
.base
.cents
.height
.truncate_push(height, state.unrealized_profit)?;
self.loss
.raw
.base
.cents
.height
.truncate_push(height, state.unrealized_loss)?;
@@ -57,8 +57,8 @@ impl UnrealizedBasic {
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
vec![
&mut self.profit.raw.cents.height as &mut dyn AnyStoredVec,
&mut self.loss.raw.cents.height,
&mut self.profit.base.cents.height as &mut dyn AnyStoredVec,
&mut self.loss.base.cents.height,
]
}
@@ -68,8 +68,8 @@ impl UnrealizedBasic {
others: &[&Self],
exit: &Exit,
) -> Result<()> {
sum_others!(self, starting_indexes, others, exit; profit.raw.cents.height);
sum_others!(self, starting_indexes, others, exit; loss.raw.cents.height);
sum_others!(self, starting_indexes, others, exit; profit.base.cents.height);
sum_others!(self, starting_indexes, others, exit; loss.base.cents.height);
Ok(())
}

View File

@@ -35,8 +35,8 @@ impl UnrealizedCore {
let neg_unrealized_loss = LazyPerBlock::from_computed::<NegCentsUnsignedToDollars>(
&cfg.name("neg_unrealized_loss"),
cfg.version,
basic.loss.raw.cents.height.read_only_boxed_clone(),
&basic.loss.raw.cents,
basic.loss.base.cents.height.read_only_boxed_clone(),
&basic.loss.base.cents,
);
let net_unrealized_pnl = cfg.import("net_unrealized_pnl", Version::ZERO)?;
@@ -90,8 +90,8 @@ impl UnrealizedCore {
.height
.compute_binary::<Cents, Cents, CentsSubtractToCentsSigned>(
starting_indexes.height,
&self.basic.profit.raw.cents.height,
&self.basic.loss.raw.cents.height,
&self.basic.profit.base.cents.height,
&self.basic.loss.base.cents.height,
exit,
)?;

View File

@@ -96,8 +96,8 @@ impl UnrealizedFull {
self.gross_pnl.cents.height.compute_add(
starting_indexes.height,
&self.inner.core.basic.profit.raw.cents.height,
&self.inner.core.basic.loss.raw.cents.height,
&self.inner.core.basic.profit.base.cents.height,
&self.inner.core.basic.loss.base.cents.height,
exit,
)?;

View File

@@ -23,7 +23,7 @@ use crate::{
state::BlockState,
},
indexes, inputs,
internal::{CachedWindowStarts, ComputedPerBlockCumulative, finalize_db, open_db},
internal::{CachedWindowStarts, PerBlockCumulative, db_utils::{finalize_db, open_db}},
outputs, prices, transactions,
};
@@ -70,7 +70,7 @@ pub struct Vecs<M: StorageMode = Rw> {
#[traversable(wrap = "cohorts", rename = "address")]
pub address_cohorts: AddressCohorts<M>,
#[traversable(wrap = "cointime")]
pub coinblocks_destroyed: ComputedPerBlockCumulative<StoredF64, M>,
pub coinblocks_destroyed: PerBlockCumulative<StoredF64, M>,
pub addresses: AddressMetricsVecs<M>,
/// In-memory block state for UTXO processing. Persisted via supply_state.
@@ -173,7 +173,7 @@ impl Vecs {
utxo_cohorts,
address_cohorts,
coinblocks_destroyed: ComputedPerBlockCumulative::forced_import(
coinblocks_destroyed: PerBlockCumulative::forced_import(
&db,
"coinblocks_destroyed",
version + Version::TWO,
@@ -489,6 +489,6 @@ impl Vecs {
.min(Height::from(self.addresses.funded.min_stateful_len()))
.min(Height::from(self.addresses.empty.min_stateful_len()))
.min(Height::from(self.addresses.activity.min_stateful_len()))
.min(Height::from(self.coinblocks_destroyed.raw.height.len()))
.min(Height::from(self.coinblocks_destroyed.base.height.len()))
}
}

View File

@@ -33,7 +33,7 @@ use vecdb::{CachedVec, Database, Exit, ReadableVec, Rw, StorageMode};
use crate::{
blocks,
internal::{finalize_db, open_db},
internal::db_utils::{finalize_db, open_db},
};
pub use cached_mappings::CachedMappings;

View File

@@ -6,7 +6,7 @@ use brk_types::Version;
use super::Vecs;
use crate::{
indexes,
internal::{finalize_db, open_db, ComputedPerBlock, PercentPerBlock, RatioPerBlock},
internal::{PerBlock, PercentPerBlock, RatioPerBlock, db_utils::{finalize_db, open_db}},
};
const VERSION: Version = Version::new(1);
@@ -27,16 +27,16 @@ impl Vecs {
let thermocap_multiple =
RatioPerBlock::forced_import_raw(&db, "thermocap_multiple", v, indexes)?;
let coindays_destroyed_supply_adjusted =
ComputedPerBlock::forced_import(&db, "coindays_destroyed_supply_adjusted", v, indexes)?;
PerBlock::forced_import(&db, "coindays_destroyed_supply_adjusted", v, indexes)?;
let coinyears_destroyed_supply_adjusted =
ComputedPerBlock::forced_import(&db, "coinyears_destroyed_supply_adjusted", v, indexes)?;
PerBlock::forced_import(&db, "coinyears_destroyed_supply_adjusted", v, indexes)?;
let dormancy = super::vecs::DormancyVecs {
supply_adjusted: ComputedPerBlock::forced_import(&db, "dormancy_supply_adjusted", v, indexes)?,
flow: ComputedPerBlock::forced_import(&db, "dormancy_flow", v, indexes)?,
supply_adjusted: PerBlock::forced_import(&db, "dormancy_supply_adjusted", v, indexes)?,
flow: PerBlock::forced_import(&db, "dormancy_flow", v, indexes)?,
};
let stock_to_flow = ComputedPerBlock::forced_import(&db, "stock_to_flow", v, indexes)?;
let stock_to_flow = PerBlock::forced_import(&db, "stock_to_flow", v, indexes)?;
let seller_exhaustion_constant =
ComputedPerBlock::forced_import(&db, "seller_exhaustion_constant", v, indexes)?;
PerBlock::forced_import(&db, "seller_exhaustion_constant", v, indexes)?;
let this = Self {
db,

View File

@@ -2,12 +2,12 @@ use brk_traversable::Traversable;
use brk_types::{BasisPoints16, BasisPoints32, StoredF32};
use vecdb::{Database, Rw, StorageMode};
use crate::internal::{ComputedPerBlock, PercentPerBlock, RatioPerBlock};
use crate::internal::{PerBlock, PercentPerBlock, RatioPerBlock};
#[derive(Traversable)]
pub struct DormancyVecs<M: StorageMode = Rw> {
pub supply_adjusted: ComputedPerBlock<StoredF32, M>,
pub flow: ComputedPerBlock<StoredF32, M>,
pub supply_adjusted: PerBlock<StoredF32, M>,
pub flow: PerBlock<StoredF32, M>,
}
#[derive(Traversable)]
@@ -19,9 +19,9 @@ pub struct Vecs<M: StorageMode = Rw> {
pub gini: PercentPerBlock<BasisPoints16, M>,
pub rhodl_ratio: RatioPerBlock<BasisPoints32, M>,
pub thermocap_multiple: RatioPerBlock<BasisPoints32, M>,
pub coindays_destroyed_supply_adjusted: ComputedPerBlock<StoredF32, M>,
pub coinyears_destroyed_supply_adjusted: ComputedPerBlock<StoredF32, M>,
pub coindays_destroyed_supply_adjusted: PerBlock<StoredF32, M>,
pub coinyears_destroyed_supply_adjusted: PerBlock<StoredF32, M>,
pub dormancy: DormancyVecs<M>,
pub stock_to_flow: ComputedPerBlock<StoredF32, M>,
pub seller_exhaustion_constant: ComputedPerBlock<StoredF32, M>,
pub stock_to_flow: PerBlock<StoredF32, M>,
pub seller_exhaustion_constant: PerBlock<StoredF32, M>,
}

View File

@@ -3,7 +3,7 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::{CachedWindowStarts, ComputedPerBlockAggregated}};
use crate::{indexes, internal::{CachedWindowStarts, PerBlockAggregated}};
impl Vecs {
pub(crate) fn forced_import(
@@ -12,7 +12,7 @@ impl Vecs {
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self(ComputedPerBlockAggregated::forced_import(
Ok(Self(PerBlockAggregated::forced_import(
db,
"input_count",
version,

View File

@@ -4,9 +4,9 @@ use brk_traversable::Traversable;
use brk_types::StoredU64;
use vecdb::{Rw, StorageMode};
use crate::internal::ComputedPerBlockAggregated;
use crate::internal::PerBlockAggregated;
#[derive(Deref, DerefMut, Traversable)]
pub struct Vecs<M: StorageMode = Rw>(
#[traversable(flatten)] pub ComputedPerBlockAggregated<StoredU64, M>,
#[traversable(flatten)] pub PerBlockAggregated<StoredU64, M>,
);

View File

@@ -5,7 +5,7 @@ use brk_types::Version;
use crate::{
indexes,
internal::{finalize_db, open_db, CachedWindowStarts},
internal::{CachedWindowStarts, db_utils::{finalize_db, open_db}},
};
use super::{CountVecs, SpentVecs, Vecs};

View File

@@ -7,7 +7,8 @@ use vecdb::{
};
use crate::internal::{
ComputedVecValue, DistributionStats, compute_aggregations, compute_aggregations_nblock_window,
ComputedVecValue, DistributionStats,
algo::{compute_aggregations, compute_aggregations_nblock_window},
};
#[derive(Traversable)]

View File

@@ -6,20 +6,20 @@ use vecdb::{
VecIndex, VecValue, Version,
};
use crate::internal::{ComputedVecValue, compute_aggregations};
use crate::internal::{ComputedVecValue, algo::compute_aggregations};
use super::Distribution;
/// Full stats aggregate: distribution + sum + cumulative
#[derive(Traversable)]
pub struct Full<I: VecIndex, T: ComputedVecValue + JsonSchema, M: StorageMode = Rw> {
pub struct DistributionFull<I: VecIndex, T: ComputedVecValue + JsonSchema, M: StorageMode = Rw> {
#[traversable(flatten)]
pub distribution: Distribution<I, T, M>,
pub sum: M::Stored<EagerVec<PcoVec<I, T>>>,
pub cumulative: M::Stored<EagerVec<PcoVec<I, T>>>,
}
impl<I: VecIndex, T: ComputedVecValue + JsonSchema> Full<I, T> {
impl<I: VecIndex, T: ComputedVecValue + JsonSchema> DistributionFull<I, T> {
pub(crate) fn forced_import(db: &Database, name: &str, version: Version) -> Result<Self> {
Ok(Self {
distribution: Distribution::forced_import(db, name, version)?,
@@ -65,8 +65,8 @@ impl<I: VecIndex, T: ComputedVecValue + JsonSchema> Full<I, T> {
)
}
pub fn read_only_clone(&self) -> Full<I, T, Ro> {
Full {
pub fn read_only_clone(&self) -> DistributionFull<I, T, Ro> {
DistributionFull {
distribution: self.distribution.read_only_clone(),
sum: StoredVec::read_only_clone(&self.sum),
cumulative: StoredVec::read_only_clone(&self.cumulative),

View File

@@ -1,7 +1,7 @@
mod distribution;
mod full;
mod distribution_full;
mod lazy_distribution;
pub use distribution::*;
pub use full::*;
pub use distribution_full::*;
pub use lazy_distribution::*;

View File

@@ -1,3 +0,0 @@
mod lazy;
pub use lazy::*;

View File

@@ -1,9 +1,11 @@
mod constant;
mod distribution_stats;
mod per_resolution;
mod window_24h;
mod windows;
mod windows_from_1w;
pub use constant::*;
pub use distribution_stats::*;
pub use per_resolution::*;
pub use window_24h::*;

View File

@@ -1,11 +1,4 @@
use brk_traversable::Traversable;
use brk_types::Height;
use vecdb::CachedVec;
/// Cached window starts for lazy rolling computations.
/// Clone-cheap (all fields are Arc-backed). Shared across all metrics.
#[derive(Clone)]
pub struct CachedWindowStarts(pub Windows<CachedVec<Height, Height>>);
#[derive(Clone, Traversable)]
pub struct Windows<A> {

View File

@@ -1,8 +1,8 @@
mod aggregate;
mod algo;
pub(crate) mod algo;
mod amount;
mod containers;
mod db_utils;
pub(crate) mod db_utils;
mod per_block;
mod per_tx;
mod indexes;
@@ -10,10 +10,8 @@ mod traits;
mod transform;
pub(crate) use aggregate::*;
pub(crate) use algo::*;
pub(crate) use amount::*;
pub(crate) use containers::*;
pub(crate) use db_utils::*;
pub(crate) use per_block::*;
pub(crate) use per_tx::*;
pub(crate) use indexes::*;

View File

@@ -6,16 +6,16 @@ use vecdb::{AnyVec, Database, Exit, ReadableCloneableVec, Rw, StorageMode};
use crate::{
indexes,
internal::{
CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock, SatsToBitcoin, SatsToCents,
CentsUnsignedToDollars, PerBlock, LazyPerBlock, SatsToBitcoin, SatsToCents,
},
prices,
};
#[derive(Traversable)]
pub struct AmountPerBlock<M: StorageMode = Rw> {
pub sats: ComputedPerBlock<Sats, M>,
pub sats: PerBlock<Sats, M>,
pub btc: LazyPerBlock<Bitcoin, Sats>,
pub cents: ComputedPerBlock<Cents, M>,
pub cents: PerBlock<Cents, M>,
pub usd: LazyPerBlock<Dollars, Cents>,
}
@@ -27,7 +27,7 @@ impl AmountPerBlock {
indexes: &indexes::Vecs,
) -> Result<Self> {
let sats =
ComputedPerBlock::forced_import(db, &format!("{name}_sats"), version, indexes)?;
PerBlock::forced_import(db, &format!("{name}_sats"), version, indexes)?;
let btc = LazyPerBlock::from_computed::<SatsToBitcoin>(
name,
@@ -37,7 +37,7 @@ impl AmountPerBlock {
);
let cents =
ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
let usd = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
&format!("{name}_usd"),

View File

@@ -11,7 +11,7 @@ use crate::{
#[derive(Traversable)]
pub struct AmountPerBlockCumulativeWithSums<M: StorageMode = Rw> {
pub raw: AmountPerBlock<M>,
pub base: AmountPerBlock<M>,
pub cumulative: AmountPerBlock<M>,
pub sum: LazyRollingSumsAmountFromHeight,
}
@@ -28,7 +28,7 @@ impl AmountPerBlockCumulativeWithSums {
) -> Result<Self> {
let v = version + VERSION;
let raw = AmountPerBlock::forced_import(db, name, v, indexes)?;
let base = AmountPerBlock::forced_import(db, name, v, indexes)?;
let cumulative =
AmountPerBlock::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
let sum = LazyRollingSumsAmountFromHeight::new(
@@ -41,7 +41,7 @@ impl AmountPerBlockCumulativeWithSums {
);
Ok(Self {
raw,
base,
cumulative,
sum,
})
@@ -54,7 +54,7 @@ impl AmountPerBlockCumulativeWithSums {
exit: &Exit,
compute_sats: impl FnOnce(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
) -> Result<()> {
compute_sats(&mut self.raw.sats.height)?;
compute_sats(&mut self.base.sats.height)?;
self.compute_rest(max_from, prices, exit)
}
@@ -67,14 +67,14 @@ impl AmountPerBlockCumulativeWithSums {
self.cumulative
.sats
.height
.compute_cumulative(max_from, &self.raw.sats.height, exit)?;
.compute_cumulative(max_from, &self.base.sats.height, exit)?;
self.raw
self.base
.cents
.height
.compute_binary::<Sats, Cents, SatsToCents>(
max_from,
&self.raw.sats.height,
&self.base.sats.height,
&prices.spot.cents.height,
exit,
)?;
@@ -82,7 +82,7 @@ impl AmountPerBlockCumulativeWithSums {
self.cumulative
.cents
.height
.compute_cumulative(max_from, &self.raw.cents.height, exit)?;
.compute_cumulative(max_from, &self.base.cents.height, exit)?;
Ok(())
}

View File

@@ -8,7 +8,7 @@ use crate::{
indexes,
internal::{
AmountPerBlock, DistributionStats, WindowStarts, Windows,
compute_rolling_distribution_from_starts,
algo::compute_rolling_distribution_from_starts,
},
};

View File

@@ -1,4 +1,4 @@
//! ComputedPerBlockAggregated - Full (distribution + sum + cumulative) + RollingFull.
//! PerBlockAggregated - DistributionFull (distribution + sum + cumulative) + RollingComplete.
//!
//! 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.
@@ -11,20 +11,20 @@ use vecdb::{Database, Exit, Rw, StorageMode};
use crate::{
indexes,
internal::{CachedWindowStarts, Full, NumericValue, RollingFull, WindowStarts},
internal::{CachedWindowStarts, DistributionFull, NumericValue, RollingComplete, WindowStarts},
};
#[derive(Traversable)]
pub struct ComputedPerBlockAggregated<T, M: StorageMode = Rw>
pub struct PerBlockAggregated<T, M: StorageMode = Rw>
where
T: NumericValue + JsonSchema,
{
#[traversable(flatten)]
pub full: Full<Height, T, M>,
pub rolling: RollingFull<T, M>,
pub full: DistributionFull<Height, T, M>,
pub rolling: RollingComplete<T, M>,
}
impl<T> ComputedPerBlockAggregated<T>
impl<T> PerBlockAggregated<T>
where
T: NumericValue + JsonSchema,
{
@@ -35,8 +35,8 @@ where
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let full = Full::forced_import(db, name, version)?;
let rolling = RollingFull::forced_import(
let full = DistributionFull::forced_import(db, name, version)?;
let rolling = RollingComplete::forced_import(
db,
name,
version,
@@ -48,13 +48,13 @@ where
Ok(Self { full, rolling })
}
/// Compute Full stats via closure, then rolling distribution from the per-block sum.
/// Compute DistributionFull stats via closure, then rolling distribution from the per-block sum.
pub(crate) fn compute(
&mut self,
max_from: Height,
windows: &WindowStarts<'_>,
exit: &Exit,
compute_full: impl FnOnce(&mut Full<Height, T>) -> Result<()>,
compute_full: impl FnOnce(&mut DistributionFull<Height, T>) -> Result<()>,
) -> Result<()>
where
T: From<f64> + Default + Copy + Ord,

View File

@@ -15,7 +15,7 @@ use crate::internal::{Resolutions, ComputedVecValue, NumericValue};
#[derive(Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct ComputedPerBlock<T, M: StorageMode = Rw>
pub struct PerBlock<T, M: StorageMode = Rw>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -26,7 +26,7 @@ where
pub resolutions: Box<Resolutions<T>>,
}
impl<T> ComputedPerBlock<T>
impl<T> PerBlock<T>
where
T: NumericValue + JsonSchema,
{

View File

@@ -1,6 +1,6 @@
//! ComputedPerBlockCumulative - raw ComputedPerBlock + cumulative ComputedPerBlock.
//! PerBlockCumulative - base PerBlock + cumulative PerBlock.
//!
//! Like ComputedPerBlockCumulativeWithSums but without RollingWindows.
//! Like PerBlockCumulativeWithSums but without RollingWindows.
//! Used for distribution metrics where rolling is optional per cohort.
use brk_error::Result;
@@ -11,19 +11,19 @@ use vecdb::{Database, Exit, Rw, StorageMode};
use crate::{
indexes,
internal::{ComputedPerBlock, NumericValue},
internal::{PerBlock, NumericValue},
};
#[derive(Traversable)]
pub struct ComputedPerBlockCumulative<T, M: StorageMode = Rw>
pub struct PerBlockCumulative<T, M: StorageMode = Rw>
where
T: NumericValue + JsonSchema,
{
pub raw: ComputedPerBlock<T, M>,
pub cumulative: ComputedPerBlock<T, M>,
pub base: PerBlock<T, M>,
pub cumulative: PerBlock<T, M>,
}
impl<T> ComputedPerBlockCumulative<T>
impl<T> PerBlockCumulative<T>
where
T: NumericValue + JsonSchema,
{
@@ -33,21 +33,21 @@ where
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?;
let base = PerBlock::forced_import(db, name, version, indexes)?;
let cumulative =
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
Ok(Self { raw, cumulative })
Ok(Self { base, cumulative })
}
/// Compute cumulative from already-filled raw vec.
/// Compute cumulative from already-filled base vec.
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
where
T: Default,
{
self.cumulative
.height
.compute_cumulative(max_from, &self.raw.height, exit)?;
.compute_cumulative(max_from, &self.base.height, exit)?;
Ok(())
}
}

View File

@@ -1,4 +1,4 @@
//! ComputedPerBlockCumulativeWithSums - raw ComputedPerBlock + cumulative ComputedPerBlock + lazy rolling sums.
//! PerBlockCumulativeWithSums - base PerBlock + cumulative PerBlock + lazy rolling sums.
//!
//! Rolling sums are derived lazily from the cumulative vec via LazyDeltaVec.
//! No rolling sum vecs are stored on disk.
@@ -17,21 +17,21 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
use crate::{
indexes,
internal::{CachedWindowStarts, ComputedPerBlock, LazyRollingSumsFromHeight, NumericValue},
internal::{CachedWindowStarts, PerBlock, LazyRollingSumsFromHeight, NumericValue},
};
#[derive(Traversable)]
pub struct ComputedPerBlockCumulativeWithSums<T, C, M: StorageMode = Rw>
pub struct PerBlockCumulativeWithSums<T, C, M: StorageMode = Rw>
where
T: NumericValue + JsonSchema,
C: NumericValue + JsonSchema,
{
pub raw: ComputedPerBlock<T, M>,
pub cumulative: ComputedPerBlock<C, M>,
pub base: PerBlock<T, M>,
pub cumulative: PerBlock<C, M>,
pub sum: LazyRollingSumsFromHeight<C>,
}
impl<T, C> ComputedPerBlockCumulativeWithSums<T, C>
impl<T, C> PerBlockCumulativeWithSums<T, C>
where
T: NumericValue + JsonSchema + Into<C>,
C: NumericValue + JsonSchema,
@@ -43,9 +43,9 @@ where
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?;
let base = PerBlock::forced_import(db, name, version, indexes)?;
let cumulative =
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
let sum = LazyRollingSumsFromHeight::new(
&format!("{name}_sum"),
version,
@@ -55,34 +55,34 @@ where
);
Ok(Self {
raw,
base,
cumulative,
sum,
})
}
/// Compute raw data via closure, then cumulative. Rolling sums are lazy.
/// Compute base data via closure, then cumulative. Rolling sums are lazy.
pub(crate) fn compute(
&mut self,
max_from: Height,
exit: &Exit,
compute_raw: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
compute_base: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
) -> Result<()>
where
C: Default,
{
compute_raw(&mut self.raw.height)?;
compute_base(&mut self.base.height)?;
self.compute_rest(max_from, exit)
}
/// Compute cumulative from already-populated raw data. Rolling sums are lazy.
/// Compute cumulative from already-populated base data. Rolling sums are lazy.
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
where
C: Default,
{
self.cumulative
.height
.compute_cumulative(max_from, &self.raw.height, exit)?;
.compute_cumulative(max_from, &self.base.height, exit)?;
Ok(())
}
}

View File

@@ -1,4 +1,4 @@
//! ComputedPerBlockFull - raw ComputedPerBlock + cumulative ComputedPerBlock + RollingFull.
//! PerBlockFull - base PerBlock + cumulative PerBlock + RollingComplete.
//!
//! For metrics with stored per-block data, cumulative sums, and rolling windows.
@@ -10,21 +10,21 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
use crate::{
indexes,
internal::{CachedWindowStarts, ComputedPerBlock, NumericValue, RollingFull, WindowStarts},
internal::{CachedWindowStarts, PerBlock, NumericValue, RollingComplete, WindowStarts},
};
#[derive(Traversable)]
pub struct ComputedPerBlockFull<T, M: StorageMode = Rw>
pub struct PerBlockFull<T, M: StorageMode = Rw>
where
T: NumericValue + JsonSchema,
{
pub raw: ComputedPerBlock<T, M>,
pub cumulative: ComputedPerBlock<T, M>,
pub base: PerBlock<T, M>,
pub cumulative: PerBlock<T, M>,
#[traversable(flatten)]
pub rolling: RollingFull<T, M>,
pub rolling: RollingComplete<T, M>,
}
impl<T> ComputedPerBlockFull<T>
impl<T> PerBlockFull<T>
where
T: NumericValue + JsonSchema,
{
@@ -35,10 +35,10 @@ where
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?;
let base = PerBlock::forced_import(db, name, version, indexes)?;
let cumulative =
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
let rolling = RollingFull::forced_import(
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
let rolling = RollingComplete::forced_import(
db,
name,
version,
@@ -48,30 +48,30 @@ where
)?;
Ok(Self {
raw,
base,
cumulative,
rolling,
})
}
/// Compute raw data via closure, then cumulative + rolling distribution.
/// Compute base data via closure, then cumulative + rolling distribution.
pub(crate) fn compute(
&mut self,
max_from: Height,
windows: &WindowStarts<'_>,
exit: &Exit,
compute_raw: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
compute_base: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
) -> Result<()>
where
T: From<f64> + Default + Copy + Ord,
f64: From<T>,
{
compute_raw(&mut self.raw.height)?;
compute_base(&mut self.base.height)?;
self.cumulative
.height
.compute_cumulative(max_from, &self.raw.height, exit)?;
.compute_cumulative(max_from, &self.base.height, exit)?;
self.rolling
.compute(max_from, windows, &self.raw.height, exit)?;
.compute(max_from, windows, &self.base.height, exit)?;
Ok(())
}
}

View File

@@ -6,33 +6,33 @@ use vecdb::{ReadableCloneableVec, UnaryTransform};
use crate::{
indexes,
internal::{
CachedWindowStarts, ComputedPerBlockFull, ComputedVecValue, LazyPerBlock, LazyRollingFull,
CachedWindowStarts, PerBlockFull, ComputedVecValue, LazyPerBlock, LazyRollingComplete,
NumericValue,
},
};
/// Lazy analog of `ResolutionsFull<T>`: lazy cumulative + lazy rolling full.
/// Derived by transforming a `ComputedPerBlockFull<S1T>`. Zero stored vecs.
/// Lazy analog of `PerBlockRolling<T>`: lazy cumulative + lazy rolling complete.
/// Derived by transforming a `PerBlockFull<S1T>`. Zero stored vecs.
#[derive(Clone, Traversable)]
pub struct LazyResolutionsFull<T, S1T>
pub struct LazyPerBlockRolling<T, S1T>
where
T: NumericValue + JsonSchema,
S1T: ComputedVecValue + JsonSchema,
{
pub cumulative: LazyPerBlock<T, S1T>,
#[traversable(flatten)]
pub rolling: LazyRollingFull<T, S1T>,
pub rolling: LazyRollingComplete<T, S1T>,
}
impl<T, S1T> LazyResolutionsFull<T, S1T>
impl<T, S1T> LazyPerBlockRolling<T, S1T>
where
T: NumericValue + JsonSchema + 'static,
S1T: NumericValue + JsonSchema,
{
pub(crate) fn from_computed_per_block_full<F: UnaryTransform<S1T, T>>(
pub(crate) fn from_per_block_full<F: UnaryTransform<S1T, T>>(
name: &str,
version: Version,
source: &ComputedPerBlockFull<S1T>,
source: &PerBlockFull<S1T>,
cached_starts: &CachedWindowStarts,
indexes: &indexes::Vecs,
) -> Self {
@@ -43,7 +43,7 @@ where
&source.cumulative,
);
let rolling = LazyRollingFull::from_rolling_full::<F>(
let rolling = LazyRollingComplete::from_rolling_complete::<F>(
name,
version,
&cumulative.height,

View File

@@ -1,23 +1,21 @@
mod aggregated;
mod base;
mod constant;
mod cumulative;
mod cumulative_sum;
mod resolutions;
mod resolutions_full;
mod lazy_resolutions_full;
mod rolling;
mod lazy_rolling;
mod full;
mod rolling_average;
mod with_deltas;
pub use aggregated::*;
pub use base::*;
pub use constant::*;
pub use cumulative::*;
pub use cumulative_sum::*;
pub use resolutions::*;
pub use resolutions_full::*;
pub use lazy_resolutions_full::*;
pub use rolling::*;
pub use lazy_rolling::*;
pub use full::*;
pub use rolling_average::*;
pub use with_deltas::*;

View File

@@ -1,7 +1,7 @@
//! ResolutionsFull - LazyAggVec index views + cumulative (from height) + RollingFull.
//! PerBlockRolling - LazyAggVec index views + cumulative (from height) + RollingComplete.
//!
//! For metrics derived from indexer sources (no stored height vec).
//! Cumulative gets its own ComputedPerBlock so it has LazyAggVec index views too.
//! Cumulative gets its own PerBlock so it has LazyAggVec index views too.
use brk_error::Result;
use brk_traversable::Traversable;
@@ -11,20 +11,20 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
use crate::{
indexes,
internal::{CachedWindowStarts, ComputedPerBlock, NumericValue, RollingFull, WindowStarts},
internal::{CachedWindowStarts, PerBlock, NumericValue, RollingComplete, WindowStarts},
};
#[derive(Traversable)]
pub struct ResolutionsFull<T, M: StorageMode = Rw>
pub struct PerBlockRolling<T, M: StorageMode = Rw>
where
T: NumericValue + JsonSchema,
{
pub cumulative: ComputedPerBlock<T, M>,
pub cumulative: PerBlock<T, M>,
#[traversable(flatten)]
pub rolling: RollingFull<T, M>,
pub rolling: RollingComplete<T, M>,
}
impl<T> ResolutionsFull<T>
impl<T> PerBlockRolling<T>
where
T: NumericValue + JsonSchema,
{
@@ -36,8 +36,8 @@ where
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let cumulative =
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
let rolling = RollingFull::forced_import(
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
let rolling = RollingComplete::forced_import(
db,
name,
version,

View File

@@ -1,4 +1,4 @@
//! ComputedPerBlock with rolling average (no distribution stats).
//! PerBlock with rolling average (no distribution stats).
//!
//! Stored height data + f64 cumulative + lazy 4-window rolling averages.
//! Rolling averages are computed on-the-fly from the cumulative via DeltaAvg.
@@ -15,7 +15,7 @@ use crate::indexes;
use crate::internal::{CachedWindowStarts, LazyRollingAvgsFromHeight, NumericValue};
#[derive(Traversable)]
pub struct ComputedPerBlockRollingAverage<T, M: StorageMode = Rw>
pub struct PerBlockRollingAverage<T, M: StorageMode = Rw>
where
T: NumericValue + JsonSchema,
{
@@ -26,7 +26,7 @@ where
pub average: LazyRollingAvgsFromHeight<T>,
}
impl<T> ComputedPerBlockRollingAverage<T>
impl<T> PerBlockRollingAverage<T>
where
T: NumericValue + JsonSchema,
{

View File

@@ -8,12 +8,12 @@ use vecdb::{Rw, StorageMode};
use crate::{
indexes,
internal::{
BpsType, CachedWindowStarts, ComputedPerBlock, LazyRollingDeltasFromHeight, NumericValue,
BpsType, CachedWindowStarts, PerBlock, LazyRollingDeltasFromHeight, NumericValue,
},
};
#[derive(Deref, DerefMut, Traversable)]
pub struct ComputedPerBlockWithDeltas<S, C, B, M: StorageMode = Rw>
pub struct PerBlockWithDeltas<S, C, B, M: StorageMode = Rw>
where
S: NumericValue + JsonSchema + Into<f64>,
C: NumericValue + JsonSchema + From<f64>,
@@ -22,11 +22,11 @@ where
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub inner: ComputedPerBlock<S, M>,
pub inner: PerBlock<S, M>,
pub delta: LazyRollingDeltasFromHeight<S, C, B>,
}
impl<S, C, B> ComputedPerBlockWithDeltas<S, C, B>
impl<S, C, B> PerBlockWithDeltas<S, C, B>
where
S: NumericValue + JsonSchema + Into<f64>,
C: NumericValue + JsonSchema + From<f64>,
@@ -40,7 +40,7 @@ where
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let inner = ComputedPerBlock::forced_import(db, name, version, indexes)?;
let inner = PerBlock::forced_import(db, name, version, indexes)?;
let delta = LazyRollingDeltasFromHeight::new(
&format!("{name}_delta"),

View File

@@ -7,7 +7,7 @@ use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode, UnaryTransform};
use crate::{
indexes,
internal::{
CentsSignedToDollars, CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock,
CentsSignedToDollars, CentsUnsignedToDollars, PerBlock, LazyPerBlock,
NumericValue,
},
};
@@ -29,7 +29,7 @@ impl CentsType for CentsSigned {
/// Generic over `C` to support both `Cents` (unsigned) and `CentsSigned` (signed).
#[derive(Traversable)]
pub struct FiatPerBlock<C: CentsType, M: StorageMode = Rw> {
pub cents: ComputedPerBlock<C, M>,
pub cents: PerBlock<C, M>,
pub usd: LazyPerBlock<Dollars, C>,
}
@@ -41,7 +41,7 @@ impl<C: CentsType> FiatPerBlock<C> {
indexes: &indexes::Vecs,
) -> Result<Self> {
let cents =
ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
let usd = LazyPerBlock::from_computed::<C::ToDollars>(
name,
version,

View File

@@ -10,7 +10,7 @@ use crate::{
#[derive(Traversable)]
pub struct FiatPerBlockCumulativeWithSums<C: CentsType, M: StorageMode = Rw> {
pub raw: FiatPerBlock<C, M>,
pub base: FiatPerBlock<C, M>,
pub cumulative: FiatPerBlock<C, M>,
pub sum: LazyRollingSumsFiatFromHeight<C>,
}
@@ -23,7 +23,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let raw = FiatPerBlock::forced_import(db, name, version, indexes)?;
let base = FiatPerBlock::forced_import(db, name, version, indexes)?;
let cumulative = FiatPerBlock::forced_import(
db,
&format!("{name}_cumulative"),
@@ -37,7 +37,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
cached_starts,
indexes,
);
Ok(Self { raw, cumulative, sum })
Ok(Self { base, cumulative, sum })
}
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
@@ -47,7 +47,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
self.cumulative
.cents
.height
.compute_cumulative(max_from, &self.raw.cents.height, exit)?;
.compute_cumulative(max_from, &self.base.cents.height, exit)?;
Ok(())
}
}

View File

@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
use brk_types::{Dollars, Version};
use vecdb::ReadableCloneableVec;
use crate::internal::{CentsType, ComputedPerBlock, Identity, LazyPerBlock, NumericValue};
use crate::internal::{CentsType, PerBlock, Identity, LazyPerBlock, NumericValue};
/// Lazy fiat: both cents and usd are lazy views of a stored source.
/// Zero extra stored vecs.
@@ -16,7 +16,7 @@ impl<C: CentsType> LazyFiatPerBlock<C> {
pub(crate) fn from_computed(
name: &str,
version: Version,
source: &ComputedPerBlock<C>,
source: &PerBlock<C>,
) -> Self
where
C: NumericValue,

View File

@@ -6,7 +6,7 @@ use vecdb::{LazyVecFrom1, ReadableBoxedVec, ReadableCloneableVec, UnaryTransform
use crate::{
indexes,
internal::{ComputedPerBlock, ComputedVecValue, DerivedResolutions, NumericValue},
internal::{PerBlock, ComputedVecValue, DerivedResolutions, NumericValue},
};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
@@ -31,7 +31,7 @@ where
name: &str,
version: Version,
height_source: ReadableBoxedVec<Height, S1T>,
source: &ComputedPerBlock<S1T>,
source: &PerBlock<S1T>,
) -> Self
where
S1T: NumericValue,

View File

@@ -10,7 +10,7 @@ use vecdb::{ReadableBoxedVec, ReadableCloneableVec, UnaryTransform, VecValue};
use crate::{
indexes,
internal::{
ComputedPerBlock, Resolutions, ComputedVecValue, NumericValue, PerResolution,
PerBlock, Resolutions, ComputedVecValue, NumericValue, PerResolution,
},
};
@@ -50,7 +50,7 @@ where
pub(crate) fn from_computed<F: UnaryTransform<S1T, T>>(
name: &str,
version: Version,
source: &ComputedPerBlock<S1T>,
source: &PerBlock<S1T>,
) -> Self
where
S1T: NumericValue,

View File

@@ -7,10 +7,10 @@ use vecdb::{
use crate::{
indexes,
internal::{BpsType, ComputeDrawdown},
internal::{BpsType, algo::ComputeDrawdown},
};
use crate::internal::{ComputedPerBlock, LazyPerBlock};
use crate::internal::{PerBlock, LazyPerBlock};
/// Basis-point storage with both ratio and percentage float views.
///
@@ -20,7 +20,7 @@ use crate::internal::{ComputedPerBlock, LazyPerBlock};
/// - `percent`: bps / 100 (e.g., 4523 bps -> 45.23%)
#[derive(Traversable)]
pub struct PercentPerBlock<B: BpsType, M: StorageMode = Rw> {
pub bps: ComputedPerBlock<B, M>,
pub bps: PerBlock<B, M>,
pub ratio: LazyPerBlock<StoredF32, B>,
pub percent: LazyPerBlock<StoredF32, B>,
}
@@ -32,7 +32,7 @@ impl<B: BpsType> PercentPerBlock<B> {
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
let bps = ComputedPerBlock::forced_import(db, &format!("{name}_bps"), version, indexes)?;
let bps = PerBlock::forced_import(db, &format!("{name}_bps"), version, indexes)?;
let bps_clone = bps.height.read_only_boxed_clone();
let ratio = LazyPerBlock::from_computed::<B::ToRatio>(

View File

@@ -0,0 +1,46 @@
use brk_traversable::Traversable;
use brk_types::{StoredF32, Version};
use vecdb::{ReadableCloneableVec, UnaryTransform};
use crate::internal::{BpsType, LazyPerBlock, PercentPerBlock};
/// Fully lazy variant of `PercentPerBlock` — no stored vecs.
///
/// BPS values are lazily derived from a source `PercentPerBlock` via a unary transform,
/// and ratio/percent float views are chained from the lazy BPS.
#[derive(Clone, Traversable)]
pub struct LazyPercentPerBlock<B: BpsType> {
pub bps: LazyPerBlock<B, B>,
pub ratio: LazyPerBlock<StoredF32, B>,
pub percent: LazyPerBlock<StoredF32, B>,
}
impl<B: BpsType> LazyPercentPerBlock<B> {
/// Create from a stored `PercentPerBlock` source via a BPS-to-BPS unary transform.
pub(crate) fn from_percent<F: UnaryTransform<B, B>>(
name: &str,
version: Version,
source: &PercentPerBlock<B>,
) -> Self {
let bps = LazyPerBlock::from_computed::<F>(
&format!("{name}_bps"),
version,
source.bps.height.read_only_boxed_clone(),
&source.bps,
);
let ratio = LazyPerBlock::from_lazy::<B::ToRatio, B>(
&format!("{name}_ratio"),
version,
&bps,
);
let percent = LazyPerBlock::from_lazy::<B::ToPercent, B>(name, version, &bps);
Self {
bps,
ratio,
percent,
}
}
}

View File

@@ -0,0 +1,33 @@
use brk_traversable::Traversable;
use brk_types::Version;
use derive_more::{Deref, DerefMut};
use vecdb::UnaryTransform;
use crate::internal::{BpsType, PercentRollingWindows, Windows};
use super::LazyPercentPerBlock;
/// Fully lazy rolling percent windows — 4 windows (24h, 1w, 1m, 1y),
/// each with lazy BPS + lazy ratio/percent float views.
///
/// No stored vecs. All values derived from a source `PercentRollingWindows`.
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(transparent)]
pub struct LazyPercentRollingWindows<B: BpsType>(pub Windows<LazyPercentPerBlock<B>>);
impl<B: BpsType> LazyPercentRollingWindows<B> {
/// Create from a stored `PercentRollingWindows` source via a BPS-to-BPS unary transform.
pub(crate) fn from_rolling<F: UnaryTransform<B, B>>(
name: &str,
version: Version,
source: &PercentRollingWindows<B>,
) -> Self {
Self(source.0.map_with_suffix(|suffix, source_window| {
LazyPercentPerBlock::from_percent::<F>(
&format!("{name}_{suffix}"),
version,
source_window,
)
}))
}
}

View File

@@ -1,7 +1,11 @@
mod base;
mod lazy;
mod lazy_windows;
mod rolling_average;
mod windows;
pub use base::*;
pub use lazy::*;
pub use lazy_windows::*;
pub use rolling_average::*;
pub use windows::*;

View File

@@ -8,12 +8,12 @@ use crate::{
internal::{BpsType, CachedWindowStarts},
};
use crate::internal::{ComputedPerBlockRollingAverage, LazyPerBlock};
use crate::internal::{PerBlockRollingAverage, LazyPerBlock};
/// Like PercentPerBlock but with rolling average stats on the bps data.
#[derive(Traversable)]
pub struct PercentPerBlockRollingAverage<B: BpsType, M: StorageMode = Rw> {
pub bps: ComputedPerBlockRollingAverage<B, M>,
pub bps: PerBlockRollingAverage<B, M>,
pub ratio: LazyPerBlock<StoredF32, B>,
pub percent: LazyPerBlock<StoredF32, B>,
}
@@ -26,7 +26,7 @@ impl<B: BpsType> PercentPerBlockRollingAverage<B> {
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let bps = ComputedPerBlockRollingAverage::forced_import(
let bps = PerBlockRollingAverage::forced_import(
db,
&format!("{name}_bps"),
version,

View File

@@ -4,7 +4,7 @@ use brk_types::{Cents, Height, Version};
use vecdb::{AnyExportableVec, Database, ReadOnlyClone, Ro, Rw, StorageMode, WritableVec};
use crate::indexes;
use crate::internal::{ComputedPerBlock, Price};
use crate::internal::{PerBlock, Price};
pub const PERCENTILES: [u8; 19] = [
5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95,
@@ -12,7 +12,7 @@ pub const PERCENTILES: [u8; 19] = [
pub const PERCENTILES_LEN: usize = PERCENTILES.len();
pub struct PercentilesVecs<M: StorageMode = Rw> {
pub vecs: [Price<ComputedPerBlock<Cents, M>>; PERCENTILES_LEN],
pub vecs: [Price<PerBlock<Cents, M>>; PERCENTILES_LEN],
}
const VERSION: Version = Version::ONE;
@@ -73,7 +73,7 @@ impl ReadOnlyClone for PercentilesVecs {
impl<M: StorageMode> Traversable for PercentilesVecs<M>
where
Price<ComputedPerBlock<Cents, M>>: Traversable,
Price<PerBlock<Cents, M>>: Traversable,
{
fn to_tree_node(&self) -> TreeNode {
TreeNode::Branch(

View File

@@ -10,7 +10,7 @@ use brk_types::{Cents, Dollars, SatsFract, Version};
use schemars::JsonSchema;
use vecdb::{Database, ReadableCloneableVec, UnaryTransform};
use super::{ComputedPerBlock, LazyPerBlock};
use super::{PerBlock, LazyPerBlock};
use crate::{
indexes,
internal::{CentsUnsignedToDollars, ComputedVecValue, DollarsToSatsFract, NumericValue},
@@ -24,7 +24,7 @@ pub struct Price<C> {
pub sats: LazyPerBlock<SatsFract, Dollars>,
}
impl Price<ComputedPerBlock<Cents>> {
impl Price<PerBlock<Cents>> {
/// Import from database: stored cents, lazy USD + sats.
pub(crate) fn forced_import(
db: &Database,
@@ -33,7 +33,7 @@ impl Price<ComputedPerBlock<Cents>> {
indexes: &indexes::Vecs,
) -> Result<Self> {
let cents =
ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
let usd = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
name,
version,
@@ -57,7 +57,7 @@ where
pub(crate) fn from_cents_source<F: UnaryTransform<ST, Cents>>(
name: &str,
version: Version,
source: &ComputedPerBlock<ST>,
source: &PerBlock<ST>,
) -> Self {
let cents = LazyPerBlock::from_computed::<F>(
&format!("{name}_cents"),

View File

@@ -5,12 +5,12 @@ use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
use crate::{
indexes,
internal::{BpsType, ComputedPerBlock, LazyPerBlock},
internal::{BpsType, PerBlock, LazyPerBlock},
};
#[derive(Traversable)]
pub struct RatioPerBlock<B: BpsType = BasisPoints32, M: StorageMode = Rw> {
pub bps: ComputedPerBlock<B, M>,
pub bps: PerBlock<B, M>,
pub ratio: LazyPerBlock<StoredF32, B>,
}
@@ -34,7 +34,7 @@ impl<B: BpsType> RatioPerBlock<B> {
) -> Result<Self> {
let v = version + VERSION;
let bps = ComputedPerBlock::forced_import(db, &format!("{name}_bps"), v, indexes)?;
let bps = PerBlock::forced_import(db, &format!("{name}_bps"), v, indexes)?;
let ratio = LazyPerBlock::from_computed::<B::ToRatio>(
name,

Some files were not shown because too many files have changed in this diff Show More