mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-12 19:48:15 -07:00
global: snapshot
This commit is contained in:
@@ -7,7 +7,8 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedVecValue, DistributionStats, compute_aggregations, compute_aggregations_nblock_window,
|
||||
ComputedVecValue, DistributionStats,
|
||||
algo::{compute_aggregations, compute_aggregations_nblock_window},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
|
||||
+5
-5
@@ -6,20 +6,20 @@ use vecdb::{
|
||||
VecIndex, VecValue, Version,
|
||||
};
|
||||
|
||||
use crate::internal::{ComputedVecValue, compute_aggregations};
|
||||
use crate::internal::{ComputedVecValue, algo::compute_aggregations};
|
||||
|
||||
use super::Distribution;
|
||||
|
||||
/// Full stats aggregate: distribution + sum + cumulative
|
||||
#[derive(Traversable)]
|
||||
pub struct Full<I: VecIndex, T: ComputedVecValue + JsonSchema, M: StorageMode = Rw> {
|
||||
pub struct DistributionFull<I: VecIndex, T: ComputedVecValue + JsonSchema, M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub distribution: Distribution<I, T, M>,
|
||||
pub sum: M::Stored<EagerVec<PcoVec<I, T>>>,
|
||||
pub cumulative: M::Stored<EagerVec<PcoVec<I, T>>>,
|
||||
}
|
||||
|
||||
impl<I: VecIndex, T: ComputedVecValue + JsonSchema> Full<I, T> {
|
||||
impl<I: VecIndex, T: ComputedVecValue + JsonSchema> DistributionFull<I, T> {
|
||||
pub(crate) fn forced_import(db: &Database, name: &str, version: Version) -> Result<Self> {
|
||||
Ok(Self {
|
||||
distribution: Distribution::forced_import(db, name, version)?,
|
||||
@@ -65,8 +65,8 @@ impl<I: VecIndex, T: ComputedVecValue + JsonSchema> Full<I, T> {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn read_only_clone(&self) -> Full<I, T, Ro> {
|
||||
Full {
|
||||
pub fn read_only_clone(&self) -> DistributionFull<I, T, Ro> {
|
||||
DistributionFull {
|
||||
distribution: self.distribution.read_only_clone(),
|
||||
sum: StoredVec::read_only_clone(&self.sum),
|
||||
cumulative: StoredVec::read_only_clone(&self.cumulative),
|
||||
@@ -1,7 +1,7 @@
|
||||
mod distribution;
|
||||
mod full;
|
||||
mod distribution_full;
|
||||
mod lazy_distribution;
|
||||
|
||||
pub use distribution::*;
|
||||
pub use full::*;
|
||||
pub use distribution_full::*;
|
||||
pub use lazy_distribution::*;
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
mod lazy;
|
||||
|
||||
pub use lazy::*;
|
||||
@@ -1,9 +1,11 @@
|
||||
mod constant;
|
||||
mod distribution_stats;
|
||||
mod per_resolution;
|
||||
mod window_24h;
|
||||
mod windows;
|
||||
mod windows_from_1w;
|
||||
|
||||
pub use constant::*;
|
||||
pub use distribution_stats::*;
|
||||
pub use per_resolution::*;
|
||||
pub use window_24h::*;
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::Height;
|
||||
use vecdb::CachedVec;
|
||||
|
||||
/// Cached window starts for lazy rolling computations.
|
||||
/// Clone-cheap (all fields are Arc-backed). Shared across all metrics.
|
||||
#[derive(Clone)]
|
||||
pub struct CachedWindowStarts(pub Windows<CachedVec<Height, Height>>);
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Windows<A> {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
mod aggregate;
|
||||
mod algo;
|
||||
pub(crate) mod algo;
|
||||
mod amount;
|
||||
mod containers;
|
||||
mod db_utils;
|
||||
pub(crate) mod db_utils;
|
||||
mod per_block;
|
||||
mod per_tx;
|
||||
mod indexes;
|
||||
@@ -10,10 +10,8 @@ mod traits;
|
||||
mod transform;
|
||||
|
||||
pub(crate) use aggregate::*;
|
||||
pub(crate) use algo::*;
|
||||
pub(crate) use amount::*;
|
||||
pub(crate) use containers::*;
|
||||
pub(crate) use db_utils::*;
|
||||
pub(crate) use per_block::*;
|
||||
pub(crate) use per_tx::*;
|
||||
pub(crate) use indexes::*;
|
||||
|
||||
@@ -6,16 +6,16 @@ use vecdb::{AnyVec, Database, Exit, ReadableCloneableVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock, SatsToBitcoin, SatsToCents,
|
||||
CentsUnsignedToDollars, PerBlock, LazyPerBlock, SatsToBitcoin, SatsToCents,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct AmountPerBlock<M: StorageMode = Rw> {
|
||||
pub sats: ComputedPerBlock<Sats, M>,
|
||||
pub sats: PerBlock<Sats, M>,
|
||||
pub btc: LazyPerBlock<Bitcoin, Sats>,
|
||||
pub cents: ComputedPerBlock<Cents, M>,
|
||||
pub cents: PerBlock<Cents, M>,
|
||||
pub usd: LazyPerBlock<Dollars, Cents>,
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ impl AmountPerBlock {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let sats =
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_sats"), version, indexes)?;
|
||||
PerBlock::forced_import(db, &format!("{name}_sats"), version, indexes)?;
|
||||
|
||||
let btc = LazyPerBlock::from_computed::<SatsToBitcoin>(
|
||||
name,
|
||||
@@ -37,7 +37,7 @@ impl AmountPerBlock {
|
||||
);
|
||||
|
||||
let cents =
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
|
||||
let usd = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||
&format!("{name}_usd"),
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct AmountPerBlockCumulativeWithSums<M: StorageMode = Rw> {
|
||||
pub raw: AmountPerBlock<M>,
|
||||
pub base: AmountPerBlock<M>,
|
||||
pub cumulative: AmountPerBlock<M>,
|
||||
pub sum: LazyRollingSumsAmountFromHeight,
|
||||
}
|
||||
@@ -28,7 +28,7 @@ impl AmountPerBlockCumulativeWithSums {
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let raw = AmountPerBlock::forced_import(db, name, v, indexes)?;
|
||||
let base = AmountPerBlock::forced_import(db, name, v, indexes)?;
|
||||
let cumulative =
|
||||
AmountPerBlock::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
let sum = LazyRollingSumsAmountFromHeight::new(
|
||||
@@ -41,7 +41,7 @@ impl AmountPerBlockCumulativeWithSums {
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
raw,
|
||||
base,
|
||||
cumulative,
|
||||
sum,
|
||||
})
|
||||
@@ -54,7 +54,7 @@ impl AmountPerBlockCumulativeWithSums {
|
||||
exit: &Exit,
|
||||
compute_sats: impl FnOnce(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
|
||||
) -> Result<()> {
|
||||
compute_sats(&mut self.raw.sats.height)?;
|
||||
compute_sats(&mut self.base.sats.height)?;
|
||||
self.compute_rest(max_from, prices, exit)
|
||||
}
|
||||
|
||||
@@ -67,14 +67,14 @@ impl AmountPerBlockCumulativeWithSums {
|
||||
self.cumulative
|
||||
.sats
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.raw.sats.height, exit)?;
|
||||
.compute_cumulative(max_from, &self.base.sats.height, exit)?;
|
||||
|
||||
self.raw
|
||||
self.base
|
||||
.cents
|
||||
.height
|
||||
.compute_binary::<Sats, Cents, SatsToCents>(
|
||||
max_from,
|
||||
&self.raw.sats.height,
|
||||
&self.base.sats.height,
|
||||
&prices.spot.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
@@ -82,7 +82,7 @@ impl AmountPerBlockCumulativeWithSums {
|
||||
self.cumulative
|
||||
.cents
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.raw.cents.height, exit)?;
|
||||
.compute_cumulative(max_from, &self.base.cents.height, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
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),
|
||||
//! where we want full per-block stats plus rolling window stats.
|
||||
@@ -11,20 +11,20 @@ use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, Full, NumericValue, RollingFull, WindowStarts},
|
||||
internal::{CachedWindowStarts, DistributionFull, NumericValue, RollingComplete, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedPerBlockAggregated<T, M: StorageMode = Rw>
|
||||
pub struct PerBlockAggregated<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
#[traversable(flatten)]
|
||||
pub full: Full<Height, T, M>,
|
||||
pub rolling: RollingFull<T, M>,
|
||||
pub full: DistributionFull<Height, T, M>,
|
||||
pub rolling: RollingComplete<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ComputedPerBlockAggregated<T>
|
||||
impl<T> PerBlockAggregated<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -35,8 +35,8 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let full = Full::forced_import(db, name, version)?;
|
||||
let rolling = RollingFull::forced_import(
|
||||
let full = DistributionFull::forced_import(db, name, version)?;
|
||||
let rolling = RollingComplete::forced_import(
|
||||
db,
|
||||
name,
|
||||
version,
|
||||
@@ -48,13 +48,13 @@ where
|
||||
Ok(Self { full, rolling })
|
||||
}
|
||||
|
||||
/// Compute Full stats via closure, then rolling distribution from the per-block sum.
|
||||
/// Compute DistributionFull stats via closure, then rolling distribution from the per-block sum.
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
windows: &WindowStarts<'_>,
|
||||
exit: &Exit,
|
||||
compute_full: impl FnOnce(&mut Full<Height, T>) -> Result<()>,
|
||||
compute_full: impl FnOnce(&mut DistributionFull<Height, T>) -> Result<()>,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: From<f64> + Default + Copy + Ord,
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::internal::{Resolutions, ComputedVecValue, NumericValue};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedPerBlock<T, M: StorageMode = Rw>
|
||||
pub struct PerBlock<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -26,7 +26,7 @@ where
|
||||
pub resolutions: Box<Resolutions<T>>,
|
||||
}
|
||||
|
||||
impl<T> ComputedPerBlock<T>
|
||||
impl<T> PerBlock<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! ComputedPerBlockCumulative - raw ComputedPerBlock + cumulative ComputedPerBlock.
|
||||
//! PerBlockCumulative - base PerBlock + cumulative PerBlock.
|
||||
//!
|
||||
//! Like ComputedPerBlockCumulativeWithSums but without RollingWindows.
|
||||
//! Like PerBlockCumulativeWithSums but without RollingWindows.
|
||||
//! Used for distribution metrics where rolling is optional per cohort.
|
||||
|
||||
use brk_error::Result;
|
||||
@@ -11,19 +11,19 @@ use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedPerBlock, NumericValue},
|
||||
internal::{PerBlock, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedPerBlockCumulative<T, M: StorageMode = Rw>
|
||||
pub struct PerBlockCumulative<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub raw: ComputedPerBlock<T, M>,
|
||||
pub cumulative: ComputedPerBlock<T, M>,
|
||||
pub base: PerBlock<T, M>,
|
||||
pub cumulative: PerBlock<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ComputedPerBlockCumulative<T>
|
||||
impl<T> PerBlockCumulative<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -33,21 +33,21 @@ where
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?;
|
||||
let base = PerBlock::forced_import(db, name, version, indexes)?;
|
||||
let cumulative =
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
|
||||
Ok(Self { raw, cumulative })
|
||||
Ok(Self { base, cumulative })
|
||||
}
|
||||
|
||||
/// Compute cumulative from already-filled raw vec.
|
||||
/// Compute cumulative from already-filled base vec.
|
||||
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
|
||||
where
|
||||
T: Default,
|
||||
{
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.raw.height, exit)?;
|
||||
.compute_cumulative(max_from, &self.base.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedPerBlockCumulativeWithSums - raw ComputedPerBlock + cumulative ComputedPerBlock + lazy rolling sums.
|
||||
//! PerBlockCumulativeWithSums - base PerBlock + cumulative PerBlock + lazy rolling sums.
|
||||
//!
|
||||
//! Rolling sums are derived lazily from the cumulative vec via LazyDeltaVec.
|
||||
//! No rolling sum vecs are stored on disk.
|
||||
@@ -17,21 +17,21 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, ComputedPerBlock, LazyRollingSumsFromHeight, NumericValue},
|
||||
internal::{CachedWindowStarts, PerBlock, LazyRollingSumsFromHeight, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedPerBlockCumulativeWithSums<T, C, M: StorageMode = Rw>
|
||||
pub struct PerBlockCumulativeWithSums<T, C, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
C: NumericValue + JsonSchema,
|
||||
{
|
||||
pub raw: ComputedPerBlock<T, M>,
|
||||
pub cumulative: ComputedPerBlock<C, M>,
|
||||
pub base: PerBlock<T, M>,
|
||||
pub cumulative: PerBlock<C, M>,
|
||||
pub sum: LazyRollingSumsFromHeight<C>,
|
||||
}
|
||||
|
||||
impl<T, C> ComputedPerBlockCumulativeWithSums<T, C>
|
||||
impl<T, C> PerBlockCumulativeWithSums<T, C>
|
||||
where
|
||||
T: NumericValue + JsonSchema + Into<C>,
|
||||
C: NumericValue + JsonSchema,
|
||||
@@ -43,9 +43,9 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?;
|
||||
let base = PerBlock::forced_import(db, name, version, indexes)?;
|
||||
let cumulative =
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
let sum = LazyRollingSumsFromHeight::new(
|
||||
&format!("{name}_sum"),
|
||||
version,
|
||||
@@ -55,34 +55,34 @@ where
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
raw,
|
||||
base,
|
||||
cumulative,
|
||||
sum,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute raw data via closure, then cumulative. Rolling sums are lazy.
|
||||
/// Compute base data via closure, then cumulative. Rolling sums are lazy.
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
exit: &Exit,
|
||||
compute_raw: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||
compute_base: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||
) -> Result<()>
|
||||
where
|
||||
C: Default,
|
||||
{
|
||||
compute_raw(&mut self.raw.height)?;
|
||||
compute_base(&mut self.base.height)?;
|
||||
self.compute_rest(max_from, exit)
|
||||
}
|
||||
|
||||
/// Compute cumulative from already-populated raw data. Rolling sums are lazy.
|
||||
/// Compute cumulative from already-populated base data. Rolling sums are lazy.
|
||||
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
|
||||
where
|
||||
C: Default,
|
||||
{
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.raw.height, exit)?;
|
||||
.compute_cumulative(max_from, &self.base.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedPerBlockFull - raw ComputedPerBlock + cumulative ComputedPerBlock + RollingFull.
|
||||
//! PerBlockFull - base PerBlock + cumulative PerBlock + RollingComplete.
|
||||
//!
|
||||
//! For metrics with stored per-block data, cumulative sums, and rolling windows.
|
||||
|
||||
@@ -10,21 +10,21 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, ComputedPerBlock, NumericValue, RollingFull, WindowStarts},
|
||||
internal::{CachedWindowStarts, PerBlock, NumericValue, RollingComplete, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedPerBlockFull<T, M: StorageMode = Rw>
|
||||
pub struct PerBlockFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub raw: ComputedPerBlock<T, M>,
|
||||
pub cumulative: ComputedPerBlock<T, M>,
|
||||
pub base: PerBlock<T, M>,
|
||||
pub cumulative: PerBlock<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingFull<T, M>,
|
||||
pub rolling: RollingComplete<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ComputedPerBlockFull<T>
|
||||
impl<T> PerBlockFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -35,10 +35,10 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let raw = ComputedPerBlock::forced_import(db, name, version, indexes)?;
|
||||
let base = PerBlock::forced_import(db, name, version, indexes)?;
|
||||
let cumulative =
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
let rolling = RollingFull::forced_import(
|
||||
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
let rolling = RollingComplete::forced_import(
|
||||
db,
|
||||
name,
|
||||
version,
|
||||
@@ -48,30 +48,30 @@ where
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
raw,
|
||||
base,
|
||||
cumulative,
|
||||
rolling,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute raw data via closure, then cumulative + rolling distribution.
|
||||
/// Compute base data via closure, then cumulative + rolling distribution.
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
windows: &WindowStarts<'_>,
|
||||
exit: &Exit,
|
||||
compute_raw: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||
compute_base: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: From<f64> + Default + Copy + Ord,
|
||||
f64: From<T>,
|
||||
{
|
||||
compute_raw(&mut self.raw.height)?;
|
||||
compute_base(&mut self.base.height)?;
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.raw.height, exit)?;
|
||||
.compute_cumulative(max_from, &self.base.height, exit)?;
|
||||
self.rolling
|
||||
.compute(max_from, windows, &self.raw.height, exit)?;
|
||||
.compute(max_from, windows, &self.base.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -6,33 +6,33 @@ use vecdb::{ReadableCloneableVec, UnaryTransform};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, ComputedPerBlockFull, ComputedVecValue, LazyPerBlock, LazyRollingFull,
|
||||
CachedWindowStarts, PerBlockFull, ComputedVecValue, LazyPerBlock, LazyRollingComplete,
|
||||
NumericValue,
|
||||
},
|
||||
};
|
||||
|
||||
/// Lazy analog of `ResolutionsFull<T>`: lazy cumulative + lazy rolling full.
|
||||
/// Derived by transforming a `ComputedPerBlockFull<S1T>`. Zero stored vecs.
|
||||
/// Lazy analog of `PerBlockRolling<T>`: lazy cumulative + lazy rolling complete.
|
||||
/// Derived by transforming a `PerBlockFull<S1T>`. Zero stored vecs.
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyResolutionsFull<T, S1T>
|
||||
pub struct LazyPerBlockRolling<T, S1T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub cumulative: LazyPerBlock<T, S1T>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: LazyRollingFull<T, S1T>,
|
||||
pub rolling: LazyRollingComplete<T, S1T>,
|
||||
}
|
||||
|
||||
impl<T, S1T> LazyResolutionsFull<T, S1T>
|
||||
impl<T, S1T> LazyPerBlockRolling<T, S1T>
|
||||
where
|
||||
T: NumericValue + JsonSchema + 'static,
|
||||
S1T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_computed_per_block_full<F: UnaryTransform<S1T, T>>(
|
||||
pub(crate) fn from_per_block_full<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedPerBlockFull<S1T>,
|
||||
source: &PerBlockFull<S1T>,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
@@ -43,7 +43,7 @@ where
|
||||
&source.cumulative,
|
||||
);
|
||||
|
||||
let rolling = LazyRollingFull::from_rolling_full::<F>(
|
||||
let rolling = LazyRollingComplete::from_rolling_complete::<F>(
|
||||
name,
|
||||
version,
|
||||
&cumulative.height,
|
||||
@@ -1,23 +1,21 @@
|
||||
mod aggregated;
|
||||
mod base;
|
||||
mod constant;
|
||||
mod cumulative;
|
||||
mod cumulative_sum;
|
||||
mod resolutions;
|
||||
mod resolutions_full;
|
||||
mod lazy_resolutions_full;
|
||||
mod rolling;
|
||||
mod lazy_rolling;
|
||||
mod full;
|
||||
mod rolling_average;
|
||||
mod with_deltas;
|
||||
|
||||
pub use aggregated::*;
|
||||
pub use base::*;
|
||||
pub use constant::*;
|
||||
pub use cumulative::*;
|
||||
pub use cumulative_sum::*;
|
||||
pub use resolutions::*;
|
||||
pub use resolutions_full::*;
|
||||
pub use lazy_resolutions_full::*;
|
||||
pub use rolling::*;
|
||||
pub use lazy_rolling::*;
|
||||
pub use full::*;
|
||||
pub use rolling_average::*;
|
||||
pub use with_deltas::*;
|
||||
|
||||
+9
-9
@@ -1,7 +1,7 @@
|
||||
//! ResolutionsFull - LazyAggVec index views + cumulative (from height) + RollingFull.
|
||||
//! PerBlockRolling - LazyAggVec index views + cumulative (from height) + RollingComplete.
|
||||
//!
|
||||
//! For metrics derived from indexer sources (no stored height vec).
|
||||
//! Cumulative gets its own ComputedPerBlock so it has LazyAggVec index views too.
|
||||
//! Cumulative gets its own PerBlock so it has LazyAggVec index views too.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -11,20 +11,20 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, ComputedPerBlock, NumericValue, RollingFull, WindowStarts},
|
||||
internal::{CachedWindowStarts, PerBlock, NumericValue, RollingComplete, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ResolutionsFull<T, M: StorageMode = Rw>
|
||||
pub struct PerBlockRolling<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub cumulative: ComputedPerBlock<T, M>,
|
||||
pub cumulative: PerBlock<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingFull<T, M>,
|
||||
pub rolling: RollingComplete<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ResolutionsFull<T>
|
||||
impl<T> PerBlockRolling<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -36,8 +36,8 @@ where
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let cumulative =
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
let rolling = RollingFull::forced_import(
|
||||
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
let rolling = RollingComplete::forced_import(
|
||||
db,
|
||||
name,
|
||||
version,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedPerBlock with rolling average (no distribution stats).
|
||||
//! PerBlock with rolling average (no distribution stats).
|
||||
//!
|
||||
//! Stored height data + f64 cumulative + lazy 4-window rolling averages.
|
||||
//! Rolling averages are computed on-the-fly from the cumulative via DeltaAvg.
|
||||
@@ -15,7 +15,7 @@ use crate::indexes;
|
||||
use crate::internal::{CachedWindowStarts, LazyRollingAvgsFromHeight, NumericValue};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedPerBlockRollingAverage<T, M: StorageMode = Rw>
|
||||
pub struct PerBlockRollingAverage<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -26,7 +26,7 @@ where
|
||||
pub average: LazyRollingAvgsFromHeight<T>,
|
||||
}
|
||||
|
||||
impl<T> ComputedPerBlockRollingAverage<T>
|
||||
impl<T> PerBlockRollingAverage<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
|
||||
@@ -8,12 +8,12 @@ use vecdb::{Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
BpsType, CachedWindowStarts, ComputedPerBlock, LazyRollingDeltasFromHeight, NumericValue,
|
||||
BpsType, CachedWindowStarts, PerBlock, LazyRollingDeltasFromHeight, NumericValue,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct ComputedPerBlockWithDeltas<S, C, B, M: StorageMode = Rw>
|
||||
pub struct PerBlockWithDeltas<S, C, B, M: StorageMode = Rw>
|
||||
where
|
||||
S: NumericValue + JsonSchema + Into<f64>,
|
||||
C: NumericValue + JsonSchema + From<f64>,
|
||||
@@ -22,11 +22,11 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub inner: ComputedPerBlock<S, M>,
|
||||
pub inner: PerBlock<S, M>,
|
||||
pub delta: LazyRollingDeltasFromHeight<S, C, B>,
|
||||
}
|
||||
|
||||
impl<S, C, B> ComputedPerBlockWithDeltas<S, C, B>
|
||||
impl<S, C, B> PerBlockWithDeltas<S, C, B>
|
||||
where
|
||||
S: NumericValue + JsonSchema + Into<f64>,
|
||||
C: NumericValue + JsonSchema + From<f64>,
|
||||
@@ -40,7 +40,7 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let inner = ComputedPerBlock::forced_import(db, name, version, indexes)?;
|
||||
let inner = PerBlock::forced_import(db, name, version, indexes)?;
|
||||
|
||||
let delta = LazyRollingDeltasFromHeight::new(
|
||||
&format!("{name}_delta"),
|
||||
|
||||
@@ -7,7 +7,7 @@ use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode, UnaryTransform};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CentsSignedToDollars, CentsUnsignedToDollars, ComputedPerBlock, LazyPerBlock,
|
||||
CentsSignedToDollars, CentsUnsignedToDollars, PerBlock, LazyPerBlock,
|
||||
NumericValue,
|
||||
},
|
||||
};
|
||||
@@ -29,7 +29,7 @@ impl CentsType for CentsSigned {
|
||||
/// Generic over `C` to support both `Cents` (unsigned) and `CentsSigned` (signed).
|
||||
#[derive(Traversable)]
|
||||
pub struct FiatPerBlock<C: CentsType, M: StorageMode = Rw> {
|
||||
pub cents: ComputedPerBlock<C, M>,
|
||||
pub cents: PerBlock<C, M>,
|
||||
pub usd: LazyPerBlock<Dollars, C>,
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ impl<C: CentsType> FiatPerBlock<C> {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let cents =
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let usd = LazyPerBlock::from_computed::<C::ToDollars>(
|
||||
name,
|
||||
version,
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct FiatPerBlockCumulativeWithSums<C: CentsType, M: StorageMode = Rw> {
|
||||
pub raw: FiatPerBlock<C, M>,
|
||||
pub base: FiatPerBlock<C, M>,
|
||||
pub cumulative: FiatPerBlock<C, M>,
|
||||
pub sum: LazyRollingSumsFiatFromHeight<C>,
|
||||
}
|
||||
@@ -23,7 +23,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let raw = FiatPerBlock::forced_import(db, name, version, indexes)?;
|
||||
let base = FiatPerBlock::forced_import(db, name, version, indexes)?;
|
||||
let cumulative = FiatPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_cumulative"),
|
||||
@@ -37,7 +37,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
|
||||
cached_starts,
|
||||
indexes,
|
||||
);
|
||||
Ok(Self { raw, cumulative, sum })
|
||||
Ok(Self { base, cumulative, sum })
|
||||
}
|
||||
|
||||
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
|
||||
@@ -47,7 +47,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
|
||||
self.cumulative
|
||||
.cents
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.raw.cents.height, exit)?;
|
||||
.compute_cumulative(max_from, &self.base.cents.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Version};
|
||||
use vecdb::ReadableCloneableVec;
|
||||
|
||||
use crate::internal::{CentsType, ComputedPerBlock, Identity, LazyPerBlock, NumericValue};
|
||||
use crate::internal::{CentsType, PerBlock, Identity, LazyPerBlock, NumericValue};
|
||||
|
||||
/// Lazy fiat: both cents and usd are lazy views of a stored source.
|
||||
/// Zero extra stored vecs.
|
||||
@@ -16,7 +16,7 @@ impl<C: CentsType> LazyFiatPerBlock<C> {
|
||||
pub(crate) fn from_computed(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedPerBlock<C>,
|
||||
source: &PerBlock<C>,
|
||||
) -> Self
|
||||
where
|
||||
C: NumericValue,
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{LazyVecFrom1, ReadableBoxedVec, ReadableCloneableVec, UnaryTransform
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedPerBlock, ComputedVecValue, DerivedResolutions, NumericValue},
|
||||
internal::{PerBlock, ComputedVecValue, DerivedResolutions, NumericValue},
|
||||
};
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
@@ -31,7 +31,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: ReadableBoxedVec<Height, S1T>,
|
||||
source: &ComputedPerBlock<S1T>,
|
||||
source: &PerBlock<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
|
||||
@@ -10,7 +10,7 @@ use vecdb::{ReadableBoxedVec, ReadableCloneableVec, UnaryTransform, VecValue};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedPerBlock, Resolutions, ComputedVecValue, NumericValue, PerResolution,
|
||||
PerBlock, Resolutions, ComputedVecValue, NumericValue, PerResolution,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -50,7 +50,7 @@ where
|
||||
pub(crate) fn from_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedPerBlock<S1T>,
|
||||
source: &PerBlock<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
|
||||
@@ -7,10 +7,10 @@ use vecdb::{
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{BpsType, ComputeDrawdown},
|
||||
internal::{BpsType, algo::ComputeDrawdown},
|
||||
};
|
||||
|
||||
use crate::internal::{ComputedPerBlock, LazyPerBlock};
|
||||
use crate::internal::{PerBlock, LazyPerBlock};
|
||||
|
||||
/// Basis-point storage with both ratio and percentage float views.
|
||||
///
|
||||
@@ -20,7 +20,7 @@ use crate::internal::{ComputedPerBlock, LazyPerBlock};
|
||||
/// - `percent`: bps / 100 (e.g., 4523 bps -> 45.23%)
|
||||
#[derive(Traversable)]
|
||||
pub struct PercentPerBlock<B: BpsType, M: StorageMode = Rw> {
|
||||
pub bps: ComputedPerBlock<B, M>,
|
||||
pub bps: PerBlock<B, M>,
|
||||
pub ratio: LazyPerBlock<StoredF32, B>,
|
||||
pub percent: LazyPerBlock<StoredF32, B>,
|
||||
}
|
||||
@@ -32,7 +32,7 @@ impl<B: BpsType> PercentPerBlock<B> {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let bps = ComputedPerBlock::forced_import(db, &format!("{name}_bps"), version, indexes)?;
|
||||
let bps = PerBlock::forced_import(db, &format!("{name}_bps"), version, indexes)?;
|
||||
let bps_clone = bps.height.read_only_boxed_clone();
|
||||
|
||||
let ratio = LazyPerBlock::from_computed::<B::ToRatio>(
|
||||
|
||||
@@ -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 lazy;
|
||||
mod lazy_windows;
|
||||
mod rolling_average;
|
||||
mod windows;
|
||||
|
||||
pub use base::*;
|
||||
pub use lazy::*;
|
||||
pub use lazy_windows::*;
|
||||
pub use rolling_average::*;
|
||||
pub use windows::*;
|
||||
|
||||
@@ -8,12 +8,12 @@ use crate::{
|
||||
internal::{BpsType, CachedWindowStarts},
|
||||
};
|
||||
|
||||
use crate::internal::{ComputedPerBlockRollingAverage, LazyPerBlock};
|
||||
use crate::internal::{PerBlockRollingAverage, LazyPerBlock};
|
||||
|
||||
/// Like PercentPerBlock but with rolling average stats on the bps data.
|
||||
#[derive(Traversable)]
|
||||
pub struct PercentPerBlockRollingAverage<B: BpsType, M: StorageMode = Rw> {
|
||||
pub bps: ComputedPerBlockRollingAverage<B, M>,
|
||||
pub bps: PerBlockRollingAverage<B, M>,
|
||||
pub ratio: LazyPerBlock<StoredF32, B>,
|
||||
pub percent: LazyPerBlock<StoredF32, B>,
|
||||
}
|
||||
@@ -26,7 +26,7 @@ impl<B: BpsType> PercentPerBlockRollingAverage<B> {
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let bps = ComputedPerBlockRollingAverage::forced_import(
|
||||
let bps = PerBlockRollingAverage::forced_import(
|
||||
db,
|
||||
&format!("{name}_bps"),
|
||||
version,
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Cents, Height, Version};
|
||||
use vecdb::{AnyExportableVec, Database, ReadOnlyClone, Ro, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::indexes;
|
||||
use crate::internal::{ComputedPerBlock, Price};
|
||||
use crate::internal::{PerBlock, Price};
|
||||
|
||||
pub const PERCENTILES: [u8; 19] = [
|
||||
5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95,
|
||||
@@ -12,7 +12,7 @@ pub const PERCENTILES: [u8; 19] = [
|
||||
pub const PERCENTILES_LEN: usize = PERCENTILES.len();
|
||||
|
||||
pub struct PercentilesVecs<M: StorageMode = Rw> {
|
||||
pub vecs: [Price<ComputedPerBlock<Cents, M>>; PERCENTILES_LEN],
|
||||
pub vecs: [Price<PerBlock<Cents, M>>; PERCENTILES_LEN],
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE;
|
||||
@@ -73,7 +73,7 @@ impl ReadOnlyClone for PercentilesVecs {
|
||||
|
||||
impl<M: StorageMode> Traversable for PercentilesVecs<M>
|
||||
where
|
||||
Price<ComputedPerBlock<Cents, M>>: Traversable,
|
||||
Price<PerBlock<Cents, M>>: Traversable,
|
||||
{
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
|
||||
@@ -10,7 +10,7 @@ use brk_types::{Cents, Dollars, SatsFract, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, ReadableCloneableVec, UnaryTransform};
|
||||
|
||||
use super::{ComputedPerBlock, LazyPerBlock};
|
||||
use super::{PerBlock, LazyPerBlock};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CentsUnsignedToDollars, ComputedVecValue, DollarsToSatsFract, NumericValue},
|
||||
@@ -24,7 +24,7 @@ pub struct Price<C> {
|
||||
pub sats: LazyPerBlock<SatsFract, Dollars>,
|
||||
}
|
||||
|
||||
impl Price<ComputedPerBlock<Cents>> {
|
||||
impl Price<PerBlock<Cents>> {
|
||||
/// Import from database: stored cents, lazy USD + sats.
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
@@ -33,7 +33,7 @@ impl Price<ComputedPerBlock<Cents>> {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let cents =
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let usd = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||
name,
|
||||
version,
|
||||
@@ -57,7 +57,7 @@ where
|
||||
pub(crate) fn from_cents_source<F: UnaryTransform<ST, Cents>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedPerBlock<ST>,
|
||||
source: &PerBlock<ST>,
|
||||
) -> Self {
|
||||
let cents = LazyPerBlock::from_computed::<F>(
|
||||
&format!("{name}_cents"),
|
||||
|
||||
@@ -5,12 +5,12 @@ use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{BpsType, ComputedPerBlock, LazyPerBlock},
|
||||
internal::{BpsType, PerBlock, LazyPerBlock},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RatioPerBlock<B: BpsType = BasisPoints32, M: StorageMode = Rw> {
|
||||
pub bps: ComputedPerBlock<B, M>,
|
||||
pub bps: PerBlock<B, M>,
|
||||
pub ratio: LazyPerBlock<StoredF32, B>,
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ impl<B: BpsType> RatioPerBlock<B> {
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let bps = ComputedPerBlock::forced_import(db, &format!("{name}_bps"), v, indexes)?;
|
||||
let bps = PerBlock::forced_import(db, &format!("{name}_bps"), v, indexes)?;
|
||||
|
||||
let ratio = LazyPerBlock::from_computed::<B::ToRatio>(
|
||||
name,
|
||||
|
||||
@@ -8,16 +8,16 @@ use vecdb::{
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ExpandingPercentiles, Price, PriceTimesRatioBp32Cents},
|
||||
internal::{Price, PriceTimesRatioBp32Cents, algo::ExpandingPercentiles},
|
||||
};
|
||||
|
||||
use super::{super::ComputedPerBlock, RatioPerBlock};
|
||||
use super::{super::PerBlock, RatioPerBlock};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RatioBand<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub ratio: RatioPerBlock<BasisPoints32, M>,
|
||||
pub price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub price: Price<PerBlock<Cents, M>>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
|
||||
@@ -4,17 +4,17 @@ use brk_types::{BasisPoints32, Cents, Dollars, Height, Indexes, SatsFract, Store
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedPerBlock, LazyPerBlock, Price};
|
||||
use crate::internal::{PerBlock, LazyPerBlock, Price};
|
||||
use crate::{indexes, prices};
|
||||
|
||||
use super::{RatioPerBlock, RatioPerBlockPercentiles};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct PriceWithRatioPerBlock<M: StorageMode = Rw> {
|
||||
pub cents: ComputedPerBlock<Cents, M>,
|
||||
pub cents: PerBlock<Cents, M>,
|
||||
pub usd: LazyPerBlock<Dollars, Cents>,
|
||||
pub sats: LazyPerBlock<SatsFract, Dollars>,
|
||||
pub bps: ComputedPerBlock<BasisPoints32, M>,
|
||||
pub bps: PerBlock<BasisPoints32, M>,
|
||||
pub ratio: LazyPerBlock<StoredF32, BasisPoints32>,
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
//! RollingFull - Lazy rolling sums + stored rolling distribution per window.
|
||||
//! RollingComplete - Lazy rolling sums + stored rolling distribution per window.
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::{
|
||||
|
||||
/// Lazy rolling sums + stored rolling distribution (8 stats × 4 windows).
|
||||
#[derive(Traversable)]
|
||||
pub struct RollingFull<T, M: StorageMode = Rw>
|
||||
pub struct RollingComplete<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -26,7 +26,7 @@ where
|
||||
pub distribution: RollingDistribution<T, M>,
|
||||
}
|
||||
|
||||
impl<T> RollingFull<T>
|
||||
impl<T> RollingComplete<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedVecValue, DistributionStats, NumericValue, RollingWindows, WindowStarts,
|
||||
compute_rolling_distribution_from_starts,
|
||||
algo::compute_rolling_distribution_from_starts,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
+7
-9
@@ -1,22 +1,20 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::Version;
|
||||
use brk_types::{Height, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableCloneableVec, UnaryTransform};
|
||||
|
||||
use brk_types::Height;
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, ComputedVecValue, LazyRollingDistribution, LazyRollingSumsFromHeight,
|
||||
NumericValue, RollingFull,
|
||||
NumericValue, RollingComplete,
|
||||
},
|
||||
};
|
||||
|
||||
/// Lazy analog of `RollingFull<T>`: lazy rolling sums + lazy rolling distribution.
|
||||
/// Lazy analog of `RollingComplete<T>`: lazy rolling sums + lazy rolling distribution.
|
||||
/// Zero stored vecs.
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyRollingFull<T, S1T>
|
||||
pub struct LazyRollingComplete<T, S1T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -26,16 +24,16 @@ where
|
||||
pub distribution: LazyRollingDistribution<T, S1T>,
|
||||
}
|
||||
|
||||
impl<T, S1T> LazyRollingFull<T, S1T>
|
||||
impl<T, S1T> LazyRollingComplete<T, S1T>
|
||||
where
|
||||
T: NumericValue + JsonSchema + 'static,
|
||||
S1T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_rolling_full<F: UnaryTransform<S1T, T>>(
|
||||
pub(crate) fn from_rolling_complete<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
cumulative: &(impl ReadableCloneableVec<Height, T> + 'static),
|
||||
source: &RollingFull<S1T>,
|
||||
source: &RollingComplete<S1T>,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
@@ -2,9 +2,9 @@ mod avg;
|
||||
mod avgs;
|
||||
mod delta;
|
||||
mod distribution;
|
||||
mod full;
|
||||
mod complete;
|
||||
mod lazy_complete;
|
||||
mod lazy_distribution;
|
||||
mod lazy_full;
|
||||
mod sum;
|
||||
mod sums;
|
||||
mod windows;
|
||||
@@ -13,9 +13,9 @@ pub use avg::*;
|
||||
pub use avgs::*;
|
||||
pub use delta::*;
|
||||
pub use distribution::*;
|
||||
pub use full::*;
|
||||
pub use complete::*;
|
||||
pub use lazy_complete::*;
|
||||
pub use lazy_distribution::*;
|
||||
pub use lazy_full::*;
|
||||
pub use sum::*;
|
||||
pub use sums::*;
|
||||
pub use windows::*;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! RollingWindows - newtype on Windows with ComputedPerBlock per window duration.
|
||||
//! RollingWindows - newtype on Windows with PerBlock per window duration.
|
||||
//!
|
||||
//! Each of the 4 windows (24h, 1w, 1m, 1y) contains a height-level stored vec
|
||||
//! plus all 17 LazyAggVec index views.
|
||||
@@ -11,18 +11,25 @@ use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, EagerVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use vecdb::CachedVec;
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedPerBlock, ComputedVecValue, NumericValue, RollingWindow24h, Windows, WindowsFrom1w},
|
||||
internal::{PerBlock, ComputedVecValue, NumericValue, RollingWindow24h, Windows, WindowsFrom1w},
|
||||
};
|
||||
|
||||
/// 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>>);
|
||||
|
||||
/// Rolling window start heights — the 4 height-ago vecs (24h, 1w, 1m, 1y).
|
||||
pub type WindowStarts<'a> = Windows<&'a EagerVec<PcoVec<Height, Height>>>;
|
||||
|
||||
/// 4 rolling window vecs (24h, 1w, 1m, 1y), each with height data + all 17 index views.
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct RollingWindows<T, M: StorageMode = Rw>(pub Windows<ComputedPerBlock<T, M>>)
|
||||
pub struct RollingWindows<T, M: StorageMode = Rw>(pub Windows<PerBlock<T, M>>)
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema;
|
||||
|
||||
@@ -37,16 +44,16 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self(Windows::try_from_fn(|suffix| {
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||
PerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||
})?))
|
||||
}
|
||||
}
|
||||
|
||||
/// Single 24h rolling window backed by ComputedPerBlock (1 stored vec).
|
||||
/// Single 24h rolling window backed by PerBlock (1 stored vec).
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct RollingWindow24hPerBlock<T, M: StorageMode = Rw>(
|
||||
pub RollingWindow24h<ComputedPerBlock<T, M>>,
|
||||
pub RollingWindow24h<PerBlock<T, M>>,
|
||||
)
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema;
|
||||
@@ -62,7 +69,7 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self(RollingWindow24h {
|
||||
_24h: ComputedPerBlock::forced_import(
|
||||
_24h: PerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_24h"),
|
||||
version,
|
||||
@@ -75,7 +82,7 @@ where
|
||||
/// Extended rolling windows: 1w + 1m + 1y (3 stored vecs).
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct RollingWindowsFrom1w<T, M: StorageMode = Rw>(pub WindowsFrom1w<ComputedPerBlock<T, M>>)
|
||||
pub struct RollingWindowsFrom1w<T, M: StorageMode = Rw>(pub WindowsFrom1w<PerBlock<T, M>>)
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema;
|
||||
|
||||
@@ -90,7 +97,7 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self(WindowsFrom1w::try_from_fn(|suffix| {
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||
PerBlock::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||
})?))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Indexes, StoredF32, Version};
|
||||
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, indexes, internal::ComputedPerBlock};
|
||||
use crate::{blocks, indexes, internal::PerBlock};
|
||||
|
||||
use super::period_suffix;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct StdDevPerBlock<M: StorageMode = Rw> {
|
||||
days: usize,
|
||||
pub sma: ComputedPerBlock<StoredF32, M>,
|
||||
pub sd: ComputedPerBlock<StoredF32, M>,
|
||||
pub sma: PerBlock<StoredF32, M>,
|
||||
pub sd: PerBlock<StoredF32, M>,
|
||||
}
|
||||
|
||||
impl StdDevPerBlock {
|
||||
@@ -27,8 +27,8 @@ impl StdDevPerBlock {
|
||||
let p = period_suffix(period);
|
||||
|
||||
let sma =
|
||||
ComputedPerBlock::forced_import(db, &format!("{name}_sma{p}"), version, indexes)?;
|
||||
let sd = ComputedPerBlock::forced_import(db, &format!("{name}_sd{p}"), version, indexes)?;
|
||||
PerBlock::forced_import(db, &format!("{name}_sma{p}"), version, indexes)?;
|
||||
let sd = PerBlock::forced_import(db, &format!("{name}_sd{p}"), version, indexes)?;
|
||||
|
||||
Ok(Self { days, sma, sd })
|
||||
}
|
||||
|
||||
@@ -8,23 +8,23 @@ use vecdb::{
|
||||
|
||||
use crate::{
|
||||
blocks, indexes,
|
||||
internal::{ComputedPerBlock, Price, PriceTimesRatioCents},
|
||||
internal::{PerBlock, Price, PriceTimesRatioCents},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct StdDevBand<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub value: ComputedPerBlock<StoredF32, M>,
|
||||
pub price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub value: PerBlock<StoredF32, M>,
|
||||
pub price: Price<PerBlock<Cents, M>>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct StdDevPerBlockExtended<M: StorageMode = Rw> {
|
||||
days: usize,
|
||||
pub sd: ComputedPerBlock<StoredF32, M>,
|
||||
pub zscore: ComputedPerBlock<StoredF32, M>,
|
||||
pub sd: PerBlock<StoredF32, M>,
|
||||
pub zscore: PerBlock<StoredF32, M>,
|
||||
|
||||
pub _0sd: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub _0sd: Price<PerBlock<Cents, M>>,
|
||||
pub p0_5sd: StdDevBand<M>,
|
||||
pub p1sd: StdDevBand<M>,
|
||||
pub p1_5sd: StdDevBand<M>,
|
||||
@@ -53,7 +53,7 @@ impl StdDevPerBlockExtended {
|
||||
|
||||
macro_rules! import {
|
||||
($suffix:expr) => {
|
||||
ComputedPerBlock::forced_import(
|
||||
PerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_{}{p}", $suffix),
|
||||
version,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedPerTxDistribution - stored per-tx EagerVec + computed distribution.
|
||||
//! PerTxDistribution - stored per-tx EagerVec + computed distribution.
|
||||
//!
|
||||
//! Like LazyFromTxDistribution, but the per-tx source is eagerly computed
|
||||
//! and stored rather than lazily derived.
|
||||
@@ -16,7 +16,7 @@ use crate::{
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedPerTxDistribution<T, M: StorageMode = Rw>
|
||||
pub struct PerTxDistribution<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -25,7 +25,7 @@ where
|
||||
pub distribution: TxDerivedDistribution<T, M>,
|
||||
}
|
||||
|
||||
impl<T> ComputedPerTxDistribution<T>
|
||||
impl<T> PerTxDistribution<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ use crate::internal::{ComputedVecValue, LazyTxDerivedDistribution, TxDerivedDist
|
||||
/// Like `LazyPerTxDistribution` but with a lazy-derived distribution
|
||||
/// (transformed from another type's distribution rather than eagerly computed).
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyPerTxDistributionDerived<T, S1, S2, DSource>
|
||||
pub struct LazyPerTxDistributionTransformed<T, S1, S2, DSource>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema,
|
||||
S1: ComputedVecValue,
|
||||
@@ -20,7 +20,7 @@ where
|
||||
pub distribution: LazyTxDerivedDistribution<T, DSource>,
|
||||
}
|
||||
|
||||
impl<T, S1, S2, DSource> LazyPerTxDistributionDerived<T, S1, S2, DSource>
|
||||
impl<T, S1, S2, DSource> LazyPerTxDistributionTransformed<T, S1, S2, DSource>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1: ComputedVecValue + JsonSchema,
|
||||
@@ -2,10 +2,10 @@ mod derived;
|
||||
mod distribution;
|
||||
mod lazy_derived;
|
||||
mod lazy_distribution;
|
||||
mod lazy_distribution_derived;
|
||||
mod lazy_distribution_transformed;
|
||||
|
||||
pub use derived::*;
|
||||
pub use distribution::*;
|
||||
pub use lazy_derived::*;
|
||||
pub use lazy_distribution::*;
|
||||
pub use lazy_distribution_derived::*;
|
||||
pub use lazy_distribution_transformed::*;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Sats, StoredF32, StoredI8, StoredU16, StoredU32, StoredU64, VSize, Weight};
|
||||
use brk_types::{BasisPoints16, Bitcoin, Cents, Dollars, Sats, StoredF32, StoredF64, StoredI8, StoredU16, StoredU32, StoredU64, VSize, Weight};
|
||||
use vecdb::{BinaryTransform, UnaryTransform, VecValue};
|
||||
|
||||
pub struct Identity<T>(PhantomData<T>);
|
||||
@@ -88,6 +88,52 @@ impl<S, const V: i8> UnaryTransform<S, StoredI8> for ReturnI8<V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ThsToPhsF32;
|
||||
|
||||
impl UnaryTransform<StoredF32, StoredF32> for ThsToPhsF32 {
|
||||
#[inline(always)]
|
||||
fn apply(ths: StoredF32) -> StoredF32 {
|
||||
(*ths * 1000.0).into()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BlocksToDaysF32;
|
||||
|
||||
impl UnaryTransform<StoredU32, StoredF32> for BlocksToDaysF32 {
|
||||
#[inline(always)]
|
||||
fn apply(blocks: StoredU32) -> StoredF32 {
|
||||
(*blocks as f32 / crate::blocks::TARGET_BLOCKS_PER_DAY_F32).into()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OneMinusF64;
|
||||
|
||||
impl UnaryTransform<StoredF64, StoredF64> for OneMinusF64 {
|
||||
#[inline(always)]
|
||||
fn apply(v: StoredF64) -> StoredF64 {
|
||||
StoredF64::from(1.0 - *v)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DifficultyToHashF64;
|
||||
|
||||
impl UnaryTransform<StoredF64, StoredF64> for DifficultyToHashF64 {
|
||||
#[inline(always)]
|
||||
fn apply(difficulty: StoredF64) -> StoredF64 {
|
||||
const MULTIPLIER: f64 = 4_294_967_296.0 / 600.0; // 2^32 / 600
|
||||
StoredF64::from(*difficulty * MULTIPLIER)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OneMinusBp16;
|
||||
|
||||
impl UnaryTransform<BasisPoints16, BasisPoints16> for OneMinusBp16 {
|
||||
#[inline(always)]
|
||||
fn apply(v: BasisPoints16) -> BasisPoints16 {
|
||||
BasisPoints16::ONE - v
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VBytesToWeight;
|
||||
|
||||
impl UnaryTransform<StoredU64, Weight> for VBytesToWeight {
|
||||
|
||||
@@ -6,8 +6,9 @@ mod ratio;
|
||||
mod specialized;
|
||||
|
||||
pub use arithmetic::{
|
||||
HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin, Identity, MaskSats, ReturnF32Tenths,
|
||||
ReturnI8, ReturnU16, VBytesToWeight, VSizeToWeight,
|
||||
BlocksToDaysF32, DifficultyToHashF64, HalveCents, HalveDollars, HalveSats,
|
||||
HalveSatsToBitcoin, Identity, MaskSats, OneMinusBp16, OneMinusF64, ReturnF32Tenths, ReturnI8,
|
||||
ReturnU16, ThsToPhsF32, VBytesToWeight, VSizeToWeight,
|
||||
};
|
||||
pub use bps::{
|
||||
Bp16ToFloat, Bp16ToPercent, Bp32ToFloat, Bp32ToPercent, Bps16ToFloat, Bps16ToPercent, Bps32ToFloat,
|
||||
|
||||
Reference in New Issue
Block a user