global: big snapshot

This commit is contained in:
nym21
2026-03-13 12:47:01 +01:00
parent c83955eea7
commit 2b31c7f6b7
158 changed files with 4961 additions and 6939 deletions

View File

@@ -2,12 +2,10 @@ mod distribution_stats;
mod per_resolution;
mod window_24h;
mod windows;
mod windows_except_1m;
mod windows_from_1w;
pub use distribution_stats::*;
pub use per_resolution::*;
pub use window_24h::*;
pub use windows::*;
pub use windows_except_1m::*;
pub use windows_from_1w::*;

View File

@@ -1,4 +1,11 @@
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> {
@@ -33,4 +40,32 @@ impl<A> Windows<A> {
pub fn as_mut_array_from_1w(&mut self) -> [&mut A; 3] {
[&mut self._1w, &mut self._1m, &mut self._1y]
}
pub fn map_with_suffix<B>(&self, mut f: impl FnMut(&str, &A) -> B) -> Windows<B> {
Windows {
_24h: f(Self::SUFFIXES[0], &self._24h),
_1w: f(Self::SUFFIXES[1], &self._1w),
_1m: f(Self::SUFFIXES[2], &self._1m),
_1y: f(Self::SUFFIXES[3], &self._1y),
}
}
}
impl<A, B> Windows<(A, B)> {
pub fn unzip(self) -> (Windows<A>, Windows<B>) {
(
Windows {
_24h: self._24h.0,
_1w: self._1w.0,
_1m: self._1m.0,
_1y: self._1y.0,
},
Windows {
_24h: self._24h.1,
_1w: self._1w.1,
_1m: self._1m.1,
_1y: self._1y.1,
},
)
}
}

View File

@@ -1,30 +0,0 @@
use brk_traversable::Traversable;
#[derive(Clone, Traversable)]
pub struct WindowsExcept1m<A> {
pub _24h: A,
pub _1w: A,
pub _1y: A,
}
impl<A> WindowsExcept1m<A> {
pub const SUFFIXES: [&'static str; 3] = ["24h", "1w", "1y"];
pub fn try_from_fn<E>(
mut f: impl FnMut(&str) -> std::result::Result<A, E>,
) -> std::result::Result<Self, E> {
Ok(Self {
_24h: f(Self::SUFFIXES[0])?,
_1w: f(Self::SUFFIXES[1])?,
_1y: f(Self::SUFFIXES[2])?,
})
}
pub fn as_array(&self) -> [&A; 3] {
[&self._24h, &self._1w, &self._1y]
}
pub fn as_mut_array(&mut self) -> [&mut A; 3] {
[&mut self._24h, &mut self._1w, &mut self._1y]
}
}