mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-31 12:43:06 -07:00
computer: indexes + rolling
This commit is contained in:
@@ -158,28 +158,16 @@ impl Vecs {
|
||||
)?;
|
||||
|
||||
// Compute rolling window block counts
|
||||
self.block_count_24h_sum.height.compute_transform(
|
||||
let ws = crate::internal::WindowStarts {
|
||||
_24h: &self.height_24h_ago,
|
||||
_7d: &self.height_1w_ago,
|
||||
_30d: &self.height_1m_ago,
|
||||
_1y: &self.height_1y_ago,
|
||||
};
|
||||
self.block_count_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&self.height_24h_ago,
|
||||
|(h, start, ..)| (h, StoredU32::from(*h + 1 - *start)),
|
||||
exit,
|
||||
)?;
|
||||
self.block_count_1w_sum.height.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.height_1w_ago,
|
||||
|(h, start, ..)| (h, StoredU32::from(*h + 1 - *start)),
|
||||
exit,
|
||||
)?;
|
||||
self.block_count_1m_sum.height.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.height_1m_ago,
|
||||
|(h, start, ..)| (h, StoredU32::from(*h + 1 - *start)),
|
||||
exit,
|
||||
)?;
|
||||
self.block_count_1y_sum.height.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.height_1y_ago,
|
||||
|(h, start, ..)| (h, StoredU32::from(*h + 1 - *start)),
|
||||
&ws,
|
||||
&self.block_count.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{Database, ImportableVec};
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{BlockCountTarget, ComputedFromHeightLast, ComputedFromHeightSumCum, ConstantVecs},
|
||||
internal::{BlockCountTarget, ComputedFromHeightSumCum, ConstantVecs, RollingWindows},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -52,27 +52,9 @@ impl Vecs {
|
||||
height_6y_ago: ImportableVec::forced_import(db, "height_6y_ago", version)?,
|
||||
height_8y_ago: ImportableVec::forced_import(db, "height_8y_ago", version)?,
|
||||
height_10y_ago: ImportableVec::forced_import(db, "height_10y_ago", version)?,
|
||||
block_count_24h_sum: ComputedFromHeightLast::forced_import(
|
||||
block_count_sum: RollingWindows::forced_import(
|
||||
db,
|
||||
"block_count_24h_sum",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
block_count_1w_sum: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"block_count_1w_sum",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
block_count_1m_sum: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"block_count_1m_sum",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
block_count_1y_sum: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"block_count_1y_sum",
|
||||
"block_count_sum",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredU32, StoredU64};
|
||||
use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, ComputedFromHeightSumCum, ConstantVecs};
|
||||
use crate::internal::{ComputedFromHeightSumCum, ConstantVecs, RollingWindows, WindowStarts};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
@@ -40,13 +40,20 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub height_8y_ago: M::Stored<EagerVec<PcoVec<Height, Height>>>,
|
||||
pub height_10y_ago: M::Stored<EagerVec<PcoVec<Height, Height>>>,
|
||||
// Rolling window block counts
|
||||
pub block_count_24h_sum: ComputedFromHeightLast<StoredU32, M>,
|
||||
pub block_count_1w_sum: ComputedFromHeightLast<StoredU32, M>,
|
||||
pub block_count_1m_sum: ComputedFromHeightLast<StoredU32, M>,
|
||||
pub block_count_1y_sum: ComputedFromHeightLast<StoredU32, M>,
|
||||
pub block_count_sum: RollingWindows<StoredU32, M>,
|
||||
}
|
||||
|
||||
impl Vecs {
|
||||
/// Get the standard 4 rolling window start heights (24h, 7d, 30d, 1y).
|
||||
pub fn window_starts(&self) -> WindowStarts<'_> {
|
||||
WindowStarts {
|
||||
_24h: &self.height_24h_ago,
|
||||
_7d: &self.height_1w_ago,
|
||||
_30d: &self.height_1m_ago,
|
||||
_1y: &self.height_1y_ago,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_vec(&self, days: usize) -> &EagerVec<PcoVec<Height, Height>> {
|
||||
match days {
|
||||
1 => &self.height_24h_ago,
|
||||
|
||||
Reference in New Issue
Block a user