mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 14:49:58 -07:00
global: snapshot
This commit is contained in:
@@ -5,7 +5,7 @@ use brk_types::{Bitcoin, Dollars, Sats, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
use crate::internal::{LazyValueHeight, LazyValueHeightDerivedLast, ValueFromHeightLast};
|
||||
use crate::internal::{LazyValueFromHeight, LazyValueHeightDerivedLast, ValueFromHeightLast};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
@@ -14,7 +14,7 @@ const VERSION: Version = Version::ZERO;
|
||||
#[traversable(merge)]
|
||||
pub struct LazyValueFromHeightLast {
|
||||
#[traversable(flatten)]
|
||||
pub height: LazyValueHeight,
|
||||
pub height: LazyValueFromHeight,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
@@ -35,7 +35,7 @@ impl LazyValueFromHeightLast {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height =
|
||||
LazyValueHeight::from_block_source::<SatsTransform, BitcoinTransform, DollarsTransform>(name, source, v);
|
||||
LazyValueFromHeight::from_block_source::<SatsTransform, BitcoinTransform, DollarsTransform>(name, source, v);
|
||||
|
||||
let rest =
|
||||
LazyValueHeightDerivedLast::from_block_source::<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
@@ -1,13 +1,15 @@
|
||||
mod by_unit;
|
||||
mod constant;
|
||||
mod cumulative;
|
||||
mod cumulative_rolling_full;
|
||||
mod cumulative_rolling_sum;
|
||||
mod cumulative_full;
|
||||
mod cumulative_sum;
|
||||
mod distribution;
|
||||
mod full;
|
||||
mod last;
|
||||
mod lazy_computed_full;
|
||||
mod lazy_computed_value_cumulative;
|
||||
mod lazy_last;
|
||||
mod lazy_value_last;
|
||||
mod percentiles;
|
||||
mod price;
|
||||
mod ratio;
|
||||
@@ -18,20 +20,20 @@ mod value_ema;
|
||||
mod value_full;
|
||||
mod value_last;
|
||||
mod value_last_rolling;
|
||||
mod value_lazy_computed_cumulative;
|
||||
mod value_lazy_last;
|
||||
mod value_sum_cumulative;
|
||||
|
||||
pub use by_unit::*;
|
||||
pub use constant::*;
|
||||
pub use cumulative::*;
|
||||
pub use cumulative_rolling_full::*;
|
||||
pub use cumulative_rolling_sum::*;
|
||||
pub use cumulative_full::*;
|
||||
pub use cumulative_sum::*;
|
||||
pub use distribution::*;
|
||||
pub use full::*;
|
||||
pub use last::*;
|
||||
pub use lazy_computed_full::*;
|
||||
pub use lazy_computed_value_cumulative::*;
|
||||
pub use lazy_last::*;
|
||||
pub use lazy_value_last::*;
|
||||
pub use percentiles::*;
|
||||
pub use price::*;
|
||||
pub use ratio::*;
|
||||
@@ -42,6 +44,4 @@ pub use value_ema::*;
|
||||
pub use value_full::*;
|
||||
pub use value_last::*;
|
||||
pub use value_last_rolling::*;
|
||||
pub use value_lazy_computed_cumulative::*;
|
||||
pub use value_lazy_last::*;
|
||||
pub use value_sum_cumulative::*;
|
||||
@@ -12,13 +12,13 @@ const VERSION: Version = Version::ZERO;
|
||||
///
|
||||
/// All fields are lazy transforms from existing sources - no storage.
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyValueHeight {
|
||||
pub struct LazyValueFromHeight {
|
||||
pub sats: LazyVecFrom1<Height, Sats, Height, Sats>,
|
||||
pub btc: LazyVecFrom1<Height, Bitcoin, Height, Sats>,
|
||||
pub usd: LazyVecFrom1<Height, Dollars, Height, Dollars>,
|
||||
}
|
||||
|
||||
impl LazyValueHeight {
|
||||
impl LazyValueFromHeight {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
name: &str,
|
||||
source: &ValueFromHeightLast,
|
||||
@@ -1,9 +1,9 @@
|
||||
mod cumulative_full;
|
||||
mod last;
|
||||
mod lazy_last;
|
||||
mod value_lazy_last;
|
||||
mod lazy_value_last;
|
||||
|
||||
pub use cumulative_full::*;
|
||||
pub use last::*;
|
||||
pub use lazy_last::*;
|
||||
pub use value_lazy_last::*;
|
||||
pub use lazy_value_last::*;
|
||||
@@ -1,22 +1,34 @@
|
||||
mod compute;
|
||||
mod distribution_stats;
|
||||
mod eager_indexes;
|
||||
mod from_height;
|
||||
mod from_tx;
|
||||
mod group;
|
||||
mod height;
|
||||
mod height_derived;
|
||||
mod indexes;
|
||||
mod lazy_eager_indexes;
|
||||
mod multi;
|
||||
mod single;
|
||||
mod rolling;
|
||||
pub(crate) mod sliding_window;
|
||||
mod traits;
|
||||
mod transform;
|
||||
mod tx_derived;
|
||||
mod vec;
|
||||
mod windows;
|
||||
|
||||
pub(crate) use compute::*;
|
||||
pub(crate) use distribution_stats::*;
|
||||
pub(crate) use eager_indexes::*;
|
||||
pub(crate) use from_height::*;
|
||||
pub(crate) use from_tx::*;
|
||||
pub(crate) use group::*;
|
||||
pub(crate) use height::*;
|
||||
pub(crate) use height_derived::*;
|
||||
pub(crate) use indexes::*;
|
||||
pub(crate) use lazy_eager_indexes::*;
|
||||
pub(crate) use multi::*;
|
||||
pub(crate) use single::*;
|
||||
pub(crate) use rolling::*;
|
||||
pub(crate) use traits::*;
|
||||
pub use transform::*;
|
||||
pub(crate) use tx_derived::*;
|
||||
pub(crate) use vec::*;
|
||||
pub(crate) use windows::*;
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
//! Multi-index composite types.
|
||||
|
||||
mod from_height;
|
||||
mod from_tx;
|
||||
mod height_derived;
|
||||
mod tx_derived;
|
||||
|
||||
pub use from_height::*;
|
||||
pub use from_tx::*;
|
||||
pub use height_derived::*;
|
||||
pub use tx_derived::*;
|
||||
@@ -1,10 +1,8 @@
|
||||
mod block_windows;
|
||||
mod distribution;
|
||||
mod full;
|
||||
mod value_windows;
|
||||
mod windows;
|
||||
|
||||
pub use block_windows::*;
|
||||
pub use distribution::*;
|
||||
pub use full::*;
|
||||
pub use value_windows::*;
|
||||
@@ -1,11 +0,0 @@
|
||||
//! Single-index types and primitives.
|
||||
|
||||
mod group;
|
||||
mod height;
|
||||
mod rolling;
|
||||
mod vec;
|
||||
|
||||
pub use group::*;
|
||||
pub use height::*;
|
||||
pub use rolling::*;
|
||||
pub use vec::*;
|
||||
@@ -1,34 +0,0 @@
|
||||
//! Block-count-based rolling distribution — 6-block window.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::Height;
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, Rw, StorageMode, Version};
|
||||
|
||||
use crate::internal::{ComputedVecValue, Distribution, NumericValue};
|
||||
|
||||
/// Single 6-block rolling window distribution with 8 distribution stat vecs.
|
||||
#[derive(Traversable)]
|
||||
pub struct BlockRollingDistribution<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
#[traversable(rename = "6b")]
|
||||
pub _6b: Distribution<Height, T, M>,
|
||||
}
|
||||
|
||||
impl<T> BlockRollingDistribution<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
_6b: Distribution::forced_import(db, &format!("{name}_6b"), version)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,34 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode, Version};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
internal::{
|
||||
BlockRollingDistribution, ComputedVecValue, Distribution, NumericValue,
|
||||
},
|
||||
internal::{ComputedVecValue, Distribution, NumericValue},
|
||||
};
|
||||
|
||||
/// 6-block rolling window distribution with 8 distribution stat vecs.
|
||||
#[derive(Traversable)]
|
||||
pub struct BlockRollingDistribution<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
#[traversable(rename = "6b")]
|
||||
pub _6b: Distribution<Height, T, M>,
|
||||
}
|
||||
|
||||
impl<T> BlockRollingDistribution<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
_6b: Distribution::forced_import(db, &format!("{name}_6b"), version)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct TxDerivedDistribution<T, M: StorageMode = Rw>
|
||||
where
|
||||
Reference in New Issue
Block a user