mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -313,22 +313,22 @@ impl RealizedFull {
|
||||
.value_created
|
||||
.base
|
||||
.height
|
||||
.truncate_push(height, accum.profit_value_created)?;
|
||||
.truncate_push(height, accum.profit_value_created())?;
|
||||
self.profit
|
||||
.value_destroyed
|
||||
.base
|
||||
.height
|
||||
.truncate_push(height, accum.profit_value_destroyed)?;
|
||||
.truncate_push(height, accum.profit_value_destroyed())?;
|
||||
self.loss
|
||||
.value_created
|
||||
.base
|
||||
.height
|
||||
.truncate_push(height, accum.loss_value_created)?;
|
||||
.truncate_push(height, accum.loss_value_created())?;
|
||||
self.loss
|
||||
.value_destroyed
|
||||
.base
|
||||
.height
|
||||
.truncate_push(height, accum.loss_value_destroyed)?;
|
||||
.truncate_push(height, accum.loss_value_destroyed())?;
|
||||
self.cap_raw
|
||||
.truncate_push(height, accum.cap_raw)?;
|
||||
self.investor
|
||||
@@ -353,7 +353,7 @@ impl RealizedFull {
|
||||
.value
|
||||
.base
|
||||
.height
|
||||
.truncate_push(height, accum.peak_regret)?;
|
||||
.truncate_push(height, accum.peak_regret())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -600,23 +600,43 @@ impl RealizedFull {
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RealizedFullAccum {
|
||||
pub(crate) profit_value_created: Cents,
|
||||
pub(crate) profit_value_destroyed: Cents,
|
||||
pub(crate) loss_value_created: Cents,
|
||||
pub(crate) loss_value_destroyed: Cents,
|
||||
profit_value_created: CentsSats,
|
||||
profit_value_destroyed: CentsSats,
|
||||
loss_value_created: CentsSats,
|
||||
loss_value_destroyed: CentsSats,
|
||||
pub(crate) cap_raw: CentsSats,
|
||||
pub(crate) investor_cap_raw: CentsSquaredSats,
|
||||
pub(crate) peak_regret: Cents,
|
||||
peak_regret: CentsSats,
|
||||
}
|
||||
|
||||
impl RealizedFullAccum {
|
||||
pub(crate) fn add(&mut self, state: &RealizedState) {
|
||||
self.profit_value_created += state.profit_value_created();
|
||||
self.profit_value_destroyed += state.profit_value_destroyed();
|
||||
self.loss_value_created += state.loss_value_created();
|
||||
self.loss_value_destroyed += state.loss_value_destroyed();
|
||||
self.profit_value_created += CentsSats::new(state.profit_value_created_raw());
|
||||
self.profit_value_destroyed += CentsSats::new(state.profit_value_destroyed_raw());
|
||||
self.loss_value_created += CentsSats::new(state.loss_value_created_raw());
|
||||
self.loss_value_destroyed += CentsSats::new(state.loss_value_destroyed_raw());
|
||||
self.cap_raw += state.cap_raw();
|
||||
self.investor_cap_raw += state.investor_cap_raw();
|
||||
self.peak_regret += state.peak_regret();
|
||||
self.peak_regret += CentsSats::new(state.peak_regret_raw());
|
||||
}
|
||||
|
||||
pub(crate) fn profit_value_created(&self) -> Cents {
|
||||
self.profit_value_created.to_cents()
|
||||
}
|
||||
|
||||
pub(crate) fn profit_value_destroyed(&self) -> Cents {
|
||||
self.profit_value_destroyed.to_cents()
|
||||
}
|
||||
|
||||
pub(crate) fn loss_value_created(&self) -> Cents {
|
||||
self.loss_value_created.to_cents()
|
||||
}
|
||||
|
||||
pub(crate) fn loss_value_destroyed(&self) -> Cents {
|
||||
self.loss_value_destroyed.to_cents()
|
||||
}
|
||||
|
||||
pub(crate) fn peak_regret(&self) -> Cents {
|
||||
self.peak_regret.to_cents()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
use vecdb::{Database, ReadableCloneableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{PerBlock, DaysToYears, DerivedResolutions, PercentPerBlock, Price},
|
||||
internal::{DaysToYears, LazyPerBlock, PerBlock, PercentPerBlock, Price},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ONE;
|
||||
@@ -23,18 +23,20 @@ impl Vecs {
|
||||
let max_days_between =
|
||||
PerBlock::forced_import(db, "max_days_between_price_ath", v, indexes)?;
|
||||
|
||||
let max_years_between = DerivedResolutions::from_computed::<DaysToYears>(
|
||||
let max_years_between = LazyPerBlock::from_computed::<DaysToYears>(
|
||||
"max_years_between_price_ath",
|
||||
v,
|
||||
max_days_between.height.read_only_boxed_clone(),
|
||||
&max_days_between,
|
||||
);
|
||||
|
||||
let days_since =
|
||||
PerBlock::forced_import(db, "days_since_price_ath", v, indexes)?;
|
||||
|
||||
let years_since = DerivedResolutions::from_computed::<DaysToYears>(
|
||||
let years_since = LazyPerBlock::from_computed::<DaysToYears>(
|
||||
"years_since_price_ath",
|
||||
v,
|
||||
days_since.height.read_only_boxed_clone(),
|
||||
&days_since,
|
||||
);
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPointsSigned16, Cents, StoredF32};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{PerBlock, DerivedResolutions, PercentPerBlock, Price};
|
||||
use crate::internal::{LazyPerBlock, PerBlock, PercentPerBlock, Price};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub high: Price<PerBlock<Cents, M>>,
|
||||
pub drawdown: PercentPerBlock<BasisPointsSigned16, M>,
|
||||
pub days_since: PerBlock<StoredF32, M>,
|
||||
pub years_since: DerivedResolutions<StoredF32, StoredF32>,
|
||||
pub years_since: LazyPerBlock<StoredF32>,
|
||||
pub max_days_between: PerBlock<StoredF32, M>,
|
||||
pub max_years_between: DerivedResolutions<StoredF32, StoredF32>,
|
||||
pub max_years_between: LazyPerBlock<StoredF32>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user