mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -2,21 +2,20 @@ use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Height, Indexes, Sats, StoredF64, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::internal::ComputedFromHeightCumulativeSum;
|
||||
|
||||
use crate::{blocks, distribution::metrics::ImportConfig, prices};
|
||||
|
||||
use super::CoreActivity;
|
||||
use super::ActivityCore;
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct ActivityMetrics<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub core: CoreActivity<M>,
|
||||
pub core: ActivityCore<M>,
|
||||
|
||||
pub coinblocks_destroyed: ComputedFromHeightCumulativeSum<StoredF64, M>,
|
||||
pub coindays_destroyed: ComputedFromHeightCumulativeSum<StoredF64, M>,
|
||||
@@ -25,7 +24,7 @@ pub struct ActivityMetrics<M: StorageMode = Rw> {
|
||||
impl ActivityMetrics {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
Ok(Self {
|
||||
core: CoreActivity::forced_import(cfg)?,
|
||||
core: ActivityCore::forced_import(cfg)?,
|
||||
coinblocks_destroyed: cfg
|
||||
.import_cumulative_sum("coinblocks_destroyed", Version::ONE)?,
|
||||
coindays_destroyed: cfg.import_cumulative_sum("coindays_destroyed", Version::ONE)?,
|
||||
@@ -58,13 +57,12 @@ impl ActivityMetrics {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn par_iter_mut(&mut self) -> impl ParallelIterator<Item = &mut dyn AnyStoredVec> {
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
vec![
|
||||
&mut self.core.sent.base.sats.height as &mut dyn AnyStoredVec,
|
||||
&mut self.coinblocks_destroyed.height as &mut dyn AnyStoredVec,
|
||||
&mut self.coindays_destroyed.height as &mut dyn AnyStoredVec,
|
||||
]
|
||||
.into_par_iter()
|
||||
}
|
||||
|
||||
pub(crate) fn validate_computed_versions(&mut self, _base_version: Version) -> Result<()> {
|
||||
@@ -77,7 +75,7 @@ impl ActivityMetrics {
|
||||
others: &[&Self],
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let core_refs: Vec<&CoreActivity> = others.iter().map(|o| &o.core).collect();
|
||||
let core_refs: Vec<&ActivityCore> = others.iter().map(|o| &o.core).collect();
|
||||
self.core
|
||||
.compute_from_stateful(starting_indexes, &core_refs, exit)?;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Indexes, Sats, Version};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::internal::{RollingEmas2w, ValueFromHeightCumulative};
|
||||
@@ -9,12 +8,12 @@ use crate::internal::{RollingEmas2w, ValueFromHeightCumulative};
|
||||
use crate::{blocks, distribution::metrics::ImportConfig, prices};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct CoreActivity<M: StorageMode = Rw> {
|
||||
pub struct ActivityCore<M: StorageMode = Rw> {
|
||||
pub sent: ValueFromHeightCumulative<M>,
|
||||
pub sent_ema: RollingEmas2w<M>,
|
||||
}
|
||||
|
||||
impl CoreActivity {
|
||||
impl ActivityCore {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
Ok(Self {
|
||||
sent: cfg.import_value_cumulative("sent", Version::ZERO)?,
|
||||
@@ -31,8 +30,8 @@ impl CoreActivity {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn par_iter_mut(&mut self) -> impl ParallelIterator<Item = &mut dyn AnyStoredVec> {
|
||||
vec![&mut self.sent.base.sats.height as &mut dyn AnyStoredVec].into_par_iter()
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
vec![&mut self.sent.base.sats.height as &mut dyn AnyStoredVec]
|
||||
}
|
||||
|
||||
pub(crate) fn validate_computed_versions(&mut self, _base_version: Version) -> Result<()> {
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
use brk_cohort::Filter;
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, Dollars, Height, Indexes, Version};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||
use brk_types::{Cents, Dollars, Height, Indexes};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, distribution::state::{CohortState, RealizedState}, prices};
|
||||
use crate::{blocks, prices};
|
||||
|
||||
use crate::distribution::metrics::{
|
||||
ActivityMetrics, CohortMetricsBase, CostBasisBase, CostBasisWithExtended, ImportConfig,
|
||||
OutputsMetrics, RealizedAdjusted, RealizedBase, RealizedWithExtended, RelativeForAll,
|
||||
SupplyMetrics, UnrealizedBase,
|
||||
ActivityMetrics, CostBasisWithExtended, ImportConfig, OutputsMetrics, RealizedAdjusted,
|
||||
RealizedWithExtended, RelativeForAll, SupplyMetrics, UnrealizedFull,
|
||||
};
|
||||
|
||||
/// All-cohort metrics: extended realized + adjusted (as composable add-on),
|
||||
@@ -25,7 +23,7 @@ pub struct AllCohortMetrics<M: StorageMode = Rw> {
|
||||
pub activity: Box<ActivityMetrics<M>>,
|
||||
pub realized: Box<RealizedWithExtended<M>>,
|
||||
pub cost_basis: Box<CostBasisWithExtended<M>>,
|
||||
pub unrealized: Box<UnrealizedBase<M>>,
|
||||
pub unrealized: Box<UnrealizedFull<M>>,
|
||||
pub adjusted: Box<RealizedAdjusted<M>>,
|
||||
pub relative: Box<RelativeForAll<M>>,
|
||||
}
|
||||
@@ -41,7 +39,7 @@ impl AllCohortMetrics {
|
||||
cfg: &ImportConfig,
|
||||
supply: SupplyMetrics,
|
||||
) -> Result<Self> {
|
||||
let unrealized = UnrealizedBase::forced_import(cfg)?;
|
||||
let unrealized = UnrealizedFull::forced_import(cfg)?;
|
||||
let realized = RealizedWithExtended::forced_import(cfg)?;
|
||||
let adjusted = RealizedAdjusted::forced_import(cfg)?;
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
use brk_cohort::Filter;
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Height, Indexes, Sats, Version};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||
use brk_types::{Dollars, Height, Indexes, Sats};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, prices};
|
||||
|
||||
use crate::distribution::metrics::{
|
||||
ActivityMetrics, CohortMetricsBase, CostBasisBase, ImportConfig, OutputsMetrics, RealizedBase,
|
||||
RelativeWithRelToAll, SupplyMetrics, UnrealizedBase,
|
||||
ActivityMetrics, CostBasisBase, ImportConfig, OutputsMetrics, RealizedFull,
|
||||
RelativeWithRelToAll, SupplyMetrics, UnrealizedFull,
|
||||
};
|
||||
|
||||
/// Basic cohort metrics: no extensions, with relative (rel_to_all).
|
||||
@@ -21,9 +20,9 @@ pub struct BasicCohortMetrics<M: StorageMode = Rw> {
|
||||
pub supply: Box<SupplyMetrics<M>>,
|
||||
pub outputs: Box<OutputsMetrics<M>>,
|
||||
pub activity: Box<ActivityMetrics<M>>,
|
||||
pub realized: Box<RealizedBase<M>>,
|
||||
pub realized: Box<RealizedFull<M>>,
|
||||
pub cost_basis: Box<CostBasisBase<M>>,
|
||||
pub unrealized: Box<UnrealizedBase<M>>,
|
||||
pub unrealized: Box<UnrealizedFull<M>>,
|
||||
pub relative: Box<RelativeWithRelToAll<M>>,
|
||||
}
|
||||
|
||||
@@ -32,8 +31,8 @@ impl_cohort_metrics_base!(BasicCohortMetrics, base_cost_basis);
|
||||
impl BasicCohortMetrics {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let supply = SupplyMetrics::forced_import(cfg)?;
|
||||
let unrealized = UnrealizedBase::forced_import(cfg)?;
|
||||
let realized = RealizedBase::forced_import(cfg)?;
|
||||
let unrealized = UnrealizedFull::forced_import(cfg)?;
|
||||
let realized = RealizedFull::forced_import(cfg)?;
|
||||
|
||||
let relative = RelativeWithRelToAll::forced_import(cfg)?;
|
||||
|
||||
@@ -58,7 +57,7 @@ impl BasicCohortMetrics {
|
||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.realized.compute_rest_part2_base(
|
||||
self.realized.compute_rest_part2(
|
||||
blocks,
|
||||
prices,
|
||||
starting_indexes,
|
||||
|
||||
@@ -2,7 +2,6 @@ use brk_cohort::Filter;
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Height, Indexes, Sats, Version};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, prices};
|
||||
@@ -68,9 +67,9 @@ impl CompleteCohortMetrics {
|
||||
|
||||
pub(crate) fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
let mut vecs: Vec<&mut dyn AnyStoredVec> = Vec::new();
|
||||
vecs.extend(self.supply.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.outputs.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.activity.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.supply.collect_vecs_mut());
|
||||
vecs.extend(self.outputs.collect_vecs_mut());
|
||||
vecs.extend(self.activity.collect_vecs_mut());
|
||||
vecs.extend(self.realized.collect_vecs_mut());
|
||||
vecs.extend(self.cost_basis.collect_vecs_mut());
|
||||
vecs.extend(self.unrealized.collect_vecs_mut());
|
||||
@@ -101,10 +100,10 @@ impl CompleteCohortMetrics {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Realized: aggregate only Complete-tier fields from Source's RealizedBase
|
||||
// Realized: aggregate only Complete-tier fields from Source's RealizedFull
|
||||
let realized_complete_refs: Vec<&RealizedComplete> = others
|
||||
.iter()
|
||||
.map(|v| &v.realized_base().complete)
|
||||
.map(|v| &v.realized_full().complete)
|
||||
.collect();
|
||||
self.realized
|
||||
.compute_from_stateful(starting_indexes, &realized_complete_refs, exit)?;
|
||||
@@ -112,7 +111,7 @@ impl CompleteCohortMetrics {
|
||||
// Unrealized: aggregate only Complete-tier fields
|
||||
let unrealized_complete_refs: Vec<&UnrealizedComplete> = others
|
||||
.iter()
|
||||
.map(|v| &v.unrealized_base().complete)
|
||||
.map(|v| &v.unrealized_full().complete)
|
||||
.collect();
|
||||
self.unrealized
|
||||
.compute_from_stateful(starting_indexes, &unrealized_complete_refs, exit)?;
|
||||
|
||||
@@ -2,13 +2,12 @@ use brk_cohort::Filter;
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Height, Indexes, Sats, Version};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, prices};
|
||||
|
||||
use crate::distribution::metrics::{
|
||||
CoreActivity, CoreRealized, ImportConfig, OutputsMetrics,
|
||||
ActivityCore, RealizedCore, ImportConfig, OutputsMetrics,
|
||||
RelativeCompleteWithRelToAll, SupplyMetrics, UnrealizedComplete,
|
||||
};
|
||||
|
||||
@@ -18,8 +17,8 @@ pub struct CoreCohortMetrics<M: StorageMode = Rw> {
|
||||
pub filter: Filter,
|
||||
pub supply: Box<SupplyMetrics<M>>,
|
||||
pub outputs: Box<OutputsMetrics<M>>,
|
||||
pub activity: Box<CoreActivity<M>>,
|
||||
pub realized: Box<CoreRealized<M>>,
|
||||
pub activity: Box<ActivityCore<M>>,
|
||||
pub realized: Box<RealizedCore<M>>,
|
||||
pub unrealized: Box<UnrealizedComplete<M>>,
|
||||
pub relative: Box<RelativeCompleteWithRelToAll<M>>,
|
||||
}
|
||||
@@ -30,8 +29,8 @@ impl CoreCohortMetrics {
|
||||
filter: cfg.filter.clone(),
|
||||
supply: Box::new(SupplyMetrics::forced_import(cfg)?),
|
||||
outputs: Box::new(OutputsMetrics::forced_import(cfg)?),
|
||||
activity: Box::new(CoreActivity::forced_import(cfg)?),
|
||||
realized: Box::new(CoreRealized::forced_import(cfg)?),
|
||||
activity: Box::new(ActivityCore::forced_import(cfg)?),
|
||||
realized: Box::new(RealizedCore::forced_import(cfg)?),
|
||||
unrealized: Box::new(UnrealizedComplete::forced_import(cfg)?),
|
||||
relative: Box::new(RelativeCompleteWithRelToAll::forced_import(cfg)?),
|
||||
})
|
||||
@@ -54,9 +53,9 @@ impl CoreCohortMetrics {
|
||||
|
||||
pub(crate) fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
let mut vecs: Vec<&mut dyn AnyStoredVec> = Vec::new();
|
||||
vecs.extend(self.supply.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.outputs.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.activity.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.supply.collect_vecs_mut());
|
||||
vecs.extend(self.outputs.collect_vecs_mut());
|
||||
vecs.extend(self.activity.collect_vecs_mut());
|
||||
vecs.extend(self.realized.collect_vecs_mut());
|
||||
vecs.extend(self.unrealized.collect_vecs_mut());
|
||||
vecs
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
use brk_cohort::Filter;
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, Dollars, Height, Indexes, Sats, Version};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||
use brk_types::{Dollars, Height, Indexes, Sats};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, distribution::state::{CohortState, RealizedState}, prices};
|
||||
use crate::{blocks, prices};
|
||||
|
||||
use crate::distribution::metrics::{
|
||||
ActivityMetrics, CohortMetricsBase, CostBasisBase, CostBasisWithExtended, ImportConfig,
|
||||
OutputsMetrics, RealizedBase, RealizedWithExtended, RelativeWithExtended, SupplyMetrics,
|
||||
UnrealizedBase,
|
||||
ActivityMetrics, CostBasisWithExtended, ImportConfig, OutputsMetrics,
|
||||
RealizedWithExtended, RelativeWithExtended, SupplyMetrics, UnrealizedFull,
|
||||
};
|
||||
|
||||
/// Cohort metrics with extended realized + extended cost basis (no adjusted).
|
||||
@@ -24,7 +22,7 @@ pub struct ExtendedCohortMetrics<M: StorageMode = Rw> {
|
||||
pub activity: Box<ActivityMetrics<M>>,
|
||||
pub realized: Box<RealizedWithExtended<M>>,
|
||||
pub cost_basis: Box<CostBasisWithExtended<M>>,
|
||||
pub unrealized: Box<UnrealizedBase<M>>,
|
||||
pub unrealized: Box<UnrealizedFull<M>>,
|
||||
pub relative: Box<RelativeWithExtended<M>>,
|
||||
}
|
||||
|
||||
@@ -33,7 +31,7 @@ impl_cohort_metrics_base!(ExtendedCohortMetrics, extended_cost_basis);
|
||||
impl ExtendedCohortMetrics {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let supply = SupplyMetrics::forced_import(cfg)?;
|
||||
let unrealized = UnrealizedBase::forced_import(cfg)?;
|
||||
let unrealized = UnrealizedFull::forced_import(cfg)?;
|
||||
let realized = RealizedWithExtended::forced_import(cfg)?;
|
||||
|
||||
let relative = RelativeWithExtended::forced_import(cfg)?;
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
use brk_cohort::Filter;
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, Dollars, Height, Indexes, Sats, Version};
|
||||
use brk_types::{Cents, Dollars, Height, Indexes, Sats};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, distribution::state::{CohortState, RealizedState}, prices};
|
||||
use crate::{blocks, prices};
|
||||
|
||||
use crate::distribution::metrics::{
|
||||
ActivityMetrics, CohortMetricsBase, CostBasisBase, ImportConfig, OutputsMetrics, RealizedAdjusted,
|
||||
RealizedBase, SupplyMetrics, UnrealizedBase,
|
||||
};
|
||||
use crate::distribution::metrics::{ImportConfig, RealizedAdjusted};
|
||||
|
||||
use super::ExtendedCohortMetrics;
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ use brk_types::{
|
||||
BasisPoints16, BasisPoints32, Bitcoin, Cents, Dollars, Height, Indexes, Sats, StoredF32,
|
||||
Version,
|
||||
};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::{blocks, prices};
|
||||
@@ -251,8 +250,8 @@ impl MinimalCohortMetrics {
|
||||
|
||||
pub(crate) fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
let mut vecs: Vec<&mut dyn AnyStoredVec> = Vec::new();
|
||||
vecs.extend(self.supply.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.outputs.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.supply.collect_vecs_mut());
|
||||
vecs.extend(self.outputs.collect_vecs_mut());
|
||||
vecs.extend(self.realized.collect_vecs_mut());
|
||||
vecs.extend(self.unrealized.collect_vecs_mut());
|
||||
vecs
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::Version;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
use vecdb::{AnyStoredVec, Rw, StorageMode};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
|
||||
@@ -27,6 +27,12 @@ impl CostBasisWithExtended {
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
let mut vecs = self.base.collect_vecs_mut();
|
||||
vecs.extend(self.extended.collect_vecs_mut());
|
||||
vecs
|
||||
}
|
||||
|
||||
pub(crate) fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
|
||||
self.extended.validate_computed_versions(base_version)
|
||||
}
|
||||
|
||||
@@ -21,20 +21,20 @@ mod activity;
|
||||
/// - `deref_extended_cost_basis`: Deref wrapper delegating to `self.inner` (avoids DerefMut borrow conflicts)
|
||||
macro_rules! impl_cohort_metrics_base {
|
||||
($type:ident, base_cost_basis) => {
|
||||
impl CohortMetricsBase for $type {
|
||||
impl $crate::distribution::metrics::CohortMetricsBase for $type {
|
||||
impl_cohort_metrics_base!(@accessors);
|
||||
|
||||
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
|
||||
fn validate_computed_versions(&mut self, base_version: brk_types::Version) -> brk_error::Result<()> {
|
||||
self.supply.validate_computed_versions(base_version)?;
|
||||
self.activity.validate_computed_versions(base_version)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
let mut vecs: Vec<&mut dyn AnyStoredVec> = Vec::new();
|
||||
vecs.extend(self.supply.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.outputs.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.activity.par_iter_mut().collect::<Vec<_>>());
|
||||
fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn vecdb::AnyStoredVec> {
|
||||
let mut vecs: Vec<&mut dyn vecdb::AnyStoredVec> = Vec::new();
|
||||
vecs.extend(self.supply.collect_vecs_mut());
|
||||
vecs.extend(self.outputs.collect_vecs_mut());
|
||||
vecs.extend(self.activity.collect_vecs_mut());
|
||||
vecs.extend(self.realized.collect_vecs_mut());
|
||||
vecs.extend(self.cost_basis.collect_vecs_mut());
|
||||
vecs.extend(self.unrealized.collect_vecs_mut());
|
||||
@@ -44,10 +44,10 @@ macro_rules! impl_cohort_metrics_base {
|
||||
};
|
||||
|
||||
($type:ident, extended_cost_basis) => {
|
||||
impl CohortMetricsBase for $type {
|
||||
impl $crate::distribution::metrics::CohortMetricsBase for $type {
|
||||
impl_cohort_metrics_base!(@accessors);
|
||||
|
||||
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
|
||||
fn validate_computed_versions(&mut self, base_version: brk_types::Version) -> brk_error::Result<()> {
|
||||
self.supply.validate_computed_versions(base_version)?;
|
||||
self.activity.validate_computed_versions(base_version)?;
|
||||
self.cost_basis.validate_computed_versions(base_version)?;
|
||||
@@ -56,11 +56,11 @@ macro_rules! impl_cohort_metrics_base {
|
||||
|
||||
fn compute_then_truncate_push_unrealized_states(
|
||||
&mut self,
|
||||
height: Height,
|
||||
height_price: Cents,
|
||||
state: &mut CohortState<RealizedState>,
|
||||
height: brk_types::Height,
|
||||
height_price: brk_types::Cents,
|
||||
state: &mut $crate::distribution::state::CohortState<$crate::distribution::state::RealizedState>,
|
||||
is_day_boundary: bool,
|
||||
) -> Result<()> {
|
||||
) -> brk_error::Result<()> {
|
||||
self.compute_and_push_unrealized_base(height, height_price, state)?;
|
||||
self.cost_basis
|
||||
.extended
|
||||
@@ -68,14 +68,13 @@ macro_rules! impl_cohort_metrics_base {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
let mut vecs: Vec<&mut dyn AnyStoredVec> = Vec::new();
|
||||
vecs.extend(self.supply.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.outputs.par_iter_mut().collect::<Vec<_>>());
|
||||
vecs.extend(self.activity.par_iter_mut().collect::<Vec<_>>());
|
||||
fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn vecdb::AnyStoredVec> {
|
||||
let mut vecs: Vec<&mut dyn vecdb::AnyStoredVec> = Vec::new();
|
||||
vecs.extend(self.supply.collect_vecs_mut());
|
||||
vecs.extend(self.outputs.collect_vecs_mut());
|
||||
vecs.extend(self.activity.collect_vecs_mut());
|
||||
vecs.extend(self.realized.collect_vecs_mut());
|
||||
vecs.extend(self.cost_basis.base.collect_vecs_mut());
|
||||
vecs.extend(self.cost_basis.extended.collect_vecs_mut());
|
||||
vecs.extend(self.cost_basis.collect_vecs_mut());
|
||||
vecs.extend(self.unrealized.collect_vecs_mut());
|
||||
vecs
|
||||
}
|
||||
@@ -83,61 +82,61 @@ macro_rules! impl_cohort_metrics_base {
|
||||
};
|
||||
|
||||
($type:ident, deref_extended_cost_basis) => {
|
||||
impl CohortMetricsBase for $type {
|
||||
impl $crate::distribution::metrics::CohortMetricsBase for $type {
|
||||
impl_cohort_metrics_base!(@deref_accessors);
|
||||
|
||||
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
|
||||
fn validate_computed_versions(&mut self, base_version: brk_types::Version) -> brk_error::Result<()> {
|
||||
self.inner.validate_computed_versions(base_version)
|
||||
}
|
||||
|
||||
fn compute_then_truncate_push_unrealized_states(
|
||||
&mut self,
|
||||
height: Height,
|
||||
height_price: Cents,
|
||||
state: &mut CohortState<RealizedState>,
|
||||
height: brk_types::Height,
|
||||
height_price: brk_types::Cents,
|
||||
state: &mut $crate::distribution::state::CohortState<$crate::distribution::state::RealizedState>,
|
||||
is_day_boundary: bool,
|
||||
) -> Result<()> {
|
||||
) -> brk_error::Result<()> {
|
||||
self.inner.compute_then_truncate_push_unrealized_states(
|
||||
height, height_price, state, is_day_boundary,
|
||||
)
|
||||
}
|
||||
|
||||
fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn vecdb::AnyStoredVec> {
|
||||
self.inner.collect_all_vecs_mut()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
(@accessors) => {
|
||||
fn filter(&self) -> &Filter { &self.filter }
|
||||
fn supply(&self) -> &SupplyMetrics { &self.supply }
|
||||
fn supply_mut(&mut self) -> &mut SupplyMetrics { &mut self.supply }
|
||||
fn outputs(&self) -> &OutputsMetrics { &self.outputs }
|
||||
fn outputs_mut(&mut self) -> &mut OutputsMetrics { &mut self.outputs }
|
||||
fn activity(&self) -> &ActivityMetrics { &self.activity }
|
||||
fn activity_mut(&mut self) -> &mut ActivityMetrics { &mut self.activity }
|
||||
fn realized_base(&self) -> &RealizedBase { &self.realized }
|
||||
fn realized_base_mut(&mut self) -> &mut RealizedBase { &mut self.realized }
|
||||
fn unrealized_base(&self) -> &UnrealizedBase { &self.unrealized }
|
||||
fn unrealized_base_mut(&mut self) -> &mut UnrealizedBase { &mut self.unrealized }
|
||||
fn cost_basis_base(&self) -> &CostBasisBase { &self.cost_basis }
|
||||
fn cost_basis_base_mut(&mut self) -> &mut CostBasisBase { &mut self.cost_basis }
|
||||
fn filter(&self) -> &brk_cohort::Filter { &self.filter }
|
||||
fn supply(&self) -> &$crate::distribution::metrics::SupplyMetrics { &self.supply }
|
||||
fn supply_mut(&mut self) -> &mut $crate::distribution::metrics::SupplyMetrics { &mut self.supply }
|
||||
fn outputs(&self) -> &$crate::distribution::metrics::OutputsMetrics { &self.outputs }
|
||||
fn outputs_mut(&mut self) -> &mut $crate::distribution::metrics::OutputsMetrics { &mut self.outputs }
|
||||
fn activity(&self) -> &$crate::distribution::metrics::ActivityMetrics { &self.activity }
|
||||
fn activity_mut(&mut self) -> &mut $crate::distribution::metrics::ActivityMetrics { &mut self.activity }
|
||||
fn realized_full(&self) -> &$crate::distribution::metrics::RealizedFull { &self.realized }
|
||||
fn realized_full_mut(&mut self) -> &mut $crate::distribution::metrics::RealizedFull { &mut self.realized }
|
||||
fn unrealized_full(&self) -> &$crate::distribution::metrics::UnrealizedFull { &self.unrealized }
|
||||
fn unrealized_full_mut(&mut self) -> &mut $crate::distribution::metrics::UnrealizedFull { &mut self.unrealized }
|
||||
fn cost_basis_base(&self) -> &$crate::distribution::metrics::CostBasisBase { &self.cost_basis }
|
||||
fn cost_basis_base_mut(&mut self) -> &mut $crate::distribution::metrics::CostBasisBase { &mut self.cost_basis }
|
||||
};
|
||||
|
||||
(@deref_accessors) => {
|
||||
fn filter(&self) -> &Filter { self.inner.filter() }
|
||||
fn supply(&self) -> &SupplyMetrics { self.inner.supply() }
|
||||
fn supply_mut(&mut self) -> &mut SupplyMetrics { self.inner.supply_mut() }
|
||||
fn outputs(&self) -> &OutputsMetrics { self.inner.outputs() }
|
||||
fn outputs_mut(&mut self) -> &mut OutputsMetrics { self.inner.outputs_mut() }
|
||||
fn activity(&self) -> &ActivityMetrics { self.inner.activity() }
|
||||
fn activity_mut(&mut self) -> &mut ActivityMetrics { self.inner.activity_mut() }
|
||||
fn realized_base(&self) -> &RealizedBase { self.inner.realized_base() }
|
||||
fn realized_base_mut(&mut self) -> &mut RealizedBase { self.inner.realized_base_mut() }
|
||||
fn unrealized_base(&self) -> &UnrealizedBase { self.inner.unrealized_base() }
|
||||
fn unrealized_base_mut(&mut self) -> &mut UnrealizedBase { self.inner.unrealized_base_mut() }
|
||||
fn cost_basis_base(&self) -> &CostBasisBase { self.inner.cost_basis_base() }
|
||||
fn cost_basis_base_mut(&mut self) -> &mut CostBasisBase { self.inner.cost_basis_base_mut() }
|
||||
fn filter(&self) -> &brk_cohort::Filter { self.inner.filter() }
|
||||
fn supply(&self) -> &$crate::distribution::metrics::SupplyMetrics { self.inner.supply() }
|
||||
fn supply_mut(&mut self) -> &mut $crate::distribution::metrics::SupplyMetrics { self.inner.supply_mut() }
|
||||
fn outputs(&self) -> &$crate::distribution::metrics::OutputsMetrics { self.inner.outputs() }
|
||||
fn outputs_mut(&mut self) -> &mut $crate::distribution::metrics::OutputsMetrics { self.inner.outputs_mut() }
|
||||
fn activity(&self) -> &$crate::distribution::metrics::ActivityMetrics { self.inner.activity() }
|
||||
fn activity_mut(&mut self) -> &mut $crate::distribution::metrics::ActivityMetrics { self.inner.activity_mut() }
|
||||
fn realized_full(&self) -> &$crate::distribution::metrics::RealizedFull { self.inner.realized_full() }
|
||||
fn realized_full_mut(&mut self) -> &mut $crate::distribution::metrics::RealizedFull { self.inner.realized_full_mut() }
|
||||
fn unrealized_full(&self) -> &$crate::distribution::metrics::UnrealizedFull { self.inner.unrealized_full() }
|
||||
fn unrealized_full_mut(&mut self) -> &mut $crate::distribution::metrics::UnrealizedFull { self.inner.unrealized_full_mut() }
|
||||
fn cost_basis_base(&self) -> &$crate::distribution::metrics::CostBasisBase { self.inner.cost_basis_base() }
|
||||
fn cost_basis_base_mut(&mut self) -> &mut $crate::distribution::metrics::CostBasisBase { self.inner.cost_basis_base_mut() }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -175,10 +174,10 @@ pub trait CohortMetricsBase: Send + Sync {
|
||||
fn outputs_mut(&mut self) -> &mut OutputsMetrics;
|
||||
fn activity(&self) -> &ActivityMetrics;
|
||||
fn activity_mut(&mut self) -> &mut ActivityMetrics;
|
||||
fn realized_base(&self) -> &RealizedBase;
|
||||
fn realized_base_mut(&mut self) -> &mut RealizedBase;
|
||||
fn unrealized_base(&self) -> &UnrealizedBase;
|
||||
fn unrealized_base_mut(&mut self) -> &mut UnrealizedBase;
|
||||
fn realized_full(&self) -> &RealizedFull;
|
||||
fn realized_full_mut(&mut self) -> &mut RealizedFull;
|
||||
fn unrealized_full(&self) -> &UnrealizedFull;
|
||||
fn unrealized_full_mut(&mut self) -> &mut UnrealizedFull;
|
||||
fn cost_basis_base(&self) -> &CostBasisBase;
|
||||
fn cost_basis_base_mut(&mut self) -> &mut CostBasisBase;
|
||||
|
||||
@@ -195,7 +194,7 @@ pub trait CohortMetricsBase: Send + Sync {
|
||||
self.cost_basis_base_mut()
|
||||
.truncate_push_minmax(height, state)?;
|
||||
let unrealized_state = state.compute_unrealized_state(height_price);
|
||||
self.unrealized_base_mut()
|
||||
self.unrealized_full_mut()
|
||||
.truncate_push(height, &unrealized_state)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -218,8 +217,8 @@ pub trait CohortMetricsBase: Send + Sync {
|
||||
.min_len()
|
||||
.min(self.outputs().min_len())
|
||||
.min(self.activity().min_len())
|
||||
.min(self.realized_base().min_stateful_height_len())
|
||||
.min(self.unrealized_base().min_stateful_height_len())
|
||||
.min(self.realized_full().min_stateful_height_len())
|
||||
.min(self.unrealized_full().min_stateful_height_len())
|
||||
.min(self.cost_basis_base().min_stateful_height_len())
|
||||
}
|
||||
|
||||
@@ -234,7 +233,7 @@ pub trait CohortMetricsBase: Send + Sync {
|
||||
state.satblocks_destroyed,
|
||||
state.satdays_destroyed,
|
||||
)?;
|
||||
self.realized_base_mut()
|
||||
self.realized_full_mut()
|
||||
.truncate_push(height, &state.realized)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -248,14 +247,14 @@ pub trait CohortMetricsBase: Send + Sync {
|
||||
) -> Result<()> {
|
||||
let weights: Vec<_> = others
|
||||
.iter()
|
||||
.map(|o| &o.realized_base().realized_cap.height)
|
||||
.map(|o| &o.realized_full().realized_cap.height)
|
||||
.collect();
|
||||
let values: Vec<_> = others
|
||||
.iter()
|
||||
.map(|o| &o.unrealized_base().net_sentiment.cents.height)
|
||||
.map(|o| &o.unrealized_full().net_sentiment.cents.height)
|
||||
.collect();
|
||||
|
||||
self.unrealized_base_mut()
|
||||
self.unrealized_full_mut()
|
||||
.net_sentiment
|
||||
.cents
|
||||
.height
|
||||
@@ -284,16 +283,16 @@ pub trait CohortMetricsBase: Send + Sync {
|
||||
self.activity_mut()
|
||||
.compute_rest_part1(blocks, prices, starting_indexes, exit)?;
|
||||
|
||||
self.realized_base_mut()
|
||||
self.realized_full_mut()
|
||||
.sent_in_profit
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
self.realized_base_mut()
|
||||
self.realized_full_mut()
|
||||
.sent_in_loss
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
self.realized_base_mut()
|
||||
self.realized_full_mut()
|
||||
.compute_rest_part1(starting_indexes, exit)?;
|
||||
|
||||
self.unrealized_base_mut()
|
||||
self.unrealized_full_mut()
|
||||
.compute_rest(prices, starting_indexes, exit)?;
|
||||
|
||||
Ok(())
|
||||
@@ -305,7 +304,7 @@ pub trait CohortMetricsBase: Send + Sync {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.unrealized_base_mut()
|
||||
self.unrealized_full_mut()
|
||||
.compute_net_sentiment_height(starting_indexes, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -330,8 +329,8 @@ pub trait CohortMetricsBase: Send + Sync {
|
||||
aggregate!(supply_mut, supply);
|
||||
aggregate!(outputs_mut, outputs);
|
||||
aggregate!(activity_mut, activity);
|
||||
aggregate!(realized_base_mut, realized_base);
|
||||
aggregate!(unrealized_base_mut, unrealized_base);
|
||||
aggregate!(realized_full_mut, realized_full);
|
||||
aggregate!(unrealized_full_mut, unrealized_full);
|
||||
aggregate!(cost_basis_base_mut, cost_basis_base);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Indexes, StoredF64, StoredU64, Version};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::{blocks, internal::ComputedFromHeight};
|
||||
@@ -37,9 +36,8 @@ impl OutputsMetrics {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns a parallel iterator over all vecs for parallel writing.
|
||||
pub(crate) fn par_iter_mut(&mut self) -> impl ParallelIterator<Item = &mut dyn AnyStoredVec> {
|
||||
vec![&mut self.utxo_count.height as &mut dyn AnyStoredVec].into_par_iter()
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
vec![&mut self.utxo_count.height as &mut dyn AnyStoredVec]
|
||||
}
|
||||
|
||||
/// Compute aggregate values from separate cohorts.
|
||||
|
||||
@@ -37,7 +37,6 @@ impl RealizedAdjusted {
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute_rest_part2(
|
||||
&mut self,
|
||||
blocks: &blocks::Vecs,
|
||||
|
||||
@@ -26,7 +26,7 @@ use super::RealizedComplete;
|
||||
/// - Source-only: peak_regret, peak_regret_rel_to_realized_cap
|
||||
/// - Extended-only: investor_price, price bands, cap_raw, sell_side_risk_ratio
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct RealizedBase<M: StorageMode = Rw> {
|
||||
pub struct RealizedFull<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
@@ -50,7 +50,7 @@ pub struct RealizedBase<M: StorageMode = Rw> {
|
||||
pub peak_regret_rel_to_realized_cap: PercentFromHeight<BasisPoints32, M>,
|
||||
}
|
||||
|
||||
impl RealizedBase {
|
||||
impl RealizedFull {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let v0 = Version::ZERO;
|
||||
|
||||
@@ -219,8 +219,7 @@ impl RealizedBase {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute_rest_part2_base(
|
||||
pub(crate) fn compute_rest_part2(
|
||||
&mut self,
|
||||
blocks: &blocks::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
|
||||
@@ -21,14 +21,14 @@ use crate::{
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
|
||||
use super::CoreRealized;
|
||||
use super::RealizedCore;
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct RealizedComplete<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub core: CoreRealized<M>,
|
||||
pub core: RealizedCore<M>,
|
||||
|
||||
pub profit_value_created: ComputedFromHeight<Cents, M>,
|
||||
pub profit_value_destroyed: ComputedFromHeight<Cents, M>,
|
||||
@@ -63,7 +63,7 @@ impl RealizedComplete {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let v0 = Version::ZERO;
|
||||
|
||||
let core = CoreRealized::forced_import(cfg)?;
|
||||
let core = RealizedCore::forced_import(cfg)?;
|
||||
|
||||
let profit_value_created = cfg.import_computed("profit_value_created", v0)?;
|
||||
let profit_value_destroyed = cfg.import_computed("profit_value_destroyed", v0)?;
|
||||
@@ -175,7 +175,7 @@ impl RealizedComplete {
|
||||
others: &[&Self],
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let core_refs: Vec<&CoreRealized> = others.iter().map(|o| &o.core).collect();
|
||||
let core_refs: Vec<&RealizedCore> = others.iter().map(|o| &o.core).collect();
|
||||
self.core
|
||||
.compute_from_stateful(starting_indexes, &core_refs, exit)?;
|
||||
|
||||
@@ -199,7 +199,6 @@ impl RealizedComplete {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute_rest_part2(
|
||||
&mut self,
|
||||
blocks: &blocks::Vecs,
|
||||
|
||||
@@ -23,7 +23,7 @@ use crate::{
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct CoreRealized<M: StorageMode = Rw> {
|
||||
pub struct RealizedCore<M: StorageMode = Rw> {
|
||||
pub realized_cap_cents: ComputedFromHeight<Cents, M>,
|
||||
pub realized_profit: ComputedFromHeightCumulative<Cents, M>,
|
||||
pub realized_loss: ComputedFromHeightCumulative<Cents, M>,
|
||||
@@ -48,7 +48,7 @@ pub struct CoreRealized<M: StorageMode = Rw> {
|
||||
pub net_realized_pnl_rel_to_realized_cap: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
}
|
||||
|
||||
impl CoreRealized {
|
||||
impl RealizedCore {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let v0 = Version::ZERO;
|
||||
let v1 = Version::ONE;
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::{
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
|
||||
use super::RealizedBase;
|
||||
use super::RealizedFull;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedExtended<M: StorageMode = Rw> {
|
||||
@@ -53,10 +53,9 @@ impl RealizedExtended {
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute_rest_part2(
|
||||
&mut self,
|
||||
base: &RealizedBase,
|
||||
base: &RealizedFull,
|
||||
blocks: &blocks::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{blocks, prices};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
|
||||
use super::{RealizedBase, RealizedExtended};
|
||||
use super::{RealizedFull, RealizedExtended};
|
||||
|
||||
/// Realized metrics with guaranteed extended (no Option).
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
@@ -16,19 +16,18 @@ pub struct RealizedWithExtended<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub base: RealizedBase<M>,
|
||||
pub base: RealizedFull<M>,
|
||||
#[traversable(flatten)]
|
||||
pub extended: RealizedExtended<M>,
|
||||
}
|
||||
|
||||
impl RealizedWithExtended {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let base = RealizedBase::forced_import(cfg)?;
|
||||
let base = RealizedFull::forced_import(cfg)?;
|
||||
let extended = RealizedExtended::forced_import(cfg)?;
|
||||
Ok(Self { base, extended })
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute_rest_part2(
|
||||
&mut self,
|
||||
blocks: &blocks::Vecs,
|
||||
@@ -38,7 +37,7 @@ impl RealizedWithExtended {
|
||||
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.base.compute_rest_part2_base(
|
||||
self.base.compute_rest_part2(
|
||||
blocks,
|
||||
prices,
|
||||
starting_indexes,
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{NegRatioDollarsBps32, PercentFromHeight, RatioDollarsBp16};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, RealizedBase, UnrealizedBase};
|
||||
use crate::distribution::metrics::{ImportConfig, RealizedFull, UnrealizedFull};
|
||||
|
||||
use super::RelativeComplete;
|
||||
|
||||
@@ -50,8 +50,8 @@ impl RelativeBase {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
unrealized: &UnrealizedBase,
|
||||
realized: &RealizedBase,
|
||||
unrealized: &UnrealizedFull,
|
||||
realized: &RealizedFull,
|
||||
supply_total_sats: &impl ReadableVec<Height, Sats>,
|
||||
market_cap: &impl ReadableVec<Height, Dollars>,
|
||||
exit: &Exit,
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::internal::{
|
||||
NegRatioDollarsBps32, PercentFromHeight, RatioDollarsBp16, RatioDollarsBp32, RatioDollarsBps32,
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
use crate::distribution::metrics::{ImportConfig, UnrealizedFull};
|
||||
|
||||
/// Extended relative metrics for own market cap (extended && rel_to_all).
|
||||
#[derive(Traversable)]
|
||||
@@ -37,7 +37,7 @@ impl RelativeExtendedOwnMarketCap {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
unrealized: &UnrealizedBase,
|
||||
unrealized: &UnrealizedFull,
|
||||
own_market_cap: &impl ReadableVec<Height, Dollars>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::internal::{
|
||||
NegRatioDollarsBps32, PercentFromHeight, RatioDollarsBp16, RatioDollarsBps32,
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
use crate::distribution::metrics::{ImportConfig, UnrealizedFull};
|
||||
|
||||
/// Extended relative metrics for own total unrealized PnL (extended only).
|
||||
#[derive(Traversable)]
|
||||
@@ -37,7 +37,7 @@ impl RelativeExtendedOwnPnl {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
unrealized: &UnrealizedBase,
|
||||
unrealized: &UnrealizedFull,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.unrealized_profit_rel_to_own_gross_pnl
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Dollars, Height, Sats};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, RealizedBase, UnrealizedBase};
|
||||
use crate::distribution::metrics::{ImportConfig, RealizedFull, UnrealizedFull};
|
||||
|
||||
use super::{RelativeBase, RelativeExtendedOwnPnl};
|
||||
|
||||
@@ -27,12 +27,11 @@ impl RelativeForAll {
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
unrealized: &UnrealizedBase,
|
||||
realized: &RealizedBase,
|
||||
unrealized: &UnrealizedFull,
|
||||
realized: &RealizedFull,
|
||||
supply_total_sats: &impl ReadableVec<Height, Sats>,
|
||||
market_cap: &impl ReadableVec<Height, Dollars>,
|
||||
exit: &Exit,
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Dollars, Height, Sats};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, RealizedBase, UnrealizedBase};
|
||||
use crate::distribution::metrics::{ImportConfig, RealizedFull, UnrealizedFull};
|
||||
|
||||
use super::{RelativeBase, RelativeExtendedOwnMarketCap, RelativeExtendedOwnPnl, RelativeToAll};
|
||||
|
||||
@@ -38,8 +38,8 @@ impl RelativeWithExtended {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
unrealized: &UnrealizedBase,
|
||||
realized: &RealizedBase,
|
||||
unrealized: &UnrealizedFull,
|
||||
realized: &RealizedFull,
|
||||
supply_total_sats: &impl ReadableVec<Height, Sats>,
|
||||
market_cap: &impl ReadableVec<Height, Dollars>,
|
||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Dollars, Height, Sats};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, RealizedBase, UnrealizedBase};
|
||||
use crate::distribution::metrics::{ImportConfig, RealizedFull, UnrealizedFull};
|
||||
|
||||
use super::{RelativeBase, RelativeToAll};
|
||||
|
||||
@@ -32,8 +32,8 @@ impl RelativeWithRelToAll {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
unrealized: &UnrealizedBase,
|
||||
realized: &RealizedBase,
|
||||
unrealized: &UnrealizedFull,
|
||||
realized: &RealizedFull,
|
||||
supply_total_sats: &impl ReadableVec<Height, Sats>,
|
||||
market_cap: &impl ReadableVec<Height, Dollars>,
|
||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||
|
||||
@@ -28,7 +28,6 @@ impl RelativeCompleteWithRelToAll {
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
|
||||
@@ -3,7 +3,6 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Indexes, Sats, Version};
|
||||
|
||||
use crate::{blocks, prices};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::internal::{
|
||||
@@ -54,13 +53,11 @@ impl SupplyMetrics {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns a parallel iterator over all vecs for parallel writing.
|
||||
pub(crate) fn par_iter_mut(&mut self) -> impl ParallelIterator<Item = &mut dyn AnyStoredVec> {
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
vec![
|
||||
&mut self.total.base.sats.height as &mut dyn AnyStoredVec,
|
||||
&mut self.total.base.cents.height as &mut dyn AnyStoredVec,
|
||||
]
|
||||
.into_par_iter()
|
||||
}
|
||||
|
||||
/// Eagerly compute USD height values from sats × price.
|
||||
|
||||
@@ -20,7 +20,7 @@ use super::UnrealizedComplete;
|
||||
/// - Source-only: invested_capital, raw BytesVecs, unrealized_gross_pnl
|
||||
/// - Extended-only: pain_index, greed_index, net_sentiment
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct UnrealizedBase<M: StorageMode = Rw> {
|
||||
pub struct UnrealizedFull<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
@@ -43,7 +43,7 @@ pub struct UnrealizedBase<M: StorageMode = Rw> {
|
||||
pub net_sentiment: FiatFromHeight<CentsSigned, M>,
|
||||
}
|
||||
|
||||
impl UnrealizedBase {
|
||||
impl UnrealizedFull {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let v0 = Version::ZERO;
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ where
|
||||
) {
|
||||
let mapping_len = mapping.len();
|
||||
let source_len = source.len();
|
||||
let mut cursor = Cursor::from_dyn(&**source);
|
||||
let mut cursor = Cursor::new(&**source);
|
||||
for i in from..to {
|
||||
if i >= mapping_len {
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user