mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 23:29:58 -07:00
computer: indexes + rolling
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
//! Lazy binary transform from Full sources.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, ReadableBoxedVec, LazyVecFrom2};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightFull, ComputedVecValue, TxDerivedFull, LazyBinaryHeightDerivedSumCum,
|
||||
NumericValue,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryFromHeightFull<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
S2T: ComputedVecValue,
|
||||
{
|
||||
#[traversable(rename = "base")]
|
||||
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: Box<LazyBinaryHeightDerivedSumCum<T, S1T, S2T>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryFromHeightFull<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: NumericValue + JsonSchema,
|
||||
S2T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_height_and_txindex<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source1: ReadableBoxedVec<Height, S1T>,
|
||||
height_source2: ReadableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedFromHeightFull<S1T>,
|
||||
source2: &TxDerivedFull<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
height: LazyVecFrom2::transformed::<F>(name, v, height_source1, height_source2),
|
||||
rest: Box::new(LazyBinaryHeightDerivedSumCum::from_full_sources::<F>(
|
||||
name, v, &source1.rest, source2,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,13 @@ use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, ReadableBoxedVec, ReadableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedHeightDerivedLast, ComputedVecValue,
|
||||
LazyBinaryComputedFromHeightLast, LazyBinaryComputedFromHeightSum,
|
||||
LazyBinaryHeightDerivedLast, LazyBinaryTransformLast,
|
||||
LazyFromHeightLast, NumericValue,
|
||||
use crate::{
|
||||
indexes_from,
|
||||
internal::{
|
||||
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedHeightDerivedLast,
|
||||
ComputedVecValue, LazyBinaryComputedFromHeightLast, LazyBinaryHeightDerivedLast,
|
||||
LazyBinaryTransformLast, LazyFromHeightLast, NumericValue,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
@@ -43,25 +45,7 @@ macro_rules! build_rest {
|
||||
)
|
||||
};
|
||||
}
|
||||
Box::new(LazyBinaryHeightDerivedLast {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
})
|
||||
Box::new(LazyBinaryHeightDerivedLast(indexes_from!(period)))
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -269,12 +253,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a LazyBinaryComputedFromHeightLast and a LazyBinaryComputedFromHeightSum.
|
||||
pub(crate) fn from_lazy_binary_block_last_and_lazy_binary_sum<F, S1aT, S1bT, S2aT, S2bT>(
|
||||
/// Create from two LazyBinaryComputedFromHeightLast sources.
|
||||
pub(crate) fn from_both_lazy_binary_computed_block_last<F, S1aT, S1bT, S2aT, S2bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryComputedFromHeightLast<S1T, S1aT, S1bT>,
|
||||
source2: &LazyBinaryComputedFromHeightSum<S2T, S2aT, S2bT>,
|
||||
source2: &LazyBinaryComputedFromHeightLast<S2T, S2aT, S2bT>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
//! Lazy binary transform from two Sum-only sources with height level.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, ReadableBoxedVec, ReadableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightSum, ComputedFromHeightSumCum, ComputedVecValue,
|
||||
LazyBinaryHeightDerivedSum, LazyFromHeightLast, NumericValue,
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryFromHeightSum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
S2T: ComputedVecValue,
|
||||
{
|
||||
#[traversable(rename = "sum")]
|
||||
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: Box<LazyBinaryHeightDerivedSum<T, S1T, S2T>>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryFromHeightSum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: NumericValue + JsonSchema,
|
||||
S2T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_computed<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedFromHeightSum<S1T>,
|
||||
source2: &ComputedFromHeightSum<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
height: LazyVecFrom2::transformed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.height.read_only_boxed_clone(),
|
||||
source2.height.read_only_boxed_clone(),
|
||||
),
|
||||
rest: Box::new(LazyBinaryHeightDerivedSum::from_derived::<F>(name, v, &source1.rest, &source2.rest)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from two LazyBinaryFromHeightSum sources.
|
||||
pub(crate) fn from_binary<F, S1aT, S1bT, S2aT, S2bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryFromHeightSum<S1T, S1aT, S1bT>,
|
||||
source2: &LazyBinaryFromHeightSum<S2T, S2aT, S2bT>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
S1aT: ComputedVecValue + JsonSchema,
|
||||
S1bT: ComputedVecValue + JsonSchema,
|
||||
S2aT: ComputedVecValue + JsonSchema,
|
||||
S2bT: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
height: LazyVecFrom2::transformed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.height.read_only_boxed_clone(),
|
||||
source2.height.read_only_boxed_clone(),
|
||||
),
|
||||
rest: Box::new(LazyBinaryHeightDerivedSum::from_binary::<F, _, _, _, _>(
|
||||
name,
|
||||
v,
|
||||
&source1.rest,
|
||||
&source2.rest,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a SumCum source (using only sum) and a LazyLast source.
|
||||
/// Produces sum-only output (no cumulative).
|
||||
pub(crate) fn from_sumcum_lazy_last<F, S2ST>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source1: ReadableBoxedVec<Height, S1T>,
|
||||
height_source2: ReadableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &LazyFromHeightLast<S2T, S2ST>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
S2ST: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
height: LazyVecFrom2::transformed::<F>(name, v, height_source1, height_source2),
|
||||
rest: Box::new(LazyBinaryHeightDerivedSum::from_sumcum_lazy_last::<F, S2ST>(
|
||||
name,
|
||||
v,
|
||||
source1,
|
||||
source2,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
//! Lazy binary transform from two SumCum sources.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, ReadableBoxedVec, ReadableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightSumCum, ComputedHeightDerivedSumCum,
|
||||
ComputedVecValue, LazyBinaryHeightDerivedSumCum, LazyFromHeightLast, NumericValue,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryFromHeightSumCum<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
S2T: ComputedVecValue,
|
||||
{
|
||||
#[traversable(rename = "sum")]
|
||||
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
|
||||
#[traversable(rename = "cumulative")]
|
||||
pub height_cumulative: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: Box<LazyBinaryHeightDerivedSumCum<T, S1T, S2T>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryFromHeightSumCum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
S2T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_derived<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source1: ReadableBoxedVec<Height, S1T>,
|
||||
height_source2: ReadableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedHeightDerivedSumCum<S1T>,
|
||||
source2: &ComputedHeightDerivedSumCum<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
S2T: PartialOrd,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
height: LazyVecFrom2::transformed::<F>(name, v, height_source1, height_source2),
|
||||
height_cumulative: LazyVecFrom2::transformed::<F>(
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
source1.height_cumulative.read_only_boxed_clone(),
|
||||
source2.height_cumulative.read_only_boxed_clone(),
|
||||
),
|
||||
rest: Box::new(LazyBinaryHeightDerivedSumCum::from_computed_sum_raw::<F>(
|
||||
name,
|
||||
v,
|
||||
source1,
|
||||
source2,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
// --- Methods accepting SumCum + LazyLast sources ---
|
||||
|
||||
pub(crate) fn from_computed_lazy_last<F, S2ST>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source1: ReadableBoxedVec<Height, S1T>,
|
||||
height_source2: ReadableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &LazyFromHeightLast<S2T, S2ST>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
S1T: PartialOrd,
|
||||
S2T: NumericValue,
|
||||
S2ST: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom2::transformed::<F>(name, v, height_source1, height_source2),
|
||||
height_cumulative: LazyVecFrom2::transformed::<F>(
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
source1.height_cumulative.read_only_boxed_clone(),
|
||||
source2.height.read_only_boxed_clone(),
|
||||
),
|
||||
rest: Box::new(LazyBinaryHeightDerivedSumCum::from_computed_lazy_last::<F, S2ST>(name, v, source1, source2)),
|
||||
}
|
||||
}
|
||||
}
|
||||
89
crates/brk_computer/src/internal/multi/from_height/cum.rs
Normal file
89
crates/brk_computer/src/internal/multi/from_height/cum.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
//! ComputedFromHeightCum - stored height + LazyLast + cumulative (from height).
|
||||
//!
|
||||
//! Like ComputedFromHeightCumSum but without RollingWindows.
|
||||
//! Used for distribution metrics where rolling is optional per cohort.
|
||||
//! Cumulative gets its own ComputedFromHeightLast so it has LazyLast index views.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedFromHeightCum<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub last: ComputedFromHeightLast<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedFromHeightCum<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 last = ComputedFromHeightLast::forced_import(db, name, v, indexes)?;
|
||||
let cumulative = ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
Ok(Self { last, cumulative })
|
||||
}
|
||||
|
||||
/// Compute height data via closure, then cumulative only (no rolling).
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
exit: &Exit,
|
||||
compute_height: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: Default,
|
||||
{
|
||||
compute_height(&mut self.last.height)?;
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.last.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute cumulative from already-filled height vec.
|
||||
pub(crate) fn compute_cumulative(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
exit: &Exit,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: Default,
|
||||
{
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.last.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
//! ComputedFromHeightCumFull - stored height + LazyLast + cumulative (from height) + RollingFull.
|
||||
//!
|
||||
//! For metrics with stored per-block data, cumulative sums, and rolling windows.
|
||||
//! Cumulative gets its own ComputedFromHeightLast so it has LazyLast index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, NumericValue, RollingFull, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedFromHeightCumFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub last: ComputedFromHeightLast<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedFromHeightCumFull<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 last = ComputedFromHeightLast::forced_import(db, name, v, indexes)?;
|
||||
let cumulative = ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
indexes,
|
||||
)?;
|
||||
let rolling = RollingFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
last,
|
||||
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.last.height)?;
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.last.height, exit)?;
|
||||
self.rolling
|
||||
.compute(max_from, windows, &self.last.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
//! ComputedFromHeightCumSum - stored height + LazyLast + cumulative (from height) + RollingWindows (sum).
|
||||
//!
|
||||
//! Like ComputedFromHeightCumFull 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 LazyLast index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, NumericValue, RollingWindows, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedFromHeightCumSum<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub last: ComputedFromHeightLast<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingWindows<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedFromHeightCumSum<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 last = ComputedFromHeightLast::forced_import(db, name, v, indexes)?;
|
||||
let cumulative = ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
indexes,
|
||||
)?;
|
||||
let rolling = RollingWindows::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
last,
|
||||
cumulative,
|
||||
rolling,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute height data via closure, then cumulative + rolling sum.
|
||||
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: Default + SubAssign,
|
||||
{
|
||||
compute_height(&mut self.last.height)?;
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.last.height, exit)?;
|
||||
self.rolling
|
||||
.compute_rolling_sum(max_from, windows, &self.last.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,9 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{
|
||||
Database, EagerVec, Exit, ImportableVec, PcoVec, ReadableCloneableVec, Rw, StorageMode,
|
||||
};
|
||||
use vecdb::{Database, EagerVec, ImportableVec, PcoVec, ReadableCloneableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
use crate::indexes;
|
||||
|
||||
use crate::internal::{ComputedHeightDerivedFull, ComputedVecValue, NumericValue};
|
||||
|
||||
@@ -51,17 +49,9 @@ where
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
Ok(Self { height, rest: Box::new(rest) })
|
||||
}
|
||||
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
mut compute: impl FnMut(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||
) -> Result<()> {
|
||||
compute(&mut self.height)?;
|
||||
self.rest.compute_cumulative(starting_indexes, &self.height, exit)?;
|
||||
Ok(())
|
||||
Ok(Self {
|
||||
height,
|
||||
rest: Box::new(rest),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
//! LazyBinaryComputedFromHeightSum - block sum with lazy binary transform at height level.
|
||||
//!
|
||||
//! Height-level sum is lazy: `transform(source1[h], source2[h])`.
|
||||
//! Day1 stats are stored since they require aggregation across heights.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, ReadableBoxedVec, ReadableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedHeightDerivedSum, ComputedVecValue, NumericValue},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
/// Block sum aggregation with lazy binary transform at height + computed derived indexes.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryComputedFromHeightSum<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
S2T: ComputedVecValue,
|
||||
{
|
||||
#[traversable(rename = "sum")]
|
||||
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<ComputedHeightDerivedSum<T>>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryComputedFromHeightSum<T, S1T, S2T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
S2T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: ReadableBoxedVec<Height, S1T>,
|
||||
source2: ReadableBoxedVec<Height, S2T>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height = LazyVecFrom2::transformed::<F>(name, v, source1, source2);
|
||||
|
||||
let rest =
|
||||
ComputedHeightDerivedSum::forced_import(name, height.read_only_boxed_clone(), v, indexes);
|
||||
|
||||
Self { height, rest: Box::new(rest) }
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//! Lazy unary transform from height with Sum aggregation.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableBoxedVec, LazyVecFrom1, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightSum, ComputedVecValue, LazyHeightDerivedSum, NumericValue,
|
||||
};
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyFromHeightSum<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
{
|
||||
pub height: LazyVecFrom1<Height, T, Height, S1T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<LazyHeightDerivedSum<T, S1T>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyFromHeightSum<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: ReadableBoxedVec<Height, S1T>,
|
||||
source: &ComputedFromHeightSum<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: Box::new(LazyHeightDerivedSum::from_derived_computed::<F>(name, v, &source.rest)),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
//! Lazy unary transform from height with Distribution aggregation.
|
||||
//! Like LazyFromHeightFull but without sum/cumulative (for ratio/percentage metrics).
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableBoxedVec, LazyVecFrom1, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedHeightDerivedFull, ComputedVecValue, LazyHeightDerivedDistribution, NumericValue,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyFromHeightTransformDistribution<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
{
|
||||
#[traversable(rename = "base")]
|
||||
pub height: LazyVecFrom1<Height, T, Height, S1T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: Box<LazyHeightDerivedDistribution<T, S1T>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyFromHeightTransformDistribution<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_derived<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: ReadableBoxedVec<Height, S1T>,
|
||||
source: &ComputedHeightDerivedFull<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: Box::new(LazyHeightDerivedDistribution::from_derived_computed::<F>(name, v, source)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +1,67 @@
|
||||
mod binary_full;
|
||||
mod binary_last;
|
||||
mod binary_sum;
|
||||
mod binary_sum_cum;
|
||||
mod constant;
|
||||
mod cum;
|
||||
mod cum_rolling_full;
|
||||
mod cum_rolling_sum;
|
||||
mod distribution;
|
||||
mod full;
|
||||
mod last;
|
||||
mod lazy_binary_computed_distribution;
|
||||
mod lazy_binary_computed_full;
|
||||
mod lazy_binary_computed_last;
|
||||
mod lazy_binary_computed_sum;
|
||||
mod lazy_binary_computed_sum_cum;
|
||||
mod lazy_computed_full;
|
||||
mod lazy_computed_sum_cum;
|
||||
mod lazy_full;
|
||||
mod lazy_last;
|
||||
mod lazy_sum;
|
||||
mod lazy_sum_cum;
|
||||
mod lazy_transform_distribution;
|
||||
mod lazy_value;
|
||||
mod percentiles;
|
||||
mod price;
|
||||
mod ratio;
|
||||
mod stddev;
|
||||
mod stored_value_last;
|
||||
mod sum;
|
||||
mod sum_cum;
|
||||
mod value_binary;
|
||||
mod value_change;
|
||||
mod value_ema;
|
||||
mod value_full;
|
||||
mod value_last;
|
||||
mod value_lazy_binary_last;
|
||||
mod value_lazy_computed_sum_cum;
|
||||
mod value_lazy_computed_cum;
|
||||
mod value_lazy_last;
|
||||
mod value_lazy_sum_cum;
|
||||
mod value_sum;
|
||||
mod value_sum_cum;
|
||||
|
||||
pub use binary_full::*;
|
||||
pub use binary_last::*;
|
||||
pub use binary_sum::*;
|
||||
pub use binary_sum_cum::*;
|
||||
pub use constant::*;
|
||||
pub use cum::*;
|
||||
pub use cum_rolling_full::*;
|
||||
pub use cum_rolling_sum::*;
|
||||
pub use distribution::*;
|
||||
pub use full::*;
|
||||
pub use last::*;
|
||||
pub use lazy_binary_computed_distribution::*;
|
||||
pub use lazy_binary_computed_full::*;
|
||||
pub use lazy_binary_computed_last::*;
|
||||
pub use lazy_binary_computed_sum::*;
|
||||
pub use lazy_binary_computed_sum_cum::*;
|
||||
pub use lazy_computed_full::*;
|
||||
pub use lazy_computed_sum_cum::*;
|
||||
pub use lazy_full::*;
|
||||
pub use lazy_last::*;
|
||||
pub use lazy_sum::*;
|
||||
pub use lazy_sum_cum::*;
|
||||
pub use lazy_transform_distribution::*;
|
||||
pub use lazy_value::*;
|
||||
pub use percentiles::*;
|
||||
pub use price::*;
|
||||
pub use ratio::*;
|
||||
pub use stddev::*;
|
||||
pub use stored_value_last::*;
|
||||
pub use sum::*;
|
||||
pub use sum_cum::*;
|
||||
pub use value_binary::*;
|
||||
pub use value_change::*;
|
||||
pub use value_ema::*;
|
||||
pub use value_full::*;
|
||||
pub use value_last::*;
|
||||
pub use value_lazy_binary_last::*;
|
||||
pub use value_lazy_computed_sum_cum::*;
|
||||
pub use value_lazy_computed_cum::*;
|
||||
pub use value_lazy_last::*;
|
||||
pub use value_lazy_sum_cum::*;
|
||||
pub use value_sum::*;
|
||||
pub use value_sum_cum::*;
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
//! ComputedFromHeight using Sum-only aggregation.
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, EagerVec, ImportableVec, PcoVec, ReadableCloneableVec, Rw, StorageMode};
|
||||
|
||||
use crate::indexes;
|
||||
|
||||
use crate::internal::{ComputedHeightDerivedSum, ComputedVecValue, NumericValue};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedFromHeightSum<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<ComputedHeightDerivedSum<T>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedFromHeightSum<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 rest =
|
||||
ComputedHeightDerivedSum::forced_import(name, height.read_only_boxed_clone(), v, indexes);
|
||||
|
||||
Ok(Self { height, rest: Box::new(rest) })
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Sats, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, ReadableCloneableVec};
|
||||
|
||||
use crate::internal::{ComputedVecValue, LazyBinaryFromHeightSumCum, LazyValueFromHeightSumCum};
|
||||
|
||||
/// Lazy value vecs computed from two ValueFromHeightSumCum sources via binary transforms.
|
||||
/// Used for computing coinbase = subsidy + fee.
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ValueBinaryFromHeight {
|
||||
pub sats: LazyBinaryFromHeightSumCum<Sats, Sats, Sats>,
|
||||
pub btc: LazyBinaryFromHeightSumCum<Bitcoin, Sats, Sats>,
|
||||
pub usd: LazyBinaryFromHeightSumCum<Dollars, Dollars, Dollars>,
|
||||
}
|
||||
|
||||
impl ValueBinaryFromHeight {
|
||||
pub(crate) fn from_lazy<SatsF, BitcoinF, DollarsF, S1T, S2T>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyValueFromHeightSumCum<S1T, S2T>,
|
||||
source2: &LazyValueFromHeightSumCum<S1T, S2T>,
|
||||
) -> Self
|
||||
where
|
||||
SatsF: BinaryTransform<Sats, Sats, Sats>,
|
||||
BitcoinF: BinaryTransform<Sats, Sats, Bitcoin>,
|
||||
DollarsF: BinaryTransform<Dollars, Dollars, Dollars>,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
S2T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
let sats = LazyBinaryFromHeightSumCum::from_derived::<SatsF>(
|
||||
name,
|
||||
version,
|
||||
source1.sats.height.read_only_boxed_clone(),
|
||||
source2.sats.height.read_only_boxed_clone(),
|
||||
&source1.sats.rest,
|
||||
&source2.sats.rest,
|
||||
);
|
||||
|
||||
let btc = LazyBinaryFromHeightSumCum::from_derived::<BitcoinF>(
|
||||
&format!("{name}_btc"),
|
||||
version,
|
||||
source1.sats.height.read_only_boxed_clone(),
|
||||
source2.sats.height.read_only_boxed_clone(),
|
||||
&source1.sats.rest,
|
||||
&source2.sats.rest,
|
||||
);
|
||||
|
||||
let usd = LazyBinaryFromHeightSumCum::from_derived::<DollarsF>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
source1.usd.height.read_only_boxed_clone(),
|
||||
source2.usd.height.read_only_boxed_clone(),
|
||||
&source1.usd.rest,
|
||||
&source2.usd.rest,
|
||||
);
|
||||
|
||||
Self {
|
||||
sats,
|
||||
btc,
|
||||
usd,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
//! Value type with stored sats height + cumulative, lazy btc + lazy dollars.
|
||||
//!
|
||||
//! Like LazyComputedValueFromHeightSumCum but with Cum (no old period aggregations).
|
||||
//! - Sats: stored height + cumulative (ComputedFromHeightCum)
|
||||
//! - BTC: lazy transform from sats (LazyFromHeightLast)
|
||||
//! - USD: lazy binary (price × sats), LazyLast per index (no stored cumulative)
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Height, Sats, Version};
|
||||
use vecdb::{Database, Exit, ReadableCloneableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedFromHeightCum, LazyBinaryComputedFromHeightLast, LazyFromHeightLast,
|
||||
PriceTimesSats, SatsToBitcoin,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
|
||||
/// Value wrapper with stored sats height + cumulative, lazy btc + lazy usd.
|
||||
#[derive(Traversable)]
|
||||
pub struct LazyComputedValueFromHeightCum<M: StorageMode = Rw> {
|
||||
pub sats: ComputedFromHeightCum<Sats, M>,
|
||||
pub btc: LazyFromHeightLast<Bitcoin, Sats>,
|
||||
pub usd: LazyBinaryComputedFromHeightLast<Dollars, Dollars, Sats>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl LazyComputedValueFromHeightCum {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = ComputedFromHeightCum::forced_import(db, name, v, indexes)?;
|
||||
|
||||
let btc = LazyFromHeightLast::from_computed::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats.height.read_only_boxed_clone(),
|
||||
&sats,
|
||||
);
|
||||
|
||||
let usd = LazyBinaryComputedFromHeightLast::forced_import::<PriceTimesSats>(
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
prices.usd.price.read_only_boxed_clone(),
|
||||
sats.height.read_only_boxed_clone(),
|
||||
indexes,
|
||||
);
|
||||
|
||||
Ok(Self { sats, btc, usd })
|
||||
}
|
||||
|
||||
/// Compute cumulative from already-filled sats height vec.
|
||||
pub(crate) fn compute_cumulative(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.sats.compute_cumulative(max_from, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
//! Value type with stored height + lazy dollars for SumCum pattern.
|
||||
//!
|
||||
//! Use this when:
|
||||
//! - Sats height is stored (primary source of truth)
|
||||
//! - Sats indexes are derived from height
|
||||
//! - Bitcoin is lazy (transform from sats)
|
||||
//! - Dollars height is lazy (price × sats), with stored indexes
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Sats, Version};
|
||||
use vecdb::{Database, Exit, ReadableCloneableVec, LazyVecFrom2, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ComputedFromHeightSumCum, LazyComputedFromHeightSumCum, LazyFromHeightSumCum,
|
||||
PriceTimesSats, SatsToBitcoin,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
|
||||
/// Value wrapper with stored sats height + lazy dollars.
|
||||
///
|
||||
/// Sats height is stored (computed directly or from stateful loop).
|
||||
/// Dollars height is lazy (price × sats).
|
||||
/// Cumulative and day1 aggregates are stored for both.
|
||||
#[derive(Traversable)]
|
||||
pub struct LazyComputedValueFromHeightSumCum<M: StorageMode = Rw> {
|
||||
pub sats: ComputedFromHeightSumCum<Sats, M>,
|
||||
pub btc: LazyFromHeightSumCum<Bitcoin, Sats>,
|
||||
pub usd: LazyComputedFromHeightSumCum<Dollars, Dollars, Sats, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl LazyComputedValueFromHeightSumCum {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = ComputedFromHeightSumCum::forced_import(db, name, v, indexes)?;
|
||||
|
||||
let btc = LazyFromHeightSumCum::from_computed::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats.height.read_only_boxed_clone(),
|
||||
&sats,
|
||||
);
|
||||
|
||||
let usd_height = LazyVecFrom2::transformed::<PriceTimesSats>(
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
prices.usd.price.read_only_boxed_clone(),
|
||||
sats.height.read_only_boxed_clone(),
|
||||
);
|
||||
|
||||
let usd = LazyComputedFromHeightSumCum::forced_import(
|
||||
db,
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
indexes,
|
||||
usd_height,
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
sats,
|
||||
btc,
|
||||
usd,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute cumulative from already-computed height.
|
||||
pub(crate) fn compute_cumulative(
|
||||
&mut self,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.sats.compute_cumulative(starting_indexes, exit)?;
|
||||
self.usd.compute_cumulative(starting_indexes, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
//! Value type for Sum pattern from Height.
|
||||
//!
|
||||
//! Height-level USD value is lazy: `sats * price`.
|
||||
//! Day1 sum is stored since it requires aggregation across heights with varying prices.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Sats, Version};
|
||||
use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedFromHeightSum, LazyBinaryComputedFromHeightSum, LazyFromHeightSum, SatsTimesPrice,
|
||||
SatsToBitcoin,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ValueFromHeightSum<M: StorageMode = Rw> {
|
||||
pub sats: ComputedFromHeightSum<Sats, M>,
|
||||
pub btc: LazyFromHeightSum<Bitcoin, Sats>,
|
||||
pub usd: LazyBinaryComputedFromHeightSum<Dollars, Sats, Dollars>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE; // Bumped for lazy height dollars
|
||||
|
||||
impl ValueFromHeightSum {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = ComputedFromHeightSum::forced_import(db, name, v, indexes)?;
|
||||
|
||||
let btc = LazyFromHeightSum::from_computed::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats.height.read_only_boxed_clone(),
|
||||
&sats,
|
||||
);
|
||||
|
||||
let usd = LazyBinaryComputedFromHeightSum::forced_import::<SatsTimesPrice>(
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
sats.height.read_only_boxed_clone(),
|
||||
prices.usd.price.read_only_boxed_clone(),
|
||||
indexes,
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
sats,
|
||||
btc,
|
||||
usd,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,3 @@
|
||||
mod lazy_distribution;
|
||||
mod value_dollars;
|
||||
mod value_full;
|
||||
|
||||
pub use lazy_distribution::*;
|
||||
pub use value_dollars::*;
|
||||
pub use value_full::*;
|
||||
|
||||
@@ -1,204 +0,0 @@
|
||||
//! Dollars from TxIndex with lazy height stats and stored day1.
|
||||
//!
|
||||
//! Height-level USD stats (min/max/avg/sum/percentiles) are lazy: `sats_stat * price`.
|
||||
//! Height cumulative and day1 stats are stored since they require aggregation
|
||||
//! across heights with varying prices.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Bitcoin, Day1, Day3, DifficultyEpoch, Dollars, HalvingEpoch, Height, Hour1, Hour4, Hour12,
|
||||
Minute1, Minute5, Minute10, Minute30, Month1, Month3, Month6, Sats, TxIndex, Version, Week1,
|
||||
Year1, Year10,
|
||||
};
|
||||
use vecdb::{
|
||||
Database, Exit, LazyVecFrom3, ReadableBoxedVec, ReadableCloneableVec, Rw, StorageMode,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{CumulativeVec, Full, LazyBinaryTransformFull, LazyFull, SatsTimesPrice},
|
||||
};
|
||||
|
||||
/// Lazy dollars at TxIndex: `sats * price[height]`
|
||||
pub type LazyDollarsTxIndex =
|
||||
LazyVecFrom3<TxIndex, Dollars, TxIndex, Sats, TxIndex, Height, Height, Dollars>;
|
||||
|
||||
/// Lazy dollars height stats: `sats_height_stat * price`
|
||||
pub type LazyDollarsHeightFull = LazyBinaryTransformFull<Height, Dollars, Sats, Dollars>;
|
||||
|
||||
/// Dollars with lazy txindex and height fields, stored day1.
|
||||
///
|
||||
/// Height-level stats (except cumulative) are lazy: `sats * price[height]`.
|
||||
/// Cumulative at height level is stored since it requires summing historical values.
|
||||
/// Day1 stats are stored since they aggregate across heights with varying prices.
|
||||
#[derive(Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ValueDollarsFromTxFull<M: StorageMode = Rw> {
|
||||
#[traversable(skip)]
|
||||
pub txindex: LazyDollarsTxIndex,
|
||||
#[traversable(flatten)]
|
||||
pub height: LazyDollarsHeightFull,
|
||||
#[traversable(rename = "cumulative")]
|
||||
pub height_cumulative: CumulativeVec<Height, Dollars, M>,
|
||||
pub minute1: LazyFull<Minute1, Dollars, Height, Height>,
|
||||
pub minute5: LazyFull<Minute5, Dollars, Height, Height>,
|
||||
pub minute10: LazyFull<Minute10, Dollars, Height, Height>,
|
||||
pub minute30: LazyFull<Minute30, Dollars, Height, Height>,
|
||||
pub hour1: LazyFull<Hour1, Dollars, Height, Height>,
|
||||
pub hour4: LazyFull<Hour4, Dollars, Height, Height>,
|
||||
pub hour12: LazyFull<Hour12, Dollars, Height, Height>,
|
||||
pub day1: LazyFull<Day1, Dollars, Height, Height>,
|
||||
pub day3: LazyFull<Day3, Dollars, Height, Height>,
|
||||
pub week1: LazyFull<Week1, Dollars, Height, Height>,
|
||||
pub month1: LazyFull<Month1, Dollars, Height, Height>,
|
||||
pub month3: LazyFull<Month3, Dollars, Height, Height>,
|
||||
pub month6: LazyFull<Month6, Dollars, Height, Height>,
|
||||
pub year1: LazyFull<Year1, Dollars, Height, Height>,
|
||||
pub year10: LazyFull<Year10, Dollars, Height, Height>,
|
||||
pub halvingepoch: LazyFull<HalvingEpoch, Dollars, Height, HalvingEpoch>,
|
||||
pub difficultyepoch: LazyFull<DifficultyEpoch, Dollars, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE; // Bumped for lazy height change
|
||||
|
||||
impl ValueDollarsFromTxFull {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
sats_height: &Full<Height, Sats>,
|
||||
height_to_price: ReadableBoxedVec<Height, Dollars>,
|
||||
sats_txindex: ReadableBoxedVec<TxIndex, Sats>,
|
||||
txindex_to_height: ReadableBoxedVec<TxIndex, Height>,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let txindex = create_lazy_txindex(
|
||||
name,
|
||||
v,
|
||||
sats_txindex,
|
||||
txindex_to_height,
|
||||
height_to_price.clone(),
|
||||
);
|
||||
|
||||
// Lazy height stats: sats_stat * price
|
||||
let height = LazyBinaryTransformFull::from_full_and_source::<SatsTimesPrice>(
|
||||
name,
|
||||
v,
|
||||
sats_height,
|
||||
height_to_price.clone(),
|
||||
);
|
||||
|
||||
// Stored cumulative - must be computed by summing historical sum*price
|
||||
let height_cumulative = CumulativeVec::forced_import(db, name, v)?;
|
||||
|
||||
macro_rules! period {
|
||||
($idx:ident) => {
|
||||
LazyFull::from_height_source(
|
||||
name,
|
||||
v,
|
||||
height.boxed_sum(),
|
||||
height_cumulative.read_only_boxed_clone(),
|
||||
indexes.$idx.first_height.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! epoch {
|
||||
($idx:ident) => {
|
||||
LazyFull::from_stats_aggregate(
|
||||
name,
|
||||
v,
|
||||
height.boxed_average(),
|
||||
height.boxed_min(),
|
||||
height.boxed_max(),
|
||||
height.boxed_sum(),
|
||||
height_cumulative.read_only_boxed_clone(),
|
||||
height.boxed_average(),
|
||||
indexes.$idx.identity.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
let minute1 = period!(minute1);
|
||||
let minute5 = period!(minute5);
|
||||
let minute10 = period!(minute10);
|
||||
let minute30 = period!(minute30);
|
||||
let hour1 = period!(hour1);
|
||||
let hour4 = period!(hour4);
|
||||
let hour12 = period!(hour12);
|
||||
let day1 = period!(day1);
|
||||
let day3 = period!(day3);
|
||||
let week1 = period!(week1);
|
||||
let month1 = period!(month1);
|
||||
let month3 = period!(month3);
|
||||
let month6 = period!(month6);
|
||||
let year1 = period!(year1);
|
||||
let year10 = period!(year10);
|
||||
let halvingepoch = epoch!(halvingepoch);
|
||||
let difficultyepoch = epoch!(difficultyepoch);
|
||||
|
||||
Ok(Self {
|
||||
txindex,
|
||||
height,
|
||||
height_cumulative,
|
||||
minute1,
|
||||
minute5,
|
||||
minute10,
|
||||
minute30,
|
||||
hour1,
|
||||
hour4,
|
||||
hour12,
|
||||
day1,
|
||||
day3,
|
||||
week1,
|
||||
month1,
|
||||
month3,
|
||||
month6,
|
||||
year1,
|
||||
year10,
|
||||
halvingepoch,
|
||||
difficultyepoch,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute stored fields (cumulative and day1) from lazy height stats.
|
||||
///
|
||||
/// This is MUCH faster than the old approach since it only iterates heights,
|
||||
/// not all transactions per block.
|
||||
pub(crate) fn derive_from(
|
||||
&mut self,
|
||||
_indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// Compute height cumulative by summing lazy height.sum values
|
||||
self.height_cumulative.0.compute_cumulative(
|
||||
starting_indexes.height,
|
||||
&self.height.sum,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn create_lazy_txindex(
|
||||
name: &str,
|
||||
version: Version,
|
||||
sats_txindex: ReadableBoxedVec<TxIndex, Sats>,
|
||||
txindex_to_height: ReadableBoxedVec<TxIndex, Height>,
|
||||
height_to_price: ReadableBoxedVec<Height, Dollars>,
|
||||
) -> LazyDollarsTxIndex {
|
||||
LazyVecFrom3::init(
|
||||
&format!("{name}_txindex"),
|
||||
version,
|
||||
sats_txindex,
|
||||
txindex_to_height,
|
||||
height_to_price,
|
||||
|_index, sats, _height, close| close * Bitcoin::from(sats),
|
||||
)
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
//! ValueFromTxFull - eager txindex Sats source + ValueTxDerivedFull (sats/bitcoin/dollars).
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Sats, TxIndex, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{ComputeIndexes, indexes, internal::ValueTxDerivedFull, prices};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct ValueFromTxFull<M: StorageMode = Rw> {
|
||||
#[traversable(rename = "txindex")]
|
||||
pub base: M::Stored<EagerVec<PcoVec<TxIndex, Sats>>>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub indexes: ValueTxDerivedFull<M>,
|
||||
}
|
||||
|
||||
impl ValueFromTxFull {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
indexer: &Indexer,
|
||||
prices: &prices::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
let txindex = EagerVec::forced_import(db, name, v)?;
|
||||
let derived =
|
||||
ValueTxDerivedFull::forced_import(db, name, v, indexes, indexer, prices, &txindex)?;
|
||||
Ok(Self {
|
||||
base: txindex,
|
||||
indexes: derived,
|
||||
})
|
||||
}
|
||||
|
||||
/// Derive from source, skipping first N transactions per block from all calculations.
|
||||
///
|
||||
/// Use `skip_count: 1` to exclude coinbase transactions from fee/feerate stats.
|
||||
pub(crate) fn derive_from_with_skip(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
skip_count: usize,
|
||||
) -> Result<()> {
|
||||
self.indexes.derive_from_with_skip(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&self.base,
|
||||
exit,
|
||||
skip_count,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,44 +1,53 @@
|
||||
//! Lazy binary transform for derived block with Last aggregation only.
|
||||
//!
|
||||
//! Newtype on `Indexes` with `LazyBinaryTransformLast` per field.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Hour1, Hour12, Hour4, Minute1, Minute10, Minute30,
|
||||
Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, ReadableCloneableVec};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedVecValue,
|
||||
LazyBinaryTransformLast, LazyFromHeightLast, NumericValue,
|
||||
use crate::{
|
||||
indexes_from,
|
||||
internal::{
|
||||
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedVecValue, Indexes,
|
||||
LazyBinaryTransformLast, LazyFromHeightLast, NumericValue,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryHeightDerivedLast<T, S1T = T, S2T = T>
|
||||
pub type LazyBinaryHeightDerivedLastInner<T, S1T, S2T> = Indexes<
|
||||
LazyBinaryTransformLast<Minute1, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Minute5, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Minute10, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Minute30, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Hour1, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Hour4, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Hour12, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Day1, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Day3, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Week1, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Month1, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Month3, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Month6, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Year1, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<Year10, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<HalvingEpoch, T, S1T, S2T>,
|
||||
LazyBinaryTransformLast<DifficultyEpoch, T, S1T, S2T>,
|
||||
>;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct LazyBinaryHeightDerivedLast<T, S1T = T, S2T = T>(
|
||||
pub LazyBinaryHeightDerivedLastInner<T, S1T, S2T>,
|
||||
)
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
S2T: ComputedVecValue,
|
||||
{
|
||||
pub minute1: LazyBinaryTransformLast<Minute1, T, S1T, S2T>,
|
||||
pub minute5: LazyBinaryTransformLast<Minute5, T, S1T, S2T>,
|
||||
pub minute10: LazyBinaryTransformLast<Minute10, T, S1T, S2T>,
|
||||
pub minute30: LazyBinaryTransformLast<Minute30, T, S1T, S2T>,
|
||||
pub hour1: LazyBinaryTransformLast<Hour1, T, S1T, S2T>,
|
||||
pub hour4: LazyBinaryTransformLast<Hour4, T, S1T, S2T>,
|
||||
pub hour12: LazyBinaryTransformLast<Hour12, T, S1T, S2T>,
|
||||
pub day1: LazyBinaryTransformLast<Day1, T, S1T, S2T>,
|
||||
pub day3: LazyBinaryTransformLast<Day3, T, S1T, S2T>,
|
||||
pub week1: LazyBinaryTransformLast<Week1, T, S1T, S2T>,
|
||||
pub month1: LazyBinaryTransformLast<Month1, T, S1T, S2T>,
|
||||
pub month3: LazyBinaryTransformLast<Month3, T, S1T, S2T>,
|
||||
pub month6: LazyBinaryTransformLast<Month6, T, S1T, S2T>,
|
||||
pub year1: LazyBinaryTransformLast<Year1, T, S1T, S2T>,
|
||||
pub year10: LazyBinaryTransformLast<Year10, T, S1T, S2T>,
|
||||
pub halvingepoch: LazyBinaryTransformLast<HalvingEpoch, T, S1T, S2T>,
|
||||
pub difficultyepoch: LazyBinaryTransformLast<DifficultyEpoch, T, S1T, S2T>,
|
||||
}
|
||||
S2T: ComputedVecValue;
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
@@ -71,25 +80,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
Self(indexes_from!(period))
|
||||
}
|
||||
|
||||
pub(crate) fn from_computed_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
@@ -115,25 +106,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
Self(indexes_from!(period))
|
||||
}
|
||||
|
||||
pub(crate) fn from_lazy_block_last_and_block_last<F, S1SourceT>(
|
||||
@@ -160,25 +133,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
Self(indexes_from!(period))
|
||||
}
|
||||
|
||||
pub(crate) fn from_block_last_and_lazy_block_last<F, S2SourceT>(
|
||||
@@ -205,24 +160,6 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
Self(indexes_from!(period))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
//! Lazy aggregated binary transform for Sum-only pattern across all time periods.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Hour1, Hour12, Hour4, Minute1, Minute10, Minute30,
|
||||
Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, ReadableCloneableVec};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightSumCum, ComputedHeightDerivedSum, ComputedVecValue, LazyBinaryTransformSum,
|
||||
LazyFromHeightLast, NumericValue,
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryHeightDerivedSum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
S2T: ComputedVecValue,
|
||||
{
|
||||
pub minute1: LazyBinaryTransformSum<Minute1, T, S1T, S2T>,
|
||||
pub minute5: LazyBinaryTransformSum<Minute5, T, S1T, S2T>,
|
||||
pub minute10: LazyBinaryTransformSum<Minute10, T, S1T, S2T>,
|
||||
pub minute30: LazyBinaryTransformSum<Minute30, T, S1T, S2T>,
|
||||
pub hour1: LazyBinaryTransformSum<Hour1, T, S1T, S2T>,
|
||||
pub hour4: LazyBinaryTransformSum<Hour4, T, S1T, S2T>,
|
||||
pub hour12: LazyBinaryTransformSum<Hour12, T, S1T, S2T>,
|
||||
pub day1: LazyBinaryTransformSum<Day1, T, S1T, S2T>,
|
||||
pub day3: LazyBinaryTransformSum<Day3, T, S1T, S2T>,
|
||||
pub week1: LazyBinaryTransformSum<Week1, T, S1T, S2T>,
|
||||
pub month1: LazyBinaryTransformSum<Month1, T, S1T, S2T>,
|
||||
pub month3: LazyBinaryTransformSum<Month3, T, S1T, S2T>,
|
||||
pub month6: LazyBinaryTransformSum<Month6, T, S1T, S2T>,
|
||||
pub year1: LazyBinaryTransformSum<Year1, T, S1T, S2T>,
|
||||
pub year10: LazyBinaryTransformSum<Year10, T, S1T, S2T>,
|
||||
pub halvingepoch: LazyBinaryTransformSum<HalvingEpoch, T, S1T, S2T>,
|
||||
pub difficultyepoch: LazyBinaryTransformSum<DifficultyEpoch, T, S1T, S2T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryHeightDerivedSum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: NumericValue + JsonSchema,
|
||||
S2T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_derived<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedHeightDerivedSum<S1T>,
|
||||
source2: &ComputedHeightDerivedSum<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($p:ident) => {
|
||||
LazyBinaryTransformSum::from_boxed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.$p.read_only_boxed_clone(),
|
||||
source2.$p.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from two LazyBinaryHeightDerivedSum sources.
|
||||
pub(crate) fn from_binary<F, S1aT, S1bT, S2aT, S2bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryHeightDerivedSum<S1T, S1aT, S1bT>,
|
||||
source2: &LazyBinaryHeightDerivedSum<S2T, S2aT, S2bT>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
S1aT: ComputedVecValue + JsonSchema,
|
||||
S1bT: ComputedVecValue + JsonSchema,
|
||||
S2aT: ComputedVecValue + JsonSchema,
|
||||
S2bT: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($p:ident) => {
|
||||
LazyBinaryTransformSum::from_boxed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.$p.read_only_boxed_clone(),
|
||||
source2.$p.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a SumCum source (using only sum) and a LazyLast source.
|
||||
pub(crate) fn from_sumcum_lazy_last<F, S2ST>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &LazyFromHeightLast<S2T, S2ST>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
S2ST: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($p:ident) => {
|
||||
LazyBinaryTransformSum::from_boxed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.$p.sum.read_only_boxed_clone(),
|
||||
source2.$p.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,184 +0,0 @@
|
||||
//! Lazy aggregated SumCum - binary transform version.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Hour1, Hour4, Hour12, Minute1, Minute5, Minute10,
|
||||
Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, ReadableCloneableVec};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightSumCum, ComputedHeightDerivedFull, ComputedHeightDerivedSumCum,
|
||||
ComputedVecValue, LazyBinaryTransformSumCum, LazyFromHeightLast, NumericValue, TxDerivedFull,
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryHeightDerivedSumCum<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
S2T: ComputedVecValue,
|
||||
{
|
||||
pub minute1: LazyBinaryTransformSumCum<Minute1, T, S1T, S2T>,
|
||||
pub minute5: LazyBinaryTransformSumCum<Minute5, T, S1T, S2T>,
|
||||
pub minute10: LazyBinaryTransformSumCum<Minute10, T, S1T, S2T>,
|
||||
pub minute30: LazyBinaryTransformSumCum<Minute30, T, S1T, S2T>,
|
||||
pub hour1: LazyBinaryTransformSumCum<Hour1, T, S1T, S2T>,
|
||||
pub hour4: LazyBinaryTransformSumCum<Hour4, T, S1T, S2T>,
|
||||
pub hour12: LazyBinaryTransformSumCum<Hour12, T, S1T, S2T>,
|
||||
pub day1: LazyBinaryTransformSumCum<Day1, T, S1T, S2T>,
|
||||
pub day3: LazyBinaryTransformSumCum<Day3, T, S1T, S2T>,
|
||||
pub week1: LazyBinaryTransformSumCum<Week1, T, S1T, S2T>,
|
||||
pub month1: LazyBinaryTransformSumCum<Month1, T, S1T, S2T>,
|
||||
pub month3: LazyBinaryTransformSumCum<Month3, T, S1T, S2T>,
|
||||
pub month6: LazyBinaryTransformSumCum<Month6, T, S1T, S2T>,
|
||||
pub year1: LazyBinaryTransformSumCum<Year1, T, S1T, S2T>,
|
||||
pub year10: LazyBinaryTransformSumCum<Year10, T, S1T, S2T>,
|
||||
pub halvingepoch: LazyBinaryTransformSumCum<HalvingEpoch, T, S1T, S2T>,
|
||||
pub difficultyepoch: LazyBinaryTransformSumCum<DifficultyEpoch, T, S1T, S2T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryHeightDerivedSumCum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
S2T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
/// Create from two ComputedHeightDerivedSumCum sources.
|
||||
pub(crate) fn from_computed_sum_raw<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedHeightDerivedSumCum<S1T>,
|
||||
source2: &ComputedHeightDerivedSumCum<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($p:ident) => {
|
||||
LazyBinaryTransformSumCum::from_sources_sum_raw::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.$p.sum.read_only_boxed_clone(),
|
||||
source2.$p.sum.read_only_boxed_clone(),
|
||||
source1.$p.cumulative.read_only_boxed_clone(),
|
||||
source2.$p.cumulative.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from ComputedHeightDerivedFull + TxDerivedFull sources.
|
||||
pub(crate) fn from_full_sources<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedHeightDerivedFull<S1T>,
|
||||
source2: &TxDerivedFull<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
S2T: PartialOrd,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($p:ident) => {
|
||||
LazyBinaryTransformSumCum::from_lazy_stats_aggregate::<F, _, _, _, _>(
|
||||
name, v, &source1.$p, &source2.$p,
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
|
||||
// --- Methods accepting SumCum + LazyLast sources ---
|
||||
|
||||
pub(crate) fn from_computed_lazy_last<F, S2ST>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &LazyFromHeightLast<S2T, S2ST>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
S1T: PartialOrd,
|
||||
S2T: NumericValue,
|
||||
S2ST: ComputedVecValue + schemars::JsonSchema,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($p:ident) => {
|
||||
LazyBinaryTransformSumCum::from_sources_last_sum_raw::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.$p.sum.read_only_boxed_clone(),
|
||||
source1.$p.cumulative.read_only_boxed_clone(),
|
||||
source2.$p.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
//! ComputedHeightDerivedCumFull - LazyLast index views + cumulative (from height) + RollingFull.
|
||||
//!
|
||||
//! For metrics derived from indexer sources (no stored height vec).
|
||||
//! Cumulative gets its own ComputedFromHeightLast so it has LazyLast 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, Exit, ReadableBoxedVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedFromHeightLast, ComputedHeightDerivedLast, NumericValue, RollingFull, WindowStarts,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDerivedCumFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
#[traversable(flatten)]
|
||||
pub last: ComputedHeightDerivedLast<T>,
|
||||
#[traversable(flatten)]
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDerivedCumFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
height_source: ReadableBoxedVec<Height, T>,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let last = ComputedHeightDerivedLast::forced_import(name, height_source, v, indexes);
|
||||
let cumulative = ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
indexes,
|
||||
)?;
|
||||
let rolling = RollingFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
last,
|
||||
cumulative,
|
||||
rolling,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
windows: &WindowStarts<'_>,
|
||||
height_source: &impl ReadableVec<Height, T>,
|
||||
exit: &Exit,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: From<f64> + Default + SubAssign + Copy + Ord,
|
||||
f64: From<T>,
|
||||
{
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, height_source, exit)?;
|
||||
self.rolling.compute(max_from, windows, height_source, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
//! ComputedHeightDerivedFirst - lazy time periods + epochs (first value).
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4, Minute1, Minute10,
|
||||
Minute30, Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableBoxedVec, ReadableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecValue, LazyFirst, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDerivedFirst<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
pub minute1: LazyFirst<Minute1, T, Height, Height>,
|
||||
pub minute5: LazyFirst<Minute5, T, Height, Height>,
|
||||
pub minute10: LazyFirst<Minute10, T, Height, Height>,
|
||||
pub minute30: LazyFirst<Minute30, T, Height, Height>,
|
||||
pub hour1: LazyFirst<Hour1, T, Height, Height>,
|
||||
pub hour4: LazyFirst<Hour4, T, Height, Height>,
|
||||
pub hour12: LazyFirst<Hour12, T, Height, Height>,
|
||||
pub day1: LazyFirst<Day1, T, Height, Height>,
|
||||
pub day3: LazyFirst<Day3, T, Height, Height>,
|
||||
pub week1: LazyFirst<Week1, T, Height, Height>,
|
||||
pub month1: LazyFirst<Month1, T, Height, Height>,
|
||||
pub month3: LazyFirst<Month3, T, Height, Height>,
|
||||
pub month6: LazyFirst<Month6, T, Height, Height>,
|
||||
pub year1: LazyFirst<Year1, T, Height, Height>,
|
||||
pub year10: LazyFirst<Year10, T, Height, Height>,
|
||||
pub halvingepoch: LazyFirst<HalvingEpoch, T, Height, HalvingEpoch>,
|
||||
pub difficultyepoch: LazyFirst<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDerivedFirst<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
name: &str,
|
||||
height_source: ReadableBoxedVec<Height, T>,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($idx:ident) => {
|
||||
LazyFirst::from_height_source(
|
||||
name,
|
||||
v,
|
||||
height_source.clone(),
|
||||
indexes.$idx.first_height.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! epoch {
|
||||
($idx:ident) => {
|
||||
LazyFirst::from_source(
|
||||
name,
|
||||
v,
|
||||
height_source.clone(),
|
||||
indexes.$idx.identity.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: epoch!(halvingepoch),
|
||||
difficultyepoch: epoch!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +1,48 @@
|
||||
//! ComputedHeightDerivedLast - lazy time periods + epochs (last value).
|
||||
//!
|
||||
//! Newtype on `Indexes` with `LazyLast` per field.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4, Minute1, Minute10,
|
||||
Minute30, Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableBoxedVec, ReadableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecValue, LazyLast, NumericValue, SparseLast},
|
||||
indexes_from,
|
||||
internal::{ComputedVecValue, Indexes, LazyLast, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDerivedLast<T>
|
||||
/// All 17 time-period/epoch `LazyLast` vecs, packed as a newtype on `Indexes`.
|
||||
pub type ComputedHeightDerivedLastInner<T> = Indexes<
|
||||
LazyLast<Minute1, T, Height, Height>,
|
||||
LazyLast<Minute5, T, Height, Height>,
|
||||
LazyLast<Minute10, T, Height, Height>,
|
||||
LazyLast<Minute30, T, Height, Height>,
|
||||
LazyLast<Hour1, T, Height, Height>,
|
||||
LazyLast<Hour4, T, Height, Height>,
|
||||
LazyLast<Hour12, T, Height, Height>,
|
||||
LazyLast<Day1, T, Height, Height>,
|
||||
LazyLast<Day3, T, Height, Height>,
|
||||
LazyLast<Week1, T, Height, Height>,
|
||||
LazyLast<Month1, T, Height, Height>,
|
||||
LazyLast<Month3, T, Height, Height>,
|
||||
LazyLast<Month6, T, Height, Height>,
|
||||
LazyLast<Year1, T, Height, Height>,
|
||||
LazyLast<Year10, T, Height, Height>,
|
||||
LazyLast<HalvingEpoch, T, Height, HalvingEpoch>,
|
||||
LazyLast<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
>;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct ComputedHeightDerivedLast<T>(pub ComputedHeightDerivedLastInner<T>)
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
pub minute1: LazyLast<Minute1, T, Height, Height>,
|
||||
pub minute5: LazyLast<Minute5, T, Height, Height>,
|
||||
pub minute10: LazyLast<Minute10, T, Height, Height>,
|
||||
pub minute30: LazyLast<Minute30, T, Height, Height>,
|
||||
pub hour1: LazyLast<Hour1, T, Height, Height>,
|
||||
pub hour4: LazyLast<Hour4, T, Height, Height>,
|
||||
pub hour12: LazyLast<Hour12, T, Height, Height>,
|
||||
pub day1: LazyLast<Day1, T, Height, Height>,
|
||||
pub day3: LazyLast<Day3, T, Height, Height>,
|
||||
pub week1: LazyLast<Week1, T, Height, Height>,
|
||||
pub month1: LazyLast<Month1, T, Height, Height>,
|
||||
pub month3: LazyLast<Month3, T, Height, Height>,
|
||||
pub month6: LazyLast<Month6, T, Height, Height>,
|
||||
pub year1: LazyLast<Year1, T, Height, Height>,
|
||||
pub year10: LazyLast<Year10, T, Height, Height>,
|
||||
pub halvingepoch: LazyLast<HalvingEpoch, T, Height, HalvingEpoch>,
|
||||
pub difficultyepoch: LazyLast<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema;
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
@@ -74,24 +80,6 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: epoch!(halvingepoch),
|
||||
difficultyepoch: epoch!(difficultyepoch),
|
||||
}
|
||||
Self(indexes_from!(period, epoch))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
//! Lazy aggregated Distribution for block-level sources.
|
||||
//! Like LazyHeightDerivedFull but without sum/cumulative (for ratio/percentage metrics).
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Hour1, Hour12, Hour4, Minute1, Minute10, Minute30,
|
||||
Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedHeightDerivedFull, ComputedVecValue, LazyTransformDistribution, NumericValue,
|
||||
};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyHeightDerivedDistribution<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
{
|
||||
pub minute1: LazyTransformDistribution<Minute1, T, S1T>,
|
||||
pub minute5: LazyTransformDistribution<Minute5, T, S1T>,
|
||||
pub minute10: LazyTransformDistribution<Minute10, T, S1T>,
|
||||
pub minute30: LazyTransformDistribution<Minute30, T, S1T>,
|
||||
pub hour1: LazyTransformDistribution<Hour1, T, S1T>,
|
||||
pub hour4: LazyTransformDistribution<Hour4, T, S1T>,
|
||||
pub hour12: LazyTransformDistribution<Hour12, T, S1T>,
|
||||
pub day1: LazyTransformDistribution<Day1, T, S1T>,
|
||||
pub day3: LazyTransformDistribution<Day3, T, S1T>,
|
||||
pub week1: LazyTransformDistribution<Week1, T, S1T>,
|
||||
pub month1: LazyTransformDistribution<Month1, T, S1T>,
|
||||
pub month3: LazyTransformDistribution<Month3, T, S1T>,
|
||||
pub month6: LazyTransformDistribution<Month6, T, S1T>,
|
||||
pub year1: LazyTransformDistribution<Year1, T, S1T>,
|
||||
pub year10: LazyTransformDistribution<Year10, T, S1T>,
|
||||
pub halvingepoch: LazyTransformDistribution<HalvingEpoch, T, S1T>,
|
||||
pub difficultyepoch: LazyTransformDistribution<DifficultyEpoch, T, S1T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyHeightDerivedDistribution<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_derived_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedHeightDerivedFull<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($p:ident) => {
|
||||
LazyTransformDistribution::from_boxed::<F>(
|
||||
name,
|
||||
v,
|
||||
source.$p.average.read_only_boxed_clone(),
|
||||
source.$p.min.read_only_boxed_clone(),
|
||||
source.$p.max.read_only_boxed_clone(),
|
||||
source.$p.percentiles.pct10.read_only_boxed_clone(),
|
||||
source.$p.percentiles.pct25.read_only_boxed_clone(),
|
||||
source.$p.percentiles.median.read_only_boxed_clone(),
|
||||
source.$p.percentiles.pct75.read_only_boxed_clone(),
|
||||
source.$p.percentiles.pct90.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,50 @@
|
||||
//! Lazy aggregated Last for block-level sources.
|
||||
//!
|
||||
//! Newtype on `Indexes` with `LazyTransformLast` per field.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Hour1, Hour12, Hour4, Minute1, Minute10, Minute30,
|
||||
Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, ComputedHeightDerivedLast, ComputedVecValue,
|
||||
LazyBinaryHeightDerivedLast, LazyTransformLast, NumericValue,
|
||||
use crate::{
|
||||
indexes_from,
|
||||
internal::{
|
||||
ComputedFromHeightLast, ComputedHeightDerivedLast, ComputedVecValue, Indexes,
|
||||
LazyBinaryHeightDerivedLast, LazyTransformLast, NumericValue,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyHeightDerivedLast<T, S1T = T>
|
||||
pub type LazyHeightDerivedLastInner<T, S1T> = Indexes<
|
||||
LazyTransformLast<Minute1, T, S1T>,
|
||||
LazyTransformLast<Minute5, T, S1T>,
|
||||
LazyTransformLast<Minute10, T, S1T>,
|
||||
LazyTransformLast<Minute30, T, S1T>,
|
||||
LazyTransformLast<Hour1, T, S1T>,
|
||||
LazyTransformLast<Hour4, T, S1T>,
|
||||
LazyTransformLast<Hour12, T, S1T>,
|
||||
LazyTransformLast<Day1, T, S1T>,
|
||||
LazyTransformLast<Day3, T, S1T>,
|
||||
LazyTransformLast<Week1, T, S1T>,
|
||||
LazyTransformLast<Month1, T, S1T>,
|
||||
LazyTransformLast<Month3, T, S1T>,
|
||||
LazyTransformLast<Month6, T, S1T>,
|
||||
LazyTransformLast<Year1, T, S1T>,
|
||||
LazyTransformLast<Year10, T, S1T>,
|
||||
LazyTransformLast<HalvingEpoch, T, S1T>,
|
||||
LazyTransformLast<DifficultyEpoch, T, S1T>,
|
||||
>;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct LazyHeightDerivedLast<T, S1T = T>(pub LazyHeightDerivedLastInner<T, S1T>)
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
{
|
||||
pub minute1: LazyTransformLast<Minute1, T, S1T>,
|
||||
pub minute5: LazyTransformLast<Minute5, T, S1T>,
|
||||
pub minute10: LazyTransformLast<Minute10, T, S1T>,
|
||||
pub minute30: LazyTransformLast<Minute30, T, S1T>,
|
||||
pub hour1: LazyTransformLast<Hour1, T, S1T>,
|
||||
pub hour4: LazyTransformLast<Hour4, T, S1T>,
|
||||
pub hour12: LazyTransformLast<Hour12, T, S1T>,
|
||||
pub day1: LazyTransformLast<Day1, T, S1T>,
|
||||
pub day3: LazyTransformLast<Day3, T, S1T>,
|
||||
pub week1: LazyTransformLast<Week1, T, S1T>,
|
||||
pub month1: LazyTransformLast<Month1, T, S1T>,
|
||||
pub month3: LazyTransformLast<Month3, T, S1T>,
|
||||
pub month6: LazyTransformLast<Month6, T, S1T>,
|
||||
pub year1: LazyTransformLast<Year1, T, S1T>,
|
||||
pub year10: LazyTransformLast<Year10, T, S1T>,
|
||||
pub halvingepoch: LazyTransformLast<HalvingEpoch, T, S1T>,
|
||||
pub difficultyepoch: LazyTransformLast<DifficultyEpoch, T, S1T>,
|
||||
}
|
||||
S1T: ComputedVecValue;
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
@@ -62,25 +69,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
Self(indexes_from!(period))
|
||||
}
|
||||
|
||||
pub(crate) fn from_derived_computed<F: UnaryTransform<S1T, T>>(
|
||||
@@ -99,25 +88,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
Self(indexes_from!(period))
|
||||
}
|
||||
|
||||
/// Create by unary-transforming a LazyHeightDerivedLast source.
|
||||
@@ -138,25 +109,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
Self(indexes_from!(period))
|
||||
}
|
||||
|
||||
/// Create by unary-transforming a LazyBinaryHeightDerivedLast source.
|
||||
@@ -178,25 +131,6 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
Self(indexes_from!(period))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
//! Lazy aggregated Sum for block-level sources.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Hour1, Hour12, Hour4, Minute1, Minute10, Minute30,
|
||||
Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedHeightDerivedSum, ComputedVecValue, LazyTransformSum, NumericValue,
|
||||
};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyHeightDerivedSum<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
{
|
||||
pub minute1: LazyTransformSum<Minute1, T, S1T>,
|
||||
pub minute5: LazyTransformSum<Minute5, T, S1T>,
|
||||
pub minute10: LazyTransformSum<Minute10, T, S1T>,
|
||||
pub minute30: LazyTransformSum<Minute30, T, S1T>,
|
||||
pub hour1: LazyTransformSum<Hour1, T, S1T>,
|
||||
pub hour4: LazyTransformSum<Hour4, T, S1T>,
|
||||
pub hour12: LazyTransformSum<Hour12, T, S1T>,
|
||||
pub day1: LazyTransformSum<Day1, T, S1T>,
|
||||
pub day3: LazyTransformSum<Day3, T, S1T>,
|
||||
pub week1: LazyTransformSum<Week1, T, S1T>,
|
||||
pub month1: LazyTransformSum<Month1, T, S1T>,
|
||||
pub month3: LazyTransformSum<Month3, T, S1T>,
|
||||
pub month6: LazyTransformSum<Month6, T, S1T>,
|
||||
pub year1: LazyTransformSum<Year1, T, S1T>,
|
||||
pub year10: LazyTransformSum<Year10, T, S1T>,
|
||||
pub halvingepoch: LazyTransformSum<HalvingEpoch, T, S1T>,
|
||||
pub difficultyepoch: LazyTransformSum<DifficultyEpoch, T, S1T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyHeightDerivedSum<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_derived_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedHeightDerivedSum<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($p:ident) => {
|
||||
LazyTransformSum::from_boxed::<F>(name, v, source.$p.read_only_boxed_clone())
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
//! ComputedHeightDerivedMax - lazy time periods + epochs (max value).
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4, Minute1, Minute10,
|
||||
Minute30, Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableBoxedVec, ReadableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecValue, LazyMax, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDerivedMax<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
pub minute1: LazyMax<Minute1, T, Height, Height>,
|
||||
pub minute5: LazyMax<Minute5, T, Height, Height>,
|
||||
pub minute10: LazyMax<Minute10, T, Height, Height>,
|
||||
pub minute30: LazyMax<Minute30, T, Height, Height>,
|
||||
pub hour1: LazyMax<Hour1, T, Height, Height>,
|
||||
pub hour4: LazyMax<Hour4, T, Height, Height>,
|
||||
pub hour12: LazyMax<Hour12, T, Height, Height>,
|
||||
pub day1: LazyMax<Day1, T, Height, Height>,
|
||||
pub day3: LazyMax<Day3, T, Height, Height>,
|
||||
pub week1: LazyMax<Week1, T, Height, Height>,
|
||||
pub month1: LazyMax<Month1, T, Height, Height>,
|
||||
pub month3: LazyMax<Month3, T, Height, Height>,
|
||||
pub month6: LazyMax<Month6, T, Height, Height>,
|
||||
pub year1: LazyMax<Year1, T, Height, Height>,
|
||||
pub year10: LazyMax<Year10, T, Height, Height>,
|
||||
pub halvingepoch: LazyMax<HalvingEpoch, T, Height, HalvingEpoch>,
|
||||
pub difficultyepoch: LazyMax<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDerivedMax<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
name: &str,
|
||||
height_source: ReadableBoxedVec<Height, T>,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($idx:ident) => {
|
||||
LazyMax::from_height_source_raw(
|
||||
name,
|
||||
v,
|
||||
height_source.clone(),
|
||||
indexes.$idx.first_height.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! epoch {
|
||||
($idx:ident) => {
|
||||
LazyMax::from_source_raw(
|
||||
name,
|
||||
v,
|
||||
height_source.clone(),
|
||||
indexes.$idx.identity.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: epoch!(halvingepoch),
|
||||
difficultyepoch: epoch!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
//! ComputedHeightDerivedMin - lazy time periods + epochs (min value).
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4, Minute1, Minute10,
|
||||
Minute30, Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableBoxedVec, ReadableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecValue, LazyMin, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDerivedMin<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
pub minute1: LazyMin<Minute1, T, Height, Height>,
|
||||
pub minute5: LazyMin<Minute5, T, Height, Height>,
|
||||
pub minute10: LazyMin<Minute10, T, Height, Height>,
|
||||
pub minute30: LazyMin<Minute30, T, Height, Height>,
|
||||
pub hour1: LazyMin<Hour1, T, Height, Height>,
|
||||
pub hour4: LazyMin<Hour4, T, Height, Height>,
|
||||
pub hour12: LazyMin<Hour12, T, Height, Height>,
|
||||
pub day1: LazyMin<Day1, T, Height, Height>,
|
||||
pub day3: LazyMin<Day3, T, Height, Height>,
|
||||
pub week1: LazyMin<Week1, T, Height, Height>,
|
||||
pub month1: LazyMin<Month1, T, Height, Height>,
|
||||
pub month3: LazyMin<Month3, T, Height, Height>,
|
||||
pub month6: LazyMin<Month6, T, Height, Height>,
|
||||
pub year1: LazyMin<Year1, T, Height, Height>,
|
||||
pub year10: LazyMin<Year10, T, Height, Height>,
|
||||
pub halvingepoch: LazyMin<HalvingEpoch, T, Height, HalvingEpoch>,
|
||||
pub difficultyepoch: LazyMin<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDerivedMin<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
name: &str,
|
||||
height_source: ReadableBoxedVec<Height, T>,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($idx:ident) => {
|
||||
LazyMin::from_height_source_raw(
|
||||
name,
|
||||
v,
|
||||
height_source.clone(),
|
||||
indexes.$idx.first_height.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! epoch {
|
||||
($idx:ident) => {
|
||||
LazyMin::from_source_raw(
|
||||
name,
|
||||
v,
|
||||
height_source.clone(),
|
||||
indexes.$idx.identity.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: epoch!(halvingepoch),
|
||||
difficultyepoch: epoch!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,21 @@
|
||||
mod binary_last;
|
||||
mod binary_sum;
|
||||
mod binary_sum_cum;
|
||||
mod cum_full;
|
||||
mod distribution;
|
||||
mod first;
|
||||
mod full;
|
||||
mod last;
|
||||
mod lazy_distribution;
|
||||
mod lazy_full;
|
||||
mod lazy_last;
|
||||
mod lazy_sum;
|
||||
mod lazy_sum_cum;
|
||||
mod max;
|
||||
mod min;
|
||||
mod ohlc;
|
||||
mod split_ohlc;
|
||||
mod sum;
|
||||
mod sum_cum;
|
||||
mod value_lazy_last;
|
||||
|
||||
pub use binary_last::*;
|
||||
pub use binary_sum::*;
|
||||
pub use binary_sum_cum::*;
|
||||
pub use cum_full::*;
|
||||
pub use distribution::*;
|
||||
pub use first::*;
|
||||
pub use full::*;
|
||||
pub use last::*;
|
||||
pub use lazy_distribution::*;
|
||||
pub use lazy_full::*;
|
||||
pub use lazy_last::*;
|
||||
pub use lazy_sum::*;
|
||||
pub use lazy_sum_cum::*;
|
||||
pub use max::*;
|
||||
pub use min::*;
|
||||
pub use ohlc::*;
|
||||
pub use split_ohlc::*;
|
||||
pub use sum::*;
|
||||
pub use sum_cum::*;
|
||||
pub use value_lazy_last::*;
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
//! Lazy OHLC period groupings derived from height-level data.
|
||||
//!
|
||||
//! Each period's OHLC is computed lazily in a single pass over the source range:
|
||||
//! open = first, high = max, low = min, close = last.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4, Minute1, Minute10,
|
||||
Minute30, Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableBoxedVec, ReadableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecValue, LazyOHLC, OHLCRecord},
|
||||
};
|
||||
|
||||
/// Lazy bundled OHLC vecs for all periods, derived from height-level data.
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDerivedOHLC<OHLC>
|
||||
where
|
||||
OHLC: OHLCRecord + 'static,
|
||||
{
|
||||
pub minute1: LazyOHLC<Minute1, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub minute5: LazyOHLC<Minute5, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub minute10: LazyOHLC<Minute10, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub minute30: LazyOHLC<Minute30, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub hour1: LazyOHLC<Hour1, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub hour4: LazyOHLC<Hour4, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub hour12: LazyOHLC<Hour12, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub day1: LazyOHLC<Day1, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub day3: LazyOHLC<Day3, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub week1: LazyOHLC<Week1, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub month1: LazyOHLC<Month1, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub month3: LazyOHLC<Month3, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub month6: LazyOHLC<Month6, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub year1: LazyOHLC<Year1, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub year10: LazyOHLC<Year10, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub halvingepoch: LazyOHLC<HalvingEpoch, OHLC, Height, OHLC::Inner, Height>,
|
||||
pub difficultyepoch: LazyOHLC<DifficultyEpoch, OHLC, Height, OHLC::Inner, Height>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<OHLC> ComputedHeightDerivedOHLC<OHLC>
|
||||
where
|
||||
OHLC: OHLCRecord + 'static,
|
||||
OHLC::Inner: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
height_source: ReadableBoxedVec<Height, OHLC::Inner>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($idx:ident) => {
|
||||
LazyOHLC::from_height_source(
|
||||
name,
|
||||
v,
|
||||
height_source.clone(),
|
||||
indexes.$idx.first_height.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//! OHLC split into separate First/Last/Max/Min period groupings derived from height-level data.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::ReadableBoxedVec;
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedHeightDerivedFirst, ComputedHeightDerivedLast, ComputedHeightDerivedMax,
|
||||
ComputedHeightDerivedMin, ComputedVecValue, NumericValue,
|
||||
},
|
||||
};
|
||||
|
||||
/// Split OHLC vecs for all periods, derived from height data.
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ComputedHeightDerivedSplitOHLC<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
pub open: ComputedHeightDerivedFirst<T>,
|
||||
pub high: ComputedHeightDerivedMax<T>,
|
||||
pub low: ComputedHeightDerivedMin<T>,
|
||||
pub close: ComputedHeightDerivedLast<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDerivedSplitOHLC<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
height_source: ReadableBoxedVec<Height, T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
open: ComputedHeightDerivedFirst::forced_import(&format!("{name}_open"), height_source.clone(), v, indexes),
|
||||
high: ComputedHeightDerivedMax::forced_import(&format!("{name}_high"), height_source.clone(), v, indexes),
|
||||
low: ComputedHeightDerivedMin::forced_import(&format!("{name}_low"), height_source.clone(), v, indexes),
|
||||
close: ComputedHeightDerivedLast::forced_import(&format!("{name}_close"), height_source, v, indexes),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
//! ComputedHeightDerivedSum - lazy time periods + epochs.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4, Minute1, Minute10,
|
||||
Minute30, Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableBoxedVec, ReadableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecValue, LazySum, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDerivedSum<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
pub minute1: LazySum<Minute1, T, Height, Height>,
|
||||
pub minute5: LazySum<Minute5, T, Height, Height>,
|
||||
pub minute10: LazySum<Minute10, T, Height, Height>,
|
||||
pub minute30: LazySum<Minute30, T, Height, Height>,
|
||||
pub hour1: LazySum<Hour1, T, Height, Height>,
|
||||
pub hour4: LazySum<Hour4, T, Height, Height>,
|
||||
pub hour12: LazySum<Hour12, T, Height, Height>,
|
||||
pub day1: LazySum<Day1, T, Height, Height>,
|
||||
pub day3: LazySum<Day3, T, Height, Height>,
|
||||
pub week1: LazySum<Week1, T, Height, Height>,
|
||||
pub month1: LazySum<Month1, T, Height, Height>,
|
||||
pub month3: LazySum<Month3, T, Height, Height>,
|
||||
pub month6: LazySum<Month6, T, Height, Height>,
|
||||
pub year1: LazySum<Year1, T, Height, Height>,
|
||||
pub year10: LazySum<Year10, T, Height, Height>,
|
||||
pub halvingepoch: LazySum<HalvingEpoch, T, Height, HalvingEpoch>,
|
||||
pub difficultyepoch: LazySum<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDerivedSum<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
name: &str,
|
||||
height_source: ReadableBoxedVec<Height, T>,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($idx:ident) => {
|
||||
LazySum::from_height_source_raw(
|
||||
name,
|
||||
v,
|
||||
height_source.clone(),
|
||||
indexes.$idx.first_height.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! epoch {
|
||||
($idx:ident) => {
|
||||
LazySum::from_source_raw(
|
||||
name,
|
||||
v,
|
||||
height_source.clone(),
|
||||
indexes.$idx.identity.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: epoch!(halvingepoch),
|
||||
difficultyepoch: epoch!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,163 +0,0 @@
|
||||
//! TxDerivedFull - aggregates from TxIndex to height Full + lazy time periods + epochs.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4, Minute1, Minute10,
|
||||
Minute30, Minute5, Month1, Month3, Month6, TxIndex, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes, ComputeIndexes,
|
||||
internal::{ComputedVecValue, Full, LazyFull, NumericValue},
|
||||
};
|
||||
|
||||
/// Aggregates from TxIndex to height/time periods with full stats.
|
||||
#[derive(Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct TxDerivedFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
pub height: Full<Height, T, M>,
|
||||
pub minute1: LazyFull<Minute1, T, Height, Height>,
|
||||
pub minute5: LazyFull<Minute5, T, Height, Height>,
|
||||
pub minute10: LazyFull<Minute10, T, Height, Height>,
|
||||
pub minute30: LazyFull<Minute30, T, Height, Height>,
|
||||
pub hour1: LazyFull<Hour1, T, Height, Height>,
|
||||
pub hour4: LazyFull<Hour4, T, Height, Height>,
|
||||
pub hour12: LazyFull<Hour12, T, Height, Height>,
|
||||
pub day1: LazyFull<Day1, T, Height, Height>,
|
||||
pub day3: LazyFull<Day3, T, Height, Height>,
|
||||
pub week1: LazyFull<Week1, T, Height, Height>,
|
||||
pub month1: LazyFull<Month1, T, Height, Height>,
|
||||
pub month3: LazyFull<Month3, T, Height, Height>,
|
||||
pub month6: LazyFull<Month6, T, Height, Height>,
|
||||
pub year1: LazyFull<Year1, T, Height, Height>,
|
||||
pub year10: LazyFull<Year10, T, Height, Height>,
|
||||
pub halvingepoch: LazyFull<HalvingEpoch, T, Height, HalvingEpoch>,
|
||||
pub difficultyepoch: LazyFull<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE;
|
||||
|
||||
impl<T> TxDerivedFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let height = Full::forced_import(db, name, version + VERSION)?;
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($idx:ident) => {
|
||||
LazyFull::from_height_source(
|
||||
name,
|
||||
v,
|
||||
height.boxed_sum(),
|
||||
height.boxed_cumulative(),
|
||||
indexes.$idx.first_height.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! epoch {
|
||||
($idx:ident) => {
|
||||
LazyFull::from_stats_aggregate(
|
||||
name,
|
||||
v,
|
||||
height.boxed_average(),
|
||||
height.boxed_min(),
|
||||
height.boxed_max(),
|
||||
height.boxed_sum(),
|
||||
height.boxed_cumulative(),
|
||||
height.boxed_average(),
|
||||
indexes.$idx.identity.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
let minute1 = period!(minute1);
|
||||
let minute5 = period!(minute5);
|
||||
let minute10 = period!(minute10);
|
||||
let minute30 = period!(minute30);
|
||||
let hour1 = period!(hour1);
|
||||
let hour4 = period!(hour4);
|
||||
let hour12 = period!(hour12);
|
||||
let day1 = period!(day1);
|
||||
let day3 = period!(day3);
|
||||
let week1 = period!(week1);
|
||||
let month1 = period!(month1);
|
||||
let month3 = period!(month3);
|
||||
let month6 = period!(month6);
|
||||
let year1 = period!(year1);
|
||||
let year10 = period!(year10);
|
||||
let halvingepoch = epoch!(halvingepoch);
|
||||
let difficultyepoch = epoch!(difficultyepoch);
|
||||
|
||||
Ok(Self {
|
||||
height,
|
||||
minute1,
|
||||
minute5,
|
||||
minute10,
|
||||
minute30,
|
||||
hour1,
|
||||
hour4,
|
||||
hour12,
|
||||
day1,
|
||||
day3,
|
||||
week1,
|
||||
month1,
|
||||
month3,
|
||||
month6,
|
||||
year1,
|
||||
year10,
|
||||
halvingepoch,
|
||||
difficultyepoch,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn derive_from(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
txindex_source: &impl ReadableVec<TxIndex, T>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.derive_from_with_skip(indexer, indexes, starting_indexes, txindex_source, exit, 0)
|
||||
}
|
||||
|
||||
/// Derive from source, skipping first N transactions per block from all calculations.
|
||||
///
|
||||
/// Use `skip_count: 1` to exclude coinbase transactions from fee/feerate stats.
|
||||
pub(crate) fn derive_from_with_skip(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
txindex_source: &impl ReadableVec<TxIndex, T>,
|
||||
exit: &Exit,
|
||||
skip_count: usize,
|
||||
) -> Result<()> {
|
||||
self.height.compute_with_skip(
|
||||
starting_indexes.height,
|
||||
txindex_source,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexes.height.txindex_count,
|
||||
exit,
|
||||
skip_count,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
//! Lazy transform of TxDerivedFull.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4, Minute1, Minute10,
|
||||
Minute30, Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{ComputedVecValue, TxDerivedFull, LazyTransformFull};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyTxDerivedFull<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
{
|
||||
pub height: LazyTransformFull<Height, T, S1T>,
|
||||
pub minute1: LazyTransformFull<Minute1, T, S1T>,
|
||||
pub minute5: LazyTransformFull<Minute5, T, S1T>,
|
||||
pub minute10: LazyTransformFull<Minute10, T, S1T>,
|
||||
pub minute30: LazyTransformFull<Minute30, T, S1T>,
|
||||
pub hour1: LazyTransformFull<Hour1, T, S1T>,
|
||||
pub hour4: LazyTransformFull<Hour4, T, S1T>,
|
||||
pub hour12: LazyTransformFull<Hour12, T, S1T>,
|
||||
pub day1: LazyTransformFull<Day1, T, S1T>,
|
||||
pub day3: LazyTransformFull<Day3, T, S1T>,
|
||||
pub week1: LazyTransformFull<Week1, T, S1T>,
|
||||
pub month1: LazyTransformFull<Month1, T, S1T>,
|
||||
pub month3: LazyTransformFull<Month3, T, S1T>,
|
||||
pub month6: LazyTransformFull<Month6, T, S1T>,
|
||||
pub year1: LazyTransformFull<Year1, T, S1T>,
|
||||
pub year10: LazyTransformFull<Year10, T, S1T>,
|
||||
pub halvingepoch: LazyTransformFull<HalvingEpoch, T, S1T>,
|
||||
pub difficultyepoch: LazyTransformFull<DifficultyEpoch, T, S1T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyTxDerivedFull<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &TxDerivedFull<S1T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($p:ident) => {
|
||||
LazyTransformFull::from_boxed::<F>(
|
||||
name,
|
||||
v,
|
||||
source.$p.average.read_only_boxed_clone(),
|
||||
source.$p.min.read_only_boxed_clone(),
|
||||
source.$p.max.read_only_boxed_clone(),
|
||||
source.$p.percentiles.pct10.read_only_boxed_clone(),
|
||||
source.$p.percentiles.pct25.read_only_boxed_clone(),
|
||||
source.$p.percentiles.median.read_only_boxed_clone(),
|
||||
source.$p.percentiles.pct75.read_only_boxed_clone(),
|
||||
source.$p.percentiles.pct90.read_only_boxed_clone(),
|
||||
source.$p.sum.read_only_boxed_clone(),
|
||||
source.$p.cumulative.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
height: LazyTransformFull::from_stats_aggregate::<F>(name, v, &source.height),
|
||||
minute1: period!(minute1),
|
||||
minute5: period!(minute5),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halvingepoch: period!(halvingepoch),
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,3 @@
|
||||
mod distribution;
|
||||
mod full;
|
||||
mod lazy_full;
|
||||
mod value_full;
|
||||
|
||||
pub use distribution::*;
|
||||
pub use full::*;
|
||||
pub use lazy_full::*;
|
||||
pub use value_full::*;
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
//! Value type for Full pattern from TxIndex.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Sats, TxIndex, Version};
|
||||
use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{LazyTxDerivedFull, SatsToBitcoin, TxDerivedFull, ValueDollarsFromTxFull},
|
||||
prices,
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ValueTxDerivedFull<M: StorageMode = Rw> {
|
||||
pub sats: TxDerivedFull<Sats, M>,
|
||||
pub btc: LazyTxDerivedFull<Bitcoin, Sats>,
|
||||
pub usd: ValueDollarsFromTxFull<M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl ValueTxDerivedFull {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
indexer: &Indexer,
|
||||
prices: &prices::Vecs,
|
||||
sats_txindex: &impl ReadableCloneableVec<TxIndex, Sats>,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = TxDerivedFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
let btc =
|
||||
LazyTxDerivedFull::from_computed::<SatsToBitcoin>(&format!("{name}_btc"), v, &sats);
|
||||
|
||||
let usd = ValueDollarsFromTxFull::forced_import(
|
||||
db,
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
indexes,
|
||||
&sats.height,
|
||||
prices.usd.price.read_only_boxed_clone(),
|
||||
sats_txindex.read_only_boxed_clone(),
|
||||
indexer.vecs.transactions.height.read_only_boxed_clone(),
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
sats,
|
||||
btc,
|
||||
usd,
|
||||
})
|
||||
}
|
||||
|
||||
/// Derive from source, skipping first N transactions per block from all calculations.
|
||||
///
|
||||
/// Use `skip_count: 1` to exclude coinbase transactions from fee/feerate stats.
|
||||
pub(crate) fn derive_from_with_skip(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
txindex_source: &impl ReadableVec<TxIndex, Sats>,
|
||||
exit: &Exit,
|
||||
skip_count: usize,
|
||||
) -> Result<()> {
|
||||
self.sats.derive_from_with_skip(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
txindex_source,
|
||||
exit,
|
||||
skip_count,
|
||||
)?;
|
||||
|
||||
self.usd.derive_from(indexes, starting_indexes, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user