mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-20 07:28:11 -07:00
global: snapshot
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use std::{fs, ops::Deref, path::Path};
|
||||
|
||||
use brk_core::{
|
||||
Date, Dateindex, Decadeindex, Difficultyepoch, Halvingepoch, Height, Monthindex, Timestamp,
|
||||
Txindex, Txinindex, Txoutindex, Weekindex, Yearindex,
|
||||
Date, Dateindex, Decadeindex, Difficultyepoch, Halvingepoch, Height, Monthindex, Quarterindex,
|
||||
Timestamp, Txindex, Txinindex, Txoutindex, Weekindex, Yearindex,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
@@ -35,8 +35,8 @@ pub struct Vecs {
|
||||
pub halvingepoch_to_timestamp: StorableVec<Halvingepoch, Timestamp>,
|
||||
pub height_to_dateindex: StorableVec<Height, Dateindex>,
|
||||
pub height_to_difficultyepoch: StorableVec<Height, Difficultyepoch>,
|
||||
pub height_to_fixed_timestamp: StorableVec<Height, Timestamp>,
|
||||
pub height_to_fixed_date: StorableVec<Height, Date>,
|
||||
pub height_to_fixed_timestamp: StorableVec<Height, Timestamp>,
|
||||
pub height_to_halvingepoch: StorableVec<Height, Halvingepoch>,
|
||||
pub height_to_height: StorableVec<Height, Height>,
|
||||
pub height_to_last_txindex: StorableVec<Height, Txindex>,
|
||||
@@ -44,8 +44,13 @@ pub struct Vecs {
|
||||
pub monthindex_to_first_dateindex: StorableVec<Monthindex, Dateindex>,
|
||||
pub monthindex_to_last_dateindex: StorableVec<Monthindex, Dateindex>,
|
||||
pub monthindex_to_monthindex: StorableVec<Monthindex, Monthindex>,
|
||||
pub monthindex_to_quarterindex: StorableVec<Monthindex, Quarterindex>,
|
||||
pub monthindex_to_timestamp: StorableVec<Monthindex, Timestamp>,
|
||||
pub monthindex_to_yearindex: StorableVec<Monthindex, Yearindex>,
|
||||
pub quarterindex_to_first_monthindex: StorableVec<Quarterindex, Monthindex>,
|
||||
pub quarterindex_to_last_monthindex: StorableVec<Quarterindex, Monthindex>,
|
||||
pub quarterindex_to_quarterindex: StorableVec<Quarterindex, Quarterindex>,
|
||||
pub quarterindex_to_timestamp: StorableVec<Quarterindex, Timestamp>,
|
||||
pub txindex_to_last_txinindex: StorableVec<Txindex, Txinindex>,
|
||||
pub txindex_to_last_txoutindex: StorableVec<Txindex, Txoutindex>,
|
||||
pub weekindex_to_first_dateindex: StorableVec<Weekindex, Dateindex>,
|
||||
@@ -279,6 +284,31 @@ impl Vecs {
|
||||
Version::from(1),
|
||||
compressed,
|
||||
)?,
|
||||
monthindex_to_quarterindex: StorableVec::forced_import(
|
||||
&path.join("monthindex_to_quarterindex"),
|
||||
Version::from(1),
|
||||
compressed,
|
||||
)?,
|
||||
quarterindex_to_first_monthindex: StorableVec::forced_import(
|
||||
&path.join("quarterindex_to_first_monthindex"),
|
||||
Version::from(1),
|
||||
compressed,
|
||||
)?,
|
||||
quarterindex_to_last_monthindex: StorableVec::forced_import(
|
||||
&path.join("quarterindex_to_last_monthindex"),
|
||||
Version::from(1),
|
||||
compressed,
|
||||
)?,
|
||||
quarterindex_to_quarterindex: StorableVec::forced_import(
|
||||
&path.join("quarterindex_to_quarterindex"),
|
||||
Version::from(1),
|
||||
compressed,
|
||||
)?,
|
||||
quarterindex_to_timestamp: StorableVec::forced_import(
|
||||
&path.join("quarterindex_to_timestamp"),
|
||||
Version::from(1),
|
||||
compressed,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -509,6 +539,52 @@ impl Vecs {
|
||||
|
||||
// ---
|
||||
|
||||
let starting_quarterindex = self
|
||||
.monthindex_to_quarterindex
|
||||
.get(starting_monthindex)?
|
||||
.copied()
|
||||
.unwrap_or_default();
|
||||
|
||||
self.monthindex_to_quarterindex.compute_transform(
|
||||
starting_monthindex,
|
||||
self.monthindex_to_monthindex.mut_vec(),
|
||||
|(mi, ..)| (mi, Quarterindex::from(mi)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.quarterindex_to_first_monthindex
|
||||
.compute_inverse_more_to_less(
|
||||
starting_monthindex,
|
||||
self.monthindex_to_quarterindex.mut_vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// let quarter_count = self.quarterindex_to_first_monthindex.len();
|
||||
|
||||
self.quarterindex_to_last_monthindex
|
||||
.compute_last_index_from_first(
|
||||
starting_quarterindex,
|
||||
self.quarterindex_to_first_monthindex.mut_vec(),
|
||||
month_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.quarterindex_to_quarterindex.compute_transform(
|
||||
starting_quarterindex,
|
||||
self.quarterindex_to_first_monthindex.mut_vec(),
|
||||
|(yi, ..)| (yi, yi),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.quarterindex_to_timestamp.compute_transform(
|
||||
starting_quarterindex,
|
||||
self.quarterindex_to_first_monthindex.mut_vec(),
|
||||
|(i, m, ..)| (i, *self.monthindex_to_timestamp.get(m).unwrap().unwrap()),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
|
||||
let starting_yearindex = self
|
||||
.monthindex_to_yearindex
|
||||
.get(starting_monthindex)?
|
||||
@@ -700,6 +776,7 @@ impl Vecs {
|
||||
dateindex: starting_dateindex,
|
||||
weekindex: starting_weekindex,
|
||||
monthindex: starting_monthindex,
|
||||
quarterindex: starting_quarterindex,
|
||||
yearindex: starting_yearindex,
|
||||
decadeindex: starting_decadeindex,
|
||||
difficultyepoch: starting_difficultyepoch,
|
||||
@@ -752,6 +829,11 @@ impl Vecs {
|
||||
self.weekindex_to_timestamp.any_vec(),
|
||||
self.yearindex_to_timestamp.any_vec(),
|
||||
self.height_to_fixed_timestamp.any_vec(),
|
||||
self.monthindex_to_quarterindex.any_vec(),
|
||||
self.quarterindex_to_first_monthindex.any_vec(),
|
||||
self.quarterindex_to_last_monthindex.any_vec(),
|
||||
self.quarterindex_to_quarterindex.any_vec(),
|
||||
self.quarterindex_to_timestamp.any_vec(),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -761,6 +843,7 @@ pub struct Indexes {
|
||||
pub dateindex: Dateindex,
|
||||
pub weekindex: Weekindex,
|
||||
pub monthindex: Monthindex,
|
||||
pub quarterindex: Quarterindex,
|
||||
pub yearindex: Yearindex,
|
||||
pub decadeindex: Decadeindex,
|
||||
pub difficultyepoch: Difficultyepoch,
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::{fs, path::Path};
|
||||
|
||||
use brk_core::{
|
||||
Cents, Close, Dateindex, Decadeindex, Difficultyepoch, Dollars, Height, High, Low, Monthindex,
|
||||
OHLCCents, OHLCDollars, Open, Sats, Weekindex, Yearindex,
|
||||
OHLCCents, OHLCDollars, Open, Quarterindex, Sats, Weekindex, Yearindex,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_fetcher::Fetcher;
|
||||
@@ -53,6 +53,7 @@ pub struct Vecs {
|
||||
pub weekindex_to_ohlc: StorableVec<Weekindex, OHLCDollars>,
|
||||
pub difficultyepoch_to_ohlc: StorableVec<Difficultyepoch, OHLCDollars>,
|
||||
pub monthindex_to_ohlc: StorableVec<Monthindex, OHLCDollars>,
|
||||
pub quarterindex_to_ohlc: StorableVec<Quarterindex, OHLCDollars>,
|
||||
pub yearindex_to_ohlc: StorableVec<Yearindex, OHLCDollars>,
|
||||
// pub halvingepoch_to_ohlc: StorableVec<Halvingepoch, OHLCDollars>,
|
||||
pub decadeindex_to_ohlc: StorableVec<Decadeindex, OHLCDollars>,
|
||||
@@ -238,6 +239,11 @@ impl Vecs {
|
||||
Version::from(1),
|
||||
compressed,
|
||||
)?,
|
||||
quarterindex_to_ohlc: StorableVec::forced_import(
|
||||
&path.join("quarterindex_to_ohlc"),
|
||||
Version::from(1),
|
||||
compressed,
|
||||
)?,
|
||||
yearindex_to_ohlc: StorableVec::forced_import(
|
||||
&path.join("yearindex_to_ohlc"),
|
||||
Version::from(1),
|
||||
@@ -623,6 +629,52 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.quarterindex_to_ohlc.compute_transform(
|
||||
starting_indexes.quarterindex,
|
||||
self.timeindexes_to_close
|
||||
.quarterindex
|
||||
.last
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.mut_vec(),
|
||||
|(i, close, ..)| {
|
||||
(
|
||||
i,
|
||||
OHLCDollars {
|
||||
open: *self
|
||||
.timeindexes_to_open
|
||||
.quarterindex
|
||||
.first
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.get(i)
|
||||
.unwrap()
|
||||
.unwrap(),
|
||||
high: *self
|
||||
.timeindexes_to_high
|
||||
.quarterindex
|
||||
.max
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.get(i)
|
||||
.unwrap()
|
||||
.unwrap(),
|
||||
low: *self
|
||||
.timeindexes_to_low
|
||||
.quarterindex
|
||||
.min
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.get(i)
|
||||
.unwrap()
|
||||
.unwrap(),
|
||||
close,
|
||||
},
|
||||
)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.yearindex_to_ohlc.compute_transform(
|
||||
starting_indexes.yearindex,
|
||||
self.timeindexes_to_close
|
||||
@@ -750,6 +802,7 @@ impl Vecs {
|
||||
self.weekindex_to_ohlc.any_vec(),
|
||||
self.difficultyepoch_to_ohlc.any_vec(),
|
||||
self.monthindex_to_ohlc.any_vec(),
|
||||
self.quarterindex_to_ohlc.any_vec(),
|
||||
self.yearindex_to_ohlc.any_vec(),
|
||||
// self.halvingepoch_to_ohlc.any_vec(),
|
||||
self.decadeindex_to_ohlc.any_vec(),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_core::{Dateindex, Decadeindex, Monthindex, Weekindex, Yearindex};
|
||||
use brk_core::{Dateindex, Decadeindex, Monthindex, Quarterindex, Weekindex, Yearindex};
|
||||
use brk_exit::Exit;
|
||||
use brk_vec::{AnyStorableVec, Compressed};
|
||||
|
||||
@@ -15,6 +15,7 @@ where
|
||||
{
|
||||
pub weekindex: StorableVecBuilder<Weekindex, T>,
|
||||
pub monthindex: StorableVecBuilder<Monthindex, T>,
|
||||
pub quarterindex: StorableVecBuilder<Quarterindex, T>,
|
||||
pub yearindex: StorableVecBuilder<Yearindex, T>,
|
||||
pub decadeindex: StorableVecBuilder<Decadeindex, T>,
|
||||
}
|
||||
@@ -34,6 +35,7 @@ where
|
||||
Ok(Self {
|
||||
weekindex: StorableVecBuilder::forced_import(path, compressed, options)?,
|
||||
monthindex: StorableVecBuilder::forced_import(path, compressed, options)?,
|
||||
quarterindex: StorableVecBuilder::forced_import(path, compressed, options)?,
|
||||
yearindex: StorableVecBuilder::forced_import(path, compressed, options)?,
|
||||
decadeindex: StorableVecBuilder::forced_import(path, compressed, options)?,
|
||||
})
|
||||
@@ -62,6 +64,14 @@ where
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.quarterindex.from_aligned(
|
||||
starting_indexes.quarterindex,
|
||||
&mut self.monthindex,
|
||||
indexes.quarterindex_to_first_monthindex.mut_vec(),
|
||||
indexes.quarterindex_to_last_monthindex.mut_vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.yearindex.from_aligned(
|
||||
starting_indexes.yearindex,
|
||||
&mut self.monthindex,
|
||||
@@ -85,6 +95,7 @@ where
|
||||
[
|
||||
self.weekindex.as_any_vecs(),
|
||||
self.monthindex.as_any_vecs(),
|
||||
self.quarterindex.as_any_vecs(),
|
||||
self.yearindex.as_any_vecs(),
|
||||
self.decadeindex.as_any_vecs(),
|
||||
]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_core::{Dateindex, Decadeindex, Difficultyepoch, Height, Monthindex, Weekindex, Yearindex};
|
||||
use brk_core::{
|
||||
Dateindex, Decadeindex, Difficultyepoch, Height, Monthindex, Quarterindex, Weekindex, Yearindex,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_vec::{AnyStorableVec, Compressed};
|
||||
|
||||
@@ -17,6 +19,7 @@ where
|
||||
pub weekindex: StorableVecBuilder<Weekindex, T>,
|
||||
pub difficultyepoch: StorableVecBuilder<Difficultyepoch, T>,
|
||||
pub monthindex: StorableVecBuilder<Monthindex, T>,
|
||||
pub quarterindex: StorableVecBuilder<Quarterindex, T>,
|
||||
pub yearindex: StorableVecBuilder<Yearindex, T>,
|
||||
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
|
||||
pub decadeindex: StorableVecBuilder<Decadeindex, T>,
|
||||
@@ -41,6 +44,7 @@ where
|
||||
weekindex: StorableVecBuilder::forced_import(path, compressed, options)?,
|
||||
difficultyepoch: StorableVecBuilder::forced_import(path, compressed, options)?,
|
||||
monthindex: StorableVecBuilder::forced_import(path, compressed, options)?,
|
||||
quarterindex: StorableVecBuilder::forced_import(path, compressed, options)?,
|
||||
yearindex: StorableVecBuilder::forced_import(path, compressed, options)?,
|
||||
// halvingepoch: StorableVecGeneator::forced_import(path, compressed, options)?,
|
||||
decadeindex: StorableVecBuilder::forced_import(path, compressed, options)?,
|
||||
@@ -78,6 +82,14 @@ where
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.quarterindex.from_aligned(
|
||||
starting_indexes.quarterindex,
|
||||
&mut self.monthindex,
|
||||
indexes.quarterindex_to_first_monthindex.mut_vec(),
|
||||
indexes.quarterindex_to_last_monthindex.mut_vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.yearindex.from_aligned(
|
||||
starting_indexes.yearindex,
|
||||
&mut self.monthindex,
|
||||
@@ -111,6 +123,7 @@ where
|
||||
self.weekindex.as_any_vecs(),
|
||||
self.difficultyepoch.as_any_vecs(),
|
||||
self.monthindex.as_any_vecs(),
|
||||
self.quarterindex.as_any_vecs(),
|
||||
self.yearindex.as_any_vecs(),
|
||||
// self.halvingepoch.as_any_vecs(),
|
||||
self.decadeindex.as_any_vecs(),
|
||||
|
||||
Reference in New Issue
Block a user