mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 14:49:58 -07:00
global: snapshot
This commit is contained in:
85
crates/brk_computer/src/internal/containers/constant.rs
Normal file
85
crates/brk_computer/src/internal/containers/constant.rs
Normal file
@@ -0,0 +1,85 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30,
|
||||
Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use vecdb::{Formattable, LazyVecFrom1, ReadableCloneableVec, UnaryTransform, VecValue};
|
||||
|
||||
use crate::indexes;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ConstantVecs<T>
|
||||
where
|
||||
T: VecValue + Formattable + Serialize + JsonSchema,
|
||||
{
|
||||
pub height: LazyVecFrom1<Height, T, Height, Height>,
|
||||
pub minute10: LazyVecFrom1<Minute10, T, Minute10, Minute10>,
|
||||
pub minute30: LazyVecFrom1<Minute30, T, Minute30, Minute30>,
|
||||
pub hour1: LazyVecFrom1<Hour1, T, Hour1, Hour1>,
|
||||
pub hour4: LazyVecFrom1<Hour4, T, Hour4, Hour4>,
|
||||
pub hour12: LazyVecFrom1<Hour12, T, Hour12, Hour12>,
|
||||
pub day1: LazyVecFrom1<Day1, T, Day1, Day1>,
|
||||
pub day3: LazyVecFrom1<Day3, T, Day3, Day3>,
|
||||
pub week1: LazyVecFrom1<Week1, T, Week1, Week1>,
|
||||
pub month1: LazyVecFrom1<Month1, T, Month1, Month1>,
|
||||
pub month3: LazyVecFrom1<Month3, T, Month3, Month3>,
|
||||
pub month6: LazyVecFrom1<Month6, T, Month6, Month6>,
|
||||
pub year1: LazyVecFrom1<Year1, T, Year1, Year1>,
|
||||
pub year10: LazyVecFrom1<Year10, T, Year10, Year10>,
|
||||
pub halving: LazyVecFrom1<Halving, T, Halving, Halving>,
|
||||
pub epoch: LazyVecFrom1<Epoch, T, Epoch, Epoch>,
|
||||
}
|
||||
|
||||
impl<T: VecValue + Formattable + Serialize + JsonSchema> ConstantVecs<T> {
|
||||
pub(crate) fn new<F>(name: &str, version: Version, indexes: &indexes::Vecs) -> Self
|
||||
where
|
||||
F: UnaryTransform<Height, T>
|
||||
+ UnaryTransform<Minute10, T>
|
||||
+ UnaryTransform<Minute30, T>
|
||||
+ UnaryTransform<Hour1, T>
|
||||
+ UnaryTransform<Hour4, T>
|
||||
+ UnaryTransform<Hour12, T>
|
||||
+ UnaryTransform<Day1, T>
|
||||
+ UnaryTransform<Day3, T>
|
||||
+ UnaryTransform<Week1, T>
|
||||
+ UnaryTransform<Month1, T>
|
||||
+ UnaryTransform<Month3, T>
|
||||
+ UnaryTransform<Month6, T>
|
||||
+ UnaryTransform<Year1, T>
|
||||
+ UnaryTransform<Year10, T>
|
||||
+ UnaryTransform<Halving, T>
|
||||
+ UnaryTransform<Epoch, T>,
|
||||
{
|
||||
macro_rules! period {
|
||||
($idx:ident) => {
|
||||
LazyVecFrom1::transformed::<F>(
|
||||
name,
|
||||
version,
|
||||
indexes.$idx.identity.read_only_boxed_clone(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
Self {
|
||||
height: period!(height),
|
||||
minute10: period!(minute10),
|
||||
minute30: period!(minute30),
|
||||
hour1: period!(hour1),
|
||||
hour4: period!(hour4),
|
||||
hour12: period!(hour12),
|
||||
day1: period!(day1),
|
||||
day3: period!(day3),
|
||||
week1: period!(week1),
|
||||
month1: period!(month1),
|
||||
month3: period!(month3),
|
||||
month6: period!(month6),
|
||||
year1: period!(year1),
|
||||
year10: period!(year10),
|
||||
halving: period!(halving),
|
||||
epoch: period!(epoch),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
mod constant;
|
||||
mod distribution_stats;
|
||||
mod per_resolution;
|
||||
mod window_24h;
|
||||
mod windows;
|
||||
mod windows_from_1w;
|
||||
|
||||
pub use constant::*;
|
||||
pub use distribution_stats::*;
|
||||
pub use per_resolution::*;
|
||||
pub use window_24h::*;
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::Height;
|
||||
use vecdb::CachedVec;
|
||||
|
||||
/// 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>>);
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Windows<A> {
|
||||
|
||||
Reference in New Issue
Block a user