mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-12 19:48:15 -07:00
global: snapshot
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Emas1w1m<A> {
|
||||
#[traversable(rename = "1w")]
|
||||
pub _1w: A,
|
||||
#[traversable(rename = "1m")]
|
||||
pub _1m: A,
|
||||
}
|
||||
|
||||
impl<A> Emas1w1m<A> {
|
||||
pub const SUFFIXES: [&'static str; 2] = ["ema_1w", "ema_1m"];
|
||||
|
||||
pub fn try_from_fn<E>(
|
||||
mut f: impl FnMut(&str) -> std::result::Result<A, E>,
|
||||
) -> std::result::Result<Self, E> {
|
||||
Ok(Self {
|
||||
_1w: f(Self::SUFFIXES[0])?,
|
||||
_1m: f(Self::SUFFIXES[1])?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn as_array(&self) -> [&A; 2] {
|
||||
[&self._1w, &self._1m]
|
||||
}
|
||||
|
||||
pub fn as_mut_array(&mut self) -> [&mut A; 2] {
|
||||
[&mut self._1w, &mut self._1m]
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
mod distribution_stats;
|
||||
mod emas;
|
||||
mod per_period;
|
||||
mod windows;
|
||||
|
||||
pub use distribution_stats::*;
|
||||
pub use emas::*;
|
||||
pub use per_period::*;
|
||||
pub use windows::*;
|
||||
|
||||
@@ -66,27 +66,4 @@ impl ValueFromHeight {
|
||||
.compute_rolling_sum(max_from, window_starts, cents_source, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn compute_ema(
|
||||
&mut self,
|
||||
starting_height: Height,
|
||||
window_starts: &impl ReadableVec<Height, Height>,
|
||||
sats_source: &impl ReadableVec<Height, Sats>,
|
||||
cents_source: &(impl ReadableVec<Height, Cents> + Sync),
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.base.sats.height.compute_rolling_ema(
|
||||
starting_height,
|
||||
window_starts,
|
||||
sats_source,
|
||||
exit,
|
||||
)?;
|
||||
self.base.cents.height.compute_rolling_ema(
|
||||
starting_height,
|
||||
window_starts,
|
||||
cents_source,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
mod _1w_1m;
|
||||
mod _2w;
|
||||
mod percent_1w_1m;
|
||||
|
||||
pub use _1w_1m::*;
|
||||
pub use _2w::*;
|
||||
pub use percent_1w_1m::*;
|
||||
@@ -1,54 +0,0 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{BpsType, Emas1w1m, PercentFromHeight},
|
||||
};
|
||||
|
||||
/// 2 EMA vecs (1w, 1m) sourced from 24h rolling window,
|
||||
/// each storing basis points with lazy ratio and percent float views.
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct PercentRollingEmas1w1m<B: BpsType, M: StorageMode = Rw>(
|
||||
pub Emas1w1m<PercentFromHeight<B, M>>,
|
||||
);
|
||||
|
||||
impl<B: BpsType> PercentRollingEmas1w1m<B> {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self(Emas1w1m::try_from_fn(|suffix| {
|
||||
PercentFromHeight::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||
})?))
|
||||
}
|
||||
|
||||
pub(crate) fn compute_from_24h(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
height_1w_ago: &impl ReadableVec<Height, Height>,
|
||||
height_1m_ago: &impl ReadableVec<Height, Height>,
|
||||
source: &impl ReadableVec<Height, B>,
|
||||
exit: &Exit,
|
||||
) -> Result<()>
|
||||
where
|
||||
f64: From<B>,
|
||||
B: From<f64> + Default,
|
||||
{
|
||||
self._1w
|
||||
.bps
|
||||
.height
|
||||
.compute_rolling_ema(max_from, height_1w_ago, source, exit)?;
|
||||
self._1m
|
||||
.bps
|
||||
.height
|
||||
.compute_rolling_ema(max_from, height_1m_ago, source, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
mod distribution;
|
||||
mod emas;
|
||||
mod full;
|
||||
mod percent_windows;
|
||||
mod value_windows;
|
||||
mod windows;
|
||||
|
||||
pub use distribution::*;
|
||||
pub use emas::*;
|
||||
pub use full::*;
|
||||
pub use percent_windows::*;
|
||||
pub use value_windows::*;
|
||||
|
||||
Reference in New Issue
Block a user