mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 15:19:58 -07:00
global: snapshot
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
//! These functions replace the Option-based compute logic in flexible builders.
|
||||
//! Each function takes optional mutable references and computes only for Some() vecs.
|
||||
|
||||
use brk_error::{Error, Result};
|
||||
use brk_error::Result;
|
||||
use brk_types::{CheckedSub, StoredU64};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{
|
||||
@@ -28,6 +28,10 @@ fn validate_and_start<I: VecIndex, T: ComputedVecValue + JsonSchema>(
|
||||
///
|
||||
/// This function computes all requested aggregations in a single pass when possible,
|
||||
/// optimizing for the common case where multiple aggregations are needed.
|
||||
///
|
||||
/// The `skip_count` parameter allows skipping the first N items from ALL calculations.
|
||||
/// This is useful for excluding coinbase transactions (which have 0 fee) from
|
||||
/// fee/feerate aggregations.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn compute_aggregations<I, T, A>(
|
||||
max_from: I,
|
||||
@@ -35,6 +39,7 @@ pub fn compute_aggregations<I, T, A>(
|
||||
first_indexes: &impl IterableVec<I, A>,
|
||||
count_indexes: &impl IterableVec<I, StoredU64>,
|
||||
exit: &Exit,
|
||||
skip_count: usize,
|
||||
mut first: Option<&mut EagerVec<PcoVec<I, T>>>,
|
||||
mut last: Option<&mut EagerVec<PcoVec<I, T>>>,
|
||||
mut min: Option<&mut EagerVec<PcoVec<I, T>>>,
|
||||
@@ -105,29 +110,37 @@ where
|
||||
let count_index = count_indexes_iter.next().unwrap();
|
||||
let count = *count_index as usize;
|
||||
|
||||
// Effective count after skipping (e.g., skip coinbase for fee calculations)
|
||||
let effective_count = count.saturating_sub(skip_count);
|
||||
let effective_first_index = first_index + skip_count.min(count);
|
||||
|
||||
if let Some(ref mut first_vec) = first {
|
||||
let f = source_iter
|
||||
.get(first_index)
|
||||
.unwrap_or_else(|| T::from(0_usize));
|
||||
let f = if effective_count > 0 {
|
||||
source_iter.get_unwrap(effective_first_index)
|
||||
} else {
|
||||
T::from(0_usize)
|
||||
};
|
||||
first_vec.truncate_push_at(idx, f)?;
|
||||
}
|
||||
|
||||
if let Some(ref mut last_vec) = last {
|
||||
if count == 0 {
|
||||
panic!("should not compute last if count can be 0");
|
||||
if effective_count == 0 {
|
||||
// If all items skipped, use zero
|
||||
last_vec.truncate_push_at(idx, T::from(0_usize))?;
|
||||
} else {
|
||||
let last_index = first_index + (count - 1);
|
||||
let v = source_iter.get_unwrap(last_index);
|
||||
last_vec.truncate_push_at(idx, v)?;
|
||||
}
|
||||
let last_index = first_index + (count - 1);
|
||||
let v = source_iter.get_unwrap(last_index);
|
||||
last_vec.truncate_push_at(idx, v)?;
|
||||
}
|
||||
|
||||
// Fast path: only min/max needed, no sorting or allocation required
|
||||
if needs_minmax && !needs_percentiles && !needs_aggregates {
|
||||
source_iter.set_position(first_index);
|
||||
source_iter.set_position(effective_first_index);
|
||||
let mut min_val: Option<T> = None;
|
||||
let mut max_val: Option<T> = None;
|
||||
|
||||
for val in (&mut source_iter).take(count) {
|
||||
for val in (&mut source_iter).take(effective_count) {
|
||||
if needs_min {
|
||||
min_val = Some(min_val.map_or(val, |m| if val < m { val } else { m }));
|
||||
}
|
||||
@@ -137,43 +150,94 @@ where
|
||||
}
|
||||
|
||||
if let Some(ref mut min_vec) = min {
|
||||
min_vec.truncate_push_at(idx, min_val.unwrap())?;
|
||||
let v = min_val.or(max_val).unwrap_or_else(|| T::from(0_usize));
|
||||
min_vec.truncate_push_at(idx, v)?;
|
||||
}
|
||||
if let Some(ref mut max_vec) = max {
|
||||
max_vec.truncate_push_at(idx, max_val.unwrap())?;
|
||||
let v = max_val.or(min_val).unwrap_or_else(|| T::from(0_usize));
|
||||
max_vec.truncate_push_at(idx, v)?;
|
||||
}
|
||||
} else if needs_percentiles || needs_aggregates || needs_minmax {
|
||||
source_iter.set_position(first_index);
|
||||
let mut values: Vec<T> = (&mut source_iter).take(count).collect();
|
||||
|
||||
if needs_percentiles {
|
||||
values.sort_unstable();
|
||||
source_iter.set_position(effective_first_index);
|
||||
let values: Vec<T> = (&mut source_iter).take(effective_count).collect();
|
||||
|
||||
if values.is_empty() {
|
||||
// Handle edge case where all items were skipped
|
||||
if let Some(ref mut max_vec) = max {
|
||||
max_vec.truncate_push_at(
|
||||
idx,
|
||||
*values
|
||||
.last()
|
||||
.ok_or(Error::Internal("Empty values for percentiles"))?,
|
||||
)?;
|
||||
max_vec.truncate_push_at(idx, T::from(0_usize))?;
|
||||
}
|
||||
if let Some(ref mut pct90_vec) = pct90 {
|
||||
pct90_vec.truncate_push_at(idx, get_percentile(&values, 0.90))?;
|
||||
pct90_vec.truncate_push_at(idx, T::from(0_usize))?;
|
||||
}
|
||||
if let Some(ref mut pct75_vec) = pct75 {
|
||||
pct75_vec.truncate_push_at(idx, get_percentile(&values, 0.75))?;
|
||||
pct75_vec.truncate_push_at(idx, T::from(0_usize))?;
|
||||
}
|
||||
if let Some(ref mut median_vec) = median {
|
||||
median_vec.truncate_push_at(idx, get_percentile(&values, 0.50))?;
|
||||
median_vec.truncate_push_at(idx, T::from(0_usize))?;
|
||||
}
|
||||
if let Some(ref mut pct25_vec) = pct25 {
|
||||
pct25_vec.truncate_push_at(idx, get_percentile(&values, 0.25))?;
|
||||
pct25_vec.truncate_push_at(idx, T::from(0_usize))?;
|
||||
}
|
||||
if let Some(ref mut pct10_vec) = pct10 {
|
||||
pct10_vec.truncate_push_at(idx, get_percentile(&values, 0.10))?;
|
||||
pct10_vec.truncate_push_at(idx, T::from(0_usize))?;
|
||||
}
|
||||
if let Some(ref mut min_vec) = min {
|
||||
min_vec.truncate_push_at(idx, *values.first().unwrap())?;
|
||||
min_vec.truncate_push_at(idx, T::from(0_usize))?;
|
||||
}
|
||||
if let Some(ref mut average_vec) = average {
|
||||
average_vec.truncate_push_at(idx, T::from(0_usize))?;
|
||||
}
|
||||
if let Some(ref mut sum_vec) = sum {
|
||||
sum_vec.truncate_push_at(idx, T::from(0_usize))?;
|
||||
}
|
||||
if let Some(ref mut cumulative_vec) = cumulative {
|
||||
let t = cumulative_val.unwrap();
|
||||
cumulative_vec.truncate_push_at(idx, t)?;
|
||||
}
|
||||
} else if needs_percentiles {
|
||||
let mut sorted_values = values.clone();
|
||||
sorted_values.sort_unstable();
|
||||
|
||||
if let Some(ref mut max_vec) = max {
|
||||
max_vec.truncate_push_at(idx, *sorted_values.last().unwrap())?;
|
||||
}
|
||||
if let Some(ref mut pct90_vec) = pct90 {
|
||||
pct90_vec.truncate_push_at(idx, get_percentile(&sorted_values, 0.90))?;
|
||||
}
|
||||
if let Some(ref mut pct75_vec) = pct75 {
|
||||
pct75_vec.truncate_push_at(idx, get_percentile(&sorted_values, 0.75))?;
|
||||
}
|
||||
if let Some(ref mut median_vec) = median {
|
||||
median_vec.truncate_push_at(idx, get_percentile(&sorted_values, 0.50))?;
|
||||
}
|
||||
if let Some(ref mut pct25_vec) = pct25 {
|
||||
pct25_vec.truncate_push_at(idx, get_percentile(&sorted_values, 0.25))?;
|
||||
}
|
||||
if let Some(ref mut pct10_vec) = pct10 {
|
||||
pct10_vec.truncate_push_at(idx, get_percentile(&sorted_values, 0.10))?;
|
||||
}
|
||||
if let Some(ref mut min_vec) = min {
|
||||
min_vec.truncate_push_at(idx, *sorted_values.first().unwrap())?;
|
||||
}
|
||||
|
||||
if needs_aggregates {
|
||||
let len = values.len();
|
||||
let sum_val = values.into_iter().fold(T::from(0), |a, b| a + b);
|
||||
|
||||
if let Some(ref mut average_vec) = average {
|
||||
average_vec.truncate_push_at(idx, sum_val / len)?;
|
||||
}
|
||||
|
||||
if needs_sum_or_cumulative {
|
||||
if let Some(ref mut sum_vec) = sum {
|
||||
sum_vec.truncate_push_at(idx, sum_val)?;
|
||||
}
|
||||
if let Some(ref mut cumulative_vec) = cumulative {
|
||||
let t = cumulative_val.unwrap() + sum_val;
|
||||
cumulative_val.replace(t);
|
||||
cumulative_vec.truncate_push_at(idx, t)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if needs_minmax {
|
||||
if let Some(ref mut min_vec) = min {
|
||||
@@ -182,9 +246,27 @@ where
|
||||
if let Some(ref mut max_vec) = max {
|
||||
max_vec.truncate_push_at(idx, *values.iter().max().unwrap())?;
|
||||
}
|
||||
}
|
||||
|
||||
if needs_aggregates {
|
||||
if needs_aggregates {
|
||||
let len = values.len();
|
||||
let sum_val = values.into_iter().fold(T::from(0), |a, b| a + b);
|
||||
|
||||
if let Some(ref mut average_vec) = average {
|
||||
average_vec.truncate_push_at(idx, sum_val / len)?;
|
||||
}
|
||||
|
||||
if needs_sum_or_cumulative {
|
||||
if let Some(ref mut sum_vec) = sum {
|
||||
sum_vec.truncate_push_at(idx, sum_val)?;
|
||||
}
|
||||
if let Some(ref mut cumulative_vec) = cumulative {
|
||||
let t = cumulative_val.unwrap() + sum_val;
|
||||
cumulative_val.replace(t);
|
||||
cumulative_vec.truncate_push_at(idx, t)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if needs_aggregates {
|
||||
let len = values.len();
|
||||
let sum_val = values.into_iter().fold(T::from(0), |a, b| a + b);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyPeriodsAverage<T>
|
||||
pub struct LazyDateDerivedAverage<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -27,7 +27,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> LazyPeriodsAverage<T>
|
||||
impl<T> LazyDateDerivedAverage<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyPeriodsDistribution<T>
|
||||
pub struct LazyDateDerivedDistribution<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -27,7 +27,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> LazyPeriodsDistribution<T>
|
||||
impl<T> LazyDateDerivedDistribution<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyPeriodsFirst<T>
|
||||
pub struct LazyDateDerivedFirst<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -27,7 +27,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> LazyPeriodsFirst<T>
|
||||
impl<T> LazyDateDerivedFirst<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyPeriodsFull<T>
|
||||
pub struct LazyDateDerivedFull<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -27,7 +27,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> LazyPeriodsFull<T>
|
||||
impl<T> LazyDateDerivedFull<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyPeriodsLast<T>
|
||||
pub struct LazyDateDerivedLast<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -27,7 +27,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> LazyPeriodsLast<T>
|
||||
impl<T> LazyDateDerivedLast<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyPeriodsMax<T>
|
||||
pub struct LazyDateDerivedMax<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -27,7 +27,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> LazyPeriodsMax<T>
|
||||
impl<T> LazyDateDerivedMax<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -37,12 +37,36 @@ where
|
||||
version: Version,
|
||||
dateindex_source: IterableBoxedVec<DateIndex, T>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
Self::from_source_inner(name, version, dateindex_source, indexes, false)
|
||||
}
|
||||
|
||||
/// Create from an external dateindex source without adding _max suffix.
|
||||
pub fn from_source_raw(
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source: IterableBoxedVec<DateIndex, T>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
Self::from_source_inner(name, version, dateindex_source, indexes, true)
|
||||
}
|
||||
|
||||
fn from_source_inner(
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source: IterableBoxedVec<DateIndex, T>,
|
||||
indexes: &indexes::Vecs,
|
||||
raw: bool,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($idx:ident) => {
|
||||
LazyMax::from_source(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
|
||||
if raw {
|
||||
LazyMax::from_source_raw(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
|
||||
} else {
|
||||
LazyMax::from_source(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyPeriodsMin<T>
|
||||
pub struct LazyDateDerivedMin<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -27,7 +27,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> LazyPeriodsMin<T>
|
||||
impl<T> LazyDateDerivedMin<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -37,12 +37,36 @@ where
|
||||
version: Version,
|
||||
dateindex_source: IterableBoxedVec<DateIndex, T>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
Self::from_source_inner(name, version, dateindex_source, indexes, false)
|
||||
}
|
||||
|
||||
/// Create from an external dateindex source without adding _min suffix.
|
||||
pub fn from_source_raw(
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source: IterableBoxedVec<DateIndex, T>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
Self::from_source_inner(name, version, dateindex_source, indexes, true)
|
||||
}
|
||||
|
||||
fn from_source_inner(
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source: IterableBoxedVec<DateIndex, T>,
|
||||
indexes: &indexes::Vecs,
|
||||
raw: bool,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($idx:ident) => {
|
||||
LazyMin::from_source(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
|
||||
if raw {
|
||||
LazyMin::from_source_raw(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
|
||||
} else {
|
||||
LazyMin::from_source(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ mod distribution;
|
||||
mod first;
|
||||
mod full;
|
||||
mod last;
|
||||
mod lazy;
|
||||
mod max;
|
||||
mod min;
|
||||
mod sum;
|
||||
@@ -14,7 +13,6 @@ pub use distribution::*;
|
||||
pub use first::*;
|
||||
pub use full::*;
|
||||
pub use last::*;
|
||||
pub use lazy::*;
|
||||
pub use max::*;
|
||||
pub use min::*;
|
||||
pub use sum::*;
|
||||
@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyPeriodsSum<T>
|
||||
pub struct LazyDateDerivedSum<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -27,7 +27,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> LazyPeriodsSum<T>
|
||||
impl<T> LazyDateDerivedSum<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyPeriodsSumCum<T>
|
||||
pub struct LazyDateDerivedSumCum<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -27,7 +27,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> LazyPeriodsSumCum<T>
|
||||
impl<T> LazyDateDerivedSumCum<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedDateAverage - dateindex storage + lazy periods for average-value aggregation.
|
||||
//! ComputedFromDateAverage - dateindex storage + lazy periods for average-value aggregation.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -9,11 +9,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedVecValue, LazyPeriodsAverage};
|
||||
use crate::internal::{ComputedVecValue, LazyDateDerivedAverage};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedDateAverage<T>
|
||||
pub struct ComputedFromDateAverage<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -21,12 +21,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: LazyPeriodsAverage<T>,
|
||||
pub rest: LazyDateDerivedAverage<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedDateAverage<T>
|
||||
impl<T> ComputedFromDateAverage<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -39,7 +39,7 @@ where
|
||||
let dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
|
||||
|
||||
Ok(Self {
|
||||
rest: LazyPeriodsAverage::from_source(
|
||||
rest: LazyDateDerivedAverage::from_source(
|
||||
name,
|
||||
version + VERSION,
|
||||
dateindex.boxed_clone(),
|
||||
@@ -8,15 +8,16 @@ use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockLast, ComputedBlockSum, ComputedDateLast, ComputedVecValue, LazyBinaryTransformLast,
|
||||
LazyPeriodsLast, LazyPeriodsSumCum, NumericValue,
|
||||
ComputedFromHeightLast, ComputedFromHeightSum, ComputedFromDateLast, ComputedVecValue,
|
||||
LazyBinaryComputedFromHeightLast, LazyBinaryComputedFromHeightSum, LazyBinaryTransformLast,
|
||||
LazyDateDerivedLast, LazyDateDerivedSumCum, NumericValue,
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryDateLast<T, S1T, S2T>
|
||||
pub struct LazyBinaryFromDateLast<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -31,7 +32,7 @@ where
|
||||
pub decadeindex: LazyBinaryTransformLast<DecadeIndex, T, S1T, S2T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryDateLast<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyBinaryFromDateLast<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -40,8 +41,8 @@ where
|
||||
pub fn from_computed_both_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedDateLast<S1T>,
|
||||
source2: &ComputedDateLast<S2T>,
|
||||
source1: &ComputedFromDateLast<S1T>,
|
||||
source2: &ComputedFromDateLast<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -76,8 +77,8 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
|
||||
source1: &LazyPeriodsLast<S1T>,
|
||||
source2: &ComputedDateLast<S2T>,
|
||||
source1: &LazyDateDerivedLast<S1T>,
|
||||
source2: &ComputedFromDateLast<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -112,8 +113,8 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
|
||||
source1: &LazyPeriodsLast<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &LazyDateDerivedLast<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S2T: NumericValue,
|
||||
@@ -136,7 +137,7 @@ where
|
||||
name,
|
||||
v,
|
||||
dateindex_source1,
|
||||
source2.dateindex.0.boxed_clone(),
|
||||
source2.dateindex.boxed_clone(),
|
||||
),
|
||||
weekindex: period!(weekindex),
|
||||
monthindex: period!(monthindex),
|
||||
@@ -151,9 +152,9 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
|
||||
source1: &LazyPeriodsLast<S1T>,
|
||||
source1: &LazyDateDerivedLast<S1T>,
|
||||
dateindex_source2: IterableBoxedVec<DateIndex, S2T>,
|
||||
source2: &LazyPeriodsLast<S2T>,
|
||||
source2: &LazyDateDerivedLast<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -187,8 +188,8 @@ where
|
||||
pub fn from_height_and_dateindex_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockLast<S1T>,
|
||||
source2: &ComputedDateLast<S2T>,
|
||||
source1: &ComputedFromHeightLast<S1T>,
|
||||
source2: &ComputedFromDateLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -210,7 +211,7 @@ where
|
||||
dateindex: LazyVecFrom2::transformed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.dateindex.0.boxed_clone(),
|
||||
source1.dateindex.boxed_clone(),
|
||||
source2.dateindex.boxed_clone(),
|
||||
),
|
||||
weekindex: period!(weekindex),
|
||||
@@ -225,8 +226,8 @@ where
|
||||
pub fn from_dateindex_and_height_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedDateLast<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedFromDateLast<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S2T: NumericValue,
|
||||
@@ -249,7 +250,7 @@ where
|
||||
name,
|
||||
v,
|
||||
source1.dateindex.boxed_clone(),
|
||||
source2.dateindex.0.boxed_clone(),
|
||||
source2.dateindex.boxed_clone(),
|
||||
),
|
||||
weekindex: period!(weekindex),
|
||||
monthindex: period!(monthindex),
|
||||
@@ -263,8 +264,8 @@ where
|
||||
pub fn from_both_block_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockLast<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedFromHeightLast<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -287,8 +288,8 @@ where
|
||||
dateindex: LazyVecFrom2::transformed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.dateindex.0.boxed_clone(),
|
||||
source2.dateindex.0.boxed_clone(),
|
||||
source1.dateindex.boxed_clone(),
|
||||
source2.dateindex.boxed_clone(),
|
||||
),
|
||||
weekindex: period!(weekindex),
|
||||
monthindex: period!(monthindex),
|
||||
@@ -302,8 +303,8 @@ where
|
||||
pub fn from_dateindex_last_and_height_sum<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedDateLast<S1T>,
|
||||
source2: &ComputedBlockSum<S2T>,
|
||||
source1: &ComputedFromDateLast<S1T>,
|
||||
source2: &ComputedFromHeightSum<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S2T: NumericValue,
|
||||
@@ -326,7 +327,7 @@ where
|
||||
name,
|
||||
v,
|
||||
source1.dateindex.boxed_clone(),
|
||||
source2.dateindex.0.boxed_clone(),
|
||||
source2.dateindex.boxed_clone(),
|
||||
),
|
||||
weekindex: period!(weekindex),
|
||||
monthindex: period!(monthindex),
|
||||
@@ -340,8 +341,8 @@ where
|
||||
pub fn from_block_last_and_height_sum<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockLast<S1T>,
|
||||
source2: &ComputedBlockSum<S2T>,
|
||||
source1: &ComputedFromHeightLast<S1T>,
|
||||
source2: &ComputedFromHeightSum<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -364,8 +365,8 @@ where
|
||||
dateindex: LazyVecFrom2::transformed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.dateindex.0.boxed_clone(),
|
||||
source2.dateindex.0.boxed_clone(),
|
||||
source1.dateindex.boxed_clone(),
|
||||
source2.dateindex.boxed_clone(),
|
||||
),
|
||||
weekindex: period!(weekindex),
|
||||
monthindex: period!(monthindex),
|
||||
@@ -380,9 +381,9 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
|
||||
dates1: &LazyPeriodsSumCum<S1T>,
|
||||
dates1: &LazyDateDerivedSumCum<S1T>,
|
||||
dateindex_source2: IterableBoxedVec<DateIndex, S2T>,
|
||||
dates2: &LazyPeriodsSumCum<S2T>,
|
||||
dates2: &LazyDateDerivedSumCum<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -417,13 +418,13 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a LazyPeriodsLast source and a BinaryDateLast source.
|
||||
/// Create from a LazyDateDerivedLast source and a BinaryDateLast source.
|
||||
pub fn from_derived_last_and_binary_last<F, S2aT, S2bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
|
||||
source1: &LazyPeriodsLast<S1T>,
|
||||
source2: &LazyBinaryDateLast<S2T, S2aT, S2bT>,
|
||||
source1: &LazyDateDerivedLast<S1T>,
|
||||
source2: &LazyBinaryFromDateLast<S2T, S2aT, S2bT>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
@@ -459,12 +460,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a BinaryDateLast source and a ComputedDateLast source.
|
||||
/// Create from a BinaryDateLast source and a ComputedFromDateLast source.
|
||||
pub fn from_binary_and_computed_last<F, S1aT, S1bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryDateLast<S1T, S1aT, S1bT>,
|
||||
source2: &ComputedDateLast<S2T>,
|
||||
source1: &LazyBinaryFromDateLast<S1T, S1aT, S1bT>,
|
||||
source2: &ComputedFromDateLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
@@ -500,12 +501,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a BinaryDateLast source and a ComputedBlockLast source.
|
||||
/// Create from a BinaryDateLast source and a ComputedFromHeightLast source.
|
||||
pub fn from_binary_and_block_last<F, S1aT, S1bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryDateLast<S1T, S1aT, S1bT>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &LazyBinaryFromDateLast<S1T, S1aT, S1bT>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
@@ -531,7 +532,7 @@ where
|
||||
name,
|
||||
v,
|
||||
source1.dateindex.boxed_clone(),
|
||||
source2.dateindex.0.boxed_clone(),
|
||||
source2.dateindex.boxed_clone(),
|
||||
),
|
||||
weekindex: period!(weekindex),
|
||||
monthindex: period!(monthindex),
|
||||
@@ -542,12 +543,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a ComputedDateLast source and a BinaryDateLast source.
|
||||
/// Create from a ComputedFromDateLast source and a BinaryDateLast source.
|
||||
pub fn from_computed_and_binary_last<F, S2aT, S2bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedDateLast<S1T>,
|
||||
source2: &LazyBinaryDateLast<S2T, S2aT, S2bT>,
|
||||
source1: &ComputedFromDateLast<S1T>,
|
||||
source2: &LazyBinaryFromDateLast<S2T, S2aT, S2bT>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
@@ -587,8 +588,8 @@ where
|
||||
pub fn from_both_binary_last<F, S1aT, S1bT, S2aT, S2bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryDateLast<S1T, S1aT, S1bT>,
|
||||
source2: &LazyBinaryDateLast<S2T, S2aT, S2bT>,
|
||||
source1: &LazyBinaryFromDateLast<S1T, S1aT, S1bT>,
|
||||
source2: &LazyBinaryFromDateLast<S2T, S2aT, S2bT>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
@@ -625,4 +626,131 @@ where
|
||||
decadeindex: period!(decadeindex),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a BinaryDateLast source and a LazyDateDerivedLast source.
|
||||
pub fn from_binary_and_derived_last<F, S1aT, S1bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryFromDateLast<S1T, S1aT, S1bT>,
|
||||
dateindex_source2: IterableBoxedVec<DateIndex, S2T>,
|
||||
source2: &LazyDateDerivedLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
S1aT: ComputedVecValue + JsonSchema,
|
||||
S1bT: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($p:ident) => {
|
||||
LazyBinaryTransformLast::from_vecs::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.$p.boxed_clone(),
|
||||
source2.$p.boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
dateindex: LazyVecFrom2::transformed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.dateindex.boxed_clone(),
|
||||
dateindex_source2,
|
||||
),
|
||||
weekindex: period!(weekindex),
|
||||
monthindex: period!(monthindex),
|
||||
quarterindex: period!(quarterindex),
|
||||
semesterindex: period!(semesterindex),
|
||||
yearindex: period!(yearindex),
|
||||
decadeindex: period!(decadeindex),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a LazyBinaryComputedFromHeightLast and a ComputedFromHeightSum.
|
||||
pub fn from_lazy_binary_block_last_and_height_sum<F, S1aT, S1bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryComputedFromHeightLast<S1T, S1aT, S1bT>,
|
||||
source2: &ComputedFromHeightSum<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
S1aT: ComputedVecValue + JsonSchema,
|
||||
S1bT: ComputedVecValue + JsonSchema,
|
||||
S2T: NumericValue,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! period {
|
||||
($p:ident) => {
|
||||
LazyBinaryTransformLast::from_vecs::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.rest.dates.$p.boxed_clone(),
|
||||
source2.$p.boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
dateindex: LazyVecFrom2::transformed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.rest.dateindex.boxed_clone(),
|
||||
source2.dateindex.boxed_clone(),
|
||||
),
|
||||
weekindex: period!(weekindex),
|
||||
monthindex: period!(monthindex),
|
||||
quarterindex: period!(quarterindex),
|
||||
semesterindex: period!(semesterindex),
|
||||
yearindex: period!(yearindex),
|
||||
decadeindex: period!(decadeindex),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a LazyBinaryComputedFromHeightLast and a LazyBinaryComputedFromHeightSum.
|
||||
pub fn from_lazy_binary_block_last_and_lazy_binary_sum<F, S1aT, S1bT, S2aT, S2bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryComputedFromHeightLast<S1T, S1aT, S1bT>,
|
||||
source2: &LazyBinaryComputedFromHeightSum<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) => {
|
||||
LazyBinaryTransformLast::from_vecs::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.rest.dates.$p.boxed_clone(),
|
||||
source2.rest.dates.$p.boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
dateindex: LazyVecFrom2::transformed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.rest.dateindex.boxed_clone(),
|
||||
source2.rest.dateindex.boxed_clone(),
|
||||
),
|
||||
weekindex: period!(weekindex),
|
||||
monthindex: period!(monthindex),
|
||||
quarterindex: period!(quarterindex),
|
||||
semesterindex: period!(semesterindex),
|
||||
yearindex: period!(yearindex),
|
||||
decadeindex: period!(decadeindex),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,13 @@ use brk_types::{
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, IterableCloneableVec};
|
||||
|
||||
use crate::internal::{ComputedVecValue, ComputedDerivedBlockSum, LazyBinaryTransformSum, NumericValue};
|
||||
use crate::internal::{ComputedVecValue, ComputedHeightDerivedSum, LazyBinaryTransformSum, NumericValue};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryDateSum<T, S1T, S2T>
|
||||
pub struct LazyBinaryFromDateSum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -28,7 +28,7 @@ where
|
||||
pub decadeindex: LazyBinaryTransformSum<DecadeIndex, T, S1T, S2T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryDateSum<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyBinaryFromDateSum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: NumericValue + JsonSchema,
|
||||
@@ -37,8 +37,8 @@ where
|
||||
pub fn from_derived<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedDerivedBlockSum<S1T>,
|
||||
source2: &ComputedDerivedBlockSum<S2T>,
|
||||
source1: &ComputedHeightDerivedSum<S1T>,
|
||||
source2: &ComputedHeightDerivedSum<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -8,16 +8,16 @@ use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, IterableCloneableVec};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockLast, ComputedBlockSumCum, ComputedDerivedBlockLast,
|
||||
ComputedDerivedBlockSumCum, ComputedVecValue, LazyBinaryTransformSumCum, LazyPeriodsFull,
|
||||
LazyPeriodsSumCum, NumericValue, SumCum,
|
||||
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedHeightDerivedLast,
|
||||
ComputedHeightDerivedSumCum, ComputedVecValue, LazyBinaryTransformSumCum, LazyDateDerivedFull,
|
||||
LazyDateDerivedSumCum, NumericValue, SumCum,
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryDateSumCum<T, S1T = T, S2T = T>
|
||||
pub struct LazyBinaryFromDateSumCum<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -32,7 +32,7 @@ where
|
||||
pub decadeindex: LazyBinaryTransformSumCum<DecadeIndex, T, S1T, S2T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryDateSumCum<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyBinaryFromDateSumCum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -43,9 +43,9 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex1: &SumCum<DateIndex, S1T>,
|
||||
periods1: &LazyPeriodsSumCum<S1T>,
|
||||
periods1: &LazyDateDerivedSumCum<S1T>,
|
||||
dateindex2: &SumCum<DateIndex, S2T>,
|
||||
periods2: &LazyPeriodsSumCum<S2T>,
|
||||
periods2: &LazyDateDerivedSumCum<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -74,9 +74,9 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex1: &SumCum<DateIndex, S1T>,
|
||||
dates1: &LazyPeriodsFull<S1T>,
|
||||
dates1: &LazyDateDerivedFull<S1T>,
|
||||
dateindex2: &SumCum<DateIndex, S2T>,
|
||||
dates2: &LazyPeriodsFull<S2T>,
|
||||
dates2: &LazyDateDerivedFull<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -106,9 +106,9 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex1: &SumCum<DateIndex, S1T>,
|
||||
periods1: &LazyPeriodsSumCum<S1T>,
|
||||
periods1: &LazyDateDerivedSumCum<S1T>,
|
||||
dateindex2: &SumCum<DateIndex, S2T>,
|
||||
periods2: &LazyPeriodsSumCum<S2T>,
|
||||
periods2: &LazyDateDerivedSumCum<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -138,8 +138,8 @@ where
|
||||
pub fn from_computed_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockSumCum<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -174,8 +174,8 @@ where
|
||||
pub fn from_derived_computed_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedDerivedBlockSumCum<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedHeightDerivedSumCum<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -210,8 +210,8 @@ where
|
||||
pub fn from_computed_derived_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockSumCum<S1T>,
|
||||
source2: &ComputedDerivedBlockLast<S2T>,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &ComputedHeightDerivedLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -246,8 +246,8 @@ where
|
||||
pub fn from_derived_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedDerivedBlockSumCum<S1T>,
|
||||
source2: &ComputedDerivedBlockLast<S2T>,
|
||||
source1: &ComputedHeightDerivedSumCum<S1T>,
|
||||
source2: &ComputedHeightDerivedLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -9,11 +9,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedVecValue, LazyPeriodsFirst};
|
||||
use crate::internal::{ComputedVecValue, LazyDateDerivedFirst};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedDateFirst<T>
|
||||
pub struct ComputedFromDateFirst<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -21,12 +21,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: LazyPeriodsFirst<T>,
|
||||
pub rest: LazyDateDerivedFirst<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedDateFirst<T>
|
||||
impl<T> ComputedFromDateFirst<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -39,7 +39,7 @@ where
|
||||
let dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
|
||||
|
||||
Ok(Self {
|
||||
rest: LazyPeriodsFirst::from_source(
|
||||
rest: LazyDateDerivedFirst::from_source(
|
||||
name,
|
||||
version + VERSION,
|
||||
dateindex.boxed_clone(),
|
||||
@@ -9,11 +9,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, Itera
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedVecValue, LazyPeriodsLast};
|
||||
use crate::internal::{ComputedVecValue, LazyDateDerivedLast};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedDateLast<T>
|
||||
pub struct ComputedFromDateLast<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -21,12 +21,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: LazyPeriodsLast<T>,
|
||||
pub rest: LazyDateDerivedLast<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedDateLast<T>
|
||||
impl<T> ComputedFromDateLast<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -39,7 +39,7 @@ where
|
||||
let dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
|
||||
|
||||
Ok(Self {
|
||||
rest: LazyPeriodsLast::from_source(
|
||||
rest: LazyDateDerivedLast::from_source(
|
||||
name,
|
||||
version + VERSION,
|
||||
dateindex.boxed_clone(),
|
||||
@@ -13,7 +13,7 @@ use crate::indexes;
|
||||
/// Lazy vecs for all time period indexes (no height).
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyPeriodVecs<T>
|
||||
pub struct LazyFromDate<T>
|
||||
where
|
||||
T: VecValue + Formattable + Serialize + JsonSchema,
|
||||
{
|
||||
@@ -26,7 +26,7 @@ where
|
||||
pub decadeindex: LazyVecFrom1<DecadeIndex, T, DecadeIndex, DecadeIndex>,
|
||||
}
|
||||
|
||||
impl<T: VecValue + Formattable + Serialize + JsonSchema> LazyPeriodVecs<T> {
|
||||
impl<T: VecValue + Formattable + Serialize + JsonSchema> LazyFromDate<T> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
name: &str,
|
||||
@@ -5,13 +5,13 @@ use brk_types::{DateIndex, DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex,
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{IterableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{ComputedVecValue, Full, LazyPeriodsFull, LazyTransformFull, LazyTransformStats};
|
||||
use crate::internal::{ComputedVecValue, Full, LazyDateDerivedFull, LazyTransformFull, LazyTransformStats};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyDateFull<T, S1T = T>
|
||||
pub struct LazyFromDateFull<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -25,7 +25,7 @@ where
|
||||
pub decadeindex: LazyTransformStats<DecadeIndex, T, S1T>,
|
||||
}
|
||||
|
||||
impl<T, S1T> LazyDateFull<T, S1T>
|
||||
impl<T, S1T> LazyFromDateFull<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -34,7 +34,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex: &Full<DateIndex, S1T>,
|
||||
source: &LazyPeriodsFull<S1T>,
|
||||
source: &LazyDateDerivedFull<S1T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -7,13 +7,13 @@ use brk_types::{
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{IterableBoxedVec, IterableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{ComputedBlockLast, ComputedDateLast, ComputedVecValue, LazyPeriodsLast, LazyTransformLast, NumericValue};
|
||||
use crate::internal::{ComputedFromHeightLast, ComputedFromDateLast, ComputedVecValue, LazyDateDerivedLast, LazyTransformLast, NumericValue};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyDateLast<T, S1T = T>
|
||||
pub struct LazyFromDateLast<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -27,7 +27,7 @@ where
|
||||
pub decadeindex: LazyTransformLast<DecadeIndex, T, S1T>,
|
||||
}
|
||||
|
||||
impl<T, S1T> LazyDateLast<T, S1T>
|
||||
impl<T, S1T> LazyFromDateLast<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -35,7 +35,7 @@ where
|
||||
pub fn from_source<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedDateLast<S1T>,
|
||||
source: &ComputedFromDateLast<S1T>,
|
||||
) -> Self {
|
||||
Self::from_computed::<F>(name, version, source.dateindex.boxed_clone(), source)
|
||||
}
|
||||
@@ -44,7 +44,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source: IterableBoxedVec<DateIndex, S1T>,
|
||||
source: &ComputedDateLast<S1T>,
|
||||
source: &ComputedFromDateLast<S1T>,
|
||||
) -> Self {
|
||||
Self::from_derived::<F>(name, version, dateindex_source, &source.rest)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source: IterableBoxedVec<DateIndex, S1T>,
|
||||
source: &LazyPeriodsLast<S1T>,
|
||||
source: &LazyDateDerivedLast<S1T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -77,11 +77,11 @@ where
|
||||
pub fn from_block_source<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedBlockLast<S1T>,
|
||||
source: &ComputedFromHeightLast<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
Self::from_derived::<F>(name, version, source.dateindex.0.boxed_clone(), &source.dates)
|
||||
Self::from_derived::<F>(name, version, source.dateindex.boxed_clone(), &source.dates)
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,13 @@ use brk_types::{DateIndex, DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex,
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{IterableBoxedVec, IterableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{ComputedVecValue, LazyPeriodsSum, LazyTransformSum};
|
||||
use crate::internal::{ComputedVecValue, LazyDateDerivedSum, LazyTransformSum};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyDateSum<T, S1T = T>
|
||||
pub struct LazyFromDateSum<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -25,7 +25,7 @@ where
|
||||
pub decadeindex: LazyTransformSum<DecadeIndex, T, S1T>,
|
||||
}
|
||||
|
||||
impl<T, S1T> LazyDateSum<T, S1T>
|
||||
impl<T, S1T> LazyFromDateSum<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -34,7 +34,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex_source: IterableBoxedVec<DateIndex, S1T>,
|
||||
source: &LazyPeriodsSum<S1T>,
|
||||
source: &LazyDateDerivedSum<S1T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -5,13 +5,13 @@ use brk_types::{DateIndex, DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex,
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{IterableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{ComputedVecValue, LazyPeriodsSumCum, LazyTransformSumCum, SumCum};
|
||||
use crate::internal::{ComputedVecValue, LazyDateDerivedSumCum, LazyTransformSumCum, SumCum};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyDateSumCum<T, S1T = T>
|
||||
pub struct LazyFromDateSumCum<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -25,7 +25,7 @@ where
|
||||
pub decadeindex: LazyTransformSumCum<DecadeIndex, T, S1T>,
|
||||
}
|
||||
|
||||
impl<T, S1T> LazyDateSumCum<T, S1T>
|
||||
impl<T, S1T> LazyFromDateSumCum<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -34,7 +34,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex: &SumCum<DateIndex, S1T>,
|
||||
source: &LazyPeriodsSumCum<S1T>,
|
||||
source: &LazyDateDerivedSumCum<S1T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -9,11 +9,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedVecValue, LazyPeriodsMax};
|
||||
use crate::internal::{ComputedVecValue, LazyDateDerivedMax};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedDateMax<T>
|
||||
pub struct ComputedFromDateMax<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -21,12 +21,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: LazyPeriodsMax<T>,
|
||||
pub rest: LazyDateDerivedMax<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedDateMax<T>
|
||||
impl<T> ComputedFromDateMax<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -35,16 +35,47 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Self::forced_import_inner(db, name, version, indexes, false)
|
||||
}
|
||||
|
||||
/// Import without adding _max suffix to lazy vecs.
|
||||
pub fn forced_import_raw(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Self::forced_import_inner(db, name, version, indexes, true)
|
||||
}
|
||||
|
||||
fn forced_import_inner(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
raw: bool,
|
||||
) -> Result<Self> {
|
||||
let dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
|
||||
|
||||
Ok(Self {
|
||||
rest: LazyPeriodsMax::from_source(
|
||||
let rest = if raw {
|
||||
LazyDateDerivedMax::from_source_raw(
|
||||
name,
|
||||
version + VERSION,
|
||||
dateindex.boxed_clone(),
|
||||
indexes,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
LazyDateDerivedMax::from_source(
|
||||
name,
|
||||
version + VERSION,
|
||||
dateindex.boxed_clone(),
|
||||
indexes,
|
||||
)
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
rest,
|
||||
dateindex,
|
||||
})
|
||||
}
|
||||
@@ -9,11 +9,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedVecValue, LazyPeriodsMin};
|
||||
use crate::internal::{ComputedVecValue, LazyDateDerivedMin};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedDateMin<T>
|
||||
pub struct ComputedFromDateMin<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -21,12 +21,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: LazyPeriodsMin<T>,
|
||||
pub rest: LazyDateDerivedMin<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedDateMin<T>
|
||||
impl<T> ComputedFromDateMin<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -35,16 +35,47 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Self::forced_import_inner(db, name, version, indexes, false)
|
||||
}
|
||||
|
||||
/// Import without adding _min suffix to lazy vecs.
|
||||
pub fn forced_import_raw(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Self::forced_import_inner(db, name, version, indexes, true)
|
||||
}
|
||||
|
||||
fn forced_import_inner(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
raw: bool,
|
||||
) -> Result<Self> {
|
||||
let dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
|
||||
|
||||
Ok(Self {
|
||||
rest: LazyPeriodsMin::from_source(
|
||||
let rest = if raw {
|
||||
LazyDateDerivedMin::from_source_raw(
|
||||
name,
|
||||
version + VERSION,
|
||||
dateindex.boxed_clone(),
|
||||
indexes,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
LazyDateDerivedMin::from_source(
|
||||
name,
|
||||
version + VERSION,
|
||||
dateindex.boxed_clone(),
|
||||
indexes,
|
||||
)
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
rest,
|
||||
dateindex,
|
||||
})
|
||||
}
|
||||
@@ -4,12 +4,19 @@ mod binary_sum;
|
||||
mod binary_sum_cum;
|
||||
mod first;
|
||||
mod last;
|
||||
mod lazy;
|
||||
mod lazy_full;
|
||||
mod lazy_last;
|
||||
mod lazy_sum;
|
||||
mod lazy_sum_cum;
|
||||
mod max;
|
||||
mod min;
|
||||
mod percentiles;
|
||||
mod ratio;
|
||||
mod stddev;
|
||||
mod value_derived_last;
|
||||
mod value_last;
|
||||
mod value_lazy_last;
|
||||
|
||||
pub use average::*;
|
||||
pub use binary_last::*;
|
||||
@@ -17,9 +24,16 @@ pub use binary_sum::*;
|
||||
pub use binary_sum_cum::*;
|
||||
pub use first::*;
|
||||
pub use last::*;
|
||||
pub use lazy::*;
|
||||
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 percentiles::*;
|
||||
pub use ratio::*;
|
||||
pub use stddev::*;
|
||||
pub use value_derived_last::*;
|
||||
pub use value_last::*;
|
||||
pub use value_lazy_last::*;
|
||||
@@ -8,7 +8,7 @@ use vecdb::{
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use super::super::ComputedDateLast;
|
||||
use super::ComputedFromDateLast;
|
||||
|
||||
pub const PERCENTILES: [u8; 19] = [
|
||||
5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95,
|
||||
@@ -17,7 +17,7 @@ pub const PERCENTILES_LEN: usize = PERCENTILES.len();
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CostBasisPercentiles {
|
||||
pub vecs: [Option<ComputedDateLast<Dollars>>; PERCENTILES_LEN],
|
||||
pub vecs: [Option<ComputedFromDateLast<Dollars>>; PERCENTILES_LEN],
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
@@ -37,7 +37,7 @@ impl CostBasisPercentiles {
|
||||
} else {
|
||||
format!("{name}_cost_basis_pct{p:02}")
|
||||
};
|
||||
ComputedDateLast::forced_import(db, &metric_name, version + VERSION, indexes)
|
||||
ComputedFromDateLast::forced_import(db, &metric_name, version + VERSION, indexes)
|
||||
.unwrap()
|
||||
})
|
||||
});
|
||||
@@ -81,7 +81,7 @@ impl CostBasisPercentiles {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get(&self, percentile: u8) -> Option<&ComputedDateLast<Dollars>> {
|
||||
pub fn get(&self, percentile: u8) -> Option<&ComputedFromDateLast<Dollars>> {
|
||||
PERCENTILES
|
||||
.iter()
|
||||
.position(|&p| p == percentile)
|
||||
@@ -9,49 +9,50 @@ use vecdb::{
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ComputedStandardDeviationVecsDate, LazyBinaryDateLast, PriceTimesRatio,
|
||||
ComputedFromDateStdDev, LazyBinaryFromDateLast, PriceTimesRatio,
|
||||
StandardDeviationVecsOptions,
|
||||
},
|
||||
price,
|
||||
utils::get_percentile,
|
||||
};
|
||||
|
||||
use super::super::{ComputedBlockLast, ComputedDateLast};
|
||||
use super::ComputedFromDateLast;
|
||||
use crate::internal::ComputedFromHeightLast;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ComputedRatioVecsDate {
|
||||
pub price: Option<ComputedDateLast<Dollars>>,
|
||||
pub struct ComputedFromDateRatio {
|
||||
pub price: Option<ComputedFromDateLast<Dollars>>,
|
||||
|
||||
pub ratio: ComputedDateLast<StoredF32>,
|
||||
pub ratio_1w_sma: Option<ComputedDateLast<StoredF32>>,
|
||||
pub ratio_1m_sma: Option<ComputedDateLast<StoredF32>>,
|
||||
pub ratio_pct99: Option<ComputedDateLast<StoredF32>>,
|
||||
pub ratio_pct98: Option<ComputedDateLast<StoredF32>>,
|
||||
pub ratio_pct95: Option<ComputedDateLast<StoredF32>>,
|
||||
pub ratio_pct5: Option<ComputedDateLast<StoredF32>>,
|
||||
pub ratio_pct2: Option<ComputedDateLast<StoredF32>>,
|
||||
pub ratio_pct1: Option<ComputedDateLast<StoredF32>>,
|
||||
pub ratio_pct99_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
|
||||
pub ratio_pct98_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
|
||||
pub ratio_pct95_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
|
||||
pub ratio_pct5_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
|
||||
pub ratio_pct2_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
|
||||
pub ratio_pct1_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
|
||||
pub ratio: ComputedFromDateLast<StoredF32>,
|
||||
pub ratio_1w_sma: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub ratio_1m_sma: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub ratio_pct99: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub ratio_pct98: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub ratio_pct95: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub ratio_pct5: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub ratio_pct2: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub ratio_pct1: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub ratio_pct99_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
|
||||
pub ratio_pct98_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
|
||||
pub ratio_pct95_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
|
||||
pub ratio_pct5_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
|
||||
pub ratio_pct2_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
|
||||
pub ratio_pct1_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
|
||||
|
||||
pub ratio_sd: Option<ComputedStandardDeviationVecsDate>,
|
||||
pub ratio_4y_sd: Option<ComputedStandardDeviationVecsDate>,
|
||||
pub ratio_2y_sd: Option<ComputedStandardDeviationVecsDate>,
|
||||
pub ratio_1y_sd: Option<ComputedStandardDeviationVecsDate>,
|
||||
pub ratio_sd: Option<ComputedFromDateStdDev>,
|
||||
pub ratio_4y_sd: Option<ComputedFromDateStdDev>,
|
||||
pub ratio_2y_sd: Option<ComputedFromDateStdDev>,
|
||||
pub ratio_1y_sd: Option<ComputedFromDateStdDev>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::TWO;
|
||||
|
||||
impl ComputedRatioVecsDate {
|
||||
impl ComputedFromDateRatio {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
metric_price: Option<&ComputedBlockLast<Dollars>>,
|
||||
metric_price: Option<&ComputedFromHeightLast<Dollars>>,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
extended: bool,
|
||||
@@ -61,7 +62,7 @@ impl ComputedRatioVecsDate {
|
||||
|
||||
macro_rules! import {
|
||||
($suffix:expr) => {
|
||||
ComputedDateLast::forced_import(db, &format!("{name}_{}", $suffix), v, indexes)
|
||||
ComputedFromDateLast::forced_import(db, &format!("{name}_{}", $suffix), v, indexes)
|
||||
.unwrap()
|
||||
};
|
||||
}
|
||||
@@ -69,11 +70,11 @@ impl ComputedRatioVecsDate {
|
||||
// Only compute internally when metric_price is None
|
||||
let price = metric_price
|
||||
.is_none()
|
||||
.then(|| ComputedDateLast::forced_import(db, name, v, indexes).unwrap());
|
||||
.then(|| ComputedFromDateLast::forced_import(db, name, v, indexes).unwrap());
|
||||
|
||||
macro_rules! import_sd {
|
||||
($suffix:expr, $days:expr) => {
|
||||
ComputedStandardDeviationVecsDate::forced_import(
|
||||
ComputedFromDateStdDev::forced_import(
|
||||
db,
|
||||
&format!("{name}_{}", $suffix),
|
||||
$days,
|
||||
@@ -97,7 +98,7 @@ impl ComputedRatioVecsDate {
|
||||
($ratio:expr, $suffix:expr) => {
|
||||
if let Some(mp) = metric_price {
|
||||
$ratio.as_ref().map(|r| {
|
||||
LazyBinaryDateLast::from_height_and_dateindex_last::<PriceTimesRatio>(
|
||||
LazyBinaryFromDateLast::from_height_and_dateindex_last::<PriceTimesRatio>(
|
||||
&format!("{name}_{}", $suffix),
|
||||
v,
|
||||
mp,
|
||||
@@ -106,7 +107,7 @@ impl ComputedRatioVecsDate {
|
||||
})
|
||||
} else {
|
||||
price.as_ref().zip($ratio.as_ref()).map(|(p, r)| {
|
||||
LazyBinaryDateLast::from_computed_both_last::<PriceTimesRatio>(
|
||||
LazyBinaryFromDateLast::from_computed_both_last::<PriceTimesRatio>(
|
||||
&format!("{name}_{}", $suffix),
|
||||
v,
|
||||
p,
|
||||
@@ -10,44 +10,44 @@ use vecdb::{
|
||||
|
||||
use crate::{ComputeIndexes, indexes, price};
|
||||
|
||||
use crate::internal::{ClosePriceTimesRatio, ComputedDateLast, LazyBinaryDateLast};
|
||||
use crate::internal::{ClosePriceTimesRatio, ComputedFromDateLast, LazyBinaryFromDateLast};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ComputedStandardDeviationVecsDate {
|
||||
pub struct ComputedFromDateStdDev {
|
||||
days: usize,
|
||||
|
||||
pub sma: Option<ComputedDateLast<StoredF32>>,
|
||||
pub sma: Option<ComputedFromDateLast<StoredF32>>,
|
||||
|
||||
pub sd: ComputedDateLast<StoredF32>,
|
||||
pub sd: ComputedFromDateLast<StoredF32>,
|
||||
|
||||
pub zscore: Option<ComputedDateLast<StoredF32>>,
|
||||
pub zscore: Option<ComputedFromDateLast<StoredF32>>,
|
||||
|
||||
pub p0_5sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub p1sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub p1_5sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub p2sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub p2_5sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub p3sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub m0_5sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub m1sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub m1_5sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub m2sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub m2_5sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub m3sd: Option<ComputedDateLast<StoredF32>>,
|
||||
pub p0_5sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub p1sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub p1_5sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub p2sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub p2_5sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub p3sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub m0_5sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub m1sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub m1_5sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub m2sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub m2_5sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
pub m3sd: Option<ComputedFromDateLast<StoredF32>>,
|
||||
|
||||
pub _0sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p0_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p1sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p1_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p2sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p2_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p3sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m0_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m1sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m1_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m2sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m2_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m3sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub _0sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p0_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p1sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p1_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p2sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p2_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub p3sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m0_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m1sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m1_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m2sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m2_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
pub m3sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
@@ -94,7 +94,7 @@ impl StandardDeviationVecsOptions {
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputedStandardDeviationVecsDate {
|
||||
impl ComputedFromDateStdDev {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
@@ -109,7 +109,7 @@ impl ComputedStandardDeviationVecsDate {
|
||||
|
||||
macro_rules! import {
|
||||
($suffix:expr) => {
|
||||
ComputedDateLast::forced_import(
|
||||
ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
&format!("{name}_{}", $suffix),
|
||||
version,
|
||||
@@ -140,7 +140,7 @@ impl ComputedStandardDeviationVecsDate {
|
||||
.zip($band.as_ref())
|
||||
.filter(|_| options.price_bands())
|
||||
.map(|(p, b)| {
|
||||
LazyBinaryDateLast::from_computed_both_last::<ClosePriceTimesRatio>(
|
||||
LazyBinaryFromDateLast::from_computed_both_last::<ClosePriceTimesRatio>(
|
||||
&format!("{name}_{}", $suffix),
|
||||
version,
|
||||
p,
|
||||
@@ -370,7 +370,7 @@ impl ComputedStandardDeviationVecsDate {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn mut_stateful_computed(&mut self) -> impl Iterator<Item = &mut ComputedDateLast<StoredF32>> {
|
||||
fn mut_stateful_computed(&mut self) -> impl Iterator<Item = &mut ComputedFromDateLast<StoredF32>> {
|
||||
[
|
||||
Some(&mut self.sd),
|
||||
self.p0_5sd.as_mut(),
|
||||
@@ -7,22 +7,22 @@ use vecdb::{Database, Exit, IterableBoxedVec};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{ComputedDateLast, LazyPeriodsLast, LazyDateLast, SatsToBitcoin},
|
||||
internal::{ComputedFromDateLast, LazyDateDerivedLast, LazyFromDateLast, SatsToBitcoin},
|
||||
price,
|
||||
traits::ComputeFromBitcoin,
|
||||
utils::OptionExt,
|
||||
};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ValueLazyPeriodsLast {
|
||||
pub sats: LazyPeriodsLast<Sats>,
|
||||
pub bitcoin: LazyDateLast<Bitcoin, Sats>,
|
||||
pub dollars: Option<ComputedDateLast<Dollars>>,
|
||||
pub struct LazyValueDateDerivedLast {
|
||||
pub sats: LazyDateDerivedLast<Sats>,
|
||||
pub bitcoin: LazyFromDateLast<Bitcoin, Sats>,
|
||||
pub dollars: Option<ComputedFromDateLast<Dollars>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl ValueLazyPeriodsLast {
|
||||
impl LazyValueDateDerivedLast {
|
||||
pub fn from_source(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -31,9 +31,9 @@ impl ValueLazyPeriodsLast {
|
||||
compute_dollars: bool,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let sats = LazyPeriodsLast::from_source(name, version + VERSION, source.clone(), indexes);
|
||||
let sats = LazyDateDerivedLast::from_source(name, version + VERSION, source.clone(), indexes);
|
||||
|
||||
let bitcoin = LazyDateLast::from_derived::<SatsToBitcoin>(
|
||||
let bitcoin = LazyFromDateLast::from_derived::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
version + VERSION,
|
||||
source,
|
||||
@@ -41,7 +41,7 @@ impl ValueLazyPeriodsLast {
|
||||
);
|
||||
|
||||
let dollars = compute_dollars.then(|| {
|
||||
ComputedDateLast::forced_import(db, &format!("{name}_usd"), version + VERSION, indexes)
|
||||
ComputedFromDateLast::forced_import(db, &format!("{name}_usd"), version + VERSION, indexes)
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
@@ -54,7 +54,7 @@ impl ValueLazyPeriodsLast {
|
||||
|
||||
pub fn compute_dollars<F>(&mut self, mut compute: F) -> Result<()>
|
||||
where
|
||||
F: FnMut(&mut ComputedDateLast<Dollars>) -> Result<()>,
|
||||
F: FnMut(&mut ComputedFromDateLast<Dollars>) -> Result<()>,
|
||||
{
|
||||
if let Some(dollars) = self.dollars.as_mut() {
|
||||
compute(dollars)?;
|
||||
@@ -8,21 +8,21 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes, price};
|
||||
|
||||
use super::ValueLazyPeriodsLast;
|
||||
use super::LazyValueDateDerivedLast;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ValueDateLast {
|
||||
pub struct ValueFromDateLast {
|
||||
#[traversable(rename = "sats")]
|
||||
pub sats_dateindex: EagerVec<PcoVec<DateIndex, Sats>>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: ValueLazyPeriodsLast,
|
||||
pub rest: LazyValueDateDerivedLast,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl ValueDateLast {
|
||||
impl ValueFromDateLast {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -32,7 +32,7 @@ impl ValueDateLast {
|
||||
) -> Result<Self> {
|
||||
let sats_dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
|
||||
|
||||
let rest = ValueLazyPeriodsLast::from_source(
|
||||
let rest = LazyValueDateDerivedLast::from_source(
|
||||
db,
|
||||
name,
|
||||
sats_dateindex.boxed_clone(),
|
||||
@@ -70,7 +70,7 @@ impl ValueDateLast {
|
||||
|
||||
pub fn compute_dollars<F>(&mut self, compute: F) -> Result<()>
|
||||
where
|
||||
F: FnMut(&mut crate::internal::ComputedDateLast<brk_types::Dollars>) -> Result<()>,
|
||||
F: FnMut(&mut crate::internal::ComputedFromDateLast<brk_types::Dollars>) -> Result<()>,
|
||||
{
|
||||
self.rest.compute_dollars(compute)
|
||||
}
|
||||
@@ -4,21 +4,21 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Sats, Version};
|
||||
use vecdb::{IterableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{LazyDateLast, ValueBlockLast, ValueDateLast};
|
||||
use crate::internal::{LazyFromDateLast, ValueFromHeightLast, ValueFromDateLast};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyValueDateLast {
|
||||
pub sats: LazyDateLast<Sats, Sats>,
|
||||
pub bitcoin: LazyDateLast<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyDateLast<Dollars, Dollars>>,
|
||||
pub struct LazyValueFromDateLast {
|
||||
pub sats: LazyFromDateLast<Sats, Sats>,
|
||||
pub bitcoin: LazyFromDateLast<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyFromDateLast<Dollars, Dollars>>,
|
||||
}
|
||||
|
||||
impl LazyValueDateLast {
|
||||
impl LazyValueFromDateLast {
|
||||
pub fn from_source<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
name: &str,
|
||||
source: &ValueDateLast,
|
||||
source: &ValueFromDateLast,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
@@ -28,14 +28,14 @@ impl LazyValueDateLast {
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = LazyDateLast::from_derived::<SatsTransform>(
|
||||
let sats = LazyFromDateLast::from_derived::<SatsTransform>(
|
||||
name,
|
||||
v,
|
||||
source.sats_dateindex.boxed_clone(),
|
||||
&source.sats,
|
||||
);
|
||||
|
||||
let bitcoin = LazyDateLast::from_derived::<BitcoinTransform>(
|
||||
let bitcoin = LazyFromDateLast::from_derived::<BitcoinTransform>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
source.sats_dateindex.boxed_clone(),
|
||||
@@ -43,7 +43,7 @@ impl LazyValueDateLast {
|
||||
);
|
||||
|
||||
let dollars = source.dollars.as_ref().map(|dollars_source| {
|
||||
LazyDateLast::from_computed::<DollarsTransform>(
|
||||
LazyFromDateLast::from_computed::<DollarsTransform>(
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
dollars_source.dateindex.boxed_clone(),
|
||||
@@ -56,7 +56,7 @@ impl LazyValueDateLast {
|
||||
|
||||
pub fn from_block_source<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
name: &str,
|
||||
source: &ValueBlockLast,
|
||||
source: &ValueFromHeightLast,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
@@ -66,25 +66,25 @@ impl LazyValueDateLast {
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = LazyDateLast::from_derived::<SatsTransform>(
|
||||
let sats = LazyFromDateLast::from_derived::<SatsTransform>(
|
||||
name,
|
||||
v,
|
||||
source.sats.rest.dateindex.0.boxed_clone(),
|
||||
source.sats.rest.dateindex.boxed_clone(),
|
||||
&source.sats.rest.dates,
|
||||
);
|
||||
|
||||
let bitcoin = LazyDateLast::from_derived::<BitcoinTransform>(
|
||||
let bitcoin = LazyFromDateLast::from_derived::<BitcoinTransform>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
source.sats.rest.dateindex.0.boxed_clone(),
|
||||
source.sats.rest.dateindex.boxed_clone(),
|
||||
&source.sats.rest.dates,
|
||||
);
|
||||
|
||||
let dollars = source.dollars.as_ref().map(|dollars_source| {
|
||||
LazyDateLast::from_derived::<DollarsTransform>(
|
||||
LazyFromDateLast::from_derived::<DollarsTransform>(
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
dollars_source.rest.dateindex.0.boxed_clone(),
|
||||
dollars_source.rest.dateindex.boxed_clone(),
|
||||
&dollars_source.rest.dates,
|
||||
)
|
||||
});
|
||||
@@ -7,27 +7,27 @@ use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, IterableBoxedVec, LazyVecFrom2};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockFull, ComputedVecValue, DerivedTxFull, LazyBinaryDerivedBlockSumCum, NumericValue,
|
||||
ComputedFromHeightFull, ComputedVecValue, TxDerivedFull, LazyBinaryHeightDerivedSumCum, NumericValue,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryBlockFull<T, S1T = T, S2T = T>
|
||||
pub struct LazyBinaryFromHeightFull<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
S2T: ComputedVecValue,
|
||||
{
|
||||
#[traversable(wrap = "base")]
|
||||
#[traversable(rename = "base")]
|
||||
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: LazyBinaryDerivedBlockSumCum<T, S1T, S2T>,
|
||||
pub rest: LazyBinaryHeightDerivedSumCum<T, S1T, S2T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryBlockFull<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyBinaryFromHeightFull<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: NumericValue + JsonSchema,
|
||||
@@ -38,14 +38,14 @@ where
|
||||
version: Version,
|
||||
height_source1: IterableBoxedVec<Height, S1T>,
|
||||
height_source2: IterableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedBlockFull<S1T>,
|
||||
source2: &DerivedTxFull<S2T>,
|
||||
source1: &ComputedFromHeightFull<S1T>,
|
||||
source2: &TxDerivedFull<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
height: LazyVecFrom2::transformed::<F>(name, v, height_source1, height_source2),
|
||||
rest: LazyBinaryDerivedBlockSumCum::from_derived_full::<F, _, _, _, _>(
|
||||
rest: LazyBinaryHeightDerivedSumCum::from_derived_full::<F, _, _, _, _>(
|
||||
name,
|
||||
v,
|
||||
&source1.dateindex.sum_cum,
|
||||
@@ -7,14 +7,14 @@ use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockLast, ComputedBlockSumCum, ComputedHeightDateLast, ComputedVecValue,
|
||||
LazyBinaryDateLast, LazyBinaryDerivedBlockLast, LazyBinaryTransformLast, LazyPeriodsLast,
|
||||
NumericValue,
|
||||
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedFromHeightAndDateLast, ComputedVecValue,
|
||||
LazyBinaryComputedFromHeightLast, LazyBinaryFromDateLast, LazyBinaryHeightDerivedLast,
|
||||
LazyBinaryTransformLast, LazyDateDerivedLast, NumericValue,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryBlockLast<T, S1T = T, S2T = T>
|
||||
pub struct LazyBinaryFromHeightLast<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -23,12 +23,12 @@ where
|
||||
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: LazyBinaryDerivedBlockLast<T, S1T, S2T>,
|
||||
pub rest: LazyBinaryHeightDerivedLast<T, S1T, S2T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryBlockLast<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyBinaryFromHeightLast<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -37,8 +37,8 @@ where
|
||||
pub fn from_computed_sum_cum<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockSumCum<S1T>,
|
||||
source2: &ComputedBlockSumCum<S2T>,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &ComputedFromHeightSumCum<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -50,18 +50,18 @@ where
|
||||
height: LazyVecFrom2::transformed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.height_cumulative.0.boxed_clone(),
|
||||
source2.height_cumulative.0.boxed_clone(),
|
||||
source1.height_cumulative.boxed_clone(),
|
||||
source2.height_cumulative.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockLast::from_computed_sum_cum::<F>(name, v, source1, source2),
|
||||
rest: LazyBinaryHeightDerivedLast::from_computed_sum_cum::<F>(name, v, source1, source2),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_computed_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockLast<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedFromHeightLast<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -76,15 +76,15 @@ where
|
||||
source1.height.boxed_clone(),
|
||||
source2.height.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockLast::from_computed_last::<F>(name, v, source1, source2),
|
||||
rest: LazyBinaryHeightDerivedLast::from_computed_last::<F>(name, v, source1, source2),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_computed_height_date_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedHeightDateLast<S1T>,
|
||||
source2: &ComputedHeightDateLast<S2T>,
|
||||
source1: &ComputedFromHeightAndDateLast<S1T>,
|
||||
source2: &ComputedFromHeightAndDateLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -99,18 +99,18 @@ where
|
||||
source1.height.boxed_clone(),
|
||||
source2.height.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockLast::from_computed_height_date_last::<F>(
|
||||
rest: LazyBinaryHeightDerivedLast::from_computed_height_date_last::<F>(
|
||||
name, v, source1, source2,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a ComputedHeightDateLast and a LazyBinaryBlockLast.
|
||||
/// Create from a ComputedFromHeightAndDateLast and a LazyBinaryFromHeightLast.
|
||||
pub fn from_computed_height_date_and_binary_block<F, S2aT, S2bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedHeightDateLast<S1T>,
|
||||
source2: &LazyBinaryBlockLast<S2T, S2aT, S2bT>,
|
||||
source1: &ComputedFromHeightAndDateLast<S1T>,
|
||||
source2: &LazyBinaryFromHeightLast<S2T, S2aT, S2bT>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
@@ -127,8 +127,8 @@ where
|
||||
source1.height.boxed_clone(),
|
||||
source2.height.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockLast {
|
||||
dates: LazyBinaryDateLast::from_computed_and_binary_last::<F, _, _>(
|
||||
rest: LazyBinaryHeightDerivedLast {
|
||||
dates: LazyBinaryFromDateLast::from_computed_and_binary_last::<F, _, _>(
|
||||
name,
|
||||
v,
|
||||
&source1.rest,
|
||||
@@ -137,19 +137,19 @@ where
|
||||
difficultyepoch: LazyBinaryTransformLast::from_vecs::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.difficultyepoch.0.boxed_clone(),
|
||||
source1.difficultyepoch.boxed_clone(),
|
||||
source2.rest.difficultyepoch.boxed_clone(),
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a ComputedHeightDateLast and a ComputedBlockLast.
|
||||
/// Create from a ComputedFromHeightAndDateLast and a ComputedFromHeightLast.
|
||||
pub fn from_computed_height_date_and_block_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedHeightDateLast<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedFromHeightAndDateLast<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -164,18 +164,18 @@ where
|
||||
source1.height.boxed_clone(),
|
||||
source2.height.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockLast::from_computed_height_date_and_block_last::<F>(
|
||||
rest: LazyBinaryHeightDerivedLast::from_computed_height_date_and_block_last::<F>(
|
||||
name, v, source1, source2,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a LazyBinaryBlockLast and a ComputedBlockLast.
|
||||
/// Create from a LazyBinaryFromHeightLast and a ComputedFromHeightLast.
|
||||
pub fn from_binary_block_and_computed_block_last<F, S1aT, S1bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryBlockLast<S1T, S1aT, S1bT>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &LazyBinaryFromHeightLast<S1T, S1aT, S1bT>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
@@ -192,8 +192,8 @@ where
|
||||
source1.height.boxed_clone(),
|
||||
source2.height.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockLast {
|
||||
dates: LazyBinaryDateLast::from_binary_and_block_last::<F, _, _>(
|
||||
rest: LazyBinaryHeightDerivedLast {
|
||||
dates: LazyBinaryFromDateLast::from_binary_and_block_last::<F, _, _>(
|
||||
name,
|
||||
v,
|
||||
&source1.rest.dates,
|
||||
@@ -209,12 +209,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from two LazyBinaryBlockLast sources.
|
||||
/// Create from two LazyBinaryFromHeightLast sources.
|
||||
pub fn from_both_binary_block<F, S1aT, S1bT, S2aT, S2bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryBlockLast<S1T, S1aT, S1bT>,
|
||||
source2: &LazyBinaryBlockLast<S2T, S2aT, S2bT>,
|
||||
source1: &LazyBinaryFromHeightLast<S1T, S1aT, S1bT>,
|
||||
source2: &LazyBinaryFromHeightLast<S2T, S2aT, S2bT>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
@@ -232,8 +232,8 @@ where
|
||||
source1.height.boxed_clone(),
|
||||
source2.height.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockLast {
|
||||
dates: LazyBinaryDateLast::from_both_binary_last::<F, _, _, _, _>(
|
||||
rest: LazyBinaryHeightDerivedLast {
|
||||
dates: LazyBinaryFromDateLast::from_both_binary_last::<F, _, _, _, _>(
|
||||
name,
|
||||
v,
|
||||
&source1.rest.dates,
|
||||
@@ -251,7 +251,7 @@ where
|
||||
|
||||
/// Create from separate height, difficultyepoch, and date sources.
|
||||
///
|
||||
/// Use when sources are split across different types (e.g., ValueHeightDateLast + ComputedBlockLast).
|
||||
/// Use when sources are split across different types (e.g., ValueFromHeightAndDateLast + ComputedFromHeightLast).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn from_height_difficultyepoch_dates<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
@@ -261,16 +261,16 @@ where
|
||||
difficultyepoch_source1: IterableBoxedVec<DifficultyEpoch, S1T>,
|
||||
difficultyepoch_source2: IterableBoxedVec<DifficultyEpoch, S2T>,
|
||||
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
|
||||
dates_source1: &LazyPeriodsLast<S1T>,
|
||||
dates_source1: &LazyDateDerivedLast<S1T>,
|
||||
dateindex_source2: IterableBoxedVec<DateIndex, S2T>,
|
||||
dates_source2: &LazyPeriodsLast<S2T>,
|
||||
dates_source2: &LazyDateDerivedLast<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
height: LazyVecFrom2::transformed::<F>(name, v, height_source1, height_source2),
|
||||
rest: LazyBinaryDerivedBlockLast {
|
||||
dates: LazyBinaryDateLast::from_both_derived_last::<F>(
|
||||
rest: LazyBinaryHeightDerivedLast {
|
||||
dates: LazyBinaryFromDateLast::from_both_derived_last::<F>(
|
||||
name,
|
||||
v,
|
||||
dateindex_source1,
|
||||
@@ -287,4 +287,86 @@ where
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a ComputedFromHeightAndDateLast and a LazyBinaryComputedFromHeightLast.
|
||||
pub fn from_computed_height_date_and_lazy_binary_block_last<F, S2aT, S2bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedFromHeightAndDateLast<S1T>,
|
||||
source2: &LazyBinaryComputedFromHeightLast<S2T, S2aT, S2bT>,
|
||||
) -> Self
|
||||
where
|
||||
F: BinaryTransform<S1T, S2T, T>,
|
||||
S1T: PartialOrd,
|
||||
S2aT: ComputedVecValue + JsonSchema,
|
||||
S2bT: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
height: LazyVecFrom2::transformed::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.height.boxed_clone(),
|
||||
source2.height.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryHeightDerivedLast {
|
||||
dates: LazyBinaryFromDateLast::from_both_derived_last::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.rest.dateindex.boxed_clone(),
|
||||
&source1.rest.rest,
|
||||
source2.rest.dateindex.boxed_clone(),
|
||||
&source2.rest.dates,
|
||||
),
|
||||
difficultyepoch: LazyBinaryTransformLast::from_vecs::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.difficultyepoch.boxed_clone(),
|
||||
source2.rest.difficultyepoch.boxed_clone(),
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from a LazyBinaryFromHeightLast and a LazyBinaryComputedFromHeightLast.
|
||||
pub fn from_binary_block_and_lazy_binary_block_last<F, S1aT, S1bT, S2aT, S2bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyBinaryFromHeightLast<S1T, S1aT, S1bT>,
|
||||
source2: &LazyBinaryComputedFromHeightLast<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.boxed_clone(),
|
||||
source2.height.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryHeightDerivedLast {
|
||||
dates: LazyBinaryFromDateLast::from_binary_and_derived_last::<F, _, _>(
|
||||
name,
|
||||
v,
|
||||
&source1.rest.dates,
|
||||
source2.rest.dateindex.boxed_clone(),
|
||||
&source2.rest.dates,
|
||||
),
|
||||
difficultyepoch: LazyBinaryTransformLast::from_vecs::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.rest.difficultyepoch.boxed_clone(),
|
||||
source2.rest.difficultyepoch.boxed_clone(),
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockSum, ComputedDerivedBlockSum, ComputedVecValue, LazyBinaryDerivedBlockSum,
|
||||
ComputedFromHeightSum, ComputedHeightDerivedSum, ComputedVecValue, LazyBinaryHeightDerivedSum,
|
||||
NumericValue,
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryBlockSum<T, S1T, S2T>
|
||||
pub struct LazyBinaryFromHeightSum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -25,10 +25,10 @@ where
|
||||
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: LazyBinaryDerivedBlockSum<T, S1T, S2T>,
|
||||
pub rest: LazyBinaryHeightDerivedSum<T, S1T, S2T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryBlockSum<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyBinaryFromHeightSum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: NumericValue + JsonSchema,
|
||||
@@ -39,22 +39,22 @@ where
|
||||
version: Version,
|
||||
height_source1: IterableBoxedVec<Height, S1T>,
|
||||
height_source2: IterableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedDerivedBlockSum<S1T>,
|
||||
source2: &ComputedDerivedBlockSum<S2T>,
|
||||
source1: &ComputedHeightDerivedSum<S1T>,
|
||||
source2: &ComputedHeightDerivedSum<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
height: LazyVecFrom2::transformed::<F>(name, v, height_source1, height_source2),
|
||||
rest: LazyBinaryDerivedBlockSum::from_derived::<F>(name, v, source1, source2),
|
||||
rest: LazyBinaryHeightDerivedSum::from_derived::<F>(name, v, source1, source2),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_computed<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockSum<S1T>,
|
||||
source2: &ComputedBlockSum<S2T>,
|
||||
source1: &ComputedFromHeightSum<S1T>,
|
||||
source2: &ComputedFromHeightSum<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -65,7 +65,7 @@ where
|
||||
source1.height.boxed_clone(),
|
||||
source2.height.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockSum::from_derived::<F>(name, v, &source1.rest, &source2.rest),
|
||||
rest: LazyBinaryHeightDerivedSum::from_derived::<F>(name, v, &source1.rest, &source2.rest),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,13 @@ use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockLast, ComputedBlockSumCum, ComputedDerivedBlockLast, ComputedDerivedBlockSumCum,
|
||||
ComputedVecValue, LazyBinaryDerivedBlockSumCum, NumericValue,
|
||||
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedHeightDerivedLast, ComputedHeightDerivedSumCum,
|
||||
ComputedVecValue, LazyBinaryHeightDerivedSumCum, NumericValue,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryBlockSumCum<T, S1T = T, S2T = T>
|
||||
pub struct LazyBinaryFromHeightSumCum<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -25,12 +25,12 @@ where
|
||||
pub height_cumulative: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: LazyBinaryDerivedBlockSumCum<T, S1T, S2T>,
|
||||
pub rest: LazyBinaryHeightDerivedSumCum<T, S1T, S2T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryBlockSumCum<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyBinaryFromHeightSumCum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -41,8 +41,8 @@ where
|
||||
version: Version,
|
||||
height_source1: IterableBoxedVec<Height, S1T>,
|
||||
height_source2: IterableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedBlockSumCum<S1T>,
|
||||
source2: &ComputedBlockSumCum<S2T>,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &ComputedFromHeightSumCum<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -55,10 +55,10 @@ where
|
||||
height_cumulative: LazyVecFrom2::transformed::<F>(
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
source1.height_cumulative.0.boxed_clone(),
|
||||
source2.height_cumulative.0.boxed_clone(),
|
||||
source1.height_cumulative.boxed_clone(),
|
||||
source2.height_cumulative.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockSumCum::from_computed_sum_raw::<F>(
|
||||
rest: LazyBinaryHeightDerivedSumCum::from_computed_sum_raw::<F>(
|
||||
name,
|
||||
v,
|
||||
&source1.dateindex,
|
||||
@@ -76,8 +76,8 @@ where
|
||||
version: Version,
|
||||
height_source1: IterableBoxedVec<Height, S1T>,
|
||||
height_source2: IterableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedDerivedBlockSumCum<S1T>,
|
||||
source2: &ComputedDerivedBlockSumCum<S2T>,
|
||||
source1: &ComputedHeightDerivedSumCum<S1T>,
|
||||
source2: &ComputedHeightDerivedSumCum<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -90,10 +90,10 @@ where
|
||||
height_cumulative: LazyVecFrom2::transformed::<F>(
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
source1.height_cumulative.0.boxed_clone(),
|
||||
source2.height_cumulative.0.boxed_clone(),
|
||||
source1.height_cumulative.boxed_clone(),
|
||||
source2.height_cumulative.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockSumCum::from_computed_sum_raw::<F>(
|
||||
rest: LazyBinaryHeightDerivedSumCum::from_computed_sum_raw::<F>(
|
||||
name,
|
||||
v,
|
||||
&source1.dateindex,
|
||||
@@ -113,8 +113,8 @@ where
|
||||
version: Version,
|
||||
height_source1: IterableBoxedVec<Height, S1T>,
|
||||
height_source2: IterableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedBlockSumCum<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -126,10 +126,10 @@ where
|
||||
height_cumulative: LazyVecFrom2::transformed::<F>(
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
source1.height_cumulative.0.boxed_clone(),
|
||||
source1.height_cumulative.boxed_clone(),
|
||||
source2.height.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockSumCum::from_computed_last::<F>(name, v, source1, source2),
|
||||
rest: LazyBinaryHeightDerivedSumCum::from_computed_last::<F>(name, v, source1, source2),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,8 +138,8 @@ where
|
||||
version: Version,
|
||||
height_source1: IterableBoxedVec<Height, S1T>,
|
||||
height_source2: IterableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedDerivedBlockSumCum<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedHeightDerivedSumCum<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -151,10 +151,10 @@ where
|
||||
height_cumulative: LazyVecFrom2::transformed::<F>(
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
source1.height_cumulative.0.boxed_clone(),
|
||||
source1.height_cumulative.boxed_clone(),
|
||||
source2.height.boxed_clone(),
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockSumCum::from_derived_computed_last::<F>(name, v, source1, source2),
|
||||
rest: LazyBinaryHeightDerivedSumCum::from_derived_computed_last::<F>(name, v, source1, source2),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,8 +163,8 @@ where
|
||||
version: Version,
|
||||
height_source1: IterableBoxedVec<Height, S1T>,
|
||||
height_source2: IterableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedDerivedBlockSumCum<S1T>,
|
||||
source2: &ComputedDerivedBlockLast<S2T>,
|
||||
source1: &ComputedHeightDerivedSumCum<S1T>,
|
||||
source2: &ComputedHeightDerivedLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -176,10 +176,10 @@ where
|
||||
height_cumulative: LazyVecFrom2::transformed::<F>(
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
source1.height_cumulative.0.boxed_clone(),
|
||||
source1.height_cumulative.boxed_clone(),
|
||||
height_source2,
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockSumCum::from_derived_last::<F>(name, v, source1, source2),
|
||||
rest: LazyBinaryHeightDerivedSumCum::from_derived_last::<F>(name, v, source1, source2),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,8 +188,8 @@ where
|
||||
version: Version,
|
||||
height_source1: IterableBoxedVec<Height, S1T>,
|
||||
height_source2: IterableBoxedVec<Height, S2T>,
|
||||
source1: &ComputedBlockSumCum<S1T>,
|
||||
source2: &ComputedDerivedBlockLast<S2T>,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &ComputedHeightDerivedLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -201,10 +201,10 @@ where
|
||||
height_cumulative: LazyVecFrom2::transformed::<F>(
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
source1.height_cumulative.0.boxed_clone(),
|
||||
source1.height_cumulative.boxed_clone(),
|
||||
height_source2,
|
||||
),
|
||||
rest: LazyBinaryDerivedBlockSumCum::from_computed_derived_last::<F>(name, v, source1, source2),
|
||||
rest: LazyBinaryHeightDerivedSumCum::from_computed_derived_last::<F>(name, v, source1, source2),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedBlock with full stats aggregation.
|
||||
//! ComputedFromHeight with full stats aggregation.
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
@@ -10,24 +10,24 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedVecValue, ComputedDerivedBlockFull, NumericValue};
|
||||
use crate::internal::{ComputedVecValue, ComputedHeightDerivedFull, NumericValue};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedBlockFull<T>
|
||||
pub struct ComputedFromHeightFull<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
#[traversable(wrap = "base")]
|
||||
#[traversable(rename = "base")]
|
||||
pub height: EagerVec<PcoVec<Height, T>>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: ComputedDerivedBlockFull<T>,
|
||||
pub rest: ComputedHeightDerivedFull<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedBlockFull<T>
|
||||
impl<T> ComputedFromHeightFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -41,7 +41,7 @@ where
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
|
||||
let rest = ComputedDerivedBlockFull::forced_import(
|
||||
let rest = ComputedHeightDerivedFull::forced_import(
|
||||
db,
|
||||
name,
|
||||
height.boxed_clone(),
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedBlock using Sum-only aggregation.
|
||||
//! ComputedFromHeight using only LastVec aggregation.
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
@@ -10,11 +10,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedVecValue, ComputedDerivedBlockSum, NumericValue};
|
||||
use crate::internal::{ComputedVecValue, ComputedHeightDerivedLast, NumericValue};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedBlockSum<T>
|
||||
pub struct ComputedFromHeightLast<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -22,12 +22,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: ComputedDerivedBlockSum<T>,
|
||||
pub rest: ComputedHeightDerivedLast<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedBlockSum<T>
|
||||
impl<T> ComputedFromHeightLast<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -42,7 +42,7 @@ where
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
|
||||
let rest =
|
||||
ComputedDerivedBlockSum::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
ComputedHeightDerivedLast::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
|
||||
Ok(Self { height, rest })
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
//! LazyBinaryComputedFromHeightFull - block full with lazy binary transform at height level.
|
||||
//!
|
||||
//! Height-level values are lazy: `transform(source1[h], source2[h])`.
|
||||
//! Cumulative, dateindex stats, and difficultyepoch are stored since they
|
||||
//! require aggregation across heights.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, Database, Exit, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{ComputedHeightDerivedFull, ComputedVecValue, NumericValue},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
/// Block full aggregation with lazy binary transform at height + computed derived indexes.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryComputedFromHeightFull<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: ComputedHeightDerivedFull<T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryComputedFromHeightFull<T, S1T, S2T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
S2T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub fn forced_import<F: BinaryTransform<S1T, S2T, T>>(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: IterableBoxedVec<Height, S1T>,
|
||||
source2: IterableBoxedVec<Height, S2T>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height = LazyVecFrom2::transformed::<F>(name, v, source1, source2);
|
||||
|
||||
let rest =
|
||||
ComputedHeightDerivedFull::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
|
||||
Ok(Self { height, rest })
|
||||
}
|
||||
|
||||
pub fn derive_from(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.rest
|
||||
.derive_from(indexes, starting_indexes, &self.height, exit)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
//! LazyBinaryComputedFromHeightLast - block last with lazy binary transform at height level.
|
||||
//!
|
||||
//! Height-level value is lazy: `transform(source1[h], source2[h])`.
|
||||
//! DateIndex last is stored since it requires finding the last value within each date
|
||||
//! (which may span multiple heights with varying prices).
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, Database, Exit, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{ComputedHeightDerivedLast, ComputedVecValue, NumericValue},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
/// Block last aggregation with lazy binary transform at height + computed derived indexes.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryComputedFromHeightLast<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
S2T: ComputedVecValue,
|
||||
{
|
||||
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: ComputedHeightDerivedLast<T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryComputedFromHeightLast<T, S1T, S2T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
S2T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub fn forced_import<F: BinaryTransform<S1T, S2T, T>>(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: IterableBoxedVec<Height, S1T>,
|
||||
source2: IterableBoxedVec<Height, S2T>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height = LazyVecFrom2::transformed::<F>(name, v, source1, source2);
|
||||
|
||||
let rest =
|
||||
ComputedHeightDerivedLast::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
|
||||
Ok(Self { height, rest })
|
||||
}
|
||||
|
||||
pub fn derive_from(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.rest
|
||||
.derive_from(indexes, starting_indexes, &self.height, exit)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
//! LazyBinaryComputedFromHeightSum - block sum with lazy binary transform at height level.
|
||||
//!
|
||||
//! Height-level sum is lazy: `transform(source1[h], source2[h])`.
|
||||
//! DateIndex stats are stored since they require aggregation across heights.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, Database, Exit, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, 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: ComputedHeightDerivedSum<T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryComputedFromHeightSum<T, S1T, S2T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
S2T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub fn forced_import<F: BinaryTransform<S1T, S2T, T>>(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: IterableBoxedVec<Height, S1T>,
|
||||
source2: IterableBoxedVec<Height, S2T>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height = LazyVecFrom2::transformed::<F>(name, v, source1, source2);
|
||||
|
||||
let rest =
|
||||
ComputedHeightDerivedSum::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
|
||||
Ok(Self { height, rest })
|
||||
}
|
||||
|
||||
pub fn derive_from(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.rest
|
||||
.derive_from(indexes, starting_indexes, &self.height, exit)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
//! LazyBinaryComputedFromHeightSumCum - block sum_cum with lazy binary transform at height level.
|
||||
//!
|
||||
//! Height-level sum is lazy: `transform(source1[h], source2[h])`.
|
||||
//! Cumulative and dateindex stats are stored since they require aggregation
|
||||
//! across heights.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, Database, Exit, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{ComputedHeightDerivedSumCum, ComputedVecValue, NumericValue},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
/// Block sum_cum aggregation with lazy binary transform at height + computed derived indexes.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryComputedFromHeightSumCum<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: ComputedHeightDerivedSumCum<T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryComputedFromHeightSumCum<T, S1T, S2T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
S2T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub fn forced_import<F: BinaryTransform<S1T, S2T, T>>(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: IterableBoxedVec<Height, S1T>,
|
||||
source2: IterableBoxedVec<Height, S2T>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height = LazyVecFrom2::transformed::<F>(name, v, source1, source2);
|
||||
|
||||
let rest =
|
||||
ComputedHeightDerivedSumCum::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
|
||||
Ok(Self { height, rest })
|
||||
}
|
||||
|
||||
pub fn derive_from(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.rest
|
||||
.derive_from(indexes, starting_indexes, &self.height, exit)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//! LazyBlockFullHeight - block full with lazy height transform.
|
||||
//! LazyComputedFromHeightFull - block full with lazy height transform.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -9,7 +9,7 @@ use vecdb::{Database, Exit, IterableCloneableVec, LazyVecFrom1, UnaryTransform};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{ComputedVecValue, ComputedDerivedBlockFull, NumericValue},
|
||||
internal::{ComputedVecValue, ComputedHeightDerivedFull, NumericValue},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
@@ -17,7 +17,7 @@ const VERSION: Version = Version::ZERO;
|
||||
/// Block full aggregation with lazy height transform + computed derived indexes.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBlockFullHeight<T, S = T>
|
||||
pub struct LazyComputedFromHeightFull<T, S = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S: ComputedVecValue,
|
||||
@@ -26,10 +26,10 @@ where
|
||||
pub height: LazyVecFrom1<Height, T, Height, S>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: ComputedDerivedBlockFull<T>,
|
||||
pub rest: ComputedHeightDerivedFull<T>,
|
||||
}
|
||||
|
||||
impl<T, S> LazyBlockFullHeight<T, S>
|
||||
impl<T, S> LazyComputedFromHeightFull<T, S>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
S: ComputedVecValue + JsonSchema,
|
||||
@@ -46,7 +46,7 @@ where
|
||||
let height = LazyVecFrom1::transformed::<F>(name, v, source.boxed_clone());
|
||||
|
||||
let rest =
|
||||
ComputedDerivedBlockFull::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
ComputedHeightDerivedFull::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
|
||||
Ok(Self { height, rest })
|
||||
}
|
||||
@@ -64,7 +64,7 @@ where
|
||||
let height = LazyVecFrom1::init(name, v, source.boxed_clone(), init_fn);
|
||||
|
||||
let rest =
|
||||
ComputedDerivedBlockFull::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
ComputedHeightDerivedFull::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
|
||||
Ok(Self { height, rest })
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//! LazyBlockSumCumHeight - block sum+cumulative with lazy height transform.
|
||||
//! LazyComputedFromHeightSumCum - block sum+cumulative with lazy height transform.
|
||||
//!
|
||||
//! Use this when you need:
|
||||
//! - Lazy height (binary transform from two sources)
|
||||
@@ -14,7 +14,7 @@ use vecdb::{Database, Exit, IterableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
|
||||
use crate::internal::{ComputedVecValue, ComputedDerivedBlockSumCum, NumericValue};
|
||||
use crate::internal::{ComputedVecValue, ComputedHeightDerivedSumCum, NumericValue};
|
||||
|
||||
/// Block sum+cumulative with lazy binary height transform + computed derived indexes.
|
||||
///
|
||||
@@ -23,7 +23,7 @@ use crate::internal::{ComputedVecValue, ComputedDerivedBlockSumCum, NumericValue
|
||||
/// Coarser periods are lazy lookups.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBlockSumCumHeight<T, S1T = T, S2T = T>
|
||||
pub struct LazyComputedFromHeightSumCum<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -33,12 +33,12 @@ where
|
||||
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: ComputedDerivedBlockSumCum<T>,
|
||||
pub rest: ComputedHeightDerivedSumCum<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T, S2T> LazyBlockSumCumHeight<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyComputedFromHeightSumCum<T, S1T, S2T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -53,7 +53,7 @@ where
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let rest = ComputedDerivedBlockSumCum::forced_import(
|
||||
let rest = ComputedHeightDerivedSumCum::forced_import(
|
||||
db,
|
||||
name,
|
||||
height.boxed_clone(),
|
||||
@@ -1,4 +1,4 @@
|
||||
//! LazyBlockDistribution - lazy height + derived distribution (avg/min/max) for indexes.
|
||||
//! LazyFromHeightDistribution - lazy height + derived distribution (avg/min/max) for indexes.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -9,7 +9,7 @@ use vecdb::{ComputeFrom1, Database, Exit, IterableCloneableVec, LazyVecFrom1, Un
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{ComputedVecValue, ComputedDerivedBlockDistribution, NumericValue},
|
||||
internal::{ComputedVecValue, ComputedHeightDerivedDistribution, NumericValue},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
@@ -20,7 +20,7 @@ const VERSION: Version = Version::ZERO;
|
||||
/// Indexes (dateindex + periods + difficultyepoch) store distribution stats (avg/min/max).
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBlockDistribution<T, S = T>
|
||||
pub struct LazyFromHeightDistribution<T, S = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S: ComputedVecValue,
|
||||
@@ -30,10 +30,10 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: ComputedDerivedBlockDistribution<T>,
|
||||
pub rest: ComputedHeightDerivedDistribution<T>,
|
||||
}
|
||||
|
||||
impl<T, S> LazyBlockDistribution<T, S>
|
||||
impl<T, S> LazyFromHeightDistribution<T, S>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
S: ComputedVecValue + JsonSchema,
|
||||
@@ -49,7 +49,7 @@ where
|
||||
|
||||
let height = LazyVecFrom1::transformed::<F>(name, v, source.boxed_clone());
|
||||
|
||||
let rest = ComputedDerivedBlockDistribution::forced_import(
|
||||
let rest = ComputedHeightDerivedDistribution::forced_import(
|
||||
db,
|
||||
name,
|
||||
height.boxed_clone(),
|
||||
@@ -72,7 +72,7 @@ where
|
||||
|
||||
let height = LazyVecFrom1::init(name, v, source.boxed_clone(), init_fn);
|
||||
|
||||
let rest = ComputedDerivedBlockDistribution::forced_import(
|
||||
let rest = ComputedHeightDerivedDistribution::forced_import(
|
||||
db,
|
||||
name,
|
||||
height.boxed_clone(),
|
||||
@@ -7,26 +7,26 @@ use schemars::JsonSchema;
|
||||
use vecdb::{IterableBoxedVec, LazyVecFrom1, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockFull, ComputedDerivedBlockFull, ComputedVecValue, LazyDerivedBlockFull,
|
||||
ComputedFromHeightFull, ComputedHeightDerivedFull, ComputedVecValue, LazyHeightDerivedFull,
|
||||
NumericValue,
|
||||
};
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBlockFull<T, S1T = T>
|
||||
pub struct LazyFromHeightFull<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
{
|
||||
#[traversable(wrap = "base")]
|
||||
#[traversable(rename = "base")]
|
||||
pub height: LazyVecFrom1<Height, T, Height, S1T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: LazyDerivedBlockFull<T, S1T>,
|
||||
pub rest: LazyHeightDerivedFull<T, S1T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyBlockFull<T, S1T>
|
||||
impl<T, S1T> LazyFromHeightFull<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -35,12 +35,12 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: IterableBoxedVec<Height, S1T>,
|
||||
source: &ComputedBlockFull<S1T>,
|
||||
source: &ComputedFromHeightFull<S1T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: LazyDerivedBlockFull::from_computed::<F>(
|
||||
rest: LazyHeightDerivedFull::from_computed::<F>(
|
||||
name,
|
||||
v,
|
||||
&source.dateindex,
|
||||
@@ -54,7 +54,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: IterableBoxedVec<Height, S1T>,
|
||||
source: &ComputedDerivedBlockFull<S1T>,
|
||||
source: &ComputedHeightDerivedFull<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -62,7 +62,7 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: LazyDerivedBlockFull::from_derived_computed::<F>(name, v, source),
|
||||
rest: LazyHeightDerivedFull::from_derived_computed::<F>(name, v, source),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,12 @@ use schemars::JsonSchema;
|
||||
use vecdb::{IterableBoxedVec, IterableCloneableVec, LazyVecFrom1, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockLast, ComputedDerivedBlockLast, ComputedHeightDateLast, ComputedVecValue,
|
||||
LazyDerivedBlockLast, NumericValue,
|
||||
ComputedFromHeightAndDateLast, ComputedFromHeightLast, ComputedHeightDerivedLast,
|
||||
ComputedVecValue, LazyBinaryComputedFromHeightLast, LazyHeightDerivedLast, NumericValue,
|
||||
};
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBlockLast<T, S1T = T>
|
||||
pub struct LazyFromHeightLast<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -20,12 +20,13 @@ where
|
||||
pub height: LazyVecFrom1<Height, T, Height, S1T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: LazyDerivedBlockLast<T, S1T>,
|
||||
#[traversable(flatten)]
|
||||
pub rest: LazyHeightDerivedLast<T, S1T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyBlockLast<T, S1T>
|
||||
impl<T, S1T> LazyFromHeightLast<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -34,7 +35,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: IterableBoxedVec<Height, S1T>,
|
||||
source: &ComputedBlockLast<S1T>,
|
||||
source: &ComputedFromHeightLast<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -42,7 +43,7 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: LazyDerivedBlockLast::from_computed::<F>(name, v, source),
|
||||
rest: LazyHeightDerivedLast::from_computed::<F>(name, v, source),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: IterableBoxedVec<Height, S1T>,
|
||||
source: &ComputedDerivedBlockLast<S1T>,
|
||||
source: &ComputedHeightDerivedLast<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -58,14 +59,14 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: LazyDerivedBlockLast::from_derived_computed::<F>(name, v, source),
|
||||
rest: LazyHeightDerivedLast::from_derived_computed::<F>(name, v, source),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_computed_height_date<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedHeightDateLast<S1T>,
|
||||
source: &ComputedFromHeightAndDateLast<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -73,7 +74,26 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, source.height.boxed_clone()),
|
||||
rest: LazyDerivedBlockLast::from_computed_height_date::<F>(name, v, source),
|
||||
rest: LazyHeightDerivedLast::from_computed_height_date::<F>(name, v, source),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_lazy_binary_computed<F, S1aT, S1bT>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: IterableBoxedVec<Height, S1T>,
|
||||
source: &LazyBinaryComputedFromHeightLast<S1T, S1aT, S1bT>,
|
||||
) -> Self
|
||||
where
|
||||
F: UnaryTransform<S1T, T>,
|
||||
S1T: NumericValue,
|
||||
S1aT: ComputedVecValue + JsonSchema,
|
||||
S1bT: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: LazyHeightDerivedLast::from_derived_computed::<F>(name, v, &source.rest),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,11 @@ use schemars::JsonSchema;
|
||||
use vecdb::{IterableBoxedVec, LazyVecFrom1, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockSum, ComputedDerivedBlockSum, ComputedVecValue, LazyDerivedBlockSum, NumericValue,
|
||||
ComputedFromHeightSum, ComputedHeightDerivedSum, ComputedVecValue, LazyHeightDerivedSum, NumericValue,
|
||||
};
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBlockSum<T, S1T = T>
|
||||
pub struct LazyFromHeightSum<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -20,12 +20,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: LazyDerivedBlockSum<T, S1T>,
|
||||
pub rest: LazyHeightDerivedSum<T, S1T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyBlockSum<T, S1T>
|
||||
impl<T, S1T> LazyFromHeightSum<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -34,12 +34,12 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: IterableBoxedVec<Height, S1T>,
|
||||
source: &ComputedBlockSum<S1T>,
|
||||
source: &ComputedFromHeightSum<S1T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: LazyDerivedBlockSum::from_computed::<F>(
|
||||
rest: LazyHeightDerivedSum::from_computed::<F>(
|
||||
name,
|
||||
v,
|
||||
&source.dateindex,
|
||||
@@ -53,7 +53,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: IterableBoxedVec<Height, S1T>,
|
||||
source: &ComputedDerivedBlockSum<S1T>,
|
||||
source: &ComputedHeightDerivedSum<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -61,7 +61,7 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: LazyDerivedBlockSum::from_derived_computed::<F>(name, v, source),
|
||||
rest: LazyHeightDerivedSum::from_derived_computed::<F>(name, v, source),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,12 @@ use schemars::JsonSchema;
|
||||
use vecdb::{IterableBoxedVec, LazyVecFrom1, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockSumCum, ComputedDerivedBlockSumCum, ComputedVecValue, LazyDerivedBlockSumCum,
|
||||
NumericValue,
|
||||
ComputedFromHeightSumCum, ComputedHeightDerivedSumCum, ComputedVecValue,
|
||||
LazyHeightDerivedSumCum, NumericValue,
|
||||
};
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBlockSumCum<T, S1T = T>
|
||||
pub struct LazyFromHeightSumCum<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -21,12 +21,13 @@ where
|
||||
pub height: LazyVecFrom1<Height, T, Height, S1T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: LazyDerivedBlockSumCum<T, S1T>,
|
||||
#[traversable(flatten)]
|
||||
pub rest: LazyHeightDerivedSumCum<T, S1T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyBlockSumCum<T, S1T>
|
||||
impl<T, S1T> LazyFromHeightSumCum<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -35,12 +36,12 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: IterableBoxedVec<Height, S1T>,
|
||||
source: &ComputedBlockSumCum<S1T>,
|
||||
source: &ComputedFromHeightSumCum<S1T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: LazyDerivedBlockSumCum::from_computed::<F>(
|
||||
rest: LazyHeightDerivedSumCum::from_computed::<F>(
|
||||
name,
|
||||
v,
|
||||
&source.dateindex,
|
||||
@@ -54,7 +55,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: IterableBoxedVec<Height, S1T>,
|
||||
source: &ComputedDerivedBlockSumCum<S1T>,
|
||||
source: &ComputedHeightDerivedSumCum<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -62,7 +63,7 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: LazyDerivedBlockSumCum::from_derived_computed::<F>(name, v, source),
|
||||
rest: LazyHeightDerivedSumCum::from_derived_computed::<F>(name, v, source),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,21 +3,21 @@ use brk_types::{Bitcoin, Close, Dollars, Height, Sats, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{BinaryTransform, IterableBoxedVec, LazyVecFrom1, LazyVecFrom2, UnaryTransform};
|
||||
|
||||
use super::LazyDerivedBlockValue;
|
||||
use crate::internal::LazyDerivedValuesHeight;
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBlockValue {
|
||||
pub struct LazyFromHeightValue {
|
||||
#[traversable(rename = "sats")]
|
||||
pub sats: LazyVecFrom1<Height, Sats, Height, Sats>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: LazyDerivedBlockValue,
|
||||
pub rest: LazyDerivedValuesHeight,
|
||||
}
|
||||
|
||||
impl LazyBlockValue {
|
||||
impl LazyFromHeightValue {
|
||||
pub fn from_sources<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
name: &str,
|
||||
sats_source: IterableBoxedVec<Height, Sats>,
|
||||
@@ -50,7 +50,7 @@ impl LazyBlockValue {
|
||||
|
||||
Self {
|
||||
sats,
|
||||
rest: LazyDerivedBlockValue { bitcoin, dollars },
|
||||
rest: LazyDerivedValuesHeight { bitcoin, dollars },
|
||||
}
|
||||
}
|
||||
}
|
||||
59
crates/brk_computer/src/internal/multi/from_height/mod.rs
Normal file
59
crates/brk_computer/src/internal/multi/from_height/mod.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
mod binary_full;
|
||||
mod binary_last;
|
||||
mod binary_sum;
|
||||
mod binary_sum_cum;
|
||||
mod full;
|
||||
mod last;
|
||||
mod lazy_distribution;
|
||||
mod lazy_full;
|
||||
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_last;
|
||||
mod lazy_sum;
|
||||
mod lazy_sum_cum;
|
||||
mod sum;
|
||||
mod sum_cum;
|
||||
mod value_binary;
|
||||
mod value_full;
|
||||
mod value_last;
|
||||
mod value_lazy_binary_last;
|
||||
mod lazy_value;
|
||||
mod value_lazy_computed_sum_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 full::*;
|
||||
pub use last::*;
|
||||
pub use lazy_distribution::*;
|
||||
pub use lazy_full::*;
|
||||
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_last::*;
|
||||
pub use lazy_sum::*;
|
||||
pub use lazy_sum_cum::*;
|
||||
pub use sum::*;
|
||||
pub use sum_cum::*;
|
||||
pub use value_binary::*;
|
||||
pub use value_full::*;
|
||||
pub use value_last::*;
|
||||
pub use value_lazy_binary_last::*;
|
||||
pub use lazy_value::*;
|
||||
pub use value_lazy_computed_sum_cum::*;
|
||||
pub use value_lazy_last::*;
|
||||
pub use value_lazy_sum_cum::*;
|
||||
pub use value_sum::*;
|
||||
pub use value_sum_cum::*;
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedBlock using only LastVec aggregation.
|
||||
//! ComputedFromHeight using Sum-only aggregation.
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
@@ -10,11 +10,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedVecValue, ComputedDerivedBlockLast, NumericValue};
|
||||
use crate::internal::{ComputedVecValue, ComputedHeightDerivedSum, NumericValue};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedBlockLast<T>
|
||||
pub struct ComputedFromHeightSum<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -22,12 +22,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: ComputedDerivedBlockLast<T>,
|
||||
pub rest: ComputedHeightDerivedSum<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedBlockLast<T>
|
||||
impl<T> ComputedFromHeightSum<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -42,7 +42,7 @@ where
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
|
||||
let rest =
|
||||
ComputedDerivedBlockLast::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
ComputedHeightDerivedSum::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
|
||||
Ok(Self { height, rest })
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedBlock using SumCum aggregation.
|
||||
//! ComputedFromHeight using SumCum aggregation.
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
@@ -11,13 +11,13 @@ use vecdb::{
|
||||
IterableCloneableVec, IterableVec, PcoVec, VecIndex,
|
||||
};
|
||||
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedVecValue, ComputedDerivedBlockSumCum, NumericValue};
|
||||
use crate::internal::{ComputedHeightDerivedSumCum, ComputedVecValue, NumericValue};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedBlockSumCum<T>
|
||||
pub struct ComputedFromHeightSumCum<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -25,12 +25,13 @@ where
|
||||
pub height: EagerVec<PcoVec<Height, T>>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub rest: ComputedDerivedBlockSumCum<T>,
|
||||
#[traversable(flatten)]
|
||||
pub rest: ComputedHeightDerivedSumCum<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedBlockSumCum<T>
|
||||
impl<T> ComputedFromHeightSumCum<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -44,13 +45,8 @@ where
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
|
||||
let rest = ComputedDerivedBlockSumCum::forced_import(
|
||||
db,
|
||||
name,
|
||||
height.boxed_clone(),
|
||||
v,
|
||||
indexes,
|
||||
)?;
|
||||
let rest =
|
||||
ComputedHeightDerivedSumCum::forced_import(db, name, height.boxed_clone(), v, indexes)?;
|
||||
|
||||
Ok(Self { height, rest })
|
||||
}
|
||||
@@ -76,7 +72,8 @@ where
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.rest.derive_from(indexes, starting_indexes, &self.height, exit)
|
||||
self.rest
|
||||
.derive_from(indexes, starting_indexes, &self.height, exit)
|
||||
}
|
||||
|
||||
/// Derive from an external height source (e.g., a LazyVec).
|
||||
@@ -101,6 +98,7 @@ where
|
||||
}
|
||||
self.height.write()?;
|
||||
|
||||
self.rest.derive_from(indexes, starting_indexes, &self.height, exit)
|
||||
self.rest
|
||||
.derive_from(indexes, starting_indexes, &self.height, exit)
|
||||
}
|
||||
}
|
||||
@@ -4,34 +4,34 @@ use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, IterableBoxedVec, IterableCloneableVec};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedVecValue, ValueDerivedBlockSumCum, LazyBinaryBlockSumCum, LazyValueBlockSumCum,
|
||||
ValueBlockSumCum,
|
||||
ComputedVecValue, ValueHeightDerivedSumCum, LazyBinaryFromHeightSumCum, LazyValueFromHeightSumCum,
|
||||
ValueFromHeightSumCum,
|
||||
};
|
||||
|
||||
/// Lazy value vecs computed from two ValueBlockSumCum sources via binary transforms.
|
||||
/// Lazy value vecs computed from two ValueFromHeightSumCum sources via binary transforms.
|
||||
/// Used for computing coinbase = subsidy + fee.
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ValueBinaryBlock {
|
||||
pub sats: LazyBinaryBlockSumCum<Sats, Sats, Sats>,
|
||||
pub bitcoin: LazyBinaryBlockSumCum<Bitcoin, Sats, Sats>,
|
||||
pub dollars: Option<LazyBinaryBlockSumCum<Dollars, Dollars, Dollars>>,
|
||||
pub struct ValueBinaryFromHeight {
|
||||
pub sats: LazyBinaryFromHeightSumCum<Sats, Sats, Sats>,
|
||||
pub bitcoin: LazyBinaryFromHeightSumCum<Bitcoin, Sats, Sats>,
|
||||
pub dollars: Option<LazyBinaryFromHeightSumCum<Dollars, Dollars, Dollars>>,
|
||||
}
|
||||
|
||||
impl ValueBinaryBlock {
|
||||
impl ValueBinaryFromHeight {
|
||||
pub fn from_computed<SatsF, BitcoinF, DollarsF>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source1: IterableBoxedVec<Height, Sats>,
|
||||
height_source2: IterableBoxedVec<Height, Sats>,
|
||||
source1: &ValueBlockSumCum,
|
||||
source2: &ValueBlockSumCum,
|
||||
source1: &ValueFromHeightSumCum,
|
||||
source2: &ValueFromHeightSumCum,
|
||||
) -> Self
|
||||
where
|
||||
SatsF: BinaryTransform<Sats, Sats, Sats>,
|
||||
BitcoinF: BinaryTransform<Sats, Sats, Bitcoin>,
|
||||
DollarsF: BinaryTransform<Dollars, Dollars, Dollars>,
|
||||
{
|
||||
let sats = LazyBinaryBlockSumCum::from_computed::<SatsF>(
|
||||
let sats = LazyBinaryFromHeightSumCum::from_computed::<SatsF>(
|
||||
name,
|
||||
version,
|
||||
height_source1.boxed_clone(),
|
||||
@@ -40,7 +40,7 @@ impl ValueBinaryBlock {
|
||||
&source2.sats,
|
||||
);
|
||||
|
||||
let bitcoin = LazyBinaryBlockSumCum::from_computed::<BitcoinF>(
|
||||
let bitcoin = LazyBinaryFromHeightSumCum::from_computed::<BitcoinF>(
|
||||
&format!("{name}_btc"),
|
||||
version,
|
||||
height_source1,
|
||||
@@ -49,18 +49,20 @@ impl ValueBinaryBlock {
|
||||
&source2.sats,
|
||||
);
|
||||
|
||||
// For dollars: use from_derived since the height is now lazy (LazyVecFrom2)
|
||||
// The rest (cumulative, dateindex) is still ComputedHeightDerivedSumCum
|
||||
let dollars = source1
|
||||
.dollars
|
||||
.as_ref()
|
||||
.zip(source2.dollars.as_ref())
|
||||
.map(|(d1, d2)| {
|
||||
LazyBinaryBlockSumCum::from_computed::<DollarsF>(
|
||||
LazyBinaryFromHeightSumCum::from_derived::<DollarsF>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
d1.height.boxed_clone(),
|
||||
d2.height.boxed_clone(),
|
||||
d1,
|
||||
d2,
|
||||
&d1.rest,
|
||||
&d2.rest,
|
||||
)
|
||||
});
|
||||
|
||||
@@ -76,15 +78,15 @@ impl ValueBinaryBlock {
|
||||
version: Version,
|
||||
height_source1: IterableBoxedVec<Height, Sats>,
|
||||
height_source2: IterableBoxedVec<Height, Sats>,
|
||||
source1: &ValueDerivedBlockSumCum,
|
||||
source2: &ValueDerivedBlockSumCum,
|
||||
source1: &ValueHeightDerivedSumCum,
|
||||
source2: &ValueHeightDerivedSumCum,
|
||||
) -> Self
|
||||
where
|
||||
SatsF: BinaryTransform<Sats, Sats, Sats>,
|
||||
BitcoinF: BinaryTransform<Sats, Sats, Bitcoin>,
|
||||
DollarsF: BinaryTransform<Dollars, Dollars, Dollars>,
|
||||
{
|
||||
let sats = LazyBinaryBlockSumCum::from_derived::<SatsF>(
|
||||
let sats = LazyBinaryFromHeightSumCum::from_derived::<SatsF>(
|
||||
name,
|
||||
version,
|
||||
height_source1.boxed_clone(),
|
||||
@@ -93,7 +95,7 @@ impl ValueBinaryBlock {
|
||||
&source2.sats,
|
||||
);
|
||||
|
||||
let bitcoin = LazyBinaryBlockSumCum::from_derived::<BitcoinF>(
|
||||
let bitcoin = LazyBinaryFromHeightSumCum::from_derived::<BitcoinF>(
|
||||
&format!("{name}_btc"),
|
||||
version,
|
||||
height_source1,
|
||||
@@ -107,11 +109,11 @@ impl ValueBinaryBlock {
|
||||
.as_ref()
|
||||
.zip(source2.dollars.as_ref())
|
||||
.map(|(d1, d2)| {
|
||||
LazyBinaryBlockSumCum::from_derived::<DollarsF>(
|
||||
LazyBinaryFromHeightSumCum::from_derived::<DollarsF>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
d1.height_cumulative.0.boxed_clone(),
|
||||
d2.height_cumulative.0.boxed_clone(),
|
||||
d1.height_cumulative.boxed_clone(),
|
||||
d2.height_cumulative.boxed_clone(),
|
||||
d1,
|
||||
d2,
|
||||
)
|
||||
@@ -127,8 +129,8 @@ impl ValueBinaryBlock {
|
||||
pub fn from_lazy<SatsF, BitcoinF, DollarsF, S1T, S2T>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &LazyValueBlockSumCum<S1T, S2T>,
|
||||
source2: &LazyValueBlockSumCum<S1T, S2T>,
|
||||
source1: &LazyValueFromHeightSumCum<S1T, S2T>,
|
||||
source2: &LazyValueFromHeightSumCum<S1T, S2T>,
|
||||
) -> Self
|
||||
where
|
||||
SatsF: BinaryTransform<Sats, Sats, Sats>,
|
||||
@@ -137,7 +139,7 @@ impl ValueBinaryBlock {
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
S2T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
let sats = LazyBinaryBlockSumCum::from_derived::<SatsF>(
|
||||
let sats = LazyBinaryFromHeightSumCum::from_derived::<SatsF>(
|
||||
name,
|
||||
version,
|
||||
source1.sats.height.boxed_clone(),
|
||||
@@ -146,7 +148,7 @@ impl ValueBinaryBlock {
|
||||
&source2.sats.rest,
|
||||
);
|
||||
|
||||
let bitcoin = LazyBinaryBlockSumCum::from_derived::<BitcoinF>(
|
||||
let bitcoin = LazyBinaryFromHeightSumCum::from_derived::<BitcoinF>(
|
||||
&format!("{name}_btc"),
|
||||
version,
|
||||
source1.sats.height.boxed_clone(),
|
||||
@@ -160,7 +162,7 @@ impl ValueBinaryBlock {
|
||||
.as_ref()
|
||||
.zip(source2.dollars.as_ref())
|
||||
.map(|(d1, d2)| {
|
||||
LazyBinaryBlockSumCum::from_derived::<DollarsF>(
|
||||
LazyBinaryFromHeightSumCum::from_derived::<DollarsF>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
d1.height.boxed_clone(),
|
||||
@@ -0,0 +1,94 @@
|
||||
//! Value type for Full pattern from Height.
|
||||
//!
|
||||
//! Height-level USD stats are lazy: `sats * price`.
|
||||
//! Cumulative and dateindex stats are stored since they require aggregation
|
||||
//! across heights with varying prices.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Close, Dollars, Height, Sats, Version};
|
||||
use vecdb::{Database, EagerVec, Exit, IterableCloneableVec, PcoVec};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ComputedFromHeightFull, LazyBinaryComputedFromHeightFull, LazyFromHeightFull,
|
||||
SatsTimesClosePrice, SatsToBitcoin,
|
||||
},
|
||||
price,
|
||||
};
|
||||
|
||||
/// Lazy dollars type: `sats[h] * price[h]` at height level, stored derived.
|
||||
pub type LazyDollarsFromHeightFull =
|
||||
LazyBinaryComputedFromHeightFull<Dollars, Sats, Close<Dollars>>;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ValueFromHeightFull {
|
||||
pub sats: ComputedFromHeightFull<Sats>,
|
||||
pub bitcoin: LazyFromHeightFull<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyDollarsFromHeightFull>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE; // Bumped for lazy height dollars
|
||||
|
||||
impl ValueFromHeightFull {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = ComputedFromHeightFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
let bitcoin = LazyFromHeightFull::from_computed::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats.height.boxed_clone(),
|
||||
&sats,
|
||||
);
|
||||
|
||||
let dollars = price
|
||||
.map(|price| {
|
||||
LazyBinaryComputedFromHeightFull::forced_import::<SatsTimesClosePrice>(
|
||||
db,
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
sats.height.boxed_clone(),
|
||||
price.usd.split.close.height.boxed_clone(),
|
||||
indexes,
|
||||
)
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
Ok(Self {
|
||||
sats,
|
||||
bitcoin,
|
||||
dollars,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compute_all<F>(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
mut compute: F,
|
||||
) -> Result<()>
|
||||
where
|
||||
F: FnMut(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
|
||||
{
|
||||
// Compute sats
|
||||
self.sats
|
||||
.compute_all(indexes, starting_indexes, exit, |v| compute(v))?;
|
||||
|
||||
// Derive dollars (height is lazy, just compute cumulative and dateindex)
|
||||
if let Some(dollars) = self.dollars.as_mut() {
|
||||
dollars.derive_from(indexes, starting_indexes, exit)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
110
crates/brk_computer/src/internal/multi/from_height/value_last.rs
Normal file
110
crates/brk_computer/src/internal/multi/from_height/value_last.rs
Normal file
@@ -0,0 +1,110 @@
|
||||
//! Value type for Last pattern from Height.
|
||||
//!
|
||||
//! Height-level USD value is lazy: `sats * price`.
|
||||
//! DateIndex last is stored since it requires finding the last value within each date.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Close, Dollars, Height, Sats, Version};
|
||||
use vecdb::{Database, EagerVec, Exit, IterableCloneableVec, PcoVec};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ComputedFromHeightLast, LazyBinaryComputedFromHeightLast, LazyFromHeightLast,
|
||||
SatsTimesClosePrice, SatsToBitcoin,
|
||||
},
|
||||
price,
|
||||
};
|
||||
|
||||
/// Lazy dollars type: `sats[h] * price[h]` at height level, stored derived.
|
||||
pub type LazyDollarsFromHeightLast =
|
||||
LazyBinaryComputedFromHeightLast<Dollars, Sats, Close<Dollars>>;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ValueFromHeightLast {
|
||||
pub sats: ComputedFromHeightLast<Sats>,
|
||||
pub bitcoin: LazyFromHeightLast<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyDollarsFromHeightLast>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE; // Bumped for lazy height dollars
|
||||
|
||||
impl ValueFromHeightLast {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = ComputedFromHeightLast::forced_import(db, name, v, indexes)?;
|
||||
|
||||
let bitcoin = LazyFromHeightLast::from_computed::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats.height.boxed_clone(),
|
||||
&sats,
|
||||
);
|
||||
|
||||
let dollars = price
|
||||
.map(|price| {
|
||||
LazyBinaryComputedFromHeightLast::forced_import::<SatsTimesClosePrice>(
|
||||
db,
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
sats.height.boxed_clone(),
|
||||
price.usd.split.close.height.boxed_clone(),
|
||||
indexes,
|
||||
)
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
Ok(Self {
|
||||
sats,
|
||||
bitcoin,
|
||||
dollars,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compute_all<F>(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
mut compute: F,
|
||||
) -> Result<()>
|
||||
where
|
||||
F: FnMut(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
|
||||
{
|
||||
// Compute sats (closure receives &mut height vec)
|
||||
self.sats
|
||||
.compute_all(indexes, starting_indexes, exit, |v| compute(v))?;
|
||||
|
||||
// Derive dollars (height is lazy, just compute dateindex last)
|
||||
if let Some(dollars) = self.dollars.as_mut() {
|
||||
dollars.derive_from(indexes, starting_indexes, exit)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute derived vecs from existing height data.
|
||||
pub fn compute_rest(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.sats.compute_rest(indexes, starting_indexes, exit)?;
|
||||
|
||||
// Derive dollars (height is lazy, just compute dateindex last)
|
||||
if let Some(dollars) = self.dollars.as_mut() {
|
||||
dollars.derive_from(indexes, starting_indexes, exit)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ use brk_types::{Bitcoin, Close, Dollars, Sats, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{BinaryTransform, IterableCloneableVec, UnaryTransform};
|
||||
|
||||
use super::{LazyBlockValue, LazyTransformedValueDifficultyEpoch};
|
||||
use crate::internal::LazyValueDateLast;
|
||||
use crate::{internal::ValueBlockLast, price};
|
||||
use super::LazyFromHeightValue;
|
||||
use crate::internal::{LazyTransformedValueDifficultyEpoch, LazyValueFromDateLast};
|
||||
use crate::{internal::ValueFromHeightLast, price};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
@@ -19,21 +19,21 @@ const VERSION: Version = Version::ZERO;
|
||||
/// No merge at this level - denominations (sats, bitcoin, dollars) stay as separate branches.
|
||||
/// Each inner field has merge which combines indexes within each denomination.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
pub struct LazyBinaryValueBlockLast {
|
||||
pub struct LazyBinaryValueFromHeightLast {
|
||||
#[traversable(flatten)]
|
||||
pub height: LazyBlockValue,
|
||||
pub height: LazyFromHeightValue,
|
||||
#[traversable(flatten)]
|
||||
pub difficultyepoch: LazyTransformedValueDifficultyEpoch,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub dates: LazyValueDateLast,
|
||||
pub dates: LazyValueFromDateLast,
|
||||
}
|
||||
|
||||
impl LazyBinaryValueBlockLast {
|
||||
impl LazyBinaryValueFromHeightLast {
|
||||
pub fn from_block_source<SatsTransform, BitcoinTransform, HeightDollarsTransform, DateDollarsTransform>(
|
||||
name: &str,
|
||||
source: &ValueBlockLast,
|
||||
source: &ValueFromHeightLast,
|
||||
price: Option<&price::Vecs>,
|
||||
version: Version,
|
||||
) -> Self
|
||||
@@ -47,7 +47,7 @@ impl LazyBinaryValueBlockLast {
|
||||
|
||||
let price_source = price.map(|p| p.usd.split.close.height.boxed_clone());
|
||||
|
||||
let height = LazyBlockValue::from_sources::<SatsTransform, BitcoinTransform, HeightDollarsTransform>(
|
||||
let height = LazyFromHeightValue::from_sources::<SatsTransform, BitcoinTransform, HeightDollarsTransform>(
|
||||
name,
|
||||
source.sats.height.boxed_clone(),
|
||||
price_source,
|
||||
@@ -60,7 +60,7 @@ impl LazyBinaryValueBlockLast {
|
||||
HeightDollarsTransform,
|
||||
>(name, source, price, v);
|
||||
|
||||
let dates = LazyValueDateLast::from_block_source::<SatsTransform, BitcoinTransform, DateDollarsTransform>(
|
||||
let dates = LazyValueFromDateLast::from_block_source::<SatsTransform, BitcoinTransform, DateDollarsTransform>(
|
||||
name, source, v,
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@ use vecdb::{Database, Exit, IterableCloneableVec, LazyVecFrom2};
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ClosePriceTimesSats, ComputedBlockSumCum, LazyBlockSumCum, LazyBlockSumCumHeight,
|
||||
ClosePriceTimesSats, ComputedFromHeightSumCum, LazyFromHeightSumCum, LazyComputedFromHeightSumCum,
|
||||
SatsToBitcoin,
|
||||
},
|
||||
price,
|
||||
@@ -26,15 +26,15 @@ use crate::{
|
||||
/// Dollars height is lazy (price × sats).
|
||||
/// Cumulative and dateindex aggregates are stored for both.
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyComputedValueBlockSumCum {
|
||||
pub sats: ComputedBlockSumCum<Sats>,
|
||||
pub bitcoin: LazyBlockSumCum<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyBlockSumCumHeight<Dollars, Close<Dollars>, Sats>>,
|
||||
pub struct LazyComputedValueFromHeightSumCum {
|
||||
pub sats: ComputedFromHeightSumCum<Sats>,
|
||||
pub bitcoin: LazyFromHeightSumCum<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyComputedFromHeightSumCum<Dollars, Close<Dollars>, Sats>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl LazyComputedValueBlockSumCum {
|
||||
impl LazyComputedValueFromHeightSumCum {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -44,9 +44,9 @@ impl LazyComputedValueBlockSumCum {
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = ComputedBlockSumCum::forced_import(db, name, v, indexes)?;
|
||||
let sats = ComputedFromHeightSumCum::forced_import(db, name, v, indexes)?;
|
||||
|
||||
let bitcoin = LazyBlockSumCum::from_computed::<SatsToBitcoin>(
|
||||
let bitcoin = LazyFromHeightSumCum::from_computed::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats.height.boxed_clone(),
|
||||
@@ -61,7 +61,7 @@ impl LazyComputedValueBlockSumCum {
|
||||
sats.height.boxed_clone(),
|
||||
);
|
||||
|
||||
Some(LazyBlockSumCumHeight::forced_import(
|
||||
Some(LazyComputedFromHeightSumCum::forced_import(
|
||||
db,
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
@@ -1,31 +1,30 @@
|
||||
//! Lazy value wrapper for ValueBlockLast - all transforms are lazy.
|
||||
//! Lazy value wrapper for ValueFromHeightLast - all transforms are lazy.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Sats, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
use super::LazyValueBlockHeight;
|
||||
use crate::internal::{LazyValueDateLast, SatsToBitcoin, ValueBlockLast};
|
||||
use crate::internal::{LazyValueFromDateLast, LazyValueHeight, SatsToBitcoin, ValueFromHeightLast};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
/// Lazy value wrapper with height + date last transforms from ValueBlockLast.
|
||||
/// Lazy value wrapper with height + date last transforms from ValueFromHeightLast.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyValueBlockLast {
|
||||
pub struct LazyValueFromHeightLast {
|
||||
#[traversable(flatten)]
|
||||
pub height: LazyValueBlockHeight,
|
||||
pub height: LazyValueHeight,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub dates: LazyValueDateLast,
|
||||
pub dates: LazyValueFromDateLast,
|
||||
}
|
||||
|
||||
impl LazyValueBlockLast {
|
||||
impl LazyValueFromHeightLast {
|
||||
pub fn from_block_source<SatsTransform, DollarsTransform>(
|
||||
name: &str,
|
||||
source: &ValueBlockLast,
|
||||
source: &ValueFromHeightLast,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
@@ -35,9 +34,9 @@ impl LazyValueBlockLast {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height =
|
||||
LazyValueBlockHeight::from_block_source::<SatsTransform, DollarsTransform>(name, source, v);
|
||||
LazyValueHeight::from_block_source::<SatsTransform, DollarsTransform>(name, source, v);
|
||||
|
||||
let dates = LazyValueDateLast::from_block_source::<SatsTransform, SatsToBitcoin, DollarsTransform>(
|
||||
let dates = LazyValueFromDateLast::from_block_source::<SatsTransform, SatsToBitcoin, DollarsTransform>(
|
||||
name, source, v,
|
||||
);
|
||||
|
||||
@@ -13,7 +13,7 @@ use vecdb::{
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ClosePriceTimesSats, ComputedVecValue, LazyBlockSumCum, LazyBlockSumCumHeight,
|
||||
ClosePriceTimesSats, ComputedVecValue, LazyFromHeightSumCum, LazyComputedFromHeightSumCum,
|
||||
SatsToBitcoin,
|
||||
},
|
||||
price,
|
||||
@@ -25,19 +25,19 @@ use crate::{
|
||||
/// Dollars height is also lazy (price × sats).
|
||||
/// Cumulative and dateindex are stored.
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyValueBlockSumCum<S1T, S2T>
|
||||
pub struct LazyValueFromHeightSumCum<S1T, S2T>
|
||||
where
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
S2T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub sats: LazyBlockSumCumHeight<Sats, S1T, S2T>,
|
||||
pub bitcoin: LazyBlockSumCum<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyBlockSumCumHeight<Dollars, Close<Dollars>, Sats>>,
|
||||
pub sats: LazyComputedFromHeightSumCum<Sats, S1T, S2T>,
|
||||
pub bitcoin: LazyFromHeightSumCum<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyComputedFromHeightSumCum<Dollars, Close<Dollars>, Sats>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<S1T, S2T> LazyValueBlockSumCum<S1T, S2T>
|
||||
impl<S1T, S2T> LazyValueFromHeightSumCum<S1T, S2T>
|
||||
where
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
S2T: ComputedVecValue + JsonSchema,
|
||||
@@ -57,9 +57,9 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats_height = LazyVecFrom2::transformed::<F>(name, v, source1, source2);
|
||||
let sats = LazyBlockSumCumHeight::forced_import(db, name, v, indexes, sats_height)?;
|
||||
let sats = LazyComputedFromHeightSumCum::forced_import(db, name, v, indexes, sats_height)?;
|
||||
|
||||
let bitcoin = LazyBlockSumCum::from_derived::<SatsToBitcoin>(
|
||||
let bitcoin = LazyFromHeightSumCum::from_derived::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats.height.boxed_clone(),
|
||||
@@ -74,7 +74,7 @@ where
|
||||
sats.height.boxed_clone(),
|
||||
);
|
||||
|
||||
Some(LazyBlockSumCumHeight::forced_import(
|
||||
Some(LazyComputedFromHeightSumCum::forced_import(
|
||||
db,
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
@@ -0,0 +1,93 @@
|
||||
//! Value type for Sum pattern from Height.
|
||||
//!
|
||||
//! Height-level USD value is lazy: `sats * price`.
|
||||
//! DateIndex sum is stored since it requires aggregation across heights with varying prices.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Close, Dollars, Height, Sats, Version};
|
||||
use vecdb::{Database, EagerVec, Exit, IterableCloneableVec, PcoVec};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ComputedFromHeightSum, LazyBinaryComputedFromHeightSum, LazyFromHeightSum,
|
||||
SatsTimesClosePrice, SatsToBitcoin,
|
||||
},
|
||||
price,
|
||||
};
|
||||
|
||||
/// Lazy dollars type: `sats[h] * price[h]` at height level, stored derived.
|
||||
pub type LazyDollarsFromHeightSum =
|
||||
LazyBinaryComputedFromHeightSum<Dollars, Sats, Close<Dollars>>;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ValueFromHeightSum {
|
||||
pub sats: ComputedFromHeightSum<Sats>,
|
||||
pub bitcoin: LazyFromHeightSum<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyDollarsFromHeightSum>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE; // Bumped for lazy height dollars
|
||||
|
||||
impl ValueFromHeightSum {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = ComputedFromHeightSum::forced_import(db, name, v, indexes)?;
|
||||
|
||||
let bitcoin = LazyFromHeightSum::from_computed::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats.height.boxed_clone(),
|
||||
&sats,
|
||||
);
|
||||
|
||||
let dollars = price
|
||||
.map(|price| {
|
||||
LazyBinaryComputedFromHeightSum::forced_import::<SatsTimesClosePrice>(
|
||||
db,
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
sats.height.boxed_clone(),
|
||||
price.usd.split.close.height.boxed_clone(),
|
||||
indexes,
|
||||
)
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
Ok(Self {
|
||||
sats,
|
||||
bitcoin,
|
||||
dollars,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compute_all<F>(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
mut compute: F,
|
||||
) -> Result<()>
|
||||
where
|
||||
F: FnMut(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
|
||||
{
|
||||
// Compute sats (closure receives &mut height vec)
|
||||
self.sats
|
||||
.compute_all(indexes, starting_indexes, exit, |v| compute(v))?;
|
||||
|
||||
// Derive dollars (height is lazy, just compute dateindex sum)
|
||||
if let Some(dollars) = self.dollars.as_mut() {
|
||||
dollars.derive_from(indexes, starting_indexes, exit)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
//! Value type for SumCum pattern from Height.
|
||||
//!
|
||||
//! Height-level USD sum is lazy: `sats * price`.
|
||||
//! Cumulative and dateindex stats are stored since they require aggregation
|
||||
//! across heights with varying prices.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Close, Dollars, Height, Sats, Version};
|
||||
use vecdb::{Database, EagerVec, Exit, IterableCloneableVec, IterableVec, PcoVec};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ComputedFromHeightSumCum, LazyBinaryComputedFromHeightSumCum, LazyFromHeightSumCum,
|
||||
SatsTimesClosePrice, SatsToBitcoin,
|
||||
},
|
||||
price,
|
||||
};
|
||||
|
||||
/// Lazy dollars type: `sats[h] * price[h]` at height level, stored derived.
|
||||
pub type LazyDollarsFromHeightSumCum =
|
||||
LazyBinaryComputedFromHeightSumCum<Dollars, Sats, Close<Dollars>>;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ValueFromHeightSumCum {
|
||||
pub sats: ComputedFromHeightSumCum<Sats>,
|
||||
pub bitcoin: LazyFromHeightSumCum<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyDollarsFromHeightSumCum>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE; // Bumped for lazy height dollars
|
||||
|
||||
impl ValueFromHeightSumCum {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = ComputedFromHeightSumCum::forced_import(db, name, v, indexes)?;
|
||||
|
||||
let bitcoin = LazyFromHeightSumCum::from_computed::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats.height.boxed_clone(),
|
||||
&sats,
|
||||
);
|
||||
|
||||
let dollars = price
|
||||
.map(|price| {
|
||||
LazyBinaryComputedFromHeightSumCum::forced_import::<SatsTimesClosePrice>(
|
||||
db,
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
sats.height.boxed_clone(),
|
||||
price.usd.split.close.height.boxed_clone(),
|
||||
indexes,
|
||||
)
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
Ok(Self {
|
||||
sats,
|
||||
bitcoin,
|
||||
dollars,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compute_all<F>(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
mut compute: F,
|
||||
) -> Result<()>
|
||||
where
|
||||
F: FnMut(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
|
||||
{
|
||||
// Compute sats (closure receives &mut height vec)
|
||||
self.sats
|
||||
.compute_all(indexes, starting_indexes, exit, |v| compute(v))?;
|
||||
|
||||
// Derive dollars (height is lazy, just compute cumulative and dateindex)
|
||||
if let Some(dollars) = self.dollars.as_mut() {
|
||||
dollars.derive_from(indexes, starting_indexes, exit)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Derive from an external height source (e.g., a LazyVec).
|
||||
pub fn derive_from(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
source: &impl IterableVec<Height, Sats>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// Derive sats from source
|
||||
self.sats
|
||||
.derive_from(indexes, starting_indexes, source, exit)?;
|
||||
|
||||
// Derive dollars (height is lazy, just compute cumulative and dateindex)
|
||||
if let Some(dollars) = self.dollars.as_mut() {
|
||||
dollars.derive_from(indexes, starting_indexes, exit)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute rest (derived indexes) from already-computed height.
|
||||
pub fn compute_rest(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.sats.compute_rest(indexes, starting_indexes, exit)?;
|
||||
|
||||
// Derive dollars (height is lazy, just compute cumulative and dateindex)
|
||||
if let Some(dollars) = self.dollars.as_mut() {
|
||||
dollars.derive_from(indexes, starting_indexes, exit)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//! LazyBinaryHeightDateLast - height storage + binary transform lazy date periods.
|
||||
//! LazyBinaryFromHeightAndDateLast - height storage + binary transform lazy date periods.
|
||||
//!
|
||||
//! Use this when height is stored as EagerVec and date periods are lazy binary transforms.
|
||||
|
||||
@@ -9,14 +9,14 @@ use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, EagerVec, PcoVec};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedDateLast, ComputedHeightDateLast, ComputedVecValue, LazyBinaryDateLast,
|
||||
ComputedFromDateLast, ComputedFromHeightAndDateLast, ComputedVecValue, LazyBinaryFromDateLast,
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryHeightDateLast<T, S1T, S2T>
|
||||
pub struct LazyBinaryFromHeightAndDateLast<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -26,10 +26,10 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: LazyBinaryDateLast<T, S1T, S2T>,
|
||||
pub rest: LazyBinaryFromDateLast<T, S1T, S2T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryHeightDateLast<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyBinaryFromHeightAndDateLast<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -39,14 +39,14 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height: EagerVec<PcoVec<Height, T>>,
|
||||
source1: &ComputedDateLast<S1T>,
|
||||
source2: &ComputedDateLast<S2T>,
|
||||
source1: &ComputedFromDateLast<S1T>,
|
||||
source2: &ComputedFromDateLast<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
height,
|
||||
rest: LazyBinaryDateLast::from_computed_both_last::<F>(name, v, source1, source2),
|
||||
rest: LazyBinaryFromDateLast::from_computed_both_last::<F>(name, v, source1, source2),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height: EagerVec<PcoVec<Height, T>>,
|
||||
source1: &ComputedHeightDateLast<S1T>,
|
||||
source2: &ComputedHeightDateLast<S2T>,
|
||||
source1: &ComputedFromHeightAndDateLast<S1T>,
|
||||
source2: &ComputedFromHeightAndDateLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: JsonSchema + 'static,
|
||||
@@ -65,7 +65,7 @@ where
|
||||
|
||||
Self {
|
||||
height,
|
||||
rest: LazyBinaryDateLast::from_computed_both_last::<F>(
|
||||
rest: LazyBinaryFromDateLast::from_computed_both_last::<F>(
|
||||
name,
|
||||
v,
|
||||
&source1.rest,
|
||||
@@ -8,7 +8,7 @@ use vecdb::Database;
|
||||
|
||||
use crate::indexes;
|
||||
use crate::internal::{
|
||||
ComputedHeightDateFirst, ComputedHeightDateLast, ComputedHeightDateMax, ComputedHeightDateMin,
|
||||
ComputedFromHeightAndDateFirst, ComputedFromHeightAndDateLast, ComputedFromHeightAndDateMax, ComputedFromHeightAndDateMin,
|
||||
ComputedVecValue,
|
||||
};
|
||||
|
||||
@@ -16,18 +16,18 @@ use crate::internal::{
|
||||
///
|
||||
/// Access pattern: `ohlc.{open,high,low,close}.{height,dateindex,weekindex,...,difficultyepoch}`
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct OHLCComputedVecs<T>
|
||||
pub struct ComputedOHLC<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema + From<f64>,
|
||||
f64: From<T>,
|
||||
{
|
||||
pub open: ComputedHeightDateFirst<Open<T>>,
|
||||
pub high: ComputedHeightDateMax<High<T>>,
|
||||
pub low: ComputedHeightDateMin<Low<T>>,
|
||||
pub close: ComputedHeightDateLast<Close<T>>,
|
||||
pub open: ComputedFromHeightAndDateFirst<Open<T>>,
|
||||
pub high: ComputedFromHeightAndDateMax<High<T>>,
|
||||
pub low: ComputedFromHeightAndDateMin<Low<T>>,
|
||||
pub close: ComputedFromHeightAndDateLast<Close<T>>,
|
||||
}
|
||||
|
||||
impl<T> OHLCComputedVecs<T>
|
||||
impl<T> ComputedOHLC<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema + From<f64> + 'static,
|
||||
f64: From<T>,
|
||||
@@ -39,25 +39,25 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
open: ComputedHeightDateFirst::forced_import(
|
||||
open: ComputedFromHeightAndDateFirst::forced_import(
|
||||
db,
|
||||
&format!("{name}_open"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
high: ComputedHeightDateMax::forced_import(
|
||||
high: ComputedFromHeightAndDateMax::forced_import_raw(
|
||||
db,
|
||||
&format!("{name}_high"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
low: ComputedHeightDateMin::forced_import(
|
||||
low: ComputedFromHeightAndDateMin::forced_import_raw(
|
||||
db,
|
||||
&format!("{name}_low"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
close: ComputedHeightDateLast::forced_import(
|
||||
close: ComputedFromHeightAndDateLast::forced_import(
|
||||
db,
|
||||
&format!("{name}_close"),
|
||||
version,
|
||||
@@ -1,7 +1,7 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
DateIndex, DecadeIndex, Height, MonthIndex, QuarterIndex, SemesterIndex, Version, WeekIndex,
|
||||
YearIndex,
|
||||
DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, SemesterIndex,
|
||||
Version, WeekIndex, YearIndex,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
@@ -18,6 +18,7 @@ where
|
||||
T: VecValue + Formattable + Serialize + JsonSchema,
|
||||
{
|
||||
pub height: LazyVecFrom1<Height, T, Height, Height>,
|
||||
pub difficultyepoch: LazyVecFrom1<DifficultyEpoch, T, DifficultyEpoch, DifficultyEpoch>,
|
||||
pub dateindex: LazyVecFrom1<DateIndex, T, DateIndex, DateIndex>,
|
||||
pub weekindex: LazyVecFrom1<WeekIndex, T, WeekIndex, WeekIndex>,
|
||||
pub monthindex: LazyVecFrom1<MonthIndex, T, MonthIndex, MonthIndex>,
|
||||
@@ -32,6 +33,7 @@ impl<T: VecValue + Formattable + Serialize + JsonSchema> ConstantVecs<T> {
|
||||
pub fn new<F>(name: &str, version: Version, indexes: &indexes::Vecs) -> Self
|
||||
where
|
||||
F: UnaryTransform<Height, T>
|
||||
+ UnaryTransform<DifficultyEpoch, T>
|
||||
+ UnaryTransform<DateIndex, T>
|
||||
+ UnaryTransform<WeekIndex, T>
|
||||
+ UnaryTransform<MonthIndex, T>
|
||||
@@ -46,6 +48,11 @@ impl<T: VecValue + Formattable + Serialize + JsonSchema> ConstantVecs<T> {
|
||||
version,
|
||||
indexes.height.identity.boxed_clone(),
|
||||
),
|
||||
difficultyepoch: LazyVecFrom1::transformed::<F>(
|
||||
name,
|
||||
version,
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
),
|
||||
dateindex: LazyVecFrom1::transformed::<F>(
|
||||
name,
|
||||
version,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedHeightDateFirst - height storage + dateindex storage + lazy periods.
|
||||
//! ComputedFromHeightAndDateFirst - height storage + dateindex storage + lazy periods.
|
||||
//!
|
||||
//! Use this when both height and dateindex are stored EagerVecs with first-value aggregation.
|
||||
|
||||
@@ -11,11 +11,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedDateFirst, ComputedVecValue, LazyFirst};
|
||||
use crate::internal::{ComputedFromDateFirst, ComputedVecValue, LazyFirst};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDateFirst<T>
|
||||
pub struct ComputedFromHeightAndDateFirst<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -23,13 +23,13 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: ComputedDateFirst<T>,
|
||||
pub rest: ComputedFromDateFirst<T>,
|
||||
pub difficultyepoch: LazyFirst<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDateFirst<T>
|
||||
impl<T> ComputedFromHeightAndDateFirst<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -42,7 +42,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let rest = ComputedDateFirst::forced_import(db, name, v, indexes)?;
|
||||
let rest = ComputedFromDateFirst::forced_import(db, name, v, indexes)?;
|
||||
let difficultyepoch = LazyFirst::from_source(
|
||||
name,
|
||||
v,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedHeightDateLast - height storage + dateindex storage + lazy periods.
|
||||
//! ComputedFromHeightAndDateLast - height storage + dateindex storage + lazy periods.
|
||||
//!
|
||||
//! Use this when both height and dateindex are stored EagerVecs with last-value aggregation.
|
||||
|
||||
@@ -9,13 +9,13 @@ use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVec};
|
||||
|
||||
use crate::{indexes, internal::ComputedDateLast, ComputeIndexes};
|
||||
use crate::{indexes, internal::ComputedFromDateLast, ComputeIndexes};
|
||||
|
||||
use crate::internal::{ComputedVecValue, LazyLast};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDateLast<T>
|
||||
pub struct ComputedFromHeightAndDateLast<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -23,13 +23,13 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: ComputedDateLast<T>,
|
||||
pub rest: ComputedFromDateLast<T>,
|
||||
pub difficultyepoch: LazyLast<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDateLast<T>
|
||||
impl<T> ComputedFromHeightAndDateLast<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -42,7 +42,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let rest = ComputedDateLast::forced_import(db, name, v, indexes)?;
|
||||
let rest = ComputedFromDateLast::forced_import(db, name, v, indexes)?;
|
||||
let difficultyepoch = LazyLast::from_source(
|
||||
name,
|
||||
v,
|
||||
@@ -11,7 +11,8 @@ use vecdb::{BytesVec, BytesVecValue, EagerVec, Formattable};
|
||||
|
||||
/// Bundled OHLC vecs for all periods (time + chain based).
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct OHLCPeriodVecs<T>
|
||||
#[traversable(merge)]
|
||||
pub struct LazyFromHeightAndDateOHLC<T>
|
||||
where
|
||||
T: BytesVecValue + Formattable + Serialize + JsonSchema + 'static,
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedHeightDateMax - height storage + dateindex storage + lazy periods.
|
||||
//! ComputedFromHeightAndDateMax - height storage + dateindex storage + lazy periods.
|
||||
//!
|
||||
//! Use this when both height and dateindex are stored EagerVecs with max-value aggregation.
|
||||
|
||||
@@ -11,11 +11,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedDateMax, ComputedVecValue, LazyMax};
|
||||
use crate::internal::{ComputedFromDateMax, ComputedVecValue, LazyMax};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDateMax<T>
|
||||
pub struct ComputedFromHeightAndDateMax<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -23,13 +23,13 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: ComputedDateMax<T>,
|
||||
pub rest: ComputedFromDateMax<T>,
|
||||
pub difficultyepoch: LazyMax<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDateMax<T>
|
||||
impl<T> ComputedFromHeightAndDateMax<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -38,17 +38,50 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Self::forced_import_inner(db, name, version, indexes, false)
|
||||
}
|
||||
|
||||
/// Import without adding _max suffix to lazy vecs.
|
||||
pub fn forced_import_raw(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Self::forced_import_inner(db, name, version, indexes, true)
|
||||
}
|
||||
|
||||
fn forced_import_inner(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
raw: bool,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let rest = ComputedDateMax::forced_import(db, name, v, indexes)?;
|
||||
let difficultyepoch = LazyMax::from_source(
|
||||
name,
|
||||
v,
|
||||
height.boxed_clone(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
);
|
||||
let rest = if raw {
|
||||
ComputedFromDateMax::forced_import_raw(db, name, v, indexes)?
|
||||
} else {
|
||||
ComputedFromDateMax::forced_import(db, name, v, indexes)?
|
||||
};
|
||||
let difficultyepoch = if raw {
|
||||
LazyMax::from_source_raw(
|
||||
name,
|
||||
v,
|
||||
height.boxed_clone(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
)
|
||||
} else {
|
||||
LazyMax::from_source(
|
||||
name,
|
||||
v,
|
||||
height.boxed_clone(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
)
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
height,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedHeightDateMin - height storage + dateindex storage + lazy periods.
|
||||
//! ComputedFromHeightAndDateMin - height storage + dateindex storage + lazy periods.
|
||||
//!
|
||||
//! Use this when both height and dateindex are stored EagerVecs with min-value aggregation.
|
||||
|
||||
@@ -11,11 +11,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::internal::{ComputedDateMin, ComputedVecValue, LazyMin};
|
||||
use crate::internal::{ComputedFromDateMin, ComputedVecValue, LazyMin};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDateMin<T>
|
||||
pub struct ComputedFromHeightAndDateMin<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -23,13 +23,13 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: ComputedDateMin<T>,
|
||||
pub rest: ComputedFromDateMin<T>,
|
||||
pub difficultyepoch: LazyMin<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDateMin<T>
|
||||
impl<T> ComputedFromHeightAndDateMin<T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -38,17 +38,50 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Self::forced_import_inner(db, name, version, indexes, false)
|
||||
}
|
||||
|
||||
/// Import without adding _min suffix to lazy vecs.
|
||||
pub fn forced_import_raw(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Self::forced_import_inner(db, name, version, indexes, true)
|
||||
}
|
||||
|
||||
fn forced_import_inner(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
raw: bool,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let rest = ComputedDateMin::forced_import(db, name, v, indexes)?;
|
||||
let difficultyepoch = LazyMin::from_source(
|
||||
name,
|
||||
v,
|
||||
height.boxed_clone(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
);
|
||||
let rest = if raw {
|
||||
ComputedFromDateMin::forced_import_raw(db, name, v, indexes)?
|
||||
} else {
|
||||
ComputedFromDateMin::forced_import(db, name, v, indexes)?
|
||||
};
|
||||
let difficultyepoch = if raw {
|
||||
LazyMin::from_source_raw(
|
||||
name,
|
||||
v,
|
||||
height.boxed_clone(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
)
|
||||
} else {
|
||||
LazyMin::from_source(
|
||||
name,
|
||||
v,
|
||||
height.boxed_clone(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
)
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
height,
|
||||
@@ -0,0 +1,19 @@
|
||||
mod binary_last;
|
||||
mod computed_ohlc;
|
||||
mod constant;
|
||||
mod first;
|
||||
mod last;
|
||||
mod lazy_ohlc;
|
||||
mod max;
|
||||
mod min;
|
||||
mod value_last;
|
||||
|
||||
pub use binary_last::*;
|
||||
pub use computed_ohlc::*;
|
||||
pub use constant::*;
|
||||
pub use first::*;
|
||||
pub use last::*;
|
||||
pub use lazy_ohlc::*;
|
||||
pub use max::*;
|
||||
pub use min::*;
|
||||
pub use value_last::*;
|
||||
@@ -11,29 +11,28 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
|
||||
|
||||
use crate::{ComputeIndexes, indexes, price};
|
||||
|
||||
use crate::internal::{LazyDerivedBlockValue, LazyValueDifficultyEpochFromHeight};
|
||||
use super::ValueDateLast;
|
||||
use crate::internal::{LazyDerivedValuesHeight, LazyValueDifficultyEpoch, ValueFromDateLast};
|
||||
|
||||
/// Value type where both height and dateindex are stored independently.
|
||||
/// Dateindex values cannot be derived from height (e.g., unrealized P&L).
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ValueHeightDateLast {
|
||||
pub struct ValueFromHeightAndDateLast {
|
||||
#[traversable(rename = "sats")]
|
||||
pub height: EagerVec<PcoVec<Height, Sats>>,
|
||||
#[traversable(flatten)]
|
||||
pub height_value: LazyDerivedBlockValue,
|
||||
pub height_value: LazyDerivedValuesHeight,
|
||||
#[traversable(flatten)]
|
||||
pub difficultyepoch: LazyValueDifficultyEpochFromHeight,
|
||||
pub difficultyepoch: LazyValueDifficultyEpoch,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub indexes: ValueDateLast,
|
||||
pub indexes: ValueFromDateLast,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl ValueHeightDateLast {
|
||||
impl ValueFromHeightAndDateLast {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -49,9 +48,9 @@ impl ValueHeightDateLast {
|
||||
let price_source = price.map(|p| p.usd.split.close.height.boxed_clone());
|
||||
|
||||
let height_value =
|
||||
LazyDerivedBlockValue::from_source(name, height.boxed_clone(), v, price_source);
|
||||
LazyDerivedValuesHeight::from_source(name, height.boxed_clone(), v, price_source);
|
||||
|
||||
let difficultyepoch = LazyValueDifficultyEpochFromHeight::from_height_source(
|
||||
let difficultyepoch = LazyValueDifficultyEpoch::from_height_source(
|
||||
name,
|
||||
height.boxed_clone(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
@@ -59,7 +58,7 @@ impl ValueHeightDateLast {
|
||||
v,
|
||||
);
|
||||
|
||||
let indexes = ValueDateLast::forced_import(db, name, v, compute_dollars, indexes)?;
|
||||
let indexes = ValueFromDateLast::forced_import(db, name, v, compute_dollars, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
height,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! LazyTxDistribution - lazy txindex source + computed distribution.
|
||||
//! LazyFromTxDistribution - lazy txindex source + computed distribution.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
@@ -10,14 +10,14 @@ use vecdb::{CollectableVec, Database, Exit, LazyVecFrom2};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{ComputedVecValue, DerivedTxDistribution, NumericValue},
|
||||
internal::{ComputedVecValue, TxDerivedDistribution, NumericValue},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyTxDistribution<T, S1, S2>
|
||||
pub struct LazyFromTxDistribution<T, S1, S2>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1: ComputedVecValue,
|
||||
@@ -27,10 +27,10 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub distribution: DerivedTxDistribution<T>,
|
||||
pub distribution: TxDerivedDistribution<T>,
|
||||
}
|
||||
|
||||
impl<T, S1, S2> LazyTxDistribution<T, S1, S2>
|
||||
impl<T, S1, S2> LazyFromTxDistribution<T, S1, S2>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
S1: ComputedVecValue + JsonSchema,
|
||||
@@ -44,7 +44,7 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
let distribution = DerivedTxDistribution::forced_import(db, name, v, indexes)?;
|
||||
let distribution = TxDerivedDistribution::forced_import(db, name, v, indexes)?;
|
||||
Ok(Self {
|
||||
txindex,
|
||||
distribution,
|
||||
7
crates/brk_computer/src/internal/multi/from_tx/mod.rs
Normal file
7
crates/brk_computer/src/internal/multi/from_tx/mod.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
mod lazy_distribution;
|
||||
mod value_dollars;
|
||||
mod value_full;
|
||||
|
||||
pub use lazy_distribution::*;
|
||||
pub use value_dollars::*;
|
||||
pub use value_full::*;
|
||||
202
crates/brk_computer/src/internal/multi/from_tx/value_dollars.rs
Normal file
202
crates/brk_computer/src/internal/multi/from_tx/value_dollars.rs
Normal file
@@ -0,0 +1,202 @@
|
||||
//! Dollars from TxIndex with lazy height stats and stored dateindex.
|
||||
//!
|
||||
//! Height-level USD stats (min/max/avg/sum/percentiles) are lazy: `sats_stat * price`.
|
||||
//! Height cumulative and dateindex stats are stored since they require aggregation
|
||||
//! across heights with varying prices.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Bitcoin, Close, DateIndex, DifficultyEpoch, Dollars, Height, Sats, TxIndex, Version,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{
|
||||
AnyStoredVec, AnyVec, Database, EagerVec, Exit, GenericStoredVec, ImportableVec,
|
||||
IterableBoxedVec, IterableCloneableVec, IterableVec, LazyVecFrom3,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
CumulativeVec, Full, LazyBinaryTransformFull, LazyDateDerivedFull, LazyFull,
|
||||
SatsTimesClosePrice, Stats,
|
||||
},
|
||||
};
|
||||
|
||||
/// Lazy dollars at TxIndex: `sats * price[height]`
|
||||
pub type LazyDollarsTxIndex =
|
||||
LazyVecFrom3<TxIndex, Dollars, TxIndex, Sats, TxIndex, Height, Height, Close<Dollars>>;
|
||||
|
||||
/// Lazy dollars height stats: `sats_height_stat * price`
|
||||
pub type LazyDollarsHeightFull = LazyBinaryTransformFull<Height, Dollars, Sats, Close<Dollars>>;
|
||||
|
||||
/// Dollars with lazy txindex and height fields, stored dateindex.
|
||||
///
|
||||
/// Height-level stats (except cumulative) are lazy: `sats * price[height]`.
|
||||
/// Cumulative at height level is stored since it requires summing historical values.
|
||||
/// DateIndex stats are stored since they aggregate across heights with varying prices.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ValueDollarsFromTxFull {
|
||||
#[traversable(skip)]
|
||||
pub txindex: LazyDollarsTxIndex,
|
||||
#[traversable(flatten)]
|
||||
pub height: LazyDollarsHeightFull,
|
||||
pub height_cumulative: CumulativeVec<Height, Dollars>,
|
||||
pub difficultyepoch: LazyFull<DifficultyEpoch, Dollars, Height, DifficultyEpoch>,
|
||||
pub dateindex: Stats<DateIndex, Dollars>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyDateDerivedFull<Dollars>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE; // Bumped for lazy height change
|
||||
|
||||
impl ValueDollarsFromTxFull {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
sats_height: &Full<Height, Sats>,
|
||||
height_to_price: IterableBoxedVec<Height, Close<Dollars>>,
|
||||
sats_txindex: IterableBoxedVec<TxIndex, Sats>,
|
||||
txindex_to_height: IterableBoxedVec<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::<SatsTimesClosePrice>(
|
||||
name,
|
||||
v,
|
||||
sats_height,
|
||||
height_to_price.clone(),
|
||||
);
|
||||
|
||||
// Stored cumulative - must be computed by summing historical sum*price
|
||||
let height_cumulative = CumulativeVec(EagerVec::forced_import(
|
||||
db,
|
||||
&format!("{name}_cumulative"),
|
||||
v,
|
||||
)?);
|
||||
|
||||
let dateindex = Stats::forced_import(db, name, v)?;
|
||||
|
||||
let difficultyepoch =
|
||||
LazyFull::<DifficultyEpoch, Dollars, Height, DifficultyEpoch>::from_stats_aggregate(
|
||||
name,
|
||||
v,
|
||||
height.boxed_average(),
|
||||
height.boxed_min(),
|
||||
height.boxed_max(),
|
||||
height.boxed_sum(),
|
||||
height_cumulative.0.boxed_clone(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
);
|
||||
|
||||
let dates = LazyDateDerivedFull::from_sources(
|
||||
name,
|
||||
v,
|
||||
dateindex.boxed_average(),
|
||||
dateindex.boxed_min(),
|
||||
dateindex.boxed_max(),
|
||||
dateindex.boxed_sum(),
|
||||
dateindex.boxed_cumulative(),
|
||||
indexes,
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
txindex,
|
||||
height,
|
||||
height_cumulative,
|
||||
difficultyepoch,
|
||||
dateindex,
|
||||
dates,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute stored fields (cumulative and dateindex) from lazy height stats.
|
||||
///
|
||||
/// This is MUCH faster than the old approach since it only iterates heights,
|
||||
/// not all transactions per block.
|
||||
pub fn derive_from(
|
||||
&mut self,
|
||||
_indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// Compute height cumulative by summing lazy height.sum values
|
||||
self.compute_height_cumulative(starting_indexes.height, exit)?;
|
||||
|
||||
// Compute dateindex stats by aggregating lazy height stats
|
||||
self.dateindex.compute(
|
||||
starting_indexes.dateindex,
|
||||
&self.height.average,
|
||||
&indexes.dateindex.first_height,
|
||||
&indexes.dateindex.height_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute cumulative USD by summing `sum_sats[h] * price[h]` for all heights.
|
||||
fn compute_height_cumulative(&mut self, max_from: Height, exit: &Exit) -> Result<()> {
|
||||
let starting_height = max_from.min(Height::from(self.height_cumulative.0.len()));
|
||||
|
||||
let mut cumulative = starting_height.decremented().map_or(Dollars::ZERO, |h| {
|
||||
self.height_cumulative.0.iter().get_unwrap(h)
|
||||
});
|
||||
|
||||
let mut sum_iter = self.height.sum.iter();
|
||||
let start_idx = *starting_height as usize;
|
||||
let end_idx = sum_iter.len();
|
||||
|
||||
for h in start_idx..end_idx {
|
||||
let sum_usd = sum_iter.get_unwrap(Height::from(h));
|
||||
cumulative += sum_usd;
|
||||
self.height_cumulative.0.truncate_push_at(h, cumulative)?;
|
||||
}
|
||||
|
||||
let _lock = exit.lock();
|
||||
self.height_cumulative.0.write()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn create_lazy_txindex(
|
||||
name: &str,
|
||||
version: Version,
|
||||
sats_txindex: IterableBoxedVec<TxIndex, Sats>,
|
||||
txindex_to_height: IterableBoxedVec<TxIndex, Height>,
|
||||
height_to_price: IterableBoxedVec<Height, Close<Dollars>>,
|
||||
) -> LazyDollarsTxIndex {
|
||||
LazyVecFrom3::init(
|
||||
&format!("{name}_txindex"),
|
||||
version,
|
||||
sats_txindex,
|
||||
txindex_to_height,
|
||||
height_to_price,
|
||||
|txindex, sats_iter, height_iter, price_iter| {
|
||||
sats_iter.get(txindex).and_then(|sats| {
|
||||
height_iter.get(txindex).and_then(|height| {
|
||||
price_iter
|
||||
.get(height)
|
||||
.map(|close| *close * Bitcoin::from(sats))
|
||||
})
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ValueTxFull - eager txindex Sats source + ValueDerivedTxFull (sats/bitcoin/dollars).
|
||||
//! ValueFromTxFull - eager txindex Sats source + ValueTxDerivedFull (sats/bitcoin/dollars).
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
@@ -7,23 +7,21 @@ use brk_types::{Sats, TxIndex, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec};
|
||||
|
||||
use crate::{ComputeIndexes, indexes, price};
|
||||
|
||||
use super::ValueDerivedTxFull;
|
||||
use crate::{ComputeIndexes, indexes, internal::ValueTxDerivedFull, price};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
pub struct ValueTxFull {
|
||||
pub struct ValueFromTxFull {
|
||||
#[traversable(rename = "txindex")]
|
||||
pub base: EagerVec<PcoVec<TxIndex, Sats>>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub indexes: ValueDerivedTxFull,
|
||||
pub indexes: ValueTxDerivedFull,
|
||||
}
|
||||
|
||||
impl ValueTxFull {
|
||||
impl ValueFromTxFull {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -35,7 +33,7 @@ impl ValueTxFull {
|
||||
let v = version + VERSION;
|
||||
let txindex = EagerVec::forced_import(db, name, v)?;
|
||||
let derived =
|
||||
ValueDerivedTxFull::forced_import(db, name, v, indexes, indexer, price, &txindex)?;
|
||||
ValueTxDerivedFull::forced_import(db, name, v, indexes, indexer, price, &txindex)?;
|
||||
Ok(Self {
|
||||
base: txindex,
|
||||
indexes: derived,
|
||||
@@ -49,7 +47,27 @@ impl ValueTxFull {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes
|
||||
.derive_from(indexer, indexes, starting_indexes, &self.base, exit)
|
||||
self.derive_from_with_skip(indexer, indexes, starting_indexes, 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 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,43 +0,0 @@
|
||||
mod binary_full;
|
||||
mod binary_height_date_last;
|
||||
mod binary_last;
|
||||
mod binary_sum;
|
||||
mod binary_sum_cum;
|
||||
mod full;
|
||||
mod height_date_bytes;
|
||||
mod height_date_first;
|
||||
mod height_date_last;
|
||||
mod height_date_max;
|
||||
mod height_date_min;
|
||||
mod last;
|
||||
mod lazy_distribution;
|
||||
mod lazy_full;
|
||||
mod lazy_height_full;
|
||||
mod lazy_height_sum_cum;
|
||||
mod lazy_last;
|
||||
mod lazy_sum;
|
||||
mod lazy_sum_cum;
|
||||
mod sum;
|
||||
mod sum_cum;
|
||||
|
||||
pub use binary_full::*;
|
||||
pub use binary_height_date_last::*;
|
||||
pub use binary_last::*;
|
||||
pub use binary_sum::*;
|
||||
pub use binary_sum_cum::*;
|
||||
pub use full::*;
|
||||
pub use height_date_bytes::*;
|
||||
pub use height_date_first::*;
|
||||
pub use height_date_last::*;
|
||||
pub use height_date_max::*;
|
||||
pub use height_date_min::*;
|
||||
pub use last::*;
|
||||
pub use lazy_distribution::*;
|
||||
pub use lazy_full::*;
|
||||
pub use lazy_height_full::*;
|
||||
pub use lazy_height_sum_cum::*;
|
||||
pub use lazy_last::*;
|
||||
pub use lazy_sum::*;
|
||||
pub use lazy_sum_cum::*;
|
||||
pub use sum::*;
|
||||
pub use sum_cum::*;
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedHeightDateBytes - height + dateindex BytesVec storage.
|
||||
//! ComputedHeightAndDateBytes - height + dateindex BytesVec storage.
|
||||
//!
|
||||
//! Use this for simple cases where both height and dateindex are stored BytesVecs
|
||||
//! without any lazy derivations. For OHLC-type data.
|
||||
@@ -12,7 +12,7 @@ use vecdb::{BytesVec, BytesVecValue, Database, Formattable, ImportableVec};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedHeightDateBytes<T>
|
||||
pub struct ComputedHeightAndDateBytes<T>
|
||||
where
|
||||
T: BytesVecValue + Formattable + Serialize + JsonSchema,
|
||||
{
|
||||
@@ -22,7 +22,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDateBytes<T>
|
||||
impl<T> ComputedHeightAndDateBytes<T>
|
||||
where
|
||||
T: BytesVecValue + Formattable + Serialize + JsonSchema + 'static,
|
||||
{
|
||||
@@ -0,0 +1,5 @@
|
||||
mod bytes;
|
||||
mod ohlc;
|
||||
|
||||
pub use bytes::*;
|
||||
pub use ohlc::*;
|
||||
@@ -0,0 +1,21 @@
|
||||
//! Lazy OHLC component extractors for height + dateindex only.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{DateIndex, Height};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use vecdb::{BytesVecValue, Formattable};
|
||||
|
||||
use crate::internal::LazyOHLC;
|
||||
|
||||
/// Lazy OHLC component extractors for height + dateindex.
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyHeightAndDateOHLC<T, SourceT>
|
||||
where
|
||||
T: BytesVecValue + Formattable + Serialize + JsonSchema + 'static,
|
||||
SourceT: BytesVecValue + Formattable + Serialize + JsonSchema + 'static,
|
||||
{
|
||||
pub height: LazyOHLC<Height, T, SourceT>,
|
||||
pub dateindex: LazyOHLC<DateIndex, T, SourceT>,
|
||||
}
|
||||
@@ -7,13 +7,13 @@ use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, IterableCloneableVec};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockLast, ComputedBlockSumCum, ComputedHeightDateLast, ComputedVecValue,
|
||||
LazyBinaryDateLast, LazyBinaryTransformLast, NumericValue,
|
||||
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedFromHeightAndDateLast, ComputedVecValue,
|
||||
LazyBinaryFromDateLast, LazyBinaryTransformLast, NumericValue,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryDerivedBlockLast<T, S1T = T, S2T = T>
|
||||
pub struct LazyBinaryHeightDerivedLast<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -21,13 +21,13 @@ where
|
||||
{
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyBinaryDateLast<T, S1T, S2T>,
|
||||
pub dates: LazyBinaryFromDateLast<T, S1T, S2T>,
|
||||
pub difficultyepoch: LazyBinaryTransformLast<DifficultyEpoch, T, S1T, S2T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryDerivedBlockLast<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyBinaryHeightDerivedLast<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -36,8 +36,8 @@ where
|
||||
pub fn from_computed_sum_cum<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockSumCum<S1T>,
|
||||
source2: &ComputedBlockSumCum<S2T>,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &ComputedFromHeightSumCum<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -46,7 +46,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateLast::from_both_sum_cum_cumulatives::<F>(
|
||||
dates: LazyBinaryFromDateLast::from_both_sum_cum_cumulatives::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.dateindex.cumulative.boxed_clone(),
|
||||
@@ -66,8 +66,8 @@ where
|
||||
pub fn from_computed_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockLast<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedFromHeightLast<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -76,7 +76,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateLast::from_both_block_last::<F>(name, v, source1, source2),
|
||||
dates: LazyBinaryFromDateLast::from_both_block_last::<F>(name, v, source1, source2),
|
||||
difficultyepoch: LazyBinaryTransformLast::from_vecs::<F>(
|
||||
name,
|
||||
v,
|
||||
@@ -89,8 +89,8 @@ where
|
||||
pub fn from_computed_height_date_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedHeightDateLast<S1T>,
|
||||
source2: &ComputedHeightDateLast<S2T>,
|
||||
source1: &ComputedFromHeightAndDateLast<S1T>,
|
||||
source2: &ComputedFromHeightAndDateLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -99,7 +99,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateLast::from_computed_both_last::<F>(
|
||||
dates: LazyBinaryFromDateLast::from_computed_both_last::<F>(
|
||||
name,
|
||||
v,
|
||||
&source1.rest,
|
||||
@@ -108,8 +108,8 @@ where
|
||||
difficultyepoch: LazyBinaryTransformLast::from_vecs::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.difficultyepoch.0.boxed_clone(),
|
||||
source2.difficultyepoch.0.boxed_clone(),
|
||||
source1.difficultyepoch.boxed_clone(),
|
||||
source2.difficultyepoch.boxed_clone(),
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -117,8 +117,8 @@ where
|
||||
pub fn from_computed_height_date_and_block_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedHeightDateLast<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedFromHeightAndDateLast<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -127,7 +127,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateLast::from_dateindex_and_height_last::<F>(
|
||||
dates: LazyBinaryFromDateLast::from_dateindex_and_height_last::<F>(
|
||||
name,
|
||||
v,
|
||||
&source1.rest,
|
||||
@@ -136,7 +136,7 @@ where
|
||||
difficultyepoch: LazyBinaryTransformLast::from_vecs::<F>(
|
||||
name,
|
||||
v,
|
||||
source1.difficultyepoch.0.boxed_clone(),
|
||||
source1.difficultyepoch.boxed_clone(),
|
||||
source2.difficultyepoch.boxed_clone(),
|
||||
),
|
||||
}
|
||||
@@ -6,13 +6,13 @@ use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, IterableCloneableVec};
|
||||
|
||||
use crate::internal::{ComputedVecValue, ComputedDerivedBlockSum, LazyBinaryDateSum, LazyBinaryTransformSum, NumericValue};
|
||||
use crate::internal::{ComputedVecValue, ComputedHeightDerivedSum, LazyBinaryFromDateSum, LazyBinaryTransformSum, NumericValue};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryDerivedBlockSum<T, S1T, S2T>
|
||||
pub struct LazyBinaryHeightDerivedSum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -20,11 +20,11 @@ where
|
||||
{
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyBinaryDateSum<T, S1T, S2T>,
|
||||
pub dates: LazyBinaryFromDateSum<T, S1T, S2T>,
|
||||
pub difficultyepoch: LazyBinaryTransformSum<DifficultyEpoch, T, S1T, S2T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryDerivedBlockSum<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyBinaryHeightDerivedSum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: NumericValue + JsonSchema,
|
||||
@@ -33,13 +33,13 @@ where
|
||||
pub fn from_derived<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedDerivedBlockSum<S1T>,
|
||||
source2: &ComputedDerivedBlockSum<S2T>,
|
||||
source1: &ComputedHeightDerivedSum<S1T>,
|
||||
source2: &ComputedHeightDerivedSum<S2T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateSum::from_derived::<F>(name, v, source1, source2),
|
||||
dates: LazyBinaryFromDateSum::from_derived::<F>(name, v, source1, source2),
|
||||
difficultyepoch: LazyBinaryTransformSum::from_boxed::<F>(
|
||||
name,
|
||||
v,
|
||||
@@ -7,16 +7,16 @@ use schemars::JsonSchema;
|
||||
use vecdb::{BinaryTransform, IterableCloneableVec};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockLast, ComputedBlockSumCum, ComputedDerivedBlockLast, ComputedDerivedBlockSumCum,
|
||||
ComputedVecValue, LazyBinaryDateSumCum, LazyBinaryTransformSumCum, LazyFull, LazyPeriodsFull,
|
||||
LazyPeriodsSumCum, LazySumCum, NumericValue, SumCum,
|
||||
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedHeightDerivedLast, ComputedHeightDerivedSumCum,
|
||||
ComputedVecValue, LazyBinaryFromDateSumCum, LazyBinaryTransformSumCum, LazyFull, LazyDateDerivedFull,
|
||||
LazyDateDerivedSumCum, LazySumCum, NumericValue, SumCum,
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyBinaryDerivedBlockSumCum<T, S1T = T, S2T = T>
|
||||
pub struct LazyBinaryHeightDerivedSumCum<T, S1T = T, S2T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -24,11 +24,11 @@ where
|
||||
{
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyBinaryDateSumCum<T, S1T, S2T>,
|
||||
pub dates: LazyBinaryFromDateSumCum<T, S1T, S2T>,
|
||||
pub difficultyepoch: LazyBinaryTransformSumCum<DifficultyEpoch, T, S1T, S2T>,
|
||||
}
|
||||
|
||||
impl<T, S1T, S2T> LazyBinaryDerivedBlockSumCum<T, S1T, S2T>
|
||||
impl<T, S1T, S2T> LazyBinaryHeightDerivedSumCum<T, S1T, S2T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -39,16 +39,16 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex1: &SumCum<brk_types::DateIndex, S1T>,
|
||||
periods1: &LazyPeriodsSumCum<S1T>,
|
||||
periods1: &LazyDateDerivedSumCum<S1T>,
|
||||
difficultyepoch1: &LazySumCum<DifficultyEpoch, S1T, Height, DifficultyEpoch>,
|
||||
dateindex2: &SumCum<brk_types::DateIndex, S2T>,
|
||||
periods2: &LazyPeriodsSumCum<S2T>,
|
||||
periods2: &LazyDateDerivedSumCum<S2T>,
|
||||
difficultyepoch2: &LazySumCum<DifficultyEpoch, S2T, Height, DifficultyEpoch>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateSumCum::from_computed::<F>(
|
||||
dates: LazyBinaryFromDateSumCum::from_computed::<F>(
|
||||
name, v, dateindex1, periods1, dateindex2, periods2,
|
||||
),
|
||||
difficultyepoch: LazyBinaryTransformSumCum::from_sources::<F>(
|
||||
@@ -67,10 +67,10 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex1: &SumCum<brk_types::DateIndex, S1T>,
|
||||
dates1: &LazyPeriodsFull<S1T>,
|
||||
dates1: &LazyDateDerivedFull<S1T>,
|
||||
difficultyepoch1: &LazyFull<DifficultyEpoch, S1T, S1I, S1L>,
|
||||
dateindex2: &SumCum<brk_types::DateIndex, S2T>,
|
||||
dates2: &LazyPeriodsFull<S2T>,
|
||||
dates2: &LazyDateDerivedFull<S2T>,
|
||||
difficultyepoch2: &LazyFull<DifficultyEpoch, S2T, S2I, S2L>,
|
||||
) -> Self
|
||||
where
|
||||
@@ -83,7 +83,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateSumCum::from_derived_full::<F>(
|
||||
dates: LazyBinaryFromDateSumCum::from_derived_full::<F>(
|
||||
name, v, dateindex1, dates1, dateindex2, dates2,
|
||||
),
|
||||
difficultyepoch: LazyBinaryTransformSumCum::from_lazy_stats_aggregate::<F, _, _, _, _>(
|
||||
@@ -101,16 +101,16 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex1: &SumCum<brk_types::DateIndex, S1T>,
|
||||
periods1: &LazyPeriodsSumCum<S1T>,
|
||||
periods1: &LazyDateDerivedSumCum<S1T>,
|
||||
difficultyepoch1: &LazySumCum<DifficultyEpoch, S1T, Height, DifficultyEpoch>,
|
||||
dateindex2: &SumCum<brk_types::DateIndex, S2T>,
|
||||
periods2: &LazyPeriodsSumCum<S2T>,
|
||||
periods2: &LazyDateDerivedSumCum<S2T>,
|
||||
difficultyepoch2: &LazySumCum<DifficultyEpoch, S2T, Height, DifficultyEpoch>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateSumCum::from_computed_sum_raw::<F>(
|
||||
dates: LazyBinaryFromDateSumCum::from_computed_sum_raw::<F>(
|
||||
name, v, dateindex1, periods1, dateindex2, periods2,
|
||||
),
|
||||
difficultyepoch: LazyBinaryTransformSumCum::from_sources_sum_raw::<F>(
|
||||
@@ -129,8 +129,8 @@ where
|
||||
pub fn from_computed_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockSumCum<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -139,7 +139,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateSumCum::from_computed_last::<F>(name, v, source1, source2),
|
||||
dates: LazyBinaryFromDateSumCum::from_computed_last::<F>(name, v, source1, source2),
|
||||
difficultyepoch: LazyBinaryTransformSumCum::from_sources_last_sum_raw::<F>(
|
||||
name,
|
||||
v,
|
||||
@@ -153,8 +153,8 @@ where
|
||||
pub fn from_derived_computed_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedDerivedBlockSumCum<S1T>,
|
||||
source2: &ComputedBlockLast<S2T>,
|
||||
source1: &ComputedHeightDerivedSumCum<S1T>,
|
||||
source2: &ComputedFromHeightLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -163,7 +163,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateSumCum::from_derived_computed_last::<F>(name, v, source1, source2),
|
||||
dates: LazyBinaryFromDateSumCum::from_derived_computed_last::<F>(name, v, source1, source2),
|
||||
difficultyepoch: LazyBinaryTransformSumCum::from_sources_last_sum_raw::<F>(
|
||||
name,
|
||||
v,
|
||||
@@ -177,8 +177,8 @@ where
|
||||
pub fn from_computed_derived_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedBlockSumCum<S1T>,
|
||||
source2: &ComputedDerivedBlockLast<S2T>,
|
||||
source1: &ComputedFromHeightSumCum<S1T>,
|
||||
source2: &ComputedHeightDerivedLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -187,7 +187,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateSumCum::from_computed_derived_last::<F>(name, v, source1, source2),
|
||||
dates: LazyBinaryFromDateSumCum::from_computed_derived_last::<F>(name, v, source1, source2),
|
||||
difficultyepoch: LazyBinaryTransformSumCum::from_sources_last_sum_raw::<F>(
|
||||
name,
|
||||
v,
|
||||
@@ -201,8 +201,8 @@ where
|
||||
pub fn from_derived_last<F: BinaryTransform<S1T, S2T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source1: &ComputedDerivedBlockSumCum<S1T>,
|
||||
source2: &ComputedDerivedBlockLast<S2T>,
|
||||
source1: &ComputedHeightDerivedSumCum<S1T>,
|
||||
source2: &ComputedHeightDerivedLast<S2T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -211,7 +211,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyBinaryDateSumCum::from_derived_last::<F>(name, v, source1, source2),
|
||||
dates: LazyBinaryFromDateSumCum::from_derived_last::<F>(name, v, source1, source2),
|
||||
difficultyepoch: LazyBinaryTransformSumCum::from_sources_last_sum_raw::<F>(
|
||||
name,
|
||||
v,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedDerivedBlockDistribution - dateindex storage + lazy time periods + difficultyepoch.
|
||||
//! ComputedHeightDerivedDistribution - dateindex storage + lazy time periods + difficultyepoch.
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
@@ -11,26 +11,26 @@ use vecdb::{Database, Exit, IterableBoxedVec, IterableCloneableVec, IterableVec}
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ComputedVecValue, LazyPeriodsDistribution, Distribution, LazyDistribution, NumericValue,
|
||||
ComputedVecValue, LazyDateDerivedDistribution, Distribution, LazyDistribution, NumericValue,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedDerivedBlockDistribution<T>
|
||||
pub struct ComputedHeightDerivedDistribution<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
pub dateindex: Distribution<DateIndex, T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyPeriodsDistribution<T>,
|
||||
pub dates: LazyDateDerivedDistribution<T>,
|
||||
pub difficultyepoch: LazyDistribution<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedDerivedBlockDistribution<T>
|
||||
impl<T> ComputedHeightDerivedDistribution<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -44,12 +44,12 @@ where
|
||||
let dateindex = Distribution::forced_import(db, name, version + VERSION)?;
|
||||
let v = version + VERSION;
|
||||
|
||||
let dates = LazyPeriodsDistribution::from_sources(
|
||||
let dates = LazyDateDerivedDistribution::from_sources(
|
||||
name,
|
||||
v,
|
||||
dateindex.average.0.boxed_clone(),
|
||||
dateindex.minmax.min.0.boxed_clone(),
|
||||
dateindex.minmax.max.0.boxed_clone(),
|
||||
dateindex.boxed_average(),
|
||||
dateindex.boxed_min(),
|
||||
dateindex.boxed_max(),
|
||||
indexes,
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedDerivedBlockFirst - dateindex storage + difficultyepoch + lazy time periods (first value).
|
||||
//! ComputedHeightDerivedFirst - dateindex storage + difficultyepoch + lazy time periods (first value).
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
@@ -10,12 +10,12 @@ use vecdb::{Database, Exit, IterableBoxedVec, IterableCloneableVec, IterableVec}
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{ComputedVecValue, LazyPeriodsFirst, FirstVec, LazyFirst, NumericValue},
|
||||
internal::{ComputedVecValue, LazyDateDerivedFirst, FirstVec, LazyFirst, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedDerivedBlockFirst<T>
|
||||
pub struct ComputedHeightDerivedFirst<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -23,13 +23,13 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub dates: LazyPeriodsFirst<T>,
|
||||
pub dates: LazyDateDerivedFirst<T>,
|
||||
pub difficultyepoch: LazyFirst<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedDerivedBlockFirst<T>
|
||||
impl<T> ComputedHeightDerivedFirst<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -44,7 +44,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Ok(Self {
|
||||
dates: LazyPeriodsFirst::from_source(name, v, dateindex.0.boxed_clone(), indexes),
|
||||
dates: LazyDateDerivedFirst::from_source(name, v, dateindex.boxed_clone(), indexes),
|
||||
difficultyepoch: LazyFirst::from_source(
|
||||
name,
|
||||
v,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedDerivedBlockFull - height_cumulative + dateindex storage + difficultyepoch + lazy time periods.
|
||||
//! ComputedHeightDerivedFull - height_cumulative + dateindex storage + difficultyepoch + lazy time periods.
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
@@ -11,14 +11,14 @@ use vecdb::{Database, Exit, IterableBoxedVec, IterableCloneableVec, IterableVec}
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ComputedVecValue, CumulativeVec, LazyPeriodsFull, Full, LazyFull, NumericValue,
|
||||
ComputedVecValue, CumulativeVec, LazyDateDerivedFull, Full, LazyFull, NumericValue,
|
||||
compute_cumulative_extend,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedDerivedBlockFull<T>
|
||||
pub struct ComputedHeightDerivedFull<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -27,13 +27,13 @@ where
|
||||
pub dateindex: Full<DateIndex, T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyPeriodsFull<T>,
|
||||
pub dates: LazyDateDerivedFull<T>,
|
||||
pub difficultyepoch: LazyFull<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedDerivedBlockFull<T>
|
||||
impl<T> ComputedHeightDerivedFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -49,14 +49,14 @@ where
|
||||
let dateindex = Full::forced_import(db, name, v)?;
|
||||
|
||||
Ok(Self {
|
||||
dates: LazyPeriodsFull::from_sources(
|
||||
dates: LazyDateDerivedFull::from_sources(
|
||||
name,
|
||||
v,
|
||||
dateindex.distribution.average.0.boxed_clone(),
|
||||
dateindex.distribution.minmax.min.0.boxed_clone(),
|
||||
dateindex.distribution.minmax.max.0.boxed_clone(),
|
||||
dateindex.sum_cum.sum.0.boxed_clone(),
|
||||
dateindex.sum_cum.cumulative.0.boxed_clone(),
|
||||
dateindex.boxed_average(),
|
||||
dateindex.boxed_min(),
|
||||
dateindex.boxed_max(),
|
||||
dateindex.boxed_sum(),
|
||||
dateindex.boxed_cumulative(),
|
||||
indexes,
|
||||
),
|
||||
difficultyepoch: LazyFull::from_stats_aggregate(
|
||||
@@ -66,7 +66,7 @@ where
|
||||
height_source.boxed_clone(),
|
||||
height_source.boxed_clone(),
|
||||
height_source.boxed_clone(),
|
||||
height_cumulative.0.boxed_clone(),
|
||||
height_cumulative.boxed_clone(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
),
|
||||
height_cumulative,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedDerivedBlockLast - dateindex storage + difficultyepoch + lazy time periods.
|
||||
//! ComputedHeightDerivedLast - dateindex storage + difficultyepoch + lazy time periods.
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
@@ -10,12 +10,12 @@ use vecdb::{Database, Exit, IterableBoxedVec, IterableCloneableVec, IterableVec}
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{ComputedVecValue, LazyPeriodsLast, LastVec, LazyLast, NumericValue},
|
||||
internal::{ComputedVecValue, LazyDateDerivedLast, LastVec, LazyLast, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedDerivedBlockLast<T>
|
||||
pub struct ComputedHeightDerivedLast<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -23,13 +23,13 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub dates: LazyPeriodsLast<T>,
|
||||
pub dates: LazyDateDerivedLast<T>,
|
||||
pub difficultyepoch: LazyLast<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedDerivedBlockLast<T>
|
||||
impl<T> ComputedHeightDerivedLast<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -44,7 +44,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Ok(Self {
|
||||
dates: LazyPeriodsLast::from_source(name, v, dateindex.0.boxed_clone(), indexes),
|
||||
dates: LazyDateDerivedLast::from_source(name, v, dateindex.boxed_clone(), indexes),
|
||||
difficultyepoch: LazyLast::from_source(
|
||||
name,
|
||||
v,
|
||||
@@ -7,26 +7,26 @@ use schemars::JsonSchema;
|
||||
use vecdb::{IterableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedDerivedBlockFull, ComputedVecValue, Full, LazyDateFull, LazyPeriodsFull,
|
||||
ComputedHeightDerivedFull, ComputedVecValue, Full, LazyFromDateFull, LazyDateDerivedFull,
|
||||
LazyTransformStats, NumericValue,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyDerivedBlockFull<T, S1T = T>
|
||||
pub struct LazyHeightDerivedFull<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
{
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyDateFull<T, S1T>,
|
||||
pub dates: LazyFromDateFull<T, S1T>,
|
||||
pub difficultyepoch: LazyTransformStats<DifficultyEpoch, T, S1T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyDerivedBlockFull<T, S1T>
|
||||
impl<T, S1T> LazyHeightDerivedFull<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -35,7 +35,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex: &Full<DateIndex, S1T>,
|
||||
periods: &LazyPeriodsFull<S1T>,
|
||||
periods: &LazyDateDerivedFull<S1T>,
|
||||
difficultyepoch: &crate::internal::LazyFull<
|
||||
DifficultyEpoch,
|
||||
S1T,
|
||||
@@ -46,7 +46,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyDateFull::from_full::<F>(name, v, dateindex, periods),
|
||||
dates: LazyFromDateFull::from_full::<F>(name, v, dateindex, periods),
|
||||
difficultyepoch: LazyTransformStats::from_boxed::<F>(
|
||||
name,
|
||||
v,
|
||||
@@ -62,7 +62,7 @@ where
|
||||
pub fn from_derived_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedDerivedBlockFull<S1T>,
|
||||
source: &ComputedHeightDerivedFull<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -70,7 +70,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyDateFull::from_full::<F>(name, v, &source.dateindex, &source.dates),
|
||||
dates: LazyFromDateFull::from_full::<F>(name, v, &source.dateindex, &source.dates),
|
||||
difficultyepoch: LazyTransformStats::from_boxed::<F>(
|
||||
name,
|
||||
v,
|
||||
@@ -7,26 +7,26 @@ use schemars::JsonSchema;
|
||||
use vecdb::{IterableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockLast, ComputedDerivedBlockLast, ComputedHeightDateLast, ComputedVecValue,
|
||||
LazyDateLast, LazyTransformLast, NumericValue,
|
||||
ComputedFromHeightLast, ComputedHeightDerivedLast, ComputedFromHeightAndDateLast, ComputedVecValue,
|
||||
LazyFromDateLast, LazyTransformLast, NumericValue,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyDerivedBlockLast<T, S1T = T>
|
||||
pub struct LazyHeightDerivedLast<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
{
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyDateLast<T, S1T>,
|
||||
pub dates: LazyFromDateLast<T, S1T>,
|
||||
pub difficultyepoch: LazyTransformLast<DifficultyEpoch, T, S1T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyDerivedBlockLast<T, S1T>
|
||||
impl<T, S1T> LazyHeightDerivedLast<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -34,7 +34,7 @@ where
|
||||
pub fn from_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedBlockLast<S1T>,
|
||||
source: &ComputedFromHeightLast<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -42,10 +42,10 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyDateLast::from_derived::<F>(
|
||||
dates: LazyFromDateLast::from_derived::<F>(
|
||||
name,
|
||||
v,
|
||||
source.dateindex.0.boxed_clone(),
|
||||
source.dateindex.boxed_clone(),
|
||||
&source.rest,
|
||||
),
|
||||
difficultyepoch: LazyTransformLast::from_boxed::<F>(
|
||||
@@ -59,7 +59,7 @@ where
|
||||
pub fn from_derived_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedDerivedBlockLast<S1T>,
|
||||
source: &ComputedHeightDerivedLast<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -67,10 +67,10 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyDateLast::from_derived::<F>(
|
||||
dates: LazyFromDateLast::from_derived::<F>(
|
||||
name,
|
||||
v,
|
||||
source.dateindex.0.boxed_clone(),
|
||||
source.dateindex.boxed_clone(),
|
||||
&source.dates,
|
||||
),
|
||||
difficultyepoch: LazyTransformLast::from_boxed::<F>(
|
||||
@@ -84,7 +84,7 @@ where
|
||||
pub fn from_computed_height_date<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedHeightDateLast<S1T>,
|
||||
source: &ComputedFromHeightAndDateLast<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: PartialOrd,
|
||||
@@ -92,7 +92,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyDateLast::from_derived::<F>(
|
||||
dates: LazyFromDateLast::from_derived::<F>(
|
||||
name,
|
||||
v,
|
||||
source.dateindex.boxed_clone(),
|
||||
@@ -101,7 +101,7 @@ where
|
||||
difficultyepoch: LazyTransformLast::from_boxed::<F>(
|
||||
name,
|
||||
v,
|
||||
source.difficultyepoch.0.boxed_clone(),
|
||||
source.difficultyepoch.boxed_clone(),
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -7,26 +7,26 @@ use schemars::JsonSchema;
|
||||
use vecdb::{IterableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedDerivedBlockSum, ComputedVecValue, LazyDateSum, LazyPeriodsSum, LazySum,
|
||||
ComputedHeightDerivedSum, ComputedVecValue, LazyFromDateSum, LazyDateDerivedSum, LazySum,
|
||||
LazyTransformSum, NumericValue, SumVec,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyDerivedBlockSum<T, S1T = T>
|
||||
pub struct LazyHeightDerivedSum<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
{
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyDateSum<T, S1T>,
|
||||
pub dates: LazyFromDateSum<T, S1T>,
|
||||
pub difficultyepoch: LazyTransformSum<DifficultyEpoch, T, S1T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyDerivedBlockSum<T, S1T>
|
||||
impl<T, S1T> LazyHeightDerivedSum<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -35,13 +35,13 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex: &SumVec<DateIndex, S1T>,
|
||||
periods: &LazyPeriodsSum<S1T>,
|
||||
periods: &LazyDateDerivedSum<S1T>,
|
||||
difficultyepoch: &LazySum<DifficultyEpoch, S1T, Height, DifficultyEpoch>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyDateSum::from_derived::<F>(name, v, dateindex.0.boxed_clone(), periods),
|
||||
dates: LazyFromDateSum::from_derived::<F>(name, v, dateindex.boxed_clone(), periods),
|
||||
difficultyepoch: LazyTransformSum::from_boxed::<F>(
|
||||
name,
|
||||
v,
|
||||
@@ -53,7 +53,7 @@ where
|
||||
pub fn from_derived_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedDerivedBlockSum<S1T>,
|
||||
source: &ComputedHeightDerivedSum<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -61,10 +61,10 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyDateSum::from_derived::<F>(
|
||||
dates: LazyFromDateSum::from_derived::<F>(
|
||||
name,
|
||||
v,
|
||||
source.dateindex.0.boxed_clone(),
|
||||
source.dateindex.boxed_clone(),
|
||||
&source.dates,
|
||||
),
|
||||
difficultyepoch: LazyTransformSum::from_boxed::<F>(
|
||||
@@ -7,26 +7,26 @@ use schemars::JsonSchema;
|
||||
use vecdb::{IterableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedDerivedBlockSumCum, ComputedVecValue, LazyDateSumCum, LazyPeriodsSumCum, LazySumCum,
|
||||
ComputedHeightDerivedSumCum, ComputedVecValue, LazyFromDateSumCum, LazyDateDerivedSumCum, LazySumCum,
|
||||
LazyTransformSumCum, NumericValue, SumCum,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyDerivedBlockSumCum<T, S1T = T>
|
||||
pub struct LazyHeightDerivedSumCum<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
{
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyDateSumCum<T, S1T>,
|
||||
pub dates: LazyFromDateSumCum<T, S1T>,
|
||||
pub difficultyepoch: LazyTransformSumCum<DifficultyEpoch, T, S1T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyDerivedBlockSumCum<T, S1T>
|
||||
impl<T, S1T> LazyHeightDerivedSumCum<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -35,13 +35,13 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
dateindex: &SumCum<DateIndex, S1T>,
|
||||
periods: &LazyPeriodsSumCum<S1T>,
|
||||
periods: &LazyDateDerivedSumCum<S1T>,
|
||||
difficultyepoch: &LazySumCum<DifficultyEpoch, S1T, Height, DifficultyEpoch>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyDateSumCum::from_sum_cum::<F>(name, v, dateindex, periods),
|
||||
dates: LazyFromDateSumCum::from_sum_cum::<F>(name, v, dateindex, periods),
|
||||
difficultyepoch: LazyTransformSumCum::from_boxed_sum_raw::<F>(
|
||||
name,
|
||||
v,
|
||||
@@ -54,7 +54,7 @@ where
|
||||
pub fn from_derived_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedDerivedBlockSumCum<S1T>,
|
||||
source: &ComputedHeightDerivedSumCum<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -62,7 +62,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Self {
|
||||
dates: LazyDateSumCum::from_sum_cum::<F>(name, v, &source.dateindex, &source.dates),
|
||||
dates: LazyFromDateSumCum::from_sum_cum::<F>(name, v, &source.dateindex, &source.dates),
|
||||
difficultyepoch: LazyTransformSumCum::from_boxed_sum_raw::<F>(
|
||||
name,
|
||||
v,
|
||||
@@ -11,6 +11,7 @@ mod lazy_sum;
|
||||
mod lazy_sum_cum;
|
||||
mod sum;
|
||||
mod sum_cum;
|
||||
mod value_sum_cum;
|
||||
|
||||
pub use binary_last::*;
|
||||
pub use binary_sum::*;
|
||||
@@ -25,3 +26,4 @@ pub use lazy_sum::*;
|
||||
pub use lazy_sum_cum::*;
|
||||
pub use sum::*;
|
||||
pub use sum_cum::*;
|
||||
pub use value_sum_cum::*;
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedDerivedBlockSum - dateindex storage + difficultyepoch + lazy time periods.
|
||||
//! ComputedHeightDerivedSum - dateindex storage + difficultyepoch + lazy time periods.
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
@@ -13,25 +13,25 @@ use vecdb::{
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{ComputedVecValue, LazyPeriodsSum, LazySum, NumericValue, SumVec},
|
||||
internal::{ComputedVecValue, LazyDateDerivedSum, LazySum, NumericValue, SumVec},
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedDerivedBlockSum<T>
|
||||
pub struct ComputedHeightDerivedSum<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
pub dateindex: SumVec<DateIndex, T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyPeriodsSum<T>,
|
||||
pub dates: LazyDateDerivedSum<T>,
|
||||
pub difficultyepoch: LazySum<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedDerivedBlockSum<T>
|
||||
impl<T> ComputedHeightDerivedSum<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -46,7 +46,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
Ok(Self {
|
||||
dates: LazyPeriodsSum::from_source(name, v, dateindex.0.boxed_clone(), indexes),
|
||||
dates: LazyDateDerivedSum::from_source(name, v, dateindex.boxed_clone(), indexes),
|
||||
difficultyepoch: LazySum::from_source_raw(
|
||||
name,
|
||||
v,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedDerivedBlockSumCum - aggregates derived from an external height source.
|
||||
//! ComputedHeightDerivedSumCum - aggregates derived from an external height source.
|
||||
|
||||
use brk_error::Result;
|
||||
|
||||
@@ -14,14 +14,14 @@ use vecdb::{
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ComputedVecValue, CumulativeVec, LazyPeriodsSumCum, LazySumCum, NumericValue, SumCum,
|
||||
ComputedVecValue, CumulativeVec, LazyDateDerivedSumCum, LazySumCum, NumericValue, SumCum,
|
||||
compute_cumulative_extend,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedDerivedBlockSumCum<T>
|
||||
pub struct ComputedHeightDerivedSumCum<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -30,13 +30,13 @@ where
|
||||
pub dateindex: SumCum<DateIndex, T>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub dates: LazyPeriodsSumCum<T>,
|
||||
pub dates: LazyDateDerivedSumCum<T>,
|
||||
pub difficultyepoch: LazySumCum<DifficultyEpoch, T, Height, DifficultyEpoch>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedDerivedBlockSumCum<T>
|
||||
impl<T> ComputedHeightDerivedSumCum<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -52,11 +52,11 @@ where
|
||||
let height_cumulative = CumulativeVec::forced_import(db, name, v)?;
|
||||
let dateindex = SumCum::forced_import_sum_raw(db, name, v)?;
|
||||
|
||||
let dates = LazyPeriodsSumCum::from_sources(
|
||||
let dates = LazyDateDerivedSumCum::from_sources(
|
||||
name,
|
||||
v,
|
||||
dateindex.sum.0.boxed_clone(),
|
||||
dateindex.cumulative.0.boxed_clone(),
|
||||
dateindex.boxed_sum(),
|
||||
dateindex.boxed_cumulative(),
|
||||
indexes,
|
||||
);
|
||||
|
||||
@@ -64,7 +64,7 @@ where
|
||||
name,
|
||||
v,
|
||||
height_source.boxed_clone(),
|
||||
height_cumulative.0.boxed_clone(),
|
||||
height_cumulative.boxed_clone(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ use vecdb::{Database, Exit, IterableBoxedVec, IterableCloneableVec, IterableVec,
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ClosePriceTimesSats, ComputedDerivedBlockSumCum, LazyBlockSumCum, LazyBlockSumCumHeight,
|
||||
ClosePriceTimesSats, ComputedHeightDerivedSumCum, LazyFromHeightSumCum, LazyComputedFromHeightSumCum,
|
||||
SatsToBitcoin,
|
||||
},
|
||||
price,
|
||||
@@ -16,15 +16,15 @@ use crate::{
|
||||
|
||||
/// Value wrapper for derived SumCum (derives from external height source).
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ValueDerivedBlockSumCum {
|
||||
pub sats: ComputedDerivedBlockSumCum<Sats>,
|
||||
pub bitcoin: LazyBlockSumCum<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyBlockSumCumHeight<Dollars, Close<Dollars>, Sats>>,
|
||||
pub struct ValueHeightDerivedSumCum {
|
||||
pub sats: ComputedHeightDerivedSumCum<Sats>,
|
||||
pub bitcoin: LazyFromHeightSumCum<Bitcoin, Sats>,
|
||||
pub dollars: Option<LazyComputedFromHeightSumCum<Dollars, Close<Dollars>, Sats>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl ValueDerivedBlockSumCum {
|
||||
impl ValueHeightDerivedSumCum {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -35,7 +35,7 @@ impl ValueDerivedBlockSumCum {
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = ComputedDerivedBlockSumCum::forced_import(
|
||||
let sats = ComputedHeightDerivedSumCum::forced_import(
|
||||
db,
|
||||
name,
|
||||
sats_source.boxed_clone(),
|
||||
@@ -43,7 +43,7 @@ impl ValueDerivedBlockSumCum {
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let bitcoin = LazyBlockSumCum::from_derived::<SatsToBitcoin>(
|
||||
let bitcoin = LazyFromHeightSumCum::from_derived::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats_source.boxed_clone(),
|
||||
@@ -58,7 +58,7 @@ impl ValueDerivedBlockSumCum {
|
||||
sats_source.boxed_clone(),
|
||||
);
|
||||
|
||||
Some(LazyBlockSumCumHeight::forced_import(
|
||||
Some(LazyComputedFromHeightSumCum::forced_import(
|
||||
db,
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
@@ -1,17 +1,19 @@
|
||||
//! Multi-index composite types.
|
||||
|
||||
mod date;
|
||||
mod derived_date;
|
||||
mod derived_height;
|
||||
mod derived_tx;
|
||||
mod height;
|
||||
mod specialized;
|
||||
mod value;
|
||||
mod date_derived;
|
||||
mod from_date;
|
||||
mod from_height;
|
||||
mod from_height_and_date;
|
||||
mod from_tx;
|
||||
mod height_and_date;
|
||||
mod height_derived;
|
||||
mod tx_derived;
|
||||
|
||||
pub use date::*;
|
||||
pub use derived_date::*;
|
||||
pub use derived_height::*;
|
||||
pub use derived_tx::*;
|
||||
pub use height::*;
|
||||
pub use specialized::*;
|
||||
pub use value::*;
|
||||
pub use date_derived::*;
|
||||
pub use from_date::*;
|
||||
pub use from_height::*;
|
||||
pub use from_height_and_date::*;
|
||||
pub use from_tx::*;
|
||||
pub use height_and_date::*;
|
||||
pub use height_derived::*;
|
||||
pub use tx_derived::*;
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
mod constant;
|
||||
mod ohlc;
|
||||
mod percentiles;
|
||||
mod ratio;
|
||||
mod stddev;
|
||||
|
||||
pub use constant::*;
|
||||
pub use ohlc::*;
|
||||
pub use percentiles::*;
|
||||
pub use ratio::*;
|
||||
pub use stddev::*;
|
||||
@@ -1,7 +0,0 @@
|
||||
mod computed;
|
||||
mod lazy;
|
||||
mod period;
|
||||
|
||||
pub use computed::*;
|
||||
pub use lazy::*;
|
||||
pub use period::*;
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedTxDistribution - computes TxIndex data to height Distribution + dateindex MinMaxAverage + lazy aggregations.
|
||||
//! TxDerivedDistribution - computes TxIndex data to height Distribution + dateindex MinMaxAverage + lazy aggregations.
|
||||
//!
|
||||
//! Note: Percentiles are computed at height level only. DateIndex and coarser
|
||||
//! periods only have average+min+max since computing percentiles across all
|
||||
@@ -16,14 +16,14 @@ use vecdb::{CollectableVec, Database, Exit, IterableCloneableVec};
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
ComputedVecValue, LazyPeriodsDistribution, Distribution, LazyDistribution, MinMaxAverage,
|
||||
ComputedVecValue, LazyDateDerivedDistribution, Distribution, LazyDistribution, MinMaxAverage,
|
||||
NumericValue,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct DerivedTxDistribution<T>
|
||||
pub struct TxDerivedDistribution<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -33,12 +33,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub dates: LazyPeriodsDistribution<T>,
|
||||
pub dates: LazyDateDerivedDistribution<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> DerivedTxDistribution<T>
|
||||
impl<T> TxDerivedDistribution<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -56,18 +56,18 @@ where
|
||||
LazyDistribution::<DifficultyEpoch, T, Height, DifficultyEpoch>::from_distribution(
|
||||
name,
|
||||
v,
|
||||
height.average.0.boxed_clone(),
|
||||
height.minmax.min.0.boxed_clone(),
|
||||
height.minmax.max.0.boxed_clone(),
|
||||
height.boxed_average(),
|
||||
height.boxed_min(),
|
||||
height.boxed_max(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
);
|
||||
|
||||
let dates = LazyPeriodsDistribution::from_sources(
|
||||
let dates = LazyDateDerivedDistribution::from_sources(
|
||||
name,
|
||||
v,
|
||||
dateindex.average.0.boxed_clone(),
|
||||
dateindex.minmax.min.0.boxed_clone(),
|
||||
dateindex.minmax.max.0.boxed_clone(),
|
||||
dateindex.boxed_average(),
|
||||
dateindex.boxed_min(),
|
||||
dateindex.boxed_max(),
|
||||
indexes,
|
||||
);
|
||||
|
||||
@@ -87,17 +87,33 @@ where
|
||||
txindex_source: &impl CollectableVec<TxIndex, T>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.height.compute(
|
||||
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 fn derive_from_with_skip(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
txindex_source: &impl CollectableVec<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,
|
||||
)?;
|
||||
|
||||
self.dateindex.compute(
|
||||
starting_indexes.dateindex,
|
||||
&self.height.average.0,
|
||||
&self.height.average().0,
|
||||
&indexes.dateindex.first_height,
|
||||
&indexes.dateindex.height_count,
|
||||
exit,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! DerivedTxFull - aggregates from TxIndex to height Full + dateindex Stats + lazy date periods.
|
||||
//! TxDerivedFull - aggregates from TxIndex to height Full + dateindex Stats + lazy date periods.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
@@ -11,13 +11,13 @@ use vecdb::{CollectableVec, Database, Exit, IterableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes, ComputeIndexes,
|
||||
internal::{ComputedVecValue, LazyPeriodsFull, Full, LazyFull, NumericValue, Stats},
|
||||
internal::{ComputedVecValue, LazyDateDerivedFull, Full, LazyFull, NumericValue, Stats},
|
||||
};
|
||||
|
||||
/// Aggregates from TxIndex to height/dateindex with full stats.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct DerivedTxFull<T>
|
||||
pub struct TxDerivedFull<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -27,12 +27,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub dates: LazyPeriodsFull<T>,
|
||||
pub dates: LazyDateDerivedFull<T>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> DerivedTxFull<T>
|
||||
impl<T> TxDerivedFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -50,22 +50,22 @@ where
|
||||
LazyFull::<DifficultyEpoch, T, Height, DifficultyEpoch>::from_stats_aggregate(
|
||||
name,
|
||||
v,
|
||||
height.distribution.average.0.boxed_clone(),
|
||||
height.distribution.minmax.min.0.boxed_clone(),
|
||||
height.distribution.minmax.max.0.boxed_clone(),
|
||||
height.sum_cum.sum.0.boxed_clone(),
|
||||
height.sum_cum.cumulative.0.boxed_clone(),
|
||||
height.boxed_average(),
|
||||
height.boxed_min(),
|
||||
height.boxed_max(),
|
||||
height.boxed_sum(),
|
||||
height.boxed_cumulative(),
|
||||
indexes.difficultyepoch.identity.boxed_clone(),
|
||||
);
|
||||
|
||||
let dates = LazyPeriodsFull::from_sources(
|
||||
let dates = LazyDateDerivedFull::from_sources(
|
||||
name,
|
||||
v,
|
||||
dateindex.average.0.boxed_clone(),
|
||||
dateindex.minmax.min.0.boxed_clone(),
|
||||
dateindex.minmax.max.0.boxed_clone(),
|
||||
dateindex.sum_cum.sum.0.boxed_clone(),
|
||||
dateindex.sum_cum.cumulative.0.boxed_clone(),
|
||||
dateindex.boxed_average(),
|
||||
dateindex.boxed_min(),
|
||||
dateindex.boxed_max(),
|
||||
dateindex.boxed_sum(),
|
||||
dateindex.boxed_cumulative(),
|
||||
indexes,
|
||||
);
|
||||
|
||||
@@ -85,17 +85,33 @@ where
|
||||
txindex_source: &impl CollectableVec<TxIndex, T>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.height.compute(
|
||||
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 fn derive_from_with_skip(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
txindex_source: &impl CollectableVec<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,
|
||||
)?;
|
||||
|
||||
self.dateindex.compute(
|
||||
starting_indexes.dateindex,
|
||||
&self.height.distribution.average.0,
|
||||
&self.height.average().0,
|
||||
&indexes.dateindex.first_height,
|
||||
&indexes.dateindex.height_count,
|
||||
exit,
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Lazy transform of DerivedTxFull.
|
||||
//! Lazy transform of TxDerivedFull.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
@@ -8,11 +8,11 @@ use brk_types::{
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{IterableCloneableVec, UnaryTransform};
|
||||
|
||||
use crate::internal::{ComputedVecValue, DerivedTxFull, LazyTransformFull, LazyTransformStats};
|
||||
use crate::internal::{ComputedVecValue, TxDerivedFull, LazyTransformFull, LazyTransformStats};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyDerivedTxFull<T, S1T = T>
|
||||
pub struct LazyTxDerivedFull<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -30,7 +30,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyDerivedTxFull<T, S1T>
|
||||
impl<T, S1T> LazyTxDerivedFull<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -38,7 +38,7 @@ where
|
||||
pub fn from_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &DerivedTxFull<S1T>,
|
||||
source: &TxDerivedFull<S1T>,
|
||||
) -> Self {
|
||||
let v = version + VERSION;
|
||||
|
||||
@@ -58,11 +58,11 @@ where
|
||||
difficultyepoch: period!(difficultyepoch),
|
||||
dateindex: LazyTransformStats::from_boxed::<F>(
|
||||
name, v,
|
||||
source.dateindex.average.0.boxed_clone(),
|
||||
source.dateindex.minmax.min.0.boxed_clone(),
|
||||
source.dateindex.minmax.max.0.boxed_clone(),
|
||||
source.dateindex.sum_cum.sum.0.boxed_clone(),
|
||||
source.dateindex.sum_cum.cumulative.0.boxed_clone(),
|
||||
source.dateindex.boxed_average(),
|
||||
source.dateindex.boxed_min(),
|
||||
source.dateindex.boxed_max(),
|
||||
source.dateindex.boxed_sum(),
|
||||
source.dateindex.boxed_cumulative(),
|
||||
),
|
||||
weekindex: period!(weekindex),
|
||||
monthindex: period!(monthindex),
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user