mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-12 11:38:13 -07:00
global: fmt
This commit is contained in:
@@ -146,5 +146,4 @@ mod tests {
|
||||
assert_eq!(ep.count(), 0);
|
||||
assert_eq!(quantile(&ep, 0.5), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -137,8 +137,7 @@ where
|
||||
} else {
|
||||
min_out.push(T::from(window.min()));
|
||||
max_out.push(T::from(window.max()));
|
||||
let [p10, p25, p50, p75, p90] =
|
||||
window.percentiles(&[0.10, 0.25, 0.50, 0.75, 0.90]);
|
||||
let [p10, p25, p50, p75, p90] = window.percentiles(&[0.10, 0.25, 0.50, 0.75, 0.90]);
|
||||
p10_out.push(T::from(p10));
|
||||
p25_out.push(T::from(p25));
|
||||
median_out.push(T::from(p50));
|
||||
@@ -165,13 +164,7 @@ where
|
||||
// Final flush
|
||||
let _lock = exit.lock();
|
||||
for v in [
|
||||
min_out,
|
||||
max_out,
|
||||
p10_out,
|
||||
p25_out,
|
||||
median_out,
|
||||
p75_out,
|
||||
p90_out,
|
||||
min_out, max_out, p10_out, p25_out, median_out, p75_out, p90_out,
|
||||
] {
|
||||
v.write()?;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30,
|
||||
Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3,
|
||||
Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
|
||||
@@ -12,9 +12,8 @@ pub struct DistributionStats<A> {
|
||||
}
|
||||
|
||||
impl<A> DistributionStats<A> {
|
||||
pub const SUFFIXES: [&'static str; 7] = [
|
||||
"min", "max", "pct10", "pct25", "median", "pct75", "pct90",
|
||||
];
|
||||
pub const SUFFIXES: [&'static str; 7] =
|
||||
["min", "max", "pct10", "pct25", "median", "pct75", "pct90"];
|
||||
|
||||
pub fn try_from_fn<E>(
|
||||
mut f: impl FnMut(&str) -> std::result::Result<A, E>,
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
mod constant;
|
||||
mod distribution_stats;
|
||||
mod per_resolution;
|
||||
mod percent;
|
||||
mod window_24h;
|
||||
mod windows;
|
||||
mod windows_from_1w;
|
||||
mod percent;
|
||||
mod windows_to_1m;
|
||||
|
||||
pub use constant::*;
|
||||
pub use distribution_stats::*;
|
||||
pub use percent::*;
|
||||
pub use per_resolution::*;
|
||||
pub use percent::*;
|
||||
pub use window_24h::*;
|
||||
pub use windows::*;
|
||||
pub use windows_from_1w::*;
|
||||
|
||||
@@ -2,8 +2,8 @@ use brk_error::Result;
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Indexes, Minute10,
|
||||
Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Indexes, Minute10, Minute30, Month1,
|
||||
Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, Epoch, Halving, Hour1, Hour4, Hour12, Minute10, Minute30, Month1,
|
||||
Month3, Month6, Version, Week1, Year1, Year10,
|
||||
Day1, Day3, Epoch, Halving, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3, Month6,
|
||||
Version, Week1, Year1, Year10,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
|
||||
@@ -3,17 +3,17 @@ mod amount;
|
||||
mod cache_budget;
|
||||
mod containers;
|
||||
pub(crate) mod db_utils;
|
||||
mod indexes;
|
||||
mod per_block;
|
||||
mod per_tx;
|
||||
mod indexes;
|
||||
mod traits;
|
||||
mod transform;
|
||||
|
||||
pub(crate) use amount::*;
|
||||
pub(crate) use cache_budget::*;
|
||||
pub(crate) use containers::*;
|
||||
pub(crate) use indexes::*;
|
||||
pub(crate) use per_block::*;
|
||||
pub(crate) use per_tx::*;
|
||||
pub(crate) use indexes::*;
|
||||
pub(crate) use traits::*;
|
||||
pub use transform::*;
|
||||
|
||||
@@ -5,9 +5,7 @@ use vecdb::{Database, Exit, ReadableCloneableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CentsUnsignedToDollars, PerBlock, LazyPerBlock, SatsToBitcoin, SatsToCents,
|
||||
},
|
||||
internal::{CentsUnsignedToDollars, LazyPerBlock, PerBlock, SatsToBitcoin, SatsToCents},
|
||||
prices,
|
||||
};
|
||||
|
||||
@@ -26,8 +24,7 @@ impl AmountPerBlock {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let sats =
|
||||
PerBlock::forced_import(db, &format!("{name}_sats"), version, indexes)?;
|
||||
let sats = PerBlock::forced_import(db, &format!("{name}_sats"), version, indexes)?;
|
||||
|
||||
let btc = LazyPerBlock::from_computed::<SatsToBitcoin>(
|
||||
name,
|
||||
@@ -36,8 +33,7 @@ impl AmountPerBlock {
|
||||
&sats,
|
||||
);
|
||||
|
||||
let cents =
|
||||
PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let cents = PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
|
||||
let usd = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||
&format!("{name}_usd"),
|
||||
@@ -68,6 +64,4 @@ impl AmountPerBlock {
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
|
||||
use vecdb::{Database, EagerVec, Exit, ImportableVec, LazyVecFrom1, PcoVec, ReadableCloneableVec, Rw, StorageMode};
|
||||
use vecdb::{
|
||||
Database, EagerVec, Exit, ImportableVec, LazyVecFrom1, PcoVec, ReadableCloneableVec, Rw,
|
||||
StorageMode,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
internal::{CentsUnsignedToDollars, SatsToBitcoin, SatsToCents},
|
||||
@@ -21,11 +24,8 @@ impl AmountBlock {
|
||||
pub(crate) fn forced_import(db: &Database, name: &str, version: Version) -> Result<Self> {
|
||||
let sats: EagerVec<PcoVec<Height, Sats>> =
|
||||
EagerVec::forced_import(db, &format!("{name}_sats"), version)?;
|
||||
let btc = LazyVecFrom1::transformed::<SatsToBitcoin>(
|
||||
name,
|
||||
version,
|
||||
sats.read_only_boxed_clone(),
|
||||
);
|
||||
let btc =
|
||||
LazyVecFrom1::transformed::<SatsToBitcoin>(name, version, sats.read_only_boxed_clone());
|
||||
let cents: EagerVec<PcoVec<Height, Cents>> =
|
||||
EagerVec::forced_import(db, &format!("{name}_cents"), version)?;
|
||||
let usd = LazyVecFrom1::transformed::<CentsUnsignedToDollars>(
|
||||
@@ -33,7 +33,12 @@ impl AmountBlock {
|
||||
version,
|
||||
cents.read_only_boxed_clone(),
|
||||
);
|
||||
Ok(Self { btc, sats, usd, cents })
|
||||
Ok(Self {
|
||||
btc,
|
||||
sats,
|
||||
usd,
|
||||
cents,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn compute_cents(
|
||||
|
||||
@@ -37,8 +37,7 @@ impl AmountPerBlockFull {
|
||||
|
||||
let inner =
|
||||
AmountPerBlockCumulativeRolling::forced_import(db, name, v, indexes, cached_starts)?;
|
||||
let distribution =
|
||||
RollingDistributionAmountPerBlock::forced_import(db, name, v, indexes)?;
|
||||
let distribution = RollingDistributionAmountPerBlock::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
inner,
|
||||
|
||||
@@ -5,7 +5,9 @@ use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
use crate::internal::{AmountPerBlock, Identity, LazyAmount, LazyAmountDerivedResolutions, SatsToBitcoin};
|
||||
use crate::internal::{
|
||||
AmountPerBlock, Identity, LazyAmount, LazyAmountDerivedResolutions, SatsToBitcoin,
|
||||
};
|
||||
|
||||
/// Lazy value wrapper with height + all derived last transforms from AmountPerBlock.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
|
||||
@@ -11,7 +11,7 @@ use vecdb::{
|
||||
|
||||
use crate::indexes;
|
||||
|
||||
use crate::internal::{Resolutions, ComputedVecValue, NumericValue};
|
||||
use crate::internal::{ComputedVecValue, NumericValue, Resolutions};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
@@ -38,12 +38,8 @@ where
|
||||
) -> Result<Self> {
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, version)?;
|
||||
|
||||
let resolutions = Resolutions::forced_import(
|
||||
name,
|
||||
height.read_only_boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
);
|
||||
let resolutions =
|
||||
Resolutions::forced_import(name, height.read_only_boxed_clone(), version, indexes);
|
||||
|
||||
Ok(Self {
|
||||
height,
|
||||
|
||||
@@ -63,8 +63,7 @@ impl<T: NumericValue + JsonSchema> PerBlockDistribution<T> {
|
||||
let pct75 = &mut pct75.height;
|
||||
let pct90 = &mut pct90.height;
|
||||
|
||||
let combined_version =
|
||||
source.version() + first_indexes.version() + count_indexes.version();
|
||||
let combined_version = source.version() + first_indexes.version() + count_indexes.version();
|
||||
|
||||
let mut index = max_from;
|
||||
for vec in [
|
||||
@@ -182,8 +181,7 @@ impl<T: NumericValue + JsonSchema> PerBlockDistribution<T> {
|
||||
let pct75 = &mut pct75.height;
|
||||
let pct90 = &mut pct90.height;
|
||||
|
||||
let combined_version =
|
||||
source.version() + first_indexes.version() + count_indexes.version();
|
||||
let combined_version = source.version() + first_indexes.version() + count_indexes.version();
|
||||
|
||||
let mut index = max_from;
|
||||
for vec in [
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::{Height, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{LazyVecFrom1, ReadableCloneableVec, UnaryTransform, VecIndex};
|
||||
|
||||
use crate::internal::{ComputedVecValue, PerBlockDistribution, DistributionStats};
|
||||
use crate::internal::{ComputedVecValue, DistributionStats, PerBlockDistribution};
|
||||
|
||||
/// Lazy analog of `Distribution<T>`: 7 `LazyVecFrom1` fields,
|
||||
/// each derived by transforming the corresponding field of a source `PerBlockDistribution<S1T>`.
|
||||
|
||||
@@ -6,8 +6,8 @@ use vecdb::{ReadableCloneableVec, UnaryTransform};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, PerBlockFull, ComputedVecValue, LazyPerBlock, LazyRollingComplete,
|
||||
NumericValue,
|
||||
CachedWindowStarts, ComputedVecValue, LazyPerBlock, LazyRollingComplete, NumericValue,
|
||||
PerBlockFull,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, PerBlock, NumericValue, RollingComplete, WindowStarts},
|
||||
internal::{CachedWindowStarts, NumericValue, PerBlock, RollingComplete, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
|
||||
@@ -7,9 +7,7 @@ use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
BpsType, CachedWindowStarts, PerBlock, LazyRollingDeltasFromHeight, NumericValue,
|
||||
},
|
||||
internal::{BpsType, CachedWindowStarts, LazyRollingDeltasFromHeight, NumericValue, PerBlock},
|
||||
};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
|
||||
@@ -7,8 +7,7 @@ use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode, UnaryTransform};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CentsSignedToDollars, CentsUnsignedToDollars, PerBlock, LazyPerBlock,
|
||||
NumericValue,
|
||||
CentsSignedToDollars, CentsUnsignedToDollars, LazyPerBlock, NumericValue, PerBlock,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -40,8 +39,7 @@ impl<C: CentsType> FiatPerBlock<C> {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let cents =
|
||||
PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let cents = PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let usd = LazyPerBlock::from_computed::<C::ToDollars>(
|
||||
name,
|
||||
version,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Height, Version};
|
||||
use vecdb::{Database, EagerVec, ImportableVec, LazyVecFrom1, PcoVec, ReadableCloneableVec, Rw, StorageMode};
|
||||
use vecdb::{
|
||||
Database, EagerVec, ImportableVec, LazyVecFrom1, PcoVec, ReadableCloneableVec, Rw, StorageMode,
|
||||
};
|
||||
|
||||
use super::CentsType;
|
||||
|
||||
@@ -16,11 +18,8 @@ impl<C: CentsType> FiatBlock<C> {
|
||||
pub(crate) fn forced_import(db: &Database, name: &str, version: Version) -> Result<Self> {
|
||||
let cents: EagerVec<PcoVec<Height, C>> =
|
||||
EagerVec::forced_import(db, &format!("{name}_cents"), version)?;
|
||||
let usd = LazyVecFrom1::transformed::<C::ToDollars>(
|
||||
name,
|
||||
version,
|
||||
cents.read_only_boxed_clone(),
|
||||
);
|
||||
let usd =
|
||||
LazyVecFrom1::transformed::<C::ToDollars>(name, version, cents.read_only_boxed_clone());
|
||||
Ok(Self { usd, cents })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, CentsType, FiatBlock, FiatPerBlock, LazyRollingSumsFiatFromHeight},
|
||||
internal::{
|
||||
CachedWindowStarts, CentsType, FiatBlock, FiatPerBlock, LazyRollingSumsFiatFromHeight,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -24,12 +26,8 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let block = FiatBlock::forced_import(db, name, version)?;
|
||||
let cumulative = FiatPerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_cumulative"),
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
let cumulative =
|
||||
FiatPerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
|
||||
let sum = LazyRollingSumsFiatFromHeight::new(
|
||||
&format!("{name}_sum"),
|
||||
version,
|
||||
@@ -37,7 +35,11 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
|
||||
cached_starts,
|
||||
indexes,
|
||||
);
|
||||
Ok(Self { block, cumulative, sum })
|
||||
Ok(Self {
|
||||
block,
|
||||
cumulative,
|
||||
sum,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
|
||||
|
||||
@@ -39,8 +39,13 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let inner =
|
||||
FiatPerBlockCumulativeWithSums::forced_import(db, name, version, indexes, cached_starts)?;
|
||||
let inner = FiatPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
name,
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?;
|
||||
|
||||
let delta = LazyRollingDeltasFiatFromHeight::new(
|
||||
&format!("{name}_delta"),
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Version};
|
||||
use vecdb::ReadableCloneableVec;
|
||||
|
||||
use crate::internal::{CentsType, PerBlock, Identity, LazyPerBlock, NumericValue};
|
||||
use crate::internal::{CentsType, Identity, LazyPerBlock, NumericValue, PerBlock};
|
||||
|
||||
/// Lazy fiat: both cents and usd are lazy views of a stored source.
|
||||
/// Zero extra stored vecs.
|
||||
@@ -13,11 +13,7 @@ pub struct LazyFiatPerBlock<C: CentsType> {
|
||||
}
|
||||
|
||||
impl<C: CentsType> LazyFiatPerBlock<C> {
|
||||
pub(crate) fn from_computed(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &PerBlock<C>,
|
||||
) -> Self
|
||||
pub(crate) fn from_computed(name: &str, version: Version, source: &PerBlock<C>) -> Self
|
||||
where
|
||||
C: NumericValue,
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30,
|
||||
Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3,
|
||||
Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
@@ -9,9 +9,7 @@ use vecdb::{ReadableBoxedVec, ReadableCloneableVec, UnaryTransform, VecValue};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
PerBlock, Resolutions, ComputedVecValue, NumericValue, PerResolution,
|
||||
},
|
||||
internal::{ComputedVecValue, NumericValue, PerBlock, PerResolution, Resolutions},
|
||||
};
|
||||
|
||||
use super::{LazyTransformLast, MapOption};
|
||||
|
||||
@@ -29,11 +29,8 @@ impl<B: BpsType> LazyPercentPerBlock<B> {
|
||||
&source.bps,
|
||||
);
|
||||
|
||||
let ratio = LazyPerBlock::from_lazy::<B::ToRatio, B>(
|
||||
&format!("{name}_ratio"),
|
||||
version,
|
||||
&bps,
|
||||
);
|
||||
let ratio =
|
||||
LazyPerBlock::from_lazy::<B::ToRatio, B>(&format!("{name}_ratio"), version, &bps);
|
||||
|
||||
let percent = LazyPerBlock::from_lazy::<B::ToPercent, B>(name, version, &bps);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{BpsType, PerBlock, LazyPerBlock},
|
||||
internal::{BpsType, LazyPerBlock, PerBlock},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
|
||||
@@ -148,7 +148,8 @@ impl RatioPerBlockPercentiles {
|
||||
|
||||
{
|
||||
let _lock = exit.lock();
|
||||
self.mut_pct_vecs().try_for_each(|v| v.write().map(|_| ()))?;
|
||||
self.mut_pct_vecs()
|
||||
.try_for_each(|v| v.write().map(|_| ()))?;
|
||||
}
|
||||
|
||||
// Cents bands
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{BasisPoints32, Cents, Dollars, Height, Indexes, SatsFract, Store
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{PerBlock, LazyPerBlock, Price};
|
||||
use crate::internal::{LazyPerBlock, PerBlock, Price};
|
||||
use crate::{indexes, prices};
|
||||
|
||||
use super::{RatioPerBlock, RatioPerBlockPercentiles};
|
||||
@@ -105,7 +105,8 @@ impl PriceWithRatioExtendedPerBlock {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let close_price = &prices.spot.cents.height;
|
||||
self.base.compute_ratio(starting_indexes, close_price, exit)?;
|
||||
self.base
|
||||
.compute_ratio(starting_indexes, close_price, exit)?;
|
||||
self.percentiles.compute(
|
||||
starting_indexes,
|
||||
exit,
|
||||
|
||||
@@ -28,14 +28,7 @@ impl RatioPerBlockStdDevBands {
|
||||
|
||||
macro_rules! import_sd {
|
||||
($period:expr, $days:expr) => {
|
||||
StdDevPerBlockExtended::forced_import(
|
||||
db,
|
||||
name,
|
||||
$period,
|
||||
$days,
|
||||
v,
|
||||
indexes,
|
||||
)?
|
||||
StdDevPerBlockExtended::forced_import(db, name, $period, $days, v, indexes)?
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,7 @@ use crate::{
|
||||
/// with a lazy ratio float view.
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct RatioRollingWindows<B: BpsType, M: StorageMode = Rw>(
|
||||
pub Windows<RatioPerBlock<B, M>>,
|
||||
);
|
||||
pub struct RatioRollingWindows<B: BpsType, M: StorageMode = Rw>(pub Windows<RatioPerBlock<B, M>>);
|
||||
|
||||
impl<B: BpsType> RatioRollingWindows<B> {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -50,7 +48,9 @@ impl<B: BpsType> RatioRollingWindows<B> {
|
||||
.zip(sources1)
|
||||
.zip(sources2)
|
||||
{
|
||||
target.bps.compute_binary::<S1T, S2T, F>(max_from, s1, s2, exit)?;
|
||||
target
|
||||
.bps
|
||||
.compute_binary::<S1T, S2T, F>(max_from, s1, s2, exit)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, NumericValue, LazyRollingAvgsFromHeight, LazyRollingSumsFromHeight,
|
||||
CachedWindowStarts, LazyRollingAvgsFromHeight, LazyRollingSumsFromHeight, NumericValue,
|
||||
RollingDistribution, WindowStarts,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@ use vecdb::{ReadableCloneableVec, UnaryTransform};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CachedWindowStarts, ComputedVecValue, LazyRollingAvgsFromHeight,
|
||||
LazyRollingDistribution, LazyRollingSumsFromHeight, NumericValue, RollingComplete,
|
||||
CachedWindowStarts, ComputedVecValue, LazyRollingAvgsFromHeight, LazyRollingDistribution,
|
||||
LazyRollingSumsFromHeight, NumericValue, RollingComplete,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
mod avg;
|
||||
mod avgs;
|
||||
mod complete;
|
||||
mod delta;
|
||||
mod distribution;
|
||||
mod complete;
|
||||
mod lazy_complete;
|
||||
mod lazy_distribution;
|
||||
mod sum;
|
||||
@@ -11,9 +11,9 @@ mod windows;
|
||||
|
||||
pub use avg::*;
|
||||
pub use avgs::*;
|
||||
pub use complete::*;
|
||||
pub use delta::*;
|
||||
pub use distribution::*;
|
||||
pub use complete::*;
|
||||
pub use lazy_complete::*;
|
||||
pub use lazy_distribution::*;
|
||||
pub use sum::*;
|
||||
|
||||
@@ -15,7 +15,9 @@ use vecdb::CachedVec;
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{PerBlock, ComputedVecValue, NumericValue, RollingWindow24h, Windows, WindowsFrom1w},
|
||||
internal::{
|
||||
ComputedVecValue, NumericValue, PerBlock, RollingWindow24h, Windows, WindowsFrom1w,
|
||||
},
|
||||
};
|
||||
|
||||
/// Cached window starts for lazy rolling computations.
|
||||
@@ -52,9 +54,7 @@ where
|
||||
/// Single 24h rolling window backed by PerBlock (1 stored vec).
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct RollingWindow24hPerBlock<T, M: StorageMode = Rw>(
|
||||
pub RollingWindow24h<PerBlock<T, M>>,
|
||||
)
|
||||
pub struct RollingWindow24hPerBlock<T, M: StorageMode = Rw>(pub RollingWindow24h<PerBlock<T, M>>)
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema;
|
||||
|
||||
@@ -69,12 +69,7 @@ where
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self(RollingWindow24h {
|
||||
_24h: PerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_24h"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
_24h: PerBlock::forced_import(db, &format!("{name}_24h"), version, indexes)?,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ impl StdDevPerBlock {
|
||||
let version = parent_version + Version::TWO;
|
||||
let p = period_suffix(period);
|
||||
|
||||
let sma =
|
||||
PerBlock::forced_import(db, &format!("{name}_sma{p}"), version, indexes)?;
|
||||
let sma = PerBlock::forced_import(db, &format!("{name}_sma{p}"), version, indexes)?;
|
||||
let sd = PerBlock::forced_import(db, &format!("{name}_sd{p}"), version, indexes)?;
|
||||
|
||||
Ok(Self { days, sma, sd })
|
||||
@@ -41,9 +40,13 @@ impl StdDevPerBlock {
|
||||
source: &impl ReadableVec<Height, StoredF32>,
|
||||
) -> Result<()> {
|
||||
if self.days == usize::MAX {
|
||||
self.sma
|
||||
.height
|
||||
.compute_sma_(starting_indexes.height, source, usize::MAX, exit, None)?;
|
||||
self.sma.height.compute_sma_(
|
||||
starting_indexes.height,
|
||||
source,
|
||||
usize::MAX,
|
||||
exit,
|
||||
None,
|
||||
)?;
|
||||
self.sd.height.compute_expanding_sd(
|
||||
starting_indexes.height,
|
||||
source,
|
||||
|
||||
@@ -162,7 +162,8 @@ impl StdDevPerBlockExtended {
|
||||
|
||||
{
|
||||
let _lock = exit.lock();
|
||||
self.mut_band_height_vecs().try_for_each(|v| v.write().map(|_| ()))?;
|
||||
self.mut_band_height_vecs()
|
||||
.try_for_each(|v| v.write().map(|_| ()))?;
|
||||
}
|
||||
|
||||
self.zscore.height.compute_zscore(
|
||||
|
||||
@@ -29,7 +29,12 @@ impl<T> PerTxDistribution<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(db: &Database, name: &str, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let tx_index = EagerVec::forced_import(db, name, version)?;
|
||||
let distribution = TxDerivedDistribution::forced_import(db, name, version, indexes)?;
|
||||
Ok(Self {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use brk_types::{BasisPoints16, BasisPoints32, BasisPointsSigned16, BasisPointsSigned32, StoredF32};
|
||||
use brk_types::{
|
||||
BasisPoints16, BasisPoints32, BasisPointsSigned16, BasisPointsSigned32, StoredF32,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use vecdb::{CheckedSub, Formattable, PcoVecValue, UnaryTransform};
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use brk_types::{BasisPoints16, Bitcoin, Cents, Dollars, Sats, StoredF32, StoredF64, StoredI8, StoredU16, StoredU32, StoredU64, VSize, Weight};
|
||||
use brk_types::{
|
||||
BasisPoints16, Bitcoin, Cents, Dollars, Sats, StoredF32, StoredF64, StoredI8, StoredU16,
|
||||
StoredU32, StoredU64, VSize, Weight,
|
||||
};
|
||||
use vecdb::{BinaryTransform, UnaryTransform, VecValue};
|
||||
|
||||
pub struct Identity<T>(PhantomData<T>);
|
||||
@@ -12,7 +15,6 @@ impl<T: VecValue> UnaryTransform<T, T> for Identity<T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct HalveSats;
|
||||
|
||||
impl UnaryTransform<Sats, Sats> for HalveSats {
|
||||
|
||||
@@ -15,8 +15,8 @@ pub use bps::{
|
||||
Bps32ToFloat, Bps32ToPercent,
|
||||
};
|
||||
pub use currency::{
|
||||
CentsSignedToDollars, CentsSubtractToCentsSigned, CentsTimesTenths, CentsUnsignedToDollars,
|
||||
CentsUnsignedToSats, DollarsToSatsFract, AvgCentsToUsd, AvgSatsToBtc,
|
||||
AvgCentsToUsd, AvgSatsToBtc, CentsSignedToDollars, CentsSubtractToCentsSigned,
|
||||
CentsTimesTenths, CentsUnsignedToDollars, CentsUnsignedToSats, DollarsToSatsFract,
|
||||
NegCentsUnsignedToDollars, SatsToBitcoin, SatsToCents,
|
||||
};
|
||||
pub use derived::{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use brk_types::{
|
||||
BasisPoints16, BasisPoints32, BasisPointsSigned32, Cents, CentsSigned, Dollars, Sats, StoredF32,
|
||||
StoredU64,
|
||||
BasisPoints16, BasisPoints32, BasisPointsSigned32, Cents, CentsSigned, Dollars, Sats,
|
||||
StoredF32, StoredU64,
|
||||
};
|
||||
use vecdb::BinaryTransform;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user