mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-01 10:43:39 -07:00
global: snapshot
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
//! ComputedFromHeightAggregated - Full (distribution + sum + cumulative) + RollingFull.
|
||||
//!
|
||||
//! For metrics aggregated per-block from finer-grained sources (e.g., per-tx data),
|
||||
//! where we want full per-block stats plus rolling window stats.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{Full, NumericValue, RollingFull, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightAggregated<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
#[traversable(flatten)]
|
||||
pub full: Full<Height, T, M>,
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedFromHeightAggregated<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height = Full::forced_import(db, name, v)?;
|
||||
let rolling = RollingFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
full: height,
|
||||
rolling,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute Full stats via closure, then rolling windows 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<()>,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: From<f64> + Default + SubAssign + Copy + Ord,
|
||||
f64: From<T>,
|
||||
{
|
||||
compute_full(&mut self.full)?;
|
||||
self.rolling.compute(
|
||||
max_from,
|
||||
windows,
|
||||
self.full.sum_cumulative.sum.inner(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -13,11 +13,11 @@ use vecdb::{
|
||||
|
||||
use crate::indexes;
|
||||
|
||||
use crate::internal::{ComputedHeightDerivedLast, ComputedVecValue, NumericValue};
|
||||
use crate::internal::{ComputedHeightDerived, ComputedVecValue, NumericValue};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedFromHeightLast<T, M: StorageMode = Rw>
|
||||
pub struct ComputedFromHeight<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -25,12 +25,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<ComputedHeightDerivedLast<T>>,
|
||||
pub rest: Box<ComputedHeightDerived<T>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedFromHeightLast<T>
|
||||
impl<T> ComputedFromHeight<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -44,7 +44,7 @@ where
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
|
||||
let rest = ComputedHeightDerivedLast::forced_import(
|
||||
let rest = ComputedHeightDerived::forced_import(
|
||||
name,
|
||||
height.read_only_boxed_clone(),
|
||||
v,
|
||||
@@ -10,7 +10,7 @@ use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CentsUnsignedToDollars, ComputedFromHeightLast, LazyFromHeightLast, SatsToBitcoin,
|
||||
CentsUnsignedToDollars, ComputedFromHeight, LazyFromHeight, SatsToBitcoin,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -19,10 +19,10 @@ pub use rolling_sum::*;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ByUnit<M: StorageMode = Rw> {
|
||||
pub sats: ComputedFromHeightLast<Sats, M>,
|
||||
pub btc: LazyFromHeightLast<Bitcoin, Sats>,
|
||||
pub cents: ComputedFromHeightLast<Cents, M>,
|
||||
pub usd: LazyFromHeightLast<Dollars, Cents>,
|
||||
pub sats: ComputedFromHeight<Sats, M>,
|
||||
pub btc: LazyFromHeight<Bitcoin, Sats>,
|
||||
pub cents: ComputedFromHeight<Cents, M>,
|
||||
pub usd: LazyFromHeight<Dollars, Cents>,
|
||||
}
|
||||
|
||||
impl ByUnit {
|
||||
@@ -32,23 +32,23 @@ impl ByUnit {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let sats = ComputedFromHeightLast::forced_import(db, name, version, indexes)?;
|
||||
let sats = ComputedFromHeight::forced_import(db, name, version, indexes)?;
|
||||
|
||||
let btc = LazyFromHeightLast::from_computed::<SatsToBitcoin>(
|
||||
let btc = LazyFromHeight::from_computed::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
version,
|
||||
sats.height.read_only_boxed_clone(),
|
||||
&sats,
|
||||
);
|
||||
|
||||
let cents = ComputedFromHeightLast::forced_import(
|
||||
let cents = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_cents"),
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let usd = LazyFromHeightLast::from_computed::<CentsUnsignedToDollars>(
|
||||
let usd = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
cents.height.read_only_boxed_clone(),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! Like ComputedFromHeightCumulativeSum but without RollingWindows.
|
||||
//! Used for distribution metrics where rolling is optional per cohort.
|
||||
//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views.
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -12,7 +12,7 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, NumericValue},
|
||||
internal::{ComputedFromHeight, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -21,7 +21,7 @@ where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
@@ -40,7 +40,7 @@ where
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let cumulative =
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
|
||||
Ok(Self { height, cumulative })
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
//! ComputedFromHeightCumulativeFull - stored height + LazyAggVec + cumulative (from height) + RollingFull.
|
||||
//!
|
||||
//! For metrics with stored per-block data, cumulative sums, and rolling windows.
|
||||
//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, NumericValue, RollingFull, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightCumulativeFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedFromHeightCumulativeFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let cumulative =
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
let rolling = RollingFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
height,
|
||||
cumulative,
|
||||
rolling,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute height data via closure, then cumulative + rolling.
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
windows: &WindowStarts<'_>,
|
||||
exit: &Exit,
|
||||
compute_height: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: From<f64> + Default + SubAssign + Copy + Ord,
|
||||
f64: From<T>,
|
||||
{
|
||||
compute_height(&mut self.height)?;
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.height, exit)?;
|
||||
self.rolling
|
||||
.compute(max_from, windows, &self.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
//! ComputedFromHeightCumulativeSum - stored height + LazyAggVec + cumulative (from height) + RollingWindows (sum).
|
||||
//!
|
||||
//! Like ComputedFromHeightCumulativeFull but with rolling sum only (no distribution).
|
||||
//! Like ComputedFromHeightFull but with rolling sum only (no distribution).
|
||||
//! Used for count metrics where distribution stats aren't meaningful.
|
||||
//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views too.
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
@@ -14,7 +14,7 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, NumericValue, RollingWindows, WindowStarts},
|
||||
internal::{ComputedFromHeight, NumericValue, RollingWindows, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -23,7 +23,7 @@ where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
pub sum: RollingWindows<T, M>,
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ where
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let cumulative =
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
let rolling = RollingWindows::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Cents, CentsSigned, Dollars, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode, UnaryTransform};
|
||||
|
||||
use super::{ComputedFromHeightLast, LazyFromHeightLast};
|
||||
use super::{ComputedFromHeight, LazyFromHeight};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CentsSignedToDollars, CentsUnsignedToDollars, NumericValue},
|
||||
@@ -26,25 +26,25 @@ impl CentsType for CentsSigned {
|
||||
/// Height-indexed fiat monetary value: cents (eager, integer) + usd (lazy, float).
|
||||
/// Generic over `C` to support both `Cents` (unsigned) and `CentsSigned` (signed).
|
||||
#[derive(Traversable)]
|
||||
pub struct FiatFromHeightLast<C: CentsType, M: StorageMode = Rw> {
|
||||
pub cents: ComputedFromHeightLast<C, M>,
|
||||
pub usd: LazyFromHeightLast<Dollars, C>,
|
||||
pub struct FiatFromHeight<C: CentsType, M: StorageMode = Rw> {
|
||||
pub cents: ComputedFromHeight<C, M>,
|
||||
pub usd: LazyFromHeight<Dollars, C>,
|
||||
}
|
||||
|
||||
impl<C: CentsType> FiatFromHeightLast<C> {
|
||||
impl<C: CentsType> FiatFromHeight<C> {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let cents = ComputedFromHeightLast::forced_import(
|
||||
let cents = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_cents"),
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
let usd = LazyFromHeightLast::from_computed::<C::ToDollars>(
|
||||
let usd = LazyFromHeight::from_computed::<C::ToDollars>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
cents.height.read_only_boxed_clone(),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! ComputedFromHeightFull - Full (distribution + sum + cumulative) + RollingFull.
|
||||
//! ComputedFromHeightFull - stored height + LazyAggVec + cumulative (from height) + RollingFull.
|
||||
//!
|
||||
//! For metrics aggregated per-block from finer-grained sources (e.g., per-tx data),
|
||||
//! where we want full per-block stats plus rolling window stats.
|
||||
//! For metrics with stored per-block data, cumulative sums, and rolling windows.
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
@@ -9,11 +9,11 @@ use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{Full, NumericValue, RollingFull, WindowStarts},
|
||||
internal::{ComputedFromHeight, NumericValue, RollingFull, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -21,8 +21,9 @@ pub struct ComputedFromHeightFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub full: Full<Height, T, M>,
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
@@ -40,34 +41,36 @@ where
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height = Full::forced_import(db, name, v)?;
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let cumulative =
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
let rolling = RollingFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
full: height,
|
||||
height,
|
||||
cumulative,
|
||||
rolling,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute Full stats via closure, then rolling windows from the per-block sum.
|
||||
/// Compute height data via closure, then cumulative + rolling.
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
windows: &WindowStarts<'_>,
|
||||
exit: &Exit,
|
||||
compute_full: impl FnOnce(&mut Full<Height, T>) -> Result<()>,
|
||||
compute_height: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: From<f64> + Default + SubAssign + Copy + Ord,
|
||||
f64: From<T>,
|
||||
{
|
||||
compute_full(&mut self.full)?;
|
||||
self.rolling.compute(
|
||||
max_from,
|
||||
windows,
|
||||
self.full.sum_cumulative.sum.inner(),
|
||||
exit,
|
||||
)?;
|
||||
compute_height(&mut self.height)?;
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.height, exit)?;
|
||||
self.rolling
|
||||
.compute(max_from, windows, &self.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -8,11 +8,11 @@ use vecdb::{LazyVecFrom1, ReadableBoxedVec, ReadableCloneableVec, UnaryTransform
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, ComputedVecValue, LazyHeightDerivedLast, NumericValue},
|
||||
internal::{ComputedFromHeight, ComputedVecValue, LazyHeightDerived, NumericValue},
|
||||
};
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyFromHeightLast<T, S1T = T>
|
||||
pub struct LazyFromHeight<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -21,12 +21,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<LazyHeightDerivedLast<T, S1T>>,
|
||||
pub rest: Box<LazyHeightDerived<T, S1T>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyFromHeightLast<T, S1T>
|
||||
impl<T, S1T> LazyFromHeight<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -35,7 +35,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: ReadableBoxedVec<Height, S1T>,
|
||||
source: &ComputedFromHeightLast<S1T>,
|
||||
source: &ComputedFromHeight<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -43,7 +43,7 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: Box::new(LazyHeightDerivedLast::from_computed::<F>(name, v, source)),
|
||||
rest: Box::new(LazyHeightDerived::from_computed::<F>(name, v, source)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source.clone()),
|
||||
rest: Box::new(LazyHeightDerivedLast::from_height_source::<F>(
|
||||
rest: Box::new(LazyHeightDerived::from_height_source::<F>(
|
||||
name,
|
||||
v,
|
||||
height_source,
|
||||
@@ -68,11 +68,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Create by unary-transforming a LazyFromHeightLast source (chaining lazy vecs).
|
||||
/// Create by unary-transforming a LazyFromHeight source (chaining lazy vecs).
|
||||
pub(crate) fn from_lazy<F, S2T>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &LazyFromHeightLast<S1T, S2T>,
|
||||
source: &LazyFromHeight<S1T, S2T>,
|
||||
) -> Self
|
||||
where
|
||||
F: UnaryTransform<S1T, T>,
|
||||
@@ -81,7 +81,7 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, source.height.read_only_boxed_clone()),
|
||||
rest: Box::new(LazyHeightDerivedLast::from_lazy::<F, S2T>(
|
||||
rest: Box::new(LazyHeightDerived::from_lazy::<F, S2T>(
|
||||
name,
|
||||
v,
|
||||
&source.rest,
|
||||
@@ -1,43 +1,31 @@
|
||||
mod aggregated;
|
||||
mod base;
|
||||
mod by_unit;
|
||||
mod constant;
|
||||
mod cumulative;
|
||||
mod fiat;
|
||||
mod cumulative_full;
|
||||
mod cumulative_sum;
|
||||
mod distribution;
|
||||
mod fiat;
|
||||
mod full;
|
||||
mod last;
|
||||
mod value_cumulative;
|
||||
mod lazy_last;
|
||||
mod lazy_value_last;
|
||||
mod lazy_base;
|
||||
mod percentiles;
|
||||
mod price;
|
||||
mod ratio;
|
||||
mod stddev;
|
||||
mod value_change;
|
||||
mod value_full;
|
||||
mod value_last;
|
||||
mod value_last_rolling;
|
||||
mod value_sum_cumulative;
|
||||
mod value;
|
||||
|
||||
pub use aggregated::*;
|
||||
pub use base::*;
|
||||
pub use by_unit::*;
|
||||
pub use constant::*;
|
||||
pub use cumulative::*;
|
||||
pub use cumulative_full::*;
|
||||
pub use fiat::*;
|
||||
pub use cumulative_sum::*;
|
||||
pub use distribution::*;
|
||||
pub use fiat::*;
|
||||
pub use full::*;
|
||||
pub use last::*;
|
||||
pub use value_cumulative::*;
|
||||
pub use lazy_last::*;
|
||||
pub use lazy_value_last::*;
|
||||
pub use lazy_base::*;
|
||||
pub use percentiles::*;
|
||||
pub use price::*;
|
||||
pub use ratio::*;
|
||||
pub use stddev::*;
|
||||
pub use value_change::*;
|
||||
pub use value_full::*;
|
||||
pub use value_last::*;
|
||||
pub use value_last_rolling::*;
|
||||
pub use value_sum_cumulative::*;
|
||||
pub use value::*;
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Cents, Height, StoredF32, Version};
|
||||
use vecdb::{AnyExportableVec, Database, ReadOnlyClone, Ro, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::indexes;
|
||||
use crate::internal::{ComputedFromHeightLast, Price};
|
||||
use crate::internal::{ComputedFromHeight, 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,
|
||||
@@ -68,7 +68,7 @@ pub(crate) fn compute_spot_percentile_rank(
|
||||
}
|
||||
|
||||
pub struct PercentilesVecs<M: StorageMode = Rw> {
|
||||
pub vecs: [Price<ComputedFromHeightLast<Cents, M>>; PERCENTILES_LEN],
|
||||
pub vecs: [Price<ComputedFromHeight<Cents, M>>; PERCENTILES_LEN],
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE;
|
||||
@@ -130,7 +130,7 @@ impl ReadOnlyClone for PercentilesVecs {
|
||||
|
||||
impl<M: StorageMode> Traversable for PercentilesVecs<M>
|
||||
where
|
||||
Price<ComputedFromHeightLast<Cents, M>>: Traversable,
|
||||
Price<ComputedFromHeight<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::{ComputedFromHeightLast, LazyFromHeightLast};
|
||||
use super::{ComputedFromHeight, LazyFromHeight};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CentsUnsignedToDollars, ComputedVecValue, DollarsToSatsFract, NumericValue},
|
||||
@@ -20,11 +20,11 @@ use crate::{
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Price<C> {
|
||||
pub cents: C,
|
||||
pub usd: LazyFromHeightLast<Dollars, Cents>,
|
||||
pub sats: LazyFromHeightLast<SatsFract, Dollars>,
|
||||
pub usd: LazyFromHeight<Dollars, Cents>,
|
||||
pub sats: LazyFromHeight<SatsFract, Dollars>,
|
||||
}
|
||||
|
||||
impl Price<ComputedFromHeightLast<Cents>> {
|
||||
impl Price<ComputedFromHeight<Cents>> {
|
||||
/// Import from database: stored cents, lazy USD + sats.
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
@@ -33,14 +33,14 @@ impl Price<ComputedFromHeightLast<Cents>> {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let cents =
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let usd = LazyFromHeightLast::from_computed::<CentsUnsignedToDollars>(
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let usd = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
cents.height.read_only_boxed_clone(),
|
||||
¢s,
|
||||
);
|
||||
let sats = LazyFromHeightLast::from_lazy::<DollarsToSatsFract, Cents>(
|
||||
let sats = LazyFromHeight::from_lazy::<DollarsToSatsFract, Cents>(
|
||||
&format!("{name}_sats"),
|
||||
version,
|
||||
&usd,
|
||||
@@ -49,7 +49,7 @@ impl Price<ComputedFromHeightLast<Cents>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<ST> Price<LazyFromHeightLast<Cents, ST>>
|
||||
impl<ST> Price<LazyFromHeight<Cents, ST>>
|
||||
where
|
||||
ST: ComputedVecValue + NumericValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -57,20 +57,20 @@ where
|
||||
pub(crate) fn from_cents_source<F: UnaryTransform<ST, Cents>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedFromHeightLast<ST>,
|
||||
source: &ComputedFromHeight<ST>,
|
||||
) -> Self {
|
||||
let cents = LazyFromHeightLast::from_computed::<F>(
|
||||
let cents = LazyFromHeight::from_computed::<F>(
|
||||
&format!("{name}_cents"),
|
||||
version,
|
||||
source.height.read_only_boxed_clone(),
|
||||
source,
|
||||
);
|
||||
let usd = LazyFromHeightLast::from_lazy::<CentsUnsignedToDollars, ST>(
|
||||
let usd = LazyFromHeight::from_lazy::<CentsUnsignedToDollars, ST>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
¢s,
|
||||
);
|
||||
let sats = LazyFromHeightLast::from_lazy::<DollarsToSatsFract, Cents>(
|
||||
let sats = LazyFromHeight::from_lazy::<DollarsToSatsFract, Cents>(
|
||||
&format!("{name}_sats"),
|
||||
version,
|
||||
&usd,
|
||||
|
||||
@@ -9,24 +9,24 @@ use crate::{
|
||||
};
|
||||
use brk_types::get_percentile;
|
||||
|
||||
use super::super::ComputedFromHeightLast;
|
||||
use super::super::ComputedFromHeight;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightRatioExtension<M: StorageMode = Rw> {
|
||||
pub ratio_1w_sma: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_1m_sma: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct99: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct98: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct95: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct5: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct2: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct1: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct99_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_pct98_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_pct95_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_pct5_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_pct2_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_pct1_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_1w_sma: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_1m_sma: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct99: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct98: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct95: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct5: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct2: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct1: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct99_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub ratio_pct98_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub ratio_pct95_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub ratio_pct5_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub ratio_pct2_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub ratio_pct1_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
|
||||
pub ratio_sd: ComputedFromHeightStdDevExtended<M>,
|
||||
pub ratio_4y_sd: ComputedFromHeightStdDevExtended<M>,
|
||||
@@ -47,7 +47,7 @@ impl ComputedFromHeightRatioExtension {
|
||||
|
||||
macro_rules! import {
|
||||
($suffix:expr) => {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_{}", $suffix),
|
||||
v,
|
||||
|
||||
@@ -13,11 +13,11 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use super::ComputedFromHeightLast;
|
||||
use super::ComputedFromHeight;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightRatio<M: StorageMode = Rw> {
|
||||
pub ratio: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::TWO;
|
||||
@@ -32,7 +32,7 @@ impl ComputedFromHeightRatio {
|
||||
let v = version + VERSION;
|
||||
|
||||
Ok(Self {
|
||||
ratio: ComputedFromHeightLast::forced_import(db, &format!("{name}_ratio"), v, indexes)?,
|
||||
ratio: ComputedFromHeight::forced_import(db, &format!("{name}_ratio"), v, indexes)?,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Cents, Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, Price};
|
||||
use crate::internal::{ComputedFromHeight, Price};
|
||||
use crate::{ComputeIndexes, blocks, indexes, prices};
|
||||
|
||||
use super::ComputedFromHeightRatioExtended;
|
||||
@@ -15,7 +15,7 @@ pub struct ComputedFromHeightPriceWithRatioExtended<M: StorageMode = Rw> {
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub inner: ComputedFromHeightRatioExtended<M>,
|
||||
pub price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub price: Price<ComputedFromHeight<Cents, M>>,
|
||||
}
|
||||
|
||||
impl ComputedFromHeightPriceWithRatioExtended {
|
||||
|
||||
@@ -8,7 +8,7 @@ use vecdb::{
|
||||
|
||||
use crate::{ComputeIndexes, blocks, indexes};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, Price};
|
||||
use crate::internal::{ComputedFromHeight, Price};
|
||||
|
||||
use super::ComputedFromHeightStdDev;
|
||||
|
||||
@@ -17,34 +17,34 @@ pub struct ComputedFromHeightStdDevExtended<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub base: ComputedFromHeightStdDev<M>,
|
||||
|
||||
pub zscore: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub zscore: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
pub p0_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p1sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p1_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p2sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p2_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p3sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m0_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m1sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m1_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m2sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m2_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m3sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p0_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub p1sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub p1_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub p2sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub p2_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub p3sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m0_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m1sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m1_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m2sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m2_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m3sd: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
pub _0sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p0_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p1sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p1_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p2sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p2_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p3sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m0_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m1sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m1_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m2sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m2_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m3sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub _0sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p0_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p1sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p1_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p2sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p2_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p3sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m0_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m1sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m1_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m2sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m2_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m3sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
}
|
||||
|
||||
impl ComputedFromHeightStdDevExtended {
|
||||
@@ -59,7 +59,7 @@ impl ComputedFromHeightStdDevExtended {
|
||||
|
||||
macro_rules! import {
|
||||
($suffix:expr) => {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_{}", $suffix),
|
||||
version,
|
||||
|
||||
@@ -9,13 +9,13 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Rw, StorageMode,
|
||||
|
||||
use crate::{ComputeIndexes, blocks, indexes};
|
||||
|
||||
use crate::internal::ComputedFromHeightLast;
|
||||
use crate::internal::ComputedFromHeight;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightStdDev<M: StorageMode = Rw> {
|
||||
days: usize,
|
||||
pub sma: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sma: ComputedFromHeight<StoredF32, M>,
|
||||
pub sd: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
impl ComputedFromHeightStdDev {
|
||||
@@ -28,13 +28,13 @@ impl ComputedFromHeightStdDev {
|
||||
) -> Result<Self> {
|
||||
let version = parent_version + Version::TWO;
|
||||
|
||||
let sma = ComputedFromHeightLast::forced_import(
|
||||
let sma = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_sma"),
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
let sd = ComputedFromHeightLast::forced_import(
|
||||
let sd = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_sd"),
|
||||
version,
|
||||
@@ -84,7 +84,7 @@ impl ComputedFromHeightStdDev {
|
||||
}
|
||||
|
||||
fn compute_sd(
|
||||
sd: &mut ComputedFromHeightLast<StoredF32>,
|
||||
sd: &mut ComputedFromHeight<StoredF32>,
|
||||
blocks: &blocks::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ use crate::{
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct ValueFromHeightLast<M: StorageMode = Rw> {
|
||||
pub struct ValueFromHeight<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub base: ByUnit<M>,
|
||||
@@ -19,7 +19,7 @@ pub struct ValueFromHeightLast<M: StorageMode = Rw> {
|
||||
|
||||
const VERSION: Version = Version::TWO;
|
||||
|
||||
impl ValueFromHeightLast {
|
||||
impl ValueFromHeight {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
+9
-9
@@ -8,7 +8,7 @@ use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CentsSignedToDollars, ComputedFromHeightLast, LazyFromHeightLast, SatsSignedToBitcoin,
|
||||
CentsSignedToDollars, ComputedFromHeight, LazyFromHeight, SatsSignedToBitcoin,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -17,10 +17,10 @@ const VERSION: Version = Version::ZERO;
|
||||
/// Change values indexed by height - sats (stored), btc (lazy), cents (stored), usd (lazy).
|
||||
#[derive(Traversable)]
|
||||
pub struct ValueFromHeightChange<M: StorageMode = Rw> {
|
||||
pub sats: ComputedFromHeightLast<SatsSigned, M>,
|
||||
pub btc: LazyFromHeightLast<Bitcoin, SatsSigned>,
|
||||
pub cents: ComputedFromHeightLast<CentsSigned, M>,
|
||||
pub usd: LazyFromHeightLast<Dollars, CentsSigned>,
|
||||
pub sats: ComputedFromHeight<SatsSigned, M>,
|
||||
pub btc: LazyFromHeight<Bitcoin, SatsSigned>,
|
||||
pub cents: ComputedFromHeight<CentsSigned, M>,
|
||||
pub usd: LazyFromHeight<Dollars, CentsSigned>,
|
||||
}
|
||||
|
||||
impl ValueFromHeightChange {
|
||||
@@ -32,23 +32,23 @@ impl ValueFromHeightChange {
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = ComputedFromHeightLast::forced_import(db, name, v, indexes)?;
|
||||
let sats = ComputedFromHeight::forced_import(db, name, v, indexes)?;
|
||||
|
||||
let btc = LazyFromHeightLast::from_computed::<SatsSignedToBitcoin>(
|
||||
let btc = LazyFromHeight::from_computed::<SatsSignedToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats.height.read_only_boxed_clone(),
|
||||
&sats,
|
||||
);
|
||||
|
||||
let cents = ComputedFromHeightLast::forced_import(
|
||||
let cents = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_cents"),
|
||||
v,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let usd = LazyFromHeightLast::from_computed::<CentsSignedToDollars>(
|
||||
let usd = LazyFromHeight::from_computed::<CentsSignedToDollars>(
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
cents.height.read_only_boxed_clone(),
|
||||
+2
-2
@@ -10,7 +10,7 @@ use crate::{
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ValueFromHeightSumCumulative<M: StorageMode = Rw> {
|
||||
pub struct ValueFromHeightCumulativeSum<M: StorageMode = Rw> {
|
||||
pub base: ByUnit<M>,
|
||||
pub cumulative: ByUnit<M>,
|
||||
pub sum: RollingSumByUnit<M>,
|
||||
@@ -18,7 +18,7 @@ pub struct ValueFromHeightSumCumulative<M: StorageMode = Rw> {
|
||||
|
||||
const VERSION: Version = Version::TWO;
|
||||
|
||||
impl ValueFromHeightSumCumulative {
|
||||
impl ValueFromHeightCumulativeSum {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
+13
-12
@@ -1,44 +1,45 @@
|
||||
//! Lazy value wrapper for ValueFromHeightLast - all transforms are lazy.
|
||||
//! Lazy value wrapper for ValueFromHeight - all transforms are lazy.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Sats, Version};
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
use crate::internal::{LazyValueFromHeight, LazyValueHeightDerivedLast, ValueFromHeightLast};
|
||||
use crate::internal::{LazyValue, LazyValueHeightDerived, ValueFromHeight};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
/// Lazy value wrapper with height + all derived last transforms from ValueFromHeightLast.
|
||||
/// Lazy value wrapper with height + all derived last transforms from ValueFromHeight.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyValueFromHeightLast {
|
||||
pub struct LazyValueFromHeight {
|
||||
#[traversable(flatten)]
|
||||
pub height: LazyValueFromHeight,
|
||||
pub height: LazyValue<Height>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<LazyValueHeightDerivedLast>,
|
||||
pub rest: Box<LazyValueHeightDerived>,
|
||||
}
|
||||
|
||||
impl LazyValueFromHeightLast {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
impl LazyValueFromHeight {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, CentsTransform, DollarsTransform>(
|
||||
name: &str,
|
||||
source: &ValueFromHeightLast,
|
||||
source: &ValueFromHeight,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
SatsTransform: UnaryTransform<Sats, Sats>,
|
||||
BitcoinTransform: UnaryTransform<Sats, Bitcoin>,
|
||||
CentsTransform: UnaryTransform<Cents, Cents>,
|
||||
DollarsTransform: UnaryTransform<Dollars, Dollars>,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
let height =
|
||||
LazyValueFromHeight::from_block_source::<SatsTransform, BitcoinTransform, DollarsTransform>(name, source, v);
|
||||
LazyValue::from_block_source::<SatsTransform, BitcoinTransform, CentsTransform, DollarsTransform>(name, source, v);
|
||||
|
||||
let rest =
|
||||
LazyValueHeightDerivedLast::from_block_source::<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
LazyValueHeightDerived::from_block_source::<SatsTransform, BitcoinTransform, CentsTransform, DollarsTransform>(
|
||||
name, source, v,
|
||||
);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
mod base;
|
||||
mod change;
|
||||
mod cumulative;
|
||||
mod cumulative_sum;
|
||||
mod full;
|
||||
mod lazy;
|
||||
mod rolling;
|
||||
|
||||
pub use base::*;
|
||||
pub use change::*;
|
||||
pub use cumulative::*;
|
||||
pub use cumulative_sum::*;
|
||||
pub use full::*;
|
||||
pub use lazy::*;
|
||||
pub use rolling::*;
|
||||
+9
-9
@@ -1,7 +1,7 @@
|
||||
//! Value type for Height + Rolling pattern.
|
||||
//!
|
||||
//! Combines ValueFromHeight (sats/btc/usd per height, no period views) with
|
||||
//! ValueFromHeightLastWindows (rolling sums across 4 windows).
|
||||
//! Combines Value (sats/btc/usd per height, no period views) with
|
||||
//! ValueFromHeightWindows (rolling sums across 4 windows).
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -11,23 +11,23 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ValueFromHeightLastWindows, ValueFromHeight, WindowStarts},
|
||||
internal::{ValueFromHeightWindows, Value, WindowStarts},
|
||||
prices,
|
||||
};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct ValueFromHeightLastRolling<M: StorageMode = Rw> {
|
||||
pub struct ValueFromHeightRolling<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub value: ValueFromHeight<M>,
|
||||
pub value: Value<Height, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: ValueFromHeightLastWindows<M>,
|
||||
pub rolling: ValueFromHeightWindows<M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl ValueFromHeightLastRolling {
|
||||
impl ValueFromHeightRolling {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -36,8 +36,8 @@ impl ValueFromHeightLastRolling {
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
Ok(Self {
|
||||
value: ValueFromHeight::forced_import(db, name, v)?,
|
||||
rolling: ValueFromHeightLastWindows::forced_import(db, name, v, indexes)?,
|
||||
value: Value::forced_import(db, name, v)?,
|
||||
rolling: ValueFromHeightWindows::forced_import(db, name, v, indexes)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
mod lazy_value;
|
||||
mod value;
|
||||
|
||||
pub use lazy_value::*;
|
||||
pub use value::*;
|
||||
+7
-7
@@ -1,7 +1,7 @@
|
||||
//! ComputedHeightDerivedCumulativeFull - LazyAggVec index views + cumulative (from height) + RollingFull.
|
||||
//! ComputedHeightDerivedFull - LazyAggVec index views + cumulative (from height) + RollingFull.
|
||||
//!
|
||||
//! For metrics derived from indexer sources (no stored height vec).
|
||||
//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views too.
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
@@ -13,22 +13,22 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, NumericValue, RollingFull, WindowStarts},
|
||||
internal::{ComputedFromHeight, NumericValue, RollingFull, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedHeightDerivedCumulativeFull<T, M: StorageMode = Rw>
|
||||
pub struct ComputedHeightDerivedFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDerivedCumulativeFull<T>
|
||||
impl<T> ComputedHeightDerivedFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -41,7 +41,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
let cumulative =
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
let rolling = RollingFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedHeightDerivedLast — sparse time periods + dense epochs (last value).
|
||||
//! ComputedHeightDerived — sparse time periods + dense epochs (last value).
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
@@ -18,7 +18,7 @@ use crate::{
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct ComputedHeightDerivedLast<T>(
|
||||
pub struct ComputedHeightDerived<T>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub Indexes<
|
||||
LazyAggVec<Minute10, Option<T>, Height, Height, T>,
|
||||
@@ -42,7 +42,7 @@ where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema;
|
||||
|
||||
/// Already read-only (no StorageMode); cloning is sufficient.
|
||||
impl<T> ReadOnlyClone for ComputedHeightDerivedLast<T>
|
||||
impl<T> ReadOnlyClone for ComputedHeightDerived<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -54,7 +54,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDerivedLast<T>
|
||||
impl<T> ComputedHeightDerived<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! LazyHeightDerivedLast — unary transform of height-derived last values.
|
||||
//! LazyHeightDerived — unary transform of height-derived last values.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
@@ -16,7 +16,7 @@ use vecdb::{
|
||||
use crate::{
|
||||
indexes, indexes_from,
|
||||
internal::{
|
||||
ComputedFromHeightLast, ComputedHeightDerivedLast, ComputedVecValue, Indexes, NumericValue,
|
||||
ComputedFromHeight, ComputedHeightDerived, ComputedVecValue, Indexes, NumericValue,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -57,7 +57,7 @@ where
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct LazyHeightDerivedLast<T, S1T = T>(
|
||||
pub struct LazyHeightDerived<T, S1T = T>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub Indexes<
|
||||
LazyTransformLast<Minute10, Option<T>, Option<S1T>>,
|
||||
@@ -83,7 +83,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyHeightDerivedLast<T, S1T>
|
||||
impl<T, S1T> LazyHeightDerived<T, S1T>
|
||||
where
|
||||
T: VecValue + PartialOrd + JsonSchema + 'static,
|
||||
S1T: VecValue + PartialOrd + JsonSchema,
|
||||
@@ -91,7 +91,7 @@ where
|
||||
pub(crate) fn from_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedFromHeightLast<S1T>,
|
||||
source: &ComputedFromHeight<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -109,14 +109,14 @@ where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
let derived =
|
||||
ComputedHeightDerivedLast::forced_import(name, height_source, version, indexes);
|
||||
ComputedHeightDerived::forced_import(name, height_source, version, indexes);
|
||||
Self::from_derived_computed::<F>(name, version, &derived)
|
||||
}
|
||||
|
||||
pub(crate) fn from_derived_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedHeightDerivedLast<S1T>,
|
||||
source: &ComputedHeightDerived<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -145,7 +145,7 @@ where
|
||||
pub(crate) fn from_lazy<F, S2T>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &LazyHeightDerivedLast<S1T, S2T>,
|
||||
source: &LazyHeightDerived<S1T, S2T>,
|
||||
) -> Self
|
||||
where
|
||||
F: UnaryTransform<S1T, T>,
|
||||
|
||||
@@ -4,48 +4,56 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Sats, Version};
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
use crate::internal::{LazyHeightDerivedLast, ValueFromHeightLast};
|
||||
use crate::internal::{LazyHeightDerived, ValueFromHeight};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyValueHeightDerivedLast {
|
||||
pub sats: LazyHeightDerivedLast<Sats, Sats>,
|
||||
pub btc: LazyHeightDerivedLast<Bitcoin, Sats>,
|
||||
pub usd: LazyHeightDerivedLast<Dollars, Dollars>,
|
||||
pub struct LazyValueHeightDerived {
|
||||
pub sats: LazyHeightDerived<Sats, Sats>,
|
||||
pub btc: LazyHeightDerived<Bitcoin, Sats>,
|
||||
pub cents: LazyHeightDerived<Cents, Cents>,
|
||||
pub usd: LazyHeightDerived<Dollars, Dollars>,
|
||||
}
|
||||
|
||||
impl LazyValueHeightDerivedLast {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
impl LazyValueHeightDerived {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, CentsTransform, DollarsTransform>(
|
||||
name: &str,
|
||||
source: &ValueFromHeightLast,
|
||||
source: &ValueFromHeight,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
SatsTransform: UnaryTransform<Sats, Sats>,
|
||||
BitcoinTransform: UnaryTransform<Sats, Bitcoin>,
|
||||
CentsTransform: UnaryTransform<Cents, Cents>,
|
||||
DollarsTransform: UnaryTransform<Dollars, Dollars>,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = LazyHeightDerivedLast::from_derived_computed::<SatsTransform>(
|
||||
let sats = LazyHeightDerived::from_derived_computed::<SatsTransform>(
|
||||
name,
|
||||
v,
|
||||
&source.sats.rest,
|
||||
);
|
||||
|
||||
let btc = LazyHeightDerivedLast::from_derived_computed::<BitcoinTransform>(
|
||||
let btc = LazyHeightDerived::from_derived_computed::<BitcoinTransform>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
&source.sats.rest,
|
||||
);
|
||||
|
||||
let usd = LazyHeightDerivedLast::from_lazy::<DollarsTransform, Cents>(
|
||||
let cents = LazyHeightDerived::from_derived_computed::<CentsTransform>(
|
||||
&format!("{name}_cents"),
|
||||
v,
|
||||
&source.cents.rest,
|
||||
);
|
||||
|
||||
let usd = LazyHeightDerived::from_lazy::<DollarsTransform, Cents>(
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
&source.usd.rest,
|
||||
);
|
||||
|
||||
Self { sats, btc, usd }
|
||||
Self { sats, btc, cents, usd }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
mod cumulative_full;
|
||||
mod full;
|
||||
mod last;
|
||||
mod lazy_last;
|
||||
mod lazy_value_last;
|
||||
|
||||
pub use cumulative_full::*;
|
||||
pub use full::*;
|
||||
pub use last::*;
|
||||
pub use lazy_last::*;
|
||||
pub use lazy_value_last::*;
|
||||
|
||||
+20
-12
@@ -1,10 +1,10 @@
|
||||
//! Fully lazy value type for Height indexing.
|
||||
//! Fully lazy value type.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Height, Sats, Version};
|
||||
use vecdb::{ReadableCloneableVec, LazyVecFrom1, UnaryTransform};
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
|
||||
use vecdb::{ReadableCloneableVec, LazyVecFrom1, UnaryTransform, VecIndex};
|
||||
|
||||
use crate::internal::ValueFromHeightLast;
|
||||
use crate::internal::ValueFromHeight;
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
@@ -12,21 +12,23 @@ const VERSION: Version = Version::ZERO;
|
||||
///
|
||||
/// All fields are lazy transforms from existing sources - no storage.
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyValueFromHeight {
|
||||
pub sats: LazyVecFrom1<Height, Sats, Height, Sats>,
|
||||
pub btc: LazyVecFrom1<Height, Bitcoin, Height, Sats>,
|
||||
pub usd: LazyVecFrom1<Height, Dollars, Height, Dollars>,
|
||||
pub struct LazyValue<I: VecIndex> {
|
||||
pub sats: LazyVecFrom1<I, Sats, I, Sats>,
|
||||
pub btc: LazyVecFrom1<I, Bitcoin, I, Sats>,
|
||||
pub cents: LazyVecFrom1<I, Cents, I, Cents>,
|
||||
pub usd: LazyVecFrom1<I, Dollars, I, Dollars>,
|
||||
}
|
||||
|
||||
impl LazyValueFromHeight {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
impl LazyValue<Height> {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, CentsTransform, DollarsTransform>(
|
||||
name: &str,
|
||||
source: &ValueFromHeightLast,
|
||||
source: &ValueFromHeight,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
SatsTransform: UnaryTransform<Sats, Sats>,
|
||||
BitcoinTransform: UnaryTransform<Sats, Bitcoin>,
|
||||
CentsTransform: UnaryTransform<Cents, Cents>,
|
||||
DollarsTransform: UnaryTransform<Dollars, Dollars>,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
@@ -40,12 +42,18 @@ impl LazyValueFromHeight {
|
||||
source.sats.height.read_only_boxed_clone(),
|
||||
);
|
||||
|
||||
let cents = LazyVecFrom1::transformed::<CentsTransform>(
|
||||
&format!("{name}_cents"),
|
||||
v,
|
||||
source.cents.height.read_only_boxed_clone(),
|
||||
);
|
||||
|
||||
let usd = LazyVecFrom1::transformed::<DollarsTransform>(
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
source.usd.height.read_only_boxed_clone(),
|
||||
);
|
||||
|
||||
Self { sats, btc, usd }
|
||||
Self { sats, btc, cents, usd }
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,16 @@ mod eager_indexes;
|
||||
mod from_height;
|
||||
mod from_tx;
|
||||
mod group;
|
||||
mod height;
|
||||
mod height_derived;
|
||||
mod indexes;
|
||||
mod lazy_eager_indexes;
|
||||
mod lazy_value;
|
||||
mod rolling;
|
||||
pub(crate) mod sliding_window;
|
||||
mod traits;
|
||||
mod transform;
|
||||
mod tx_derived;
|
||||
mod value;
|
||||
mod vec;
|
||||
mod windows;
|
||||
|
||||
@@ -22,13 +23,14 @@ pub(crate) use eager_indexes::*;
|
||||
pub(crate) use from_height::*;
|
||||
pub(crate) use from_tx::*;
|
||||
pub(crate) use group::*;
|
||||
pub(crate) use height::*;
|
||||
pub(crate) use height_derived::*;
|
||||
pub(crate) use indexes::*;
|
||||
pub(crate) use lazy_eager_indexes::*;
|
||||
pub(crate) use lazy_value::*;
|
||||
pub(crate) use rolling::*;
|
||||
pub(crate) use traits::*;
|
||||
pub use transform::*;
|
||||
pub(crate) use tx_derived::*;
|
||||
pub(crate) use value::*;
|
||||
pub(crate) use vec::*;
|
||||
pub(crate) use windows::*;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ValueFromHeightLastWindows - window-first ordering.
|
||||
//! ValueFromHeightWindows - window-first ordering.
|
||||
//!
|
||||
//! Access pattern: `coinbase_sum._24h.sats.height`
|
||||
//! Each window (24h, 7d, 30d, 1y) contains sats (stored) + btc (lazy) + usd (stored).
|
||||
@@ -14,21 +14,21 @@ use brk_types::{Cents, Sats};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ValueFromHeightLast, WindowStarts, Windows},
|
||||
internal::{ValueFromHeight, WindowStarts, Windows},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
/// Value rolling windows — window-first, currency-last.
|
||||
///
|
||||
/// Each window contains `ValueFromHeightLast` (sats + btc lazy + usd).
|
||||
/// Each window contains `ValueFromHeight` (sats + btc lazy + usd).
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct ValueFromHeightLastWindows<M: StorageMode = Rw>(
|
||||
pub Windows<ValueFromHeightLast<M>>,
|
||||
pub struct ValueFromHeightWindows<M: StorageMode = Rw>(
|
||||
pub Windows<ValueFromHeight<M>>,
|
||||
);
|
||||
|
||||
impl ValueFromHeightLastWindows {
|
||||
impl ValueFromHeightWindows {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -37,25 +37,25 @@ impl ValueFromHeightLastWindows {
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
Ok(Self(Windows {
|
||||
_24h: ValueFromHeightLast::forced_import(
|
||||
_24h: ValueFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_24h"),
|
||||
v,
|
||||
indexes,
|
||||
)?,
|
||||
_7d: ValueFromHeightLast::forced_import(
|
||||
_7d: ValueFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_7d"),
|
||||
v,
|
||||
indexes,
|
||||
)?,
|
||||
_30d: ValueFromHeightLast::forced_import(
|
||||
_30d: ValueFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_30d"),
|
||||
v,
|
||||
indexes,
|
||||
)?,
|
||||
_1y: ValueFromHeightLast::forced_import(
|
||||
_1y: ValueFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_1y"),
|
||||
v,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! RollingWindows - newtype on Windows with ComputedFromHeightLast per window duration.
|
||||
//! RollingWindows - newtype on Windows with ComputedFromHeight per window duration.
|
||||
//!
|
||||
//! Each of the 4 windows (24h, 7d, 30d, 1y) contains a height-level stored vec
|
||||
//! plus all 17 LazyAggVec index views.
|
||||
@@ -15,7 +15,7 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, ComputedVecValue, NumericValue, Windows},
|
||||
internal::{ComputedFromHeight, ComputedVecValue, NumericValue, Windows},
|
||||
};
|
||||
|
||||
/// Rolling window start heights — references to the 4 height-ago vecs.
|
||||
@@ -35,7 +35,7 @@ impl<'a> WindowStarts<'a> {
|
||||
/// 4 rolling window vecs (24h, 7d, 30d, 1y), each with height data + all 17 index views.
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct RollingWindows<T, M: StorageMode = Rw>(pub Windows<ComputedFromHeightLast<T, M>>)
|
||||
pub struct RollingWindows<T, M: StorageMode = Rw>(pub Windows<ComputedFromHeight<T, M>>)
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema;
|
||||
|
||||
@@ -53,10 +53,10 @@ where
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
Ok(Self(Windows {
|
||||
_24h: ComputedFromHeightLast::forced_import(db, &format!("{name}_24h"), v, indexes)?,
|
||||
_7d: ComputedFromHeightLast::forced_import(db, &format!("{name}_7d"), v, indexes)?,
|
||||
_30d: ComputedFromHeightLast::forced_import(db, &format!("{name}_30d"), v, indexes)?,
|
||||
_1y: ComputedFromHeightLast::forced_import(db, &format!("{name}_1y"), v, indexes)?,
|
||||
_24h: ComputedFromHeight::forced_import(db, &format!("{name}_24h"), v, indexes)?,
|
||||
_7d: ComputedFromHeight::forced_import(db, &format!("{name}_7d"), v, indexes)?,
|
||||
_30d: ComputedFromHeight::forced_import(db, &format!("{name}_30d"), v, indexes)?,
|
||||
_1y: ComputedFromHeight::forced_import(db, &format!("{name}_1y"), v, indexes)?,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
use brk_types::Cents;
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
/// Cents -> Cents/2 (for supply_halved_cents)
|
||||
pub struct HalveCents;
|
||||
|
||||
impl UnaryTransform<Cents, Cents> for HalveCents {
|
||||
#[inline(always)]
|
||||
fn apply(cents: Cents) -> Cents {
|
||||
cents / 2u64
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use brk_types::Cents;
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
/// Cents -> Cents (identity transform for lazy references)
|
||||
pub struct CentsIdentity;
|
||||
|
||||
impl UnaryTransform<Cents, Cents> for CentsIdentity {
|
||||
#[inline(always)]
|
||||
fn apply(cents: Cents) -> Cents {
|
||||
cents
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
mod block_count_target;
|
||||
mod cents_halve;
|
||||
mod cents_identity;
|
||||
mod cents_plus;
|
||||
mod cents_signed_to_dollars;
|
||||
mod cents_subtract_to_cents_signed;
|
||||
@@ -41,6 +43,8 @@ mod volatility_sqrt365;
|
||||
mod volatility_sqrt7;
|
||||
|
||||
pub use block_count_target::*;
|
||||
pub use cents_halve::*;
|
||||
pub use cents_identity::*;
|
||||
pub use cents_plus::*;
|
||||
pub use cents_signed_to_dollars::*;
|
||||
pub use cents_subtract_to_cents_signed::*;
|
||||
|
||||
+9
-9
@@ -1,6 +1,6 @@
|
||||
//! Value type with height-level data only (no period-derived views).
|
||||
//!
|
||||
//! Stores sats and cents per height, plus lazy btc and usd transforms.
|
||||
//! Stores sats and cents per index, plus lazy btc and usd transforms.
|
||||
//! Use when period views are unnecessary (e.g., rolling windows provide windowed data).
|
||||
|
||||
use brk_error::Result;
|
||||
@@ -8,22 +8,22 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
|
||||
use vecdb::{
|
||||
Database, EagerVec, Exit, ImportableVec, LazyVecFrom1, PcoVec, ReadableCloneableVec, Rw,
|
||||
StorageMode,
|
||||
StorageMode, VecIndex,
|
||||
};
|
||||
|
||||
use crate::{internal::{CentsUnsignedToDollars, SatsToBitcoin, SatsToCents}, prices};
|
||||
|
||||
const VERSION: Version = Version::TWO; // Match ValueFromHeightLast versioning
|
||||
const VERSION: Version = Version::TWO; // Match ValueFromHeight versioning
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ValueFromHeight<M: StorageMode = Rw> {
|
||||
pub sats: M::Stored<EagerVec<PcoVec<Height, Sats>>>,
|
||||
pub btc: LazyVecFrom1<Height, Bitcoin, Height, Sats>,
|
||||
pub cents: M::Stored<EagerVec<PcoVec<Height, Cents>>>,
|
||||
pub usd: LazyVecFrom1<Height, Dollars, Height, Cents>,
|
||||
pub struct Value<I: VecIndex, M: StorageMode = Rw> {
|
||||
pub sats: M::Stored<EagerVec<PcoVec<I, Sats>>>,
|
||||
pub btc: LazyVecFrom1<I, Bitcoin, I, Sats>,
|
||||
pub cents: M::Stored<EagerVec<PcoVec<I, Cents>>>,
|
||||
pub usd: LazyVecFrom1<I, Dollars, I, Cents>,
|
||||
}
|
||||
|
||||
impl ValueFromHeight {
|
||||
impl Value<Height> {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
Reference in New Issue
Block a user