computer: snapshot

This commit is contained in:
nym21
2026-02-26 23:01:51 +01:00
parent cccaf6b206
commit 78fc5ffcf7
69 changed files with 1578 additions and 2205 deletions

View File

@@ -55,7 +55,6 @@ impl AddressCohortVecs {
db,
filter,
full_name: &full_name,
context: CohortContext::Address,
version,
indexes,
};

View File

@@ -78,7 +78,6 @@ impl UTXOCohorts<Rw> {
db,
filter: Filter::All,
full_name: &all_full_name,
context: CohortContext::Utxo,
version: v + Version::ONE,
indexes,
};
@@ -94,7 +93,6 @@ impl UTXOCohorts<Rw> {
db,
filter: f,
full_name: &full_name,
context: CohortContext::Utxo,
version: v,
indexes,
};
@@ -114,7 +112,6 @@ impl UTXOCohorts<Rw> {
db,
filter: f,
full_name: &full_name,
context: CohortContext::Utxo,
version: v,
indexes,
};
@@ -146,7 +143,6 @@ impl UTXOCohorts<Rw> {
db,
filter: f,
full_name: &full_name,
context: CohortContext::Utxo,
version: v,
indexes,
};
@@ -166,7 +162,6 @@ impl UTXOCohorts<Rw> {
db,
filter: f,
full_name: &full_name,
context: CohortContext::Utxo,
version: v,
indexes,
};
@@ -184,7 +179,6 @@ impl UTXOCohorts<Rw> {
db,
filter: f,
full_name: &full_name,
context: CohortContext::Utxo,
version: v,
indexes,
};
@@ -203,7 +197,6 @@ impl UTXOCohorts<Rw> {
db,
filter: f,
full_name: &full_name,
context: CohortContext::Utxo,
version: v,
indexes,
};
@@ -222,7 +215,6 @@ impl UTXOCohorts<Rw> {
db,
filter: f,
full_name: &full_name,
context: CohortContext::Utxo,
version: v,
indexes,
};

View File

@@ -67,7 +67,7 @@ pub(crate) fn process_blocks(
// From transactions and inputs/outputs (via .height or .height.sum_cumulative.sum patterns):
let height_to_tx_count = &transactions.count.tx_count.height;
let height_to_output_count = &outputs.count.total_count.sum_cumulative.sum.0;
let height_to_output_count = &outputs.count.total_count.height.sum_cumulative.sum.0;
let height_to_input_count = &inputs.count.height.sum_cumulative.sum.0;
// From blocks:
let height_to_timestamp = &blocks.time.timestamp_monotonic;

View File

@@ -1,4 +1,4 @@
use brk_cohort::{CohortContext, Filter};
use brk_cohort::Filter;
use brk_types::Version;
use vecdb::Database;
@@ -9,17 +9,11 @@ pub struct ImportConfig<'a> {
pub db: &'a Database,
pub filter: Filter,
pub full_name: &'a str,
pub context: CohortContext,
pub version: Version,
pub indexes: &'a indexes::Vecs,
}
impl<'a> ImportConfig<'a> {
/// Whether this is an extended cohort (more relative metrics).
pub(crate) fn extended(&self) -> bool {
self.filter.is_extended(self.context)
}
/// Get full metric name with filter prefix.
pub(crate) fn name(&self, suffix: &str) -> String {
if self.full_name.is_empty() {

View File

@@ -36,14 +36,12 @@ impl CostBasisExtended {
&cfg.name("cost_basis"),
cfg.version,
cfg.indexes,
true,
)?,
invested_capital: PercentilesVecs::forced_import(
cfg.db,
&cfg.name("invested_capital"),
cfg.version,
cfg.indexes,
true,
)?,
spot_cost_basis_percentile: ComputedFromHeightLast::forced_import(
cfg.db,
@@ -99,14 +97,12 @@ impl CostBasisExtended {
self.percentiles
.vecs
.iter_mut()
.flatten()
.map(|v| &mut v.usd.height as &mut dyn AnyStoredVec),
);
vecs.extend(
self.invested_capital
.vecs
.iter_mut()
.flatten()
.map(|v| &mut v.usd.height as &mut dyn AnyStoredVec),
);
vecs.push(&mut self.spot_cost_basis_percentile.height);

View File

@@ -142,9 +142,7 @@ impl RealizedBase {
let v1 = Version::ONE;
let v2 = Version::new(2);
let v3 = Version::new(3);
let extended = cfg.extended();
// Import combined types using forced_import which handles height + derived
// Import combined types using forced_import which handles height + derived
let realized_cap_cents = ComputedFromHeightLast::forced_import(
cfg.db,
&cfg.name("realized_cap_cents"),
@@ -270,12 +268,11 @@ impl RealizedBase {
&investor_price_cents,
);
let investor_price_extra = ComputedFromHeightRatio::forced_import_from_lazy(
let investor_price_extra = ComputedFromHeightRatio::forced_import(
cfg.db,
&cfg.name("investor_price"),
cfg.version,
cfg.indexes,
extended,
)?;
let lower_price_band = Price::forced_import(
@@ -350,10 +347,8 @@ impl RealizedBase {
let realized_price_extra = ComputedFromHeightRatio::forced_import(
cfg.db,
&cfg.name("realized_price"),
Some(&realized_price.usd),
cfg.version + v1,
cfg.indexes,
extended,
)?;
let mvrv = LazyFromHeightLast::from_computed::<StoredF32Identity>(
@@ -845,28 +840,16 @@ impl RealizedBase {
exit,
)?;
self.realized_price_extra.compute_rest(
blocks,
prices,
starting_indexes,
exit,
Some(&self.realized_price.usd.height),
)?;
self.realized_price_extra.compute_usd_bands(
self.realized_price_extra.compute_ratio(
starting_indexes,
&prices.usd.price,
&self.realized_price.usd.height,
exit,
)?;
self.investor_price_extra.compute_rest(
blocks,
prices,
starting_indexes,
exit,
Some(&self.investor_price.usd.height),
)?;
self.investor_price_extra.compute_usd_bands(
self.investor_price_extra.compute_ratio(
starting_indexes,
&prices.usd.price,
&self.investor_price.usd.height,
exit,
)?;

View File

@@ -5,9 +5,7 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
use crate::{
ComputeIndexes, blocks,
internal::{
ComputedFromHeightLast, Ratio64,
},
internal::{ComputedFromHeightLast, ComputedFromHeightRatioExtension, Ratio64},
};
use crate::distribution::metrics::ImportConfig;
@@ -34,6 +32,10 @@ pub struct RealizedExtended<M: StorageMode = Rw> {
pub realized_profit_to_loss_ratio_7d: ComputedFromHeightLast<StoredF64, M>,
pub realized_profit_to_loss_ratio_30d: ComputedFromHeightLast<StoredF64, M>,
pub realized_profit_to_loss_ratio_1y: ComputedFromHeightLast<StoredF64, M>,
// === Extended ratio metrics for realized/investor price ===
pub realized_price_ratio_ext: ComputedFromHeightRatioExtension<M>,
pub investor_price_ratio_ext: ComputedFromHeightRatioExtension<M>,
}
impl RealizedExtended {
@@ -42,7 +44,12 @@ impl RealizedExtended {
macro_rules! import_rolling {
($name:expr) => {
ComputedFromHeightLast::forced_import(cfg.db, &cfg.name($name), cfg.version + v1, cfg.indexes)?
ComputedFromHeightLast::forced_import(
cfg.db,
&cfg.name($name),
cfg.version + v1,
cfg.indexes,
)?
};
}
@@ -65,9 +72,22 @@ impl RealizedExtended {
realized_profit_to_loss_ratio_7d: import_rolling!("realized_profit_to_loss_ratio_7d"),
realized_profit_to_loss_ratio_30d: import_rolling!("realized_profit_to_loss_ratio_30d"),
realized_profit_to_loss_ratio_1y: import_rolling!("realized_profit_to_loss_ratio_1y"),
realized_price_ratio_ext: ComputedFromHeightRatioExtension::forced_import(
cfg.db,
&cfg.name("realized_price"),
cfg.version + v1,
cfg.indexes,
)?,
investor_price_ratio_ext: ComputedFromHeightRatioExtension::forced_import(
cfg.db,
&cfg.name("investor_price"),
cfg.version,
cfg.indexes,
)?,
})
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn compute_rest_part2_ext(
&mut self,
base: &RealizedBase,
@@ -77,35 +97,118 @@ impl RealizedExtended {
exit: &Exit,
) -> Result<()> {
// Realized profit/loss rolling sums
self.realized_profit_24h.height.compute_rolling_sum(starting_indexes.height, &blocks.count.height_24h_ago, &base.realized_profit.height, exit)?;
self.realized_profit_7d.height.compute_rolling_sum(starting_indexes.height, &blocks.count.height_1w_ago, &base.realized_profit.height, exit)?;
self.realized_profit_30d.height.compute_rolling_sum(starting_indexes.height, &blocks.count.height_1m_ago, &base.realized_profit.height, exit)?;
self.realized_profit_1y.height.compute_rolling_sum(starting_indexes.height, &blocks.count.height_1y_ago, &base.realized_profit.height, exit)?;
self.realized_loss_24h.height.compute_rolling_sum(starting_indexes.height, &blocks.count.height_24h_ago, &base.realized_loss.height, exit)?;
self.realized_loss_7d.height.compute_rolling_sum(starting_indexes.height, &blocks.count.height_1w_ago, &base.realized_loss.height, exit)?;
self.realized_loss_30d.height.compute_rolling_sum(starting_indexes.height, &blocks.count.height_1m_ago, &base.realized_loss.height, exit)?;
self.realized_loss_1y.height.compute_rolling_sum(starting_indexes.height, &blocks.count.height_1y_ago, &base.realized_loss.height, exit)?;
// Realized cap relative to own market cap
self.realized_cap_rel_to_own_market_cap.height.compute_percentage(
self.realized_profit_24h.height.compute_rolling_sum(
starting_indexes.height,
&base.realized_cap.height,
height_to_market_cap,
&blocks.count.height_24h_ago,
&base.realized_profit.height,
exit,
)?;
self.realized_profit_7d.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1w_ago,
&base.realized_profit.height,
exit,
)?;
self.realized_profit_30d.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1m_ago,
&base.realized_profit.height,
exit,
)?;
self.realized_profit_1y.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1y_ago,
&base.realized_profit.height,
exit,
)?;
self.realized_loss_24h.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_24h_ago,
&base.realized_loss.height,
exit,
)?;
self.realized_loss_7d.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1w_ago,
&base.realized_loss.height,
exit,
)?;
self.realized_loss_30d.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1m_ago,
&base.realized_loss.height,
exit,
)?;
self.realized_loss_1y.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1y_ago,
&base.realized_loss.height,
exit,
)?;
// Realized cap relative to own market cap
self.realized_cap_rel_to_own_market_cap
.height
.compute_percentage(
starting_indexes.height,
&base.realized_cap.height,
height_to_market_cap,
exit,
)?;
// Realized profit to loss ratios
self.realized_profit_to_loss_ratio_24h.compute_binary::<Dollars, Dollars, Ratio64>(
starting_indexes.height, &self.realized_profit_24h.height, &self.realized_loss_24h.height, exit,
self.realized_profit_to_loss_ratio_24h
.compute_binary::<Dollars, Dollars, Ratio64>(
starting_indexes.height,
&self.realized_profit_24h.height,
&self.realized_loss_24h.height,
exit,
)?;
self.realized_profit_to_loss_ratio_7d
.compute_binary::<Dollars, Dollars, Ratio64>(
starting_indexes.height,
&self.realized_profit_7d.height,
&self.realized_loss_7d.height,
exit,
)?;
self.realized_profit_to_loss_ratio_30d
.compute_binary::<Dollars, Dollars, Ratio64>(
starting_indexes.height,
&self.realized_profit_30d.height,
&self.realized_loss_30d.height,
exit,
)?;
self.realized_profit_to_loss_ratio_1y
.compute_binary::<Dollars, Dollars, Ratio64>(
starting_indexes.height,
&self.realized_profit_1y.height,
&self.realized_loss_1y.height,
exit,
)?;
// Extended ratio metrics
self.realized_price_ratio_ext.compute_rest(
blocks,
starting_indexes,
exit,
&base.realized_price_extra.ratio.height,
)?;
self.realized_profit_to_loss_ratio_7d.compute_binary::<Dollars, Dollars, Ratio64>(
starting_indexes.height, &self.realized_profit_7d.height, &self.realized_loss_7d.height, exit,
self.realized_price_ratio_ext.compute_usd_bands(
starting_indexes,
&base.realized_price.usd.height,
exit,
)?;
self.realized_profit_to_loss_ratio_30d.compute_binary::<Dollars, Dollars, Ratio64>(
starting_indexes.height, &self.realized_profit_30d.height, &self.realized_loss_30d.height, exit,
self.investor_price_ratio_ext.compute_rest(
blocks,
starting_indexes,
exit,
&base.investor_price_extra.ratio.height,
)?;
self.realized_profit_to_loss_ratio_1y.compute_binary::<Dollars, Dollars, Ratio64>(
starting_indexes.height, &self.realized_profit_1y.height, &self.realized_loss_1y.height, exit,
self.investor_price_ratio_ext.compute_usd_bands(
starting_indexes,
&base.investor_price.usd.height,
exit,
)?;
Ok(())