global: snapshot

This commit is contained in:
nym21
2026-01-10 18:43:18 +01:00
parent 3bc0615000
commit 6f45ec13f3
311 changed files with 6916 additions and 7664 deletions

View File

@@ -2,7 +2,7 @@ use brk_error::Result;
use brk_indexer::Indexer;
use vecdb::Exit;
use crate::{ComputeIndexes, indexes, price, transactions};
use crate::{ComputeIndexes, indexes, transactions};
use super::Vecs;
@@ -13,7 +13,6 @@ impl Vecs {
indexes: &indexes::Vecs,
transactions: &transactions::Vecs,
starting_indexes: &ComputeIndexes,
price: Option<&price::Vecs>,
exit: &Exit,
) -> Result<()> {
// Core block metrics
@@ -29,7 +28,8 @@ impl Vecs {
self.time.compute(indexes, starting_indexes, exit)?;
// Epoch metrics
self.difficulty.compute(indexes, starting_indexes, exit)?;
self.difficulty
.compute(indexer, indexes, starting_indexes, exit)?;
self.halving.compute(indexes, starting_indexes, exit)?;
// Rewards depends on count and transactions fees
@@ -39,15 +39,14 @@ impl Vecs {
&self.count,
&transactions.fees,
starting_indexes,
price,
exit,
)?;
// Mining depends on count and rewards
// Mining depends on count, difficulty, and rewards
self.mining.compute(
indexer,
indexes,
&self.count,
&self.difficulty,
&self.rewards,
starting_indexes,
exit,

View File

@@ -5,7 +5,7 @@ use vecdb::{EagerVec, Exit, PcoVec, TypedVecIterator};
use super::super::time;
use super::Vecs;
use crate::{ComputeIndexes, indexes, internal::ComputedBlockLast};
use crate::{ComputeIndexes, indexes, internal::ComputedFromHeightLast};
impl Vecs {
pub fn compute(
@@ -104,7 +104,7 @@ impl Vecs {
get_field: F,
) -> Result<()>
where
F: FnOnce(&mut Self) -> &mut ComputedBlockLast<StoredU32>,
F: FnOnce(&mut Self) -> &mut ComputedFromHeightLast<StoredU32>,
{
get_field(self).compute_all(indexes, starting_indexes, exit, |v| {
v.compute_transform(

View File

@@ -10,13 +10,13 @@ use crate::{
TARGET_BLOCKS_PER_YEAR,
},
indexes,
internal::{ComputedBlockLast, ComputedBlockSumCum, LazyPeriodVecs},
internal::{ComputedFromHeightLast, ComputedFromHeightSumCum, LazyFromDate},
};
impl Vecs {
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
Ok(Self {
block_count_target: LazyPeriodVecs::new(
block_count_target: LazyFromDate::new(
"block_count_target",
version,
indexes,
@@ -28,30 +28,30 @@ impl Vecs {
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_YEAR)),
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_DECADE)),
),
block_count: ComputedBlockSumCum::forced_import(db, "block_count", version, indexes)?,
block_count: ComputedFromHeightSumCum::forced_import(db, "block_count", version, indexes)?,
_24h_start: ImportableVec::forced_import(db, "24h_start", version)?,
_1w_start: ImportableVec::forced_import(db, "1w_start", version)?,
_1m_start: ImportableVec::forced_import(db, "1m_start", version)?,
_1y_start: ImportableVec::forced_import(db, "1y_start", version)?,
_24h_block_count: ComputedBlockLast::forced_import(
_24h_block_count: ComputedFromHeightLast::forced_import(
db,
"24h_block_count",
version,
indexes,
)?,
_1w_block_count: ComputedBlockLast::forced_import(
_1w_block_count: ComputedFromHeightLast::forced_import(
db,
"1w_block_count",
version,
indexes,
)?,
_1m_block_count: ComputedBlockLast::forced_import(
_1m_block_count: ComputedFromHeightLast::forced_import(
db,
"1m_block_count",
version,
indexes,
)?,
_1y_block_count: ComputedBlockLast::forced_import(
_1y_block_count: ComputedFromHeightLast::forced_import(
db,
"1y_block_count",
version,

View File

@@ -2,20 +2,20 @@ use brk_traversable::Traversable;
use brk_types::{Height, StoredU32, StoredU64};
use vecdb::{EagerVec, PcoVec};
use crate::internal::{ComputedBlockLast, ComputedBlockSumCum, LazyPeriodVecs};
use crate::internal::{ComputedFromHeightLast, ComputedFromHeightSumCum, LazyFromDate};
#[derive(Clone, Traversable)]
pub struct Vecs {
pub block_count_target: LazyPeriodVecs<StoredU64>,
pub block_count: ComputedBlockSumCum<StoredU32>,
pub block_count_target: LazyFromDate<StoredU64>,
pub block_count: ComputedFromHeightSumCum<StoredU32>,
// Rolling window starts (height-indexed only, no date aggregation needed)
pub _24h_start: EagerVec<PcoVec<Height, Height>>,
pub _1w_start: EagerVec<PcoVec<Height, Height>>,
pub _1m_start: EagerVec<PcoVec<Height, Height>>,
pub _1y_start: EagerVec<PcoVec<Height, Height>>,
// Rolling window block counts
pub _24h_block_count: ComputedBlockLast<StoredU32>,
pub _1w_block_count: ComputedBlockLast<StoredU32>,
pub _1m_block_count: ComputedBlockLast<StoredU32>,
pub _1y_block_count: ComputedBlockLast<StoredU32>,
pub _24h_block_count: ComputedFromHeightLast<StoredU32>,
pub _1w_block_count: ComputedFromHeightLast<StoredU32>,
pub _1m_block_count: ComputedFromHeightLast<StoredU32>,
pub _1y_block_count: ComputedFromHeightLast<StoredU32>,
}

View File

@@ -1,5 +1,6 @@
use brk_error::Result;
use brk_types::StoredU32;
use brk_indexer::Indexer;
use brk_types::{StoredF32, StoredU32};
use vecdb::{Exit, TypedVecIterator};
use super::super::TARGET_BLOCKS_PER_DAY_F32;
@@ -9,10 +10,45 @@ use crate::{ComputeIndexes, indexes};
impl Vecs {
pub fn compute(
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
// Derive dateindex/period stats from raw difficulty
self.raw.derive_from(
indexes,
starting_indexes,
&indexer.vecs.blocks.difficulty,
exit,
)?;
// Compute difficulty as hash rate equivalent
self.as_hash
.compute_all(indexes, starting_indexes, exit, |v| {
let multiplier = 2.0_f64.powi(32) / 600.0;
v.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.difficulty,
|(i, v, ..)| (i, StoredF32::from(*v * multiplier)),
exit,
)?;
Ok(())
})?;
// Compute difficulty adjustment percentage
self.adjustment
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_percentage_change(
starting_indexes.height,
&indexer.vecs.blocks.difficulty,
1,
exit,
)?;
Ok(())
})?;
// Compute epoch by dateindex
let mut height_to_difficultyepoch_iter = indexes.height.difficultyepoch.into_iter();
self.epoch.compute_all(starting_indexes, exit, |vec| {
let mut height_count_iter = indexes.dateindex.height_count.into_iter();
@@ -31,7 +67,8 @@ impl Vecs {
Ok(())
})?;
self.blocks_before_next_difficulty_adjustment.compute_all(
// Compute blocks before next adjustment
self.blocks_before_next_adjustment.compute_all(
indexes,
starting_indexes,
exit,
@@ -46,14 +83,15 @@ impl Vecs {
},
)?;
self.days_before_next_difficulty_adjustment.compute_all(
// Compute days before next adjustment
self.days_before_next_adjustment.compute_all(
indexes,
starting_indexes,
exit,
|v| {
v.compute_transform(
starting_indexes.height,
&self.blocks_before_next_difficulty_adjustment.height,
&self.blocks_before_next_adjustment.height,
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
exit,
)?;

View File

@@ -1,26 +1,44 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::Version;
use vecdb::Database;
use vecdb::{Database, IterableCloneableVec};
use super::Vecs;
use crate::{
indexes,
internal::{ComputedBlockLast, ComputedDateLast},
internal::{
ComputedFromHeightLast, ComputedFromHeightSum, ComputedFromDateLast,
ComputedHeightDerivedLast,
},
};
impl Vecs {
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
pub fn forced_import(
db: &Database,
version: Version,
indexer: &Indexer,
indexes: &indexes::Vecs,
) -> Result<Self> {
let v2 = Version::TWO;
Ok(Self {
epoch: ComputedDateLast::forced_import(db, "difficultyepoch", version, indexes)?,
blocks_before_next_difficulty_adjustment: ComputedBlockLast::forced_import(
raw: ComputedHeightDerivedLast::forced_import(
db,
"difficulty",
indexer.vecs.blocks.difficulty.boxed_clone(),
version,
indexes,
)?,
as_hash: ComputedFromHeightLast::forced_import(db, "difficulty_as_hash", version, indexes)?,
adjustment: ComputedFromHeightSum::forced_import(db, "difficulty_adjustment", version, indexes)?,
epoch: ComputedFromDateLast::forced_import(db, "difficultyepoch", version, indexes)?,
blocks_before_next_adjustment: ComputedFromHeightLast::forced_import(
db,
"blocks_before_next_difficulty_adjustment",
version + v2,
indexes,
)?,
days_before_next_difficulty_adjustment: ComputedBlockLast::forced_import(
days_before_next_adjustment: ComputedFromHeightLast::forced_import(
db,
"days_before_next_difficulty_adjustment",
version + v2,

View File

@@ -1,12 +1,18 @@
use brk_traversable::Traversable;
use brk_types::{DifficultyEpoch, StoredF32, StoredU32};
use brk_types::{DifficultyEpoch, StoredF32, StoredF64, StoredU32};
use crate::internal::{ComputedBlockLast, ComputedDateLast};
use crate::internal::{
ComputedFromHeightLast, ComputedFromHeightSum, ComputedFromDateLast, ComputedHeightDerivedLast,
};
/// Difficulty epoch metrics and countdown
/// Difficulty metrics: raw difficulty, derived stats, adjustment, and countdown
#[derive(Clone, Traversable)]
pub struct Vecs {
pub epoch: ComputedDateLast<DifficultyEpoch>,
pub blocks_before_next_difficulty_adjustment: ComputedBlockLast<StoredU32>,
pub days_before_next_difficulty_adjustment: ComputedBlockLast<StoredF32>,
/// Raw difficulty with dateindex/period stats - merges with indexer's raw
pub raw: ComputedHeightDerivedLast<StoredF64>,
pub as_hash: ComputedFromHeightLast<StoredF32>,
pub adjustment: ComputedFromHeightSum<StoredF32>,
pub epoch: ComputedFromDateLast<DifficultyEpoch>,
pub blocks_before_next_adjustment: ComputedFromHeightLast<StoredU32>,
pub days_before_next_adjustment: ComputedFromHeightLast<StoredF32>,
}

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedBlockLast, ComputedDateLast},
internal::{ComputedFromHeightLast, ComputedFromDateLast},
};
impl Vecs {
@@ -13,14 +13,14 @@ impl Vecs {
let v2 = Version::TWO;
Ok(Self {
epoch: ComputedDateLast::forced_import(db, "halvingepoch", version, indexes)?,
blocks_before_next_halving: ComputedBlockLast::forced_import(
epoch: ComputedFromDateLast::forced_import(db, "halvingepoch", version, indexes)?,
blocks_before_next_halving: ComputedFromHeightLast::forced_import(
db,
"blocks_before_next_halving",
version + v2,
indexes,
)?,
days_before_next_halving: ComputedBlockLast::forced_import(
days_before_next_halving: ComputedFromHeightLast::forced_import(
db,
"days_before_next_halving",
version + v2,

View File

@@ -1,12 +1,12 @@
use brk_traversable::Traversable;
use brk_types::{HalvingEpoch, StoredF32, StoredU32};
use crate::internal::{ComputedBlockLast, ComputedDateLast};
use crate::internal::{ComputedFromHeightLast, ComputedFromDateLast};
/// Halving epoch metrics and countdown
#[derive(Clone, Traversable)]
pub struct Vecs {
pub epoch: ComputedDateLast<HalvingEpoch>,
pub blocks_before_next_halving: ComputedBlockLast<StoredU32>,
pub days_before_next_halving: ComputedBlockLast<StoredF32>,
pub epoch: ComputedFromDateLast<HalvingEpoch>,
pub blocks_before_next_halving: ComputedFromHeightLast<StoredU32>,
pub days_before_next_halving: ComputedFromHeightLast<StoredF32>,
}

View File

@@ -25,16 +25,15 @@ impl Vecs {
db.set_min_len(PAGE_SIZE * 50_000_000)?;
let version = parent_version;
let compute_dollars = price.is_some();
let count = CountVecs::forced_import(&db, version, indexes)?;
let interval = IntervalVecs::forced_import(&db, version, indexer, indexes)?;
let size = SizeVecs::forced_import(&db, version, indexer, indexes)?;
let weight = WeightVecs::forced_import(&db, version, indexer, indexes)?;
let time = TimeVecs::forced_import(&db, version, indexer, indexes)?;
let mining = MiningVecs::forced_import(&db, version, indexer, indexes)?;
let rewards = RewardsVecs::forced_import(&db, version, indexes, compute_dollars)?;
let difficulty = DifficultyVecs::forced_import(&db, version, indexes)?;
let mining = MiningVecs::forced_import(&db, version, indexes)?;
let rewards = RewardsVecs::forced_import(&db, version, indexes, price)?;
let difficulty = DifficultyVecs::forced_import(&db, version, indexer, indexes)?;
let halving = HalvingVecs::forced_import(&db, version, indexes)?;
let this = Self {

View File

@@ -4,7 +4,7 @@ use brk_types::{CheckedSub, Height, Timestamp, Version};
use vecdb::{Database, VecIndex};
use super::Vecs;
use crate::{indexes, internal::LazyBlockDistribution};
use crate::{indexes, internal::LazyFromHeightDistribution};
impl Vecs {
pub fn forced_import(
@@ -13,7 +13,7 @@ impl Vecs {
indexer: &Indexer,
indexes: &indexes::Vecs,
) -> Result<Self> {
let interval = LazyBlockDistribution::forced_import_with_init(
let interval = LazyFromHeightDistribution::forced_import_with_init(
db,
"block_interval",
version,

View File

@@ -1,10 +1,10 @@
use brk_traversable::Traversable;
use brk_types::Timestamp;
use crate::internal::LazyBlockDistribution;
use crate::internal::LazyFromHeightDistribution;
#[derive(Clone, Traversable)]
pub struct Vecs {
#[traversable(flatten)]
pub interval: LazyBlockDistribution<Timestamp>,
pub interval: LazyFromHeightDistribution<Timestamp>,
}

View File

@@ -1,47 +1,27 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::{StoredF32, StoredF64};
use vecdb::Exit;
use super::super::{ONE_TERA_HASH, TARGET_BLOCKS_PER_DAY_F64, count, rewards};
use super::super::{ONE_TERA_HASH, TARGET_BLOCKS_PER_DAY_F64, count, difficulty, rewards};
use super::Vecs;
use crate::{ComputeIndexes, indexes};
impl Vecs {
pub fn compute(
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
count_vecs: &count::Vecs,
difficulty_vecs: &difficulty::Vecs,
rewards_vecs: &rewards::Vecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.difficulty.derive_from(
indexes,
starting_indexes,
&indexer.vecs.blocks.difficulty,
exit,
)?;
self.difficulty_as_hash
.compute_all(indexes, starting_indexes, exit, |v| {
let multiplier = 2.0_f64.powi(32) / 600.0;
v.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.difficulty,
|(i, v, ..)| (i, StoredF32::from(*v * multiplier)),
exit,
)?;
Ok(())
})?;
self.hash_rate
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_transform2(
starting_indexes.height,
&count_vecs._24h_block_count.height,
&self.difficulty_as_hash.height,
&difficulty_vecs.as_hash.height,
|(i, block_count_sum, difficulty_as_hash, ..)| {
(
i,
@@ -100,17 +80,6 @@ impl Vecs {
Ok(())
})?;
self.difficulty_adjustment
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_percentage_change(
starting_indexes.height,
&indexer.vecs.blocks.difficulty,
1,
exit,
)?;
Ok(())
})?;
self.hash_price_ths
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_transform2(

View File

@@ -1,130 +1,108 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::Version;
use vecdb::{Database, IterableCloneableVec};
use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedBlockLast, ComputedBlockSum, ComputedDateLast, ComputedDerivedBlockLast},
internal::{ComputedFromHeightLast, ComputedFromDateLast},
};
impl Vecs {
pub fn forced_import(
db: &Database,
version: Version,
indexer: &Indexer,
indexes: &indexes::Vecs,
) -> Result<Self> {
let v4 = Version::new(4);
let v5 = Version::new(5);
Ok(Self {
hash_rate: ComputedBlockLast::forced_import(db, "hash_rate", version + v5, indexes)?,
hash_rate_1w_sma: ComputedDateLast::forced_import(
hash_rate: ComputedFromHeightLast::forced_import(db, "hash_rate", version + v5, indexes)?,
hash_rate_1w_sma: ComputedFromDateLast::forced_import(
db,
"hash_rate_1w_sma",
version,
indexes,
)?,
hash_rate_1m_sma: ComputedDateLast::forced_import(
hash_rate_1m_sma: ComputedFromDateLast::forced_import(
db,
"hash_rate_1m_sma",
version,
indexes,
)?,
hash_rate_2m_sma: ComputedDateLast::forced_import(
hash_rate_2m_sma: ComputedFromDateLast::forced_import(
db,
"hash_rate_2m_sma",
version,
indexes,
)?,
hash_rate_1y_sma: ComputedDateLast::forced_import(
hash_rate_1y_sma: ComputedFromDateLast::forced_import(
db,
"hash_rate_1y_sma",
version,
indexes,
)?,
hash_price_ths: ComputedBlockLast::forced_import(
hash_price_ths: ComputedFromHeightLast::forced_import(
db,
"hash_price_ths",
version + v4,
indexes,
)?,
hash_price_ths_min: ComputedBlockLast::forced_import(
hash_price_ths_min: ComputedFromHeightLast::forced_import(
db,
"hash_price_ths_min",
version + v4,
indexes,
)?,
hash_price_phs: ComputedBlockLast::forced_import(
hash_price_phs: ComputedFromHeightLast::forced_import(
db,
"hash_price_phs",
version + v4,
indexes,
)?,
hash_price_phs_min: ComputedBlockLast::forced_import(
hash_price_phs_min: ComputedFromHeightLast::forced_import(
db,
"hash_price_phs_min",
version + v4,
indexes,
)?,
hash_price_rebound: ComputedBlockLast::forced_import(
hash_price_rebound: ComputedFromHeightLast::forced_import(
db,
"hash_price_rebound",
version + v4,
indexes,
)?,
hash_value_ths: ComputedBlockLast::forced_import(
hash_value_ths: ComputedFromHeightLast::forced_import(
db,
"hash_value_ths",
version + v4,
indexes,
)?,
hash_value_ths_min: ComputedBlockLast::forced_import(
hash_value_ths_min: ComputedFromHeightLast::forced_import(
db,
"hash_value_ths_min",
version + v4,
indexes,
)?,
hash_value_phs: ComputedBlockLast::forced_import(
hash_value_phs: ComputedFromHeightLast::forced_import(
db,
"hash_value_phs",
version + v4,
indexes,
)?,
hash_value_phs_min: ComputedBlockLast::forced_import(
hash_value_phs_min: ComputedFromHeightLast::forced_import(
db,
"hash_value_phs_min",
version + v4,
indexes,
)?,
hash_value_rebound: ComputedBlockLast::forced_import(
hash_value_rebound: ComputedFromHeightLast::forced_import(
db,
"hash_value_rebound",
version + v4,
indexes,
)?,
// Derived from external indexer data - no height storage needed
difficulty: ComputedDerivedBlockLast::forced_import(
db,
"difficulty",
indexer.vecs.blocks.difficulty.boxed_clone(),
version,
indexes,
)?,
difficulty_as_hash: ComputedBlockLast::forced_import(
db,
"difficulty_as_hash",
version,
indexes,
)?,
difficulty_adjustment: ComputedBlockSum::forced_import(
db,
"difficulty_adjustment",
version,
indexes,
)?,
})
}
}

View File

@@ -1,30 +1,24 @@
use brk_traversable::Traversable;
use brk_types::{StoredF32, StoredF64};
use crate::internal::{
ComputedBlockLast, ComputedBlockSum, ComputedDateLast, ComputedDerivedBlockLast,
};
use crate::internal::{ComputedFromHeightLast, ComputedFromDateLast};
/// Mining-related metrics: hash rate, hash price, hash value, difficulty
/// Mining-related metrics: hash rate, hash price, hash value
#[derive(Clone, Traversable)]
pub struct Vecs {
pub hash_rate: ComputedBlockLast<StoredF64>,
pub hash_rate_1w_sma: ComputedDateLast<StoredF64>,
pub hash_rate_1m_sma: ComputedDateLast<StoredF32>,
pub hash_rate_2m_sma: ComputedDateLast<StoredF32>,
pub hash_rate_1y_sma: ComputedDateLast<StoredF32>,
pub hash_price_ths: ComputedBlockLast<StoredF32>,
pub hash_price_ths_min: ComputedBlockLast<StoredF32>,
pub hash_price_phs: ComputedBlockLast<StoredF32>,
pub hash_price_phs_min: ComputedBlockLast<StoredF32>,
pub hash_price_rebound: ComputedBlockLast<StoredF32>,
pub hash_value_ths: ComputedBlockLast<StoredF32>,
pub hash_value_ths_min: ComputedBlockLast<StoredF32>,
pub hash_value_phs: ComputedBlockLast<StoredF32>,
pub hash_value_phs_min: ComputedBlockLast<StoredF32>,
pub hash_value_rebound: ComputedBlockLast<StoredF32>,
/// Derived from indexer - no height storage needed
pub difficulty: ComputedDerivedBlockLast<StoredF64>,
pub difficulty_as_hash: ComputedBlockLast<StoredF32>,
pub difficulty_adjustment: ComputedBlockSum<StoredF32>,
pub hash_rate: ComputedFromHeightLast<StoredF64>,
pub hash_rate_1w_sma: ComputedFromDateLast<StoredF64>,
pub hash_rate_1m_sma: ComputedFromDateLast<StoredF32>,
pub hash_rate_2m_sma: ComputedFromDateLast<StoredF32>,
pub hash_rate_1y_sma: ComputedFromDateLast<StoredF32>,
pub hash_price_ths: ComputedFromHeightLast<StoredF32>,
pub hash_price_ths_min: ComputedFromHeightLast<StoredF32>,
pub hash_price_phs: ComputedFromHeightLast<StoredF32>,
pub hash_price_phs_min: ComputedFromHeightLast<StoredF32>,
pub hash_price_rebound: ComputedFromHeightLast<StoredF32>,
pub hash_value_ths: ComputedFromHeightLast<StoredF32>,
pub hash_value_ths_min: ComputedFromHeightLast<StoredF32>,
pub hash_value_phs: ComputedFromHeightLast<StoredF32>,
pub hash_value_phs_min: ComputedFromHeightLast<StoredF32>,
pub hash_value_rebound: ComputedFromHeightLast<StoredF32>,
}

View File

@@ -44,7 +44,9 @@ pub struct Vecs {
pub count: CountVecs,
pub interval: IntervalVecs,
#[traversable(flatten)]
pub size: SizeVecs,
#[traversable(flatten)]
pub weight: WeightVecs,
pub time: TimeVecs,
pub mining: MiningVecs,

View File

@@ -5,10 +5,9 @@ use vecdb::{Exit, IterableVec, TypedVecIterator, VecIndex};
use super::super::count;
use super::Vecs;
use crate::{ComputeIndexes, indexes, price, transactions};
use crate::{ComputeIndexes, indexes, transactions};
impl Vecs {
#[allow(clippy::too_many_arguments)]
pub fn compute(
&mut self,
indexer: &Indexer,
@@ -16,11 +15,10 @@ impl Vecs {
count_vecs: &count::Vecs,
transactions_fees: &transactions::FeesVecs,
starting_indexes: &ComputeIndexes,
price: Option<&price::Vecs>,
exit: &Exit,
) -> Result<()> {
self.coinbase
.compute_all(indexes, price, starting_indexes, exit, |vec| {
.compute_all(indexes, starting_indexes, exit, |vec| {
let mut txindex_to_first_txoutindex_iter =
indexer.vecs.transactions.first_txoutindex.iter()?;
let mut txindex_to_output_count_iter =
@@ -84,7 +82,7 @@ impl Vecs {
}
self.subsidy
.compute_all(indexes, price, starting_indexes, exit, |vec| {
.compute_all(indexes, starting_indexes, exit, |vec| {
vec.compute_transform2(
starting_indexes.height,
&self.coinbase.sats.height,
@@ -104,7 +102,7 @@ impl Vecs {
})?;
self.unclaimed_rewards
.compute_all(indexes, price, starting_indexes, exit, |vec| {
.compute_all(indexes, starting_indexes, exit, |vec| {
vec.compute_transform(
starting_indexes.height,
&self.subsidy.sats.height,

View File

@@ -5,7 +5,8 @@ use vecdb::{Database, EagerVec, ImportableVec};
use super::Vecs;
use crate::{
indexes,
internal::{ComputedDateLast, ValueBlockFull, ValueBlockHeight, ValueBlockSumCum},
internal::{ComputedFromDateLast, ValueFromHeightFull, ValueHeight, ValueFromHeightSumCum},
price,
};
impl Vecs {
@@ -13,41 +14,31 @@ impl Vecs {
db: &Database,
version: Version,
indexes: &indexes::Vecs,
compute_dollars: bool,
price: Option<&price::Vecs>,
) -> Result<Self> {
let compute_dollars = price.is_some();
Ok(Self {
_24h_coinbase_sum: ValueBlockHeight::forced_import(
_24h_coinbase_sum: ValueHeight::forced_import(
db,
"24h_coinbase_sum",
version,
compute_dollars,
)?,
coinbase: ValueBlockFull::forced_import(
db,
"coinbase",
version,
indexes,
compute_dollars,
)?,
subsidy: ValueBlockFull::forced_import(
db,
"subsidy",
version,
indexes,
compute_dollars,
)?,
unclaimed_rewards: ValueBlockSumCum::forced_import(
coinbase: ValueFromHeightFull::forced_import(db, "coinbase", version, indexes, price)?,
subsidy: ValueFromHeightFull::forced_import(db, "subsidy", version, indexes, price)?,
unclaimed_rewards: ValueFromHeightSumCum::forced_import(
db,
"unclaimed_rewards",
version,
indexes,
compute_dollars,
price,
)?,
fee_dominance: EagerVec::forced_import(db, "fee_dominance", version)?,
subsidy_dominance: EagerVec::forced_import(db, "subsidy_dominance", version)?,
subsidy_usd_1y_sma: compute_dollars
.then(|| {
ComputedDateLast::forced_import(db, "subsidy_usd_1y_sma", version, indexes)
ComputedFromDateLast::forced_import(db, "subsidy_usd_1y_sma", version, indexes)
})
.transpose()?,
})

View File

@@ -2,16 +2,16 @@ use brk_traversable::Traversable;
use brk_types::{DateIndex, Dollars, StoredF32};
use vecdb::{EagerVec, PcoVec};
use crate::internal::{ComputedDateLast, ValueBlockFull, ValueBlockHeight, ValueBlockSumCum};
use crate::internal::{ComputedFromDateLast, ValueFromHeightFull, ValueHeight, ValueFromHeightSumCum};
/// Coinbase/subsidy/rewards metrics
#[derive(Clone, Traversable)]
pub struct Vecs {
pub _24h_coinbase_sum: ValueBlockHeight,
pub coinbase: ValueBlockFull,
pub subsidy: ValueBlockFull,
pub unclaimed_rewards: ValueBlockSumCum,
pub _24h_coinbase_sum: ValueHeight,
pub coinbase: ValueFromHeightFull,
pub subsidy: ValueFromHeightFull,
pub unclaimed_rewards: ValueFromHeightSumCum,
pub fee_dominance: EagerVec<PcoVec<DateIndex, StoredF32>>,
pub subsidy_dominance: EagerVec<PcoVec<DateIndex, StoredF32>>,
pub subsidy_usd_1y_sma: Option<ComputedDateLast<Dollars>>,
pub subsidy_usd_1y_sma: Option<ComputedFromDateLast<Dollars>>,
}

View File

@@ -4,7 +4,7 @@ use brk_types::{Height, StoredU64, Version};
use vecdb::{Database, IterableCloneableVec, VecIndex};
use super::Vecs;
use crate::{indexes, internal::{ComputedDerivedBlockFull, LazyBlockFullHeight}};
use crate::{indexes, internal::{ComputedHeightDerivedFull, LazyComputedFromHeightFull}};
impl Vecs {
pub fn forced_import(
@@ -14,7 +14,7 @@ impl Vecs {
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
vbytes: LazyBlockFullHeight::forced_import_with_init(
vbytes: LazyComputedFromHeightFull::forced_import_with_init(
db,
"block_vbytes",
version,
@@ -26,7 +26,7 @@ impl Vecs {
.map(|w| StoredU64::from(w.to_vbytes_floor()))
},
)?,
size: ComputedDerivedBlockFull::forced_import(
size: ComputedHeightDerivedFull::forced_import(
db,
"block_size",
indexer.vecs.blocks.total_size.boxed_clone(),

View File

@@ -1,10 +1,10 @@
use brk_traversable::Traversable;
use brk_types::{StoredU64, Weight};
use crate::internal::{ComputedDerivedBlockFull, LazyBlockFullHeight};
use crate::internal::{ComputedHeightDerivedFull, LazyComputedFromHeightFull};
#[derive(Clone, Traversable)]
pub struct Vecs {
pub vbytes: LazyBlockFullHeight<StoredU64, Weight>,
pub size: ComputedDerivedBlockFull<StoredU64>,
pub vbytes: LazyComputedFromHeightFull<StoredU64, Weight>,
pub size: ComputedHeightDerivedFull<StoredU64>,
}

View File

@@ -4,7 +4,7 @@ use brk_types::{Date, Height, Version};
use vecdb::{Database, EagerVec, ImportableVec, IterableCloneableVec, LazyVecFrom1, VecIndex};
use super::Vecs;
use crate::{indexes, internal::ComputedDerivedBlockFirst};
use crate::{indexes, internal::ComputedHeightDerivedFirst};
impl Vecs {
pub fn forced_import(
@@ -31,7 +31,7 @@ impl Vecs {
|height: Height, timestamp_iter| timestamp_iter.get(height).map(Date::from),
),
timestamp_fixed: height_to_timestamp_fixed,
timestamp: ComputedDerivedBlockFirst::forced_import(
timestamp: ComputedHeightDerivedFirst::forced_import(
db,
"timestamp",
indexer.vecs.blocks.timestamp.boxed_clone(),

View File

@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
use brk_types::{Date, Height, Timestamp};
use vecdb::{EagerVec, LazyVecFrom1, PcoVec};
use crate::internal::ComputedDerivedBlockFirst;
use crate::internal::ComputedHeightDerivedFirst;
/// Timestamp and date metrics for blocks
#[derive(Clone, Traversable)]
@@ -10,5 +10,5 @@ pub struct Vecs {
pub date: LazyVecFrom1<Height, Date, Height, Timestamp>,
pub date_fixed: LazyVecFrom1<Height, Date, Height, Timestamp>,
pub timestamp_fixed: EagerVec<PcoVec<Height, Timestamp>>,
pub timestamp: ComputedDerivedBlockFirst<Timestamp>,
pub timestamp: ComputedHeightDerivedFirst<Timestamp>,
}

View File

@@ -6,7 +6,7 @@ use vecdb::{Database, IterableCloneableVec};
use super::Vecs;
use crate::{
indexes,
internal::{ComputedDerivedBlockFull, LazyBlockFull, WeightToFullness},
internal::{ComputedHeightDerivedFull, LazyFromHeightFull, WeightToFullness},
};
impl Vecs {
@@ -16,7 +16,7 @@ impl Vecs {
indexer: &Indexer,
indexes: &indexes::Vecs,
) -> Result<Self> {
let weight = ComputedDerivedBlockFull::forced_import(
let weight = ComputedHeightDerivedFull::forced_import(
db,
"block_weight",
indexer.vecs.blocks.weight.boxed_clone(),
@@ -24,7 +24,7 @@ impl Vecs {
indexes,
)?;
let fullness = LazyBlockFull::from_derived::<WeightToFullness>(
let fullness = LazyFromHeightFull::from_derived::<WeightToFullness>(
"block_fullness",
version,
indexer.vecs.blocks.weight.boxed_clone(),

View File

@@ -1,10 +1,10 @@
use brk_traversable::Traversable;
use brk_types::{StoredF32, Weight};
use crate::internal::{ComputedDerivedBlockFull, LazyBlockFull};
use crate::internal::{ComputedHeightDerivedFull, LazyFromHeightFull};
#[derive(Clone, Traversable)]
pub struct Vecs {
pub weight: ComputedDerivedBlockFull<Weight>,
pub fullness: LazyBlockFull<StoredF32, Weight>,
pub weight: ComputedHeightDerivedFull<Weight>,
pub fullness: LazyFromHeightFull<StoredF32, Weight>,
}

View File

@@ -5,27 +5,27 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedBlockLast, ComputedBlockSumCum},
internal::{ComputedFromHeightLast, ComputedFromHeightSumCum},
};
impl Vecs {
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
Ok(Self {
coinblocks_created: ComputedBlockSumCum::forced_import(
coinblocks_created: ComputedFromHeightSumCum::forced_import(
db,
"coinblocks_created",
version,
indexes,
)?,
coinblocks_stored: ComputedBlockSumCum::forced_import(
coinblocks_stored: ComputedFromHeightSumCum::forced_import(
db,
"coinblocks_stored",
version,
indexes,
)?,
liveliness: ComputedBlockLast::forced_import(db, "liveliness", version, indexes)?,
vaultedness: ComputedBlockLast::forced_import(db, "vaultedness", version, indexes)?,
activity_to_vaultedness_ratio: ComputedBlockLast::forced_import(
liveliness: ComputedFromHeightLast::forced_import(db, "liveliness", version, indexes)?,
vaultedness: ComputedFromHeightLast::forced_import(db, "vaultedness", version, indexes)?,
activity_to_vaultedness_ratio: ComputedFromHeightLast::forced_import(
db,
"activity_to_vaultedness_ratio",
version,

View File

@@ -1,13 +1,13 @@
use brk_traversable::Traversable;
use brk_types::StoredF64;
use crate::internal::{ComputedBlockLast, ComputedBlockSumCum};
use crate::internal::{ComputedFromHeightLast, ComputedFromHeightSumCum};
#[derive(Clone, Traversable)]
pub struct Vecs {
pub coinblocks_created: ComputedBlockSumCum<StoredF64>,
pub coinblocks_stored: ComputedBlockSumCum<StoredF64>,
pub liveliness: ComputedBlockLast<StoredF64>,
pub vaultedness: ComputedBlockLast<StoredF64>,
pub activity_to_vaultedness_ratio: ComputedBlockLast<StoredF64>,
pub coinblocks_created: ComputedFromHeightSumCum<StoredF64>,
pub coinblocks_stored: ComputedFromHeightSumCum<StoredF64>,
pub liveliness: ComputedFromHeightLast<StoredF64>,
pub vaultedness: ComputedFromHeightLast<StoredF64>,
pub activity_to_vaultedness_ratio: ComputedFromHeightLast<StoredF64>,
}

View File

@@ -3,24 +3,24 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::ComputedDateLast};
use crate::{indexes, internal::ComputedFromDateLast};
impl Vecs {
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
Ok(Self {
cointime_adj_inflation_rate: ComputedDateLast::forced_import(
cointime_adj_inflation_rate: ComputedFromDateLast::forced_import(
db,
"cointime_adj_inflation_rate",
version,
indexes,
)?,
cointime_adj_tx_btc_velocity: ComputedDateLast::forced_import(
cointime_adj_tx_btc_velocity: ComputedFromDateLast::forced_import(
db,
"cointime_adj_tx_btc_velocity",
version,
indexes,
)?,
cointime_adj_tx_usd_velocity: ComputedDateLast::forced_import(
cointime_adj_tx_usd_velocity: ComputedFromDateLast::forced_import(
db,
"cointime_adj_tx_usd_velocity",
version,

View File

@@ -1,11 +1,11 @@
use brk_traversable::Traversable;
use brk_types::{StoredF32, StoredF64};
use crate::internal::ComputedDateLast;
use crate::internal::ComputedFromDateLast;
#[derive(Clone, Traversable)]
pub struct Vecs {
pub cointime_adj_inflation_rate: ComputedDateLast<StoredF32>,
pub cointime_adj_tx_btc_velocity: ComputedDateLast<StoredF64>,
pub cointime_adj_tx_usd_velocity: ComputedDateLast<StoredF64>,
pub cointime_adj_inflation_rate: ComputedFromDateLast<StoredF32>,
pub cointime_adj_tx_btc_velocity: ComputedFromDateLast<StoredF64>,
pub cointime_adj_tx_usd_velocity: ComputedFromDateLast<StoredF64>,
}

View File

@@ -3,16 +3,16 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::ComputedBlockLast};
use crate::{indexes, internal::ComputedFromHeightLast};
impl Vecs {
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
Ok(Self {
thermo_cap: ComputedBlockLast::forced_import(db, "thermo_cap", version, indexes)?,
investor_cap: ComputedBlockLast::forced_import(db, "investor_cap", version, indexes)?,
vaulted_cap: ComputedBlockLast::forced_import(db, "vaulted_cap", version, indexes)?,
active_cap: ComputedBlockLast::forced_import(db, "active_cap", version, indexes)?,
cointime_cap: ComputedBlockLast::forced_import(db, "cointime_cap", version, indexes)?,
thermo_cap: ComputedFromHeightLast::forced_import(db, "thermo_cap", version, indexes)?,
investor_cap: ComputedFromHeightLast::forced_import(db, "investor_cap", version, indexes)?,
vaulted_cap: ComputedFromHeightLast::forced_import(db, "vaulted_cap", version, indexes)?,
active_cap: ComputedFromHeightLast::forced_import(db, "active_cap", version, indexes)?,
cointime_cap: ComputedFromHeightLast::forced_import(db, "cointime_cap", version, indexes)?,
})
}
}

View File

@@ -1,13 +1,13 @@
use brk_traversable::Traversable;
use brk_types::Dollars;
use crate::internal::ComputedBlockLast;
use crate::internal::ComputedFromHeightLast;
#[derive(Clone, Traversable)]
pub struct Vecs {
pub thermo_cap: ComputedBlockLast<Dollars>,
pub investor_cap: ComputedBlockLast<Dollars>,
pub vaulted_cap: ComputedBlockLast<Dollars>,
pub active_cap: ComputedBlockLast<Dollars>,
pub cointime_cap: ComputedBlockLast<Dollars>,
pub thermo_cap: ComputedFromHeightLast<Dollars>,
pub investor_cap: ComputedFromHeightLast<Dollars>,
pub vaulted_cap: ComputedFromHeightLast<Dollars>,
pub active_cap: ComputedFromHeightLast<Dollars>,
pub cointime_cap: ComputedFromHeightLast<Dollars>,
}

View File

@@ -24,7 +24,6 @@ impl Vecs {
self.supply.compute(
indexes,
starting_indexes,
price,
distribution,
&self.activity,
exit,

View File

@@ -20,12 +20,11 @@ impl Vecs {
let db = Database::open(&parent_path.join(DB_NAME))?;
db.set_min_len(PAGE_SIZE * 1_000_000)?;
let compute_dollars = price.is_some();
let version = parent_version + VERSION;
let v1 = version + Version::ONE;
let activity = ActivityVecs::forced_import(&db, version, indexes)?;
let supply = SupplyVecs::forced_import(&db, v1, indexes, compute_dollars)?;
let supply = SupplyVecs::forced_import(&db, v1, indexes, price)?;
let value = ValueVecs::forced_import(&db, v1, indexes)?;
let cap = CapVecs::forced_import(&db, v1, indexes)?;
let pricing = PricingVecs::forced_import(&db, version, indexes, price)?;

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedBlockLast, ComputedRatioVecsDate},
internal::{ComputedFromHeightLast, ComputedFromDateRatio},
price,
};
@@ -18,7 +18,7 @@ impl Vecs {
) -> Result<Self> {
macro_rules! computed_h {
($name:expr) => {
ComputedBlockLast::forced_import(db, $name, version, indexes)?
ComputedFromHeightLast::forced_import(db, $name, version, indexes)?
};
}
@@ -30,7 +30,7 @@ impl Vecs {
macro_rules! ratio_di {
($name:expr, $source:expr) => {
ComputedRatioVecsDate::forced_import(
ComputedFromDateRatio::forced_import(
db,
$name,
Some($source),

View File

@@ -1,16 +1,16 @@
use brk_traversable::Traversable;
use brk_types::Dollars;
use crate::internal::{ComputedBlockLast, ComputedRatioVecsDate};
use crate::internal::{ComputedFromHeightLast, ComputedFromDateRatio};
#[derive(Clone, Traversable)]
pub struct Vecs {
pub vaulted_price: ComputedBlockLast<Dollars>,
pub vaulted_price_ratio: ComputedRatioVecsDate,
pub active_price: ComputedBlockLast<Dollars>,
pub active_price_ratio: ComputedRatioVecsDate,
pub true_market_mean: ComputedBlockLast<Dollars>,
pub true_market_mean_ratio: ComputedRatioVecsDate,
pub cointime_price: ComputedBlockLast<Dollars>,
pub cointime_price_ratio: ComputedRatioVecsDate,
pub vaulted_price: ComputedFromHeightLast<Dollars>,
pub vaulted_price_ratio: ComputedFromDateRatio,
pub active_price: ComputedFromHeightLast<Dollars>,
pub active_price_ratio: ComputedFromDateRatio,
pub true_market_mean: ComputedFromHeightLast<Dollars>,
pub true_market_mean_ratio: ComputedFromDateRatio,
pub cointime_price: ComputedFromHeightLast<Dollars>,
pub cointime_price_ratio: ComputedFromDateRatio,
}

View File

@@ -3,14 +3,13 @@ use vecdb::Exit;
use super::super::activity;
use super::Vecs;
use crate::{ComputeIndexes, distribution, indexes, price};
use crate::{ComputeIndexes, distribution, indexes};
impl Vecs {
pub fn compute(
&mut self,
indexes: &indexes::Vecs,
starting_indexes: &ComputeIndexes,
price: Option<&price::Vecs>,
distribution: &distribution::Vecs,
activity: &activity::Vecs,
exit: &Exit,
@@ -25,7 +24,7 @@ impl Vecs {
.height;
self.vaulted_supply
.compute_all(indexes, price, starting_indexes, exit, |vec| {
.compute_all(indexes, starting_indexes, exit, |vec| {
vec.compute_multiply(
starting_indexes.height,
circulating_supply,
@@ -36,7 +35,7 @@ impl Vecs {
})?;
self.active_supply
.compute_all(indexes, price, starting_indexes, exit, |vec| {
.compute_all(indexes, starting_indexes, exit, |vec| {
vec.compute_multiply(
starting_indexes.height,
circulating_supply,

View File

@@ -3,29 +3,29 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::ValueBlockLast};
use crate::{indexes, internal::ValueFromHeightLast, price};
impl Vecs {
pub fn forced_import(
db: &Database,
version: Version,
indexes: &indexes::Vecs,
compute_dollars: bool,
price: Option<&price::Vecs>,
) -> Result<Self> {
Ok(Self {
vaulted_supply: ValueBlockLast::forced_import(
vaulted_supply: ValueFromHeightLast::forced_import(
db,
"vaulted_supply",
version,
indexes,
compute_dollars,
price,
)?,
active_supply: ValueBlockLast::forced_import(
active_supply: ValueFromHeightLast::forced_import(
db,
"active_supply",
version,
indexes,
compute_dollars,
price,
)?,
})
}

View File

@@ -1,9 +1,9 @@
use brk_traversable::Traversable;
use crate::internal::ValueBlockLast;
use crate::internal::ValueFromHeightLast;
#[derive(Clone, Traversable)]
pub struct Vecs {
pub vaulted_supply: ValueBlockLast,
pub active_supply: ValueBlockLast,
pub vaulted_supply: ValueFromHeightLast,
pub active_supply: ValueFromHeightLast,
}

View File

@@ -3,24 +3,24 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::ComputedBlockSumCum};
use crate::{indexes, internal::ComputedFromHeightSumCum};
impl Vecs {
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
Ok(Self {
cointime_value_destroyed: ComputedBlockSumCum::forced_import(
cointime_value_destroyed: ComputedFromHeightSumCum::forced_import(
db,
"cointime_value_destroyed",
version,
indexes,
)?,
cointime_value_created: ComputedBlockSumCum::forced_import(
cointime_value_created: ComputedFromHeightSumCum::forced_import(
db,
"cointime_value_created",
version,
indexes,
)?,
cointime_value_stored: ComputedBlockSumCum::forced_import(
cointime_value_stored: ComputedFromHeightSumCum::forced_import(
db,
"cointime_value_stored",
version,

View File

@@ -1,11 +1,11 @@
use brk_traversable::Traversable;
use brk_types::StoredF64;
use crate::internal::ComputedBlockSumCum;
use crate::internal::ComputedFromHeightSumCum;
#[derive(Clone, Traversable)]
pub struct Vecs {
pub cointime_value_destroyed: ComputedBlockSumCum<StoredF64>,
pub cointime_value_created: ComputedBlockSumCum<StoredF64>,
pub cointime_value_stored: ComputedBlockSumCum<StoredF64>,
pub cointime_value_destroyed: ComputedFromHeightSumCum<StoredF64>,
pub cointime_value_created: ComputedFromHeightSumCum<StoredF64>,
pub cointime_value_stored: ComputedFromHeightSumCum<StoredF64>,
}

View File

@@ -8,7 +8,7 @@ use vecdb::{
AnyStoredVec, AnyVec, Database, EagerVec, Exit, GenericStoredVec, PcoVec, TypedVecIterator,
};
use crate::{ComputeIndexes, indexes, internal::ComputedBlockLast};
use crate::{ComputeIndexes, indexes, internal::ComputedFromHeightLast};
/// Address count per address type (runtime state).
#[derive(Debug, Default, Deref, DerefMut)]
@@ -78,11 +78,11 @@ impl From<(&AddressTypeToAddrCountVecs, Height)> for AddressTypeToAddressCount {
/// Address count per address type, with height + derived indexes.
#[derive(Clone, Deref, DerefMut, Traversable)]
pub struct AddressTypeToAddrCountVecs(ByAddressType<ComputedBlockLast<StoredU64>>);
pub struct AddressTypeToAddrCountVecs(ByAddressType<ComputedFromHeightLast<StoredU64>>);
impl From<ByAddressType<ComputedBlockLast<StoredU64>>> for AddressTypeToAddrCountVecs {
impl From<ByAddressType<ComputedFromHeightLast<StoredU64>>> for AddressTypeToAddrCountVecs {
#[inline]
fn from(value: ByAddressType<ComputedBlockLast<StoredU64>>) -> Self {
fn from(value: ByAddressType<ComputedFromHeightLast<StoredU64>>) -> Self {
Self(value)
}
}
@@ -95,8 +95,8 @@ impl AddressTypeToAddrCountVecs {
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self::from(
ByAddressType::<ComputedBlockLast<StoredU64>>::new_with_name(|type_name| {
ComputedBlockLast::forced_import(
ByAddressType::<ComputedFromHeightLast<StoredU64>>::new_with_name(|type_name| {
ComputedFromHeightLast::forced_import(
db,
&format!("{type_name}_{name}"),
version,
@@ -224,7 +224,7 @@ impl AddressTypeToAddrCountVecs {
#[derive(Clone, Traversable)]
pub struct AddrCountVecs {
pub all: ComputedBlockLast<StoredU64>,
pub all: ComputedFromHeightLast<StoredU64>,
#[traversable(flatten)]
pub by_addresstype: AddressTypeToAddrCountVecs,
}
@@ -237,7 +237,7 @@ impl AddrCountVecs {
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
all: ComputedBlockLast::forced_import(db, name, version, indexes)?,
all: ComputedFromHeightLast::forced_import(db, name, version, indexes)?,
by_addresstype: AddressTypeToAddrCountVecs::forced_import(db, name, version, indexes)?,
})
}

View File

@@ -1,3 +1,6 @@
use std::thread;
use brk_cohort::ByAddressType;
use brk_error::{Error, Result};
use brk_traversable::Traversable;
use brk_types::{
@@ -6,10 +9,14 @@ use brk_types::{
TypeIndex, Version,
};
use rayon::prelude::*;
use rustc_hash::FxHashMap;
use vecdb::{
AnyStoredVec, BytesVec, Database, GenericStoredVec, ImportOptions, ImportableVec, Reader, Stamp,
AnyStoredVec, AnyVec, BytesVec, Database, GenericStoredVec, ImportOptions, ImportableVec,
Reader, Stamp,
};
use super::super::AddressTypeToTypeIndexMap;
const SAVED_STAMPED_CHANGES: u16 = 10;
/// Macro to define AnyAddressIndexesVecs and its methods.
@@ -75,6 +82,31 @@ macro_rules! define_any_address_indexes_vecs {
Ok(())
}
/// Get length for a given address type.
pub fn len_of(&self, address_type: OutputType) -> usize {
match address_type {
$(OutputType::$variant => self.$field.len(),)*
_ => unreachable!("Invalid address type: {:?}", address_type),
}
}
/// Update existing entry (must be within bounds).
pub fn update(&mut self, address_type: OutputType, typeindex: TypeIndex, index: AnyAddressIndex) -> Result<()> {
match address_type {
$(OutputType::$variant => self.$field.update(typeindex.into(), index)?,)*
_ => unreachable!("Invalid address type: {:?}", address_type),
}
Ok(())
}
/// Push new entry (must be at exactly len position).
pub fn push(&mut self, address_type: OutputType, index: AnyAddressIndex) {
match address_type {
$(OutputType::$variant => self.$field.push(index),)*
_ => unreachable!("Invalid address type: {:?}", address_type),
}
}
/// Write all address types with stamp.
pub fn write(&mut self, stamp: Stamp, with_changes: bool) -> Result<()> {
$(self.$field.stamped_write_maybe_with_changes(stamp, with_changes)?;)*
@@ -100,3 +132,102 @@ define_any_address_indexes_vecs!(
(p2wpkh, P2WPKH, P2WPKHAddressIndex),
(p2wsh, P2WSH, P2WSHAddressIndex),
);
impl AnyAddressIndexesVecs {
/// Process index updates in parallel by address type.
/// Accepts two maps (e.g. from empty and loaded processing) and merges per-thread.
/// Updates existing entries and pushes new ones (sorted).
/// Returns (update_count, push_count).
pub fn par_batch_update(
&mut self,
updates1: AddressTypeToTypeIndexMap<AnyAddressIndex>,
updates2: AddressTypeToTypeIndexMap<AnyAddressIndex>,
) -> Result<(usize, usize)> {
let ByAddressType {
p2a: u1_p2a,
p2pk33: u1_p2pk33,
p2pk65: u1_p2pk65,
p2pkh: u1_p2pkh,
p2sh: u1_p2sh,
p2tr: u1_p2tr,
p2wpkh: u1_p2wpkh,
p2wsh: u1_p2wsh,
} = updates1.into_inner();
let ByAddressType {
p2a: u2_p2a,
p2pk33: u2_p2pk33,
p2pk65: u2_p2pk65,
p2pkh: u2_p2pkh,
p2sh: u2_p2sh,
p2tr: u2_p2tr,
p2wpkh: u2_p2wpkh,
p2wsh: u2_p2wsh,
} = updates2.into_inner();
let Self {
p2a,
p2pk33,
p2pk65,
p2pkh,
p2sh,
p2tr,
p2wpkh,
p2wsh,
} = self;
thread::scope(|s| {
let h_p2a = s.spawn(|| process_single_type_merged(p2a, u1_p2a, u2_p2a));
let h_p2pk33 = s.spawn(|| process_single_type_merged(p2pk33, u1_p2pk33, u2_p2pk33));
let h_p2pk65 = s.spawn(|| process_single_type_merged(p2pk65, u1_p2pk65, u2_p2pk65));
let h_p2pkh = s.spawn(|| process_single_type_merged(p2pkh, u1_p2pkh, u2_p2pkh));
let h_p2sh = s.spawn(|| process_single_type_merged(p2sh, u1_p2sh, u2_p2sh));
let h_p2tr = s.spawn(|| process_single_type_merged(p2tr, u1_p2tr, u2_p2tr));
let h_p2wpkh = s.spawn(|| process_single_type_merged(p2wpkh, u1_p2wpkh, u2_p2wpkh));
let h_p2wsh = s.spawn(|| process_single_type_merged(p2wsh, u1_p2wsh, u2_p2wsh));
let mut total_updates = 0usize;
let mut total_pushes = 0usize;
for h in [
h_p2a, h_p2pk33, h_p2pk65, h_p2pkh, h_p2sh, h_p2tr, h_p2wpkh, h_p2wsh,
] {
let (updates, pushes) = h.join().unwrap()?;
total_updates += updates;
total_pushes += pushes;
}
Ok((total_updates, total_pushes))
})
}
}
/// Process updates for a single address type's BytesVec, merging two maps.
fn process_single_type_merged<I: vecdb::VecIndex>(
vec: &mut BytesVec<I, AnyAddressIndex>,
map1: FxHashMap<TypeIndex, AnyAddressIndex>,
map2: FxHashMap<TypeIndex, AnyAddressIndex>,
) -> Result<(usize, usize)> {
let current_len = vec.len();
let mut pushes = Vec::with_capacity(map1.len() + map2.len());
let mut update_count = 0usize;
for (typeindex, any_index) in map1.into_iter().chain(map2) {
if usize::from(typeindex) < current_len {
vec.update(I::from(usize::from(typeindex)), any_index)?;
update_count += 1;
} else {
pushes.push((typeindex, any_index));
}
}
let push_count = pushes.len();
if !pushes.is_empty() {
pushes.sort_unstable_by_key(|(typeindex, _)| *typeindex);
for (_, any_index) in pushes {
vec.push(any_index);
}
}
Ok((update_count, push_count))
}

View File

@@ -92,6 +92,11 @@ impl<T> AddressTypeToTypeIndexMap<T> {
self.0.into_iter()
}
/// Consume and return the inner ByAddressType.
pub fn into_inner(self) -> ByAddressType<FxHashMap<TypeIndex, T>> {
self.0
}
/// Iterate mutably over entries by address type.
pub fn iter_mut(&mut self) -> impl Iterator<Item = (OutputType, &mut FxHashMap<TypeIndex, T>)> {
self.0.iter_mut()

View File

@@ -3,6 +3,7 @@ use brk_types::{
AnyAddressIndex, EmptyAddressData, EmptyAddressIndex, LoadedAddressData, LoadedAddressIndex,
OutputType, TypeIndex,
};
use vecdb::AnyVec;
use crate::distribution::{AddressTypeToTypeIndexMap, AddressesDataVecs};
@@ -51,9 +52,12 @@ pub fn process_loaded_addresses(
addresses_data.loaded.update(index, data)?;
}
// Phase 3: Pushes (fills holes, then grows)
let mut result = AddressTypeToTypeIndexMap::default();
for (address_type, typeindex, data) in pushes {
// Phase 3: Pushes (fill holes first, then pure pushes)
let mut result = AddressTypeToTypeIndexMap::with_capacity(pushes.len() / 4);
let holes_count = addresses_data.loaded.holes().len();
let mut pushes_iter = pushes.into_iter();
for (address_type, typeindex, data) in pushes_iter.by_ref().take(holes_count) {
let index = addresses_data.loaded.fill_first_hole_or_push(data)?;
result
.get_mut(address_type)
@@ -61,6 +65,18 @@ pub fn process_loaded_addresses(
.insert(typeindex, AnyAddressIndex::from(index));
}
// Pure pushes - no holes remain
addresses_data.loaded.reserve_pushed(pushes_iter.len());
let mut next_index = addresses_data.loaded.len();
for (address_type, typeindex, data) in pushes_iter {
addresses_data.loaded.push(data);
result
.get_mut(address_type)
.unwrap()
.insert(typeindex, AnyAddressIndex::from(LoadedAddressIndex::from(next_index)));
next_index += 1;
}
Ok(result)
}
@@ -107,9 +123,12 @@ pub fn process_empty_addresses(
addresses_data.empty.update(index, data)?;
}
// Phase 3: Pushes (fills holes, then grows)
let mut result = AddressTypeToTypeIndexMap::default();
for (address_type, typeindex, data) in pushes {
// Phase 3: Pushes (fill holes first, then pure pushes)
let mut result = AddressTypeToTypeIndexMap::with_capacity(pushes.len() / 4);
let holes_count = addresses_data.empty.holes().len();
let mut pushes_iter = pushes.into_iter();
for (address_type, typeindex, data) in pushes_iter.by_ref().take(holes_count) {
let index = addresses_data.empty.fill_first_hole_or_push(data)?;
result
.get_mut(address_type)
@@ -117,5 +136,17 @@ pub fn process_empty_addresses(
.insert(typeindex, AnyAddressIndex::from(index));
}
// Pure pushes - no holes remain
addresses_data.empty.reserve_pushed(pushes_iter.len());
let mut next_index = addresses_data.empty.len();
for (address_type, typeindex, data) in pushes_iter {
addresses_data.empty.push(data);
result
.get_mut(address_type)
.unwrap()
.insert(typeindex, AnyAddressIndex::from(EmptyAddressIndex::from(next_index)));
next_index += 1;
}
Ok(result)
}

View File

@@ -8,7 +8,7 @@ use rayon::prelude::*;
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, GenericStoredVec, IterableVec};
use crate::{
ComputeIndexes, distribution::state::AddressCohortState, indexes, internal::ComputedBlockLast,
ComputeIndexes, distribution::state::AddressCohortState, indexes, internal::ComputedFromHeightLast,
price,
};
@@ -32,7 +32,7 @@ pub struct AddressCohortVecs {
#[traversable(flatten)]
pub metrics: CohortMetrics,
pub addr_count: ComputedBlockLast<StoredU64>,
pub addr_count: ComputedFromHeightLast<StoredU64>,
}
impl AddressCohortVecs {
@@ -73,7 +73,7 @@ impl AddressCohortVecs {
metrics: CohortMetrics::forced_import(&cfg, all_supply)?,
addr_count: ComputedBlockLast::forced_import(
addr_count: ComputedFromHeightLast::forced_import(
db,
&cfg.name("addr_count"),
version + VERSION,

View File

@@ -33,15 +33,12 @@ pub fn process_address_updates(
) -> Result<()> {
info!("Processing address updates...");
let i = Instant::now();
let empty_result = process_empty_addresses(addresses_data, empty_updates)?;
let loaded_result = process_loaded_addresses(addresses_data, loaded_updates)?;
let all_updates = empty_result.merge(loaded_result);
address_indexes.par_batch_update(empty_result, loaded_result)?;
for (address_type, sorted) in all_updates.into_sorted_iter() {
for (typeindex, any_index) in sorted {
address_indexes.update_or_push(address_type, typeindex, any_index)?;
}
}
info!("Processed address updates in {:?}", i.elapsed());
Ok(())
}

View File

@@ -6,7 +6,7 @@ use vecdb::{AnyStoredVec, AnyVec, EagerVec, Exit, GenericStoredVec, ImportableVe
use crate::{
ComputeIndexes, indexes,
internal::{ComputedBlockSumCum, LazyComputedValueBlockSumCum},
internal::{ComputedFromHeightSumCum, LazyComputedValueFromHeightSumCum},
};
use super::ImportConfig;
@@ -15,7 +15,7 @@ use super::ImportConfig;
#[derive(Clone, Traversable)]
pub struct ActivityMetrics {
/// Total satoshis sent at each height + derived indexes
pub sent: LazyComputedValueBlockSumCum,
pub sent: LazyComputedValueFromHeightSumCum,
/// Satoshi-blocks destroyed (supply * blocks_old when spent)
pub satblocks_destroyed: EagerVec<PcoVec<Height, Sats>>,
@@ -24,17 +24,17 @@ pub struct ActivityMetrics {
pub satdays_destroyed: EagerVec<PcoVec<Height, Sats>>,
/// Coin-blocks destroyed (in BTC rather than sats)
pub coinblocks_destroyed: ComputedBlockSumCum<StoredF64>,
pub coinblocks_destroyed: ComputedFromHeightSumCum<StoredF64>,
/// Coin-days destroyed (in BTC rather than sats)
pub coindays_destroyed: ComputedBlockSumCum<StoredF64>,
pub coindays_destroyed: ComputedFromHeightSumCum<StoredF64>,
}
impl ActivityMetrics {
/// Import activity metrics from database.
pub fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(Self {
sent: LazyComputedValueBlockSumCum::forced_import(
sent: LazyComputedValueFromHeightSumCum::forced_import(
cfg.db,
&cfg.name("sent"),
cfg.version,
@@ -54,14 +54,14 @@ impl ActivityMetrics {
cfg.version,
)?,
coinblocks_destroyed: ComputedBlockSumCum::forced_import(
coinblocks_destroyed: ComputedFromHeightSumCum::forced_import(
cfg.db,
&cfg.name("coinblocks_destroyed"),
cfg.version,
cfg.indexes,
)?,
coindays_destroyed: ComputedBlockSumCum::forced_import(
coindays_destroyed: ComputedFromHeightSumCum::forced_import(
cfg.db,
&cfg.name("coindays_destroyed"),
cfg.version,

View File

@@ -8,7 +8,7 @@ use crate::{
ComputeIndexes,
distribution::state::CohortState,
indexes,
internal::{ComputedBlockLast, CostBasisPercentiles},
internal::{ComputedFromHeightLast, CostBasisPercentiles},
};
use super::ImportConfig;
@@ -17,10 +17,10 @@ use super::ImportConfig;
#[derive(Clone, Traversable)]
pub struct CostBasisMetrics {
/// Minimum cost basis for any UTXO at this height
pub min: ComputedBlockLast<Dollars>,
pub min: ComputedFromHeightLast<Dollars>,
/// Maximum cost basis for any UTXO at this height
pub max: ComputedBlockLast<Dollars>,
pub max: ComputedFromHeightLast<Dollars>,
/// Cost basis distribution percentiles (median, quartiles, etc.)
pub percentiles: Option<CostBasisPercentiles>,
@@ -32,13 +32,13 @@ impl CostBasisMetrics {
let extended = cfg.extended();
Ok(Self {
min: ComputedBlockLast::forced_import(
min: ComputedFromHeightLast::forced_import(
cfg.db,
&cfg.name("min_cost_basis"),
cfg.version,
cfg.indexes,
)?,
max: ComputedBlockLast::forced_import(
max: ComputedFromHeightLast::forced_import(
cfg.db,
&cfg.name("max_cost_basis"),
cfg.version,

View File

@@ -313,7 +313,7 @@ impl CohortMetrics {
exit: &Exit,
) -> Result<()> {
self.supply
.compute_rest_part1(indexes, price, starting_indexes, exit)?;
.compute_rest_part1(indexes, starting_indexes, exit)?;
self.outputs.compute_rest(indexes, starting_indexes, exit)?;
self.activity
.compute_rest_part1(indexes, starting_indexes, exit)?;

View File

@@ -4,21 +4,21 @@ use brk_types::{Height, StoredU64};
use rayon::prelude::*;
use vecdb::{AnyStoredVec, AnyVec, Exit, GenericStoredVec};
use crate::{ComputeIndexes, indexes, internal::ComputedBlockLast};
use crate::{ComputeIndexes, indexes, internal::ComputedFromHeightLast};
use super::ImportConfig;
/// Output metrics for a cohort.
#[derive(Clone, Traversable)]
pub struct OutputsMetrics {
pub utxo_count: ComputedBlockLast<StoredU64>,
pub utxo_count: ComputedFromHeightLast<StoredU64>,
}
impl OutputsMetrics {
/// Import output metrics from database.
pub fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(Self {
utxo_count: ComputedBlockLast::forced_import(
utxo_count: ComputedFromHeightLast::forced_import(
cfg.db,
&cfg.name("utxo_count"),
cfg.version,

View File

@@ -12,9 +12,9 @@ use crate::{
distribution::state::RealizedState,
indexes,
internal::{
ComputedBlockLast, ComputedBlockSum, ComputedBlockSumCum, ComputedDateLast,
ComputedRatioVecsDate, DollarsMinus, LazyBinaryBlockSum, LazyBinaryBlockSumCum,
LazyBlockSum, LazyBlockSumCum, LazyDateLast, PercentageDollarsF32, StoredF32Identity,
ComputedFromHeightLast, ComputedFromHeightSum, ComputedFromHeightSumCum, ComputedFromDateLast,
ComputedFromDateRatio, DollarsMinus, LazyBinaryFromHeightSum, LazyBinaryFromHeightSumCum,
LazyFromHeightSum, LazyFromHeightSumCum, LazyFromDateLast, PercentageDollarsF32, StoredF32Identity,
},
price,
};
@@ -25,39 +25,39 @@ use super::ImportConfig;
#[derive(Clone, Traversable)]
pub struct RealizedMetrics {
// === Realized Cap ===
pub realized_cap: ComputedBlockLast<Dollars>,
pub realized_price: ComputedBlockLast<Dollars>,
pub realized_price_extra: ComputedRatioVecsDate,
pub realized_cap_rel_to_own_market_cap: Option<ComputedBlockLast<StoredF32>>,
pub realized_cap_30d_delta: ComputedDateLast<Dollars>,
pub realized_cap: ComputedFromHeightLast<Dollars>,
pub realized_price: ComputedFromHeightLast<Dollars>,
pub realized_price_extra: ComputedFromDateRatio,
pub realized_cap_rel_to_own_market_cap: Option<ComputedFromHeightLast<StoredF32>>,
pub realized_cap_30d_delta: ComputedFromDateLast<Dollars>,
// === MVRV (Market Value to Realized Value) ===
// Proxy for realized_price_extra.ratio (close / realized_price = market_cap / realized_cap)
pub mvrv: LazyDateLast<StoredF32>,
pub mvrv: LazyFromDateLast<StoredF32>,
// === Realized Profit/Loss ===
pub realized_profit: ComputedBlockSumCum<Dollars>,
pub realized_loss: ComputedBlockSumCum<Dollars>,
pub neg_realized_loss: LazyBlockSumCum<Dollars>,
pub net_realized_pnl: ComputedBlockSumCum<Dollars>,
pub realized_value: ComputedBlockSum<Dollars>,
pub realized_profit: ComputedFromHeightSumCum<Dollars>,
pub realized_loss: ComputedFromHeightSumCum<Dollars>,
pub neg_realized_loss: LazyFromHeightSumCum<Dollars>,
pub net_realized_pnl: ComputedFromHeightSumCum<Dollars>,
pub realized_value: ComputedFromHeightSum<Dollars>,
// === Realized vs Realized Cap Ratios (lazy) ===
pub realized_profit_rel_to_realized_cap: LazyBinaryBlockSumCum<StoredF32, Dollars, Dollars>,
pub realized_loss_rel_to_realized_cap: LazyBinaryBlockSumCum<StoredF32, Dollars, Dollars>,
pub net_realized_pnl_rel_to_realized_cap: LazyBinaryBlockSumCum<StoredF32, Dollars, Dollars>,
pub realized_profit_rel_to_realized_cap: LazyBinaryFromHeightSumCum<StoredF32, Dollars, Dollars>,
pub realized_loss_rel_to_realized_cap: LazyBinaryFromHeightSumCum<StoredF32, Dollars, Dollars>,
pub net_realized_pnl_rel_to_realized_cap: LazyBinaryFromHeightSumCum<StoredF32, Dollars, Dollars>,
// === Total Realized PnL ===
pub total_realized_pnl: LazyBlockSum<Dollars>,
pub total_realized_pnl: LazyFromHeightSum<Dollars>,
pub realized_profit_to_loss_ratio: Option<EagerVec<PcoVec<DateIndex, StoredF64>>>,
// === Value Created/Destroyed ===
pub value_created: ComputedBlockSum<Dollars>,
pub value_destroyed: ComputedBlockSum<Dollars>,
pub value_created: ComputedFromHeightSum<Dollars>,
pub value_destroyed: ComputedFromHeightSum<Dollars>,
// === Adjusted Value (lazy: cohort - up_to_1h) ===
pub adjusted_value_created: Option<LazyBinaryBlockSum<Dollars, Dollars, Dollars>>,
pub adjusted_value_destroyed: Option<LazyBinaryBlockSum<Dollars, Dollars, Dollars>>,
pub adjusted_value_created: Option<LazyBinaryFromHeightSum<Dollars, Dollars, Dollars>>,
pub adjusted_value_destroyed: Option<LazyBinaryFromHeightSum<Dollars, Dollars, Dollars>>,
// === SOPR (Spent Output Profit Ratio) ===
pub sopr: EagerVec<PcoVec<DateIndex, StoredF64>>,
@@ -73,9 +73,9 @@ pub struct RealizedMetrics {
pub sell_side_risk_ratio_30d_ema: EagerVec<PcoVec<DateIndex, StoredF32>>,
// === Net Realized PnL Deltas ===
pub net_realized_pnl_cumulative_30d_delta: ComputedDateLast<Dollars>,
pub net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap: ComputedDateLast<StoredF32>,
pub net_realized_pnl_cumulative_30d_delta_rel_to_market_cap: ComputedDateLast<StoredF32>,
pub net_realized_pnl_cumulative_30d_delta: ComputedFromDateLast<Dollars>,
pub net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap: ComputedFromDateLast<StoredF32>,
pub net_realized_pnl_cumulative_30d_delta_rel_to_market_cap: ComputedFromDateLast<StoredF32>,
}
impl RealizedMetrics {
@@ -87,35 +87,35 @@ impl RealizedMetrics {
let compute_adjusted = cfg.compute_adjusted();
// Import combined types using forced_import which handles height + derived
let realized_cap = ComputedBlockLast::forced_import(
let realized_cap = ComputedFromHeightLast::forced_import(
cfg.db,
&cfg.name("realized_cap"),
cfg.version,
cfg.indexes,
)?;
let realized_profit = ComputedBlockSumCum::forced_import(
let realized_profit = ComputedFromHeightSumCum::forced_import(
cfg.db,
&cfg.name("realized_profit"),
cfg.version,
cfg.indexes,
)?;
let realized_loss = ComputedBlockSumCum::forced_import(
let realized_loss = ComputedFromHeightSumCum::forced_import(
cfg.db,
&cfg.name("realized_loss"),
cfg.version,
cfg.indexes,
)?;
let neg_realized_loss = LazyBlockSumCum::from_computed::<Negate>(
let neg_realized_loss = LazyFromHeightSumCum::from_computed::<Negate>(
&cfg.name("neg_realized_loss"),
cfg.version + v1,
realized_loss.height.boxed_clone(),
&realized_loss,
);
let net_realized_pnl = ComputedBlockSumCum::forced_import(
let net_realized_pnl = ComputedFromHeightSumCum::forced_import(
cfg.db,
&cfg.name("net_realized_pnl"),
cfg.version,
@@ -123,7 +123,7 @@ impl RealizedMetrics {
)?;
// realized_value is the source for total_realized_pnl (they're identical)
let realized_value = ComputedBlockSum::forced_import(
let realized_value = ComputedFromHeightSum::forced_import(
cfg.db,
&cfg.name("realized_value"),
cfg.version,
@@ -131,7 +131,7 @@ impl RealizedMetrics {
)?;
// total_realized_pnl is a lazy alias to realized_value
let total_realized_pnl = LazyBlockSum::from_computed::<Ident>(
let total_realized_pnl = LazyFromHeightSum::from_computed::<Ident>(
&cfg.name("total_realized_pnl"),
cfg.version + v1,
realized_value.height.boxed_clone(),
@@ -140,7 +140,7 @@ impl RealizedMetrics {
// Construct lazy ratio vecs
let realized_profit_rel_to_realized_cap =
LazyBinaryBlockSumCum::from_computed_last::<PercentageDollarsF32>(
LazyBinaryFromHeightSumCum::from_computed_last::<PercentageDollarsF32>(
&cfg.name("realized_profit_rel_to_realized_cap"),
cfg.version + v1,
realized_profit.height.boxed_clone(),
@@ -150,7 +150,7 @@ impl RealizedMetrics {
);
let realized_loss_rel_to_realized_cap =
LazyBinaryBlockSumCum::from_computed_last::<PercentageDollarsF32>(
LazyBinaryFromHeightSumCum::from_computed_last::<PercentageDollarsF32>(
&cfg.name("realized_loss_rel_to_realized_cap"),
cfg.version + v1,
realized_loss.height.boxed_clone(),
@@ -160,7 +160,7 @@ impl RealizedMetrics {
);
let net_realized_pnl_rel_to_realized_cap =
LazyBinaryBlockSumCum::from_computed_last::<PercentageDollarsF32>(
LazyBinaryFromHeightSumCum::from_computed_last::<PercentageDollarsF32>(
&cfg.name("net_realized_pnl_rel_to_realized_cap"),
cfg.version + v1,
net_realized_pnl.height.boxed_clone(),
@@ -169,21 +169,21 @@ impl RealizedMetrics {
&realized_cap,
);
let realized_price = ComputedBlockLast::forced_import(
let realized_price = ComputedFromHeightLast::forced_import(
cfg.db,
&cfg.name("realized_price"),
cfg.version + v1,
cfg.indexes,
)?;
let value_created = ComputedBlockSum::forced_import(
let value_created = ComputedFromHeightSum::forced_import(
cfg.db,
&cfg.name("value_created"),
cfg.version,
cfg.indexes,
)?;
let value_destroyed = ComputedBlockSum::forced_import(
let value_destroyed = ComputedFromHeightSum::forced_import(
cfg.db,
&cfg.name("value_destroyed"),
cfg.version,
@@ -194,7 +194,7 @@ impl RealizedMetrics {
let adjusted_value_created =
(compute_adjusted && cfg.up_to_1h_realized.is_some()).then(|| {
let up_to_1h = cfg.up_to_1h_realized.unwrap();
LazyBinaryBlockSum::from_computed::<DollarsMinus>(
LazyBinaryFromHeightSum::from_computed::<DollarsMinus>(
&cfg.name("adjusted_value_created"),
cfg.version,
&value_created,
@@ -204,7 +204,7 @@ impl RealizedMetrics {
let adjusted_value_destroyed =
(compute_adjusted && cfg.up_to_1h_realized.is_some()).then(|| {
let up_to_1h = cfg.up_to_1h_realized.unwrap();
LazyBinaryBlockSum::from_computed::<DollarsMinus>(
LazyBinaryFromHeightSum::from_computed::<DollarsMinus>(
&cfg.name("adjusted_value_destroyed"),
cfg.version,
&value_destroyed,
@@ -213,7 +213,7 @@ impl RealizedMetrics {
});
// Create realized_price_extra first so we can reference its ratio for MVRV proxy
let realized_price_extra = ComputedRatioVecsDate::forced_import(
let realized_price_extra = ComputedFromDateRatio::forced_import(
cfg.db,
&cfg.name("realized_price"),
Some(&realized_price),
@@ -225,7 +225,7 @@ impl RealizedMetrics {
// MVRV is a lazy proxy for realized_price_extra.ratio
// ratio = close / realized_price = market_cap / realized_cap = MVRV
let mvrv = LazyDateLast::from_source::<StoredF32Identity>(
let mvrv = LazyFromDateLast::from_source::<StoredF32Identity>(
&cfg.name("mvrv"),
cfg.version,
&realized_price_extra.ratio,
@@ -238,7 +238,7 @@ impl RealizedMetrics {
realized_price_extra,
realized_cap_rel_to_own_market_cap: extended
.then(|| {
ComputedBlockLast::forced_import(
ComputedFromHeightLast::forced_import(
cfg.db,
&cfg.name("realized_cap_rel_to_own_market_cap"),
cfg.version,
@@ -246,7 +246,7 @@ impl RealizedMetrics {
)
})
.transpose()?,
realized_cap_30d_delta: ComputedDateLast::forced_import(
realized_cap_30d_delta: ComputedFromDateLast::forced_import(
cfg.db,
&cfg.name("realized_cap_30d_delta"),
cfg.version,
@@ -338,21 +338,21 @@ impl RealizedMetrics {
)?,
// === Net Realized PnL Deltas ===
net_realized_pnl_cumulative_30d_delta: ComputedDateLast::forced_import(
net_realized_pnl_cumulative_30d_delta: ComputedFromDateLast::forced_import(
cfg.db,
&cfg.name("net_realized_pnl_cumulative_30d_delta"),
cfg.version + v3,
cfg.indexes,
)?,
net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap:
ComputedDateLast::forced_import(
ComputedFromDateLast::forced_import(
cfg.db,
&cfg.name("net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap"),
cfg.version + v3,
cfg.indexes,
)?,
net_realized_pnl_cumulative_30d_delta_rel_to_market_cap:
ComputedDateLast::forced_import(
ComputedFromDateLast::forced_import(
cfg.db,
&cfg.name("net_realized_pnl_cumulative_30d_delta_rel_to_market_cap"),
cfg.version + v3,

View File

@@ -4,7 +4,7 @@ use brk_types::{Dollars, Sats, StoredF32, StoredF64, Version};
use vecdb::IterableCloneableVec;
use crate::internal::{
LazyBinaryBlockLast, LazyBinaryDateLast, NegPercentageDollarsF32, NegRatio32,
LazyBinaryFromHeightLast, LazyBinaryFromDateLast, NegPercentageDollarsF32, NegRatio32,
PercentageDollarsF32, PercentageSatsF64, Ratio32,
};
@@ -15,49 +15,49 @@ use super::{ImportConfig, SupplyMetrics, UnrealizedMetrics};
#[derive(Clone, Traversable)]
pub struct RelativeMetrics {
// === Supply Relative to Circulating Supply (lazy from global supply) ===
pub supply_rel_to_circulating_supply: Option<LazyBinaryDateLast<StoredF64, Sats, Sats>>,
pub supply_rel_to_circulating_supply: Option<LazyBinaryFromDateLast<StoredF64, Sats, Sats>>,
// === Supply in Profit/Loss Relative to Own Supply (lazy) ===
pub supply_in_profit_rel_to_own_supply: LazyBinaryBlockLast<StoredF64, Sats, Sats>,
pub supply_in_loss_rel_to_own_supply: LazyBinaryBlockLast<StoredF64, Sats, Sats>,
pub supply_in_profit_rel_to_own_supply: LazyBinaryFromHeightLast<StoredF64, Sats, Sats>,
pub supply_in_loss_rel_to_own_supply: LazyBinaryFromHeightLast<StoredF64, Sats, Sats>,
// === Supply in Profit/Loss Relative to Circulating Supply (lazy from global supply) ===
pub supply_in_profit_rel_to_circulating_supply:
Option<LazyBinaryBlockLast<StoredF64, Sats, Sats>>,
Option<LazyBinaryFromHeightLast<StoredF64, Sats, Sats>>,
pub supply_in_loss_rel_to_circulating_supply:
Option<LazyBinaryBlockLast<StoredF64, Sats, Sats>>,
Option<LazyBinaryFromHeightLast<StoredF64, Sats, Sats>>,
// === Unrealized vs Market Cap (lazy from global market cap) ===
pub unrealized_profit_rel_to_market_cap:
Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
pub unrealized_loss_rel_to_market_cap: Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
pub unrealized_loss_rel_to_market_cap: Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
pub neg_unrealized_loss_rel_to_market_cap:
Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
pub net_unrealized_pnl_rel_to_market_cap:
Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
// === NUPL (Net Unrealized Profit/Loss) ===
pub nupl: Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
pub nupl: Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
// === Unrealized vs Own Market Cap (lazy) ===
pub unrealized_profit_rel_to_own_market_cap:
Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
pub unrealized_loss_rel_to_own_market_cap:
Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
pub neg_unrealized_loss_rel_to_own_market_cap:
Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
pub net_unrealized_pnl_rel_to_own_market_cap:
Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
// === Unrealized vs Own Total Unrealized PnL (lazy) ===
pub unrealized_profit_rel_to_own_total_unrealized_pnl:
Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
pub unrealized_loss_rel_to_own_total_unrealized_pnl:
Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
pub neg_unrealized_loss_rel_to_own_total_unrealized_pnl:
Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
pub net_unrealized_pnl_rel_to_own_total_unrealized_pnl:
Option<LazyBinaryBlockLast<StoredF32, Dollars, Dollars>>,
Option<LazyBinaryFromHeightLast<StoredF32, Dollars, Dollars>>,
}
impl RelativeMetrics {
@@ -91,7 +91,7 @@ impl RelativeMetrics {
supply_rel_to_circulating_supply: (compute_rel_to_all
&& global_supply_sats_dates.is_some())
.then(|| {
LazyBinaryDateLast::from_both_derived_last::<PercentageSatsF64>(
LazyBinaryFromDateLast::from_both_derived_last::<PercentageSatsF64>(
&cfg.name("supply_rel_to_circulating_supply"),
cfg.version + v1,
supply.total.sats.rest.dateindex.boxed_clone(),
@@ -103,7 +103,7 @@ impl RelativeMetrics {
// === Supply in Profit/Loss Relative to Own Supply (lazy) ===
supply_in_profit_rel_to_own_supply:
LazyBinaryBlockLast::from_height_difficultyepoch_dates::<PercentageSatsF64>(
LazyBinaryFromHeightLast::from_height_difficultyepoch_dates::<PercentageSatsF64>(
&cfg.name("supply_in_profit_rel_to_own_supply"),
cfg.version + v1,
unrealized.supply_in_profit.height.boxed_clone(),
@@ -120,7 +120,7 @@ impl RelativeMetrics {
&supply.total.sats.rest.dates,
),
supply_in_loss_rel_to_own_supply:
LazyBinaryBlockLast::from_height_difficultyepoch_dates::<PercentageSatsF64>(
LazyBinaryFromHeightLast::from_height_difficultyepoch_dates::<PercentageSatsF64>(
&cfg.name("supply_in_loss_rel_to_own_supply"),
cfg.version + v1,
unrealized.supply_in_loss.height.boxed_clone(),
@@ -141,7 +141,7 @@ impl RelativeMetrics {
supply_in_profit_rel_to_circulating_supply: (compute_rel_to_all
&& global_supply_sats_height.is_some())
.then(|| {
LazyBinaryBlockLast::from_height_difficultyepoch_dates::<PercentageSatsF64>(
LazyBinaryFromHeightLast::from_height_difficultyepoch_dates::<PercentageSatsF64>(
&cfg.name("supply_in_profit_rel_to_circulating_supply"),
cfg.version + v1,
unrealized.supply_in_profit.height.boxed_clone(),
@@ -161,7 +161,7 @@ impl RelativeMetrics {
supply_in_loss_rel_to_circulating_supply: (compute_rel_to_all
&& global_supply_sats_height.is_some())
.then(|| {
LazyBinaryBlockLast::from_height_difficultyepoch_dates::<PercentageSatsF64>(
LazyBinaryFromHeightLast::from_height_difficultyepoch_dates::<PercentageSatsF64>(
&cfg.name("supply_in_loss_rel_to_circulating_supply"),
cfg.version + v1,
unrealized.supply_in_loss.height.boxed_clone(),
@@ -182,8 +182,10 @@ impl RelativeMetrics {
// === Unrealized vs Market Cap (lazy from global market cap) ===
unrealized_profit_rel_to_market_cap:
global_market_cap.map(|mc| {
LazyBinaryBlockLast::from_computed_height_date_and_block_last::<
LazyBinaryFromHeightLast::from_computed_height_date_and_lazy_binary_block_last::<
PercentageDollarsF32,
_,
_,
>(
&cfg.name("unrealized_profit_rel_to_market_cap"),
cfg.version + v2,
@@ -193,8 +195,10 @@ impl RelativeMetrics {
}),
unrealized_loss_rel_to_market_cap:
global_market_cap.map(|mc| {
LazyBinaryBlockLast::from_computed_height_date_and_block_last::<
LazyBinaryFromHeightLast::from_computed_height_date_and_lazy_binary_block_last::<
PercentageDollarsF32,
_,
_,
>(
&cfg.name("unrealized_loss_rel_to_market_cap"),
cfg.version + v2,
@@ -203,8 +207,10 @@ impl RelativeMetrics {
)
}),
neg_unrealized_loss_rel_to_market_cap: global_market_cap.map(|mc| {
LazyBinaryBlockLast::from_computed_height_date_and_block_last::<
LazyBinaryFromHeightLast::from_computed_height_date_and_lazy_binary_block_last::<
NegPercentageDollarsF32,
_,
_,
>(
&cfg.name("neg_unrealized_loss_rel_to_market_cap"),
cfg.version + v2,
@@ -213,10 +219,12 @@ impl RelativeMetrics {
)
}),
net_unrealized_pnl_rel_to_market_cap: global_market_cap.map(|mc| {
LazyBinaryBlockLast::from_binary_block_and_computed_block_last::<
LazyBinaryFromHeightLast::from_binary_block_and_lazy_binary_block_last::<
PercentageDollarsF32,
_,
_,
_,
_,
>(
&cfg.name("net_unrealized_pnl_rel_to_market_cap"),
cfg.version + v2,
@@ -227,10 +235,12 @@ impl RelativeMetrics {
// NUPL is a proxy for net_unrealized_pnl_rel_to_market_cap
nupl: global_market_cap.map(|mc| {
LazyBinaryBlockLast::from_binary_block_and_computed_block_last::<
LazyBinaryFromHeightLast::from_binary_block_and_lazy_binary_block_last::<
PercentageDollarsF32,
_,
_,
_,
_,
>(
&cfg.name("nupl"),
cfg.version + v2,
@@ -243,8 +253,10 @@ impl RelativeMetrics {
unrealized_profit_rel_to_own_market_cap: (extended && compute_rel_to_all)
.then(|| {
own_market_cap.map(|mc| {
LazyBinaryBlockLast::from_computed_height_date_and_block_last::<
LazyBinaryFromHeightLast::from_computed_height_date_and_lazy_binary_block_last::<
PercentageDollarsF32,
_,
_,
>(
&cfg.name("unrealized_profit_rel_to_own_market_cap"),
cfg.version + v2,
@@ -257,8 +269,10 @@ impl RelativeMetrics {
unrealized_loss_rel_to_own_market_cap: (extended && compute_rel_to_all)
.then(|| {
own_market_cap.map(|mc| {
LazyBinaryBlockLast::from_computed_height_date_and_block_last::<
LazyBinaryFromHeightLast::from_computed_height_date_and_lazy_binary_block_last::<
PercentageDollarsF32,
_,
_,
>(
&cfg.name("unrealized_loss_rel_to_own_market_cap"),
cfg.version + v2,
@@ -271,8 +285,10 @@ impl RelativeMetrics {
neg_unrealized_loss_rel_to_own_market_cap: (extended && compute_rel_to_all)
.then(|| {
own_market_cap.map(|mc| {
LazyBinaryBlockLast::from_computed_height_date_and_block_last::<
LazyBinaryFromHeightLast::from_computed_height_date_and_lazy_binary_block_last::<
NegPercentageDollarsF32,
_,
_,
>(
&cfg.name("neg_unrealized_loss_rel_to_own_market_cap"),
cfg.version + v2,
@@ -285,10 +301,12 @@ impl RelativeMetrics {
net_unrealized_pnl_rel_to_own_market_cap: (extended && compute_rel_to_all)
.then(|| {
own_market_cap.map(|mc| {
LazyBinaryBlockLast::from_binary_block_and_computed_block_last::<
LazyBinaryFromHeightLast::from_binary_block_and_lazy_binary_block_last::<
PercentageDollarsF32,
_,
_,
_,
_,
>(
&cfg.name("net_unrealized_pnl_rel_to_own_market_cap"),
cfg.version + v2,
@@ -301,7 +319,7 @@ impl RelativeMetrics {
// === Unrealized vs Own Total Unrealized PnL (lazy, optional) ===
unrealized_profit_rel_to_own_total_unrealized_pnl: extended.then(|| {
LazyBinaryBlockLast::from_computed_height_date_and_binary_block::<Ratio32, _, _>(
LazyBinaryFromHeightLast::from_computed_height_date_and_binary_block::<Ratio32, _, _>(
&cfg.name("unrealized_profit_rel_to_own_total_unrealized_pnl"),
cfg.version,
&unrealized.unrealized_profit,
@@ -309,7 +327,7 @@ impl RelativeMetrics {
)
}),
unrealized_loss_rel_to_own_total_unrealized_pnl: extended.then(|| {
LazyBinaryBlockLast::from_computed_height_date_and_binary_block::<Ratio32, _, _>(
LazyBinaryFromHeightLast::from_computed_height_date_and_binary_block::<Ratio32, _, _>(
&cfg.name("unrealized_loss_rel_to_own_total_unrealized_pnl"),
cfg.version,
&unrealized.unrealized_loss,
@@ -317,7 +335,7 @@ impl RelativeMetrics {
)
}),
neg_unrealized_loss_rel_to_own_total_unrealized_pnl: extended.then(|| {
LazyBinaryBlockLast::from_computed_height_date_and_binary_block::<NegRatio32, _, _>(
LazyBinaryFromHeightLast::from_computed_height_date_and_binary_block::<NegRatio32, _, _>(
&cfg.name("neg_unrealized_loss_rel_to_own_total_unrealized_pnl"),
cfg.version,
&unrealized.unrealized_loss,
@@ -325,7 +343,7 @@ impl RelativeMetrics {
)
}),
net_unrealized_pnl_rel_to_own_total_unrealized_pnl: extended.then(|| {
LazyBinaryBlockLast::from_both_binary_block::<Ratio32, _, _, _, _>(
LazyBinaryFromHeightLast::from_both_binary_block::<Ratio32, _, _, _, _>(
&cfg.name("net_unrealized_pnl_rel_to_own_total_unrealized_pnl"),
cfg.version + v1,
&unrealized.net_unrealized_pnl,

View File

@@ -9,10 +9,9 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, GenericStoredVec};
use crate::{
indexes,
internal::{
HalfClosePriceTimesSats, HalveDollars, HalveSats, HalveSatsToBitcoin, LazyBinaryValueBlockLast,
ValueBlockLast,
HalfClosePriceTimesSats, HalveDollars, HalveSats, HalveSatsToBitcoin, LazyBinaryValueFromHeightLast,
ValueFromHeightLast,
},
price,
};
use super::ImportConfig;
@@ -20,24 +19,22 @@ use super::ImportConfig;
/// Supply metrics for a cohort.
#[derive(Clone, Traversable)]
pub struct SupplyMetrics {
pub total: ValueBlockLast,
pub halved: LazyBinaryValueBlockLast,
pub total: ValueFromHeightLast,
pub halved: LazyBinaryValueFromHeightLast,
}
impl SupplyMetrics {
/// Import supply metrics from database.
pub fn forced_import(cfg: &ImportConfig) -> Result<Self> {
let compute_dollars = cfg.compute_dollars();
let supply = ValueBlockLast::forced_import(
let supply = ValueFromHeightLast::forced_import(
cfg.db,
&cfg.name("supply"),
cfg.version,
cfg.indexes,
compute_dollars,
cfg.price,
)?;
let supply_half = LazyBinaryValueBlockLast::from_block_source::<
let supply_half = LazyBinaryValueFromHeightLast::from_block_source::<
HalveSats,
HalveSatsToBitcoin,
HalfClosePriceTimesSats,
@@ -100,11 +97,9 @@ impl SupplyMetrics {
pub fn compute_rest_part1(
&mut self,
indexes: &indexes::Vecs,
price: Option<&price::Vecs>,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.total
.compute_rest(indexes, price, starting_indexes, exit)
self.total.compute_rest(indexes, starting_indexes, exit)
}
}

View File

@@ -8,8 +8,8 @@ use crate::{
ComputeIndexes,
distribution::state::UnrealizedState,
internal::{
ComputedHeightDateLast, DollarsMinus, DollarsPlus, LazyBinaryBlockLast, LazyBlockLast,
ValueHeightDateLast,
ComputedFromHeightAndDateLast, DollarsMinus, DollarsPlus, LazyBinaryFromHeightLast, LazyFromHeightLast,
ValueFromHeightAndDateLast,
},
};
@@ -19,19 +19,19 @@ use super::ImportConfig;
#[derive(Clone, Traversable)]
pub struct UnrealizedMetrics {
// === Supply in Profit/Loss ===
pub supply_in_profit: ValueHeightDateLast,
pub supply_in_loss: ValueHeightDateLast,
pub supply_in_profit: ValueFromHeightAndDateLast,
pub supply_in_loss: ValueFromHeightAndDateLast,
// === Unrealized Profit/Loss ===
pub unrealized_profit: ComputedHeightDateLast<Dollars>,
pub unrealized_loss: ComputedHeightDateLast<Dollars>,
pub unrealized_profit: ComputedFromHeightAndDateLast<Dollars>,
pub unrealized_loss: ComputedFromHeightAndDateLast<Dollars>,
// === Negated ===
pub neg_unrealized_loss: LazyBlockLast<Dollars>,
pub neg_unrealized_loss: LazyFromHeightLast<Dollars>,
// === Net and Total ===
pub net_unrealized_pnl: LazyBinaryBlockLast<Dollars>,
pub total_unrealized_pnl: LazyBinaryBlockLast<Dollars>,
pub net_unrealized_pnl: LazyBinaryFromHeightLast<Dollars>,
pub total_unrealized_pnl: LazyBinaryFromHeightLast<Dollars>,
}
impl UnrealizedMetrics {
@@ -40,7 +40,7 @@ impl UnrealizedMetrics {
let compute_dollars = cfg.compute_dollars();
// === Supply in Profit/Loss ===
let supply_in_profit = ValueHeightDateLast::forced_import(
let supply_in_profit = ValueFromHeightAndDateLast::forced_import(
cfg.db,
&cfg.name("supply_in_profit"),
cfg.version,
@@ -48,7 +48,7 @@ impl UnrealizedMetrics {
cfg.indexes,
cfg.price,
)?;
let supply_in_loss = ValueHeightDateLast::forced_import(
let supply_in_loss = ValueFromHeightAndDateLast::forced_import(
cfg.db,
&cfg.name("supply_in_loss"),
cfg.version,
@@ -58,13 +58,13 @@ impl UnrealizedMetrics {
)?;
// === Unrealized Profit/Loss ===
let unrealized_profit = ComputedHeightDateLast::forced_import(
let unrealized_profit = ComputedFromHeightAndDateLast::forced_import(
cfg.db,
&cfg.name("unrealized_profit"),
cfg.version,
cfg.indexes,
)?;
let unrealized_loss = ComputedHeightDateLast::forced_import(
let unrealized_loss = ComputedFromHeightAndDateLast::forced_import(
cfg.db,
&cfg.name("unrealized_loss"),
cfg.version,
@@ -72,20 +72,20 @@ impl UnrealizedMetrics {
)?;
// === Negated ===
let neg_unrealized_loss = LazyBlockLast::from_computed_height_date::<Negate>(
let neg_unrealized_loss = LazyFromHeightLast::from_computed_height_date::<Negate>(
&cfg.name("neg_unrealized_loss"),
cfg.version,
&unrealized_loss,
);
// === Net and Total ===
let net_unrealized_pnl = LazyBinaryBlockLast::from_computed_height_date_last::<DollarsMinus>(
let net_unrealized_pnl = LazyBinaryFromHeightLast::from_computed_height_date_last::<DollarsMinus>(
&cfg.name("net_unrealized_pnl"),
cfg.version,
&unrealized_profit,
&unrealized_loss,
);
let total_unrealized_pnl = LazyBinaryBlockLast::from_computed_height_date_last::<DollarsPlus>(
let total_unrealized_pnl = LazyBinaryFromHeightLast::from_computed_height_date_last::<DollarsPlus>(
&cfg.name("total_unrealized_pnl"),
cfg.version,
&unrealized_profit,

View File

@@ -43,9 +43,9 @@ pub struct Vecs {
pub addr_count: AddrCountVecs,
pub empty_addr_count: AddrCountVecs,
pub loadedaddressindex_to_loadedaddressindex:
pub loadedaddressindex:
LazyVecFrom1<LoadedAddressIndex, LoadedAddressIndex, LoadedAddressIndex, LoadedAddressData>,
pub emptyaddressindex_to_emptyaddressindex:
pub emptyaddressindex:
LazyVecFrom1<EmptyAddressIndex, EmptyAddressIndex, EmptyAddressIndex, EmptyAddressData>,
}
@@ -90,13 +90,13 @@ impl Vecs {
)?;
// Identity mappings for traversable
let loadedaddressindex_to_loadedaddressindex = LazyVecFrom1::init(
let loadedaddressindex = LazyVecFrom1::init(
"loadedaddressindex",
version,
loadedaddressindex_to_loadedaddressdata.boxed_clone(),
|index, _| Some(index),
);
let emptyaddressindex_to_emptyaddressindex = LazyVecFrom1::init(
let emptyaddressindex = LazyVecFrom1::init(
"emptyaddressindex",
version,
emptyaddressindex_to_emptyaddressdata.boxed_clone(),
@@ -125,8 +125,8 @@ impl Vecs {
loaded: loadedaddressindex_to_loadedaddressdata,
empty: emptyaddressindex_to_emptyaddressdata,
},
loadedaddressindex_to_loadedaddressindex,
emptyaddressindex_to_emptyaddressindex,
loadedaddressindex,
emptyaddressindex,
db,
};

View File

@@ -3,11 +3,11 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::DerivedTxFull};
use crate::{indexes, internal::TxDerivedFull};
impl Vecs {
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
Ok(Self(DerivedTxFull::forced_import(
Ok(Self(TxDerivedFull::forced_import(
db,
"input_count",
version,

View File

@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
use brk_types::StoredU64;
use derive_more::{Deref, DerefMut};
use crate::internal::DerivedTxFull;
use crate::internal::TxDerivedFull;
#[derive(Clone, Deref, DerefMut, Traversable)]
pub struct Vecs(pub DerivedTxFull<StoredU64>);
pub struct Vecs(pub TxDerivedFull<StoredU64>);

View File

@@ -3,7 +3,7 @@
//! These functions replace the Option-based compute logic in flexible builders.
//! Each function takes optional mutable references and computes only for Some() vecs.
use brk_error::{Error, Result};
use brk_error::Result;
use brk_types::{CheckedSub, StoredU64};
use schemars::JsonSchema;
use vecdb::{
@@ -28,6 +28,10 @@ fn validate_and_start<I: VecIndex, T: ComputedVecValue + JsonSchema>(
///
/// This function computes all requested aggregations in a single pass when possible,
/// optimizing for the common case where multiple aggregations are needed.
///
/// The `skip_count` parameter allows skipping the first N items from ALL calculations.
/// This is useful for excluding coinbase transactions (which have 0 fee) from
/// fee/feerate aggregations.
#[allow(clippy::too_many_arguments)]
pub fn compute_aggregations<I, T, A>(
max_from: I,
@@ -35,6 +39,7 @@ pub fn compute_aggregations<I, T, A>(
first_indexes: &impl IterableVec<I, A>,
count_indexes: &impl IterableVec<I, StoredU64>,
exit: &Exit,
skip_count: usize,
mut first: Option<&mut EagerVec<PcoVec<I, T>>>,
mut last: Option<&mut EagerVec<PcoVec<I, T>>>,
mut min: Option<&mut EagerVec<PcoVec<I, T>>>,
@@ -105,29 +110,37 @@ where
let count_index = count_indexes_iter.next().unwrap();
let count = *count_index as usize;
// Effective count after skipping (e.g., skip coinbase for fee calculations)
let effective_count = count.saturating_sub(skip_count);
let effective_first_index = first_index + skip_count.min(count);
if let Some(ref mut first_vec) = first {
let f = source_iter
.get(first_index)
.unwrap_or_else(|| T::from(0_usize));
let f = if effective_count > 0 {
source_iter.get_unwrap(effective_first_index)
} else {
T::from(0_usize)
};
first_vec.truncate_push_at(idx, f)?;
}
if let Some(ref mut last_vec) = last {
if count == 0 {
panic!("should not compute last if count can be 0");
if effective_count == 0 {
// If all items skipped, use zero
last_vec.truncate_push_at(idx, T::from(0_usize))?;
} else {
let last_index = first_index + (count - 1);
let v = source_iter.get_unwrap(last_index);
last_vec.truncate_push_at(idx, v)?;
}
let last_index = first_index + (count - 1);
let v = source_iter.get_unwrap(last_index);
last_vec.truncate_push_at(idx, v)?;
}
// Fast path: only min/max needed, no sorting or allocation required
if needs_minmax && !needs_percentiles && !needs_aggregates {
source_iter.set_position(first_index);
source_iter.set_position(effective_first_index);
let mut min_val: Option<T> = None;
let mut max_val: Option<T> = None;
for val in (&mut source_iter).take(count) {
for val in (&mut source_iter).take(effective_count) {
if needs_min {
min_val = Some(min_val.map_or(val, |m| if val < m { val } else { m }));
}
@@ -137,43 +150,94 @@ where
}
if let Some(ref mut min_vec) = min {
min_vec.truncate_push_at(idx, min_val.unwrap())?;
let v = min_val.or(max_val).unwrap_or_else(|| T::from(0_usize));
min_vec.truncate_push_at(idx, v)?;
}
if let Some(ref mut max_vec) = max {
max_vec.truncate_push_at(idx, max_val.unwrap())?;
let v = max_val.or(min_val).unwrap_or_else(|| T::from(0_usize));
max_vec.truncate_push_at(idx, v)?;
}
} else if needs_percentiles || needs_aggregates || needs_minmax {
source_iter.set_position(first_index);
let mut values: Vec<T> = (&mut source_iter).take(count).collect();
if needs_percentiles {
values.sort_unstable();
source_iter.set_position(effective_first_index);
let values: Vec<T> = (&mut source_iter).take(effective_count).collect();
if values.is_empty() {
// Handle edge case where all items were skipped
if let Some(ref mut max_vec) = max {
max_vec.truncate_push_at(
idx,
*values
.last()
.ok_or(Error::Internal("Empty values for percentiles"))?,
)?;
max_vec.truncate_push_at(idx, T::from(0_usize))?;
}
if let Some(ref mut pct90_vec) = pct90 {
pct90_vec.truncate_push_at(idx, get_percentile(&values, 0.90))?;
pct90_vec.truncate_push_at(idx, T::from(0_usize))?;
}
if let Some(ref mut pct75_vec) = pct75 {
pct75_vec.truncate_push_at(idx, get_percentile(&values, 0.75))?;
pct75_vec.truncate_push_at(idx, T::from(0_usize))?;
}
if let Some(ref mut median_vec) = median {
median_vec.truncate_push_at(idx, get_percentile(&values, 0.50))?;
median_vec.truncate_push_at(idx, T::from(0_usize))?;
}
if let Some(ref mut pct25_vec) = pct25 {
pct25_vec.truncate_push_at(idx, get_percentile(&values, 0.25))?;
pct25_vec.truncate_push_at(idx, T::from(0_usize))?;
}
if let Some(ref mut pct10_vec) = pct10 {
pct10_vec.truncate_push_at(idx, get_percentile(&values, 0.10))?;
pct10_vec.truncate_push_at(idx, T::from(0_usize))?;
}
if let Some(ref mut min_vec) = min {
min_vec.truncate_push_at(idx, *values.first().unwrap())?;
min_vec.truncate_push_at(idx, T::from(0_usize))?;
}
if let Some(ref mut average_vec) = average {
average_vec.truncate_push_at(idx, T::from(0_usize))?;
}
if let Some(ref mut sum_vec) = sum {
sum_vec.truncate_push_at(idx, T::from(0_usize))?;
}
if let Some(ref mut cumulative_vec) = cumulative {
let t = cumulative_val.unwrap();
cumulative_vec.truncate_push_at(idx, t)?;
}
} else if needs_percentiles {
let mut sorted_values = values.clone();
sorted_values.sort_unstable();
if let Some(ref mut max_vec) = max {
max_vec.truncate_push_at(idx, *sorted_values.last().unwrap())?;
}
if let Some(ref mut pct90_vec) = pct90 {
pct90_vec.truncate_push_at(idx, get_percentile(&sorted_values, 0.90))?;
}
if let Some(ref mut pct75_vec) = pct75 {
pct75_vec.truncate_push_at(idx, get_percentile(&sorted_values, 0.75))?;
}
if let Some(ref mut median_vec) = median {
median_vec.truncate_push_at(idx, get_percentile(&sorted_values, 0.50))?;
}
if let Some(ref mut pct25_vec) = pct25 {
pct25_vec.truncate_push_at(idx, get_percentile(&sorted_values, 0.25))?;
}
if let Some(ref mut pct10_vec) = pct10 {
pct10_vec.truncate_push_at(idx, get_percentile(&sorted_values, 0.10))?;
}
if let Some(ref mut min_vec) = min {
min_vec.truncate_push_at(idx, *sorted_values.first().unwrap())?;
}
if needs_aggregates {
let len = values.len();
let sum_val = values.into_iter().fold(T::from(0), |a, b| a + b);
if let Some(ref mut average_vec) = average {
average_vec.truncate_push_at(idx, sum_val / len)?;
}
if needs_sum_or_cumulative {
if let Some(ref mut sum_vec) = sum {
sum_vec.truncate_push_at(idx, sum_val)?;
}
if let Some(ref mut cumulative_vec) = cumulative {
let t = cumulative_val.unwrap() + sum_val;
cumulative_val.replace(t);
cumulative_vec.truncate_push_at(idx, t)?;
}
}
}
} else if needs_minmax {
if let Some(ref mut min_vec) = min {
@@ -182,9 +246,27 @@ where
if let Some(ref mut max_vec) = max {
max_vec.truncate_push_at(idx, *values.iter().max().unwrap())?;
}
}
if needs_aggregates {
if needs_aggregates {
let len = values.len();
let sum_val = values.into_iter().fold(T::from(0), |a, b| a + b);
if let Some(ref mut average_vec) = average {
average_vec.truncate_push_at(idx, sum_val / len)?;
}
if needs_sum_or_cumulative {
if let Some(ref mut sum_vec) = sum {
sum_vec.truncate_push_at(idx, sum_val)?;
}
if let Some(ref mut cumulative_vec) = cumulative {
let t = cumulative_val.unwrap() + sum_val;
cumulative_val.replace(t);
cumulative_vec.truncate_push_at(idx, t)?;
}
}
}
} else if needs_aggregates {
let len = values.len();
let sum_val = values.into_iter().fold(T::from(0), |a, b| a + b);

View File

@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyPeriodsAverage<T>
pub struct LazyDateDerivedAverage<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -27,7 +27,7 @@ where
const VERSION: Version = Version::ZERO;
impl<T> LazyPeriodsAverage<T>
impl<T> LazyDateDerivedAverage<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{

View File

@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyPeriodsDistribution<T>
pub struct LazyDateDerivedDistribution<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -27,7 +27,7 @@ where
const VERSION: Version = Version::ZERO;
impl<T> LazyPeriodsDistribution<T>
impl<T> LazyDateDerivedDistribution<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{

View File

@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyPeriodsFirst<T>
pub struct LazyDateDerivedFirst<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -27,7 +27,7 @@ where
const VERSION: Version = Version::ZERO;
impl<T> LazyPeriodsFirst<T>
impl<T> LazyDateDerivedFirst<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{

View File

@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyPeriodsFull<T>
pub struct LazyDateDerivedFull<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -27,7 +27,7 @@ where
const VERSION: Version = Version::ZERO;
impl<T> LazyPeriodsFull<T>
impl<T> LazyDateDerivedFull<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{

View File

@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyPeriodsLast<T>
pub struct LazyDateDerivedLast<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -27,7 +27,7 @@ where
const VERSION: Version = Version::ZERO;
impl<T> LazyPeriodsLast<T>
impl<T> LazyDateDerivedLast<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{

View File

@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyPeriodsMax<T>
pub struct LazyDateDerivedMax<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -27,7 +27,7 @@ where
const VERSION: Version = Version::ZERO;
impl<T> LazyPeriodsMax<T>
impl<T> LazyDateDerivedMax<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{
@@ -37,12 +37,36 @@ where
version: Version,
dateindex_source: IterableBoxedVec<DateIndex, T>,
indexes: &indexes::Vecs,
) -> Self {
Self::from_source_inner(name, version, dateindex_source, indexes, false)
}
/// Create from an external dateindex source without adding _max suffix.
pub fn from_source_raw(
name: &str,
version: Version,
dateindex_source: IterableBoxedVec<DateIndex, T>,
indexes: &indexes::Vecs,
) -> Self {
Self::from_source_inner(name, version, dateindex_source, indexes, true)
}
fn from_source_inner(
name: &str,
version: Version,
dateindex_source: IterableBoxedVec<DateIndex, T>,
indexes: &indexes::Vecs,
raw: bool,
) -> Self {
let v = version + VERSION;
macro_rules! period {
($idx:ident) => {
LazyMax::from_source(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
if raw {
LazyMax::from_source_raw(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
} else {
LazyMax::from_source(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
}
};
}

View File

@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyPeriodsMin<T>
pub struct LazyDateDerivedMin<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -27,7 +27,7 @@ where
const VERSION: Version = Version::ZERO;
impl<T> LazyPeriodsMin<T>
impl<T> LazyDateDerivedMin<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{
@@ -37,12 +37,36 @@ where
version: Version,
dateindex_source: IterableBoxedVec<DateIndex, T>,
indexes: &indexes::Vecs,
) -> Self {
Self::from_source_inner(name, version, dateindex_source, indexes, false)
}
/// Create from an external dateindex source without adding _min suffix.
pub fn from_source_raw(
name: &str,
version: Version,
dateindex_source: IterableBoxedVec<DateIndex, T>,
indexes: &indexes::Vecs,
) -> Self {
Self::from_source_inner(name, version, dateindex_source, indexes, true)
}
fn from_source_inner(
name: &str,
version: Version,
dateindex_source: IterableBoxedVec<DateIndex, T>,
indexes: &indexes::Vecs,
raw: bool,
) -> Self {
let v = version + VERSION;
macro_rules! period {
($idx:ident) => {
LazyMin::from_source(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
if raw {
LazyMin::from_source_raw(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
} else {
LazyMin::from_source(name, v, dateindex_source.clone(), indexes.$idx.identity.boxed_clone())
}
};
}

View File

@@ -3,7 +3,6 @@ mod distribution;
mod first;
mod full;
mod last;
mod lazy;
mod max;
mod min;
mod sum;
@@ -14,7 +13,6 @@ pub use distribution::*;
pub use first::*;
pub use full::*;
pub use last::*;
pub use lazy::*;
pub use max::*;
pub use min::*;
pub use sum::*;

View File

@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyPeriodsSum<T>
pub struct LazyDateDerivedSum<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -27,7 +27,7 @@ where
const VERSION: Version = Version::ZERO;
impl<T> LazyPeriodsSum<T>
impl<T> LazyDateDerivedSum<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{

View File

@@ -13,7 +13,7 @@ use crate::internal::ComputedVecValue;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyPeriodsSumCum<T>
pub struct LazyDateDerivedSumCum<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -27,7 +27,7 @@ where
const VERSION: Version = Version::ZERO;
impl<T> LazyPeriodsSumCum<T>
impl<T> LazyDateDerivedSumCum<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{

View File

@@ -1,4 +1,4 @@
//! ComputedDateAverage - dateindex storage + lazy periods for average-value aggregation.
//! ComputedFromDateAverage - dateindex storage + lazy periods for average-value aggregation.
use brk_error::Result;
use brk_traversable::Traversable;
@@ -9,11 +9,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
use crate::{ComputeIndexes, indexes};
use crate::internal::{ComputedVecValue, LazyPeriodsAverage};
use crate::internal::{ComputedVecValue, LazyDateDerivedAverage};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct ComputedDateAverage<T>
pub struct ComputedFromDateAverage<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -21,12 +21,12 @@ where
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub rest: LazyPeriodsAverage<T>,
pub rest: LazyDateDerivedAverage<T>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedDateAverage<T>
impl<T> ComputedFromDateAverage<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{
@@ -39,7 +39,7 @@ where
let dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
Ok(Self {
rest: LazyPeriodsAverage::from_source(
rest: LazyDateDerivedAverage::from_source(
name,
version + VERSION,
dateindex.boxed_clone(),

View File

@@ -8,15 +8,16 @@ use schemars::JsonSchema;
use vecdb::{BinaryTransform, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
use crate::internal::{
ComputedBlockLast, ComputedBlockSum, ComputedDateLast, ComputedVecValue, LazyBinaryTransformLast,
LazyPeriodsLast, LazyPeriodsSumCum, NumericValue,
ComputedFromHeightLast, ComputedFromHeightSum, ComputedFromDateLast, ComputedVecValue,
LazyBinaryComputedFromHeightLast, LazyBinaryComputedFromHeightSum, LazyBinaryTransformLast,
LazyDateDerivedLast, LazyDateDerivedSumCum, NumericValue,
};
const VERSION: Version = Version::ZERO;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyBinaryDateLast<T, S1T, S2T>
pub struct LazyBinaryFromDateLast<T, S1T, S2T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
@@ -31,7 +32,7 @@ where
pub decadeindex: LazyBinaryTransformLast<DecadeIndex, T, S1T, S2T>,
}
impl<T, S1T, S2T> LazyBinaryDateLast<T, S1T, S2T>
impl<T, S1T, S2T> LazyBinaryFromDateLast<T, S1T, S2T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: ComputedVecValue + JsonSchema,
@@ -40,8 +41,8 @@ where
pub fn from_computed_both_last<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedDateLast<S1T>,
source2: &ComputedDateLast<S2T>,
source1: &ComputedFromDateLast<S1T>,
source2: &ComputedFromDateLast<S2T>,
) -> Self {
let v = version + VERSION;
@@ -76,8 +77,8 @@ where
name: &str,
version: Version,
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
source1: &LazyPeriodsLast<S1T>,
source2: &ComputedDateLast<S2T>,
source1: &LazyDateDerivedLast<S1T>,
source2: &ComputedFromDateLast<S2T>,
) -> Self {
let v = version + VERSION;
@@ -112,8 +113,8 @@ where
name: &str,
version: Version,
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
source1: &LazyPeriodsLast<S1T>,
source2: &ComputedBlockLast<S2T>,
source1: &LazyDateDerivedLast<S1T>,
source2: &ComputedFromHeightLast<S2T>,
) -> Self
where
S2T: NumericValue,
@@ -136,7 +137,7 @@ where
name,
v,
dateindex_source1,
source2.dateindex.0.boxed_clone(),
source2.dateindex.boxed_clone(),
),
weekindex: period!(weekindex),
monthindex: period!(monthindex),
@@ -151,9 +152,9 @@ where
name: &str,
version: Version,
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
source1: &LazyPeriodsLast<S1T>,
source1: &LazyDateDerivedLast<S1T>,
dateindex_source2: IterableBoxedVec<DateIndex, S2T>,
source2: &LazyPeriodsLast<S2T>,
source2: &LazyDateDerivedLast<S2T>,
) -> Self {
let v = version + VERSION;
@@ -187,8 +188,8 @@ where
pub fn from_height_and_dateindex_last<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedBlockLast<S1T>,
source2: &ComputedDateLast<S2T>,
source1: &ComputedFromHeightLast<S1T>,
source2: &ComputedFromDateLast<S2T>,
) -> Self
where
S1T: NumericValue,
@@ -210,7 +211,7 @@ where
dateindex: LazyVecFrom2::transformed::<F>(
name,
v,
source1.dateindex.0.boxed_clone(),
source1.dateindex.boxed_clone(),
source2.dateindex.boxed_clone(),
),
weekindex: period!(weekindex),
@@ -225,8 +226,8 @@ where
pub fn from_dateindex_and_height_last<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedDateLast<S1T>,
source2: &ComputedBlockLast<S2T>,
source1: &ComputedFromDateLast<S1T>,
source2: &ComputedFromHeightLast<S2T>,
) -> Self
where
S2T: NumericValue,
@@ -249,7 +250,7 @@ where
name,
v,
source1.dateindex.boxed_clone(),
source2.dateindex.0.boxed_clone(),
source2.dateindex.boxed_clone(),
),
weekindex: period!(weekindex),
monthindex: period!(monthindex),
@@ -263,8 +264,8 @@ where
pub fn from_both_block_last<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedBlockLast<S1T>,
source2: &ComputedBlockLast<S2T>,
source1: &ComputedFromHeightLast<S1T>,
source2: &ComputedFromHeightLast<S2T>,
) -> Self
where
S1T: NumericValue,
@@ -287,8 +288,8 @@ where
dateindex: LazyVecFrom2::transformed::<F>(
name,
v,
source1.dateindex.0.boxed_clone(),
source2.dateindex.0.boxed_clone(),
source1.dateindex.boxed_clone(),
source2.dateindex.boxed_clone(),
),
weekindex: period!(weekindex),
monthindex: period!(monthindex),
@@ -302,8 +303,8 @@ where
pub fn from_dateindex_last_and_height_sum<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedDateLast<S1T>,
source2: &ComputedBlockSum<S2T>,
source1: &ComputedFromDateLast<S1T>,
source2: &ComputedFromHeightSum<S2T>,
) -> Self
where
S2T: NumericValue,
@@ -326,7 +327,7 @@ where
name,
v,
source1.dateindex.boxed_clone(),
source2.dateindex.0.boxed_clone(),
source2.dateindex.boxed_clone(),
),
weekindex: period!(weekindex),
monthindex: period!(monthindex),
@@ -340,8 +341,8 @@ where
pub fn from_block_last_and_height_sum<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedBlockLast<S1T>,
source2: &ComputedBlockSum<S2T>,
source1: &ComputedFromHeightLast<S1T>,
source2: &ComputedFromHeightSum<S2T>,
) -> Self
where
S1T: NumericValue,
@@ -364,8 +365,8 @@ where
dateindex: LazyVecFrom2::transformed::<F>(
name,
v,
source1.dateindex.0.boxed_clone(),
source2.dateindex.0.boxed_clone(),
source1.dateindex.boxed_clone(),
source2.dateindex.boxed_clone(),
),
weekindex: period!(weekindex),
monthindex: period!(monthindex),
@@ -380,9 +381,9 @@ where
name: &str,
version: Version,
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
dates1: &LazyPeriodsSumCum<S1T>,
dates1: &LazyDateDerivedSumCum<S1T>,
dateindex_source2: IterableBoxedVec<DateIndex, S2T>,
dates2: &LazyPeriodsSumCum<S2T>,
dates2: &LazyDateDerivedSumCum<S2T>,
) -> Self
where
S1T: PartialOrd,
@@ -417,13 +418,13 @@ where
}
}
/// Create from a LazyPeriodsLast source and a BinaryDateLast source.
/// Create from a LazyDateDerivedLast source and a BinaryDateLast source.
pub fn from_derived_last_and_binary_last<F, S2aT, S2bT>(
name: &str,
version: Version,
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
source1: &LazyPeriodsLast<S1T>,
source2: &LazyBinaryDateLast<S2T, S2aT, S2bT>,
source1: &LazyDateDerivedLast<S1T>,
source2: &LazyBinaryFromDateLast<S2T, S2aT, S2bT>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
@@ -459,12 +460,12 @@ where
}
}
/// Create from a BinaryDateLast source and a ComputedDateLast source.
/// Create from a BinaryDateLast source and a ComputedFromDateLast source.
pub fn from_binary_and_computed_last<F, S1aT, S1bT>(
name: &str,
version: Version,
source1: &LazyBinaryDateLast<S1T, S1aT, S1bT>,
source2: &ComputedDateLast<S2T>,
source1: &LazyBinaryFromDateLast<S1T, S1aT, S1bT>,
source2: &ComputedFromDateLast<S2T>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
@@ -500,12 +501,12 @@ where
}
}
/// Create from a BinaryDateLast source and a ComputedBlockLast source.
/// Create from a BinaryDateLast source and a ComputedFromHeightLast source.
pub fn from_binary_and_block_last<F, S1aT, S1bT>(
name: &str,
version: Version,
source1: &LazyBinaryDateLast<S1T, S1aT, S1bT>,
source2: &ComputedBlockLast<S2T>,
source1: &LazyBinaryFromDateLast<S1T, S1aT, S1bT>,
source2: &ComputedFromHeightLast<S2T>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
@@ -531,7 +532,7 @@ where
name,
v,
source1.dateindex.boxed_clone(),
source2.dateindex.0.boxed_clone(),
source2.dateindex.boxed_clone(),
),
weekindex: period!(weekindex),
monthindex: period!(monthindex),
@@ -542,12 +543,12 @@ where
}
}
/// Create from a ComputedDateLast source and a BinaryDateLast source.
/// Create from a ComputedFromDateLast source and a BinaryDateLast source.
pub fn from_computed_and_binary_last<F, S2aT, S2bT>(
name: &str,
version: Version,
source1: &ComputedDateLast<S1T>,
source2: &LazyBinaryDateLast<S2T, S2aT, S2bT>,
source1: &ComputedFromDateLast<S1T>,
source2: &LazyBinaryFromDateLast<S2T, S2aT, S2bT>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
@@ -587,8 +588,8 @@ where
pub fn from_both_binary_last<F, S1aT, S1bT, S2aT, S2bT>(
name: &str,
version: Version,
source1: &LazyBinaryDateLast<S1T, S1aT, S1bT>,
source2: &LazyBinaryDateLast<S2T, S2aT, S2bT>,
source1: &LazyBinaryFromDateLast<S1T, S1aT, S1bT>,
source2: &LazyBinaryFromDateLast<S2T, S2aT, S2bT>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
@@ -625,4 +626,131 @@ where
decadeindex: period!(decadeindex),
}
}
/// Create from a BinaryDateLast source and a LazyDateDerivedLast source.
pub fn from_binary_and_derived_last<F, S1aT, S1bT>(
name: &str,
version: Version,
source1: &LazyBinaryFromDateLast<S1T, S1aT, S1bT>,
dateindex_source2: IterableBoxedVec<DateIndex, S2T>,
source2: &LazyDateDerivedLast<S2T>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
S1aT: ComputedVecValue + JsonSchema,
S1bT: ComputedVecValue + JsonSchema,
{
let v = version + VERSION;
macro_rules! period {
($p:ident) => {
LazyBinaryTransformLast::from_vecs::<F>(
name,
v,
source1.$p.boxed_clone(),
source2.$p.boxed_clone(),
)
};
}
Self {
dateindex: LazyVecFrom2::transformed::<F>(
name,
v,
source1.dateindex.boxed_clone(),
dateindex_source2,
),
weekindex: period!(weekindex),
monthindex: period!(monthindex),
quarterindex: period!(quarterindex),
semesterindex: period!(semesterindex),
yearindex: period!(yearindex),
decadeindex: period!(decadeindex),
}
}
/// Create from a LazyBinaryComputedFromHeightLast and a ComputedFromHeightSum.
pub fn from_lazy_binary_block_last_and_height_sum<F, S1aT, S1bT>(
name: &str,
version: Version,
source1: &LazyBinaryComputedFromHeightLast<S1T, S1aT, S1bT>,
source2: &ComputedFromHeightSum<S2T>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
S1aT: ComputedVecValue + JsonSchema,
S1bT: ComputedVecValue + JsonSchema,
S2T: NumericValue,
{
let v = version + VERSION;
macro_rules! period {
($p:ident) => {
LazyBinaryTransformLast::from_vecs::<F>(
name,
v,
source1.rest.dates.$p.boxed_clone(),
source2.$p.boxed_clone(),
)
};
}
Self {
dateindex: LazyVecFrom2::transformed::<F>(
name,
v,
source1.rest.dateindex.boxed_clone(),
source2.dateindex.boxed_clone(),
),
weekindex: period!(weekindex),
monthindex: period!(monthindex),
quarterindex: period!(quarterindex),
semesterindex: period!(semesterindex),
yearindex: period!(yearindex),
decadeindex: period!(decadeindex),
}
}
/// Create from a LazyBinaryComputedFromHeightLast and a LazyBinaryComputedFromHeightSum.
pub fn from_lazy_binary_block_last_and_lazy_binary_sum<F, S1aT, S1bT, S2aT, S2bT>(
name: &str,
version: Version,
source1: &LazyBinaryComputedFromHeightLast<S1T, S1aT, S1bT>,
source2: &LazyBinaryComputedFromHeightSum<S2T, S2aT, S2bT>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
S1aT: ComputedVecValue + JsonSchema,
S1bT: ComputedVecValue + JsonSchema,
S2aT: ComputedVecValue + JsonSchema,
S2bT: ComputedVecValue + JsonSchema,
{
let v = version + VERSION;
macro_rules! period {
($p:ident) => {
LazyBinaryTransformLast::from_vecs::<F>(
name,
v,
source1.rest.dates.$p.boxed_clone(),
source2.rest.dates.$p.boxed_clone(),
)
};
}
Self {
dateindex: LazyVecFrom2::transformed::<F>(
name,
v,
source1.rest.dateindex.boxed_clone(),
source2.rest.dateindex.boxed_clone(),
),
weekindex: period!(weekindex),
monthindex: period!(monthindex),
quarterindex: period!(quarterindex),
semesterindex: period!(semesterindex),
yearindex: period!(yearindex),
decadeindex: period!(decadeindex),
}
}
}

View File

@@ -7,13 +7,13 @@ use brk_types::{
use schemars::JsonSchema;
use vecdb::{BinaryTransform, IterableCloneableVec};
use crate::internal::{ComputedVecValue, ComputedDerivedBlockSum, LazyBinaryTransformSum, NumericValue};
use crate::internal::{ComputedVecValue, ComputedHeightDerivedSum, LazyBinaryTransformSum, NumericValue};
const VERSION: Version = Version::ZERO;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyBinaryDateSum<T, S1T, S2T>
pub struct LazyBinaryFromDateSum<T, S1T, S2T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
@@ -28,7 +28,7 @@ where
pub decadeindex: LazyBinaryTransformSum<DecadeIndex, T, S1T, S2T>,
}
impl<T, S1T, S2T> LazyBinaryDateSum<T, S1T, S2T>
impl<T, S1T, S2T> LazyBinaryFromDateSum<T, S1T, S2T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: NumericValue + JsonSchema,
@@ -37,8 +37,8 @@ where
pub fn from_derived<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedDerivedBlockSum<S1T>,
source2: &ComputedDerivedBlockSum<S2T>,
source1: &ComputedHeightDerivedSum<S1T>,
source2: &ComputedHeightDerivedSum<S2T>,
) -> Self {
let v = version + VERSION;

View File

@@ -8,16 +8,16 @@ use schemars::JsonSchema;
use vecdb::{BinaryTransform, IterableCloneableVec};
use crate::internal::{
ComputedBlockLast, ComputedBlockSumCum, ComputedDerivedBlockLast,
ComputedDerivedBlockSumCum, ComputedVecValue, LazyBinaryTransformSumCum, LazyPeriodsFull,
LazyPeriodsSumCum, NumericValue, SumCum,
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedHeightDerivedLast,
ComputedHeightDerivedSumCum, ComputedVecValue, LazyBinaryTransformSumCum, LazyDateDerivedFull,
LazyDateDerivedSumCum, NumericValue, SumCum,
};
const VERSION: Version = Version::ZERO;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyBinaryDateSumCum<T, S1T = T, S2T = T>
pub struct LazyBinaryFromDateSumCum<T, S1T = T, S2T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
@@ -32,7 +32,7 @@ where
pub decadeindex: LazyBinaryTransformSumCum<DecadeIndex, T, S1T, S2T>,
}
impl<T, S1T, S2T> LazyBinaryDateSumCum<T, S1T, S2T>
impl<T, S1T, S2T> LazyBinaryFromDateSumCum<T, S1T, S2T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: ComputedVecValue + JsonSchema,
@@ -43,9 +43,9 @@ where
name: &str,
version: Version,
dateindex1: &SumCum<DateIndex, S1T>,
periods1: &LazyPeriodsSumCum<S1T>,
periods1: &LazyDateDerivedSumCum<S1T>,
dateindex2: &SumCum<DateIndex, S2T>,
periods2: &LazyPeriodsSumCum<S2T>,
periods2: &LazyDateDerivedSumCum<S2T>,
) -> Self {
let v = version + VERSION;
@@ -74,9 +74,9 @@ where
name: &str,
version: Version,
dateindex1: &SumCum<DateIndex, S1T>,
dates1: &LazyPeriodsFull<S1T>,
dates1: &LazyDateDerivedFull<S1T>,
dateindex2: &SumCum<DateIndex, S2T>,
dates2: &LazyPeriodsFull<S2T>,
dates2: &LazyDateDerivedFull<S2T>,
) -> Self {
let v = version + VERSION;
@@ -106,9 +106,9 @@ where
name: &str,
version: Version,
dateindex1: &SumCum<DateIndex, S1T>,
periods1: &LazyPeriodsSumCum<S1T>,
periods1: &LazyDateDerivedSumCum<S1T>,
dateindex2: &SumCum<DateIndex, S2T>,
periods2: &LazyPeriodsSumCum<S2T>,
periods2: &LazyDateDerivedSumCum<S2T>,
) -> Self {
let v = version + VERSION;
@@ -138,8 +138,8 @@ where
pub fn from_computed_last<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedBlockSumCum<S1T>,
source2: &ComputedBlockLast<S2T>,
source1: &ComputedFromHeightSumCum<S1T>,
source2: &ComputedFromHeightLast<S2T>,
) -> Self
where
S1T: PartialOrd,
@@ -174,8 +174,8 @@ where
pub fn from_derived_computed_last<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedDerivedBlockSumCum<S1T>,
source2: &ComputedBlockLast<S2T>,
source1: &ComputedHeightDerivedSumCum<S1T>,
source2: &ComputedFromHeightLast<S2T>,
) -> Self
where
S1T: NumericValue,
@@ -210,8 +210,8 @@ where
pub fn from_computed_derived_last<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedBlockSumCum<S1T>,
source2: &ComputedDerivedBlockLast<S2T>,
source1: &ComputedFromHeightSumCum<S1T>,
source2: &ComputedHeightDerivedLast<S2T>,
) -> Self
where
S1T: PartialOrd,
@@ -246,8 +246,8 @@ where
pub fn from_derived_last<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedDerivedBlockSumCum<S1T>,
source2: &ComputedDerivedBlockLast<S2T>,
source1: &ComputedHeightDerivedSumCum<S1T>,
source2: &ComputedHeightDerivedLast<S2T>,
) -> Self
where
S1T: NumericValue,

View File

@@ -9,11 +9,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
use crate::{ComputeIndexes, indexes};
use crate::internal::{ComputedVecValue, LazyPeriodsFirst};
use crate::internal::{ComputedVecValue, LazyDateDerivedFirst};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct ComputedDateFirst<T>
pub struct ComputedFromDateFirst<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -21,12 +21,12 @@ where
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub rest: LazyPeriodsFirst<T>,
pub rest: LazyDateDerivedFirst<T>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedDateFirst<T>
impl<T> ComputedFromDateFirst<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{
@@ -39,7 +39,7 @@ where
let dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
Ok(Self {
rest: LazyPeriodsFirst::from_source(
rest: LazyDateDerivedFirst::from_source(
name,
version + VERSION,
dateindex.boxed_clone(),

View File

@@ -9,11 +9,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, Itera
use crate::{ComputeIndexes, indexes};
use crate::internal::{ComputedVecValue, LazyPeriodsLast};
use crate::internal::{ComputedVecValue, LazyDateDerivedLast};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct ComputedDateLast<T>
pub struct ComputedFromDateLast<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -21,12 +21,12 @@ where
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub rest: LazyPeriodsLast<T>,
pub rest: LazyDateDerivedLast<T>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedDateLast<T>
impl<T> ComputedFromDateLast<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{
@@ -39,7 +39,7 @@ where
let dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
Ok(Self {
rest: LazyPeriodsLast::from_source(
rest: LazyDateDerivedLast::from_source(
name,
version + VERSION,
dateindex.boxed_clone(),

View File

@@ -13,7 +13,7 @@ use crate::indexes;
/// Lazy vecs for all time period indexes (no height).
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyPeriodVecs<T>
pub struct LazyFromDate<T>
where
T: VecValue + Formattable + Serialize + JsonSchema,
{
@@ -26,7 +26,7 @@ where
pub decadeindex: LazyVecFrom1<DecadeIndex, T, DecadeIndex, DecadeIndex>,
}
impl<T: VecValue + Formattable + Serialize + JsonSchema> LazyPeriodVecs<T> {
impl<T: VecValue + Formattable + Serialize + JsonSchema> LazyFromDate<T> {
#[allow(clippy::too_many_arguments)]
pub fn new(
name: &str,

View File

@@ -5,13 +5,13 @@ use brk_types::{DateIndex, DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex,
use schemars::JsonSchema;
use vecdb::{IterableCloneableVec, UnaryTransform};
use crate::internal::{ComputedVecValue, Full, LazyPeriodsFull, LazyTransformFull, LazyTransformStats};
use crate::internal::{ComputedVecValue, Full, LazyDateDerivedFull, LazyTransformFull, LazyTransformStats};
const VERSION: Version = Version::ZERO;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyDateFull<T, S1T = T>
pub struct LazyFromDateFull<T, S1T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
@@ -25,7 +25,7 @@ where
pub decadeindex: LazyTransformStats<DecadeIndex, T, S1T>,
}
impl<T, S1T> LazyDateFull<T, S1T>
impl<T, S1T> LazyFromDateFull<T, S1T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: ComputedVecValue + JsonSchema,
@@ -34,7 +34,7 @@ where
name: &str,
version: Version,
dateindex: &Full<DateIndex, S1T>,
source: &LazyPeriodsFull<S1T>,
source: &LazyDateDerivedFull<S1T>,
) -> Self {
let v = version + VERSION;

View File

@@ -7,13 +7,13 @@ use brk_types::{
use schemars::JsonSchema;
use vecdb::{IterableBoxedVec, IterableCloneableVec, UnaryTransform};
use crate::internal::{ComputedBlockLast, ComputedDateLast, ComputedVecValue, LazyPeriodsLast, LazyTransformLast, NumericValue};
use crate::internal::{ComputedFromHeightLast, ComputedFromDateLast, ComputedVecValue, LazyDateDerivedLast, LazyTransformLast, NumericValue};
const VERSION: Version = Version::ZERO;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyDateLast<T, S1T = T>
pub struct LazyFromDateLast<T, S1T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
@@ -27,7 +27,7 @@ where
pub decadeindex: LazyTransformLast<DecadeIndex, T, S1T>,
}
impl<T, S1T> LazyDateLast<T, S1T>
impl<T, S1T> LazyFromDateLast<T, S1T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: ComputedVecValue + JsonSchema,
@@ -35,7 +35,7 @@ where
pub fn from_source<F: UnaryTransform<S1T, T>>(
name: &str,
version: Version,
source: &ComputedDateLast<S1T>,
source: &ComputedFromDateLast<S1T>,
) -> Self {
Self::from_computed::<F>(name, version, source.dateindex.boxed_clone(), source)
}
@@ -44,7 +44,7 @@ where
name: &str,
version: Version,
dateindex_source: IterableBoxedVec<DateIndex, S1T>,
source: &ComputedDateLast<S1T>,
source: &ComputedFromDateLast<S1T>,
) -> Self {
Self::from_derived::<F>(name, version, dateindex_source, &source.rest)
}
@@ -53,7 +53,7 @@ where
name: &str,
version: Version,
dateindex_source: IterableBoxedVec<DateIndex, S1T>,
source: &LazyPeriodsLast<S1T>,
source: &LazyDateDerivedLast<S1T>,
) -> Self {
let v = version + VERSION;
@@ -77,11 +77,11 @@ where
pub fn from_block_source<F: UnaryTransform<S1T, T>>(
name: &str,
version: Version,
source: &ComputedBlockLast<S1T>,
source: &ComputedFromHeightLast<S1T>,
) -> Self
where
S1T: NumericValue,
{
Self::from_derived::<F>(name, version, source.dateindex.0.boxed_clone(), &source.dates)
Self::from_derived::<F>(name, version, source.dateindex.boxed_clone(), &source.dates)
}
}

View File

@@ -5,13 +5,13 @@ use brk_types::{DateIndex, DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex,
use schemars::JsonSchema;
use vecdb::{IterableBoxedVec, IterableCloneableVec, UnaryTransform};
use crate::internal::{ComputedVecValue, LazyPeriodsSum, LazyTransformSum};
use crate::internal::{ComputedVecValue, LazyDateDerivedSum, LazyTransformSum};
const VERSION: Version = Version::ZERO;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyDateSum<T, S1T = T>
pub struct LazyFromDateSum<T, S1T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
@@ -25,7 +25,7 @@ where
pub decadeindex: LazyTransformSum<DecadeIndex, T, S1T>,
}
impl<T, S1T> LazyDateSum<T, S1T>
impl<T, S1T> LazyFromDateSum<T, S1T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: ComputedVecValue + JsonSchema,
@@ -34,7 +34,7 @@ where
name: &str,
version: Version,
dateindex_source: IterableBoxedVec<DateIndex, S1T>,
source: &LazyPeriodsSum<S1T>,
source: &LazyDateDerivedSum<S1T>,
) -> Self {
let v = version + VERSION;

View File

@@ -5,13 +5,13 @@ use brk_types::{DateIndex, DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex,
use schemars::JsonSchema;
use vecdb::{IterableCloneableVec, UnaryTransform};
use crate::internal::{ComputedVecValue, LazyPeriodsSumCum, LazyTransformSumCum, SumCum};
use crate::internal::{ComputedVecValue, LazyDateDerivedSumCum, LazyTransformSumCum, SumCum};
const VERSION: Version = Version::ZERO;
#[derive(Clone, Traversable)]
#[traversable(merge)]
pub struct LazyDateSumCum<T, S1T = T>
pub struct LazyFromDateSumCum<T, S1T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
@@ -25,7 +25,7 @@ where
pub decadeindex: LazyTransformSumCum<DecadeIndex, T, S1T>,
}
impl<T, S1T> LazyDateSumCum<T, S1T>
impl<T, S1T> LazyFromDateSumCum<T, S1T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: ComputedVecValue + JsonSchema,
@@ -34,7 +34,7 @@ where
name: &str,
version: Version,
dateindex: &SumCum<DateIndex, S1T>,
source: &LazyPeriodsSumCum<S1T>,
source: &LazyDateDerivedSumCum<S1T>,
) -> Self {
let v = version + VERSION;

View File

@@ -9,11 +9,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
use crate::{ComputeIndexes, indexes};
use crate::internal::{ComputedVecValue, LazyPeriodsMax};
use crate::internal::{ComputedVecValue, LazyDateDerivedMax};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct ComputedDateMax<T>
pub struct ComputedFromDateMax<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -21,12 +21,12 @@ where
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub rest: LazyPeriodsMax<T>,
pub rest: LazyDateDerivedMax<T>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedDateMax<T>
impl<T> ComputedFromDateMax<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{
@@ -35,16 +35,47 @@ where
name: &str,
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
Self::forced_import_inner(db, name, version, indexes, false)
}
/// Import without adding _max suffix to lazy vecs.
pub fn forced_import_raw(
db: &Database,
name: &str,
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
Self::forced_import_inner(db, name, version, indexes, true)
}
fn forced_import_inner(
db: &Database,
name: &str,
version: Version,
indexes: &indexes::Vecs,
raw: bool,
) -> Result<Self> {
let dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
Ok(Self {
rest: LazyPeriodsMax::from_source(
let rest = if raw {
LazyDateDerivedMax::from_source_raw(
name,
version + VERSION,
dateindex.boxed_clone(),
indexes,
),
)
} else {
LazyDateDerivedMax::from_source(
name,
version + VERSION,
dateindex.boxed_clone(),
indexes,
)
};
Ok(Self {
rest,
dateindex,
})
}

View File

@@ -9,11 +9,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
use crate::{ComputeIndexes, indexes};
use crate::internal::{ComputedVecValue, LazyPeriodsMin};
use crate::internal::{ComputedVecValue, LazyDateDerivedMin};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct ComputedDateMin<T>
pub struct ComputedFromDateMin<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -21,12 +21,12 @@ where
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub rest: LazyPeriodsMin<T>,
pub rest: LazyDateDerivedMin<T>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedDateMin<T>
impl<T> ComputedFromDateMin<T>
where
T: ComputedVecValue + JsonSchema + 'static,
{
@@ -35,16 +35,47 @@ where
name: &str,
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
Self::forced_import_inner(db, name, version, indexes, false)
}
/// Import without adding _min suffix to lazy vecs.
pub fn forced_import_raw(
db: &Database,
name: &str,
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
Self::forced_import_inner(db, name, version, indexes, true)
}
fn forced_import_inner(
db: &Database,
name: &str,
version: Version,
indexes: &indexes::Vecs,
raw: bool,
) -> Result<Self> {
let dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
Ok(Self {
rest: LazyPeriodsMin::from_source(
let rest = if raw {
LazyDateDerivedMin::from_source_raw(
name,
version + VERSION,
dateindex.boxed_clone(),
indexes,
),
)
} else {
LazyDateDerivedMin::from_source(
name,
version + VERSION,
dateindex.boxed_clone(),
indexes,
)
};
Ok(Self {
rest,
dateindex,
})
}

View File

@@ -4,12 +4,19 @@ mod binary_sum;
mod binary_sum_cum;
mod first;
mod last;
mod lazy;
mod lazy_full;
mod lazy_last;
mod lazy_sum;
mod lazy_sum_cum;
mod max;
mod min;
mod percentiles;
mod ratio;
mod stddev;
mod value_derived_last;
mod value_last;
mod value_lazy_last;
pub use average::*;
pub use binary_last::*;
@@ -17,9 +24,16 @@ pub use binary_sum::*;
pub use binary_sum_cum::*;
pub use first::*;
pub use last::*;
pub use lazy::*;
pub use lazy_full::*;
pub use lazy_last::*;
pub use lazy_sum::*;
pub use lazy_sum_cum::*;
pub use max::*;
pub use min::*;
pub use percentiles::*;
pub use ratio::*;
pub use stddev::*;
pub use value_derived_last::*;
pub use value_last::*;
pub use value_lazy_last::*;

View File

@@ -8,7 +8,7 @@ use vecdb::{
use crate::{ComputeIndexes, indexes};
use super::super::ComputedDateLast;
use super::ComputedFromDateLast;
pub const PERCENTILES: [u8; 19] = [
5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95,
@@ -17,7 +17,7 @@ pub const PERCENTILES_LEN: usize = PERCENTILES.len();
#[derive(Clone)]
pub struct CostBasisPercentiles {
pub vecs: [Option<ComputedDateLast<Dollars>>; PERCENTILES_LEN],
pub vecs: [Option<ComputedFromDateLast<Dollars>>; PERCENTILES_LEN],
}
const VERSION: Version = Version::ZERO;
@@ -37,7 +37,7 @@ impl CostBasisPercentiles {
} else {
format!("{name}_cost_basis_pct{p:02}")
};
ComputedDateLast::forced_import(db, &metric_name, version + VERSION, indexes)
ComputedFromDateLast::forced_import(db, &metric_name, version + VERSION, indexes)
.unwrap()
})
});
@@ -81,7 +81,7 @@ impl CostBasisPercentiles {
Ok(())
}
pub fn get(&self, percentile: u8) -> Option<&ComputedDateLast<Dollars>> {
pub fn get(&self, percentile: u8) -> Option<&ComputedFromDateLast<Dollars>> {
PERCENTILES
.iter()
.position(|&p| p == percentile)

View File

@@ -9,49 +9,50 @@ use vecdb::{
use crate::{
ComputeIndexes, indexes,
internal::{
ComputedStandardDeviationVecsDate, LazyBinaryDateLast, PriceTimesRatio,
ComputedFromDateStdDev, LazyBinaryFromDateLast, PriceTimesRatio,
StandardDeviationVecsOptions,
},
price,
utils::get_percentile,
};
use super::super::{ComputedBlockLast, ComputedDateLast};
use super::ComputedFromDateLast;
use crate::internal::ComputedFromHeightLast;
#[derive(Clone, Traversable)]
pub struct ComputedRatioVecsDate {
pub price: Option<ComputedDateLast<Dollars>>,
pub struct ComputedFromDateRatio {
pub price: Option<ComputedFromDateLast<Dollars>>,
pub ratio: ComputedDateLast<StoredF32>,
pub ratio_1w_sma: Option<ComputedDateLast<StoredF32>>,
pub ratio_1m_sma: Option<ComputedDateLast<StoredF32>>,
pub ratio_pct99: Option<ComputedDateLast<StoredF32>>,
pub ratio_pct98: Option<ComputedDateLast<StoredF32>>,
pub ratio_pct95: Option<ComputedDateLast<StoredF32>>,
pub ratio_pct5: Option<ComputedDateLast<StoredF32>>,
pub ratio_pct2: Option<ComputedDateLast<StoredF32>>,
pub ratio_pct1: Option<ComputedDateLast<StoredF32>>,
pub ratio_pct99_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
pub ratio_pct98_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
pub ratio_pct95_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
pub ratio_pct5_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
pub ratio_pct2_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
pub ratio_pct1_usd: Option<LazyBinaryDateLast<Dollars, Dollars, StoredF32>>,
pub ratio: ComputedFromDateLast<StoredF32>,
pub ratio_1w_sma: Option<ComputedFromDateLast<StoredF32>>,
pub ratio_1m_sma: Option<ComputedFromDateLast<StoredF32>>,
pub ratio_pct99: Option<ComputedFromDateLast<StoredF32>>,
pub ratio_pct98: Option<ComputedFromDateLast<StoredF32>>,
pub ratio_pct95: Option<ComputedFromDateLast<StoredF32>>,
pub ratio_pct5: Option<ComputedFromDateLast<StoredF32>>,
pub ratio_pct2: Option<ComputedFromDateLast<StoredF32>>,
pub ratio_pct1: Option<ComputedFromDateLast<StoredF32>>,
pub ratio_pct99_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
pub ratio_pct98_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
pub ratio_pct95_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
pub ratio_pct5_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
pub ratio_pct2_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
pub ratio_pct1_usd: Option<LazyBinaryFromDateLast<Dollars, Dollars, StoredF32>>,
pub ratio_sd: Option<ComputedStandardDeviationVecsDate>,
pub ratio_4y_sd: Option<ComputedStandardDeviationVecsDate>,
pub ratio_2y_sd: Option<ComputedStandardDeviationVecsDate>,
pub ratio_1y_sd: Option<ComputedStandardDeviationVecsDate>,
pub ratio_sd: Option<ComputedFromDateStdDev>,
pub ratio_4y_sd: Option<ComputedFromDateStdDev>,
pub ratio_2y_sd: Option<ComputedFromDateStdDev>,
pub ratio_1y_sd: Option<ComputedFromDateStdDev>,
}
const VERSION: Version = Version::TWO;
impl ComputedRatioVecsDate {
impl ComputedFromDateRatio {
#[allow(clippy::too_many_arguments)]
pub fn forced_import(
db: &Database,
name: &str,
metric_price: Option<&ComputedBlockLast<Dollars>>,
metric_price: Option<&ComputedFromHeightLast<Dollars>>,
version: Version,
indexes: &indexes::Vecs,
extended: bool,
@@ -61,7 +62,7 @@ impl ComputedRatioVecsDate {
macro_rules! import {
($suffix:expr) => {
ComputedDateLast::forced_import(db, &format!("{name}_{}", $suffix), v, indexes)
ComputedFromDateLast::forced_import(db, &format!("{name}_{}", $suffix), v, indexes)
.unwrap()
};
}
@@ -69,11 +70,11 @@ impl ComputedRatioVecsDate {
// Only compute internally when metric_price is None
let price = metric_price
.is_none()
.then(|| ComputedDateLast::forced_import(db, name, v, indexes).unwrap());
.then(|| ComputedFromDateLast::forced_import(db, name, v, indexes).unwrap());
macro_rules! import_sd {
($suffix:expr, $days:expr) => {
ComputedStandardDeviationVecsDate::forced_import(
ComputedFromDateStdDev::forced_import(
db,
&format!("{name}_{}", $suffix),
$days,
@@ -97,7 +98,7 @@ impl ComputedRatioVecsDate {
($ratio:expr, $suffix:expr) => {
if let Some(mp) = metric_price {
$ratio.as_ref().map(|r| {
LazyBinaryDateLast::from_height_and_dateindex_last::<PriceTimesRatio>(
LazyBinaryFromDateLast::from_height_and_dateindex_last::<PriceTimesRatio>(
&format!("{name}_{}", $suffix),
v,
mp,
@@ -106,7 +107,7 @@ impl ComputedRatioVecsDate {
})
} else {
price.as_ref().zip($ratio.as_ref()).map(|(p, r)| {
LazyBinaryDateLast::from_computed_both_last::<PriceTimesRatio>(
LazyBinaryFromDateLast::from_computed_both_last::<PriceTimesRatio>(
&format!("{name}_{}", $suffix),
v,
p,

View File

@@ -10,44 +10,44 @@ use vecdb::{
use crate::{ComputeIndexes, indexes, price};
use crate::internal::{ClosePriceTimesRatio, ComputedDateLast, LazyBinaryDateLast};
use crate::internal::{ClosePriceTimesRatio, ComputedFromDateLast, LazyBinaryFromDateLast};
#[derive(Clone, Traversable)]
pub struct ComputedStandardDeviationVecsDate {
pub struct ComputedFromDateStdDev {
days: usize,
pub sma: Option<ComputedDateLast<StoredF32>>,
pub sma: Option<ComputedFromDateLast<StoredF32>>,
pub sd: ComputedDateLast<StoredF32>,
pub sd: ComputedFromDateLast<StoredF32>,
pub zscore: Option<ComputedDateLast<StoredF32>>,
pub zscore: Option<ComputedFromDateLast<StoredF32>>,
pub p0_5sd: Option<ComputedDateLast<StoredF32>>,
pub p1sd: Option<ComputedDateLast<StoredF32>>,
pub p1_5sd: Option<ComputedDateLast<StoredF32>>,
pub p2sd: Option<ComputedDateLast<StoredF32>>,
pub p2_5sd: Option<ComputedDateLast<StoredF32>>,
pub p3sd: Option<ComputedDateLast<StoredF32>>,
pub m0_5sd: Option<ComputedDateLast<StoredF32>>,
pub m1sd: Option<ComputedDateLast<StoredF32>>,
pub m1_5sd: Option<ComputedDateLast<StoredF32>>,
pub m2sd: Option<ComputedDateLast<StoredF32>>,
pub m2_5sd: Option<ComputedDateLast<StoredF32>>,
pub m3sd: Option<ComputedDateLast<StoredF32>>,
pub p0_5sd: Option<ComputedFromDateLast<StoredF32>>,
pub p1sd: Option<ComputedFromDateLast<StoredF32>>,
pub p1_5sd: Option<ComputedFromDateLast<StoredF32>>,
pub p2sd: Option<ComputedFromDateLast<StoredF32>>,
pub p2_5sd: Option<ComputedFromDateLast<StoredF32>>,
pub p3sd: Option<ComputedFromDateLast<StoredF32>>,
pub m0_5sd: Option<ComputedFromDateLast<StoredF32>>,
pub m1sd: Option<ComputedFromDateLast<StoredF32>>,
pub m1_5sd: Option<ComputedFromDateLast<StoredF32>>,
pub m2sd: Option<ComputedFromDateLast<StoredF32>>,
pub m2_5sd: Option<ComputedFromDateLast<StoredF32>>,
pub m3sd: Option<ComputedFromDateLast<StoredF32>>,
pub _0sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p0_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p1sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p1_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p2sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p2_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p3sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m0_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m1sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m1_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m2sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m2_5sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m3sd_usd: Option<LazyBinaryDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub _0sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p0_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p1sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p1_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p2sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p2_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub p3sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m0_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m1sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m1_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m2sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m2_5sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
pub m3sd_usd: Option<LazyBinaryFromDateLast<Dollars, Close<Dollars>, StoredF32>>,
}
#[derive(Debug, Default)]
@@ -94,7 +94,7 @@ impl StandardDeviationVecsOptions {
}
}
impl ComputedStandardDeviationVecsDate {
impl ComputedFromDateStdDev {
#[allow(clippy::too_many_arguments)]
pub fn forced_import(
db: &Database,
@@ -109,7 +109,7 @@ impl ComputedStandardDeviationVecsDate {
macro_rules! import {
($suffix:expr) => {
ComputedDateLast::forced_import(
ComputedFromDateLast::forced_import(
db,
&format!("{name}_{}", $suffix),
version,
@@ -140,7 +140,7 @@ impl ComputedStandardDeviationVecsDate {
.zip($band.as_ref())
.filter(|_| options.price_bands())
.map(|(p, b)| {
LazyBinaryDateLast::from_computed_both_last::<ClosePriceTimesRatio>(
LazyBinaryFromDateLast::from_computed_both_last::<ClosePriceTimesRatio>(
&format!("{name}_{}", $suffix),
version,
p,
@@ -370,7 +370,7 @@ impl ComputedStandardDeviationVecsDate {
Ok(())
}
fn mut_stateful_computed(&mut self) -> impl Iterator<Item = &mut ComputedDateLast<StoredF32>> {
fn mut_stateful_computed(&mut self) -> impl Iterator<Item = &mut ComputedFromDateLast<StoredF32>> {
[
Some(&mut self.sd),
self.p0_5sd.as_mut(),

View File

@@ -7,22 +7,22 @@ use vecdb::{Database, Exit, IterableBoxedVec};
use crate::{
ComputeIndexes, indexes,
internal::{ComputedDateLast, LazyPeriodsLast, LazyDateLast, SatsToBitcoin},
internal::{ComputedFromDateLast, LazyDateDerivedLast, LazyFromDateLast, SatsToBitcoin},
price,
traits::ComputeFromBitcoin,
utils::OptionExt,
};
#[derive(Clone, Traversable)]
pub struct ValueLazyPeriodsLast {
pub sats: LazyPeriodsLast<Sats>,
pub bitcoin: LazyDateLast<Bitcoin, Sats>,
pub dollars: Option<ComputedDateLast<Dollars>>,
pub struct LazyValueDateDerivedLast {
pub sats: LazyDateDerivedLast<Sats>,
pub bitcoin: LazyFromDateLast<Bitcoin, Sats>,
pub dollars: Option<ComputedFromDateLast<Dollars>>,
}
const VERSION: Version = Version::ZERO;
impl ValueLazyPeriodsLast {
impl LazyValueDateDerivedLast {
pub fn from_source(
db: &Database,
name: &str,
@@ -31,9 +31,9 @@ impl ValueLazyPeriodsLast {
compute_dollars: bool,
indexes: &indexes::Vecs,
) -> Result<Self> {
let sats = LazyPeriodsLast::from_source(name, version + VERSION, source.clone(), indexes);
let sats = LazyDateDerivedLast::from_source(name, version + VERSION, source.clone(), indexes);
let bitcoin = LazyDateLast::from_derived::<SatsToBitcoin>(
let bitcoin = LazyFromDateLast::from_derived::<SatsToBitcoin>(
&format!("{name}_btc"),
version + VERSION,
source,
@@ -41,7 +41,7 @@ impl ValueLazyPeriodsLast {
);
let dollars = compute_dollars.then(|| {
ComputedDateLast::forced_import(db, &format!("{name}_usd"), version + VERSION, indexes)
ComputedFromDateLast::forced_import(db, &format!("{name}_usd"), version + VERSION, indexes)
.unwrap()
});
@@ -54,7 +54,7 @@ impl ValueLazyPeriodsLast {
pub fn compute_dollars<F>(&mut self, mut compute: F) -> Result<()>
where
F: FnMut(&mut ComputedDateLast<Dollars>) -> Result<()>,
F: FnMut(&mut ComputedFromDateLast<Dollars>) -> Result<()>,
{
if let Some(dollars) = self.dollars.as_mut() {
compute(dollars)?;

View File

@@ -8,21 +8,21 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
use crate::{ComputeIndexes, indexes, price};
use super::ValueLazyPeriodsLast;
use super::LazyValueDateDerivedLast;
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct ValueDateLast {
pub struct ValueFromDateLast {
#[traversable(rename = "sats")]
pub sats_dateindex: EagerVec<PcoVec<DateIndex, Sats>>,
#[deref]
#[deref_mut]
pub rest: ValueLazyPeriodsLast,
pub rest: LazyValueDateDerivedLast,
}
const VERSION: Version = Version::ZERO;
impl ValueDateLast {
impl ValueFromDateLast {
pub fn forced_import(
db: &Database,
name: &str,
@@ -32,7 +32,7 @@ impl ValueDateLast {
) -> Result<Self> {
let sats_dateindex = EagerVec::forced_import(db, name, version + VERSION)?;
let rest = ValueLazyPeriodsLast::from_source(
let rest = LazyValueDateDerivedLast::from_source(
db,
name,
sats_dateindex.boxed_clone(),
@@ -70,7 +70,7 @@ impl ValueDateLast {
pub fn compute_dollars<F>(&mut self, compute: F) -> Result<()>
where
F: FnMut(&mut crate::internal::ComputedDateLast<brk_types::Dollars>) -> Result<()>,
F: FnMut(&mut crate::internal::ComputedFromDateLast<brk_types::Dollars>) -> Result<()>,
{
self.rest.compute_dollars(compute)
}

View File

@@ -4,21 +4,21 @@ use brk_traversable::Traversable;
use brk_types::{Bitcoin, Dollars, Sats, Version};
use vecdb::{IterableCloneableVec, UnaryTransform};
use crate::internal::{LazyDateLast, ValueBlockLast, ValueDateLast};
use crate::internal::{LazyFromDateLast, ValueFromHeightLast, ValueFromDateLast};
const VERSION: Version = Version::ZERO;
#[derive(Clone, Traversable)]
pub struct LazyValueDateLast {
pub sats: LazyDateLast<Sats, Sats>,
pub bitcoin: LazyDateLast<Bitcoin, Sats>,
pub dollars: Option<LazyDateLast<Dollars, Dollars>>,
pub struct LazyValueFromDateLast {
pub sats: LazyFromDateLast<Sats, Sats>,
pub bitcoin: LazyFromDateLast<Bitcoin, Sats>,
pub dollars: Option<LazyFromDateLast<Dollars, Dollars>>,
}
impl LazyValueDateLast {
impl LazyValueFromDateLast {
pub fn from_source<SatsTransform, BitcoinTransform, DollarsTransform>(
name: &str,
source: &ValueDateLast,
source: &ValueFromDateLast,
version: Version,
) -> Self
where
@@ -28,14 +28,14 @@ impl LazyValueDateLast {
{
let v = version + VERSION;
let sats = LazyDateLast::from_derived::<SatsTransform>(
let sats = LazyFromDateLast::from_derived::<SatsTransform>(
name,
v,
source.sats_dateindex.boxed_clone(),
&source.sats,
);
let bitcoin = LazyDateLast::from_derived::<BitcoinTransform>(
let bitcoin = LazyFromDateLast::from_derived::<BitcoinTransform>(
&format!("{name}_btc"),
v,
source.sats_dateindex.boxed_clone(),
@@ -43,7 +43,7 @@ impl LazyValueDateLast {
);
let dollars = source.dollars.as_ref().map(|dollars_source| {
LazyDateLast::from_computed::<DollarsTransform>(
LazyFromDateLast::from_computed::<DollarsTransform>(
&format!("{name}_usd"),
v,
dollars_source.dateindex.boxed_clone(),
@@ -56,7 +56,7 @@ impl LazyValueDateLast {
pub fn from_block_source<SatsTransform, BitcoinTransform, DollarsTransform>(
name: &str,
source: &ValueBlockLast,
source: &ValueFromHeightLast,
version: Version,
) -> Self
where
@@ -66,25 +66,25 @@ impl LazyValueDateLast {
{
let v = version + VERSION;
let sats = LazyDateLast::from_derived::<SatsTransform>(
let sats = LazyFromDateLast::from_derived::<SatsTransform>(
name,
v,
source.sats.rest.dateindex.0.boxed_clone(),
source.sats.rest.dateindex.boxed_clone(),
&source.sats.rest.dates,
);
let bitcoin = LazyDateLast::from_derived::<BitcoinTransform>(
let bitcoin = LazyFromDateLast::from_derived::<BitcoinTransform>(
&format!("{name}_btc"),
v,
source.sats.rest.dateindex.0.boxed_clone(),
source.sats.rest.dateindex.boxed_clone(),
&source.sats.rest.dates,
);
let dollars = source.dollars.as_ref().map(|dollars_source| {
LazyDateLast::from_derived::<DollarsTransform>(
LazyFromDateLast::from_derived::<DollarsTransform>(
&format!("{name}_usd"),
v,
dollars_source.rest.dateindex.0.boxed_clone(),
dollars_source.rest.dateindex.boxed_clone(),
&dollars_source.rest.dates,
)
});

View File

@@ -7,27 +7,27 @@ use schemars::JsonSchema;
use vecdb::{BinaryTransform, IterableBoxedVec, LazyVecFrom2};
use crate::internal::{
ComputedBlockFull, ComputedVecValue, DerivedTxFull, LazyBinaryDerivedBlockSumCum, NumericValue,
ComputedFromHeightFull, ComputedVecValue, TxDerivedFull, LazyBinaryHeightDerivedSumCum, NumericValue,
};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyBinaryBlockFull<T, S1T = T, S2T = T>
pub struct LazyBinaryFromHeightFull<T, S1T = T, S2T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
S2T: ComputedVecValue,
{
#[traversable(wrap = "base")]
#[traversable(rename = "base")]
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
#[deref]
#[deref_mut]
pub rest: LazyBinaryDerivedBlockSumCum<T, S1T, S2T>,
pub rest: LazyBinaryHeightDerivedSumCum<T, S1T, S2T>,
}
const VERSION: Version = Version::ZERO;
impl<T, S1T, S2T> LazyBinaryBlockFull<T, S1T, S2T>
impl<T, S1T, S2T> LazyBinaryFromHeightFull<T, S1T, S2T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: NumericValue + JsonSchema,
@@ -38,14 +38,14 @@ where
version: Version,
height_source1: IterableBoxedVec<Height, S1T>,
height_source2: IterableBoxedVec<Height, S2T>,
source1: &ComputedBlockFull<S1T>,
source2: &DerivedTxFull<S2T>,
source1: &ComputedFromHeightFull<S1T>,
source2: &TxDerivedFull<S2T>,
) -> Self {
let v = version + VERSION;
Self {
height: LazyVecFrom2::transformed::<F>(name, v, height_source1, height_source2),
rest: LazyBinaryDerivedBlockSumCum::from_derived_full::<F, _, _, _, _>(
rest: LazyBinaryHeightDerivedSumCum::from_derived_full::<F, _, _, _, _>(
name,
v,
&source1.dateindex.sum_cum,

View File

@@ -7,14 +7,14 @@ use schemars::JsonSchema;
use vecdb::{BinaryTransform, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
use crate::internal::{
ComputedBlockLast, ComputedBlockSumCum, ComputedHeightDateLast, ComputedVecValue,
LazyBinaryDateLast, LazyBinaryDerivedBlockLast, LazyBinaryTransformLast, LazyPeriodsLast,
NumericValue,
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedFromHeightAndDateLast, ComputedVecValue,
LazyBinaryComputedFromHeightLast, LazyBinaryFromDateLast, LazyBinaryHeightDerivedLast,
LazyBinaryTransformLast, LazyDateDerivedLast, NumericValue,
};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyBinaryBlockLast<T, S1T = T, S2T = T>
pub struct LazyBinaryFromHeightLast<T, S1T = T, S2T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
@@ -23,12 +23,12 @@ where
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
#[deref]
#[deref_mut]
pub rest: LazyBinaryDerivedBlockLast<T, S1T, S2T>,
pub rest: LazyBinaryHeightDerivedLast<T, S1T, S2T>,
}
const VERSION: Version = Version::ZERO;
impl<T, S1T, S2T> LazyBinaryBlockLast<T, S1T, S2T>
impl<T, S1T, S2T> LazyBinaryFromHeightLast<T, S1T, S2T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: ComputedVecValue + JsonSchema,
@@ -37,8 +37,8 @@ where
pub fn from_computed_sum_cum<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedBlockSumCum<S1T>,
source2: &ComputedBlockSumCum<S2T>,
source1: &ComputedFromHeightSumCum<S1T>,
source2: &ComputedFromHeightSumCum<S2T>,
) -> Self
where
S1T: PartialOrd,
@@ -50,18 +50,18 @@ where
height: LazyVecFrom2::transformed::<F>(
name,
v,
source1.height_cumulative.0.boxed_clone(),
source2.height_cumulative.0.boxed_clone(),
source1.height_cumulative.boxed_clone(),
source2.height_cumulative.boxed_clone(),
),
rest: LazyBinaryDerivedBlockLast::from_computed_sum_cum::<F>(name, v, source1, source2),
rest: LazyBinaryHeightDerivedLast::from_computed_sum_cum::<F>(name, v, source1, source2),
}
}
pub fn from_computed_last<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedBlockLast<S1T>,
source2: &ComputedBlockLast<S2T>,
source1: &ComputedFromHeightLast<S1T>,
source2: &ComputedFromHeightLast<S2T>,
) -> Self
where
S1T: NumericValue,
@@ -76,15 +76,15 @@ where
source1.height.boxed_clone(),
source2.height.boxed_clone(),
),
rest: LazyBinaryDerivedBlockLast::from_computed_last::<F>(name, v, source1, source2),
rest: LazyBinaryHeightDerivedLast::from_computed_last::<F>(name, v, source1, source2),
}
}
pub fn from_computed_height_date_last<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedHeightDateLast<S1T>,
source2: &ComputedHeightDateLast<S2T>,
source1: &ComputedFromHeightAndDateLast<S1T>,
source2: &ComputedFromHeightAndDateLast<S2T>,
) -> Self
where
S1T: PartialOrd,
@@ -99,18 +99,18 @@ where
source1.height.boxed_clone(),
source2.height.boxed_clone(),
),
rest: LazyBinaryDerivedBlockLast::from_computed_height_date_last::<F>(
rest: LazyBinaryHeightDerivedLast::from_computed_height_date_last::<F>(
name, v, source1, source2,
),
}
}
/// Create from a ComputedHeightDateLast and a LazyBinaryBlockLast.
/// Create from a ComputedFromHeightAndDateLast and a LazyBinaryFromHeightLast.
pub fn from_computed_height_date_and_binary_block<F, S2aT, S2bT>(
name: &str,
version: Version,
source1: &ComputedHeightDateLast<S1T>,
source2: &LazyBinaryBlockLast<S2T, S2aT, S2bT>,
source1: &ComputedFromHeightAndDateLast<S1T>,
source2: &LazyBinaryFromHeightLast<S2T, S2aT, S2bT>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
@@ -127,8 +127,8 @@ where
source1.height.boxed_clone(),
source2.height.boxed_clone(),
),
rest: LazyBinaryDerivedBlockLast {
dates: LazyBinaryDateLast::from_computed_and_binary_last::<F, _, _>(
rest: LazyBinaryHeightDerivedLast {
dates: LazyBinaryFromDateLast::from_computed_and_binary_last::<F, _, _>(
name,
v,
&source1.rest,
@@ -137,19 +137,19 @@ where
difficultyepoch: LazyBinaryTransformLast::from_vecs::<F>(
name,
v,
source1.difficultyepoch.0.boxed_clone(),
source1.difficultyepoch.boxed_clone(),
source2.rest.difficultyepoch.boxed_clone(),
),
},
}
}
/// Create from a ComputedHeightDateLast and a ComputedBlockLast.
/// Create from a ComputedFromHeightAndDateLast and a ComputedFromHeightLast.
pub fn from_computed_height_date_and_block_last<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedHeightDateLast<S1T>,
source2: &ComputedBlockLast<S2T>,
source1: &ComputedFromHeightAndDateLast<S1T>,
source2: &ComputedFromHeightLast<S2T>,
) -> Self
where
S1T: PartialOrd,
@@ -164,18 +164,18 @@ where
source1.height.boxed_clone(),
source2.height.boxed_clone(),
),
rest: LazyBinaryDerivedBlockLast::from_computed_height_date_and_block_last::<F>(
rest: LazyBinaryHeightDerivedLast::from_computed_height_date_and_block_last::<F>(
name, v, source1, source2,
),
}
}
/// Create from a LazyBinaryBlockLast and a ComputedBlockLast.
/// Create from a LazyBinaryFromHeightLast and a ComputedFromHeightLast.
pub fn from_binary_block_and_computed_block_last<F, S1aT, S1bT>(
name: &str,
version: Version,
source1: &LazyBinaryBlockLast<S1T, S1aT, S1bT>,
source2: &ComputedBlockLast<S2T>,
source1: &LazyBinaryFromHeightLast<S1T, S1aT, S1bT>,
source2: &ComputedFromHeightLast<S2T>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
@@ -192,8 +192,8 @@ where
source1.height.boxed_clone(),
source2.height.boxed_clone(),
),
rest: LazyBinaryDerivedBlockLast {
dates: LazyBinaryDateLast::from_binary_and_block_last::<F, _, _>(
rest: LazyBinaryHeightDerivedLast {
dates: LazyBinaryFromDateLast::from_binary_and_block_last::<F, _, _>(
name,
v,
&source1.rest.dates,
@@ -209,12 +209,12 @@ where
}
}
/// Create from two LazyBinaryBlockLast sources.
/// Create from two LazyBinaryFromHeightLast sources.
pub fn from_both_binary_block<F, S1aT, S1bT, S2aT, S2bT>(
name: &str,
version: Version,
source1: &LazyBinaryBlockLast<S1T, S1aT, S1bT>,
source2: &LazyBinaryBlockLast<S2T, S2aT, S2bT>,
source1: &LazyBinaryFromHeightLast<S1T, S1aT, S1bT>,
source2: &LazyBinaryFromHeightLast<S2T, S2aT, S2bT>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
@@ -232,8 +232,8 @@ where
source1.height.boxed_clone(),
source2.height.boxed_clone(),
),
rest: LazyBinaryDerivedBlockLast {
dates: LazyBinaryDateLast::from_both_binary_last::<F, _, _, _, _>(
rest: LazyBinaryHeightDerivedLast {
dates: LazyBinaryFromDateLast::from_both_binary_last::<F, _, _, _, _>(
name,
v,
&source1.rest.dates,
@@ -251,7 +251,7 @@ where
/// Create from separate height, difficultyepoch, and date sources.
///
/// Use when sources are split across different types (e.g., ValueHeightDateLast + ComputedBlockLast).
/// Use when sources are split across different types (e.g., ValueFromHeightAndDateLast + ComputedFromHeightLast).
#[allow(clippy::too_many_arguments)]
pub fn from_height_difficultyepoch_dates<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
@@ -261,16 +261,16 @@ where
difficultyepoch_source1: IterableBoxedVec<DifficultyEpoch, S1T>,
difficultyepoch_source2: IterableBoxedVec<DifficultyEpoch, S2T>,
dateindex_source1: IterableBoxedVec<DateIndex, S1T>,
dates_source1: &LazyPeriodsLast<S1T>,
dates_source1: &LazyDateDerivedLast<S1T>,
dateindex_source2: IterableBoxedVec<DateIndex, S2T>,
dates_source2: &LazyPeriodsLast<S2T>,
dates_source2: &LazyDateDerivedLast<S2T>,
) -> Self {
let v = version + VERSION;
Self {
height: LazyVecFrom2::transformed::<F>(name, v, height_source1, height_source2),
rest: LazyBinaryDerivedBlockLast {
dates: LazyBinaryDateLast::from_both_derived_last::<F>(
rest: LazyBinaryHeightDerivedLast {
dates: LazyBinaryFromDateLast::from_both_derived_last::<F>(
name,
v,
dateindex_source1,
@@ -287,4 +287,86 @@ where
},
}
}
/// Create from a ComputedFromHeightAndDateLast and a LazyBinaryComputedFromHeightLast.
pub fn from_computed_height_date_and_lazy_binary_block_last<F, S2aT, S2bT>(
name: &str,
version: Version,
source1: &ComputedFromHeightAndDateLast<S1T>,
source2: &LazyBinaryComputedFromHeightLast<S2T, S2aT, S2bT>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
S1T: PartialOrd,
S2aT: ComputedVecValue + JsonSchema,
S2bT: ComputedVecValue + JsonSchema,
{
let v = version + VERSION;
Self {
height: LazyVecFrom2::transformed::<F>(
name,
v,
source1.height.boxed_clone(),
source2.height.boxed_clone(),
),
rest: LazyBinaryHeightDerivedLast {
dates: LazyBinaryFromDateLast::from_both_derived_last::<F>(
name,
v,
source1.rest.dateindex.boxed_clone(),
&source1.rest.rest,
source2.rest.dateindex.boxed_clone(),
&source2.rest.dates,
),
difficultyepoch: LazyBinaryTransformLast::from_vecs::<F>(
name,
v,
source1.difficultyepoch.boxed_clone(),
source2.rest.difficultyepoch.boxed_clone(),
),
},
}
}
/// Create from a LazyBinaryFromHeightLast and a LazyBinaryComputedFromHeightLast.
pub fn from_binary_block_and_lazy_binary_block_last<F, S1aT, S1bT, S2aT, S2bT>(
name: &str,
version: Version,
source1: &LazyBinaryFromHeightLast<S1T, S1aT, S1bT>,
source2: &LazyBinaryComputedFromHeightLast<S2T, S2aT, S2bT>,
) -> Self
where
F: BinaryTransform<S1T, S2T, T>,
S1aT: ComputedVecValue + JsonSchema,
S1bT: ComputedVecValue + JsonSchema,
S2aT: ComputedVecValue + JsonSchema,
S2bT: ComputedVecValue + JsonSchema,
{
let v = version + VERSION;
Self {
height: LazyVecFrom2::transformed::<F>(
name,
v,
source1.height.boxed_clone(),
source2.height.boxed_clone(),
),
rest: LazyBinaryHeightDerivedLast {
dates: LazyBinaryFromDateLast::from_binary_and_derived_last::<F, _, _>(
name,
v,
&source1.rest.dates,
source2.rest.dateindex.boxed_clone(),
&source2.rest.dates,
),
difficultyepoch: LazyBinaryTransformLast::from_vecs::<F>(
name,
v,
source1.rest.difficultyepoch.boxed_clone(),
source2.rest.difficultyepoch.boxed_clone(),
),
},
}
}
}

View File

@@ -7,7 +7,7 @@ use schemars::JsonSchema;
use vecdb::{BinaryTransform, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
use crate::internal::{
ComputedBlockSum, ComputedDerivedBlockSum, ComputedVecValue, LazyBinaryDerivedBlockSum,
ComputedFromHeightSum, ComputedHeightDerivedSum, ComputedVecValue, LazyBinaryHeightDerivedSum,
NumericValue,
};
@@ -15,7 +15,7 @@ const VERSION: Version = Version::ZERO;
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyBinaryBlockSum<T, S1T, S2T>
pub struct LazyBinaryFromHeightSum<T, S1T, S2T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
@@ -25,10 +25,10 @@ where
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
#[deref]
#[deref_mut]
pub rest: LazyBinaryDerivedBlockSum<T, S1T, S2T>,
pub rest: LazyBinaryHeightDerivedSum<T, S1T, S2T>,
}
impl<T, S1T, S2T> LazyBinaryBlockSum<T, S1T, S2T>
impl<T, S1T, S2T> LazyBinaryFromHeightSum<T, S1T, S2T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: NumericValue + JsonSchema,
@@ -39,22 +39,22 @@ where
version: Version,
height_source1: IterableBoxedVec<Height, S1T>,
height_source2: IterableBoxedVec<Height, S2T>,
source1: &ComputedDerivedBlockSum<S1T>,
source2: &ComputedDerivedBlockSum<S2T>,
source1: &ComputedHeightDerivedSum<S1T>,
source2: &ComputedHeightDerivedSum<S2T>,
) -> Self {
let v = version + VERSION;
Self {
height: LazyVecFrom2::transformed::<F>(name, v, height_source1, height_source2),
rest: LazyBinaryDerivedBlockSum::from_derived::<F>(name, v, source1, source2),
rest: LazyBinaryHeightDerivedSum::from_derived::<F>(name, v, source1, source2),
}
}
pub fn from_computed<F: BinaryTransform<S1T, S2T, T>>(
name: &str,
version: Version,
source1: &ComputedBlockSum<S1T>,
source2: &ComputedBlockSum<S2T>,
source1: &ComputedFromHeightSum<S1T>,
source2: &ComputedFromHeightSum<S2T>,
) -> Self {
let v = version + VERSION;
@@ -65,7 +65,7 @@ where
source1.height.boxed_clone(),
source2.height.boxed_clone(),
),
rest: LazyBinaryDerivedBlockSum::from_derived::<F>(name, v, &source1.rest, &source2.rest),
rest: LazyBinaryHeightDerivedSum::from_derived::<F>(name, v, &source1.rest, &source2.rest),
}
}
}

View File

@@ -7,13 +7,13 @@ use schemars::JsonSchema;
use vecdb::{BinaryTransform, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
use crate::internal::{
ComputedBlockLast, ComputedBlockSumCum, ComputedDerivedBlockLast, ComputedDerivedBlockSumCum,
ComputedVecValue, LazyBinaryDerivedBlockSumCum, NumericValue,
ComputedFromHeightLast, ComputedFromHeightSumCum, ComputedHeightDerivedLast, ComputedHeightDerivedSumCum,
ComputedVecValue, LazyBinaryHeightDerivedSumCum, NumericValue,
};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyBinaryBlockSumCum<T, S1T = T, S2T = T>
pub struct LazyBinaryFromHeightSumCum<T, S1T = T, S2T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
@@ -25,12 +25,12 @@ where
pub height_cumulative: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
#[deref]
#[deref_mut]
pub rest: LazyBinaryDerivedBlockSumCum<T, S1T, S2T>,
pub rest: LazyBinaryHeightDerivedSumCum<T, S1T, S2T>,
}
const VERSION: Version = Version::ZERO;
impl<T, S1T, S2T> LazyBinaryBlockSumCum<T, S1T, S2T>
impl<T, S1T, S2T> LazyBinaryFromHeightSumCum<T, S1T, S2T>
where
T: ComputedVecValue + JsonSchema + 'static,
S1T: ComputedVecValue + JsonSchema,
@@ -41,8 +41,8 @@ where
version: Version,
height_source1: IterableBoxedVec<Height, S1T>,
height_source2: IterableBoxedVec<Height, S2T>,
source1: &ComputedBlockSumCum<S1T>,
source2: &ComputedBlockSumCum<S2T>,
source1: &ComputedFromHeightSumCum<S1T>,
source2: &ComputedFromHeightSumCum<S2T>,
) -> Self
where
S1T: PartialOrd,
@@ -55,10 +55,10 @@ where
height_cumulative: LazyVecFrom2::transformed::<F>(
&format!("{name}_cumulative"),
v,
source1.height_cumulative.0.boxed_clone(),
source2.height_cumulative.0.boxed_clone(),
source1.height_cumulative.boxed_clone(),
source2.height_cumulative.boxed_clone(),
),
rest: LazyBinaryDerivedBlockSumCum::from_computed_sum_raw::<F>(
rest: LazyBinaryHeightDerivedSumCum::from_computed_sum_raw::<F>(
name,
v,
&source1.dateindex,
@@ -76,8 +76,8 @@ where
version: Version,
height_source1: IterableBoxedVec<Height, S1T>,
height_source2: IterableBoxedVec<Height, S2T>,
source1: &ComputedDerivedBlockSumCum<S1T>,
source2: &ComputedDerivedBlockSumCum<S2T>,
source1: &ComputedHeightDerivedSumCum<S1T>,
source2: &ComputedHeightDerivedSumCum<S2T>,
) -> Self
where
S1T: PartialOrd,
@@ -90,10 +90,10 @@ where
height_cumulative: LazyVecFrom2::transformed::<F>(
&format!("{name}_cumulative"),
v,
source1.height_cumulative.0.boxed_clone(),
source2.height_cumulative.0.boxed_clone(),
source1.height_cumulative.boxed_clone(),
source2.height_cumulative.boxed_clone(),
),
rest: LazyBinaryDerivedBlockSumCum::from_computed_sum_raw::<F>(
rest: LazyBinaryHeightDerivedSumCum::from_computed_sum_raw::<F>(
name,
v,
&source1.dateindex,
@@ -113,8 +113,8 @@ where
version: Version,
height_source1: IterableBoxedVec<Height, S1T>,
height_source2: IterableBoxedVec<Height, S2T>,
source1: &ComputedBlockSumCum<S1T>,
source2: &ComputedBlockLast<S2T>,
source1: &ComputedFromHeightSumCum<S1T>,
source2: &ComputedFromHeightLast<S2T>,
) -> Self
where
S1T: PartialOrd,
@@ -126,10 +126,10 @@ where
height_cumulative: LazyVecFrom2::transformed::<F>(
&format!("{name}_cumulative"),
v,
source1.height_cumulative.0.boxed_clone(),
source1.height_cumulative.boxed_clone(),
source2.height.boxed_clone(),
),
rest: LazyBinaryDerivedBlockSumCum::from_computed_last::<F>(name, v, source1, source2),
rest: LazyBinaryHeightDerivedSumCum::from_computed_last::<F>(name, v, source1, source2),
}
}
@@ -138,8 +138,8 @@ where
version: Version,
height_source1: IterableBoxedVec<Height, S1T>,
height_source2: IterableBoxedVec<Height, S2T>,
source1: &ComputedDerivedBlockSumCum<S1T>,
source2: &ComputedBlockLast<S2T>,
source1: &ComputedHeightDerivedSumCum<S1T>,
source2: &ComputedFromHeightLast<S2T>,
) -> Self
where
S1T: NumericValue,
@@ -151,10 +151,10 @@ where
height_cumulative: LazyVecFrom2::transformed::<F>(
&format!("{name}_cumulative"),
v,
source1.height_cumulative.0.boxed_clone(),
source1.height_cumulative.boxed_clone(),
source2.height.boxed_clone(),
),
rest: LazyBinaryDerivedBlockSumCum::from_derived_computed_last::<F>(name, v, source1, source2),
rest: LazyBinaryHeightDerivedSumCum::from_derived_computed_last::<F>(name, v, source1, source2),
}
}
@@ -163,8 +163,8 @@ where
version: Version,
height_source1: IterableBoxedVec<Height, S1T>,
height_source2: IterableBoxedVec<Height, S2T>,
source1: &ComputedDerivedBlockSumCum<S1T>,
source2: &ComputedDerivedBlockLast<S2T>,
source1: &ComputedHeightDerivedSumCum<S1T>,
source2: &ComputedHeightDerivedLast<S2T>,
) -> Self
where
S1T: NumericValue,
@@ -176,10 +176,10 @@ where
height_cumulative: LazyVecFrom2::transformed::<F>(
&format!("{name}_cumulative"),
v,
source1.height_cumulative.0.boxed_clone(),
source1.height_cumulative.boxed_clone(),
height_source2,
),
rest: LazyBinaryDerivedBlockSumCum::from_derived_last::<F>(name, v, source1, source2),
rest: LazyBinaryHeightDerivedSumCum::from_derived_last::<F>(name, v, source1, source2),
}
}
@@ -188,8 +188,8 @@ where
version: Version,
height_source1: IterableBoxedVec<Height, S1T>,
height_source2: IterableBoxedVec<Height, S2T>,
source1: &ComputedBlockSumCum<S1T>,
source2: &ComputedDerivedBlockLast<S2T>,
source1: &ComputedFromHeightSumCum<S1T>,
source2: &ComputedHeightDerivedLast<S2T>,
) -> Self
where
S1T: PartialOrd,
@@ -201,10 +201,10 @@ where
height_cumulative: LazyVecFrom2::transformed::<F>(
&format!("{name}_cumulative"),
v,
source1.height_cumulative.0.boxed_clone(),
source1.height_cumulative.boxed_clone(),
height_source2,
),
rest: LazyBinaryDerivedBlockSumCum::from_computed_derived_last::<F>(name, v, source1, source2),
rest: LazyBinaryHeightDerivedSumCum::from_computed_derived_last::<F>(name, v, source1, source2),
}
}
}

View File

@@ -1,4 +1,4 @@
//! ComputedBlock with full stats aggregation.
//! ComputedFromHeight with full stats aggregation.
use brk_error::Result;
@@ -10,24 +10,24 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
use crate::{ComputeIndexes, indexes};
use crate::internal::{ComputedVecValue, ComputedDerivedBlockFull, NumericValue};
use crate::internal::{ComputedVecValue, ComputedHeightDerivedFull, NumericValue};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct ComputedBlockFull<T>
pub struct ComputedFromHeightFull<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
#[traversable(wrap = "base")]
#[traversable(rename = "base")]
pub height: EagerVec<PcoVec<Height, T>>,
#[deref]
#[deref_mut]
pub rest: ComputedDerivedBlockFull<T>,
pub rest: ComputedHeightDerivedFull<T>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedBlockFull<T>
impl<T> ComputedFromHeightFull<T>
where
T: NumericValue + JsonSchema,
{
@@ -41,7 +41,7 @@ where
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
let rest = ComputedDerivedBlockFull::forced_import(
let rest = ComputedHeightDerivedFull::forced_import(
db,
name,
height.boxed_clone(),

View File

@@ -1,4 +1,4 @@
//! ComputedBlock using Sum-only aggregation.
//! ComputedFromHeight using only LastVec aggregation.
use brk_error::Result;
@@ -10,11 +10,11 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVe
use crate::{ComputeIndexes, indexes};
use crate::internal::{ComputedVecValue, ComputedDerivedBlockSum, NumericValue};
use crate::internal::{ComputedVecValue, ComputedHeightDerivedLast, NumericValue};
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct ComputedBlockSum<T>
pub struct ComputedFromHeightLast<T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
{
@@ -22,12 +22,12 @@ where
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub rest: ComputedDerivedBlockSum<T>,
pub rest: ComputedHeightDerivedLast<T>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedBlockSum<T>
impl<T> ComputedFromHeightLast<T>
where
T: NumericValue + JsonSchema,
{
@@ -42,7 +42,7 @@ where
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
let rest =
ComputedDerivedBlockSum::forced_import(db, name, height.boxed_clone(), v, indexes)?;
ComputedHeightDerivedLast::forced_import(db, name, height.boxed_clone(), v, indexes)?;
Ok(Self { height, rest })
}

View File

@@ -0,0 +1,70 @@
//! LazyBinaryComputedFromHeightFull - block full with lazy binary transform at height level.
//!
//! Height-level values are lazy: `transform(source1[h], source2[h])`.
//! Cumulative, dateindex stats, and difficultyepoch are stored since they
//! require aggregation across heights.
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Height, Version};
use derive_more::{Deref, DerefMut};
use schemars::JsonSchema;
use vecdb::{BinaryTransform, Database, Exit, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
use crate::{
ComputeIndexes, indexes,
internal::{ComputedHeightDerivedFull, ComputedVecValue, NumericValue},
};
const VERSION: Version = Version::ZERO;
/// Block full aggregation with lazy binary transform at height + computed derived indexes.
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyBinaryComputedFromHeightFull<T, S1T = T, S2T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
S2T: ComputedVecValue,
{
#[traversable(rename = "base")]
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
#[deref]
#[deref_mut]
pub rest: ComputedHeightDerivedFull<T>,
}
impl<T, S1T, S2T> LazyBinaryComputedFromHeightFull<T, S1T, S2T>
where
T: NumericValue + JsonSchema,
S1T: ComputedVecValue + JsonSchema,
S2T: ComputedVecValue + JsonSchema,
{
pub fn forced_import<F: BinaryTransform<S1T, S2T, T>>(
db: &Database,
name: &str,
version: Version,
source1: IterableBoxedVec<Height, S1T>,
source2: IterableBoxedVec<Height, S2T>,
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
let height = LazyVecFrom2::transformed::<F>(name, v, source1, source2);
let rest =
ComputedHeightDerivedFull::forced_import(db, name, height.boxed_clone(), v, indexes)?;
Ok(Self { height, rest })
}
pub fn derive_from(
&mut self,
indexes: &indexes::Vecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.rest
.derive_from(indexes, starting_indexes, &self.height, exit)
}
}

View File

@@ -0,0 +1,70 @@
//! LazyBinaryComputedFromHeightLast - block last with lazy binary transform at height level.
//!
//! Height-level value is lazy: `transform(source1[h], source2[h])`.
//! DateIndex last is stored since it requires finding the last value within each date
//! (which may span multiple heights with varying prices).
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Height, Version};
use derive_more::{Deref, DerefMut};
use schemars::JsonSchema;
use vecdb::{BinaryTransform, Database, Exit, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
use crate::{
ComputeIndexes, indexes,
internal::{ComputedHeightDerivedLast, ComputedVecValue, NumericValue},
};
const VERSION: Version = Version::ZERO;
/// Block last aggregation with lazy binary transform at height + computed derived indexes.
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyBinaryComputedFromHeightLast<T, S1T = T, S2T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
S2T: ComputedVecValue,
{
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub rest: ComputedHeightDerivedLast<T>,
}
impl<T, S1T, S2T> LazyBinaryComputedFromHeightLast<T, S1T, S2T>
where
T: NumericValue + JsonSchema,
S1T: ComputedVecValue + JsonSchema,
S2T: ComputedVecValue + JsonSchema,
{
pub fn forced_import<F: BinaryTransform<S1T, S2T, T>>(
db: &Database,
name: &str,
version: Version,
source1: IterableBoxedVec<Height, S1T>,
source2: IterableBoxedVec<Height, S2T>,
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
let height = LazyVecFrom2::transformed::<F>(name, v, source1, source2);
let rest =
ComputedHeightDerivedLast::forced_import(db, name, height.boxed_clone(), v, indexes)?;
Ok(Self { height, rest })
}
pub fn derive_from(
&mut self,
indexes: &indexes::Vecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.rest
.derive_from(indexes, starting_indexes, &self.height, exit)
}
}

View File

@@ -0,0 +1,70 @@
//! LazyBinaryComputedFromHeightSum - block sum with lazy binary transform at height level.
//!
//! Height-level sum is lazy: `transform(source1[h], source2[h])`.
//! DateIndex stats are stored since they require aggregation across heights.
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Height, Version};
use derive_more::{Deref, DerefMut};
use schemars::JsonSchema;
use vecdb::{BinaryTransform, Database, Exit, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
use crate::{
ComputeIndexes, indexes,
internal::{ComputedHeightDerivedSum, ComputedVecValue, NumericValue},
};
const VERSION: Version = Version::ZERO;
/// Block sum aggregation with lazy binary transform at height + computed derived indexes.
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyBinaryComputedFromHeightSum<T, S1T = T, S2T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
S2T: ComputedVecValue,
{
#[traversable(rename = "sum")]
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub rest: ComputedHeightDerivedSum<T>,
}
impl<T, S1T, S2T> LazyBinaryComputedFromHeightSum<T, S1T, S2T>
where
T: NumericValue + JsonSchema,
S1T: ComputedVecValue + JsonSchema,
S2T: ComputedVecValue + JsonSchema,
{
pub fn forced_import<F: BinaryTransform<S1T, S2T, T>>(
db: &Database,
name: &str,
version: Version,
source1: IterableBoxedVec<Height, S1T>,
source2: IterableBoxedVec<Height, S2T>,
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
let height = LazyVecFrom2::transformed::<F>(name, v, source1, source2);
let rest =
ComputedHeightDerivedSum::forced_import(db, name, height.boxed_clone(), v, indexes)?;
Ok(Self { height, rest })
}
pub fn derive_from(
&mut self,
indexes: &indexes::Vecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.rest
.derive_from(indexes, starting_indexes, &self.height, exit)
}
}

View File

@@ -0,0 +1,71 @@
//! LazyBinaryComputedFromHeightSumCum - block sum_cum with lazy binary transform at height level.
//!
//! Height-level sum is lazy: `transform(source1[h], source2[h])`.
//! Cumulative and dateindex stats are stored since they require aggregation
//! across heights.
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Height, Version};
use derive_more::{Deref, DerefMut};
use schemars::JsonSchema;
use vecdb::{BinaryTransform, Database, Exit, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2};
use crate::{
ComputeIndexes, indexes,
internal::{ComputedHeightDerivedSumCum, ComputedVecValue, NumericValue},
};
const VERSION: Version = Version::ZERO;
/// Block sum_cum aggregation with lazy binary transform at height + computed derived indexes.
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyBinaryComputedFromHeightSumCum<T, S1T = T, S2T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
S2T: ComputedVecValue,
{
#[traversable(rename = "sum")]
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub rest: ComputedHeightDerivedSumCum<T>,
}
impl<T, S1T, S2T> LazyBinaryComputedFromHeightSumCum<T, S1T, S2T>
where
T: NumericValue + JsonSchema,
S1T: ComputedVecValue + JsonSchema,
S2T: ComputedVecValue + JsonSchema,
{
pub fn forced_import<F: BinaryTransform<S1T, S2T, T>>(
db: &Database,
name: &str,
version: Version,
source1: IterableBoxedVec<Height, S1T>,
source2: IterableBoxedVec<Height, S2T>,
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
let height = LazyVecFrom2::transformed::<F>(name, v, source1, source2);
let rest =
ComputedHeightDerivedSumCum::forced_import(db, name, height.boxed_clone(), v, indexes)?;
Ok(Self { height, rest })
}
pub fn derive_from(
&mut self,
indexes: &indexes::Vecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.rest
.derive_from(indexes, starting_indexes, &self.height, exit)
}
}

View File

@@ -1,4 +1,4 @@
//! LazyBlockFullHeight - block full with lazy height transform.
//! LazyComputedFromHeightFull - block full with lazy height transform.
use brk_error::Result;
use brk_traversable::Traversable;
@@ -9,7 +9,7 @@ use vecdb::{Database, Exit, IterableCloneableVec, LazyVecFrom1, UnaryTransform};
use crate::{
ComputeIndexes, indexes,
internal::{ComputedVecValue, ComputedDerivedBlockFull, NumericValue},
internal::{ComputedVecValue, ComputedHeightDerivedFull, NumericValue},
};
const VERSION: Version = Version::ZERO;
@@ -17,7 +17,7 @@ const VERSION: Version = Version::ZERO;
/// Block full aggregation with lazy height transform + computed derived indexes.
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyBlockFullHeight<T, S = T>
pub struct LazyComputedFromHeightFull<T, S = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S: ComputedVecValue,
@@ -26,10 +26,10 @@ where
pub height: LazyVecFrom1<Height, T, Height, S>,
#[deref]
#[deref_mut]
pub rest: ComputedDerivedBlockFull<T>,
pub rest: ComputedHeightDerivedFull<T>,
}
impl<T, S> LazyBlockFullHeight<T, S>
impl<T, S> LazyComputedFromHeightFull<T, S>
where
T: NumericValue + JsonSchema,
S: ComputedVecValue + JsonSchema,
@@ -46,7 +46,7 @@ where
let height = LazyVecFrom1::transformed::<F>(name, v, source.boxed_clone());
let rest =
ComputedDerivedBlockFull::forced_import(db, name, height.boxed_clone(), v, indexes)?;
ComputedHeightDerivedFull::forced_import(db, name, height.boxed_clone(), v, indexes)?;
Ok(Self { height, rest })
}
@@ -64,7 +64,7 @@ where
let height = LazyVecFrom1::init(name, v, source.boxed_clone(), init_fn);
let rest =
ComputedDerivedBlockFull::forced_import(db, name, height.boxed_clone(), v, indexes)?;
ComputedHeightDerivedFull::forced_import(db, name, height.boxed_clone(), v, indexes)?;
Ok(Self { height, rest })
}

View File

@@ -1,4 +1,4 @@
//! LazyBlockSumCumHeight - block sum+cumulative with lazy height transform.
//! LazyComputedFromHeightSumCum - block sum+cumulative with lazy height transform.
//!
//! Use this when you need:
//! - Lazy height (binary transform from two sources)
@@ -14,7 +14,7 @@ use vecdb::{Database, Exit, IterableCloneableVec, LazyVecFrom2};
use crate::{indexes, ComputeIndexes};
use crate::internal::{ComputedVecValue, ComputedDerivedBlockSumCum, NumericValue};
use crate::internal::{ComputedVecValue, ComputedHeightDerivedSumCum, NumericValue};
/// Block sum+cumulative with lazy binary height transform + computed derived indexes.
///
@@ -23,7 +23,7 @@ use crate::internal::{ComputedVecValue, ComputedDerivedBlockSumCum, NumericValue
/// Coarser periods are lazy lookups.
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(merge)]
pub struct LazyBlockSumCumHeight<T, S1T = T, S2T = T>
pub struct LazyComputedFromHeightSumCum<T, S1T = T, S2T = T>
where
T: ComputedVecValue + PartialOrd + JsonSchema,
S1T: ComputedVecValue,
@@ -33,12 +33,12 @@ where
pub height: LazyVecFrom2<Height, T, Height, S1T, Height, S2T>,
#[deref]
#[deref_mut]
pub rest: ComputedDerivedBlockSumCum<T>,
pub rest: ComputedHeightDerivedSumCum<T>,
}
const VERSION: Version = Version::ZERO;
impl<T, S1T, S2T> LazyBlockSumCumHeight<T, S1T, S2T>
impl<T, S1T, S2T> LazyComputedFromHeightSumCum<T, S1T, S2T>
where
T: NumericValue + JsonSchema,
S1T: ComputedVecValue + JsonSchema,
@@ -53,7 +53,7 @@ where
) -> Result<Self> {
let v = version + VERSION;
let rest = ComputedDerivedBlockSumCum::forced_import(
let rest = ComputedHeightDerivedSumCum::forced_import(
db,
name,
height.boxed_clone(),

Some files were not shown because too many files have changed in this diff Show More