mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-05 19:59:09 -07:00
global: big snapshot
This commit is contained in:
@@ -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::*;
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user