global: snapshot

This commit is contained in:
nym21
2026-03-03 00:23:19 +01:00
parent 0628f08e6b
commit 35df8d99dc
14 changed files with 224 additions and 754 deletions
@@ -92,12 +92,9 @@ impl RollingFullByUnit {
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
Ok(Self(Windows {
_24h: RollingFullSlot::forced_import(db, &format!("{name}_24h"), v, indexes)?,
_7d: RollingFullSlot::forced_import(db, &format!("{name}_7d"), v, indexes)?,
_30d: RollingFullSlot::forced_import(db, &format!("{name}_30d"), v, indexes)?,
_1y: RollingFullSlot::forced_import(db, &format!("{name}_1y"), v, indexes)?,
}))
Ok(Self(Windows::try_from_fn(|suffix| {
RollingFullSlot::forced_import(db, &format!("{name}_{suffix}"), v, indexes)
})?))
}
pub(crate) fn compute(
@@ -109,7 +106,7 @@ impl RollingFullByUnit {
exit: &Exit,
) -> Result<()> {
for (slot, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
slot.compute(max_from, starts, sats_source, cents_source, exit)?;
slot.compute(max_from, *starts, sats_source, cents_source, exit)?;
}
Ok(())
}
@@ -38,8 +38,8 @@ impl RollingSumByUnit {
exit: &Exit,
) -> Result<()> {
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
w.sats.height.compute_rolling_sum(max_from, starts, sats_source, exit)?;
w.cents.height.compute_rolling_sum(max_from, starts, cents_source, exit)?;
w.sats.height.compute_rolling_sum(max_from, *starts, sats_source, exit)?;
w.cents.height.compute_rolling_sum(max_from, *starts, cents_source, exit)?;
}
Ok(())
}
@@ -14,11 +14,8 @@ impl Windows<ByUnit> {
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
_24h: ByUnit::forced_import(db, &format!("{name}_24h"), version, indexes)?,
_7d: ByUnit::forced_import(db, &format!("{name}_7d"), version, indexes)?,
_30d: ByUnit::forced_import(db, &format!("{name}_30d"), version, indexes)?,
_1y: ByUnit::forced_import(db, &format!("{name}_1y"), version, indexes)?,
Windows::try_from_fn(|suffix| {
ByUnit::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
})
}
}
@@ -36,32 +36,9 @@ impl ValueFromHeightWindows {
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
Ok(Self(Windows {
_24h: ValueFromHeight::forced_import(
db,
&format!("{name}_24h"),
v,
indexes,
)?,
_7d: ValueFromHeight::forced_import(
db,
&format!("{name}_7d"),
v,
indexes,
)?,
_30d: ValueFromHeight::forced_import(
db,
&format!("{name}_30d"),
v,
indexes,
)?,
_1y: ValueFromHeight::forced_import(
db,
&format!("{name}_1y"),
v,
indexes,
)?,
}))
Ok(Self(Windows::try_from_fn(|suffix| {
ValueFromHeight::forced_import(db, &format!("{name}_{suffix}"), v, indexes)
})?))
}
pub(crate) fn compute_rolling_sum(
@@ -73,7 +50,7 @@ impl ValueFromHeightWindows {
exit: &Exit,
) -> Result<()> {
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
w.compute_rolling_sum(max_from, starts, sats_source, cents_source, exit)?;
w.compute_rolling_sum(max_from, *starts, sats_source, cents_source, exit)?;
}
Ok(())
}
@@ -18,19 +18,8 @@ use crate::{
internal::{ComputedFromHeight, ComputedVecValue, NumericValue, Windows},
};
/// Rolling window start heights — references to the 4 height-ago vecs.
pub struct WindowStarts<'a> {
pub _24h: &'a EagerVec<PcoVec<Height, Height>>,
pub _7d: &'a EagerVec<PcoVec<Height, Height>>,
pub _30d: &'a EagerVec<PcoVec<Height, Height>>,
pub _1y: &'a EagerVec<PcoVec<Height, Height>>,
}
impl<'a> WindowStarts<'a> {
pub fn as_array(&self) -> [&'a EagerVec<PcoVec<Height, Height>>; 4] {
[self._24h, self._7d, self._30d, self._1y]
}
}
/// Rolling window start heights — the 4 height-ago vecs (24h, 7d, 30d, 1y).
pub type WindowStarts<'a> = Windows<&'a EagerVec<PcoVec<Height, Height>>>;
/// 4 rolling window vecs (24h, 7d, 30d, 1y), each with height data + all 17 index views.
#[derive(Deref, DerefMut, Traversable)]
@@ -52,12 +41,9 @@ where
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
Ok(Self(Windows {
_24h: ComputedFromHeight::forced_import(db, &format!("{name}_24h"), v, indexes)?,
_7d: ComputedFromHeight::forced_import(db, &format!("{name}_7d"), v, indexes)?,
_30d: ComputedFromHeight::forced_import(db, &format!("{name}_30d"), v, indexes)?,
_1y: ComputedFromHeight::forced_import(db, &format!("{name}_1y"), v, indexes)?,
}))
Ok(Self(Windows::try_from_fn(|suffix| {
ComputedFromHeight::forced_import(db, &format!("{name}_{suffix}"), v, indexes)
})?))
}
pub(crate) fn compute_rolling_sum(
@@ -71,7 +57,7 @@ where
T: Default + SubAssign,
{
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
w.height.compute_rolling_sum(max_from, starts, source, exit)?;
w.height.compute_rolling_sum(max_from, *starts, source, exit)?;
}
Ok(())
}
@@ -17,6 +17,23 @@ pub struct Windows<A, B = A, C = A, D = A> {
}
impl<A> Windows<A> {
pub const SUFFIXES: [&'static str; 4] = ["24h", "7d", "30d", "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])?,
_7d: f(Self::SUFFIXES[1])?,
_30d: f(Self::SUFFIXES[2])?,
_1y: f(Self::SUFFIXES[3])?,
})
}
pub fn as_array(&self) -> [&A; 4] {
[&self._24h, &self._7d, &self._30d, &self._1y]
}
pub fn as_mut_array(&mut self) -> [&mut A; 4] {
[&mut self._24h, &mut self._7d, &mut self._30d, &mut self._1y]
}