mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-12 19:48:15 -07:00
global: veccached change
This commit is contained in:
@@ -4,7 +4,7 @@ use std::sync::{
|
||||
};
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use vecdb::{CachedVec, CachedVecBudget, ReadableBoxedVec, VecIndex, VecValue};
|
||||
use vecdb::{CachedVec, CachedVecBudget, ReadableVec, TypedVec};
|
||||
|
||||
const MAX_CACHED: usize = 256;
|
||||
const MIN_ACCESSES: u64 = 2;
|
||||
@@ -67,10 +67,13 @@ fn evict_less_popular_than(threshold: u64) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps a boxed source in a budgeted [`CachedVec`] and registers it for eviction.
|
||||
pub fn cache_wrap<I: VecIndex, T: VecValue>(source: ReadableBoxedVec<I, T>) -> CachedVec<I, T> {
|
||||
/// Wraps a source vec in a budgeted [`CachedVec`] and registers it for eviction.
|
||||
pub fn cache_wrap<V>(source: V) -> CachedVec<V>
|
||||
where
|
||||
V: TypedVec + ReadableVec<V::I, V::T> + Clone + 'static,
|
||||
{
|
||||
let access_count = Arc::new(AtomicU64::new(0));
|
||||
let cached = CachedVec::new_budgeted(source, &BUDGET, access_count.clone());
|
||||
let cached = CachedVec::wrap_budgeted(source, &BUDGET, access_count.clone());
|
||||
let clone = cached.clone();
|
||||
CACHES.lock().push(CacheEntry {
|
||||
access_count,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[derive(Clone, Copy, Traversable)]
|
||||
pub struct Windows<A> {
|
||||
pub _24h: A,
|
||||
pub _1w: A,
|
||||
|
||||
@@ -59,7 +59,7 @@ impl AmountPerBlock {
|
||||
self.cents.compute_binary::<Sats, Cents, SatsToCents>(
|
||||
max_from,
|
||||
&self.sats.height,
|
||||
&prices.cached_spot_cents,
|
||||
&prices.spot.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
|
||||
@@ -50,7 +50,7 @@ impl AmountBlock {
|
||||
self.cents.compute_binary::<Sats, Cents, SatsToCents>(
|
||||
max_from,
|
||||
&self.sats,
|
||||
&prices.cached_spot_cents,
|
||||
&prices.spot.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
|
||||
@@ -7,8 +7,8 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
AmountPerBlockCumulative, CachedWindowStarts, LazyRollingAvgsAmountFromHeight,
|
||||
LazyRollingSumsAmountFromHeight,
|
||||
AmountPerBlockCumulative, LazyRollingAvgsAmountFromHeight, LazyRollingSumsAmountFromHeight,
|
||||
WindowStartVec, Windows,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -31,7 +31,7 @@ impl AmountPerBlockCumulativeRolling {
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
AmountPerBlockCumulativeRolling, CachedWindowStarts, RollingDistributionAmountPerBlock,
|
||||
WindowStarts,
|
||||
AmountPerBlockCumulativeRolling, RollingDistributionAmountPerBlock, WindowStartVec,
|
||||
WindowStarts, Windows,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -31,7 +31,7 @@ impl AmountPerBlockFull {
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, StoredF32, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{DeltaAvg, LazyDeltaVec, LazyVecFrom1, ReadableCloneableVec};
|
||||
use vecdb::{DeltaAvg, LazyDeltaVec, LazyVecFrom1, ReadOnlyClone, ReadableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
AvgCentsToUsd, AvgSatsToBtc, CachedWindowStarts, DerivedResolutions, LazyPerBlock,
|
||||
LazyRollingAvgFromHeight, Resolutions, Windows,
|
||||
AvgCentsToUsd, AvgSatsToBtc, DerivedResolutions, LazyPerBlock, LazyRollingAvgFromHeight,
|
||||
Resolutions, WindowStartVec, Windows,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -31,15 +31,15 @@ impl LazyRollingAvgsAmountFromHeight {
|
||||
version: Version,
|
||||
cumulative_sats: &(impl ReadableCloneableVec<Height, Sats> + 'static),
|
||||
cumulative_cents: &(impl ReadableCloneableVec<Height, Cents> + 'static),
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let cum_sats = cumulative_sats.read_only_boxed_clone();
|
||||
let cum_cents = cumulative_cents.read_only_boxed_clone();
|
||||
|
||||
let make_slot = |suffix: &str, cached_start: &vecdb::CachedVec<Height, Height>| {
|
||||
let make_slot = |suffix: &str, cached_start: &&WindowStartVec| {
|
||||
let full_name = format!("{name}_{suffix}");
|
||||
let cached = cached_start.clone();
|
||||
let cached = cached_start.read_only_clone();
|
||||
let starts_version = cached.version();
|
||||
|
||||
// Sats lazy rolling avg → f64
|
||||
@@ -50,12 +50,12 @@ impl LazyRollingAvgsAmountFromHeight {
|
||||
starts_version,
|
||||
{
|
||||
let cached = cached.clone();
|
||||
move || cached.get()
|
||||
move || cached.cached()
|
||||
},
|
||||
);
|
||||
let sats_resolutions = Resolutions::forced_import(
|
||||
&format!("{full_name}_sats"),
|
||||
sats_avg.read_only_boxed_clone(),
|
||||
sats_avg.clone(),
|
||||
version,
|
||||
indexes,
|
||||
);
|
||||
@@ -84,11 +84,11 @@ impl LazyRollingAvgsAmountFromHeight {
|
||||
version,
|
||||
cum_cents.clone(),
|
||||
starts_version,
|
||||
move || cached.get(),
|
||||
move || cached.cached(),
|
||||
);
|
||||
let cents_resolutions = Resolutions::forced_import(
|
||||
&format!("{full_name}_cents"),
|
||||
cents_avg.read_only_boxed_clone(),
|
||||
cents_avg.clone(),
|
||||
version,
|
||||
indexes,
|
||||
);
|
||||
@@ -119,6 +119,6 @@ impl LazyRollingAvgsAmountFromHeight {
|
||||
}
|
||||
};
|
||||
|
||||
Self(cached_starts.0.map_with_suffix(make_slot))
|
||||
Self(cached_starts.map_with_suffix(make_slot))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{DeltaSub, LazyDeltaVec, LazyVecFrom1, ReadableCloneableVec};
|
||||
use vecdb::{DeltaSub, LazyDeltaVec, LazyVecFrom1, ReadOnlyClone, ReadableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, CentsUnsignedToDollars, DerivedResolutions, LazyPerBlock,
|
||||
LazyRollingSumFromHeight, Resolutions, SatsToBitcoin, Windows,
|
||||
CentsUnsignedToDollars, DerivedResolutions, LazyPerBlock, LazyRollingSumFromHeight,
|
||||
Resolutions, SatsToBitcoin, WindowStartVec, Windows,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -31,15 +31,15 @@ impl LazyRollingSumsAmountFromHeight {
|
||||
version: Version,
|
||||
cumulative_sats: &(impl ReadableCloneableVec<Height, Sats> + 'static),
|
||||
cumulative_cents: &(impl ReadableCloneableVec<Height, Cents> + 'static),
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let cum_sats = cumulative_sats.read_only_boxed_clone();
|
||||
let cum_cents = cumulative_cents.read_only_boxed_clone();
|
||||
|
||||
let make_slot = |suffix: &str, cached_start: &vecdb::CachedVec<Height, Height>| {
|
||||
let make_slot = |suffix: &str, cached_start: &&WindowStartVec| {
|
||||
let full_name = format!("{name}_{suffix}");
|
||||
let cached = cached_start.clone();
|
||||
let cached = cached_start.read_only_clone();
|
||||
let starts_version = cached.version();
|
||||
|
||||
// Sats lazy rolling sum
|
||||
@@ -50,12 +50,12 @@ impl LazyRollingSumsAmountFromHeight {
|
||||
starts_version,
|
||||
{
|
||||
let cached = cached.clone();
|
||||
move || cached.get()
|
||||
move || cached.cached()
|
||||
},
|
||||
);
|
||||
let sats_resolutions = Resolutions::forced_import(
|
||||
&format!("{full_name}_sats"),
|
||||
sats_sum.read_only_boxed_clone(),
|
||||
sats_sum.clone(),
|
||||
version,
|
||||
indexes,
|
||||
);
|
||||
@@ -84,11 +84,11 @@ impl LazyRollingSumsAmountFromHeight {
|
||||
version,
|
||||
cum_cents.clone(),
|
||||
starts_version,
|
||||
move || cached.get(),
|
||||
move || cached.cached(),
|
||||
);
|
||||
let cents_resolutions = Resolutions::forced_import(
|
||||
&format!("{full_name}_cents"),
|
||||
cents_sum.read_only_boxed_clone(),
|
||||
cents_sum.clone(),
|
||||
version,
|
||||
indexes,
|
||||
);
|
||||
@@ -119,6 +119,6 @@ impl LazyRollingSumsAmountFromHeight {
|
||||
}
|
||||
};
|
||||
|
||||
Self(cached_starts.0.map_with_suffix(make_slot))
|
||||
Self(cached_starts.map_with_suffix(make_slot))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{Database, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{AmountPerBlock, CachedWindowStarts, LazyRollingDeltasFromHeight},
|
||||
internal::{AmountPerBlock, LazyRollingDeltasFromHeight, WindowStartVec, Windows},
|
||||
};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
@@ -24,7 +24,7 @@ impl AmountPerBlockWithDeltas {
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let inner = AmountPerBlock::forced_import(db, name, version, indexes)?;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use vecdb::{
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, NumericValue, PerBlock, RollingComplete, WindowStarts},
|
||||
internal::{NumericValue, PerBlock, RollingComplete, WindowStartVec, WindowStarts, Windows},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -31,7 +31,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let sum = EagerVec::forced_import(db, &format!("{name}_sum"), version)?;
|
||||
let cumulative =
|
||||
|
||||
@@ -5,8 +5,8 @@ use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{
|
||||
BinaryTransform, Database, EagerVec, Exit, ImportableVec, PcoVec, ReadableCloneableVec,
|
||||
ReadableVec, Rw, StorageMode, VecValue,
|
||||
BinaryTransform, Database, EagerVec, Exit, ImportableVec, PcoVec, ReadOnlyClone, ReadableVec,
|
||||
Rw, StorageMode, VecValue,
|
||||
};
|
||||
|
||||
use crate::indexes;
|
||||
@@ -39,7 +39,7 @@ where
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, version)?;
|
||||
|
||||
let resolutions =
|
||||
Resolutions::forced_import(name, height.read_only_boxed_clone(), version, indexes);
|
||||
Resolutions::forced_import(name, height.read_only_clone(), version, indexes);
|
||||
|
||||
Ok(Self {
|
||||
height,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{CachedVec, Database, EagerVec, ImportableVec, PcoVec, ReadOnlyClone, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{NumericValue, Resolutions},
|
||||
};
|
||||
|
||||
/// Like [`PerBlock`](super::PerBlock) but with height wrapped in [`CachedVec`]
|
||||
/// for fast repeated reads.
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct CachedPerBlock<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: CachedVec<M::Stored<EagerVec<PcoVec<Height, T>>>>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub resolutions: Box<Resolutions<T>>,
|
||||
}
|
||||
|
||||
impl<T> CachedPerBlock<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, version)?;
|
||||
|
||||
let resolutions =
|
||||
Resolutions::forced_import(name, height.read_only_clone(), version, indexes);
|
||||
|
||||
Ok(Self {
|
||||
height: CachedVec::wrap(height),
|
||||
resolutions: Box::new(resolutions),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, LazyRollingAvgsFromHeight, LazyRollingSumsFromHeight, NumericValue,
|
||||
PerBlock,
|
||||
LazyRollingAvgsFromHeight, LazyRollingSumsFromHeight, NumericValue, PerBlock,
|
||||
WindowStartVec, Windows,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -45,7 +45,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let block = EagerVec::forced_import(db, name, version)?;
|
||||
let cumulative =
|
||||
|
||||
@@ -10,7 +10,7 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, NumericValue, PerBlock, RollingComplete, WindowStarts},
|
||||
internal::{NumericValue, PerBlock, RollingComplete, WindowStartVec, WindowStarts, Windows},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -33,7 +33,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let block = EagerVec::forced_import(db, name, version)?;
|
||||
let cumulative =
|
||||
|
||||
@@ -6,8 +6,8 @@ use vecdb::{ReadableCloneableVec, UnaryTransform};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, ComputedVecValue, LazyPerBlock, LazyRollingComplete, NumericValue,
|
||||
PerBlockFull,
|
||||
ComputedVecValue, LazyPerBlock, LazyRollingComplete, NumericValue, PerBlockFull,
|
||||
WindowStartVec, Windows,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &PerBlockFull<S1T>,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let cumulative = LazyPerBlock::from_computed::<F>(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
mod aggregated;
|
||||
mod base;
|
||||
mod cached;
|
||||
mod cumulative_rolling;
|
||||
mod distribution;
|
||||
mod full;
|
||||
@@ -12,6 +13,7 @@ mod with_deltas;
|
||||
|
||||
pub use aggregated::*;
|
||||
pub use base::*;
|
||||
pub use cached::*;
|
||||
pub use cumulative_rolling::*;
|
||||
pub use distribution::*;
|
||||
pub use full::*;
|
||||
|
||||
@@ -8,8 +8,8 @@ use brk_types::{
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{
|
||||
AggFold, LazyAggVec, ReadOnlyClone, ReadableBoxedVec, ReadableCloneableVec, ReadableVec,
|
||||
VecIndex, VecValue,
|
||||
AggFold, LazyAggVec, ReadOnlyClone, ReadableCloneableVec, ReadableVec, TypedVec, VecIndex,
|
||||
VecValue,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -102,47 +102,48 @@ impl<T> Resolutions<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
pub(crate) fn forced_import<V>(
|
||||
name: &str,
|
||||
height_source: ReadableBoxedVec<Height, T>,
|
||||
height_source: V,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
) -> Self
|
||||
where
|
||||
V: TypedVec<I = Height, T = T> + ReadableVec<Height, T> + Clone + 'static,
|
||||
{
|
||||
let cached = cache_wrap(height_source);
|
||||
let height_source = cached.read_only_boxed_clone();
|
||||
|
||||
let cm = &indexes.cached_mappings;
|
||||
|
||||
macro_rules! res {
|
||||
($cached:expr) => {{
|
||||
let cached = $cached.clone();
|
||||
($field:expr) => {{
|
||||
let cached = $field.read_only_clone();
|
||||
let mapping_version = cached.version();
|
||||
LazyAggVec::new(
|
||||
name,
|
||||
version,
|
||||
mapping_version,
|
||||
height_source.clone(),
|
||||
move || cached.get(),
|
||||
move || cached.cached(),
|
||||
)
|
||||
}};
|
||||
}
|
||||
|
||||
Self(PerResolution {
|
||||
minute10: res!(cm.minute10_first_height),
|
||||
minute30: res!(cm.minute30_first_height),
|
||||
hour1: res!(cm.hour1_first_height),
|
||||
hour4: res!(cm.hour4_first_height),
|
||||
hour12: res!(cm.hour12_first_height),
|
||||
day1: res!(cm.day1_first_height),
|
||||
day3: res!(cm.day3_first_height),
|
||||
week1: res!(cm.week1_first_height),
|
||||
month1: res!(cm.month1_first_height),
|
||||
month3: res!(cm.month3_first_height),
|
||||
month6: res!(cm.month6_first_height),
|
||||
year1: res!(cm.year1_first_height),
|
||||
year10: res!(cm.year10_first_height),
|
||||
halving: res!(cm.halving_identity),
|
||||
epoch: res!(cm.epoch_identity),
|
||||
minute10: res!(indexes.minute10.first_height),
|
||||
minute30: res!(indexes.minute30.first_height),
|
||||
hour1: res!(indexes.hour1.first_height),
|
||||
hour4: res!(indexes.hour4.first_height),
|
||||
hour12: res!(indexes.hour12.first_height),
|
||||
day1: res!(indexes.day1.first_height),
|
||||
day3: res!(indexes.day3.first_height),
|
||||
week1: res!(indexes.week1.first_height),
|
||||
month1: res!(indexes.month1.first_height),
|
||||
month3: res!(indexes.month3.first_height),
|
||||
month6: res!(indexes.month6.first_height),
|
||||
year1: res!(indexes.year1.first_height),
|
||||
year10: res!(indexes.year10.first_height),
|
||||
halving: res!(indexes.halving.identity),
|
||||
epoch: res!(indexes.epoch.identity),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, NumericValue, PerBlock, RollingComplete, WindowStarts},
|
||||
internal::{NumericValue, PerBlock, RollingComplete, WindowStartVec, WindowStarts, Windows},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -33,7 +33,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let cumulative =
|
||||
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
|
||||
@@ -12,7 +12,7 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::indexes;
|
||||
|
||||
use crate::internal::{CachedWindowStarts, LazyRollingAvgsFromHeight, NumericValue};
|
||||
use crate::internal::{LazyRollingAvgsFromHeight, NumericValue, WindowStartVec, Windows};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct PerBlockRollingAverage<T, M: StorageMode = Rw>
|
||||
@@ -35,7 +35,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let block: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, version)?;
|
||||
let cumulative: EagerVec<PcoVec<Height, T>> =
|
||||
|
||||
@@ -7,7 +7,9 @@ use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{BpsType, CachedWindowStarts, LazyRollingDeltasFromHeight, NumericValue, PerBlock},
|
||||
internal::{
|
||||
BpsType, LazyRollingDeltasFromHeight, NumericValue, PerBlock, WindowStartVec, Windows,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
@@ -35,7 +37,7 @@ where
|
||||
version: Version,
|
||||
delta_version_offset: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let base = PerBlock::forced_import(db, name, version, indexes)?;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, CentsType, FiatBlock, FiatPerBlock, LazyRollingSumsFiatFromHeight,
|
||||
CentsType, FiatBlock, FiatPerBlock, LazyRollingSumsFiatFromHeight, WindowStartVec, Windows,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let block = FiatBlock::forced_import(db, name, version)?;
|
||||
let cumulative =
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{Database, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{BpsType, CachedWindowStarts, LazyRollingDeltasFiatFromHeight},
|
||||
internal::{BpsType, LazyRollingDeltasFiatFromHeight, WindowStartVec, Windows},
|
||||
};
|
||||
|
||||
use super::{CentsType, FiatPerBlockCumulativeWithSums};
|
||||
@@ -37,7 +37,7 @@ where
|
||||
version: Version,
|
||||
delta_version_offset: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let inner = FiatPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{DeltaSub, LazyDeltaVec, LazyVecFrom1, ReadableCloneableVec};
|
||||
use vecdb::{DeltaSub, LazyDeltaVec, LazyVecFrom1, ReadOnlyClone, ReadableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, CentsType, DerivedResolutions, LazyPerBlock, LazyRollingSumFromHeight,
|
||||
Resolutions, Windows,
|
||||
CentsType, DerivedResolutions, LazyPerBlock, LazyRollingSumFromHeight, Resolutions,
|
||||
WindowStartVec, Windows,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -28,14 +28,14 @@ impl<C: CentsType> LazyRollingSumsFiatFromHeight<C> {
|
||||
name: &str,
|
||||
version: Version,
|
||||
cumulative_cents: &(impl ReadableCloneableVec<Height, C> + 'static),
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let cum_cents = cumulative_cents.read_only_boxed_clone();
|
||||
|
||||
let make_slot = |suffix: &str, cached_start: &vecdb::CachedVec<Height, Height>| {
|
||||
let make_slot = |suffix: &str, cached_start: &&WindowStartVec| {
|
||||
let full_name = format!("{name}_{suffix}");
|
||||
let cached = cached_start.clone();
|
||||
let cached = cached_start.read_only_clone();
|
||||
let starts_version = cached.version();
|
||||
|
||||
let cents_sum = LazyDeltaVec::<Height, C, C, DeltaSub>::new(
|
||||
@@ -43,11 +43,11 @@ impl<C: CentsType> LazyRollingSumsFiatFromHeight<C> {
|
||||
version,
|
||||
cum_cents.clone(),
|
||||
starts_version,
|
||||
move || cached.get(),
|
||||
move || cached.cached(),
|
||||
);
|
||||
let cents_resolutions = Resolutions::forced_import(
|
||||
&format!("{full_name}_cents"),
|
||||
cents_sum.read_only_boxed_clone(),
|
||||
cents_sum.clone(),
|
||||
version,
|
||||
indexes,
|
||||
);
|
||||
@@ -72,6 +72,6 @@ impl<C: CentsType> LazyRollingSumsFiatFromHeight<C> {
|
||||
LazyRollingSumFiatFromHeight { usd, cents }
|
||||
};
|
||||
|
||||
Self(cached_starts.0.map_with_suffix(make_slot))
|
||||
Self(cached_starts.map_with_suffix(make_slot))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use vecdb::{Database, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{BpsType, CachedWindowStarts, LazyRollingDeltasFiatFromHeight},
|
||||
internal::{BpsType, LazyRollingDeltasFiatFromHeight, WindowStartVec, Windows},
|
||||
};
|
||||
|
||||
use super::{CentsType, FiatPerBlock};
|
||||
@@ -38,7 +38,7 @@ where
|
||||
version: Version,
|
||||
delta_version_offset: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let inner = FiatPerBlock::forced_import(db, name, version, indexes)?;
|
||||
|
||||
|
||||
@@ -2,11 +2,16 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{LazyVecFrom1, ReadOnlyClone, ReadableBoxedVec, ReadableCloneableVec, UnaryTransform};
|
||||
use vecdb::{
|
||||
LazyVecFrom1, ReadOnlyClone, ReadableBoxedVec, ReadableCloneableVec, ReadableVec, TypedVec,
|
||||
UnaryTransform,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecValue, DerivedResolutions, NumericValue, PerBlock},
|
||||
internal::{
|
||||
CachedPerBlock, ComputedVecValue, DerivedResolutions, NumericValue, PerBlock, Resolutions,
|
||||
},
|
||||
};
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
@@ -27,6 +32,23 @@ where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_resolutions<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: ReadableBoxedVec<Height, S1T>,
|
||||
resolutions: &Resolutions<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, version, height_source),
|
||||
resolutions: Box::new(DerivedResolutions::from_derived_computed::<F>(
|
||||
name, version, resolutions,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
@@ -36,26 +58,38 @@ where
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, version, height_source),
|
||||
resolutions: Box::new(DerivedResolutions::from_computed::<F>(
|
||||
name, version, source,
|
||||
)),
|
||||
}
|
||||
Self::from_resolutions::<F>(name, version, height_source, &source.resolutions)
|
||||
}
|
||||
|
||||
pub(crate) fn from_height_source<F: UnaryTransform<S1T, T>>(
|
||||
pub(crate) fn from_cached_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: ReadableBoxedVec<Height, S1T>,
|
||||
indexes: &indexes::Vecs,
|
||||
source: &CachedPerBlock<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
Self::from_resolutions::<F>(name, version, height_source, &source.resolutions)
|
||||
}
|
||||
|
||||
pub(crate) fn from_height_source<F: UnaryTransform<S1T, T>, V>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: V,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
V: TypedVec<I = Height, T = S1T> + ReadableVec<Height, S1T> + Clone + 'static,
|
||||
{
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, version, height_source.clone()),
|
||||
resolutions: Box::new(DerivedResolutions::from_height_source::<F>(
|
||||
height: LazyVecFrom1::transformed::<F>(
|
||||
name,
|
||||
version,
|
||||
height_source.read_only_boxed_clone(),
|
||||
),
|
||||
resolutions: Box::new(DerivedResolutions::from_height_source::<F, V>(
|
||||
name,
|
||||
version,
|
||||
height_source,
|
||||
|
||||
@@ -5,11 +5,11 @@ use brk_types::{
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{ReadableBoxedVec, ReadableCloneableVec, UnaryTransform, VecValue};
|
||||
use vecdb::{ReadableCloneableVec, ReadableVec, TypedVec, UnaryTransform, VecValue};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecValue, NumericValue, PerBlock, PerResolution, Resolutions},
|
||||
internal::{ComputedVecValue, NumericValue, PerResolution, Resolutions},
|
||||
};
|
||||
|
||||
use super::{LazyTransformLast, MapOption};
|
||||
@@ -45,25 +45,15 @@ where
|
||||
T: VecValue + PartialOrd + JsonSchema + 'static,
|
||||
S1T: VecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
pub(crate) fn from_computed<F: UnaryTransform<S1T, T>>(
|
||||
pub(crate) fn from_height_source<F: UnaryTransform<S1T, T>, V>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &PerBlock<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
Self::from_derived_computed::<F>(name, version, &source.resolutions)
|
||||
}
|
||||
|
||||
pub(crate) fn from_height_source<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: ReadableBoxedVec<Height, S1T>,
|
||||
height_source: V,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
V: TypedVec<I = Height, T = S1T> + ReadableVec<Height, S1T> + Clone + 'static,
|
||||
{
|
||||
let derived = Resolutions::forced_import(name, height_source, version, indexes);
|
||||
Self::from_derived_computed::<F>(name, version, &derived)
|
||||
|
||||
@@ -71,7 +71,7 @@ impl PriceWithRatioPerBlock {
|
||||
F: FnMut(&mut EagerVec<PcoVec<Height, Cents>>) -> Result<()>,
|
||||
{
|
||||
compute_price(&mut self.cents.height)?;
|
||||
self.compute_ratio(starting_indexes, &prices.cached_spot_cents, exit)
|
||||
self.compute_ratio(starting_indexes, &prices.spot.cents.height, exit)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ impl PriceWithRatioExtendedPerBlock {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let close_price = &prices.cached_spot_cents;
|
||||
let close_price = &prices.spot.cents.height;
|
||||
self.base
|
||||
.compute_ratio(starting_indexes, close_price, exit)?;
|
||||
self.percentiles.compute(
|
||||
|
||||
@@ -67,9 +67,9 @@ impl RatioSma {
|
||||
|
||||
// Rolling SMAs
|
||||
for (sma, lookback) in [
|
||||
(&mut self._1w, &blocks.lookback._1w),
|
||||
(&mut self._1m, &blocks.lookback._1m),
|
||||
(&mut self._1y, &blocks.lookback._1y),
|
||||
(&mut self._1w, &blocks.lookback._1w.inner),
|
||||
(&mut self._1m, &blocks.lookback._1m.inner),
|
||||
(&mut self._1y, &blocks.lookback._1y.inner),
|
||||
(&mut self._2y, &blocks.lookback._2y),
|
||||
(&mut self._4y, &blocks.lookback._4y),
|
||||
] {
|
||||
|
||||
@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredF32, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{DeltaAvg, LazyDeltaVec, ReadableCloneableVec};
|
||||
use vecdb::{DeltaAvg, LazyDeltaVec, ReadOnlyClone, ReadableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, NumericValue, Resolutions, Windows},
|
||||
internal::{NumericValue, Resolutions, WindowStartVec, Windows},
|
||||
};
|
||||
|
||||
use super::LazyRollingAvgFromHeight;
|
||||
@@ -30,25 +30,25 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
cumulative: &(impl ReadableCloneableVec<Height, T> + 'static),
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let cum_source = cumulative.read_only_boxed_clone();
|
||||
|
||||
Self(cached_starts.0.map_with_suffix(|suffix, cached_start| {
|
||||
Self(cached_starts.map_with_suffix(|suffix, cached_start| {
|
||||
let full_name = format!("{name}_{suffix}");
|
||||
let cached = cached_start.clone();
|
||||
let cached = cached_start.read_only_clone();
|
||||
let starts_version = cached.version();
|
||||
let avg = LazyDeltaVec::<Height, T, StoredF32, DeltaAvg>::new(
|
||||
&full_name,
|
||||
version,
|
||||
cum_source.clone(),
|
||||
starts_version,
|
||||
move || cached.get(),
|
||||
move || cached.cached(),
|
||||
);
|
||||
let resolutions = Resolutions::forced_import(
|
||||
&full_name,
|
||||
avg.read_only_boxed_clone(),
|
||||
avg.clone(),
|
||||
version,
|
||||
indexes,
|
||||
);
|
||||
|
||||
@@ -10,8 +10,8 @@ use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, LazyRollingAvgsFromHeight, LazyRollingSumsFromHeight, NumericValue,
|
||||
RollingDistribution, WindowStarts,
|
||||
LazyRollingAvgsFromHeight, LazyRollingSumsFromHeight, NumericValue, RollingDistribution,
|
||||
WindowStartVec, WindowStarts, Windows,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ where
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cumulative: &(impl ReadableCloneableVec<Height, T> + 'static),
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
) -> Result<Self> {
|
||||
let sum = LazyRollingSumsFromHeight::new(
|
||||
&format!("{name}_sum"),
|
||||
|
||||
@@ -2,13 +2,16 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Height, StoredF32, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{DeltaChange, DeltaRate, LazyDeltaVec, LazyVecFrom1, ReadableCloneableVec, VecValue};
|
||||
use vecdb::{
|
||||
DeltaChange, DeltaRate, LazyDeltaVec, LazyVecFrom1, ReadOnlyClone, ReadableCloneableVec,
|
||||
VecValue,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
BpsType, CachedWindowStarts, CentsType, DerivedResolutions, LazyPerBlock, NumericValue,
|
||||
Percent, Resolutions, Windows,
|
||||
BpsType, CentsType, DerivedResolutions, LazyPerBlock, NumericValue, Percent, Resolutions,
|
||||
WindowStartVec, Windows,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -68,14 +71,14 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &(impl ReadableCloneableVec<Height, S> + 'static),
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let src = source.read_only_boxed_clone();
|
||||
|
||||
let make_slot = |suffix: &str, cached_start: &vecdb::CachedVec<Height, Height>| {
|
||||
let make_slot = |suffix: &str, cached_start: &&WindowStartVec| {
|
||||
let full_name = format!("{name}_{suffix}");
|
||||
let cached = cached_start.clone();
|
||||
let cached = cached_start.read_only_clone();
|
||||
let starts_version = cached.version();
|
||||
|
||||
// Absolute change: source[h] - source[ago] as C (via f64)
|
||||
@@ -86,15 +89,11 @@ where
|
||||
starts_version,
|
||||
{
|
||||
let cached = cached.clone();
|
||||
move || cached.get()
|
||||
move || cached.cached()
|
||||
},
|
||||
);
|
||||
let change_resolutions = Resolutions::forced_import(
|
||||
&full_name,
|
||||
change_vec.read_only_boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
);
|
||||
let change_resolutions =
|
||||
Resolutions::forced_import(&full_name, change_vec.clone(), version, indexes);
|
||||
let absolute = LazyDeltaFromHeight {
|
||||
height: change_vec,
|
||||
resolutions: Box::new(change_resolutions),
|
||||
@@ -107,14 +106,10 @@ where
|
||||
version,
|
||||
src.clone(),
|
||||
starts_version,
|
||||
move || cached.get(),
|
||||
);
|
||||
let rate_resolutions = Resolutions::forced_import(
|
||||
&rate_bps_name,
|
||||
rate_vec.read_only_boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
move || cached.cached(),
|
||||
);
|
||||
let rate_resolutions =
|
||||
Resolutions::forced_import(&rate_bps_name, rate_vec.clone(), version, indexes);
|
||||
let bps = LazyDeltaFromHeight {
|
||||
height: rate_vec,
|
||||
resolutions: Box::new(rate_resolutions),
|
||||
@@ -159,7 +154,7 @@ where
|
||||
(absolute, rate)
|
||||
};
|
||||
|
||||
let (absolute, rate) = cached_starts.0.map_with_suffix(make_slot).unzip();
|
||||
let (absolute, rate) = cached_starts.map_with_suffix(make_slot).unzip();
|
||||
|
||||
Self { absolute, rate }
|
||||
}
|
||||
@@ -206,14 +201,14 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &(impl ReadableCloneableVec<Height, S> + 'static),
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let src = source.read_only_boxed_clone();
|
||||
|
||||
let make_slot = |suffix: &str, cached_start: &vecdb::CachedVec<Height, Height>| {
|
||||
let make_slot = |suffix: &str, cached_start: &&WindowStartVec| {
|
||||
let full_name = format!("{name}_{suffix}");
|
||||
let cached = cached_start.clone();
|
||||
let cached = cached_start.read_only_clone();
|
||||
let starts_version = cached.version();
|
||||
|
||||
// Absolute change (cents): source[h] - source[ago] as C (via f64)
|
||||
@@ -225,12 +220,12 @@ where
|
||||
starts_version,
|
||||
{
|
||||
let cached = cached.clone();
|
||||
move || cached.get()
|
||||
move || cached.cached()
|
||||
},
|
||||
);
|
||||
let change_resolutions = Resolutions::forced_import(
|
||||
¢s_name,
|
||||
change_vec.read_only_boxed_clone(),
|
||||
change_vec.clone(),
|
||||
version,
|
||||
indexes,
|
||||
);
|
||||
@@ -262,14 +257,10 @@ where
|
||||
version,
|
||||
src.clone(),
|
||||
starts_version,
|
||||
move || cached.get(),
|
||||
);
|
||||
let rate_resolutions = Resolutions::forced_import(
|
||||
&rate_bps_name,
|
||||
rate_vec.read_only_boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
move || cached.cached(),
|
||||
);
|
||||
let rate_resolutions =
|
||||
Resolutions::forced_import(&rate_bps_name, rate_vec.clone(), version, indexes);
|
||||
let bps = LazyDeltaFromHeight {
|
||||
height: rate_vec,
|
||||
resolutions: Box::new(rate_resolutions),
|
||||
@@ -312,7 +303,7 @@ where
|
||||
(absolute, rate)
|
||||
};
|
||||
|
||||
let (absolute, rate) = cached_starts.0.map_with_suffix(make_slot).unzip();
|
||||
let (absolute, rate) = cached_starts.map_with_suffix(make_slot).unzip();
|
||||
|
||||
Self { absolute, rate }
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ use vecdb::{ReadableCloneableVec, UnaryTransform};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, ComputedVecValue, LazyRollingAvgsFromHeight, LazyRollingDistribution,
|
||||
LazyRollingSumsFromHeight, NumericValue, RollingComplete,
|
||||
ComputedVecValue, LazyRollingAvgsFromHeight, LazyRollingDistribution,
|
||||
LazyRollingSumsFromHeight, NumericValue, RollingComplete, WindowStartVec, Windows,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ where
|
||||
version: Version,
|
||||
cumulative: &(impl ReadableCloneableVec<Height, T> + 'static),
|
||||
source: &RollingComplete<S1T>,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let sum = LazyRollingSumsFromHeight::new(
|
||||
|
||||
@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{DeltaSub, LazyDeltaVec, ReadableCloneableVec};
|
||||
use vecdb::{DeltaSub, LazyDeltaVec, ReadOnlyClone, ReadableCloneableVec};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, NumericValue, Resolutions, Windows},
|
||||
internal::{NumericValue, Resolutions, WindowStartVec, Windows},
|
||||
};
|
||||
|
||||
use super::LazyRollingSumFromHeight;
|
||||
@@ -33,28 +33,23 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
cumulative: &(impl ReadableCloneableVec<Height, T> + 'static),
|
||||
cached_starts: &CachedWindowStarts,
|
||||
cached_starts: &Windows<&WindowStartVec>,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Self {
|
||||
let cum_source = cumulative.read_only_boxed_clone();
|
||||
|
||||
Self(cached_starts.0.map_with_suffix(|suffix, cached_start| {
|
||||
Self(cached_starts.map_with_suffix(|suffix, cached_start| {
|
||||
let full_name = format!("{name}_{suffix}");
|
||||
let cached = cached_start.clone();
|
||||
let cached = cached_start.read_only_clone();
|
||||
let starts_version = cached.version();
|
||||
let sum = LazyDeltaVec::<Height, T, T, DeltaSub>::new(
|
||||
&full_name,
|
||||
version,
|
||||
cum_source.clone(),
|
||||
starts_version,
|
||||
move || cached.get(),
|
||||
);
|
||||
let resolutions = Resolutions::forced_import(
|
||||
&full_name,
|
||||
sum.read_only_boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
move || cached.cached(),
|
||||
);
|
||||
let resolutions = Resolutions::forced_import(&full_name, sum.clone(), version, indexes);
|
||||
LazyRollingSumFromHeight {
|
||||
height: sum,
|
||||
resolutions: Box::new(resolutions),
|
||||
|
||||
@@ -18,10 +18,7 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
/// Cached window starts for lazy rolling computations.
|
||||
/// Clone-cheap (all fields are Arc-backed). Shared across all metrics.
|
||||
#[derive(Clone)]
|
||||
pub struct CachedWindowStarts(pub Windows<CachedVec<Height, Height>>);
|
||||
pub type WindowStartVec = CachedVec<EagerVec<PcoVec<Height, Height>>>;
|
||||
|
||||
/// Rolling window start heights — the 4 height-ago vecs (24h, 1w, 1m, 1y).
|
||||
pub type WindowStarts<'a> = Windows<&'a EagerVec<PcoVec<Height, Height>>>;
|
||||
|
||||
Reference in New Issue
Block a user