mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -20,9 +20,9 @@ impl Vecs {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.hash_rate.height.compute_transform2(
|
||||
self.rate.raw.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&count_vecs.block_count.sum._24h.height,
|
||||
&count_vecs.total.sum._24h.height,
|
||||
&difficulty_vecs.as_hash.height,
|
||||
|(i, block_count_sum, difficulty_as_hash, ..)| {
|
||||
(
|
||||
@@ -36,33 +36,33 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let hash_rate = &self.hash_rate.height;
|
||||
let hash_rate = &self.rate.raw.height;
|
||||
for (sma, window) in [
|
||||
(&mut self.hash_rate_sma._1w.height, &lookback._1w),
|
||||
(&mut self.hash_rate_sma._1m.height, &lookback._1m),
|
||||
(&mut self.hash_rate_sma._2m.height, &lookback._2m),
|
||||
(&mut self.hash_rate_sma._1y.height, &lookback._1y),
|
||||
(&mut self.rate.sma._1w.height, &lookback._1w),
|
||||
(&mut self.rate.sma._1m.height, &lookback._1m),
|
||||
(&mut self.rate.sma._2m.height, &lookback._2m),
|
||||
(&mut self.rate.sma._1y.height, &lookback._1y),
|
||||
] {
|
||||
sma.compute_rolling_average(starting_indexes.height, window, hash_rate, exit)?;
|
||||
}
|
||||
|
||||
self.hash_rate_ath.height.compute_all_time_high(
|
||||
self.rate.ath.height.compute_all_time_high(
|
||||
starting_indexes.height,
|
||||
&self.hash_rate.height,
|
||||
&self.rate.raw.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.hash_rate_drawdown.compute_drawdown(
|
||||
self.rate.drawdown.compute_drawdown(
|
||||
starting_indexes.height,
|
||||
&self.hash_rate.height,
|
||||
&self.hash_rate_ath.height,
|
||||
&self.rate.raw.height,
|
||||
&self.rate.ath.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.hash_price.ths.height.compute_transform2(
|
||||
self.price.ths.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
coinbase_usd_24h_sum,
|
||||
&self.hash_rate.height,
|
||||
&self.rate.raw.height,
|
||||
|(i, coinbase_sum, hashrate, ..)| {
|
||||
let hashrate_ths = *hashrate / ONE_TERA_HASH;
|
||||
let price = if hashrate_ths == 0.0 {
|
||||
@@ -75,17 +75,17 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.hash_price.phs.height.compute_transform(
|
||||
self.price.phs.height.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.hash_price.ths.height,
|
||||
&self.price.ths.height,
|
||||
|(i, price, ..)| (i, (*price * 1000.0).into()),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.hash_value.ths.height.compute_transform2(
|
||||
self.value.ths.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
coinbase_sats_24h_sum,
|
||||
&self.hash_rate.height,
|
||||
&self.rate.raw.height,
|
||||
|(i, coinbase_sum, hashrate, ..)| {
|
||||
let hashrate_ths = *hashrate / ONE_TERA_HASH;
|
||||
let value = if hashrate_ths == 0.0 {
|
||||
@@ -98,49 +98,49 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.hash_value.phs.height.compute_transform(
|
||||
self.value.phs.height.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.hash_value.ths.height,
|
||||
&self.value.ths.height,
|
||||
|(i, value, ..)| (i, (*value * 1000.0).into()),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
for (min_vec, src_vec) in [
|
||||
(
|
||||
&mut self.hash_price.ths_min.height,
|
||||
&self.hash_price.ths.height,
|
||||
&mut self.price.ths_min.height,
|
||||
&self.price.ths.height,
|
||||
),
|
||||
(
|
||||
&mut self.hash_price.phs_min.height,
|
||||
&self.hash_price.phs.height,
|
||||
&mut self.price.phs_min.height,
|
||||
&self.price.phs.height,
|
||||
),
|
||||
(
|
||||
&mut self.hash_value.ths_min.height,
|
||||
&self.hash_value.ths.height,
|
||||
&mut self.value.ths_min.height,
|
||||
&self.value.ths.height,
|
||||
),
|
||||
(
|
||||
&mut self.hash_value.phs_min.height,
|
||||
&self.hash_value.phs.height,
|
||||
&mut self.value.phs_min.height,
|
||||
&self.value.phs.height,
|
||||
),
|
||||
] {
|
||||
min_vec.compute_all_time_low_(starting_indexes.height, src_vec, exit, true)?;
|
||||
}
|
||||
|
||||
self.hash_price
|
||||
self.price
|
||||
.rebound
|
||||
.compute_binary::<StoredF32, StoredF32, RatioDiffF32Bps32>(
|
||||
starting_indexes.height,
|
||||
&self.hash_price.phs.height,
|
||||
&self.hash_price.phs_min.height,
|
||||
&self.price.phs.height,
|
||||
&self.price.phs_min.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.hash_value
|
||||
self.value
|
||||
.rebound
|
||||
.compute_binary::<StoredF32, StoredF32, RatioDiffF32Bps32>(
|
||||
starting_indexes.height,
|
||||
&self.hash_value.phs.height,
|
||||
&self.hash_value.phs_min.height,
|
||||
&self.value.phs.height,
|
||||
&self.value.phs_min.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::{
|
||||
vecs::{HashPriceValueVecs, HashRateSmaVecs},
|
||||
vecs::{HashPriceValueVecs, HashRateSmaVecs, RateVecs},
|
||||
Vecs,
|
||||
};
|
||||
use crate::{
|
||||
@@ -21,46 +21,48 @@ impl Vecs {
|
||||
let v5 = Version::new(5);
|
||||
|
||||
Ok(Self {
|
||||
hash_rate: ComputedPerBlock::forced_import(db, "hash_rate", version + v5, indexes)?,
|
||||
hash_rate_sma: HashRateSmaVecs {
|
||||
_1w: ComputedPerBlock::forced_import(
|
||||
rate: RateVecs {
|
||||
raw: ComputedPerBlock::forced_import(db, "hash_rate", version + v5, indexes)?,
|
||||
sma: HashRateSmaVecs {
|
||||
_1w: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"hash_rate_sma_1w",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
_1m: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"hash_rate_sma_1m",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
_2m: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"hash_rate_sma_2m",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
_1y: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"hash_rate_sma_1y",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
},
|
||||
ath: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"hash_rate_sma_1w",
|
||||
"hash_rate_ath",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
_1m: ComputedPerBlock::forced_import(
|
||||
drawdown: PercentPerBlock::forced_import(
|
||||
db,
|
||||
"hash_rate_sma_1m",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
_2m: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"hash_rate_sma_2m",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
_1y: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"hash_rate_sma_1y",
|
||||
"hash_rate_drawdown",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
},
|
||||
hash_rate_ath: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"hash_rate_ath",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_rate_drawdown: PercentPerBlock::forced_import(
|
||||
db,
|
||||
"hash_rate_drawdown",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_price: HashPriceValueVecs {
|
||||
price: HashPriceValueVecs {
|
||||
ths: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"hash_price_ths",
|
||||
@@ -92,7 +94,7 @@ impl Vecs {
|
||||
indexes,
|
||||
)?,
|
||||
},
|
||||
hash_value: HashPriceValueVecs {
|
||||
value: HashPriceValueVecs {
|
||||
ths: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"hash_value_ths",
|
||||
|
||||
@@ -22,11 +22,16 @@ pub struct HashPriceValueVecs<M: StorageMode = Rw> {
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub hash_rate: ComputedPerBlock<StoredF64, M>,
|
||||
pub hash_rate_sma: HashRateSmaVecs<M>,
|
||||
pub hash_rate_ath: ComputedPerBlock<StoredF64, M>,
|
||||
pub hash_rate_drawdown: PercentPerBlock<BasisPointsSigned16, M>,
|
||||
pub hash_price: HashPriceValueVecs<M>,
|
||||
pub hash_value: HashPriceValueVecs<M>,
|
||||
pub struct RateVecs<M: StorageMode = Rw> {
|
||||
pub raw: ComputedPerBlock<StoredF64, M>,
|
||||
pub sma: HashRateSmaVecs<M>,
|
||||
pub ath: ComputedPerBlock<StoredF64, M>,
|
||||
pub drawdown: PercentPerBlock<BasisPointsSigned16, M>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub rate: RateVecs<M>,
|
||||
pub price: HashPriceValueVecs<M>,
|
||||
pub value: HashPriceValueVecs<M>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user