global: snapshot

This commit is contained in:
nym21
2026-01-13 01:18:27 +01:00
parent 5ffb66c0dc
commit 670aa95494
35 changed files with 10804 additions and 6166 deletions

View File

@@ -1,19 +1,19 @@
mod average;
mod distribution;
mod first;
mod full;
mod last;
mod max;
mod min;
mod spread;
mod sum;
mod sum_cum;
pub use average::*;
pub use distribution::*;
pub use first::*;
pub use full::*;
pub use last::*;
pub use max::*;
pub use min::*;
pub use spread::*;
pub use sum::*;
pub use sum_cum::*;

View File

@@ -7,27 +7,27 @@ use brk_types::{
use schemars::JsonSchema;
use vecdb::{IterableBoxedVec, IterableCloneableVec};
use crate::{indexes, internal::LazyDistribution};
use crate::{indexes, internal::LazySpread};
use crate::internal::ComputedVecValue;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyDateDerivedDistribution<T>
pub struct LazyDateDerivedSpread<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
pub weekindex: LazyDistribution<WeekIndex, T, DateIndex, WeekIndex>,
pub monthindex: LazyDistribution<MonthIndex, T, DateIndex, MonthIndex>,
pub quarterindex: LazyDistribution<QuarterIndex, T, DateIndex, QuarterIndex>,
pub semesterindex: LazyDistribution<SemesterIndex, T, DateIndex, SemesterIndex>,
pub yearindex: LazyDistribution<YearIndex, T, DateIndex, YearIndex>,
pub decadeindex: LazyDistribution<DecadeIndex, T, DateIndex, DecadeIndex>,
pub weekindex: LazySpread<WeekIndex, T, DateIndex, WeekIndex>,
pub monthindex: LazySpread<MonthIndex, T, DateIndex, MonthIndex>,
pub quarterindex: LazySpread<QuarterIndex, T, DateIndex, QuarterIndex>,
pub semesterindex: LazySpread<SemesterIndex, T, DateIndex, SemesterIndex>,
pub yearindex: LazySpread<YearIndex, T, DateIndex, YearIndex>,
pub decadeindex: LazySpread<DecadeIndex, T, DateIndex, DecadeIndex>,
}
const VERSION: Version = Version::ZERO;
impl<T> LazyDateDerivedDistribution<T>
impl<T> LazyDateDerivedSpread<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{
@@ -44,8 +44,12 @@ where
macro_rules! period {
($idx:ident) => {
LazyDistribution::from_distribution(
name, v, average_source.clone(), min_source.clone(), max_source.clone(),
LazySpread::from_distribution(
name,
v,
average_source.clone(),
min_source.clone(),
max_source.clone(),
indexes.$idx.identity.boxed_clone(),
)
};

View File

@@ -0,0 +1,69 @@
//! Lazy transform for Distribution date sources.
//! Like LazyFromDateFull but without sum/cumulative (for ratio/percentage metrics).
use brk_traversable::Traversable;
use brk_types::{
DateIndex, DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex, Version, WeekIndex, YearIndex,
};
use schemars::JsonSchema;
use vecdb::{IterableCloneableVec, UnaryTransform};
use crate::internal::{
ComputedVecValue, Full, LazyDateDerivedFull, LazyTransformDistribution, LazyTransformSpread,
};
const VERSION: Version = Version::ZERO;
/// Distribution stats across date periods. Has average, min, max, percentiles but no sum/cumulative.
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyFromDateDistribution<T, S1T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
{
pub dateindex: LazyTransformDistribution<DateIndex, T, S1T>,
pub weekindex: LazyTransformSpread<WeekIndex, T, S1T>,
pub monthindex: LazyTransformSpread<MonthIndex, T, S1T>,
pub quarterindex: LazyTransformSpread<QuarterIndex, T, S1T>,
pub semesterindex: LazyTransformSpread<SemesterIndex, T, S1T>,
pub yearindex: LazyTransformSpread<YearIndex, T, S1T>,
pub decadeindex: LazyTransformSpread<DecadeIndex, T, S1T>,
}
impl<T, S1T> LazyFromDateDistribution<T, S1T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: ComputedVecValue + JsonSchema,
{
pub fn from_full<F: UnaryTransform<S1T, T>>(
name: &str,
version: Version,
dateindex: &Full<DateIndex, S1T>,
source: &LazyDateDerivedFull<S1T>,
) -> Self {
let v = version + VERSION;
macro_rules! period {
($p:ident) => {
LazyTransformSpread::from_boxed::<F>(
name,
v,
source.$p.average.boxed_clone(),
source.$p.min.boxed_clone(),
source.$p.max.boxed_clone(),
)
};
}
Self {
dateindex: LazyTransformDistribution::from_stats_aggregate::<F>(name, v, dateindex),
weekindex: period!(weekindex),
monthindex: period!(monthindex),
quarterindex: period!(quarterindex),
semesterindex: period!(semesterindex),
yearindex: period!(yearindex),
decadeindex: period!(decadeindex),
}
}
}

View File

@@ -5,6 +5,7 @@ mod binary_sum_cum;
mod first;
mod last;
mod lazy;
mod lazy_distribution;
mod lazy_full;
mod lazy_last;
mod lazy_sum;
@@ -25,6 +26,7 @@ pub use binary_sum_cum::*;
pub use first::*;
pub use last::*;
pub use lazy::*;
pub use lazy_distribution::*;
pub use lazy_full::*;
pub use lazy_last::*;
pub use lazy_sum::*;

View File

@@ -0,0 +1,50 @@
//! 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::{IterableBoxedVec, 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: LazyHeightDerivedDistribution<T, S1T>,
}
const VERSION: Version = Version::ZERO;
impl<T, S1T> LazyFromHeightTransformDistribution<T, S1T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: ComputedVecValue + JsonSchema,
{
pub fn from_derived<F: UnaryTransform<S1T, T>>(
name: &str,
version: Version,
height_source: IterableBoxedVec<Height, S1T>,
source: &ComputedHeightDerivedFull<S1T>,
) -> Self
where
S1T: NumericValue,
{
let v = version + VERSION;
Self {
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
rest: LazyHeightDerivedDistribution::from_derived_computed::<F>(name, v, source),
}
}
}

View File

@@ -6,6 +6,7 @@ mod full;
mod last;
mod lazy_distribution;
mod lazy_full;
mod lazy_transform_distribution;
mod lazy_binary_computed_full;
mod lazy_binary_computed_last;
mod lazy_binary_computed_sum;
@@ -36,6 +37,7 @@ pub use full::*;
pub use last::*;
pub use lazy_distribution::*;
pub use lazy_full::*;
pub use lazy_transform_distribution::*;
pub use lazy_binary_computed_full::*;
pub use lazy_binary_computed_last::*;
pub use lazy_binary_computed_sum::*;

View File

@@ -10,9 +10,7 @@ use vecdb::{Database, Exit, IterableBoxedVec, IterableCloneableVec, IterableVec}
use crate::{
ComputeIndexes, indexes,
internal::{
ComputedVecValue, LazyDateDerivedDistribution, Distribution, LazyDistribution, NumericValue,
},
internal::{ComputedVecValue, Distribution, LazyDateDerivedSpread, LazySpread, NumericValue},
};
#[derive(Clone, Deref, DerefMut, Traversable)]
@@ -24,8 +22,8 @@ where
pub dateindex: Distribution<DateIndex, T>,
#[deref]
#[deref_mut]
pub dates: LazyDateDerivedDistribution<T>,
pub difficultyepoch: LazyDistribution<DifficultyEpoch, T, Height, DifficultyEpoch>,
pub dates: LazyDateDerivedSpread<T>,
pub difficultyepoch: LazySpread<DifficultyEpoch, T, Height, DifficultyEpoch>,
}
const VERSION: Version = Version::ZERO;
@@ -44,7 +42,7 @@ where
let dateindex = Distribution::forced_import(db, name, version + VERSION)?;
let v = version + VERSION;
let dates = LazyDateDerivedDistribution::from_sources(
let dates = LazyDateDerivedSpread::from_sources(
name,
v,
dateindex.boxed_average(),
@@ -53,7 +51,7 @@ where
indexes,
);
let difficultyepoch = LazyDistribution::from_distribution(
let difficultyepoch = LazySpread::from_distribution(
name,
v,
height_source.boxed_clone(),

View File

@@ -0,0 +1,82 @@
//! Lazy aggregated Distribution for block-level sources.
//! Like LazyHeightDerivedFull but without sum/cumulative (for ratio/percentage metrics).
use brk_traversable::Traversable;
use brk_types::{DateIndex, DifficultyEpoch, Version};
use derive_more::{Deref, DerefMut};
use schemars::JsonSchema;
use vecdb::{IterableCloneableVec, UnaryTransform};
use crate::internal::{
ComputedHeightDerivedFull, ComputedVecValue, Full, LazyDateDerivedFull,
LazyFromDateDistribution, LazyTransformSpread, NumericValue,
};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyHeightDerivedDistribution<T, S1T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
{
#[deref]
#[deref_mut]
pub dates: LazyFromDateDistribution<T, S1T>,
pub difficultyepoch: LazyTransformSpread<DifficultyEpoch, T, S1T>,
}
const VERSION: Version = Version::ZERO;
impl<T, S1T> LazyHeightDerivedDistribution<T, S1T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: ComputedVecValue + JsonSchema,
{
pub fn from_computed<F: UnaryTransform<S1T, T>>(
name: &str,
version: Version,
dateindex: &Full<DateIndex, S1T>,
periods: &LazyDateDerivedFull<S1T>,
difficultyepoch: &crate::internal::LazyFull<
DifficultyEpoch,
S1T,
brk_types::Height,
DifficultyEpoch,
>,
) -> Self {
let v = version + VERSION;
Self {
dates: LazyFromDateDistribution::from_full::<F>(name, v, dateindex, periods),
difficultyepoch: LazyTransformSpread::from_boxed::<F>(
name,
v,
difficultyepoch.average.boxed_clone(),
difficultyepoch.min.boxed_clone(),
difficultyepoch.max.boxed_clone(),
),
}
}
pub fn from_derived_computed<F: UnaryTransform<S1T, T>>(
name: &str,
version: Version,
source: &ComputedHeightDerivedFull<S1T>,
) -> Self
where
S1T: NumericValue,
{
let v = version + VERSION;
Self {
dates: LazyFromDateDistribution::from_full::<F>(name, v, &source.dateindex, &source.dates),
difficultyepoch: LazyTransformSpread::from_boxed::<F>(
name,
v,
source.difficultyepoch.average.boxed_clone(),
source.difficultyepoch.min.boxed_clone(),
source.difficultyepoch.max.boxed_clone(),
),
}
}
}

View File

@@ -5,6 +5,7 @@ mod distribution;
mod first;
mod full;
mod last;
mod lazy_distribution;
mod lazy_full;
mod lazy_last;
mod lazy_sum;
@@ -20,6 +21,7 @@ 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::*;

View File

@@ -16,7 +16,7 @@ use vecdb::{CollectableVec, Database, Exit, IterableCloneableVec};
use crate::{
ComputeIndexes, indexes,
internal::{
ComputedVecValue, LazyDateDerivedDistribution, Distribution, LazyDistribution, MinMaxAverage,
ComputedVecValue, Distribution, LazyDateDerivedSpread, LazySpread, MinMaxAverage,
NumericValue,
},
};
@@ -28,12 +28,12 @@ where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
pub height: Distribution<Height, T>,
pub difficultyepoch: LazyDistribution<DifficultyEpoch, T, Height, DifficultyEpoch>,
pub difficultyepoch: LazySpread<DifficultyEpoch, T, Height, DifficultyEpoch>,
pub dateindex: MinMaxAverage<DateIndex, T>,
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub dates: LazyDateDerivedDistribution<T>,
pub dates: LazyDateDerivedSpread<T>,
}
const VERSION: Version = Version::ZERO;
@@ -53,7 +53,7 @@ where
let v = version + VERSION;
let difficultyepoch =
LazyDistribution::<DifficultyEpoch, T, Height, DifficultyEpoch>::from_distribution(
LazySpread::<DifficultyEpoch, T, Height, DifficultyEpoch>::from_distribution(
name,
v,
height.boxed_average(),
@@ -62,7 +62,7 @@ where
indexes.difficultyepoch.identity.boxed_clone(),
);
let dates = LazyDateDerivedDistribution::from_sources(
let dates = LazyDateDerivedSpread::from_sources(
name,
v,
dateindex.boxed_average(),