mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,7 @@ impl Vecs {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Block count raw + cumulative
|
// Block count raw + cumulative
|
||||||
self.total.raw.height.compute_range(
|
self.total.base.height.compute_range(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&indexer.vecs.blocks.weight,
|
&indexer.vecs.blocks.weight,
|
||||||
|h| (h, StoredU32::from(1_u32)),
|
|h| (h, StoredU32::from(1_u32)),
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
|||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{BlockCountTarget, CachedWindowStarts, ComputedPerBlockCumulativeWithSums, ConstantVecs},
|
internal::{BlockCountTarget, CachedWindowStarts, PerBlockCumulativeWithSums, ConstantVecs},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
@@ -21,7 +21,7 @@ impl Vecs {
|
|||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
),
|
),
|
||||||
total: ComputedPerBlockCumulativeWithSums::forced_import(
|
total: PerBlockCumulativeWithSums::forced_import(
|
||||||
db,
|
db,
|
||||||
"block_count",
|
"block_count",
|
||||||
version + Version::ONE,
|
version + Version::ONE,
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{StoredU32, StoredU64};
|
use brk_types::{StoredU32, StoredU64};
|
||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::{ComputedPerBlockCumulativeWithSums, ConstantVecs};
|
use crate::internal::{PerBlockCumulativeWithSums, ConstantVecs};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw> {
|
pub struct Vecs<M: StorageMode = Rw> {
|
||||||
pub target: ConstantVecs<StoredU64>,
|
pub target: ConstantVecs<StoredU64>,
|
||||||
pub total: ComputedPerBlockCumulativeWithSums<StoredU32, StoredU64, M>,
|
pub total: PerBlockCumulativeWithSums<StoredU32, StoredU64, M>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::{Indexes, StoredF64, StoredU32};
|
use brk_types::{Indexes, StoredU32};
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::super::TARGET_BLOCKS_PER_DAY_F32;
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::indexes;
|
use crate::indexes;
|
||||||
|
|
||||||
@@ -15,18 +14,6 @@ impl Vecs {
|
|||||||
starting_indexes: &Indexes,
|
starting_indexes: &Indexes,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> 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(
|
self.adjustment.bps.height.compute_ratio_change(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&indexer.vecs.blocks.difficulty,
|
&indexer.vecs.blocks.difficulty,
|
||||||
@@ -34,7 +21,6 @@ impl Vecs {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Compute epoch by height
|
|
||||||
self.epoch.height.compute_transform(
|
self.epoch.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&indexes.height.epoch,
|
&indexes.height.epoch,
|
||||||
@@ -42,24 +28,13 @@ impl Vecs {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Compute blocks before next adjustment
|
self.blocks_before_next.height.compute_transform(
|
||||||
self.blocks_before_next
|
|
||||||
.height
|
|
||||||
.compute_transform(
|
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&indexes.height.identity,
|
&indexes.height.identity,
|
||||||
|(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())),
|
|(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())),
|
||||||
exit,
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ use vecdb::{Database, ReadableCloneableVec};
|
|||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{ComputedPerBlock, Resolutions, PercentPerBlock},
|
internal::{
|
||||||
|
BlocksToDaysF32, DifficultyToHashF64, LazyPerBlock, PerBlock, PercentPerBlock, Resolutions,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
@@ -18,33 +20,39 @@ impl Vecs {
|
|||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let v2 = Version::TWO;
|
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 {
|
Ok(Self {
|
||||||
raw: Resolutions::forced_import(
|
base: Resolutions::forced_import(
|
||||||
"difficulty",
|
"difficulty",
|
||||||
indexer.vecs.blocks.difficulty.read_only_boxed_clone(),
|
indexer.vecs.blocks.difficulty.read_only_boxed_clone(),
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
),
|
),
|
||||||
as_hash: ComputedPerBlock::forced_import(db, "difficulty_as_hash", version, indexes)?,
|
as_hash,
|
||||||
adjustment: PercentPerBlock::forced_import(
|
adjustment: PercentPerBlock::forced_import(db, "difficulty_adjustment", version, indexes)?,
|
||||||
db,
|
epoch: PerBlock::forced_import(db, "difficulty_epoch", version, indexes)?,
|
||||||
"difficulty_adjustment",
|
blocks_before_next,
|
||||||
version,
|
days_before_next,
|
||||||
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,
|
|
||||||
)?,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{BasisPointsSigned32, Epoch, StoredF32, StoredF64, StoredU32};
|
use brk_types::{BasisPointsSigned32, Epoch, StoredF32, StoredF64, StoredU32};
|
||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::{ComputedPerBlock, Resolutions, PercentPerBlock};
|
use crate::internal::{LazyPerBlock, PerBlock, Resolutions, PercentPerBlock};
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw> {
|
pub struct Vecs<M: StorageMode = Rw> {
|
||||||
pub raw: Resolutions<StoredF64>,
|
pub base: Resolutions<StoredF64>,
|
||||||
pub as_hash: ComputedPerBlock<StoredF64, M>,
|
pub as_hash: LazyPerBlock<StoredF64>,
|
||||||
pub adjustment: PercentPerBlock<BasisPointsSigned32, M>,
|
pub adjustment: PercentPerBlock<BasisPointsSigned32, M>,
|
||||||
pub epoch: ComputedPerBlock<Epoch, M>,
|
pub epoch: PerBlock<Epoch, M>,
|
||||||
pub blocks_before_next: ComputedPerBlock<StoredU32, M>,
|
pub blocks_before_next: PerBlock<StoredU32, M>,
|
||||||
pub days_before_next: ComputedPerBlock<StoredF32, M>,
|
pub days_before_next: LazyPerBlock<StoredF32, StoredU32>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use brk_error::Result;
|
|||||||
use brk_types::{Indexes, StoredU32};
|
use brk_types::{Indexes, StoredU32};
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::super::TARGET_BLOCKS_PER_DAY_F32;
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::indexes;
|
use crate::indexes;
|
||||||
|
|
||||||
@@ -27,13 +26,6 @@ impl Vecs {
|
|||||||
exit,
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::Version;
|
use brk_types::Version;
|
||||||
use vecdb::Database;
|
use vecdb::{Database, ReadableCloneableVec};
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{indexes, internal::ComputedPerBlock};
|
use crate::{
|
||||||
|
indexes,
|
||||||
|
internal::{BlocksToDaysF32, LazyPerBlock, PerBlock},
|
||||||
|
};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn forced_import(
|
pub(crate) fn forced_import(
|
||||||
@@ -13,20 +16,21 @@ impl Vecs {
|
|||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let v2 = Version::TWO;
|
let v2 = Version::TWO;
|
||||||
|
|
||||||
Ok(Self {
|
let blocks_before_next = PerBlock::forced_import(
|
||||||
epoch: ComputedPerBlock::forced_import(db, "halving_epoch", version, indexes)?,
|
db, "blocks_before_next_halving", version + v2, indexes,
|
||||||
blocks_before_next: ComputedPerBlock::forced_import(
|
)?;
|
||||||
db,
|
|
||||||
"blocks_before_next_halving",
|
let days_before_next = LazyPerBlock::from_computed::<BlocksToDaysF32>(
|
||||||
version + v2,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
days_before_next: ComputedPerBlock::forced_import(
|
|
||||||
db,
|
|
||||||
"days_before_next_halving",
|
"days_before_next_halving",
|
||||||
version + v2,
|
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,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{Halving, StoredF32, StoredU32};
|
use brk_types::{Halving, StoredF32, StoredU32};
|
||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::ComputedPerBlock;
|
use crate::internal::{LazyPerBlock, PerBlock};
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw> {
|
pub struct Vecs<M: StorageMode = Rw> {
|
||||||
pub epoch: ComputedPerBlock<Halving, M>,
|
pub epoch: PerBlock<Halving, M>,
|
||||||
pub blocks_before_next: ComputedPerBlock<StoredU32, M>,
|
pub blocks_before_next: PerBlock<StoredU32, M>,
|
||||||
pub days_before_next: ComputedPerBlock<StoredF32, M>,
|
pub days_before_next: LazyPerBlock<StoredF32, StoredU32>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use brk_types::Version;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{finalize_db, open_db},
|
internal::db_utils::{finalize_db, open_db},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
|||||||
use vecdb::Database;
|
use vecdb::Database;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{indexes, internal::{CachedWindowStarts, ComputedPerBlockRollingAverage}};
|
use crate::{indexes, internal::{CachedWindowStarts, PerBlockRollingAverage}};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn forced_import(
|
pub(crate) fn forced_import(
|
||||||
@@ -12,7 +12,7 @@ impl Vecs {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let interval = ComputedPerBlockRollingAverage::forced_import(
|
let interval = PerBlockRollingAverage::forced_import(
|
||||||
db,
|
db,
|
||||||
"block_interval",
|
"block_interval",
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::Timestamp;
|
use brk_types::Timestamp;
|
||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::ComputedPerBlockRollingAverage;
|
use crate::internal::PerBlockRollingAverage;
|
||||||
|
|
||||||
#[derive(Deref, DerefMut, Traversable)]
|
#[derive(Deref, DerefMut, Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw>(
|
pub struct Vecs<M: StorageMode = Rw>(
|
||||||
#[traversable(flatten)] pub ComputedPerBlockRollingAverage<Timestamp, M>,
|
#[traversable(flatten)] pub PerBlockRollingAverage<Timestamp, M>,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
|||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CachedWindowStarts, ComputedPerBlockFull, ResolutionsFull},
|
internal::{CachedWindowStarts, PerBlockFull, PerBlockRolling},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
@@ -16,14 +16,14 @@ impl Vecs {
|
|||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
vbytes: ComputedPerBlockFull::forced_import(
|
vbytes: PerBlockFull::forced_import(
|
||||||
db,
|
db,
|
||||||
"block_vbytes",
|
"block_vbytes",
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
cached_starts,
|
cached_starts,
|
||||||
)?,
|
)?,
|
||||||
size: ResolutionsFull::forced_import(
|
size: PerBlockRolling::forced_import(
|
||||||
db,
|
db,
|
||||||
"block_size",
|
"block_size",
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::StoredU64;
|
use brk_types::StoredU64;
|
||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::{ComputedPerBlockFull, ResolutionsFull};
|
use crate::internal::{PerBlockFull, PerBlockRolling};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw> {
|
pub struct Vecs<M: StorageMode = Rw> {
|
||||||
pub vbytes: ComputedPerBlockFull<StoredU64, M>,
|
pub vbytes: PerBlockFull<StoredU64, M>,
|
||||||
pub size: ResolutionsFull<StoredU64, M>,
|
pub size: PerBlockRolling<StoredU64, M>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use super::Vecs;
|
|||||||
use crate::{
|
use crate::{
|
||||||
blocks::SizeVecs,
|
blocks::SizeVecs,
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CachedWindowStarts, LazyResolutionsFull, PercentPerBlockRollingAverage, VBytesToWeight},
|
internal::{CachedWindowStarts, LazyPerBlockRolling, PercentPerBlockRollingAverage, VBytesToWeight},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
@@ -17,7 +17,7 @@ impl Vecs {
|
|||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
size: &SizeVecs,
|
size: &SizeVecs,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let weight = LazyResolutionsFull::from_computed_per_block_full::<VBytesToWeight>(
|
let weight = LazyPerBlockRolling::from_per_block_full::<VBytesToWeight>(
|
||||||
"block_weight",
|
"block_weight",
|
||||||
version,
|
version,
|
||||||
&size.vbytes,
|
&size.vbytes,
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{BasisPoints16, StoredU64, Weight};
|
use brk_types::{BasisPoints16, StoredU64, Weight};
|
||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::{LazyResolutionsFull, PercentPerBlockRollingAverage};
|
use crate::internal::{LazyPerBlockRolling, PercentPerBlockRollingAverage};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw> {
|
pub struct Vecs<M: StorageMode = Rw> {
|
||||||
pub weight: LazyResolutionsFull<Weight, StoredU64>,
|
pub weight: LazyPerBlockRolling<Weight, StoredU64>,
|
||||||
pub fullness: PercentPerBlockRollingAverage<BasisPoints16, M>,
|
pub fullness: PercentPerBlockRollingAverage<BasisPoints16, M>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Bitcoin, CheckedSub, Indexes, StoredF64};
|
use brk_types::{Bitcoin, Indexes, StoredF64};
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -30,8 +30,8 @@ impl Vecs {
|
|||||||
.compute(starting_indexes.height, exit, |vec| {
|
.compute(starting_indexes.height, exit, |vec| {
|
||||||
vec.compute_subtract(
|
vec.compute_subtract(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.coinblocks_created.raw.height,
|
&self.coinblocks_created.base.height,
|
||||||
&distribution.coinblocks_destroyed.raw.height,
|
&distribution.coinblocks_destroyed.base.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -44,13 +44,6 @@ impl Vecs {
|
|||||||
exit,
|
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(
|
self.ratio.height.compute_divide(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.liveliness.height,
|
&self.liveliness.height,
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::Version;
|
use brk_types::Version;
|
||||||
use vecdb::Database;
|
use vecdb::{Database, ReadableCloneableVec};
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CachedWindowStarts, ComputedPerBlock, ComputedPerBlockCumulativeWithSums},
|
internal::{
|
||||||
|
CachedWindowStarts, LazyPerBlock, OneMinusF64, PerBlock, PerBlockCumulativeWithSums,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
@@ -15,29 +17,25 @@ impl Vecs {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> 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 {
|
Ok(Self {
|
||||||
coinblocks_created: ComputedPerBlockCumulativeWithSums::forced_import(
|
coinblocks_created: PerBlockCumulativeWithSums::forced_import(
|
||||||
db,
|
db, "coinblocks_created", version, indexes, cached_starts,
|
||||||
"coinblocks_created",
|
|
||||||
version,
|
|
||||||
indexes,
|
|
||||||
cached_starts,
|
|
||||||
)?,
|
)?,
|
||||||
coinblocks_stored: ComputedPerBlockCumulativeWithSums::forced_import(
|
coinblocks_stored: PerBlockCumulativeWithSums::forced_import(
|
||||||
db,
|
db, "coinblocks_stored", version, indexes, cached_starts,
|
||||||
"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,
|
|
||||||
)?,
|
)?,
|
||||||
|
liveliness,
|
||||||
|
vaultedness,
|
||||||
|
ratio: PerBlock::forced_import(db, "activity_to_vaultedness_ratio", version, indexes)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::StoredF64;
|
use brk_types::StoredF64;
|
||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::{ComputedPerBlock, ComputedPerBlockCumulativeWithSums};
|
use crate::internal::{LazyPerBlock, PerBlock, PerBlockCumulativeWithSums};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw> {
|
pub struct Vecs<M: StorageMode = Rw> {
|
||||||
pub coinblocks_created: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
pub coinblocks_created: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||||
pub coinblocks_stored: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
pub coinblocks_stored: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||||
pub liveliness: ComputedPerBlock<StoredF64, M>,
|
pub liveliness: PerBlock<StoredF64, M>,
|
||||||
pub vaultedness: ComputedPerBlock<StoredF64, M>,
|
pub vaultedness: LazyPerBlock<StoredF64>,
|
||||||
pub ratio: ComputedPerBlock<StoredF64, M>,
|
pub ratio: PerBlock<StoredF64, M>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
|||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{ComputedPerBlock, PercentPerBlock},
|
internal::{PerBlock, PercentPerBlock},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
@@ -21,13 +21,13 @@ impl Vecs {
|
|||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
)?,
|
)?,
|
||||||
tx_velocity_btc: ComputedPerBlock::forced_import(
|
tx_velocity_btc: PerBlock::forced_import(
|
||||||
db,
|
db,
|
||||||
"cointime_adj_tx_velocity_btc",
|
"cointime_adj_tx_velocity_btc",
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
)?,
|
)?,
|
||||||
tx_velocity_usd: ComputedPerBlock::forced_import(
|
tx_velocity_usd: PerBlock::forced_import(
|
||||||
db,
|
db,
|
||||||
"cointime_adj_tx_velocity_usd",
|
"cointime_adj_tx_velocity_usd",
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{BasisPointsSigned32, StoredF64};
|
use brk_types::{BasisPointsSigned32, StoredF64};
|
||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::{ComputedPerBlock, PercentPerBlock};
|
use crate::internal::{PerBlock, PercentPerBlock};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw> {
|
pub struct Vecs<M: StorageMode = Rw> {
|
||||||
pub inflation_rate: PercentPerBlock<BasisPointsSigned32, M>,
|
pub inflation_rate: PercentPerBlock<BasisPointsSigned32, M>,
|
||||||
pub tx_velocity_btc: ComputedPerBlock<StoredF64, M>,
|
pub tx_velocity_btc: PerBlock<StoredF64, M>,
|
||||||
pub tx_velocity_usd: ComputedPerBlock<StoredF64, M>,
|
pub tx_velocity_usd: PerBlock<StoredF64, M>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use brk_types::Version;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{finalize_db, open_db},
|
internal::db_utils::{finalize_db, open_db},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
|||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{ComputedPerBlock, PriceWithRatioExtendedPerBlock},
|
internal::{PerBlock, PriceWithRatioExtendedPerBlock},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
@@ -29,7 +29,7 @@ impl Vecs {
|
|||||||
balanced: import!("balanced_price"),
|
balanced: import!("balanced_price"),
|
||||||
terminal: import!("terminal_price"),
|
terminal: import!("terminal_price"),
|
||||||
delta: import!("delta_price"),
|
delta: import!("delta_price"),
|
||||||
cumulative_market_cap: ComputedPerBlock::forced_import(
|
cumulative_market_cap: PerBlock::forced_import(
|
||||||
db,
|
db,
|
||||||
"cumulative_market_cap",
|
"cumulative_market_cap",
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::Dollars;
|
use brk_types::Dollars;
|
||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::{ComputedPerBlock, PriceWithRatioExtendedPerBlock};
|
use crate::internal::{PerBlock, PriceWithRatioExtendedPerBlock};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw> {
|
pub struct Vecs<M: StorageMode = Rw> {
|
||||||
@@ -15,5 +15,5 @@ pub struct Vecs<M: StorageMode = Rw> {
|
|||||||
pub terminal: PriceWithRatioExtendedPerBlock<M>,
|
pub terminal: PriceWithRatioExtendedPerBlock<M>,
|
||||||
pub delta: PriceWithRatioExtendedPerBlock<M>,
|
pub delta: PriceWithRatioExtendedPerBlock<M>,
|
||||||
|
|
||||||
pub cumulative_market_cap: ComputedPerBlock<Dollars, M>,
|
pub cumulative_market_cap: PerBlock<Dollars, M>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use brk_types::{Indexes, StoredF64};
|
|||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::{super::value, Vecs};
|
use super::{super::value, Vecs};
|
||||||
use crate::{blocks, internal::ComputeRollingMedianFromStarts, prices};
|
use crate::{blocks, internal::algo::ComputeRollingMedianFromStarts, prices};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
@@ -17,7 +17,7 @@ impl Vecs {
|
|||||||
self.vocdd_median_1y.compute_rolling_median_from_starts(
|
self.vocdd_median_1y.compute_rolling_median_from_starts(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.lookback._1y,
|
&blocks.lookback._1y,
|
||||||
&value.vocdd.raw.height,
|
&value.vocdd.base.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
|||||||
use vecdb::{Database, EagerVec, ImportableVec};
|
use vecdb::{Database, EagerVec, ImportableVec};
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{indexes, internal::ComputedPerBlock};
|
use crate::{indexes, internal::PerBlock};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn forced_import(
|
pub(crate) fn forced_import(
|
||||||
@@ -15,7 +15,7 @@ impl Vecs {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
vocdd_median_1y: EagerVec::forced_import(db, "vocdd_median_1y", v1)?,
|
vocdd_median_1y: EagerVec::forced_import(db, "vocdd_median_1y", v1)?,
|
||||||
hodl_bank: EagerVec::forced_import(db, "hodl_bank", v1)?,
|
hodl_bank: EagerVec::forced_import(db, "hodl_bank", v1)?,
|
||||||
value: ComputedPerBlock::forced_import(db, "reserve_risk", v1, indexes)?,
|
value: PerBlock::forced_import(db, "reserve_risk", v1, indexes)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{Height, StoredF64};
|
use brk_types::{Height, StoredF64};
|
||||||
use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
|
use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::ComputedPerBlock;
|
use crate::internal::PerBlock;
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw> {
|
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 vocdd_median_1y: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
|
||||||
pub hodl_bank: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
|
pub hodl_bank: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ impl Vecs {
|
|||||||
vec.compute_multiply(
|
vec.compute_multiply(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&prices.spot.usd.height,
|
&prices.spot.usd.height,
|
||||||
&coinblocks_destroyed.raw.height,
|
&coinblocks_destroyed.base.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -36,7 +36,7 @@ impl Vecs {
|
|||||||
vec.compute_multiply(
|
vec.compute_multiply(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&prices.spot.usd.height,
|
&prices.spot.usd.height,
|
||||||
&activity.coinblocks_created.raw.height,
|
&activity.coinblocks_created.base.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -47,7 +47,7 @@ impl Vecs {
|
|||||||
vec.compute_multiply(
|
vec.compute_multiply(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&prices.spot.usd.height,
|
&prices.spot.usd.height,
|
||||||
&activity.coinblocks_stored.raw.height,
|
&activity.coinblocks_stored.base.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -61,7 +61,7 @@ impl Vecs {
|
|||||||
vec.compute_transform3(
|
vec.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&prices.spot.usd.height,
|
&prices.spot.usd.height,
|
||||||
&coindays_destroyed.raw.height,
|
&coindays_destroyed.base.height,
|
||||||
circulating_supply,
|
circulating_supply,
|
||||||
|(i, price, cdd, supply, _): (_, Dollars, StoredF64, Bitcoin, _)| {
|
|(i, price, cdd, supply, _): (_, Dollars, StoredF64, Bitcoin, _)| {
|
||||||
let supply_f64 = f64::from(supply);
|
let supply_f64 = f64::from(supply);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
|||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CachedWindowStarts, ComputedPerBlockCumulativeWithSums},
|
internal::{CachedWindowStarts, PerBlockCumulativeWithSums},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
@@ -16,28 +16,28 @@ impl Vecs {
|
|||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
destroyed: ComputedPerBlockCumulativeWithSums::forced_import(
|
destroyed: PerBlockCumulativeWithSums::forced_import(
|
||||||
db,
|
db,
|
||||||
"cointime_value_destroyed",
|
"cointime_value_destroyed",
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
cached_starts,
|
cached_starts,
|
||||||
)?,
|
)?,
|
||||||
created: ComputedPerBlockCumulativeWithSums::forced_import(
|
created: PerBlockCumulativeWithSums::forced_import(
|
||||||
db,
|
db,
|
||||||
"cointime_value_created",
|
"cointime_value_created",
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
cached_starts,
|
cached_starts,
|
||||||
)?,
|
)?,
|
||||||
stored: ComputedPerBlockCumulativeWithSums::forced_import(
|
stored: PerBlockCumulativeWithSums::forced_import(
|
||||||
db,
|
db,
|
||||||
"cointime_value_stored",
|
"cointime_value_stored",
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
cached_starts,
|
cached_starts,
|
||||||
)?,
|
)?,
|
||||||
vocdd: ComputedPerBlockCumulativeWithSums::forced_import(
|
vocdd: PerBlockCumulativeWithSums::forced_import(
|
||||||
db,
|
db,
|
||||||
"vocdd",
|
"vocdd",
|
||||||
version + Version::ONE,
|
version + Version::ONE,
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::StoredF64;
|
use brk_types::StoredF64;
|
||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::ComputedPerBlockCumulativeWithSums;
|
use crate::internal::PerBlockCumulativeWithSums;
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw> {
|
pub struct Vecs<M: StorageMode = Rw> {
|
||||||
pub destroyed: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
pub destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||||
pub created: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
pub created: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||||
pub stored: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
pub stored: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||||
pub vocdd: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
pub vocdd: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CachedWindowStarts, ComputedPerBlockRollingAverage},
|
internal::{CachedWindowStarts, PerBlockRollingAverage},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Per-block activity counts - reset each block.
|
/// 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").
|
/// Activity count vectors for a single category (e.g., one address type or "all").
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct ActivityCountVecs<M: StorageMode = Rw> {
|
pub struct ActivityCountVecs<M: StorageMode = Rw> {
|
||||||
pub reactivated: ComputedPerBlockRollingAverage<StoredU32, M>,
|
pub reactivated: PerBlockRollingAverage<StoredU32, M>,
|
||||||
pub sending: ComputedPerBlockRollingAverage<StoredU32, M>,
|
pub sending: PerBlockRollingAverage<StoredU32, M>,
|
||||||
pub receiving: ComputedPerBlockRollingAverage<StoredU32, M>,
|
pub receiving: PerBlockRollingAverage<StoredU32, M>,
|
||||||
pub both: ComputedPerBlockRollingAverage<StoredU32, M>,
|
pub both: PerBlockRollingAverage<StoredU32, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActivityCountVecs {
|
impl ActivityCountVecs {
|
||||||
@@ -80,28 +80,28 @@ impl ActivityCountVecs {
|
|||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
reactivated: ComputedPerBlockRollingAverage::forced_import(
|
reactivated: PerBlockRollingAverage::forced_import(
|
||||||
db,
|
db,
|
||||||
&format!("{name}_reactivated"),
|
&format!("{name}_reactivated"),
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
cached_starts,
|
cached_starts,
|
||||||
)?,
|
)?,
|
||||||
sending: ComputedPerBlockRollingAverage::forced_import(
|
sending: PerBlockRollingAverage::forced_import(
|
||||||
db,
|
db,
|
||||||
&format!("{name}_sending"),
|
&format!("{name}_sending"),
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
cached_starts,
|
cached_starts,
|
||||||
)?,
|
)?,
|
||||||
receiving: ComputedPerBlockRollingAverage::forced_import(
|
receiving: PerBlockRollingAverage::forced_import(
|
||||||
db,
|
db,
|
||||||
&format!("{name}_receiving"),
|
&format!("{name}_receiving"),
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
cached_starts,
|
cached_starts,
|
||||||
)?,
|
)?,
|
||||||
both: ComputedPerBlockRollingAverage::forced_import(
|
both: PerBlockRollingAverage::forced_import(
|
||||||
db,
|
db,
|
||||||
&format!("{name}_both"),
|
&format!("{name}_both"),
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ use vecdb::{
|
|||||||
WritableVec,
|
WritableVec,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{indexes, internal::ComputedPerBlock};
|
use crate::{indexes, internal::PerBlock};
|
||||||
|
|
||||||
#[derive(Deref, DerefMut, Traversable)]
|
#[derive(Deref, DerefMut, Traversable)]
|
||||||
pub struct AddressCountVecs<M: StorageMode = Rw>(
|
pub struct AddressCountVecs<M: StorageMode = Rw>(
|
||||||
#[traversable(flatten)] pub ComputedPerBlock<StoredU64, M>,
|
#[traversable(flatten)] pub PerBlock<StoredU64, M>,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl AddressCountVecs {
|
impl AddressCountVecs {
|
||||||
@@ -23,7 +23,7 @@ impl AddressCountVecs {
|
|||||||
version: Version,
|
version: Version,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Ok(Self(ComputedPerBlock::forced_import(
|
Ok(Self(PerBlock::forced_import(
|
||||||
db, name, version, indexes,
|
db, name, version, indexes,
|
||||||
)?))
|
)?))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use vecdb::{Database, Exit, Rw, StorageMode};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CachedWindowStarts, ComputedPerBlockCumulativeWithSums},
|
internal::{CachedWindowStarts, PerBlockCumulativeWithSums},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::TotalAddressCountVecs;
|
use super::TotalAddressCountVecs;
|
||||||
@@ -14,9 +14,9 @@ use super::TotalAddressCountVecs;
|
|||||||
/// New address count per block (global + per-type)
|
/// New address count per block (global + per-type)
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct NewAddressCountVecs<M: StorageMode = Rw> {
|
pub struct NewAddressCountVecs<M: StorageMode = Rw> {
|
||||||
pub all: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
pub all: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub by_addresstype: ByAddressType<ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>>,
|
pub by_addresstype: ByAddressType<PerBlockCumulativeWithSums<StoredU64, StoredU64, M>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NewAddressCountVecs {
|
impl NewAddressCountVecs {
|
||||||
@@ -26,7 +26,7 @@ impl NewAddressCountVecs {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let all = ComputedPerBlockCumulativeWithSums::forced_import(
|
let all = PerBlockCumulativeWithSums::forced_import(
|
||||||
db,
|
db,
|
||||||
"new_address_count",
|
"new_address_count",
|
||||||
version,
|
version,
|
||||||
@@ -35,7 +35,7 @@ impl NewAddressCountVecs {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
let by_addresstype = ByAddressType::new_with_name(|name| {
|
let by_addresstype = ByAddressType::new_with_name(|name| {
|
||||||
ComputedPerBlockCumulativeWithSums::forced_import(
|
PerBlockCumulativeWithSums::forced_import(
|
||||||
db,
|
db,
|
||||||
&format!("{name}_new_address_count"),
|
&format!("{name}_new_address_count"),
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{Height, StoredU64, Version};
|
use brk_types::{Height, StoredU64, Version};
|
||||||
use vecdb::{Database, Exit, Rw, StorageMode};
|
use vecdb::{Database, Exit, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{indexes, internal::ComputedPerBlock};
|
use crate::{indexes, internal::PerBlock};
|
||||||
|
|
||||||
use super::AddressCountsVecs;
|
use super::AddressCountsVecs;
|
||||||
|
|
||||||
/// Total address count (global + per-type) with all derived indexes
|
/// Total address count (global + per-type) with all derived indexes
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct TotalAddressCountVecs<M: StorageMode = Rw> {
|
pub struct TotalAddressCountVecs<M: StorageMode = Rw> {
|
||||||
pub all: ComputedPerBlock<StoredU64, M>,
|
pub all: PerBlock<StoredU64, M>,
|
||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub by_addresstype: ByAddressType<ComputedPerBlock<StoredU64, M>>,
|
pub by_addresstype: ByAddressType<PerBlock<StoredU64, M>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TotalAddressCountVecs {
|
impl TotalAddressCountVecs {
|
||||||
@@ -22,11 +22,11 @@ impl TotalAddressCountVecs {
|
|||||||
version: Version,
|
version: Version,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> 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| {
|
ByAddressType::new_with_name(|name| {
|
||||||
ComputedPerBlock::forced_import(
|
PerBlock::forced_import(
|
||||||
db,
|
db,
|
||||||
&format!("{name}_total_address_count"),
|
&format!("{name}_total_address_count"),
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Rw, StorageMode,
|
|||||||
use crate::{
|
use crate::{
|
||||||
distribution::state::{AddressCohortState, MinimalRealizedState},
|
distribution::state::{AddressCohortState, MinimalRealizedState},
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CachedWindowStarts, ComputedPerBlockWithDeltas},
|
internal::{CachedWindowStarts, PerBlockWithDeltas},
|
||||||
prices,
|
prices,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ pub struct AddressCohortVecs<M: StorageMode = Rw> {
|
|||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub metrics: MinimalCohortMetrics<M>,
|
pub metrics: MinimalCohortMetrics<M>,
|
||||||
|
|
||||||
pub address_count: ComputedPerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
|
pub address_count: PerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddressCohortVecs {
|
impl AddressCohortVecs {
|
||||||
@@ -51,7 +51,7 @@ impl AddressCohortVecs {
|
|||||||
cached_starts,
|
cached_starts,
|
||||||
};
|
};
|
||||||
|
|
||||||
let address_count = ComputedPerBlockWithDeltas::forced_import(
|
let address_count = PerBlockWithDeltas::forced_import(
|
||||||
db,
|
db,
|
||||||
&cfg.name("address_count"),
|
&cfg.name("address_count"),
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use brk_types::{Cents, CentsCompact, Sats};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
distribution::state::PendingDelta,
|
distribution::state::PendingDelta,
|
||||||
internal::{FenwickNode, FenwickTree, PERCENTILES, PERCENTILES_LEN},
|
internal::{PERCENTILES, PERCENTILES_LEN, algo::{FenwickNode, FenwickTree}},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::COST_BASIS_PRICE_DIGITS;
|
use super::COST_BASIS_PRICE_DIGITS;
|
||||||
|
|||||||
@@ -538,7 +538,7 @@ impl UTXOCohorts<Rw> {
|
|||||||
.minimal
|
.minimal
|
||||||
.sopr
|
.sopr
|
||||||
.value_created
|
.value_created
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.read_only_clone();
|
.read_only_clone();
|
||||||
let under_1h_value_destroyed = self
|
let under_1h_value_destroyed = self
|
||||||
@@ -549,7 +549,7 @@ impl UTXOCohorts<Rw> {
|
|||||||
.minimal
|
.minimal
|
||||||
.sopr
|
.sopr
|
||||||
.value_destroyed
|
.value_destroyed
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.read_only_clone();
|
.read_only_clone();
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ pub(crate) fn process_blocks(
|
|||||||
let height_to_first_txindex = &indexer.vecs.transactions.first_txindex;
|
let height_to_first_txindex = &indexer.vecs.transactions.first_txindex;
|
||||||
let height_to_first_txoutindex = &indexer.vecs.outputs.first_txoutindex;
|
let height_to_first_txoutindex = &indexer.vecs.outputs.first_txoutindex;
|
||||||
let height_to_first_txinindex = &indexer.vecs.inputs.first_txinindex;
|
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_output_count = &outputs.count.total.full.sum;
|
||||||
let height_to_input_count = &inputs.count.full.sum;
|
let height_to_input_count = &inputs.count.full.sum;
|
||||||
let txindex_to_output_count = &indexes.txindex.output_count;
|
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
|
blocks_old as u128 * u64::from(sent.spendable_supply.value) as u128
|
||||||
})
|
})
|
||||||
.sum();
|
.sum();
|
||||||
vecs.coinblocks_destroyed.raw.height.truncate_push(
|
vecs.coinblocks_destroyed.base.height.truncate_push(
|
||||||
height,
|
height,
|
||||||
StoredF64::from(total_satblocks as f64 / Sats::ONE_BTC_U128 as f64),
|
StoredF64::from(total_satblocks as f64 / Sats::ONE_BTC_U128 as f64),
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ pub(crate) fn write(
|
|||||||
.chain(
|
.chain(
|
||||||
[
|
[
|
||||||
&mut vecs.supply_state as &mut dyn AnyStoredVec,
|
&mut vecs.supply_state as &mut dyn AnyStoredVec,
|
||||||
&mut vecs.coinblocks_destroyed.raw.height,
|
&mut vecs.coinblocks_destroyed.base.height,
|
||||||
]
|
]
|
||||||
.into_par_iter(),
|
.into_par_iter(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}},
|
distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}},
|
||||||
internal::{AmountPerBlockCumulativeWithSums, ComputedPerBlockCumulativeWithSums},
|
internal::{AmountPerBlockCumulativeWithSums, PerBlockCumulativeWithSums},
|
||||||
prices,
|
prices,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct ActivityCore<M: StorageMode = Rw> {
|
pub struct ActivityCore<M: StorageMode = Rw> {
|
||||||
pub sent: ComputedPerBlockCumulativeWithSums<Sats, Sats, M>,
|
pub sent: PerBlockCumulativeWithSums<Sats, Sats, M>,
|
||||||
pub coindays_destroyed: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
pub coindays_destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||||
#[traversable(wrap = "sent", rename = "in_profit")]
|
#[traversable(wrap = "sent", rename = "in_profit")]
|
||||||
pub sent_in_profit: AmountPerBlockCumulativeWithSums<M>,
|
pub sent_in_profit: AmountPerBlockCumulativeWithSums<M>,
|
||||||
#[traversable(wrap = "sent", rename = "in_loss")]
|
#[traversable(wrap = "sent", rename = "in_loss")]
|
||||||
@@ -32,12 +32,12 @@ impl ActivityCore {
|
|||||||
|
|
||||||
pub(crate) fn min_len(&self) -> usize {
|
pub(crate) fn min_len(&self) -> usize {
|
||||||
self.sent
|
self.sent
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.len()
|
.len()
|
||||||
.min(self.coindays_destroyed.raw.height.len())
|
.min(self.coindays_destroyed.base.height.len())
|
||||||
.min(self.sent_in_profit.raw.sats.height.len())
|
.min(self.sent_in_profit.base.sats.height.len())
|
||||||
.min(self.sent_in_loss.raw.sats.height.len())
|
.min(self.sent_in_loss.base.sats.height.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn truncate_push(
|
pub(crate) fn truncate_push(
|
||||||
@@ -45,18 +45,18 @@ impl ActivityCore {
|
|||||||
height: Height,
|
height: Height,
|
||||||
state: &CohortState<impl RealizedOps, impl CostBasisOps>,
|
state: &CohortState<impl RealizedOps, impl CostBasisOps>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.sent.raw.height.truncate_push(height, state.sent)?;
|
self.sent.base.height.truncate_push(height, state.sent)?;
|
||||||
self.coindays_destroyed.raw.height.truncate_push(
|
self.coindays_destroyed.base.height.truncate_push(
|
||||||
height,
|
height,
|
||||||
StoredF64::from(Bitcoin::from(state.satdays_destroyed)),
|
StoredF64::from(Bitcoin::from(state.satdays_destroyed)),
|
||||||
)?;
|
)?;
|
||||||
self.sent_in_profit
|
self.sent_in_profit
|
||||||
.raw
|
.base
|
||||||
.sats
|
.sats
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, state.realized.sent_in_profit())?;
|
.truncate_push(height, state.realized.sent_in_profit())?;
|
||||||
self.sent_in_loss
|
self.sent_in_loss
|
||||||
.raw
|
.base
|
||||||
.sats
|
.sats
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, state.realized.sent_in_loss())?;
|
.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> {
|
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||||
vec![
|
vec![
|
||||||
&mut self.sent.raw.height as &mut dyn AnyStoredVec,
|
&mut self.sent.base.height as &mut dyn AnyStoredVec,
|
||||||
&mut self.coindays_destroyed.raw.height,
|
&mut self.coindays_destroyed.base.height,
|
||||||
&mut self.sent_in_profit.raw.sats.height,
|
&mut self.sent_in_profit.base.sats.height,
|
||||||
&mut self.sent_in_profit.raw.cents.height,
|
&mut self.sent_in_profit.base.cents.height,
|
||||||
&mut self.sent_in_loss.raw.sats.height,
|
&mut self.sent_in_loss.base.sats.height,
|
||||||
&mut self.sent_in_loss.raw.cents.height,
|
&mut self.sent_in_loss.base.cents.height,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,18 +84,18 @@ impl ActivityCore {
|
|||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.sent.raw.height.compute_sum_of_others(
|
self.sent.base.height.compute_sum_of_others(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&others
|
&others
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| &v.sent.raw.height)
|
.map(|v| &v.sent.base.height)
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
sum_others!(self, starting_indexes, others, exit; coindays_destroyed.raw.height);
|
sum_others!(self, starting_indexes, others, exit; coindays_destroyed.base.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; sent_in_profit.raw.sats.height);
|
sum_others!(self, starting_indexes, others, exit; sent_in_profit.base.sats.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; sent_in_loss.raw.sats.height);
|
sum_others!(self, starting_indexes, others, exit; sent_in_loss.base.sats.height);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use brk_types::{Bitcoin, Height, Indexes, Sats, StoredF32, StoredF64, Version};
|
|||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{AnyStoredVec, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
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}};
|
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 coinyears_destroyed: LazyPerBlock<StoredF64, StoredF64>,
|
||||||
|
|
||||||
pub dormancy: ComputedPerBlock<StoredF32, M>,
|
pub dormancy: PerBlock<StoredF32, M>,
|
||||||
pub velocity: ComputedPerBlock<StoredF32, M>,
|
pub velocity: PerBlock<StoredF32, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActivityFull {
|
impl ActivityFull {
|
||||||
@@ -88,8 +88,8 @@ impl ActivityFull {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.dormancy.height.compute_transform2(
|
self.dormancy.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.inner.coindays_destroyed.raw.height,
|
&self.inner.coindays_destroyed.base.height,
|
||||||
&self.inner.sent.raw.height,
|
&self.inner.sent.base.height,
|
||||||
|(i, cdd, sent_sats, ..)| {
|
|(i, cdd, sent_sats, ..)| {
|
||||||
let sent_btc = f64::from(Bitcoin::from(sent_sats));
|
let sent_btc = f64::from(Bitcoin::from(sent_sats));
|
||||||
if sent_btc == 0.0 {
|
if sent_btc == 0.0 {
|
||||||
@@ -103,7 +103,7 @@ impl ActivityFull {
|
|||||||
|
|
||||||
self.velocity.height.compute_transform2(
|
self.velocity.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.inner.sent.raw.height,
|
&self.inner.sent.base.height,
|
||||||
supply_total_sats,
|
supply_total_sats,
|
||||||
|(i, sent_sats, supply_sats, ..)| {
|
|(i, sent_sats, supply_sats, ..)| {
|
||||||
let supply = supply_sats.as_u128() as f64;
|
let supply = supply_sats.as_u128() as f64;
|
||||||
|
|||||||
@@ -128,8 +128,8 @@ impl AllCohortMetrics {
|
|||||||
|
|
||||||
self.asopr.compute_rest_part2(
|
self.asopr.compute_rest_part2(
|
||||||
starting_indexes,
|
starting_indexes,
|
||||||
&self.realized.minimal.sopr.value_created.raw.height,
|
&self.realized.minimal.sopr.value_created.base.height,
|
||||||
&self.realized.minimal.sopr.value_destroyed.raw.height,
|
&self.realized.minimal.sopr.value_destroyed.base.height,
|
||||||
under_1h_value_created,
|
under_1h_value_created,
|
||||||
under_1h_value_destroyed,
|
under_1h_value_destroyed,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ impl ExtendedAdjustedCohortMetrics {
|
|||||||
|
|
||||||
self.asopr.compute_rest_part2(
|
self.asopr.compute_rest_part2(
|
||||||
starting_indexes,
|
starting_indexes,
|
||||||
&self.inner.realized.minimal.sopr.value_created.raw.height,
|
&self.inner.realized.minimal.sopr.value_created.base.height,
|
||||||
&self.inner.realized.minimal.sopr.value_destroyed.raw.height,
|
&self.inner.realized.minimal.sopr.value_destroyed.base.height,
|
||||||
under_1h_value_created,
|
under_1h_value_created,
|
||||||
under_1h_value_destroyed,
|
under_1h_value_destroyed,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ use crate::{
|
|||||||
indexes,
|
indexes,
|
||||||
internal::{
|
internal::{
|
||||||
AmountPerBlock, AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums,
|
AmountPerBlock, AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums,
|
||||||
CachedWindowStarts, CentsType, ComputedPerBlock,
|
CachedWindowStarts, CentsType, PerBlock,
|
||||||
ComputedPerBlockCumulative, ComputedPerBlockCumulativeWithSums,
|
PerBlockCumulative, PerBlockCumulativeWithSums,
|
||||||
FiatPerBlock, FiatPerBlockCumulativeWithSums, NumericValue,
|
FiatPerBlock, FiatPerBlockCumulativeWithSums, NumericValue,
|
||||||
PercentPerBlock, PercentRollingWindows, Price,
|
PercentPerBlock, PercentRollingWindows, Price,
|
||||||
PriceWithRatioExtendedPerBlock, PriceWithRatioPerBlock, RatioPerBlock,
|
PriceWithRatioExtendedPerBlock, PriceWithRatioPerBlock, RatioPerBlock,
|
||||||
@@ -47,21 +47,21 @@ impl_config_import!(
|
|||||||
PercentPerBlock<BasisPoints32>,
|
PercentPerBlock<BasisPoints32>,
|
||||||
PercentPerBlock<BasisPointsSigned32>,
|
PercentPerBlock<BasisPointsSigned32>,
|
||||||
PercentRollingWindows<BasisPoints32>,
|
PercentRollingWindows<BasisPoints32>,
|
||||||
Price<ComputedPerBlock<Cents>>,
|
Price<PerBlock<Cents>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Generic types (macro_rules can't parse generic bounds, so written out)
|
// 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> {
|
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||||
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
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> {
|
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||||
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
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
|
where
|
||||||
T: NumericValue + JsonSchema + Into<C>,
|
T: NumericValue + JsonSchema + Into<C>,
|
||||||
C: NumericValue + JsonSchema,
|
C: NumericValue + JsonSchema,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{BasisPoints16, Cents, Height, Version};
|
use brk_types::{BasisPoints16, Cents, Height, Version};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Rw, StorageMode, WritableVec};
|
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;
|
use super::ImportConfig;
|
||||||
|
|
||||||
@@ -11,8 +11,8 @@ use super::ImportConfig;
|
|||||||
/// Used by all/sth/lth cohorts only.
|
/// Used by all/sth/lth cohorts only.
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct CostBasis<M: StorageMode = Rw> {
|
pub struct CostBasis<M: StorageMode = Rw> {
|
||||||
pub min: Price<ComputedPerBlock<Cents, M>>,
|
pub min: Price<PerBlock<Cents, M>>,
|
||||||
pub max: Price<ComputedPerBlock<Cents, M>>,
|
pub max: Price<PerBlock<Cents, M>>,
|
||||||
pub percentiles: PercentilesVecs<M>,
|
pub percentiles: PercentilesVecs<M>,
|
||||||
pub invested_capital: PercentilesVecs<M>,
|
pub invested_capital: PercentilesVecs<M>,
|
||||||
pub supply_density: PercentPerBlock<BasisPoints16, M>,
|
pub supply_density: PercentPerBlock<BasisPoints16, M>,
|
||||||
|
|||||||
@@ -8,19 +8,19 @@ use crate::{
|
|||||||
metrics::ImportConfig,
|
metrics::ImportConfig,
|
||||||
state::{CohortState, CostBasisOps, RealizedOps},
|
state::{CohortState, CostBasisOps, RealizedOps},
|
||||||
},
|
},
|
||||||
internal::ComputedPerBlockWithDeltas,
|
internal::PerBlockWithDeltas,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Base output metrics: utxo_count + delta.
|
/// Base output metrics: utxo_count + delta.
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct OutputsBase<M: StorageMode = Rw> {
|
pub struct OutputsBase<M: StorageMode = Rw> {
|
||||||
pub unspent_count: ComputedPerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
|
pub unspent_count: PerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OutputsBase {
|
impl OutputsBase {
|
||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
unspent_count: ComputedPerBlockWithDeltas::forced_import(
|
unspent_count: PerBlockWithDeltas::forced_import(
|
||||||
cfg.db,
|
cfg.db,
|
||||||
&cfg.name("utxo_count"),
|
&cfg.name("utxo_count"),
|
||||||
cfg.version,
|
cfg.version,
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{Dollars, Height, Sats, Version};
|
use brk_types::{Dollars, Height, Sats, Version};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Database, Rw, StorageMode, WritableVec};
|
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.
|
/// Supply + realized cap for a single profitability bucket.
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct ProfitabilityBucket<M: StorageMode = Rw> {
|
pub struct ProfitabilityBucket<M: StorageMode = Rw> {
|
||||||
pub supply: ComputedPerBlock<Sats, M>,
|
pub supply: PerBlock<Sats, M>,
|
||||||
pub realized_cap: ComputedPerBlock<Dollars, M>,
|
pub realized_cap: PerBlock<Dollars, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: StorageMode> ProfitabilityBucket<M> {
|
impl<M: StorageMode> ProfitabilityBucket<M> {
|
||||||
@@ -27,13 +27,13 @@ impl ProfitabilityBucket {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
supply: ComputedPerBlock::forced_import(
|
supply: PerBlock::forced_import(
|
||||||
db,
|
db,
|
||||||
&format!("{name}_supply"),
|
&format!("{name}_supply"),
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
)?,
|
)?,
|
||||||
realized_cap: ComputedPerBlock::forced_import(
|
realized_cap: PerBlock::forced_import(
|
||||||
db,
|
db,
|
||||||
&format!("{name}_realized_cap"),
|
&format!("{name}_realized_cap"),
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
distribution::metrics::ImportConfig,
|
distribution::metrics::ImportConfig,
|
||||||
internal::{ComputedPerBlockCumulativeWithSums, RatioCents64, RollingWindows},
|
internal::{PerBlockCumulativeWithSums, RatioCents64, RollingWindows},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct AdjustedSopr<M: StorageMode = Rw> {
|
pub struct AdjustedSopr<M: StorageMode = Rw> {
|
||||||
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
|
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||||
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
|
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||||
pub ratio: RollingWindows<StoredF64, M>,
|
pub ratio: RollingWindows<StoredF64, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,13 +35,13 @@ impl AdjustedSopr {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Compute value_created = base.value_created - under_1h.value_created
|
// 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,
|
starting_indexes.height,
|
||||||
base_value_created,
|
base_value_created,
|
||||||
under_1h_value_created,
|
under_1h_value_created,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.value_destroyed.raw.height.compute_subtract(
|
self.value_destroyed.base.height.compute_subtract(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
base_value_destroyed,
|
base_value_destroyed,
|
||||||
under_1h_value_destroyed,
|
under_1h_value_destroyed,
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ impl RealizedCore {
|
|||||||
let neg_realized_loss = LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
|
let neg_realized_loss = LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
|
||||||
&cfg.name("neg_realized_loss"),
|
&cfg.name("neg_realized_loss"),
|
||||||
cfg.version + Version::ONE,
|
cfg.version + Version::ONE,
|
||||||
minimal.loss.raw.cents.height.read_only_boxed_clone(),
|
minimal.loss.base.cents.height.read_only_boxed_clone(),
|
||||||
cfg.indexes,
|
cfg.indexes,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -103,10 +103,10 @@ impl RealizedCore {
|
|||||||
self.minimal
|
self.minimal
|
||||||
.compute_rest_part1(starting_indexes, exit)?;
|
.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,
|
starting_indexes.height,
|
||||||
&self.minimal.profit.raw.cents.height,
|
&self.minimal.profit.base.cents.height,
|
||||||
&self.minimal.loss.raw.cents.height,
|
&self.minimal.loss.base.cents.height,
|
||||||
|(i, profit, loss, ..)| {
|
|(i, profit, loss, ..)| {
|
||||||
(
|
(
|
||||||
i,
|
i,
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ use crate::{
|
|||||||
blocks,
|
blocks,
|
||||||
distribution::state::{WithCapital, CohortState, CostBasisData, RealizedState},
|
distribution::state::{WithCapital, CohortState, CostBasisData, RealizedState},
|
||||||
internal::{
|
internal::{
|
||||||
CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative,
|
CentsUnsignedToDollars, PerBlock, PerBlockCumulative,
|
||||||
ComputedPerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
|
PerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
|
||||||
LazyPerBlock, PercentPerBlock, PercentRollingWindows, Price,
|
LazyPerBlock, PercentPerBlock, PercentRollingWindows, Price,
|
||||||
PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32,
|
PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32,
|
||||||
RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32,
|
RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32,
|
||||||
@@ -32,16 +32,16 @@ use super::RealizedCore;
|
|||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct RealizedProfit<M: StorageMode = Rw> {
|
pub struct RealizedProfit<M: StorageMode = Rw> {
|
||||||
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
|
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||||
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
|
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||||
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
|
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||||
pub distribution_flow: LazyPerBlock<Dollars, Cents>,
|
pub distribution_flow: LazyPerBlock<Dollars, Cents>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct RealizedLoss<M: StorageMode = Rw> {
|
pub struct RealizedLoss<M: StorageMode = Rw> {
|
||||||
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
|
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||||
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
|
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||||
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
|
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||||
pub capitulation_flow: LazyPerBlock<Dollars, Cents>,
|
pub capitulation_flow: LazyPerBlock<Dollars, Cents>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,15 +63,15 @@ pub struct RealizedSopr<M: StorageMode = Rw> {
|
|||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct RealizedPeakRegret<M: StorageMode = Rw> {
|
pub struct RealizedPeakRegret<M: StorageMode = Rw> {
|
||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub value: ComputedPerBlockCumulative<Cents, M>,
|
pub value: PerBlockCumulative<Cents, M>,
|
||||||
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
|
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct RealizedInvestor<M: StorageMode = Rw> {
|
pub struct RealizedInvestor<M: StorageMode = Rw> {
|
||||||
pub price: PriceWithRatioExtendedPerBlock<M>,
|
pub price: PriceWithRatioExtendedPerBlock<M>,
|
||||||
pub lower_price_band: Price<ComputedPerBlock<Cents, M>>,
|
pub lower_price_band: Price<PerBlock<Cents, M>>,
|
||||||
pub upper_price_band: Price<ComputedPerBlock<Cents, M>>,
|
pub upper_price_band: Price<PerBlock<Cents, M>>,
|
||||||
#[traversable(hidden)]
|
#[traversable(hidden)]
|
||||||
pub cap_raw: M::Stored<BytesVec<Height, CentsSquaredSats>>,
|
pub cap_raw: M::Stored<BytesVec<Height, CentsSquaredSats>>,
|
||||||
}
|
}
|
||||||
@@ -115,13 +115,13 @@ impl RealizedFull {
|
|||||||
let core = RealizedCore::forced_import(cfg)?;
|
let core = RealizedCore::forced_import(cfg)?;
|
||||||
|
|
||||||
// Profit
|
// Profit
|
||||||
let profit_value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents> =
|
let profit_value_destroyed: PerBlockCumulativeWithSums<Cents, Cents> =
|
||||||
cfg.import("profit_value_destroyed", v1)?;
|
cfg.import("profit_value_destroyed", v1)?;
|
||||||
let profit_flow = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
let profit_flow = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||||
&cfg.name("distribution_flow"),
|
&cfg.name("distribution_flow"),
|
||||||
cfg.version,
|
cfg.version,
|
||||||
profit_value_destroyed.raw.height.read_only_boxed_clone(),
|
profit_value_destroyed.base.height.read_only_boxed_clone(),
|
||||||
&profit_value_destroyed.raw,
|
&profit_value_destroyed.base,
|
||||||
);
|
);
|
||||||
let profit = RealizedProfit {
|
let profit = RealizedProfit {
|
||||||
rel_to_rcap: cfg.import("realized_profit_rel_to_rcap", Version::new(2))?,
|
rel_to_rcap: cfg.import("realized_profit_rel_to_rcap", Version::new(2))?,
|
||||||
@@ -131,13 +131,13 @@ impl RealizedFull {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Loss
|
// Loss
|
||||||
let loss_value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents> =
|
let loss_value_destroyed: PerBlockCumulativeWithSums<Cents, Cents> =
|
||||||
cfg.import("loss_value_destroyed", v1)?;
|
cfg.import("loss_value_destroyed", v1)?;
|
||||||
let capitulation_flow = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
let capitulation_flow = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||||
&cfg.name("capitulation_flow"),
|
&cfg.name("capitulation_flow"),
|
||||||
cfg.version,
|
cfg.version,
|
||||||
loss_value_destroyed.raw.height.read_only_boxed_clone(),
|
loss_value_destroyed.base.height.read_only_boxed_clone(),
|
||||||
&loss_value_destroyed.raw,
|
&loss_value_destroyed.base,
|
||||||
);
|
);
|
||||||
let loss = RealizedLoss {
|
let loss = RealizedLoss {
|
||||||
rel_to_rcap: cfg.import("realized_loss_rel_to_rcap", Version::new(2))?,
|
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 {
|
pub(crate) fn min_stateful_len(&self) -> usize {
|
||||||
self.profit
|
self.profit
|
||||||
.value_created
|
.value_created
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.len()
|
.len()
|
||||||
.min(self.profit.value_destroyed.raw.height.len())
|
.min(self.profit.value_destroyed.base.height.len())
|
||||||
.min(self.loss.value_created.raw.height.len())
|
.min(self.loss.value_created.base.height.len())
|
||||||
.min(self.loss.value_destroyed.raw.height.len())
|
.min(self.loss.value_destroyed.base.height.len())
|
||||||
.min(self.investor.price.cents.height.len())
|
.min(self.investor.price.cents.height.len())
|
||||||
.min(self.cap_raw.len())
|
.min(self.cap_raw.len())
|
||||||
.min(self.investor.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(
|
pub(crate) fn truncate_push(
|
||||||
@@ -242,22 +242,22 @@ impl RealizedFull {
|
|||||||
self.core.truncate_push(height, state)?;
|
self.core.truncate_push(height, state)?;
|
||||||
self.profit
|
self.profit
|
||||||
.value_created
|
.value_created
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, state.realized.profit_value_created())?;
|
.truncate_push(height, state.realized.profit_value_created())?;
|
||||||
self.profit
|
self.profit
|
||||||
.value_destroyed
|
.value_destroyed
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, state.realized.profit_value_destroyed())?;
|
.truncate_push(height, state.realized.profit_value_destroyed())?;
|
||||||
self.loss
|
self.loss
|
||||||
.value_created
|
.value_created
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, state.realized.loss_value_created())?;
|
.truncate_push(height, state.realized.loss_value_created())?;
|
||||||
self.loss
|
self.loss
|
||||||
.value_destroyed
|
.value_destroyed
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, state.realized.loss_value_destroyed())?;
|
.truncate_push(height, state.realized.loss_value_destroyed())?;
|
||||||
self.investor
|
self.investor
|
||||||
@@ -272,7 +272,7 @@ impl RealizedFull {
|
|||||||
.truncate_push(height, state.realized.investor_cap_raw())?;
|
.truncate_push(height, state.realized.investor_cap_raw())?;
|
||||||
self.peak_regret
|
self.peak_regret
|
||||||
.value
|
.value
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, state.realized.peak_regret())?;
|
.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> {
|
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||||
let mut vecs = self.core.collect_vecs_mut();
|
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_created.base.height as &mut dyn AnyStoredVec);
|
||||||
vecs.push(&mut self.profit.value_destroyed.raw.height);
|
vecs.push(&mut self.profit.value_destroyed.base.height);
|
||||||
vecs.push(&mut self.loss.value_created.raw.height);
|
vecs.push(&mut self.loss.value_created.base.height);
|
||||||
vecs.push(&mut self.loss.value_destroyed.raw.height);
|
vecs.push(&mut self.loss.value_destroyed.base.height);
|
||||||
vecs.push(&mut self.investor.price.cents.height);
|
vecs.push(&mut self.investor.price.cents.height);
|
||||||
vecs.push(&mut self.cap_raw as &mut dyn AnyStoredVec);
|
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.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
|
vecs
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,22 +311,22 @@ impl RealizedFull {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.profit
|
self.profit
|
||||||
.value_created
|
.value_created
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, accum.profit_value_created)?;
|
.truncate_push(height, accum.profit_value_created)?;
|
||||||
self.profit
|
self.profit
|
||||||
.value_destroyed
|
.value_destroyed
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, accum.profit_value_destroyed)?;
|
.truncate_push(height, accum.profit_value_destroyed)?;
|
||||||
self.loss
|
self.loss
|
||||||
.value_created
|
.value_created
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, accum.loss_value_created)?;
|
.truncate_push(height, accum.loss_value_created)?;
|
||||||
self.loss
|
self.loss
|
||||||
.value_destroyed
|
.value_destroyed
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, accum.loss_value_destroyed)?;
|
.truncate_push(height, accum.loss_value_destroyed)?;
|
||||||
self.cap_raw
|
self.cap_raw
|
||||||
@@ -351,7 +351,7 @@ impl RealizedFull {
|
|||||||
|
|
||||||
self.peak_regret
|
self.peak_regret
|
||||||
.value
|
.value
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, accum.peak_regret)?;
|
.truncate_push(height, accum.peak_regret)?;
|
||||||
|
|
||||||
@@ -410,7 +410,7 @@ impl RealizedFull {
|
|||||||
.rel_to_rcap
|
.rel_to_rcap
|
||||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.core.minimal.profit.raw.cents.height,
|
&self.core.minimal.profit.base.cents.height,
|
||||||
&self.core.minimal.cap.cents.height,
|
&self.core.minimal.cap.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
@@ -418,7 +418,7 @@ impl RealizedFull {
|
|||||||
.rel_to_rcap
|
.rel_to_rcap
|
||||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.core.minimal.loss.raw.cents.height,
|
&self.core.minimal.loss.base.cents.height,
|
||||||
&self.core.minimal.cap.cents.height,
|
&self.core.minimal.cap.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
@@ -426,7 +426,7 @@ impl RealizedFull {
|
|||||||
.rel_to_rcap
|
.rel_to_rcap
|
||||||
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.core.net_pnl.raw.cents.height,
|
&self.core.net_pnl.base.cents.height,
|
||||||
&self.core.minimal.cap.cents.height,
|
&self.core.minimal.cap.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
@@ -446,10 +446,10 @@ impl RealizedFull {
|
|||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_indexes.height, exit)?;
|
||||||
|
|
||||||
// Gross PnL
|
// Gross PnL
|
||||||
self.gross_pnl.raw.cents.height.compute_add(
|
self.gross_pnl.base.cents.height.compute_add(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.core.minimal.profit.raw.cents.height,
|
&self.core.minimal.profit.base.cents.height,
|
||||||
&self.core.minimal.loss.raw.cents.height,
|
&self.core.minimal.loss.base.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.gross_pnl
|
self.gross_pnl
|
||||||
@@ -478,7 +478,7 @@ impl RealizedFull {
|
|||||||
.rel_to_rcap
|
.rel_to_rcap
|
||||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.peak_regret.value.raw.height,
|
&self.peak_regret.value.base.height,
|
||||||
&self.core.minimal.cap.cents.height,
|
&self.core.minimal.cap.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use vecdb::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
distribution::state::{CohortState, CostBasisOps, RealizedOps},
|
distribution::state::{CohortState, CostBasisOps, RealizedOps},
|
||||||
internal::{
|
internal::{
|
||||||
ComputedPerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
|
PerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
|
||||||
FiatPerBlockWithDeltas, Identity, LazyPerBlock, PriceWithRatioPerBlock,
|
FiatPerBlockWithDeltas, Identity, LazyPerBlock, PriceWithRatioPerBlock,
|
||||||
},
|
},
|
||||||
prices,
|
prices,
|
||||||
@@ -21,8 +21,8 @@ use crate::distribution::metrics::ImportConfig;
|
|||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct RealizedSoprMinimal<M: StorageMode = Rw> {
|
pub struct RealizedSoprMinimal<M: StorageMode = Rw> {
|
||||||
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
|
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||||
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
|
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
@@ -74,24 +74,24 @@ impl RealizedMinimal {
|
|||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.len()
|
.len()
|
||||||
.min(self.profit.raw.cents.height.len())
|
.min(self.profit.base.cents.height.len())
|
||||||
.min(self.loss.raw.cents.height.len())
|
.min(self.loss.base.cents.height.len())
|
||||||
.min(self.sopr.value_created.raw.height.len())
|
.min(self.sopr.value_created.base.height.len())
|
||||||
.min(self.sopr.value_destroyed.raw.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<()> {
|
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.cap.cents.height.truncate_push(height, state.realized.cap())?;
|
||||||
self.profit.raw.cents.height.truncate_push(height, state.realized.profit())?;
|
self.profit.base.cents.height.truncate_push(height, state.realized.profit())?;
|
||||||
self.loss.raw.cents.height.truncate_push(height, state.realized.loss())?;
|
self.loss.base.cents.height.truncate_push(height, state.realized.loss())?;
|
||||||
self.sopr
|
self.sopr
|
||||||
.value_created
|
.value_created
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, state.realized.value_created())?;
|
.truncate_push(height, state.realized.value_created())?;
|
||||||
self.sopr
|
self.sopr
|
||||||
.value_destroyed
|
.value_destroyed
|
||||||
.raw
|
.base
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, state.realized.value_destroyed())?;
|
.truncate_push(height, state.realized.value_destroyed())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -100,10 +100,10 @@ impl RealizedMinimal {
|
|||||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||||
vec![
|
vec![
|
||||||
&mut self.cap.cents.height as &mut dyn AnyStoredVec,
|
&mut self.cap.cents.height as &mut dyn AnyStoredVec,
|
||||||
&mut self.profit.raw.cents.height,
|
&mut self.profit.base.cents.height,
|
||||||
&mut self.loss.raw.cents.height,
|
&mut self.loss.base.cents.height,
|
||||||
&mut self.sopr.value_created.raw.height,
|
&mut self.sopr.value_created.base.height,
|
||||||
&mut self.sopr.value_destroyed.raw.height,
|
&mut self.sopr.value_destroyed.base.height,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,10 +114,10 @@ impl RealizedMinimal {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
sum_others!(self, starting_indexes, others, exit; cap.cents.height);
|
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; profit.base.cents.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; loss.raw.cents.height);
|
sum_others!(self, starting_indexes, others, exit; loss.base.cents.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; sopr.value_created.raw.height);
|
sum_others!(self, starting_indexes, others, exit; sopr.value_created.base.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; sopr.value_destroyed.raw.height);
|
sum_others!(self, starting_indexes, others, exit; sopr.value_destroyed.base.height);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,14 +42,14 @@ impl RelativeExtendedOwnMarketCap {
|
|||||||
self.unrealized_profit_rel_to_own_mcap
|
self.unrealized_profit_rel_to_own_mcap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.profit.raw.usd.height,
|
&unrealized.profit.base.usd.height,
|
||||||
own_market_cap,
|
own_market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.unrealized_loss_rel_to_own_mcap
|
self.unrealized_loss_rel_to_own_mcap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.loss.raw.usd.height,
|
&unrealized.loss.base.usd.height,
|
||||||
own_market_cap,
|
own_market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -43,14 +43,14 @@ impl RelativeExtendedOwnPnl {
|
|||||||
self.unrealized_profit_rel_to_own_gross_pnl
|
self.unrealized_profit_rel_to_own_gross_pnl
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.profit.raw.usd.height,
|
&unrealized.profit.base.usd.height,
|
||||||
gross_pnl_usd,
|
gross_pnl_usd,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.unrealized_loss_rel_to_own_gross_pnl
|
self.unrealized_loss_rel_to_own_gross_pnl
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.loss.raw.usd.height,
|
&unrealized.loss.base.usd.height,
|
||||||
gross_pnl_usd,
|
gross_pnl_usd,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -64,14 +64,14 @@ impl RelativeFull {
|
|||||||
self.unrealized_profit_rel_to_mcap
|
self.unrealized_profit_rel_to_mcap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.profit.raw.usd.height,
|
&unrealized.profit.base.usd.height,
|
||||||
market_cap,
|
market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.unrealized_loss_rel_to_mcap
|
self.unrealized_loss_rel_to_mcap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.loss.raw.usd.height,
|
&unrealized.loss.base.usd.height,
|
||||||
market_cap,
|
market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -34,21 +34,21 @@ impl UnrealizedBasic {
|
|||||||
|
|
||||||
pub(crate) fn min_stateful_len(&self) -> usize {
|
pub(crate) fn min_stateful_len(&self) -> usize {
|
||||||
self.profit
|
self.profit
|
||||||
.raw
|
.base
|
||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.len()
|
.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<()> {
|
pub(crate) fn truncate_push(&mut self, height: Height, state: &UnrealizedState) -> Result<()> {
|
||||||
self.profit
|
self.profit
|
||||||
.raw
|
.base
|
||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, state.unrealized_profit)?;
|
.truncate_push(height, state.unrealized_profit)?;
|
||||||
self.loss
|
self.loss
|
||||||
.raw
|
.base
|
||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, state.unrealized_loss)?;
|
.truncate_push(height, state.unrealized_loss)?;
|
||||||
@@ -57,8 +57,8 @@ impl UnrealizedBasic {
|
|||||||
|
|
||||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||||
vec![
|
vec![
|
||||||
&mut self.profit.raw.cents.height as &mut dyn AnyStoredVec,
|
&mut self.profit.base.cents.height as &mut dyn AnyStoredVec,
|
||||||
&mut self.loss.raw.cents.height,
|
&mut self.loss.base.cents.height,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,8 +68,8 @@ impl UnrealizedBasic {
|
|||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
sum_others!(self, starting_indexes, others, exit; profit.raw.cents.height);
|
sum_others!(self, starting_indexes, others, exit; profit.base.cents.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; loss.raw.cents.height);
|
sum_others!(self, starting_indexes, others, exit; loss.base.cents.height);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ impl UnrealizedCore {
|
|||||||
let neg_unrealized_loss = LazyPerBlock::from_computed::<NegCentsUnsignedToDollars>(
|
let neg_unrealized_loss = LazyPerBlock::from_computed::<NegCentsUnsignedToDollars>(
|
||||||
&cfg.name("neg_unrealized_loss"),
|
&cfg.name("neg_unrealized_loss"),
|
||||||
cfg.version,
|
cfg.version,
|
||||||
basic.loss.raw.cents.height.read_only_boxed_clone(),
|
basic.loss.base.cents.height.read_only_boxed_clone(),
|
||||||
&basic.loss.raw.cents,
|
&basic.loss.base.cents,
|
||||||
);
|
);
|
||||||
|
|
||||||
let net_unrealized_pnl = cfg.import("net_unrealized_pnl", Version::ZERO)?;
|
let net_unrealized_pnl = cfg.import("net_unrealized_pnl", Version::ZERO)?;
|
||||||
@@ -90,8 +90,8 @@ impl UnrealizedCore {
|
|||||||
.height
|
.height
|
||||||
.compute_binary::<Cents, Cents, CentsSubtractToCentsSigned>(
|
.compute_binary::<Cents, Cents, CentsSubtractToCentsSigned>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.basic.profit.raw.cents.height,
|
&self.basic.profit.base.cents.height,
|
||||||
&self.basic.loss.raw.cents.height,
|
&self.basic.loss.base.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -96,8 +96,8 @@ impl UnrealizedFull {
|
|||||||
|
|
||||||
self.gross_pnl.cents.height.compute_add(
|
self.gross_pnl.cents.height.compute_add(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.inner.core.basic.profit.raw.cents.height,
|
&self.inner.core.basic.profit.base.cents.height,
|
||||||
&self.inner.core.basic.loss.raw.cents.height,
|
&self.inner.core.basic.loss.base.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use crate::{
|
|||||||
state::BlockState,
|
state::BlockState,
|
||||||
},
|
},
|
||||||
indexes, inputs,
|
indexes, inputs,
|
||||||
internal::{CachedWindowStarts, ComputedPerBlockCumulative, finalize_db, open_db},
|
internal::{CachedWindowStarts, PerBlockCumulative, db_utils::{finalize_db, open_db}},
|
||||||
outputs, prices, transactions,
|
outputs, prices, transactions,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ pub struct Vecs<M: StorageMode = Rw> {
|
|||||||
#[traversable(wrap = "cohorts", rename = "address")]
|
#[traversable(wrap = "cohorts", rename = "address")]
|
||||||
pub address_cohorts: AddressCohorts<M>,
|
pub address_cohorts: AddressCohorts<M>,
|
||||||
#[traversable(wrap = "cointime")]
|
#[traversable(wrap = "cointime")]
|
||||||
pub coinblocks_destroyed: ComputedPerBlockCumulative<StoredF64, M>,
|
pub coinblocks_destroyed: PerBlockCumulative<StoredF64, M>,
|
||||||
pub addresses: AddressMetricsVecs<M>,
|
pub addresses: AddressMetricsVecs<M>,
|
||||||
|
|
||||||
/// In-memory block state for UTXO processing. Persisted via supply_state.
|
/// In-memory block state for UTXO processing. Persisted via supply_state.
|
||||||
@@ -173,7 +173,7 @@ impl Vecs {
|
|||||||
utxo_cohorts,
|
utxo_cohorts,
|
||||||
address_cohorts,
|
address_cohorts,
|
||||||
|
|
||||||
coinblocks_destroyed: ComputedPerBlockCumulative::forced_import(
|
coinblocks_destroyed: PerBlockCumulative::forced_import(
|
||||||
&db,
|
&db,
|
||||||
"coinblocks_destroyed",
|
"coinblocks_destroyed",
|
||||||
version + Version::TWO,
|
version + Version::TWO,
|
||||||
@@ -489,6 +489,6 @@ impl Vecs {
|
|||||||
.min(Height::from(self.addresses.funded.min_stateful_len()))
|
.min(Height::from(self.addresses.funded.min_stateful_len()))
|
||||||
.min(Height::from(self.addresses.empty.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.addresses.activity.min_stateful_len()))
|
||||||
.min(Height::from(self.coinblocks_destroyed.raw.height.len()))
|
.min(Height::from(self.coinblocks_destroyed.base.height.len()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ use vecdb::{CachedVec, Database, Exit, ReadableVec, Rw, StorageMode};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
blocks,
|
blocks,
|
||||||
internal::{finalize_db, open_db},
|
internal::db_utils::{finalize_db, open_db},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use cached_mappings::CachedMappings;
|
pub use cached_mappings::CachedMappings;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use brk_types::Version;
|
|||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
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);
|
const VERSION: Version = Version::new(1);
|
||||||
@@ -27,16 +27,16 @@ impl Vecs {
|
|||||||
let thermocap_multiple =
|
let thermocap_multiple =
|
||||||
RatioPerBlock::forced_import_raw(&db, "thermocap_multiple", v, indexes)?;
|
RatioPerBlock::forced_import_raw(&db, "thermocap_multiple", v, indexes)?;
|
||||||
let coindays_destroyed_supply_adjusted =
|
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 =
|
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 {
|
let dormancy = super::vecs::DormancyVecs {
|
||||||
supply_adjusted: ComputedPerBlock::forced_import(&db, "dormancy_supply_adjusted", v, indexes)?,
|
supply_adjusted: PerBlock::forced_import(&db, "dormancy_supply_adjusted", v, indexes)?,
|
||||||
flow: ComputedPerBlock::forced_import(&db, "dormancy_flow", 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 =
|
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 {
|
let this = Self {
|
||||||
db,
|
db,
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{BasisPoints16, BasisPoints32, StoredF32};
|
use brk_types::{BasisPoints16, BasisPoints32, StoredF32};
|
||||||
use vecdb::{Database, Rw, StorageMode};
|
use vecdb::{Database, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::{ComputedPerBlock, PercentPerBlock, RatioPerBlock};
|
use crate::internal::{PerBlock, PercentPerBlock, RatioPerBlock};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct DormancyVecs<M: StorageMode = Rw> {
|
pub struct DormancyVecs<M: StorageMode = Rw> {
|
||||||
pub supply_adjusted: ComputedPerBlock<StoredF32, M>,
|
pub supply_adjusted: PerBlock<StoredF32, M>,
|
||||||
pub flow: ComputedPerBlock<StoredF32, M>,
|
pub flow: PerBlock<StoredF32, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
@@ -19,9 +19,9 @@ pub struct Vecs<M: StorageMode = Rw> {
|
|||||||
pub gini: PercentPerBlock<BasisPoints16, M>,
|
pub gini: PercentPerBlock<BasisPoints16, M>,
|
||||||
pub rhodl_ratio: RatioPerBlock<BasisPoints32, M>,
|
pub rhodl_ratio: RatioPerBlock<BasisPoints32, M>,
|
||||||
pub thermocap_multiple: RatioPerBlock<BasisPoints32, M>,
|
pub thermocap_multiple: RatioPerBlock<BasisPoints32, M>,
|
||||||
pub coindays_destroyed_supply_adjusted: ComputedPerBlock<StoredF32, M>,
|
pub coindays_destroyed_supply_adjusted: PerBlock<StoredF32, M>,
|
||||||
pub coinyears_destroyed_supply_adjusted: ComputedPerBlock<StoredF32, M>,
|
pub coinyears_destroyed_supply_adjusted: PerBlock<StoredF32, M>,
|
||||||
pub dormancy: DormancyVecs<M>,
|
pub dormancy: DormancyVecs<M>,
|
||||||
pub stock_to_flow: ComputedPerBlock<StoredF32, M>,
|
pub stock_to_flow: PerBlock<StoredF32, M>,
|
||||||
pub seller_exhaustion_constant: ComputedPerBlock<StoredF32, M>,
|
pub seller_exhaustion_constant: PerBlock<StoredF32, M>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
|||||||
use vecdb::Database;
|
use vecdb::Database;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::{indexes, internal::{CachedWindowStarts, ComputedPerBlockAggregated}};
|
use crate::{indexes, internal::{CachedWindowStarts, PerBlockAggregated}};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn forced_import(
|
pub(crate) fn forced_import(
|
||||||
@@ -12,7 +12,7 @@ impl Vecs {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Ok(Self(ComputedPerBlockAggregated::forced_import(
|
Ok(Self(PerBlockAggregated::forced_import(
|
||||||
db,
|
db,
|
||||||
"input_count",
|
"input_count",
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::StoredU64;
|
use brk_types::StoredU64;
|
||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::ComputedPerBlockAggregated;
|
use crate::internal::PerBlockAggregated;
|
||||||
|
|
||||||
#[derive(Deref, DerefMut, Traversable)]
|
#[derive(Deref, DerefMut, Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw>(
|
pub struct Vecs<M: StorageMode = Rw>(
|
||||||
#[traversable(flatten)] pub ComputedPerBlockAggregated<StoredU64, M>,
|
#[traversable(flatten)] pub PerBlockAggregated<StoredU64, M>,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use brk_types::Version;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{finalize_db, open_db, CachedWindowStarts},
|
internal::{CachedWindowStarts, db_utils::{finalize_db, open_db}},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{CountVecs, SpentVecs, Vecs};
|
use super::{CountVecs, SpentVecs, Vecs};
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ use vecdb::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::internal::{
|
use crate::internal::{
|
||||||
ComputedVecValue, DistributionStats, compute_aggregations, compute_aggregations_nblock_window,
|
ComputedVecValue, DistributionStats,
|
||||||
|
algo::{compute_aggregations, compute_aggregations_nblock_window},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
|
|||||||
@@ -6,20 +6,20 @@ use vecdb::{
|
|||||||
VecIndex, VecValue, Version,
|
VecIndex, VecValue, Version,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::internal::{ComputedVecValue, compute_aggregations};
|
use crate::internal::{ComputedVecValue, algo::compute_aggregations};
|
||||||
|
|
||||||
use super::Distribution;
|
use super::Distribution;
|
||||||
|
|
||||||
/// Full stats aggregate: distribution + sum + cumulative
|
/// Full stats aggregate: distribution + sum + cumulative
|
||||||
#[derive(Traversable)]
|
#[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)]
|
#[traversable(flatten)]
|
||||||
pub distribution: Distribution<I, T, M>,
|
pub distribution: Distribution<I, T, M>,
|
||||||
pub sum: M::Stored<EagerVec<PcoVec<I, T>>>,
|
pub sum: M::Stored<EagerVec<PcoVec<I, T>>>,
|
||||||
pub cumulative: 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> {
|
pub(crate) fn forced_import(db: &Database, name: &str, version: Version) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
distribution: Distribution::forced_import(db, name, version)?,
|
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> {
|
pub fn read_only_clone(&self) -> DistributionFull<I, T, Ro> {
|
||||||
Full {
|
DistributionFull {
|
||||||
distribution: self.distribution.read_only_clone(),
|
distribution: self.distribution.read_only_clone(),
|
||||||
sum: StoredVec::read_only_clone(&self.sum),
|
sum: StoredVec::read_only_clone(&self.sum),
|
||||||
cumulative: StoredVec::read_only_clone(&self.cumulative),
|
cumulative: StoredVec::read_only_clone(&self.cumulative),
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
mod distribution;
|
mod distribution;
|
||||||
mod full;
|
mod distribution_full;
|
||||||
mod lazy_distribution;
|
mod lazy_distribution;
|
||||||
|
|
||||||
pub use distribution::*;
|
pub use distribution::*;
|
||||||
pub use full::*;
|
pub use distribution_full::*;
|
||||||
pub use lazy_distribution::*;
|
pub use lazy_distribution::*;
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
mod lazy;
|
|
||||||
|
|
||||||
pub use lazy::*;
|
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
|
mod constant;
|
||||||
mod distribution_stats;
|
mod distribution_stats;
|
||||||
mod per_resolution;
|
mod per_resolution;
|
||||||
mod window_24h;
|
mod window_24h;
|
||||||
mod windows;
|
mod windows;
|
||||||
mod windows_from_1w;
|
mod windows_from_1w;
|
||||||
|
|
||||||
|
pub use constant::*;
|
||||||
pub use distribution_stats::*;
|
pub use distribution_stats::*;
|
||||||
pub use per_resolution::*;
|
pub use per_resolution::*;
|
||||||
pub use window_24h::*;
|
pub use window_24h::*;
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
use brk_traversable::Traversable;
|
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)]
|
#[derive(Clone, Traversable)]
|
||||||
pub struct Windows<A> {
|
pub struct Windows<A> {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
mod aggregate;
|
mod aggregate;
|
||||||
mod algo;
|
pub(crate) mod algo;
|
||||||
mod amount;
|
mod amount;
|
||||||
mod containers;
|
mod containers;
|
||||||
mod db_utils;
|
pub(crate) mod db_utils;
|
||||||
mod per_block;
|
mod per_block;
|
||||||
mod per_tx;
|
mod per_tx;
|
||||||
mod indexes;
|
mod indexes;
|
||||||
@@ -10,10 +10,8 @@ mod traits;
|
|||||||
mod transform;
|
mod transform;
|
||||||
|
|
||||||
pub(crate) use aggregate::*;
|
pub(crate) use aggregate::*;
|
||||||
pub(crate) use algo::*;
|
|
||||||
pub(crate) use amount::*;
|
pub(crate) use amount::*;
|
||||||
pub(crate) use containers::*;
|
pub(crate) use containers::*;
|
||||||
pub(crate) use db_utils::*;
|
|
||||||
pub(crate) use per_block::*;
|
pub(crate) use per_block::*;
|
||||||
pub(crate) use per_tx::*;
|
pub(crate) use per_tx::*;
|
||||||
pub(crate) use indexes::*;
|
pub(crate) use indexes::*;
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ use vecdb::{AnyVec, Database, Exit, ReadableCloneableVec, Rw, StorageMode};
|
|||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{
|
internal::{
|
||||||
CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock, SatsToBitcoin, SatsToCents,
|
CentsUnsignedToDollars, PerBlock, LazyPerBlock, SatsToBitcoin, SatsToCents,
|
||||||
},
|
},
|
||||||
prices,
|
prices,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct AmountPerBlock<M: StorageMode = Rw> {
|
pub struct AmountPerBlock<M: StorageMode = Rw> {
|
||||||
pub sats: ComputedPerBlock<Sats, M>,
|
pub sats: PerBlock<Sats, M>,
|
||||||
pub btc: LazyPerBlock<Bitcoin, Sats>,
|
pub btc: LazyPerBlock<Bitcoin, Sats>,
|
||||||
pub cents: ComputedPerBlock<Cents, M>,
|
pub cents: PerBlock<Cents, M>,
|
||||||
pub usd: LazyPerBlock<Dollars, Cents>,
|
pub usd: LazyPerBlock<Dollars, Cents>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ impl AmountPerBlock {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let sats =
|
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>(
|
let btc = LazyPerBlock::from_computed::<SatsToBitcoin>(
|
||||||
name,
|
name,
|
||||||
@@ -37,7 +37,7 @@ impl AmountPerBlock {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let cents =
|
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>(
|
let usd = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||||
&format!("{name}_usd"),
|
&format!("{name}_usd"),
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use crate::{
|
|||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct AmountPerBlockCumulativeWithSums<M: StorageMode = Rw> {
|
pub struct AmountPerBlockCumulativeWithSums<M: StorageMode = Rw> {
|
||||||
pub raw: AmountPerBlock<M>,
|
pub base: AmountPerBlock<M>,
|
||||||
pub cumulative: AmountPerBlock<M>,
|
pub cumulative: AmountPerBlock<M>,
|
||||||
pub sum: LazyRollingSumsAmountFromHeight,
|
pub sum: LazyRollingSumsAmountFromHeight,
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ impl AmountPerBlockCumulativeWithSums {
|
|||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let v = version + VERSION;
|
let v = version + VERSION;
|
||||||
|
|
||||||
let raw = AmountPerBlock::forced_import(db, name, v, indexes)?;
|
let base = AmountPerBlock::forced_import(db, name, v, indexes)?;
|
||||||
let cumulative =
|
let cumulative =
|
||||||
AmountPerBlock::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
AmountPerBlock::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||||
let sum = LazyRollingSumsAmountFromHeight::new(
|
let sum = LazyRollingSumsAmountFromHeight::new(
|
||||||
@@ -41,7 +41,7 @@ impl AmountPerBlockCumulativeWithSums {
|
|||||||
);
|
);
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
raw,
|
base,
|
||||||
cumulative,
|
cumulative,
|
||||||
sum,
|
sum,
|
||||||
})
|
})
|
||||||
@@ -54,7 +54,7 @@ impl AmountPerBlockCumulativeWithSums {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
compute_sats: impl FnOnce(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
|
compute_sats: impl FnOnce(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
compute_sats(&mut self.raw.sats.height)?;
|
compute_sats(&mut self.base.sats.height)?;
|
||||||
self.compute_rest(max_from, prices, exit)
|
self.compute_rest(max_from, prices, exit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,14 +67,14 @@ impl AmountPerBlockCumulativeWithSums {
|
|||||||
self.cumulative
|
self.cumulative
|
||||||
.sats
|
.sats
|
||||||
.height
|
.height
|
||||||
.compute_cumulative(max_from, &self.raw.sats.height, exit)?;
|
.compute_cumulative(max_from, &self.base.sats.height, exit)?;
|
||||||
|
|
||||||
self.raw
|
self.base
|
||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.compute_binary::<Sats, Cents, SatsToCents>(
|
.compute_binary::<Sats, Cents, SatsToCents>(
|
||||||
max_from,
|
max_from,
|
||||||
&self.raw.sats.height,
|
&self.base.sats.height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
@@ -82,7 +82,7 @@ impl AmountPerBlockCumulativeWithSums {
|
|||||||
self.cumulative
|
self.cumulative
|
||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.compute_cumulative(max_from, &self.raw.cents.height, exit)?;
|
.compute_cumulative(max_from, &self.base.cents.height, exit)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
indexes,
|
indexes,
|
||||||
internal::{
|
internal::{
|
||||||
AmountPerBlock, DistributionStats, WindowStarts, Windows,
|
AmountPerBlock, DistributionStats, WindowStarts, Windows,
|
||||||
compute_rolling_distribution_from_starts,
|
algo::compute_rolling_distribution_from_starts,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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),
|
//! 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.
|
//! where we want full per-block stats plus rolling window stats.
|
||||||
@@ -11,20 +11,20 @@ use vecdb::{Database, Exit, Rw, StorageMode};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CachedWindowStarts, Full, NumericValue, RollingFull, WindowStarts},
|
internal::{CachedWindowStarts, DistributionFull, NumericValue, RollingComplete, WindowStarts},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct ComputedPerBlockAggregated<T, M: StorageMode = Rw>
|
pub struct PerBlockAggregated<T, M: StorageMode = Rw>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub full: Full<Height, T, M>,
|
pub full: DistributionFull<Height, T, M>,
|
||||||
pub rolling: RollingFull<T, M>,
|
pub rolling: RollingComplete<T, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ComputedPerBlockAggregated<T>
|
impl<T> PerBlockAggregated<T>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
@@ -35,8 +35,8 @@ where
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let full = Full::forced_import(db, name, version)?;
|
let full = DistributionFull::forced_import(db, name, version)?;
|
||||||
let rolling = RollingFull::forced_import(
|
let rolling = RollingComplete::forced_import(
|
||||||
db,
|
db,
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
@@ -48,13 +48,13 @@ where
|
|||||||
Ok(Self { full, rolling })
|
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(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
max_from: Height,
|
max_from: Height,
|
||||||
windows: &WindowStarts<'_>,
|
windows: &WindowStarts<'_>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
compute_full: impl FnOnce(&mut Full<Height, T>) -> Result<()>,
|
compute_full: impl FnOnce(&mut DistributionFull<Height, T>) -> Result<()>,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
T: From<f64> + Default + Copy + Ord,
|
T: From<f64> + Default + Copy + Ord,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use crate::internal::{Resolutions, ComputedVecValue, NumericValue};
|
|||||||
|
|
||||||
#[derive(Deref, DerefMut, Traversable)]
|
#[derive(Deref, DerefMut, Traversable)]
|
||||||
#[traversable(merge)]
|
#[traversable(merge)]
|
||||||
pub struct ComputedPerBlock<T, M: StorageMode = Rw>
|
pub struct PerBlock<T, M: StorageMode = Rw>
|
||||||
where
|
where
|
||||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||||
{
|
{
|
||||||
@@ -26,7 +26,7 @@ where
|
|||||||
pub resolutions: Box<Resolutions<T>>,
|
pub resolutions: Box<Resolutions<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ComputedPerBlock<T>
|
impl<T> PerBlock<T>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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.
|
//! Used for distribution metrics where rolling is optional per cohort.
|
||||||
|
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
@@ -11,19 +11,19 @@ use vecdb::{Database, Exit, Rw, StorageMode};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{ComputedPerBlock, NumericValue},
|
internal::{PerBlock, NumericValue},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct ComputedPerBlockCumulative<T, M: StorageMode = Rw>
|
pub struct PerBlockCumulative<T, M: StorageMode = Rw>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
pub raw: ComputedPerBlock<T, M>,
|
pub base: PerBlock<T, M>,
|
||||||
pub cumulative: ComputedPerBlock<T, M>,
|
pub cumulative: PerBlock<T, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ComputedPerBlockCumulative<T>
|
impl<T> PerBlockCumulative<T>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
@@ -33,21 +33,21 @@ where
|
|||||||
version: Version,
|
version: Version,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?;
|
let base = PerBlock::forced_import(db, name, version, indexes)?;
|
||||||
let cumulative =
|
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<()>
|
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
|
||||||
where
|
where
|
||||||
T: Default,
|
T: Default,
|
||||||
{
|
{
|
||||||
self.cumulative
|
self.cumulative
|
||||||
.height
|
.height
|
||||||
.compute_cumulative(max_from, &self.raw.height, exit)?;
|
.compute_cumulative(max_from, &self.base.height, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
//! Rolling sums are derived lazily from the cumulative vec via LazyDeltaVec.
|
||||||
//! No rolling sum vecs are stored on disk.
|
//! No rolling sum vecs are stored on disk.
|
||||||
@@ -17,21 +17,21 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CachedWindowStarts, ComputedPerBlock, LazyRollingSumsFromHeight, NumericValue},
|
internal::{CachedWindowStarts, PerBlock, LazyRollingSumsFromHeight, NumericValue},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct ComputedPerBlockCumulativeWithSums<T, C, M: StorageMode = Rw>
|
pub struct PerBlockCumulativeWithSums<T, C, M: StorageMode = Rw>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
C: NumericValue + JsonSchema,
|
C: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
pub raw: ComputedPerBlock<T, M>,
|
pub base: PerBlock<T, M>,
|
||||||
pub cumulative: ComputedPerBlock<C, M>,
|
pub cumulative: PerBlock<C, M>,
|
||||||
pub sum: LazyRollingSumsFromHeight<C>,
|
pub sum: LazyRollingSumsFromHeight<C>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, C> ComputedPerBlockCumulativeWithSums<T, C>
|
impl<T, C> PerBlockCumulativeWithSums<T, C>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema + Into<C>,
|
T: NumericValue + JsonSchema + Into<C>,
|
||||||
C: NumericValue + JsonSchema,
|
C: NumericValue + JsonSchema,
|
||||||
@@ -43,9 +43,9 @@ where
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?;
|
let base = PerBlock::forced_import(db, name, version, indexes)?;
|
||||||
let cumulative =
|
let cumulative =
|
||||||
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||||
let sum = LazyRollingSumsFromHeight::new(
|
let sum = LazyRollingSumsFromHeight::new(
|
||||||
&format!("{name}_sum"),
|
&format!("{name}_sum"),
|
||||||
version,
|
version,
|
||||||
@@ -55,34 +55,34 @@ where
|
|||||||
);
|
);
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
raw,
|
base,
|
||||||
cumulative,
|
cumulative,
|
||||||
sum,
|
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(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
max_from: Height,
|
max_from: Height,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
compute_raw: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
compute_base: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
C: Default,
|
C: Default,
|
||||||
{
|
{
|
||||||
compute_raw(&mut self.raw.height)?;
|
compute_base(&mut self.base.height)?;
|
||||||
self.compute_rest(max_from, exit)
|
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<()>
|
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
|
||||||
where
|
where
|
||||||
C: Default,
|
C: Default,
|
||||||
{
|
{
|
||||||
self.cumulative
|
self.cumulative
|
||||||
.height
|
.height
|
||||||
.compute_cumulative(max_from, &self.raw.height, exit)?;
|
.compute_cumulative(max_from, &self.base.height, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
//! 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::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CachedWindowStarts, ComputedPerBlock, NumericValue, RollingFull, WindowStarts},
|
internal::{CachedWindowStarts, PerBlock, NumericValue, RollingComplete, WindowStarts},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct ComputedPerBlockFull<T, M: StorageMode = Rw>
|
pub struct PerBlockFull<T, M: StorageMode = Rw>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
pub raw: ComputedPerBlock<T, M>,
|
pub base: PerBlock<T, M>,
|
||||||
pub cumulative: ComputedPerBlock<T, M>,
|
pub cumulative: PerBlock<T, M>,
|
||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub rolling: RollingFull<T, M>,
|
pub rolling: RollingComplete<T, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ComputedPerBlockFull<T>
|
impl<T> PerBlockFull<T>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
@@ -35,10 +35,10 @@ where
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?;
|
let base = PerBlock::forced_import(db, name, version, indexes)?;
|
||||||
let cumulative =
|
let cumulative =
|
||||||
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||||
let rolling = RollingFull::forced_import(
|
let rolling = RollingComplete::forced_import(
|
||||||
db,
|
db,
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
@@ -48,30 +48,30 @@ where
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
raw,
|
base,
|
||||||
cumulative,
|
cumulative,
|
||||||
rolling,
|
rolling,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute raw data via closure, then cumulative + rolling distribution.
|
/// Compute base data via closure, then cumulative + rolling distribution.
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
max_from: Height,
|
max_from: Height,
|
||||||
windows: &WindowStarts<'_>,
|
windows: &WindowStarts<'_>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
compute_raw: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
compute_base: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
T: From<f64> + Default + Copy + Ord,
|
T: From<f64> + Default + Copy + Ord,
|
||||||
f64: From<T>,
|
f64: From<T>,
|
||||||
{
|
{
|
||||||
compute_raw(&mut self.raw.height)?;
|
compute_base(&mut self.base.height)?;
|
||||||
self.cumulative
|
self.cumulative
|
||||||
.height
|
.height
|
||||||
.compute_cumulative(max_from, &self.raw.height, exit)?;
|
.compute_cumulative(max_from, &self.base.height, exit)?;
|
||||||
self.rolling
|
self.rolling
|
||||||
.compute(max_from, windows, &self.raw.height, exit)?;
|
.compute(max_from, windows, &self.base.height, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,33 +6,33 @@ use vecdb::{ReadableCloneableVec, UnaryTransform};
|
|||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{
|
internal::{
|
||||||
CachedWindowStarts, ComputedPerBlockFull, ComputedVecValue, LazyPerBlock, LazyRollingFull,
|
CachedWindowStarts, PerBlockFull, ComputedVecValue, LazyPerBlock, LazyRollingComplete,
|
||||||
NumericValue,
|
NumericValue,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Lazy analog of `ResolutionsFull<T>`: lazy cumulative + lazy rolling full.
|
/// Lazy analog of `PerBlockRolling<T>`: lazy cumulative + lazy rolling complete.
|
||||||
/// Derived by transforming a `ComputedPerBlockFull<S1T>`. Zero stored vecs.
|
/// Derived by transforming a `PerBlockFull<S1T>`. Zero stored vecs.
|
||||||
#[derive(Clone, Traversable)]
|
#[derive(Clone, Traversable)]
|
||||||
pub struct LazyResolutionsFull<T, S1T>
|
pub struct LazyPerBlockRolling<T, S1T>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
S1T: ComputedVecValue + JsonSchema,
|
S1T: ComputedVecValue + JsonSchema,
|
||||||
{
|
{
|
||||||
pub cumulative: LazyPerBlock<T, S1T>,
|
pub cumulative: LazyPerBlock<T, S1T>,
|
||||||
#[traversable(flatten)]
|
#[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
|
where
|
||||||
T: NumericValue + JsonSchema + 'static,
|
T: NumericValue + JsonSchema + 'static,
|
||||||
S1T: NumericValue + JsonSchema,
|
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,
|
name: &str,
|
||||||
version: Version,
|
version: Version,
|
||||||
source: &ComputedPerBlockFull<S1T>,
|
source: &PerBlockFull<S1T>,
|
||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -43,7 +43,7 @@ where
|
|||||||
&source.cumulative,
|
&source.cumulative,
|
||||||
);
|
);
|
||||||
|
|
||||||
let rolling = LazyRollingFull::from_rolling_full::<F>(
|
let rolling = LazyRollingComplete::from_rolling_complete::<F>(
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
&cumulative.height,
|
&cumulative.height,
|
||||||
@@ -1,23 +1,21 @@
|
|||||||
mod aggregated;
|
mod aggregated;
|
||||||
mod base;
|
mod base;
|
||||||
mod constant;
|
|
||||||
mod cumulative;
|
mod cumulative;
|
||||||
mod cumulative_sum;
|
mod cumulative_sum;
|
||||||
mod resolutions;
|
mod resolutions;
|
||||||
mod resolutions_full;
|
mod rolling;
|
||||||
mod lazy_resolutions_full;
|
mod lazy_rolling;
|
||||||
mod full;
|
mod full;
|
||||||
mod rolling_average;
|
mod rolling_average;
|
||||||
mod with_deltas;
|
mod with_deltas;
|
||||||
|
|
||||||
pub use aggregated::*;
|
pub use aggregated::*;
|
||||||
pub use base::*;
|
pub use base::*;
|
||||||
pub use constant::*;
|
|
||||||
pub use cumulative::*;
|
pub use cumulative::*;
|
||||||
pub use cumulative_sum::*;
|
pub use cumulative_sum::*;
|
||||||
pub use resolutions::*;
|
pub use resolutions::*;
|
||||||
pub use resolutions_full::*;
|
pub use rolling::*;
|
||||||
pub use lazy_resolutions_full::*;
|
pub use lazy_rolling::*;
|
||||||
pub use full::*;
|
pub use full::*;
|
||||||
pub use rolling_average::*;
|
pub use rolling_average::*;
|
||||||
pub use with_deltas::*;
|
pub use with_deltas::*;
|
||||||
|
|||||||
@@ -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).
|
//! 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_error::Result;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
@@ -11,20 +11,20 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CachedWindowStarts, ComputedPerBlock, NumericValue, RollingFull, WindowStarts},
|
internal::{CachedWindowStarts, PerBlock, NumericValue, RollingComplete, WindowStarts},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct ResolutionsFull<T, M: StorageMode = Rw>
|
pub struct PerBlockRolling<T, M: StorageMode = Rw>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
pub cumulative: ComputedPerBlock<T, M>,
|
pub cumulative: PerBlock<T, M>,
|
||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub rolling: RollingFull<T, M>,
|
pub rolling: RollingComplete<T, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ResolutionsFull<T>
|
impl<T> PerBlockRolling<T>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
@@ -36,8 +36,8 @@ where
|
|||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let cumulative =
|
let cumulative =
|
||||||
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||||
let rolling = RollingFull::forced_import(
|
let rolling = RollingComplete::forced_import(
|
||||||
db,
|
db,
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
@@ -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.
|
//! Stored height data + f64 cumulative + lazy 4-window rolling averages.
|
||||||
//! Rolling averages are computed on-the-fly from the cumulative via DeltaAvg.
|
//! 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};
|
use crate::internal::{CachedWindowStarts, LazyRollingAvgsFromHeight, NumericValue};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct ComputedPerBlockRollingAverage<T, M: StorageMode = Rw>
|
pub struct PerBlockRollingAverage<T, M: StorageMode = Rw>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
@@ -26,7 +26,7 @@ where
|
|||||||
pub average: LazyRollingAvgsFromHeight<T>,
|
pub average: LazyRollingAvgsFromHeight<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ComputedPerBlockRollingAverage<T>
|
impl<T> PerBlockRollingAverage<T>
|
||||||
where
|
where
|
||||||
T: NumericValue + JsonSchema,
|
T: NumericValue + JsonSchema,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ use vecdb::{Rw, StorageMode};
|
|||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{
|
internal::{
|
||||||
BpsType, CachedWindowStarts, ComputedPerBlock, LazyRollingDeltasFromHeight, NumericValue,
|
BpsType, CachedWindowStarts, PerBlock, LazyRollingDeltasFromHeight, NumericValue,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Deref, DerefMut, Traversable)]
|
#[derive(Deref, DerefMut, Traversable)]
|
||||||
pub struct ComputedPerBlockWithDeltas<S, C, B, M: StorageMode = Rw>
|
pub struct PerBlockWithDeltas<S, C, B, M: StorageMode = Rw>
|
||||||
where
|
where
|
||||||
S: NumericValue + JsonSchema + Into<f64>,
|
S: NumericValue + JsonSchema + Into<f64>,
|
||||||
C: NumericValue + JsonSchema + From<f64>,
|
C: NumericValue + JsonSchema + From<f64>,
|
||||||
@@ -22,11 +22,11 @@ where
|
|||||||
#[deref]
|
#[deref]
|
||||||
#[deref_mut]
|
#[deref_mut]
|
||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub inner: ComputedPerBlock<S, M>,
|
pub inner: PerBlock<S, M>,
|
||||||
pub delta: LazyRollingDeltasFromHeight<S, C, B>,
|
pub delta: LazyRollingDeltasFromHeight<S, C, B>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, C, B> ComputedPerBlockWithDeltas<S, C, B>
|
impl<S, C, B> PerBlockWithDeltas<S, C, B>
|
||||||
where
|
where
|
||||||
S: NumericValue + JsonSchema + Into<f64>,
|
S: NumericValue + JsonSchema + Into<f64>,
|
||||||
C: NumericValue + JsonSchema + From<f64>,
|
C: NumericValue + JsonSchema + From<f64>,
|
||||||
@@ -40,7 +40,7 @@ where
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let inner = ComputedPerBlock::forced_import(db, name, version, indexes)?;
|
let inner = PerBlock::forced_import(db, name, version, indexes)?;
|
||||||
|
|
||||||
let delta = LazyRollingDeltasFromHeight::new(
|
let delta = LazyRollingDeltasFromHeight::new(
|
||||||
&format!("{name}_delta"),
|
&format!("{name}_delta"),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode, UnaryTransform};
|
|||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{
|
internal::{
|
||||||
CentsSignedToDollars, CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock,
|
CentsSignedToDollars, CentsUnsignedToDollars, PerBlock, LazyPerBlock,
|
||||||
NumericValue,
|
NumericValue,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -29,7 +29,7 @@ impl CentsType for CentsSigned {
|
|||||||
/// Generic over `C` to support both `Cents` (unsigned) and `CentsSigned` (signed).
|
/// Generic over `C` to support both `Cents` (unsigned) and `CentsSigned` (signed).
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct FiatPerBlock<C: CentsType, M: StorageMode = Rw> {
|
pub struct FiatPerBlock<C: CentsType, M: StorageMode = Rw> {
|
||||||
pub cents: ComputedPerBlock<C, M>,
|
pub cents: PerBlock<C, M>,
|
||||||
pub usd: LazyPerBlock<Dollars, C>,
|
pub usd: LazyPerBlock<Dollars, C>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ impl<C: CentsType> FiatPerBlock<C> {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let cents =
|
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>(
|
let usd = LazyPerBlock::from_computed::<C::ToDollars>(
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use crate::{
|
|||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct FiatPerBlockCumulativeWithSums<C: CentsType, M: StorageMode = Rw> {
|
pub struct FiatPerBlockCumulativeWithSums<C: CentsType, M: StorageMode = Rw> {
|
||||||
pub raw: FiatPerBlock<C, M>,
|
pub base: FiatPerBlock<C, M>,
|
||||||
pub cumulative: FiatPerBlock<C, M>,
|
pub cumulative: FiatPerBlock<C, M>,
|
||||||
pub sum: LazyRollingSumsFiatFromHeight<C>,
|
pub sum: LazyRollingSumsFiatFromHeight<C>,
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> 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(
|
let cumulative = FiatPerBlock::forced_import(
|
||||||
db,
|
db,
|
||||||
&format!("{name}_cumulative"),
|
&format!("{name}_cumulative"),
|
||||||
@@ -37,7 +37,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
|
|||||||
cached_starts,
|
cached_starts,
|
||||||
indexes,
|
indexes,
|
||||||
);
|
);
|
||||||
Ok(Self { raw, cumulative, sum })
|
Ok(Self { base, cumulative, sum })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
|
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
|
||||||
@@ -47,7 +47,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
|
|||||||
self.cumulative
|
self.cumulative
|
||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.compute_cumulative(max_from, &self.raw.cents.height, exit)?;
|
.compute_cumulative(max_from, &self.base.cents.height, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{Dollars, Version};
|
use brk_types::{Dollars, Version};
|
||||||
use vecdb::ReadableCloneableVec;
|
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.
|
/// Lazy fiat: both cents and usd are lazy views of a stored source.
|
||||||
/// Zero extra stored vecs.
|
/// Zero extra stored vecs.
|
||||||
@@ -16,7 +16,7 @@ impl<C: CentsType> LazyFiatPerBlock<C> {
|
|||||||
pub(crate) fn from_computed(
|
pub(crate) fn from_computed(
|
||||||
name: &str,
|
name: &str,
|
||||||
version: Version,
|
version: Version,
|
||||||
source: &ComputedPerBlock<C>,
|
source: &PerBlock<C>,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
C: NumericValue,
|
C: NumericValue,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use vecdb::{LazyVecFrom1, ReadableBoxedVec, ReadableCloneableVec, UnaryTransform
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{ComputedPerBlock, ComputedVecValue, DerivedResolutions, NumericValue},
|
internal::{PerBlock, ComputedVecValue, DerivedResolutions, NumericValue},
|
||||||
};
|
};
|
||||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||||
#[traversable(merge)]
|
#[traversable(merge)]
|
||||||
@@ -31,7 +31,7 @@ where
|
|||||||
name: &str,
|
name: &str,
|
||||||
version: Version,
|
version: Version,
|
||||||
height_source: ReadableBoxedVec<Height, S1T>,
|
height_source: ReadableBoxedVec<Height, S1T>,
|
||||||
source: &ComputedPerBlock<S1T>,
|
source: &PerBlock<S1T>,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
S1T: NumericValue,
|
S1T: NumericValue,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use vecdb::{ReadableBoxedVec, ReadableCloneableVec, UnaryTransform, VecValue};
|
|||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{
|
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>>(
|
pub(crate) fn from_computed<F: UnaryTransform<S1T, T>>(
|
||||||
name: &str,
|
name: &str,
|
||||||
version: Version,
|
version: Version,
|
||||||
source: &ComputedPerBlock<S1T>,
|
source: &PerBlock<S1T>,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
S1T: NumericValue,
|
S1T: NumericValue,
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ use vecdb::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
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.
|
/// 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%)
|
/// - `percent`: bps / 100 (e.g., 4523 bps -> 45.23%)
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct PercentPerBlock<B: BpsType, M: StorageMode = Rw> {
|
pub struct PercentPerBlock<B: BpsType, M: StorageMode = Rw> {
|
||||||
pub bps: ComputedPerBlock<B, M>,
|
pub bps: PerBlock<B, M>,
|
||||||
pub ratio: LazyPerBlock<StoredF32, B>,
|
pub ratio: LazyPerBlock<StoredF32, B>,
|
||||||
pub percent: LazyPerBlock<StoredF32, B>,
|
pub percent: LazyPerBlock<StoredF32, B>,
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ impl<B: BpsType> PercentPerBlock<B> {
|
|||||||
version: Version,
|
version: Version,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> 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 bps_clone = bps.height.read_only_boxed_clone();
|
||||||
|
|
||||||
let ratio = LazyPerBlock::from_computed::<B::ToRatio>(
|
let ratio = LazyPerBlock::from_computed::<B::ToRatio>(
|
||||||
|
|||||||
46
crates/brk_computer/src/internal/per_block/percent/lazy.rs
Normal file
46
crates/brk_computer/src/internal/per_block/percent/lazy.rs
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,
|
||||||
|
)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
mod base;
|
mod base;
|
||||||
|
mod lazy;
|
||||||
|
mod lazy_windows;
|
||||||
mod rolling_average;
|
mod rolling_average;
|
||||||
mod windows;
|
mod windows;
|
||||||
|
|
||||||
pub use base::*;
|
pub use base::*;
|
||||||
|
pub use lazy::*;
|
||||||
|
pub use lazy_windows::*;
|
||||||
pub use rolling_average::*;
|
pub use rolling_average::*;
|
||||||
pub use windows::*;
|
pub use windows::*;
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ use crate::{
|
|||||||
internal::{BpsType, CachedWindowStarts},
|
internal::{BpsType, CachedWindowStarts},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::internal::{ComputedPerBlockRollingAverage, LazyPerBlock};
|
use crate::internal::{PerBlockRollingAverage, LazyPerBlock};
|
||||||
|
|
||||||
/// Like PercentPerBlock but with rolling average stats on the bps data.
|
/// Like PercentPerBlock but with rolling average stats on the bps data.
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct PercentPerBlockRollingAverage<B: BpsType, M: StorageMode = Rw> {
|
pub struct PercentPerBlockRollingAverage<B: BpsType, M: StorageMode = Rw> {
|
||||||
pub bps: ComputedPerBlockRollingAverage<B, M>,
|
pub bps: PerBlockRollingAverage<B, M>,
|
||||||
pub ratio: LazyPerBlock<StoredF32, B>,
|
pub ratio: LazyPerBlock<StoredF32, B>,
|
||||||
pub percent: LazyPerBlock<StoredF32, B>,
|
pub percent: LazyPerBlock<StoredF32, B>,
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ impl<B: BpsType> PercentPerBlockRollingAverage<B> {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
cached_starts: &CachedWindowStarts,
|
cached_starts: &CachedWindowStarts,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let bps = ComputedPerBlockRollingAverage::forced_import(
|
let bps = PerBlockRollingAverage::forced_import(
|
||||||
db,
|
db,
|
||||||
&format!("{name}_bps"),
|
&format!("{name}_bps"),
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use brk_types::{Cents, Height, Version};
|
|||||||
use vecdb::{AnyExportableVec, Database, ReadOnlyClone, Ro, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyExportableVec, Database, ReadOnlyClone, Ro, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
use crate::indexes;
|
use crate::indexes;
|
||||||
use crate::internal::{ComputedPerBlock, Price};
|
use crate::internal::{PerBlock, Price};
|
||||||
|
|
||||||
pub const PERCENTILES: [u8; 19] = [
|
pub const PERCENTILES: [u8; 19] = [
|
||||||
5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95,
|
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 const PERCENTILES_LEN: usize = PERCENTILES.len();
|
||||||
|
|
||||||
pub struct PercentilesVecs<M: StorageMode = Rw> {
|
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;
|
const VERSION: Version = Version::ONE;
|
||||||
@@ -73,7 +73,7 @@ impl ReadOnlyClone for PercentilesVecs {
|
|||||||
|
|
||||||
impl<M: StorageMode> Traversable for PercentilesVecs<M>
|
impl<M: StorageMode> Traversable for PercentilesVecs<M>
|
||||||
where
|
where
|
||||||
Price<ComputedPerBlock<Cents, M>>: Traversable,
|
Price<PerBlock<Cents, M>>: Traversable,
|
||||||
{
|
{
|
||||||
fn to_tree_node(&self) -> TreeNode {
|
fn to_tree_node(&self) -> TreeNode {
|
||||||
TreeNode::Branch(
|
TreeNode::Branch(
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use brk_types::{Cents, Dollars, SatsFract, Version};
|
|||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use vecdb::{Database, ReadableCloneableVec, UnaryTransform};
|
use vecdb::{Database, ReadableCloneableVec, UnaryTransform};
|
||||||
|
|
||||||
use super::{ComputedPerBlock, LazyPerBlock};
|
use super::{PerBlock, LazyPerBlock};
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{CentsUnsignedToDollars, ComputedVecValue, DollarsToSatsFract, NumericValue},
|
internal::{CentsUnsignedToDollars, ComputedVecValue, DollarsToSatsFract, NumericValue},
|
||||||
@@ -24,7 +24,7 @@ pub struct Price<C> {
|
|||||||
pub sats: LazyPerBlock<SatsFract, Dollars>,
|
pub sats: LazyPerBlock<SatsFract, Dollars>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Price<ComputedPerBlock<Cents>> {
|
impl Price<PerBlock<Cents>> {
|
||||||
/// Import from database: stored cents, lazy USD + sats.
|
/// Import from database: stored cents, lazy USD + sats.
|
||||||
pub(crate) fn forced_import(
|
pub(crate) fn forced_import(
|
||||||
db: &Database,
|
db: &Database,
|
||||||
@@ -33,7 +33,7 @@ impl Price<ComputedPerBlock<Cents>> {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let cents =
|
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>(
|
let usd = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
@@ -57,7 +57,7 @@ where
|
|||||||
pub(crate) fn from_cents_source<F: UnaryTransform<ST, Cents>>(
|
pub(crate) fn from_cents_source<F: UnaryTransform<ST, Cents>>(
|
||||||
name: &str,
|
name: &str,
|
||||||
version: Version,
|
version: Version,
|
||||||
source: &ComputedPerBlock<ST>,
|
source: &PerBlock<ST>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let cents = LazyPerBlock::from_computed::<F>(
|
let cents = LazyPerBlock::from_computed::<F>(
|
||||||
&format!("{name}_cents"),
|
&format!("{name}_cents"),
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{BpsType, ComputedPerBlock, LazyPerBlock},
|
internal::{BpsType, PerBlock, LazyPerBlock},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct RatioPerBlock<B: BpsType = BasisPoints32, M: StorageMode = Rw> {
|
pub struct RatioPerBlock<B: BpsType = BasisPoints32, M: StorageMode = Rw> {
|
||||||
pub bps: ComputedPerBlock<B, M>,
|
pub bps: PerBlock<B, M>,
|
||||||
pub ratio: LazyPerBlock<StoredF32, B>,
|
pub ratio: LazyPerBlock<StoredF32, B>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ impl<B: BpsType> RatioPerBlock<B> {
|
|||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let v = version + VERSION;
|
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>(
|
let ratio = LazyPerBlock::from_computed::<B::ToRatio>(
|
||||||
name,
|
name,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user